Meta.php 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * PHPExcel_Writer_OpenDocument_Meta
  4. *
  5. * Copyright (c) 2006 - 2015 PHPExcel
  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 PHPExcel
  22. * @package PHPExcel_Writer_OpenDocument
  23. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_Writer_OpenDocument_Meta extends PHPExcel_Writer_OpenDocument_WriterPart
  28. {
  29. /**
  30. * Write meta.xml to XML format
  31. *
  32. * @param PHPExcel $pPHPExcel
  33. * @return string XML Output
  34. * @throws PHPExcel_Writer_Exception
  35. */
  36. public function write(PHPExcel $pPHPExcel = null)
  37. {
  38. if (!$pPHPExcel) {
  39. $pPHPExcel = $this->getParentWriter()->getPHPExcel();
  40. }
  41. $objWriter = null;
  42. if ($this->getParentWriter()->getUseDiskCaching()) {
  43. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
  44. } else {
  45. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  46. }
  47. // XML header
  48. $objWriter->startDocument('1.0', 'UTF-8');
  49. // Meta
  50. $objWriter->startElement('office:document-meta');
  51. $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
  52. $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  53. $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
  54. $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
  55. $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
  56. $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
  57. $objWriter->writeAttribute('office:version', '1.2');
  58. $objWriter->startElement('office:meta');
  59. $objWriter->writeElement('meta:initial-creator', $pPHPExcel->getProperties()->getCreator());
  60. $objWriter->writeElement('dc:creator', $pPHPExcel->getProperties()->getCreator());
  61. $objWriter->writeElement('meta:creation-date', date(DATE_W3C, $pPHPExcel->getProperties()->getCreated()));
  62. $objWriter->writeElement('dc:date', date(DATE_W3C, $pPHPExcel->getProperties()->getCreated()));
  63. $objWriter->writeElement('dc:title', $pPHPExcel->getProperties()->getTitle());
  64. $objWriter->writeElement('dc:description', $pPHPExcel->getProperties()->getDescription());
  65. $objWriter->writeElement('dc:subject', $pPHPExcel->getProperties()->getSubject());
  66. $keywords = explode(' ', $pPHPExcel->getProperties()->getKeywords());
  67. foreach ($keywords as $keyword) {
  68. $objWriter->writeElement('meta:keyword', $keyword);
  69. }
  70. //<meta:document-statistic meta:table-count="XXX" meta:cell-count="XXX" meta:object-count="XXX"/>
  71. $objWriter->startElement('meta:user-defined');
  72. $objWriter->writeAttribute('meta:name', 'Company');
  73. $objWriter->writeRaw($pPHPExcel->getProperties()->getCompany());
  74. $objWriter->endElement();
  75. $objWriter->startElement('meta:user-defined');
  76. $objWriter->writeAttribute('meta:name', 'category');
  77. $objWriter->writeRaw($pPHPExcel->getProperties()->getCategory());
  78. $objWriter->endElement();
  79. $objWriter->endElement();
  80. $objWriter->endElement();
  81. return $objWriter->getData();
  82. }
  83. }