Geen omschrijving

DocPropsCore.php 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\Writer\Word2007\Part;
  18. /**
  19. * Word2007 core document properties part writer: docProps/core.xml
  20. *
  21. * @since 0.11.0
  22. */
  23. class DocPropsCore extends AbstractPart
  24. {
  25. /**
  26. * Write part
  27. *
  28. * @return string
  29. */
  30. public function write()
  31. {
  32. $phpWord = $this->getParentWriter()->getPhpWord();
  33. $xmlWriter = $this->getXmlWriter();
  34. $schema = 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties';
  35. $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
  36. $xmlWriter->startElement('cp:coreProperties');
  37. $xmlWriter->writeAttribute('xmlns:cp', $schema);
  38. $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
  39. $xmlWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
  40. $xmlWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
  41. $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  42. $xmlWriter->writeElement('dc:creator', $phpWord->getDocInfo()->getCreator());
  43. $xmlWriter->writeElement('dc:title', $phpWord->getDocInfo()->getTitle());
  44. $xmlWriter->writeElement('dc:description', $phpWord->getDocInfo()->getDescription());
  45. $xmlWriter->writeElement('dc:subject', $phpWord->getDocInfo()->getSubject());
  46. $xmlWriter->writeElement('cp:keywords', $phpWord->getDocInfo()->getKeywords());
  47. $xmlWriter->writeElement('cp:category', $phpWord->getDocInfo()->getCategory());
  48. $xmlWriter->writeElement('cp:lastModifiedBy', $phpWord->getDocInfo()->getLastModifiedBy());
  49. // dcterms:created
  50. $xmlWriter->startElement('dcterms:created');
  51. $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
  52. $xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocInfo()->getCreated()));
  53. $xmlWriter->endElement();
  54. // dcterms:modified
  55. $xmlWriter->startElement('dcterms:modified');
  56. $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
  57. $xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocInfo()->getModified()));
  58. $xmlWriter->endElement();
  59. $xmlWriter->endElement(); // cp:coreProperties
  60. return $xmlWriter->getData();
  61. }
  62. }