Meta.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Reader\ODText;
  18. use PhpOffice\PhpWord\PhpWord;
  19. use PhpOffice\PhpWord\Shared\XMLReader;
  20. /**
  21. * Meta reader
  22. *
  23. * @since 0.11.0
  24. */
  25. class Meta extends AbstractPart
  26. {
  27. /**
  28. * Read meta.xml.
  29. *
  30. * @param \PhpOffice\PhpWord\PhpWord $phpWord
  31. * @return void
  32. * @todo Process property type
  33. */
  34. public function read(PhpWord $phpWord)
  35. {
  36. $xmlReader = new XMLReader();
  37. $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
  38. $docProps = $phpWord->getDocInfo();
  39. $metaNode = $xmlReader->getElement('office:meta');
  40. // Standard properties
  41. $properties = array(
  42. 'title' => 'dc:title',
  43. 'subject' => 'dc:subject',
  44. 'description' => 'dc:description',
  45. 'keywords' => 'meta:keyword',
  46. 'creator' => 'meta:initial-creator',
  47. 'lastModifiedBy' => 'dc:creator',
  48. // 'created' => 'meta:creation-date',
  49. // 'modified' => 'dc:date',
  50. );
  51. foreach ($properties as $property => $path) {
  52. $method = "set{$property}";
  53. $propertyNode = $xmlReader->getElement($path, $metaNode);
  54. if ($propertyNode !== null && method_exists($docProps, $method)) {
  55. $docProps->$method($propertyNode->nodeValue);
  56. }
  57. }
  58. // Custom properties
  59. $propertyNodes = $xmlReader->getElements('meta:user-defined', $metaNode);
  60. foreach ($propertyNodes as $propertyNode) {
  61. $property = $xmlReader->getAttribute('meta:name', $propertyNode);
  62. // Set category, company, and manager property
  63. if (in_array($property, array('Category', 'Company', 'Manager'))) {
  64. $method = "set{$property}";
  65. $docProps->$method($propertyNode->nodeValue);
  66. // Set other custom properties
  67. } else {
  68. $docProps->setCustomProperty($property, $propertyNode->nodeValue);
  69. }
  70. }
  71. }
  72. }