1<?php
2
3/**
4 * PHPExcel_Writer_OpenDocument_Styles
5 *
6 * Copyright (c) 2006 - 2015 PHPExcel
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 *
22 * @category   PHPExcel
23 * @package    PHPExcel_Writer_OpenDocument
24 * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
26 * @version    ##VERSION##, ##DATE##
27 */
28class PHPExcel_Writer_OpenDocument_Styles extends PHPExcel_Writer_OpenDocument_WriterPart
29{
30    /**
31     * Write styles.xml to XML format
32     *
33     * @param   PHPExcel                   $pPHPExcel
34     * @return  string                     XML Output
35     * @throws  PHPExcel_Writer_Exception
36     */
37    public function write(PHPExcel $pPHPExcel = null)
38    {
39        if (!$pPHPExcel) {
40            $pPHPExcel = $this->getParentWriter()->getPHPExcel();
41        }
42
43        $objWriter = null;
44        if ($this->getParentWriter()->getUseDiskCaching()) {
45            $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
46        } else {
47            $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
48        }
49
50        // XML header
51        $objWriter->startDocument('1.0', 'UTF-8');
52
53        // Content
54        $objWriter->startElement('office:document-styles');
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:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0');
66            $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
67            $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
68            $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
69            $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
70            $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
71            $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
72            $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
73            $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
74            $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
75            $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
76            $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
77            $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
78            $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
79            $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
80            $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
81            $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
82            $objWriter->writeAttribute('office:version', '1.2');
83
84            $objWriter->writeElement('office:font-face-decls');
85            $objWriter->writeElement('office:styles');
86            $objWriter->writeElement('office:automatic-styles');
87            $objWriter->writeElement('office:master-styles');
88        $objWriter->endElement();
89
90        return $objWriter->getData();
91    }
92}
93