Overview

Packages

  • PHP
  • PHPWord

Classes

  • PHPWord
  • PHPWord_Autoloader
  • PHPWord_DocumentProperties
  • PHPWord_HashTable
  • PHPWord_IOFactory
  • PHPWord_Media
  • PHPWord_Section
  • PHPWord_Section_Footer
  • PHPWord_Section_Footer_PreserveText
  • PHPWord_Section_Header
  • PHPWord_Section_Image
  • PHPWord_Section_Link
  • PHPWord_Section_ListItem
  • PHPWord_Section_MemoryImage
  • PHPWord_Section_Object
  • PHPWord_Section_PageBreak
  • PHPWord_Section_Settings
  • PHPWord_Section_Table
  • PHPWord_Section_Table_Cell
  • PHPWord_Section_Table_Row
  • PHPWord_Section_Text
  • PHPWord_Section_TextBreak
  • PHPWord_Section_TextRun
  • PHPWord_Section_Title
  • PHPWord_Shared_Drawing
  • PHPWord_Shared_File
  • PHPWord_Shared_Font
  • PHPWord_Shared_String
  • PHPWord_Shared_XMLWriter
  • PHPWord_Shared_ZipStreamWrapper
  • PHPWord_Style
  • PHPWord_Style_Cell
  • PHPWord_Style_Font
  • PHPWord_Style_Image
  • PHPWord_Style_ListItem
  • PHPWord_Style_Paragraph
  • PHPWord_Style_Row
  • PHPWord_Style_Tab
  • PHPWord_Style_Table
  • PHPWord_Style_TableFull
  • PHPWord_Style_Tabs
  • PHPWord_Style_TOC
  • PHPWord_Template
  • PHPWord_TOC
  • PHPWord_Writer_ODText
  • PHPWord_Writer_ODText_Content
  • PHPWord_Writer_ODText_Manifest
  • PHPWord_Writer_ODText_Meta
  • PHPWord_Writer_ODText_Mimetype
  • PHPWord_Writer_ODText_Styles
  • PHPWord_Writer_ODText_WriterPart
  • PHPWord_Writer_RTF
  • PHPWord_Writer_Word2007
  • PHPWord_Writer_Word2007_Base
  • PHPWord_Writer_Word2007_ContentTypes
  • PHPWord_Writer_Word2007_DocProps
  • PHPWord_Writer_Word2007_Document
  • PHPWord_Writer_Word2007_DocumentRels
  • PHPWord_Writer_Word2007_Footer
  • PHPWord_Writer_Word2007_Header
  • PHPWord_Writer_Word2007_Rels
  • PHPWord_Writer_Word2007_Styles
  • PHPWord_Writer_Word2007_WriterPart

Interfaces

  • PHPWord_Writer_IWriter

Exceptions

  • PHPWord_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * PHPWord
  4:  *
  5:  * Copyright (c) 2013 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) 2013 PHPWord
 24:  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 25:  * @version    0.7.0
 26:  */
 27: 
 28: /**
 29:  * Class PHPWord_Writer_ODText_Manifest
 30:  */
 31: class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
 32: {
 33:     /**
 34:      * Write content file to XML format
 35:      *
 36:      * @param    PHPWord $pPHPWord
 37:      * @return    string                        XML Output
 38:      * @throws    Exception
 39:      */
 40:     public function writeContent(PHPWord $pPHPWord = null)
 41:     {
 42:         // Create XML writer
 43:         $objWriter = null;
 44:         if ($this->getParentWriter()->getUseDiskCaching()) {
 45:             $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
 46:         } else {
 47:             $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
 48:         }
 49: 
 50:         // XML header
 51:         $objWriter->startDocument('1.0', 'UTF-8');
 52: 
 53:         // office:document-content
 54:         $objWriter->startElement('office:document-content');
 55:         $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
 56:         $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
 57:         $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
 58:         $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
 59:         $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
 60:         $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
 61:         $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
 62:         $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
 63:         $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
 64:         $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
 65:         $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
 66:         $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
 67:         $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
 68:         $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
 69:         $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
 70:         $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
 71:         $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
 72:         $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
 73:         $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
 74:         $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
 75:         $objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
 76:         $objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
 77:         $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
 78:         $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
 79:         $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
 80:         $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
 81:         $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
 82:         $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
 83:         $objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
 84:         $objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
 85:         $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
 86:         $objWriter->writeAttribute('office:version', '1.2');
 87: 
 88:         // We firstly search all fonts used
 89:         $_sections = $pPHPWord->getSections();
 90:         $countSections = count($_sections);
 91:         if ($countSections > 0) {
 92:             $pSection = 0;
 93:             $numPStyles = 0;
 94:             $numFStyles = 0;
 95: 
 96:             foreach ($_sections as $section) {
 97:                 $pSection++;
 98:                 $_elements = $section->getElements();
 99: 
100:                 foreach ($_elements as $element) {
101:                     if ($element instanceof PHPWord_Section_Text) {
102:                         $fStyle = $element->getFontStyle();
103:                         $pStyle = $element->getParagraphStyle();
104: 
105:                         if ($fStyle instanceof PHPWord_Style_Font) {
106:                             $numFStyles++;
107: 
108:                             $arrStyle = array(
109:                                 'color' => $fStyle->getColor(),
110:                                 'name' => $fStyle->getName()
111:                             );
112:                             $pPHPWord->addFontStyle('T' . $numFStyles, $arrStyle);
113:                             $element->setFontStyle('T' . $numFStyles);
114:                         } elseif ($pStyle instanceof PHPWord_Style_Paragraph) {
115:                             $numPStyles++;
116: 
117:                             $pPHPWord->addParagraphStyle('P' . $numPStyles, array());
118:                             $element->setParagraph('P' . $numPStyles);
119:                         }
120:                     }
121:                 }
122:             }
123:         }
124: 
125:         // office:font-face-decls
126:         $objWriter->startElement('office:font-face-decls');
127:         $arrFonts = array();
128: 
129:         $styles = PHPWord_Style::getStyles();
130:         $numFonts = 0;
131:         if (count($styles) > 0) {
132:             foreach ($styles as $styleName => $style) {
133:                 // PHPWord_Style_Font
134:                 if ($style instanceof PHPWord_Style_Font) {
135:                     $numFonts++;
136:                     $name = $style->getName();
137:                     if (!in_array($name, $arrFonts)) {
138:                         $arrFonts[] = $name;
139: 
140:                         // style:font-face
141:                         $objWriter->startElement('style:font-face');
142:                         $objWriter->writeAttribute('style:name', $name);
143:                         $objWriter->writeAttribute('svg:font-family', $name);
144:                         $objWriter->endElement();
145:                     }
146:                 }
147:             }
148:             if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) {
149:                 $objWriter->startElement('style:font-face');
150:                 $objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
151:                 $objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
152:                 $objWriter->endElement();
153:             }
154:         }
155:         $objWriter->endElement();
156: 
157:         $objWriter->startElement('office:automatic-styles');
158:         $styles = PHPWord_Style::getStyles();
159:         $numPStyles = 0;
160:         if (count($styles) > 0) {
161:             foreach ($styles as $styleName => $style) {
162:                 if (preg_match('#^T[0-9]+$#', $styleName) != 0
163:                     || preg_match('#^P[0-9]+$#', $styleName) != 0
164:                 ) {
165:                     // PHPWord_Style_Font
166:                     if ($style instanceof PHPWord_Style_Font) {
167:                         $objWriter->startElement('style:style');
168:                         $objWriter->writeAttribute('style:name', $styleName);
169:                         $objWriter->writeAttribute('style:family', 'text');
170:                         // style:text-properties
171:                         $objWriter->startElement('style:text-properties');
172:                         $objWriter->writeAttribute('fo:color', '#' . $style->getColor());
173:                         $objWriter->writeAttribute('style:font-name', $style->getName());
174:                         $objWriter->writeAttribute('style:font-name-complex', $style->getName());
175:                         $objWriter->endElement();
176:                         $objWriter->endElement();
177:                     }
178:                     if ($style instanceof PHPWord_Style_Paragraph) {
179:                         $numPStyles++;
180:                         // style:style
181:                         $objWriter->startElement('style:style');
182:                         $objWriter->writeAttribute('style:name', $styleName);
183:                         $objWriter->writeAttribute('style:family', 'paragraph');
184:                         $objWriter->writeAttribute('style:parent-style-name', 'Standard');
185:                         $objWriter->writeAttribute('style:master-page-name', 'Standard');
186:                         // style:paragraph-properties
187:                         $objWriter->startElement('style:paragraph-properties');
188:                         $objWriter->writeAttribute('style:page-number', 'auto');
189:                         $objWriter->endElement();
190:                         $objWriter->endElement();
191:                     }
192:                 }
193:             }
194: 
195:             if ($numPStyles == 0) {
196:                 // style:style
197:                 $objWriter->startElement('style:style');
198:                 $objWriter->writeAttribute('style:name', 'P1');
199:                 $objWriter->writeAttribute('style:family', 'paragraph');
200:                 $objWriter->writeAttribute('style:parent-style-name', 'Standard');
201:                 $objWriter->writeAttribute('style:master-page-name', 'Standard');
202:                 // style:paragraph-properties
203:                 $objWriter->startElement('style:paragraph-properties');
204:                 $objWriter->writeAttribute('style:page-number', 'auto');
205:                 $objWriter->endElement();
206:                 $objWriter->endElement();
207:             }
208:         }
209:         $objWriter->endElement();
210: 
211:         // office:body
212:         $objWriter->startElement('office:body');
213:         // office:text
214:         $objWriter->startElement('office:text');
215:         // text:sequence-decls
216:         $objWriter->startElement('text:sequence-decls');
217:         // text:sequence-decl
218:         $objWriter->startElement('text:sequence-decl');
219:         $objWriter->writeAttribute('text:display-outline-level', 0);
220:         $objWriter->writeAttribute('text:name', 'Illustration');
221:         $objWriter->endElement();
222:         // text:sequence-decl
223:         $objWriter->startElement('text:sequence-decl');
224:         $objWriter->writeAttribute('text:display-outline-level', 0);
225:         $objWriter->writeAttribute('text:name', 'Table');
226:         $objWriter->endElement();
227:         // text:sequence-decl
228:         $objWriter->startElement('text:sequence-decl');
229:         $objWriter->writeAttribute('text:display-outline-level', 0);
230:         $objWriter->writeAttribute('text:name', 'Text');
231:         $objWriter->endElement();
232:         // text:sequence-decl
233:         $objWriter->startElement('text:sequence-decl');
234:         $objWriter->writeAttribute('text:display-outline-level', 0);
235:         $objWriter->writeAttribute('text:name', 'Drawing');
236:         $objWriter->endElement();
237:         $objWriter->endElement();
238: 
239:         $_sections = $pPHPWord->getSections();
240:         $countSections = count($_sections);
241:         $pSection = 0;
242: 
243:         if ($countSections > 0) {
244:             foreach ($_sections as $section) {
245:                 $pSection++;
246: 
247:                 $_elements = $section->getElements();
248: 
249:                 foreach ($_elements as $element) {
250:                     if ($element instanceof PHPWord_Section_Text) {
251:                         $this->_writeText($objWriter, $element);
252:                     } /* elseif($element instanceof PHPWord_Section_TextRun) {
253:                                     $this->_writeTextRun($objWriter, $element);
254:                                 } elseif($element instanceof PHPWord_Section_Link) {
255:                                     $this->_writeLink($objWriter, $element);
256:                                 } elseif($element instanceof PHPWord_Section_Title) {
257:                                     $this->_writeTitle($objWriter, $element);
258:                                 }*/ elseif ($element instanceof PHPWord_Section_TextBreak) {
259:                         $this->_writeTextBreak($objWriter);
260:                     } /* elseif($element instanceof PHPWord_Section_PageBreak) {
261:                                     $this->_writePageBreak($objWriter);
262:                                 } elseif($element instanceof PHPWord_Section_Table) {
263:                                     $this->_writeTable($objWriter, $element);
264:                                 } elseif($element instanceof PHPWord_Section_ListItem) {
265:                                     $this->_writeListItem($objWriter, $element);
266:                                 } elseif($element instanceof PHPWord_Section_Image ||
267:                                 $element instanceof PHPWord_Section_MemoryImage) {
268:                                     $this->_writeImage($objWriter, $element);
269:                                 } elseif($element instanceof PHPWord_Section_Object) {
270:                                     $this->_writeObject($objWriter, $element);
271:                                 } elseif($element instanceof PHPWord_TOC) {
272:                                     $this->_writeTOC($objWriter);
273:                                 }*/
274:                     else {
275:                         print_r($element);
276:                         echo '<br />';
277:                     }
278:                 }
279: 
280:                 if ($pSection == $countSections) {
281:                     $this->_writeEndSection($objWriter, $section);
282:                 } else {
283:                     $this->_writeSection($objWriter, $section);
284:                 }
285:             }
286:         }
287:         $objWriter->endElement();
288:         $objWriter->endElement();
289:         $objWriter->endElement();
290: 
291:         // Return
292:         return $objWriter->getData();
293:     }
294: 
295:     protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false)
296:     {
297:         $styleFont = $text->getFontStyle();
298:         $styleParagraph = $text->getParagraphStyle();
299: 
300:         $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
301: 
302:         if ($SfIsObject) {
303:             // Don't never be the case, because I browse all sections for cleaning all styles not declared
304:             die('PHPWord : $SfIsObject wouldn\'t be an object');
305:         } else {
306:             // text:p
307:             $objWriter->startElement('text:p');
308:             if (empty($styleFont)) {
309:                 if (empty($styleParagraph)) {
310:                     $objWriter->writeAttribute('text:style-name', 'P1');
311:                 } else {
312:                     $objWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
313:                 }
314:                 $objWriter->writeRaw($text->getText());
315:             } else {
316:                 if (empty($styleParagraph)) {
317:                     $objWriter->writeAttribute('text:style-name', 'Standard');
318:                 } else {
319:                     $objWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
320:                 }
321:                 // text:span
322:                 $objWriter->startElement('text:span');
323:                 $objWriter->writeAttribute('text:style-name', $styleFont);
324:                 $objWriter->writeRaw($text->getText());
325:                 $objWriter->endElement();
326:             }
327:             $objWriter->endElement();
328:         }
329:     }
330: 
331:     protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null)
332:     {
333:         $objWriter->startElement('text:p');
334:         $objWriter->writeAttribute('text:style-name', 'Standard');
335:         $objWriter->endElement();
336:     }
337: 
338:     private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section)
339:     {
340:     }
341: }
342: 
PHPWord API Docs API documentation generated by ApiGen 2.8.0