DocProps.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * PHPWord
  4. *
  5. * Copyright (c) 2011 PHPWord
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPWord
  22. * @package PHPWord
  23. * @copyright Copyright (c) 010 PHPWord
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version Beta 0.6.3, 08.07.2011
  26. */
  27. class PHPWord_Writer_Word2007_DocProps extends PHPWord_Writer_Word2007_WriterPart {
  28. public function writeDocPropsApp(PHPWord $pPHPWord = null) {
  29. // Create XML writer
  30. $objWriter = null;
  31. if ($this->getParentWriter()->getUseDiskCaching()) {
  32. $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
  33. } else {
  34. $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
  35. }
  36. // XML header
  37. $objWriter->startDocument('1.0','UTF-8','yes');
  38. // Properties
  39. $objWriter->startElement('Properties');
  40. $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
  41. $objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
  42. // Application
  43. $objWriter->writeElement('Application', 'Microsoft Office Word');
  44. // ScaleCrop
  45. $objWriter->writeElement('ScaleCrop', 'false');
  46. // HeadingPairs
  47. $objWriter->startElement('HeadingPairs');
  48. // Vector
  49. $objWriter->startElement('vt:vector');
  50. $objWriter->writeAttribute('size', '4');
  51. $objWriter->writeAttribute('baseType', 'variant');
  52. // Variant
  53. $objWriter->startElement('vt:variant');
  54. $objWriter->writeElement('vt:lpstr', 'Theme');
  55. $objWriter->endElement();
  56. // Variant
  57. $objWriter->startElement('vt:variant');
  58. $objWriter->writeElement('vt:i4', '1');
  59. $objWriter->endElement();
  60. // Variant
  61. $objWriter->startElement('vt:variant');
  62. $objWriter->writeElement('vt:lpstr', 'Slide Titles');
  63. $objWriter->endElement();
  64. // Variant
  65. $objWriter->startElement('vt:variant');
  66. $objWriter->writeElement('vt:i4', '1');
  67. $objWriter->endElement();
  68. $objWriter->endElement();
  69. $objWriter->endElement();
  70. // TitlesOfParts
  71. $objWriter->startElement('TitlesOfParts');
  72. // Vector
  73. $objWriter->startElement('vt:vector');
  74. $objWriter->writeAttribute('size', '1');
  75. $objWriter->writeAttribute('baseType', 'lpstr');
  76. $objWriter->writeElement('vt:lpstr', 'Office Theme');
  77. $objWriter->endElement();
  78. $objWriter->endElement();
  79. // Company
  80. $objWriter->writeElement('Company', $pPHPWord->getProperties()->getCompany());
  81. // LinksUpToDate
  82. $objWriter->writeElement('LinksUpToDate', 'false');
  83. // SharedDoc
  84. $objWriter->writeElement('SharedDoc', 'false');
  85. // HyperlinksChanged
  86. $objWriter->writeElement('HyperlinksChanged', 'false');
  87. // AppVersion
  88. $objWriter->writeElement('AppVersion', '12.0000');
  89. $objWriter->endElement();
  90. // Return
  91. return $objWriter->getData();
  92. }
  93. public function writeDocPropsCore(PHPWord $pPHPWord = null) {
  94. // Create XML writer
  95. $objWriter = null;
  96. if ($this->getParentWriter()->getUseDiskCaching()) {
  97. $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
  98. } else {
  99. $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
  100. }
  101. // XML header
  102. $objWriter->startDocument('1.0','UTF-8','yes');
  103. // cp:coreProperties
  104. $objWriter->startElement('cp:coreProperties');
  105. $objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
  106. $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
  107. $objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
  108. $objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
  109. $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  110. // dc:creator
  111. $objWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getCreator());
  112. // cp:lastModifiedBy
  113. $objWriter->writeElement('cp:lastModifiedBy', $pPHPWord->getProperties()->getLastModifiedBy());
  114. // dcterms:created
  115. $objWriter->startElement('dcterms:created');
  116. $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
  117. $objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getCreated()));
  118. $objWriter->endElement();
  119. // dcterms:modified
  120. $objWriter->startElement('dcterms:modified');
  121. $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
  122. $objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getModified()));
  123. $objWriter->endElement();
  124. // dc:title
  125. $objWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle());
  126. // dc:description
  127. $objWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription());
  128. // dc:subject
  129. $objWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject());
  130. // cp:keywords
  131. $objWriter->writeElement('cp:keywords', $pPHPWord->getProperties()->getKeywords());
  132. // cp:category
  133. $objWriter->writeElement('cp:category', $pPHPWord->getProperties()->getCategory());
  134. $objWriter->endElement();
  135. // Return
  136. return $objWriter->getData();
  137. }
  138. }