1<?php
2
3/**
4 * PHPExcel_Writer_OpenDocument_Settings
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_Settings extends PHPExcel_Writer_OpenDocument_WriterPart
29{
30    /**
31     * Write settings.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        // Settings
54        $objWriter->startElement('office:document-settings');
55            $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
56            $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
57            $objWriter->writeAttribute('xmlns:config', 'urn:oasis:names:tc:opendocument:xmlns:config:1.0');
58            $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
59            $objWriter->writeAttribute('office:version', '1.2');
60
61            $objWriter->startElement('office:settings');
62                $objWriter->startElement('config:config-item-set');
63                    $objWriter->writeAttribute('config:name', 'ooo:view-settings');
64                    $objWriter->startElement('config:config-item-map-indexed');
65                        $objWriter->writeAttribute('config:name', 'Views');
66                    $objWriter->endElement();
67                $objWriter->endElement();
68                $objWriter->startElement('config:config-item-set');
69                    $objWriter->writeAttribute('config:name', 'ooo:configuration-settings');
70                $objWriter->endElement();
71            $objWriter->endElement();
72        $objWriter->endElement();
73
74        return $objWriter->getData();
75    }
76}
77