Header.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_Header extends PHPWord_Writer_Word2007_Base {
  28. public function writeHeader(PHPWord_Section_Header $header) {
  29. // Create XML writer
  30. if ($this->getParentWriter()->getUseDiskCaching()) {
  31. $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
  32. } else {
  33. $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
  34. }
  35. // XML header
  36. $objWriter->startDocument('1.0', 'UTF-8', 'yes');
  37. $objWriter->startElement('w:hdr');
  38. $objWriter->writeAttribute('xmlns:ve','http://schemas.openxmlformats.org/markup-compatibility/2006');
  39. $objWriter->writeAttribute('xmlns:o','urn:schemas-microsoft-com:office:office');
  40. $objWriter->writeAttribute('xmlns:r','http://schemas.openxmlformats.org/officeDocument/2006/relationships');
  41. $objWriter->writeAttribute('xmlns:m','http://schemas.openxmlformats.org/officeDocument/2006/math');
  42. $objWriter->writeAttribute('xmlns:v','urn:schemas-microsoft-com:vml');
  43. $objWriter->writeAttribute('xmlns:wp','http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
  44. $objWriter->writeAttribute('xmlns:w10','urn:schemas-microsoft-com:office:word');
  45. $objWriter->writeAttribute('xmlns:w','http://schemas.openxmlformats.org/wordprocessingml/2006/main');
  46. $objWriter->writeAttribute('xmlns:wne','http://schemas.microsoft.com/office/word/2006/wordml');
  47. $_elements = $header->getElements();
  48. foreach($_elements as $element) {
  49. if($element instanceof PHPWord_Section_Text) {
  50. $this->_writeText($objWriter, $element);
  51. } elseif($element instanceof PHPWord_Section_TextRun) {
  52. $this->_writeTextRun($objWriter, $element);
  53. } elseif($element instanceof PHPWord_Section_TextBreak) {
  54. $this->_writeTextBreak($objWriter);
  55. } elseif($element instanceof PHPWord_Section_Table) {
  56. $this->_writeTable($objWriter, $element);
  57. } elseif($element instanceof PHPWord_Section_Image ||
  58. $element instanceof PHPWord_Section_MemoryImage) {
  59. if(!$element->getIsWatermark()) {
  60. $this->_writeImage($objWriter, $element);
  61. } else {
  62. $this->_writeWatermark($objWriter, $element);
  63. }
  64. } elseif($element instanceof PHPWord_Section_Footer_PreserveText) {
  65. $this->_writePreserveText($objWriter, $element);
  66. }
  67. }
  68. $objWriter->endElement();
  69. // Return
  70. return $objWriter->getData();
  71. }
  72. }
  73. ?>