diff --git a/CHANGELOG.md b/CHANGELOG.md index ae41bd4d..8c2c73ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ v0.16.0 (xx dec 2018) - RTF writer: Round getPageSizeW and getPageSizeH to avoid decimals @Patrick64 #1493 - Fix parsing of Office 365 documents @Timanx #1485 +### Miscelaneous +- Get rid of duplicated code in TemplateProcessor @abcdmitry #1161 + v0.15.0 (14 Jul 2018) ---------------------- ### Added diff --git a/docs/containers.rst b/docs/containers.rst index dc194d59..34b2a9a3 100644 --- a/docs/containers.rst +++ b/docs/containers.rst @@ -104,6 +104,12 @@ You can pass an optional parameter to specify where the header/footer should be - ``Footer::FIRST`` each first page of the section - ``Footer::EVEN`` each even page of the section. Will only be applied if the evenAndOddHeaders is set to true in phpWord->settings +To change the evenAndOddHeaders use the ``getSettings`` method to return the Settings object, and then call the ``setEvenAndOddHeaders`` method: + +.. code-block:: php + $phpWord->getSettings()->setEvenAndOddHeaders(true); + + Footers ------- diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index 4ec9e2cc..599ca0cf 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -244,10 +244,10 @@ class TemplateProcessor { if (is_array($search)) { foreach ($search as &$item) { - $item = self::ensureMacroCompleted($item); + $item = static::ensureMacroCompleted($item); } } else { - $search = self::ensureMacroCompleted($search); + $search = static::ensureMacroCompleted($search); } if (is_array($replace)) { @@ -521,7 +521,7 @@ class TemplateProcessor $xmlImage = str_replace(array('{RID}', '{WIDTH}', '{HEIGHT}'), array($rid, $preparedImageAttrs['width'], $preparedImageAttrs['height']), $imgTpl); // replace variable - $varNameWithArgsFixed = self::ensureMacroCompleted($varNameWithArgs); + $varNameWithArgsFixed = static::ensureMacroCompleted($varNameWithArgs); $matches = array(); if (preg_match('/(<[^<]+>)([^<]*)(' . preg_quote($varNameWithArgsFixed) . ')([^>]*)(<[^>]+>)/Uu', $partContent, $matches)) { $wholeTag = $matches[0]; @@ -582,9 +582,7 @@ class TemplateProcessor */ public function cloneRow($search, $numberOfClones) { - if ('${' !== substr($search, 0, 2) && '}' !== substr($search, -1)) { - $search = '${' . $search . '}'; - } + $search = static::ensureMacroCompleted($search); $tagPos = strpos($this->tempDocumentMainPart, $search); if (!$tagPos) {