No Description

Manifest.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\ODText\Part;
  18. use PhpOffice\PhpWord\Media;
  19. /**
  20. * ODText manifest part writer: META-INF/manifest.xml
  21. */
  22. class Manifest extends AbstractPart
  23. {
  24. /**
  25. * Write part
  26. *
  27. * @return string
  28. */
  29. public function write()
  30. {
  31. $parts = array('content.xml', 'meta.xml', 'styles.xml');
  32. $xmlWriter = $this->getXmlWriter();
  33. $xmlWriter->startDocument('1.0', 'UTF-8');
  34. $xmlWriter->startElement('manifest:manifest');
  35. $xmlWriter->writeAttribute('manifest:version', '1.2');
  36. $xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
  37. $xmlWriter->startElement('manifest:file-entry');
  38. $xmlWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text');
  39. $xmlWriter->writeAttribute('manifest:full-path', '/');
  40. $xmlWriter->writeAttribute('manifest:version', '1.2');
  41. $xmlWriter->endElement();
  42. // Parts
  43. foreach ($parts as $part) {
  44. $xmlWriter->startElement('manifest:file-entry');
  45. $xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
  46. $xmlWriter->writeAttribute('manifest:full-path', $part);
  47. $xmlWriter->endElement();
  48. }
  49. // Media files
  50. $media = Media::getElements('section');
  51. foreach ($media as $medium) {
  52. if ($medium['type'] == 'image') {
  53. $xmlWriter->startElement('manifest:file-entry');
  54. $xmlWriter->writeAttribute('manifest:media-type', $medium['imageType']);
  55. $xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . $medium['target']);
  56. $xmlWriter->endElement();
  57. }
  58. }
  59. $xmlWriter->endElement(); // manifest:manifest
  60. return $xmlWriter->getData();
  61. }
  62. }