From 5e1838af47e05b6c2b518f8078dfa80fc61c2c42 Mon Sep 17 00:00:00 2001 From: Guillaume Luchet Date: Thu, 29 Oct 2015 09:21:08 +0100 Subject: [PATCH 01/12] Update composer.json to allow installation using composer require Elma/HTML_Template_IT --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index a9c63dd..3e0a4a1 100644 --- a/composer.json +++ b/composer.json @@ -36,10 +36,10 @@ "./" ], "license": "Modified BSD license", - "name": "pear/html_template_it", + "name": "elma/html_template_it", "support": { "issues": "http://pear.php.net/bugs/search.php?cmd=display&package_name[]=HTML_Template_IT", - "source": "https://github.com/pear/HTML_Template_IT" + "source": "https://github.com/Elma/HTML_Template_IT" }, "type": "library", "require": { @@ -48,4 +48,4 @@ "require-dev": { "phpunit/phpunit": "*" } -} \ No newline at end of file +} From bf75524b08379d22fb46fd97fc22bc8c1ba10bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lernon?= Date: Fri, 17 Mar 2017 14:56:50 +0100 Subject: [PATCH 02/12] no more use the php4 constructor method --- HTML/Template/IT.php | 2 +- HTML/Template/ITX.php | 2 +- HTML/Template/IT_Error.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HTML/Template/IT.php b/HTML/Template/IT.php index 6a151fb..6455033 100644 --- a/HTML/Template/IT.php +++ b/HTML/Template/IT.php @@ -407,7 +407,7 @@ class HTML_Template_IT * @see setRoot() * @access public */ - function HTML_Template_IT($root = '', $options = null) + function __construct($root = '', $options = null) { if (!is_null($options)) { $this->setOptions($options); diff --git a/HTML/Template/ITX.php b/HTML/Template/ITX.php index cdb6dfa..5815d7d 100644 --- a/HTML/Template/ITX.php +++ b/HTML/Template/ITX.php @@ -136,7 +136,7 @@ class HTML_Template_ITX extends HTML_Template_IT * @access public * @see HTML_Template_IT() */ - function HTML_Template_ITX($root = '') + function __construct($root = '') { $this->checkblocknameRegExp = '@' . $this->blocknameRegExp . '@'; diff --git a/HTML/Template/IT_Error.php b/HTML/Template/IT_Error.php index a83213e..b5f4134 100644 --- a/HTML/Template/IT_Error.php +++ b/HTML/Template/IT_Error.php @@ -56,7 +56,7 @@ class IT_Error extends PEAR_Error * @param string $file file where the error occured * @param string $line linenumber where the error occured */ - function IT_Error($msg, $file = __FILE__, $line = __LINE__) + function __construct($msg, $file = __FILE__, $line = __LINE__) { $this->PEAR_Error(sprintf("%s [%s on line %d].", $msg, $file, $line)); } // end func IT_Error From 85a777c030d9ae891fa51ee9c7f716cc2c949be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lernon?= Date: Fri, 17 Mar 2017 15:06:44 +0100 Subject: [PATCH 03/12] dont break the php4 constructor api --- HTML/Template/IT.php | 7 +++++++ HTML/Template/ITX.php | 8 ++++++++ HTML/Template/IT_Error.php | 10 +++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/HTML/Template/IT.php b/HTML/Template/IT.php index 6455033..38e0aea 100644 --- a/HTML/Template/IT.php +++ b/HTML/Template/IT.php @@ -427,6 +427,13 @@ function __construct($root = '', $options = null) $this->setRoot($root); } // end constructor + /** + * Dont break the php4 constructor + */ + function HTML_Template_IT($root = '', $options = null) + { + self::__construct($root, $options); + } /** * Sets the option for the template class diff --git a/HTML/Template/ITX.php b/HTML/Template/ITX.php index 5815d7d..d27278a 100644 --- a/HTML/Template/ITX.php +++ b/HTML/Template/ITX.php @@ -147,6 +147,14 @@ function __construct($root = '') $this->HTML_Template_IT($root); } // end func constructor + /** + * Dont break the php4 constructor + */ + function HTML_Template_ITX($root = '') + { + self::__construct($root); + } + /** * Clears all datafields of the object and rebuild the internal blocklist * diff --git a/HTML/Template/IT_Error.php b/HTML/Template/IT_Error.php index b5f4134..0dc477c 100644 --- a/HTML/Template/IT_Error.php +++ b/HTML/Template/IT_Error.php @@ -60,6 +60,14 @@ function __construct($msg, $file = __FILE__, $line = __LINE__) { $this->PEAR_Error(sprintf("%s [%s on line %d].", $msg, $file, $line)); } // end func IT_Error - + + /** + * Dont break the php4 constructor + */ + function IT_Error($msg, $file = __FILE__, $line = __LINE__) + { + self::__construct($msg, $file, $line); + } + } // end class IT_Error ?> From 3fe61076794540ab806dbb28dbe2d1fe012e98a1 Mon Sep 17 00:00:00 2001 From: Franck LECUVIER Date: Tue, 22 Jan 2019 16:40:18 +0100 Subject: [PATCH 04/12] ref#50469 Replaced preg_replace with /e by preg_replace_callback --- HTML/Template/IT.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/HTML/Template/IT.php b/HTML/Template/IT.php index 38e0aea..85908ed 100644 --- a/HTML/Template/IT.php +++ b/HTML/Template/IT.php @@ -1095,9 +1095,9 @@ function getFile($filename) $content = fread($fh, $fsize); fclose($fh); - return preg_replace( - "##ime", - "\$this->getFile('\\1')", + return preg_replace_callback( + "##im", + create_function('$matches', 'return $this->getFile($matches[1]);'), $content ); } // end func getFile @@ -1190,4 +1190,3 @@ function errorMessage($value, $blockname = '') $errorMessages[$value] : $errorMessages[IT_ERROR]; } } // end class IntegratedTemplate -?> From 192e04a3dd0170cbd5cde54a834e33cb7891b41c Mon Sep 17 00:00:00 2001 From: MatthieuBT <73939884+MatthieuBT@users.noreply.github.com> Date: Wed, 4 Nov 2020 12:19:05 +0100 Subject: [PATCH 05/12] #64906 Rename class to fit PSR-0 --- tests/AllTests.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/AllTests.php b/tests/AllTests.php index 60c53eb..88cdeb2 100644 --- a/tests/AllTests.php +++ b/tests/AllTests.php @@ -1,6 +1,6 @@ From fed90104c98c49a2b2c30ea47a71e4b962c4a1c5 Mon Sep 17 00:00:00 2001 From: Guillaume Luchet Date: Mon, 8 Feb 2021 11:08:56 +0100 Subject: [PATCH 06/12] update tests workflow --- README | 9 +++++---- composer.json | 2 +- phpunit.xml | 10 ++++++++++ tests/ITTest.php | 5 ++--- tests/ITXTest.php | 1 - 5 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 phpunit.xml diff --git a/README b/README index c9d2687..732c4d2 100644 --- a/README +++ b/README @@ -4,10 +4,11 @@ Please report all new issues via the PEAR bug tracker. If this package is marked as unmaintained and you have fixes, please submit your pull requests and start discussion on the pear-qa mailing list. -To test, run either -$ phpunit tests/ - or -$ pear run-tests -r +To test, run + +$ composer install +$ php vendor/bin/phpunit + To build, simply $ pear package diff --git a/composer.json b/composer.json index 3e0a4a1..b51caa3 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,6 @@ "pear/pear_exception": "*" }, "require-dev": { - "phpunit/phpunit": "*" + "phpunit/phpunit": "^4.8" } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..c476c03 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,10 @@ + + + + + + ./tests + + + + diff --git a/tests/ITTest.php b/tests/ITTest.php index 309e116..c4063a4 100644 --- a/tests/ITTest.php +++ b/tests/ITTest.php @@ -1,6 +1,5 @@ tpl->loadTemplateFile('placeholderreplacementscope.html', true, true); - + if (PEAR::isError($result)) { $this->fail('Error loading template file: ' . $result->getMessage()); } diff --git a/tests/ITXTest.php b/tests/ITXTest.php index 2521aee..39ac6a3 100644 --- a/tests/ITXTest.php +++ b/tests/ITXTest.php @@ -1,6 +1,5 @@ Date: Mon, 8 Feb 2021 11:09:21 +0100 Subject: [PATCH 07/12] Fix usage of $this in non static context --- HTML/Template/IT.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/HTML/Template/IT.php b/HTML/Template/IT.php index 85908ed..532f7b3 100644 --- a/HTML/Template/IT.php +++ b/HTML/Template/IT.php @@ -1095,9 +1095,13 @@ function getFile($filename) $content = fread($fh, $fsize); fclose($fh); + $callback = function($matches) { + return $this->getFile($matches[1]); + }; + return preg_replace_callback( "##im", - create_function('$matches', 'return $this->getFile($matches[1]);'), + $callback, $content ); } // end func getFile From 06eec3540127f4244d1ecb042ea8200ed49e4c9e Mon Sep 17 00:00:00 2001 From: Guillaume Luchet Date: Fri, 10 Dec 2021 10:49:02 +0100 Subject: [PATCH 08/12] fix some deprecated array and string offset access with curly braces --- HTML/Template/IT.php | 2 +- HTML/Template/ITX.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HTML/Template/IT.php b/HTML/Template/IT.php index 532f7b3..2736b29 100644 --- a/HTML/Template/IT.php +++ b/HTML/Template/IT.php @@ -1072,7 +1072,7 @@ function findBlocks($string) */ function getFile($filename) { - if ($filename{0} == '/' && substr($this->fileRoot, -1) == '/') { + if ($filename[0] == '/' && substr($this->fileRoot, -1) == '/') { $filename = substr($filename, 1); } diff --git a/HTML/Template/ITX.php b/HTML/Template/ITX.php index d27278a..79bbaff 100644 --- a/HTML/Template/ITX.php +++ b/HTML/Template/ITX.php @@ -704,7 +704,7 @@ function buildFunctionlist() while ($head != '' && $args2 = $this->getValue($head, ',')) { $arg2 = trim($args2); - $args[] = ('"' == $arg2{0} || "'" == $arg2{0}) ? + $args[] = ('"' == $arg2[0] || "'" == $arg2[0]) ? substr($arg2, 1, -1) : $arg2; if ($arg2 == $head) { From 5cb18a8cbcfa1528d7c61ef2e6cdbc78b4c67bff Mon Sep 17 00:00:00 2001 From: Guillaume Luchet Date: Fri, 10 Dec 2021 13:59:52 +0100 Subject: [PATCH 09/12] add check_placeholder_exists option to not check if a placeholder exists and add a setGlobalOptions method --- HTML/Template/IT.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/HTML/Template/IT.php b/HTML/Template/IT.php index 2736b29..2a4ca70 100644 --- a/HTML/Template/IT.php +++ b/HTML/Template/IT.php @@ -390,9 +390,12 @@ class HTML_Template_IT var $_options = array( 'preserve_data' => false, 'use_preg' => true, - 'preserve_input'=> true + 'preserve_input'=> true, + 'check_placeholder_exists' => true, ); + public static $globalOptions = []; + /** * Builds some complex regular expressions and optinally sets the * file root directory. @@ -409,6 +412,9 @@ class HTML_Template_IT */ function __construct($root = '', $options = null) { + if (!empty(self::$globalOptions)) { + $this->setOptions(self::$globalOptions); + } if (!is_null($options)) { $this->setOptions($options); } @@ -489,6 +495,16 @@ function setOptions($options) return IT_OK; } + /** + * Define global options used for all new instances. + * options defined using constructor parameter will overwrite + * globalOptions + */ + public static function setGlobalOptions($options) + { + self::$globalOptions = $options; + } + /** * Print a certain block with all replacements done. * @@ -774,7 +790,7 @@ function setVariable($variable, $value = '') $this->setVariable($key, $value); } } else { - if ($this->checkPlaceholderExists($this->currentBlock, $variable)) { + if (!$this->_options['check_placeholder_exists'] || $this->checkPlaceholderExists($this->currentBlock, $variable)) { $this->variableCache[$variable] = $value; } } From f817accb7cf0f4fc2552e7455cfb7b3927baf2ff Mon Sep 17 00:00:00 2001 From: Guillaume Luchet Date: Mon, 11 Apr 2022 13:57:13 +0200 Subject: [PATCH 10/12] update phpunit --- composer.json | 2 +- tests/ITTest.php | 8 +++++--- tests/ITXTest.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index b51caa3..dcdfeea 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,6 @@ "pear/pear_exception": "*" }, "require-dev": { - "phpunit/phpunit": "^4.8" + "phpunit/phpunit": "^9.4" } } diff --git a/tests/ITTest.php b/tests/ITTest.php index c4063a4..3c471ae 100644 --- a/tests/ITTest.php +++ b/tests/ITTest.php @@ -1,7 +1,9 @@ tpl = new HTML_Template_IT(dirname(__FILE__) . '/templates'); } - function tearDown() + function tearDown(): void { unset($this->tpl); } diff --git a/tests/ITXTest.php b/tests/ITXTest.php index 39ac6a3..feb4a50 100644 --- a/tests/ITXTest.php +++ b/tests/ITXTest.php @@ -23,7 +23,7 @@ function _numberFormatCallback($float, $decimals) class ITXTest extends ITTest { - function setUp() + function setUp(): void { $this->tpl = new HTML_Template_ITX(dirname(__FILE__) . '/templates'); } From ad7b4f7258b0758cd9152a19be2d97b3a814e415 Mon Sep 17 00:00:00 2001 From: Guillaume Luchet Date: Mon, 11 Apr 2022 14:50:44 +0200 Subject: [PATCH 11/12] replace each and update signature of static method for php8 compatibility --- HTML/Template/ITX.php | 14 +++++++------- tests/ITXTest.php | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/HTML/Template/ITX.php b/HTML/Template/ITX.php index 79bbaff..eb9b455 100644 --- a/HTML/Template/ITX.php +++ b/HTML/Template/ITX.php @@ -319,7 +319,7 @@ function addBlock($placeholder, $blockname, $template) } elseif (count($parents) > 1) { reset($parents); - while (list($k, $parent) = each($parents)) { + foreach ($parents as $k => $parent) { $msg .= "$parent, "; } $msg = substr($parent, -2); @@ -405,7 +405,7 @@ function placeholderExists($placeholder, $block = '') if (is_array($variables = $this->blockvariables[$block])) { // search the value in the list of blockvariables reset($variables); - while (list($k, $variable) = each($variables)) { + foreach ($variables as $k => $variable) { if ($k == $placeholder) { $found = $block; break; @@ -417,7 +417,7 @@ function placeholderExists($placeholder, $block = '') // search all blocks and return the name of the first block that // contains the placeholder reset($this->blockvariables); - while (list($blockname, $variables) = each($this->blockvariables)) { + foreach ($this->blockvariables as $blockname => $variables) { if (is_array($variables) && isset($variables[$placeholder])) { $found = $blockname; break; @@ -438,7 +438,7 @@ function placeholderExists($placeholder, $block = '') function performCallback() { reset($this->functions); - while (list($func_id, $function) = each($this->functions)) { + foreach ($this->functions as $func_id => $function) { if (isset($this->callback[$function['name']])) { if ($this->callback[$function['name']]['expandParameters']) { $callFunction = 'call_user_func_array'; @@ -790,7 +790,7 @@ function deleteFromBlockvariablelist($block, $variables) } reset($this->blockvariables[$block]); - while (list($varname, $val) = each($this->blockvariables[$block])) { + foreach ($this->blockvariables[$block] as $varname => $val) { if (isset($variables[$varname])) { unset($this->blockvariables[$block][$varname]); } @@ -848,10 +848,10 @@ function findPlaceholderBlocks($variable) { $parents = array(); reset($this->blocklist); - while (list($blockname, $content) = each($this->blocklist)) { + foreach ($this->blocklist as $blockname => $content) { reset($this->blockvariables[$blockname]); - while (list($varname, $val) = each($this->blockvariables[$blockname])) { + foreach ($this->blockvariables[$blockname] as $varname => $val) { if ($variable == $varname) { $parents[] = $blockname; } diff --git a/tests/ITXTest.php b/tests/ITXTest.php index feb4a50..e2f72de 100644 --- a/tests/ITXTest.php +++ b/tests/ITXTest.php @@ -10,12 +10,12 @@ function _uppercaseCallback($ary) class Callbacks { - function _lowercaseCallback($ary) + public static function _lowercaseCallback($ary) { return strtolower($ary[0]); } - function _numberFormatCallback($float, $decimals) + public static function _numberFormatCallback($float, $decimals) { return number_format($float, $decimals); } From bbfaaac0362f6e04e7b81f4e9aef56f1f4347c3d Mon Sep 17 00:00:00 2001 From: Guillaume Luchet Date: Mon, 11 Apr 2022 14:52:43 +0200 Subject: [PATCH 12/12] update branch alias --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index b51caa3..474716f 100644 --- a/composer.json +++ b/composer.json @@ -47,5 +47,10 @@ }, "require-dev": { "phpunit/phpunit": "^4.8" + }, + "extra": { + "branch-alias": { + "dev-v1.4.0-rc": "1.4.x-dev" + } } }