|
| 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-2016 PHPWord contributors |
| 15 | + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 16 | + */ |
| 17 | + |
| 18 | +namespace PhpOffice\PhpWord\Reader\Word2007; |
| 19 | + |
| 20 | +use PhpOffice\Common\XMLReader; |
| 21 | +use PhpOffice\PhpWord\PhpWord; |
| 22 | +use PhpOffice\PhpWord\Metadata\Protection; |
| 23 | + |
| 24 | +/** |
| 25 | + * Settings reader |
| 26 | + * |
| 27 | + * @since 0.14.0 |
| 28 | + */ |
| 29 | +class Settings extends AbstractPart |
| 30 | +{ |
| 31 | + |
| 32 | + private static $booleanProperties = array('hideSpellingErrors', 'hideGrammaticalErrors', 'evenAndOddHeaders'); |
| 33 | + private static $decimalProperties = array('zoom'); |
| 34 | + |
| 35 | + /** |
| 36 | + * Read settings.xml. |
| 37 | + * |
| 38 | + * @param \PhpOffice\PhpWord\PhpWord $phpWord |
| 39 | + * @return void |
| 40 | + */ |
| 41 | + public function read(PhpWord $phpWord) |
| 42 | + { |
| 43 | + $xmlReader = new XMLReader(); |
| 44 | + $xmlReader->getDomFromZip($this->docFile, $this->xmlFile); |
| 45 | + |
| 46 | + $docSettings = $phpWord->getSettings(); |
| 47 | + |
| 48 | + $nodes = $xmlReader->getElements('*'); |
| 49 | + if ($nodes->length > 0) { |
| 50 | + foreach ($nodes as $node) { |
| 51 | + $name = str_replace('w:', '', $node->nodeName); |
| 52 | + $value = $xmlReader->getAttribute('w:val', $node); |
| 53 | + $method = 'set' . $name; |
| 54 | + |
| 55 | + if (in_array($name, $this::$booleanProperties)) { |
| 56 | + if ($value == 'false') { |
| 57 | + $docSettings->$method(false); |
| 58 | + } else { |
| 59 | + $docSettings->$method(true); |
| 60 | + } |
| 61 | + } else if (method_exists($this, $method)) { |
| 62 | + $this->$method($xmlReader, $phpWord, $node); |
| 63 | + } else if (method_exists($this, $method)) { |
| 64 | + $docSettings->$method($value); |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + private function setDocumentProtection(XMLReader $xmlReader, PhpWord $phpWord, \DOMNode $node) { |
| 71 | + $documentProtection = $phpWord->getSettings()->getDocumentProtection(); |
| 72 | + |
| 73 | + $edit = $xmlReader->getAttribute('w:edit', $node); |
| 74 | + $documentProtection->setEditing($edit); |
| 75 | + } |
| 76 | +} |
0 commit comments