Compare commits

..

No commits in common. "master" and "upstream/1.3.0" have entirely different histories.

32 changed files with 2978 additions and 3096 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,65 +1,65 @@
<?php <?php
/** /**
* Integrated Template - IT * Integrated Template - IT
* *
* PHP version 4 * PHP version 4
* *
* Copyright (c) 1997-2007 Ulf Wendel, Pierre-Alain Joye, * Copyright (c) 1997-2007 Ulf Wendel, Pierre-Alain Joye,
* David Soria Parra * David Soria Parra
* *
* This source file is subject to the New BSD license, That is bundled * This source file is subject to the New BSD license, That is bundled
* with this package in the file LICENSE, and is available through * with this package in the file LICENSE, and is available through
* the world-wide-web at * the world-wide-web at
* http://www.opensource.org/licenses/bsd-license.php * http://www.opensource.org/licenses/bsd-license.php
* If you did not receive a copy of the new BSD license and are unable * If you did not receive a copy of the new BSDlicense and are unable
* to obtain it through the world-wide-web, please send a note to * to obtain it through the world-wide-web, please send a note to
* pajoye@php.net so we can mail you a copy immediately. * pajoye@php.net so we can mail you a copy immediately.
* *
* Author: Ulf Wendel <ulf.wendel@phpdoc.de> * Author: Ulf Wendel <ulf.wendel@phpdoc.de>
* Pierre-Alain Joye <pajoye@php.net> * Pierre-Alain Joye <pajoye@php.net>
* David Soria Parra <dsp@php.net> * David Soria Parra <dsp@php.net>
* *
* @category HTML * @category HTML
* @package HTML_Template_IT * @package HTML_Template_IT
* @author Ulf Wendel <uw@netuse.de> * @author Ulf Wendel <uw@netuse.de>
* @license BSD http://www.opensource.org/licenses/bsd-license.php * @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id$ * @version CVS: $Id: IT_Error.php 295117 2010-02-15 23:25:21Z clockwerx $
* @link http://pear.php.net/packages/HTML_Template_IT * @link http://pear.php.net/packages/HTML_Template_IT
* @access public * @access public
*/ */
require_once "PEAR.php"; require_once "PEAR.php";
/** /**
* IT[X] Error class * IT[X] Error class
* *
* @category HTML * @category HTML
* @package HTML_Template_IT * @package HTML_Template_IT
* @author Ulf Wendel <uw@netuse.de> * @author Ulf Wendel <uw@netuse.de>
* @license BSD http://www.opensource.org/licenses/bsd-license.php * @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/packages/HTML_Template_IT * @link http://pear.php.net/packages/HTML_Template_IT
* @access public * @access public
*/ */
class IT_Error extends PEAR_Error class IT_Error extends PEAR_Error
{ {
/** /**
* Prefix of all error messages. * Prefix of all error messages.
* *
* @var string * @var string
*/ */
var $error_message_prefix = "IntegratedTemplate Error: "; var $error_message_prefix = "IntegratedTemplate Error: ";
/** /**
* Creates an cache error object. * Creates an cache error object.
* *
* @param string $msg error message * @param string $msg error message
* @param string $file file where the error occurred * @param string $file file where the error occured
* @param string $line linenumber where the error occurred * @param string $line linenumber where the error occured
*/ */
function __construct($msg, $file = __FILE__, $line = __LINE__) function IT_Error($msg, $file = __FILE__, $line = __LINE__)
{ {
$this->PEAR_Error(sprintf("%s [%s on line %d].", $msg, $file, $line)); $this->PEAR_Error(sprintf("%s [%s on line %d].", $msg, $file, $line));
} // end func IT_Error } // end func IT_Error
} // end class IT_Error } // end class IT_Error
?> ?>

View File

@ -1,22 +1,22 @@
Redistribution and use in source and binary forms, with or without modification Redistribution and use in source and binary forms, with or without modification
, are permitted provided that the following conditions are met: , are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, th 1. Redistributions of source code must retain the above copyright notice, th
is list of conditions and the following disclaimer. is list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, 2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/ this list of conditions and the following disclaimer in the documentation and/
or other materials provided with the distribution. or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products derived 3. The name of the author may not be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WA THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WA
RRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABIL RRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABIL
ITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR C AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR C
ONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOW GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOW
EVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILI EVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILI
TY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE U TY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE U
SE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,27 +1,27 @@
<?php <?php
require_once 'HTML/Template/IT.php'; require_once 'HTML/Template/IT.php';
$data = array ( $data = array (
'0' => array('Stig', 'Bakken'), '0' => array('Stig', 'Bakken'),
'1' => array('Martin', 'Jansen'), '1' => array('Martin', 'Jansen'),
'2' => array('Alexander', 'Merz') '2' => array('Alexander', 'Merz')
); );
$tpl = new HTML_Template_IT('./templates'); $tpl = new HTML_Template_IT('./templates');
$tpl->loadTemplatefile('main.tpl.htm', true, true); $tpl->loadTemplatefile('main.tpl.htm', true, true);
foreach ($data as $name) { foreach ($data as $name) {
foreach ($name as $cell) { foreach ($name as $cell) {
// Assign data to the inner block // Assign data to the inner block
$tpl->setCurrentBlock('cell'); $tpl->setCurrentBlock('cell');
$tpl->setVariable('DATA', $cell); $tpl->setVariable('DATA', $cell);
$tpl->parseCurrentBlock(); $tpl->parseCurrentBlock();
} }
// Assign data and the inner block to the // Assign data and the inner block to the
// outer block // outer block
$tpl->setCurrentBlock('row'); $tpl->setCurrentBlock('row');
$tpl->parseCurrentBlock(); $tpl->parseCurrentBlock();
} }
// print the output // print the output
$tpl->show(); $tpl->show();
?> ?>

View File

@ -1,62 +1,58 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/** /**
* An example for the usage of ITX::addBlockfile * An example for the usage of ITX::addBlockfile
* *
* @version CVS: $Id$ * @version CVS: $Id: sample_itx_addblockfile.php 216180 2006-07-11 21:56:05Z dsp $
*/ */
// Show all errors and warnings require_once 'HTML/Template/ITX.php';
error_reporting(E_ALL);
ini_set('display_errors', 1); $data = array (array ('packagename'=>'mypackage',
'version' =>'1.0',
require_once 'HTML/Template/ITX.php'; 'changelog' => array ('fix bug #002',
'add author FOO to AUTHORS')
$data = array (array ('packagename'=>'mypackage', ),
'version' =>'1.0', array ('packagename'=>'mypackage',
'changelog' => array ('fix bug #002', 'version' =>'1.0 RC 1',
'add author FOO to AUTHORS') 'changelog' => array ('fix bug #002',
), 'added method foo()')
array ('packagename'=>'mypackage', )
'version' =>'1.0 RC 1', );
'changelog' => array ('fix bug #002',
'added method foo()') $tpl = new HTML_Template_ITX('./templates');
) $tpl->loadTemplatefile('addblockfile_main.tpl.htm', true, true);
);
// The complete content of "addblockfile_main.tpl.htm" will be loaded into a block
$tpl = new HTML_Template_ITX('./templates'); // called "list_template". The placeholder {DESCRIPTION} will be replaced
$tpl->loadTemplatefile('addblockfile_main.tpl.htm', true, true); // with the added block "list_template".
$tpl->addBlockfile('DESCRIPTION', 'list_template', 'addblockfile_list.tpl.htm');
// The complete content of "addblockfile_main.tpl.htm" will be loaded into a block
// called "list_template". The placeholder {DESCRIPTION} will be replaced
// with the added block "list_template". // we now have the following blocks loaded:
$tpl->addBlockfile('DESCRIPTION', 'list_template', 'addblockfile_list.tpl.htm'); // __global__, row, list_template and listelement
// lets assign the data.
foreach ($data as $entry) {
// we now have the following blocks loaded: // assign data to the inner block (listelement) of list_template.
// __global__, row, list_template and listelement $tpl->setCurrentBlock('listelement');
// lets assign the data. foreach ($entry['changelog'] as $changelogentry) {
foreach ($data as $entry) { $tpl->setVariable('ENTRY', $changelogentry);
// assign data to the inner block (listelement) of list_template. $tpl->parseCurrentBlock();
$tpl->setCurrentBlock('listelement'); }
foreach ($entry['changelog'] as $changelogentry) {
$tpl->setVariable('ENTRY', $changelogentry); // assign data to the added list_template block
$tpl->parseCurrentBlock(); $tpl->setCurrentBlock('list_template');
} $tpl->setVariable('LISTNAME', $entry['version']);
$tpl->parseCurrentBlock();
// assign data to the added list_template block
$tpl->setCurrentBlock('list_template'); // back in the original templatefile we assign data to the row block
$tpl->setVariable('LISTNAME', $entry['version']); // notice:
$tpl->parseCurrentBlock(); // {DESCRIPTION} is not longer available, because it was replaced by the
// list_template block
// back in the original templatefile we assign data to the row block $tpl->setCurrentBlock('row');
// notice: $tpl->setVariable('NAME', $entry['packagename']);
// {DESCRIPTION} is not longer available, because it was replaced by the $tpl->parseCurrentBlock();
// list_template block }
$tpl->setCurrentBlock('row');
$tpl->setVariable('NAME', $entry['packagename']); $tpl->show();
$tpl->parseCurrentBlock(); ?>
}
$tpl->show();
?>

View File

@ -1,6 +1,6 @@
{LISTNAME} {LISTNAME}
<ul> <ul>
<!-- BEGIN listelement --> <!-- BEGIN listelement -->
<li>{ENTRY}</li> <li>{ENTRY}</li>
<!-- END listelement --> <!-- END listelement -->
</ul> </ul>

View File

@ -1,12 +1,12 @@
<html> <html>
<body> <body>
<table> <table>
<!-- BEGIN row --> <!-- BEGIN row -->
<tr> <tr>
<td>{NAME}</td> <td>{NAME}</td>
<td>{DESCRIPTION}</td> <td>{DESCRIPTION}</td>
</tr> </tr>
<!-- END row --> <!-- END row -->
</table> </table>
</body> </body>
</html> </html>

View File

@ -1,13 +1,13 @@
<html> <html>
<table border> <table border>
<!-- BEGIN row --> <!-- BEGIN row -->
<tr> <tr>
<!-- BEGIN cell --> <!-- BEGIN cell -->
<td> <td>
{DATA} {DATA}
</td> </td>
<!-- END cell --> <!-- END cell -->
</tr> </tr>
<!-- END row --> <!-- END row -->
</table> </table>
</html> </html>

View File

@ -0,0 +1,36 @@
<?php
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'HTML_Template_IT_AllTests::main');
}
require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'PHPUnit/Framework/TestSuite.php';
require_once 'ITTest.php';
require_once 'ITXTest.php';
class HTML_Template_IT_AllTests
{
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('HTML_Template_IT tests');
$suite->addTestSuite('ITTest');
$suite->addTestSuite('ITXTest');
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'HTML_Template_IT_AllTests::main') {
HTML_Template_IT_AllTests::main();
}
?>

View File

@ -1,373 +1,416 @@
<?php <?php
require_once 'HTML/Template/IT.php';
// As we want to run on PHP < 7.1, require_once 'PHPUnit/Framework/TestCase.php';
// we can't use return type declaration in fixtures.
// Therefore we use PHPUnitPolyFills snakecase fixtures set_up/tear_down class ITTest extends PHPUnit_Framework_TestCase
// instead of setUp/tearDown. {
// See https://github.com/Yoast/PHPUnit-Polyfills?tab=readme-ov-file#option-1-yoastphpunitpolyfillstestcasestestcase /**
use Yoast\PHPUnitPolyfills\TestCases\TestCase; * An HTML_Template_IT object
* @var object
require_once 'HTML/Template/IT.php'; */
var $tpl;
class ITTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{ function setUp()
/** {
* An HTML_Template_IT object $this->tpl = new HTML_Template_IT(dirname(__FILE__) . '/templates');
* @var object }
*/
var $tpl; function tearDown()
{
protected function set_up() unset($this->tpl);
{ }
$this->tpl = new HTML_Template_IT(dirname(__FILE__) . '/templates');
} function _stripWhitespace($str)
{
protected function tear_down() return preg_replace('/\\s+/', '', $str);
{ }
unset($this->tpl);
} function _methodExists($name)
{
function _stripWhitespace($str) if (in_array(strtolower($name), get_class_methods($this->tpl))) {
{ return true;
return preg_replace('/\\s+/', '', $str); }
} $this->assertTrue(false, 'method '. $name . ' not implemented in ' . get_class($this->tpl));
return false;
function _methodExists($name) }
{
if (in_array(strtolower($name), get_class_methods($this->tpl))) { /**
return true; * Tests a setTemplate method
} *
$this->assertTrue(false, 'method '. $name . ' not implemented in ' . get_class($this->tpl)); */
return false; function testSetTemplate()
} {
$result = $this->tpl->setTemplate('A template', false, false);
/** if (PEAR::isError($result)) {
* Tests a setTemplate method $this->assertTrue(false, 'Error setting template: '. $result->getMessage());
* }
*/ $this->assertEquals('A template', $this->tpl->get());
function testSetTemplate() }
{
$result = $this->tpl->setTemplate('A template', false, false); /**
if (PEAR::isError($result)) { * Tests a loadTemplatefile method
$this->assertTrue(false, 'Error setting template: '. $result->getMessage()); *
} */
$this->assertEquals('A template', $this->tpl->get()); function testLoadTemplatefile()
} {
$result = $this->tpl->loadTemplatefile('loadtemplatefile.html', false, false);
/** if (PEAR::isError($result)) {
* Tests a loadTemplatefile method $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
* }
*/ $this->assertEquals('A template', trim($this->tpl->get()));
function testLoadTemplatefile() }
{
$result = $this->tpl->loadTemplatefile('loadtemplatefile.html', false, false); /**
if (PEAR::isError($result)) { * Tests a setVariable method
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage()); *
} */
$this->assertEquals('A template', trim($this->tpl->get())); function testSetVariable()
} {
$result = $this->tpl->setTemplate('{placeholder1} {placeholder2} {placeholder3}', true, true);
/** if (PEAR::isError($result)) {
* Tests a setVariable method $this->assertTrue(false, 'Error setting template: '. $result->getMessage());
* }
*/ // "scalar" call
function testSetVariable() $this->tpl->setVariable('placeholder1', 'var1');
{ // array call
$result = $this->tpl->setTemplate('{placeholder1} {placeholder2} {placeholder3}', true, true); $this->tpl->setVariable(array(
if (PEAR::isError($result)) { 'placeholder2' => 'var2',
$this->assertTrue(false, 'Error setting template: '. $result->getMessage()); 'placeholder3' => 'var3'
} ));
// "scalar" call $this->assertEquals('var1 var2 var3', $this->tpl->get());
$this->tpl->setVariable('placeholder1', 'var1'); }
// array call
$this->tpl->setVariable(array( /**
'placeholder2' => 'var2', * Tests the <!-- INCLUDE --> functionality
'placeholder3' => 'var3' *
)); */
$this->assertEquals('var1 var2 var3', $this->tpl->get()); function testInclude()
} {
$result = $this->tpl->loadTemplateFile('include.html', false, false);
/** if (PEAR::isError($result)) {
* Tests the <!-- INCLUDE --> functionality $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
* }
*/ $this->assertEquals('Master file; Included file', trim($this->tpl->get()));
function testInclude() }
{
$result = $this->tpl->loadTemplateFile('include.html', false, false); /**
if (PEAR::isError($result)) { *
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage()); */
} function testCurrentBlock()
$this->assertEquals('Master file; Included file', trim($this->tpl->get())); {
} $result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
if (PEAR::isError($result)) {
/** $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
* }
*/ $this->tpl->setVariable('outer', 'a');
function testCurrentBlock() $this->tpl->setCurrentBlock('inner_block');
{ for ($i = 0; $i < 5; $i++) {
$result = $this->tpl->loadTemplateFile('blockiteration.html', true, true); $this->tpl->setVariable('inner', $i + 1);
if (PEAR::isError($result)) { $this->tpl->parseCurrentBlock();
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage()); } // for
} $this->assertEquals('a|1|2|3|4|5#', $this->_stripWhitespace($this->tpl->get()));
$this->tpl->setVariable('outer', 'a'); }
$this->tpl->setCurrentBlock('inner_block');
for ($i = 0; $i < 5; $i++) { /**
$this->tpl->setVariable('inner', $i + 1); *
$this->tpl->parseCurrentBlock(); */
} // for function testRemovePlaceholders()
$this->assertEquals('a|1|2|3|4|5#', $this->_stripWhitespace($this->tpl->get())); {
} $result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true);
if (PEAR::isError($result)) {
/** $this->assertTrue(false, 'Error setting template: '. $result->getMessage());
* }
*/ // we do not set {placeholder3}
function testRemovePlaceholders() $this->tpl->setVariable(array(
{ 'placeholder1' => 'var1',
$result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true); 'placeholder2' => 'var2'
if (PEAR::isError($result)) { ));
$this->assertTrue(false, 'Error setting template: '. $result->getMessage()); $this->assertEquals('var1,var2,', $this->tpl->get());
}
// we do not set {placeholder3} // Now, we should really add a switch for keeping {stuff} in
$this->tpl->setVariable(array( // data supplied to setVariable() safe. Until then, removing it should
'placeholder1' => 'var1', // be expected behaviour
'placeholder2' => 'var2' $result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true);
)); $this->tpl->setOption('preserve_input', false);
$this->assertEquals('var1,var2,', $this->tpl->get()); if (PEAR::isError($result)) {
$this->assertTrue(false, 'Error setting template: '. $result->getMessage());
// Now, we should really add a switch for keeping {stuff} in }
// data supplied to setVariable() safe. Until then, removing it should $this->tpl->setVariable(array(
// be expected behaviour 'placeholder1' => 'var1',
$result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true); 'placeholder2' => 'var2',
$this->tpl->setOption('preserve_input', false); 'placeholder3' => 'var3{stuff}'
if (PEAR::isError($result)) { ));
$this->assertTrue(false, 'Error setting template: '. $result->getMessage()); $this->assertEquals('var1,var2,var3', $this->tpl->get());
}
$this->tpl->setVariable(array( $result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true);
'placeholder1' => 'var1', $this->tpl->setOption('preserve_input', true);
'placeholder2' => 'var2', if (PEAR::isError($result)) {
'placeholder3' => 'var3{stuff}' $this->assertTrue(false, 'Error setting template: '. $result->getMessage());
)); }
$this->assertEquals('var1,var2,var3', $this->tpl->get()); $this->tpl->setVariable(array(
'placeholder1' => 'var1',
$result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true); 'placeholder2' => 'var2',
$this->tpl->setOption('preserve_input', true); 'placeholder3' => 'var3{stuff}'
if (PEAR::isError($result)) { ));
$this->assertTrue(false, 'Error setting template: '. $result->getMessage()); $this->assertEquals('var1,var2,var3{stuff}', $this->tpl->get());
}
$this->tpl->setVariable(array( }
'placeholder1' => 'var1',
'placeholder2' => 'var2', /**
'placeholder3' => 'var3{stuff}' *
)); */
$this->assertEquals('var1,var2,var3{stuff}', $this->tpl->get()); function testTouchBlock()
{
} $result = $this->tpl->loadTemplateFile('blockiteration.html', false, true);
if (PEAR::isError($result)) {
/** $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
* }
*/ $this->tpl->setVariable('outer', 'data');
function testTouchBlock() // inner_block should be preserved in output, even if empty
{ $this->tpl->touchBlock('inner_block');
$result = $this->tpl->loadTemplateFile('blockiteration.html', false, true); $this->assertEquals('data|{inner}#', $this->_stripWhitespace($this->tpl->get()));
if (PEAR::isError($result)) { }
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
} // Not available in stock class
$this->tpl->setVariable('outer', 'data');
// inner_block should be preserved in output, even if empty /**
$this->tpl->touchBlock('inner_block'); *
$this->assertEquals('data|{inner}#', $this->_stripWhitespace($this->tpl->get())); */
} /*
function testHideBlock()
// Not available in stock class {
if (!$this->_methodExists('hideBlock')) {
/** return;
* Test for bug #9501. preg_replace treat $<NUM> and \<NUM> as }
* backreferences. IT escapes them. $result = $this->tpl->loadTemplateFile('blockiteration.html', false, true);
* if (PEAR::isError($result)) {
*/ $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
function testBug9501() }
{ $this->tpl->setVariable(array(
$this->tpl->setTemplate("Test: {VALUE}"); 'outer' => 'data',
$this->tpl->clearCache = true; 'inner' => 'stuff'
));
$this->tpl->setVariable("VALUE", '$12.34'); // inner_block is not empty, but should be removed nonetheless
$this->assertEquals('Test: $12.34', $this->tpl->get()); $this->tpl->hideBlock('inner_block');
$this->assertEquals('data#', $this->_stripWhitespace($this->tpl->get()));
$this->tpl->setVariable("VALUE", '$1256.34'); }
$this->assertEquals('Test: $1256.34', $this->tpl->get()); */
/**
$this->tpl->setVariable("VALUE", '^1.34'); *
$this->assertEquals('Test: ^1.34', $this->tpl->get()); */
/*
$this->tpl->setVariable("VALUE", '$1.34'); function testSetGlobalVariable()
$this->assertEquals('Test: $1.34', $this->tpl->get()); {
if (!$this->_methodExists('setGlobalVariable')) {
$this->tpl->setVariable("VALUE", '\$12.34'); return;
$this->assertEquals('Test: \$12.34', $this->tpl->get()); }
$result = $this->tpl->loadTemplateFile('globals.html', false, true);
$this->tpl->setVariable("VALUE", "\$12.34"); if (PEAR::isError($result)) {
$this->assertEquals('Test: $12.34', $this->tpl->get()); $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
}
$this->tpl->setVariable("VALUE", "\$12.34"); $this->tpl->setGlobalVariable('glob', 'glob');
$this->assertEquals('Test: $12.34', $this->tpl->get()); // {var2} is not, block_two should be removed
$this->tpl->setVariable(array(
// $12 is not parsed as a variable as it starts with a number 'var1' => 'one',
$this->tpl->setVariable("VALUE", "$12.34"); 'var3' => 'three'
$this->assertEquals('Test: $12.34', $this->tpl->get()); ));
for ($i = 0; $i < 3; $i++) {
$this->tpl->setVariable("VALUE", "\\$12.34"); $this->tpl->setVariable('var4', $i + 1);
$this->assertEquals('Test: \$12.34', $this->tpl->get()); $this->tpl->parse('block_four');
} // for
// taken from the bugreport $this->assertEquals('glob:one#glob:three|glob:1|glob:2|glob:3#', $this->_stripWhitespace($this->tpl->get()));
$word = 'Cost is $456.98'; }
$this->tpl->setVariable("VALUE", $word); */
$this->assertEquals('Test: Cost is $456.98', $this->tpl->get());
$word = "Cost is \$" . '183.22'; /**
$this->tpl->setVariable("VALUE", $word); * Test for bug #9501. preg_replace treat $<NUM> and \<NUM> as
$this->assertEquals('Test: Cost is $183.22', $this->tpl->get()); * backreferences. IT escapes them.
} *
*/
function testBug9783 () function testBug9501()
{ {
$this->tpl->setTemplate("<!-- BEGIN entry -->{DATA} <!-- END entry -->", true, true); $this->tpl->setTemplate("Test: {VALUE}");
$data = array ('{Bakken}', 'Soria', 'Joye'); $this->tpl->clearCache = true;
foreach ($data as $name) {
$this->tpl->setCurrentBlock('entry'); $this->tpl->setVariable("VALUE", '$12.34');
$this->tpl->setVariable('DATA', $name); $this->assertEquals('Test: $12.34', $this->tpl->get());
$this->tpl->parseCurrentBlock();
} $this->tpl->setVariable("VALUE", '$1256.34');
$this->assertEquals('Test: $1256.34', $this->tpl->get());
$this->assertEquals('{Bakken} Soria Joye', trim($this->tpl->get()));
$this->tpl->setVariable("VALUE", '^1.34');
} $this->assertEquals('Test: ^1.34', $this->tpl->get());
function testBug9853 () $this->tpl->setVariable("VALUE", '$1.34');
{ $this->assertEquals('Test: $1.34', $this->tpl->get());
$this->tpl->loadTemplatefile("bug_9853_01.tpl", true, true);
$this->tpl->setVariable("VALUE", '\$12.34');
$this->tpl->setVariable("VAR" , "Ok !"); $this->assertEquals('Test: \$12.34', $this->tpl->get());
$this->tpl->parse("foo1");
$this->tpl->setVariable("VALUE", "\$12.34");
$this->tpl->setVariable("VAR" , "Ok !"); $this->assertEquals('Test: $12.34', $this->tpl->get());
$this->tpl->parse("foo2");
$this->tpl->setVariable("VALUE", "\$12.34");
$this->tpl->setVariable("VAR." , "Ok !"); $this->assertEquals('Test: $12.34', $this->tpl->get());
$this->tpl->setVariable("VAR2" , "Okay");
$this->tpl->parse("bar"); // $12 is not parsed as a variable as it starts with a number
$this->tpl->setVariable("VALUE", "$12.34");
$this->tpl->parse(); $this->assertEquals('Test: $12.34', $this->tpl->get());
$output01 = $this->tpl->get();
$this->tpl->setVariable("VALUE", "\\$12.34");
$this->tpl->loadTemplatefile("bug_9853_02.tpl", true, true); $this->assertEquals('Test: \$12.34', $this->tpl->get());
$this->tpl->setVariable("VAR" , "Ok !"); // taken from the bugreport
$this->tpl->parse("foo."); $word = 'Cost is $456.98';
$this->tpl->setVariable("VALUE", $word);
$this->tpl->setVariable("VAR" , "Ok !"); $this->assertEquals('Test: Cost is $456.98', $this->tpl->get());
$this->tpl->parse("foo2");
$word = "Cost is \$" . '183.22';
$this->tpl->setVariable("VAR." , "Ok !"); $this->tpl->setVariable("VALUE", $word);
$this->tpl->setVariable("VAR2" , "Okay"); $this->assertEquals('Test: Cost is $183.22', $this->tpl->get());
$this->tpl->parse("bar"); }
$this->tpl->parse(); function testBug9783 ()
$output02 = $this->tpl->get(); {
$this->tpl->setTemplate("<!-- BEGIN entry -->{DATA} <!-- END entry -->", true, true);
$this->assertEquals($output01, $output02); $data = array ('{Bakken}', 'Soria', 'Joye');
} foreach ($data as $name) {
$this->tpl->setCurrentBlock('entry');
$this->tpl->setVariable('DATA', $name);
/** $this->tpl->parseCurrentBlock();
* Tests iterations over two blocks }
*
*/ $this->assertEquals('{Bakken} Soria Joye', trim($this->tpl->get()));
function testBlockIteration()
{ }
$data = array(
'a', function testBug9853 ()
array('b', array('1', '2', '3', '4')), {
'c', $this->tpl->loadTemplatefile("bug_9853_01.tpl", true, true);
array('d', array('5', '6', '7'))
); $this->tpl->setVariable("VAR" , "Ok !");
$this->tpl->parse("foo1");
$result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
if (PEAR::isError($result)) { $this->tpl->setVariable("VAR" , "Ok !");
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage()); $this->tpl->parse("foo2");
}
foreach ($data as $value) { $this->tpl->setVariable("VAR." , "Ok !");
if (is_array($value)) { $this->tpl->setVariable("VAR2" , "Okay");
$this->tpl->setVariable('outer', $value[0]); $this->tpl->parse("bar");
foreach ($value[1] as $v) {
$this->tpl->setVariable('inner', $v); $this->tpl->parse();
$this->tpl->parse('inner_block'); $output01 = $this->tpl->get();
}
} else { $this->tpl->loadTemplatefile("bug_9853_02.tpl", true, true);
$this->tpl->setVariable('outer', $value);
} $this->tpl->setVariable("VAR" , "Ok !");
$this->tpl->parse('outer_block'); $this->tpl->parse("foo.");
}
$this->assertEquals('a#b|1|2|3|4#c#d|5|6|7#', $this->_stripWhitespace($this->tpl->get())); $this->tpl->setVariable("VAR" , "Ok !");
} $this->tpl->parse("foo2");
/** $this->tpl->setVariable("VAR." , "Ok !");
* $this->tpl->setVariable("VAR2" , "Okay");
* $this->tpl->parse("bar");
*/
function testTouchBlockIteration() $this->tpl->parse();
{ $output02 = $this->tpl->get();
$data = array('a','b','c','d','e');
$result = $this->tpl->loadTemplateFile('blockiteration.html', true, true); $this->assertEquals($output01, $output02);
if (PEAR::isError($result)) { }
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
}
for ($i = 0; $i < count($data); $i++) { /**
$this->tpl->setVariable('outer', $data[$i]); * Tests iterations over two blocks
// the inner_block is empty and should be removed *
if (0 == $i % 2) { */
$this->tpl->touchBlock('inner_block'); function testBlockIteration()
} {
$this->tpl->parse('outer_block'); $data = array(
} 'a',
$this->assertEquals('a|#b#c|#d#e|#', $this->_stripWhitespace($this->tpl->get())); array('b', array('1', '2', '3', '4')),
} 'c',
array('d', array('5', '6', '7'))
public function testShouldSetOptionsCorrectly() { );
$result = $this->tpl->setOption('removeEmptyBlocks', false);
$result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
$this->assertFalse(PEAR::isError($result)); if (PEAR::isError($result)) {
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
$this->assertFalse($this->tpl->removeEmptyBlocks); }
foreach ($data as $value) {
$result = $this->tpl->setOption('removeEmptyBlocks', true); if (is_array($value)) {
$this->tpl->setVariable('outer', $value[0]);
$this->assertFalse(PEAR::isError($result)); foreach ($value[1] as $v) {
$this->tpl->setVariable('inner', $v);
$this->assertTrue($this->tpl->removeEmptyBlocks); $this->tpl->parse('inner_block');
}
} } else {
$this->tpl->setVariable('outer', $value);
}
public function testPlaceholderReplacementScope() { $this->tpl->parse('outer_block');
$result = $this->tpl->loadTemplateFile('placeholderreplacementscope.html', true, true); }
$this->assertEquals('a#b|1|2|3|4#c#d|5|6|7#', $this->_stripWhitespace($this->tpl->get()));
if (PEAR::isError($result)) { }
$this->fail('Error loading template file: ' . $result->getMessage());
} /**
*
*
$this->tpl->setCurrentBlock('foo'); */
$this->tpl->setVariable('var1','test'); function testTouchBlockIteration()
$this->tpl->parseCurrentBlock(); {
$this->tpl->setCurrentBlock('bar'); $data = array('a','b','c','d','e');
$this->tpl->setVariable('var1','not'); $result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
$this->tpl->setVariable('var2','good'); if (PEAR::isError($result)) {
$this->tpl->parseCurrentBlock(); $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
}
$actual = $this->_stripWhitespace($this->tpl->get()); for ($i = 0; $i < count($data); $i++) {
$this->assertEquals('testgood', $actual); $this->tpl->setVariable('outer', $data[$i]);
} // the inner_block is empty and should be removed
if (0 == $i % 2) {
} $this->tpl->touchBlock('inner_block');
}
?> $this->tpl->parse('outer_block');
}
$this->assertEquals('a|#b#c|#d#e|#', $this->_stripWhitespace($this->tpl->get()));
}
public function testShouldSetOptionsCorrectly() {
$result = $this->tpl->setOption('removeEmptyBlocks', false);
$this->assertFalse(PEAR::isError($result));
$this->assertFalse($this->tpl->removeEmptyBlocks);
$result = $this->tpl->setOption('removeEmptyBlocks', true);
$this->assertFalse(PEAR::isError($result));
$this->assertTrue($this->tpl->removeEmptyBlocks);
}
public function testPlaceholderReplacementScope() {
$result = $this->tpl->loadTemplateFile('placeholderreplacementscope.html', true, true);
if (PEAR::isError($result)) {
$this->fail('Error loading template file: ' . $result->getMessage());
}
$this->tpl->setCurrentBlock('foo');
$this->tpl->setVariable('var1','test');
$this->tpl->parseCurrentBlock();
$this->tpl->setCurrentBlock('bar');
$this->tpl->setVariable('var1','not');
$this->tpl->setVariable('var2','good');
$this->tpl->parseCurrentBlock();
$actual = $this->_stripWhitespace($this->tpl->get());
$this->assertEquals('testgood', $actual);
}
}
?>

View File

@ -1,170 +1,171 @@
<?php <?php
require_once 'HTML/Template/ITX.php'; require_once 'HTML/Template/ITX.php';
require_once 'PHPUnit/Framework/TestCase.php';
require_once 'ITTest.php';
require_once 'ITTest.php';
function _uppercaseCallback($ary)
{ function _uppercaseCallback($ary)
return strtoupper($ary[0]); {
} return strtoupper($ary[0]);
}
class Callbacks
{ class Callbacks
static function _lowercaseCallback($ary) {
{ function _lowercaseCallback($ary)
return strtolower($ary[0]); {
} return strtolower($ary[0]);
}
static function _numberFormatCallback($float, $decimals)
{ function _numberFormatCallback($float, $decimals)
return number_format($float, $decimals); {
} return number_format($float, $decimals);
} }
}
class ITXTest extends ITTest
{ class ITXTest extends ITTest
function set_up() {
{ function setUp()
$this->tpl = new HTML_Template_ITX(dirname(__FILE__) . '/templates'); {
} $this->tpl = new HTML_Template_ITX(dirname(__FILE__) . '/templates');
}
function testPlaceholderExists()
{ function testPlaceholderExists()
$this->tpl->setTemplate('{var}'); {
$this->assertSame("__global__", $this->tpl->placeholderExists('var'), 'Existing placeholder \'var\' reported as nonexistant'); $this->tpl->setTemplate('{var}');
$this->assertSame("", $this->tpl->placeholderExists('foobar'), 'Nonexistant placeholder \'foobar\' reported as existing'); $this->assertSame("__global__", $this->tpl->placeholderExists('var'), 'Existing placeholder \'var\' reported as nonexistant');
$this->assertSame("__global__", $this->tpl->placeholderExists('var', '__global__'), 'Existing in block \'__global__\' placeholder \'var\' reported as nonexistant'); $this->assertSame("", $this->tpl->placeholderExists('foobar'), 'Nonexistant placeholder \'foobar\' reported as existing');
$this->assertSame("", $this->tpl->placeholderExists('foobar', '__global__'), 'Nonexistant in block \'__global__\' placeholder \'foobar\' reported as existing'); $this->assertSame("__global__", $this->tpl->placeholderExists('var', '__global__'), 'Existing in block \'__global__\' placeholder \'var\' reported as nonexistant');
} $this->assertSame("", $this->tpl->placeholderExists('foobar', '__global__'), 'Nonexistant in block \'__global__\' placeholder \'foobar\' reported as existing');
}
function testBlockExists()
{ function testBlockExists()
$this->tpl->setTemplate('{var}'); {
$this->assertTrue($this->tpl->blockExists('__global__'), 'Existing block \'__global__\' reported as nonexistant'); $this->tpl->setTemplate('{var}');
$this->assertTrue(!$this->tpl->blockExists('foobar'), 'Nonexistant block \'foobar\' reported as existing'); $this->assertTrue($this->tpl->blockExists('__global__'), 'Existing block \'__global__\' reported as nonexistant');
} $this->assertTrue(!$this->tpl->blockExists('foobar'), 'Nonexistant block \'foobar\' reported as existing');
}
function testAddBlock()
{ function testAddBlock()
$result = $this->tpl->loadTemplatefile('blocks.html', true, true); {
if (PEAR::isError($result)) { $result = $this->tpl->loadTemplatefile('blocks.html', true, true);
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage()); if (PEAR::isError($result)) {
} $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
$this->tpl->addBlock('var', 'added', 'added:{new_var}'); }
$this->assertTrue($this->tpl->blockExists('added'), 'The new block seems to be missing'); $this->tpl->addBlock('var', 'added', 'added:{new_var}');
$this->assertTrue(!$this->tpl->placeholderExists('var'), 'The old variable seems to be still present in the template'); $this->assertTrue($this->tpl->blockExists('added'), 'The new block seems to be missing');
$this->tpl->setVariable('new_var', 'new_value'); $this->assertTrue(!$this->tpl->placeholderExists('var'), 'The old variable seems to be still present in the template');
$this->assertEquals('added:new_value', $this->_stripWhitespace($this->tpl->get())); $this->tpl->setVariable('new_var', 'new_value');
} $this->assertEquals('added:new_value', $this->_stripWhitespace($this->tpl->get()));
}
function testAddBlockfile()
{ function testAddBlockfile()
$result = $this->tpl->loadTemplatefile('blocks.html', true, true); {
if (PEAR::isError($result)) { $result = $this->tpl->loadTemplatefile('blocks.html', true, true);
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage()); if (PEAR::isError($result)) {
} $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
$result = $this->tpl->addBlockfile('var', 'added', 'addblock.html'); }
if (PEAR::isError($result)) { $result = $this->tpl->addBlockfile('var', 'added', 'addblock.html');
$this->assertTrue(false, 'Error adding block from file: '. $result->getMessage()); if (PEAR::isError($result)) {
} $this->assertTrue(false, 'Error adding block from file: '. $result->getMessage());
$this->assertTrue($this->tpl->blockExists('added'), 'The new block seems to be missing'); }
$this->assertTrue(!$this->tpl->placeholderExists('var'), 'The old variable seems to be still present in the template'); $this->assertTrue($this->tpl->blockExists('added'), 'The new block seems to be missing');
$this->tpl->setVariable('new_var', 'new_value'); $this->assertTrue(!$this->tpl->placeholderExists('var'), 'The old variable seems to be still present in the template');
$this->assertEquals('added:new_value', $this->_stripWhitespace($this->tpl->get())); $this->tpl->setVariable('new_var', 'new_value');
} $this->assertEquals('added:new_value', $this->_stripWhitespace($this->tpl->get()));
}
function testReplaceBlock()
{ function testReplaceBlock()
$result = $this->tpl->loadTemplatefile('blocks.html', true, true); {
if (PEAR::isError($result)) { $result = $this->tpl->loadTemplatefile('blocks.html', true, true);
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage()); if (PEAR::isError($result)) {
} $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
$this->tpl->setVariable('old_var', 'old_value'); }
$this->tpl->parse('old_block'); $this->tpl->setVariable('old_var', 'old_value');
// old_block's contents should be discarded $this->tpl->parse('old_block');
$this->tpl->replaceBlock('old_block', 'replaced:{replaced_var}#', false); // old_block's contents should be discarded
$this->assertTrue(!$this->tpl->blockExists('old_inner_block') && !$this->tpl->placeholderExists('old_var'), $this->tpl->replaceBlock('old_block', 'replaced:{replaced_var}#', false);
'The replaced block\'s contents seem to be still present'); $this->assertTrue(!$this->tpl->blockExists('old_inner_block') && !$this->tpl->placeholderExists('old_var'),
$this->tpl->setVariable('replaced_var', 'replaced_value'); 'The replaced block\'s contents seem to be still present');
$this->tpl->parse('old_block'); $this->tpl->setVariable('replaced_var', 'replaced_value');
// this time old_block's contents should be preserved $this->tpl->parse('old_block');
$this->tpl->replaceBlock('old_block', 'replaced_again:{brand_new_var}', true); // this time old_block's contents should be preserved
$this->tpl->setVariable('brand_new_var', 'brand_new_value'); $this->tpl->replaceBlock('old_block', 'replaced_again:{brand_new_var}', true);
$this->assertEquals('replaced:replaced_value#replaced_again:brand_new_value', $this->_stripWhitespace($this->tpl->get())); $this->tpl->setVariable('brand_new_var', 'brand_new_value');
} $this->assertEquals('replaced:replaced_value#replaced_again:brand_new_value', $this->_stripWhitespace($this->tpl->get()));
}
function testReplaceBlockfile()
{ function testReplaceBlockfile()
$result = $this->tpl->loadTemplatefile('blocks.html', true, true); {
if (PEAR::isError($result)) { $result = $this->tpl->loadTemplatefile('blocks.html', true, true);
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage()); if (PEAR::isError($result)) {
} $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
$this->tpl->setVariable('old_var', 'old_value'); }
$this->tpl->parse('old_block'); $this->tpl->setVariable('old_var', 'old_value');
// old_block's contents should be discarded $this->tpl->parse('old_block');
$result = $this->tpl->replaceBlockfile('old_block', 'replaceblock.html', false); // old_block's contents should be discarded
if (PEAR::isError($result)) { $result = $this->tpl->replaceBlockfile('old_block', 'replaceblock.html', false);
$this->assertTrue(false, 'Error replacing block from file: '. $result->getMessage()); if (PEAR::isError($result)) {
} $this->assertTrue(false, 'Error replacing block from file: '. $result->getMessage());
$this->assertTrue(!$this->tpl->blockExists('old_inner_block') && !$this->tpl->placeholderExists('old_var'), }
'The replaced block\'s contents seem to be still present'); $this->assertTrue(!$this->tpl->blockExists('old_inner_block') && !$this->tpl->placeholderExists('old_var'),
$this->tpl->setVariable(array( 'The replaced block\'s contents seem to be still present');
'replaced_var' => 'replaced_value', $this->tpl->setVariable(array(
'replaced_inner_var' => 'inner_value' 'replaced_var' => 'replaced_value',
)); 'replaced_inner_var' => 'inner_value'
$this->tpl->parse('old_block'); ));
// this time old_block's contents should be preserved $this->tpl->parse('old_block');
$result = $this->tpl->replaceBlockfile('old_block', 'addblock.html', true); // this time old_block's contents should be preserved
if (PEAR::isError($result)) { $result = $this->tpl->replaceBlockfile('old_block', 'addblock.html', true);
$this->assertTrue(false, 'Error replacing block from file: '. $result->getMessage()); if (PEAR::isError($result)) {
} $this->assertTrue(false, 'Error replacing block from file: '. $result->getMessage());
$this->tpl->setVariable('new_var', 'again'); }
$this->assertEquals('replaced:replaced_value|inner_value#added:again', $this->_stripWhitespace($this->tpl->get())); $this->tpl->setVariable('new_var', 'again');
} $this->assertEquals('replaced:replaced_value|inner_value#added:again', $this->_stripWhitespace($this->tpl->get()));
}
function testCallback()
{ function testCallback()
$this->tpl->setTemplate('callback:func_uppercase(word)'); {
$this->tpl->setCallbackFunction('uppercase', '_uppercaseCallback'); $this->tpl->setTemplate('callback:func_uppercase(word)');
$res = $this->tpl->performCallback(); $this->tpl->setCallbackFunction('uppercase', '_uppercaseCallback');
if (PEAR::isError($res)) { $res = $this->tpl->performCallback();
$this->assertTrue(false, 'Error performing callback: '. $res->getMessage()); if (PEAR::isError($res)) {
} $this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
$this->assertEquals('callback:WORD', $this->tpl->get()); }
$this->assertEquals('callback:WORD', $this->tpl->get());
$this->tpl->setTemplate('callback:func_lowercase(Word)');
$this->tpl->setCallbackFunction('lowercase', array('Callbacks','_lowercaseCallback')); $this->tpl->setTemplate('callback:func_lowercase(Word)');
$res = $this->tpl->performCallback(); $this->tpl->setCallbackFunction('lowercase', array('Callbacks','_lowercaseCallback'));
if (PEAR::isError($res)) { $res = $this->tpl->performCallback();
$this->assertTrue(false, 'Error performing callback: '. $res->getMessage()); if (PEAR::isError($res)) {
} $this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
$this->assertEquals('callback:word', $this->tpl->get()); }
$this->assertEquals('callback:word', $this->tpl->get());
$this->tpl->setTemplate('callback:func_lowercase(Word)');
$this->tpl->setCallbackFunction('lowercase', array(new Callbacks,'_lowercaseCallback')); $this->tpl->setTemplate('callback:func_lowercase(Word)');
$res = $this->tpl->performCallback(); $this->tpl->setCallbackFunction('lowercase', array(new Callbacks,'_lowercaseCallback'));
if (PEAR::isError($res)) { $res = $this->tpl->performCallback();
$this->assertTrue(false, 'Error performing callback: '. $res->getMessage()); if (PEAR::isError($res)) {
} $this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
$this->assertEquals('callback:word', $this->tpl->get()); }
$this->assertEquals('callback:word', $this->tpl->get());
$this->tpl->setTemplate('callback:func_numberFormat(1.5, 2)');
$this->tpl->setCallbackFunction('numberFormat', array('Callbacks', '_numberFormatCallback'), '', true); $this->tpl->setTemplate('callback:func_numberFormat(1.5, 2)');
$res = $this->tpl->performCallback(); $this->tpl->setCallbackFunction('numberFormat', array('Callbacks', '_numberFormatCallback'), '', true);
if (PEAR::isError($res)) { $res = $this->tpl->performCallback();
$this->assertTrue(false, 'Error performing callback: '. $res->getMessage()); if (PEAR::isError($res)) {
} $this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
$this->assertEquals('callback:1.50', $this->tpl->get()); }
$this->assertEquals('callback:1.50', $this->tpl->get());
$this->tpl->setTemplate('callback:func_numberFormat(1.5, 2)');
$GLOBALS['obj'] = new Callbacks; $this->tpl->setTemplate('callback:func_numberFormat(1.5, 2)');
$this->tpl->setCallbackFunction('numberFormat', '_numberFormatCallback', 'obj', true); $GLOBALS['obj'] = new Callbacks;
$res = $this->tpl->performCallback(); $this->tpl->setCallbackFunction('numberFormat', '_numberFormatCallback', 'obj', true);
if (PEAR::isError($res)) { $res = $this->tpl->performCallback();
$this->assertTrue(false, 'Error performing callback: '. $res->getMessage()); if (PEAR::isError($res)) {
} $this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
$this->assertEquals('callback:1.50', $this->tpl->get()); }
} $this->assertEquals('callback:1.50', $this->tpl->get());
} }
}
?>
?>

View File

@ -1,7 +1,7 @@
<!-- BEGIN outer_block --> <!-- BEGIN outer_block -->
{outer} {outer}
<!-- BEGIN inner_block --> <!-- BEGIN inner_block -->
|{inner} |{inner}
<!-- END inner_block --> <!-- END inner_block -->
# #
<!-- END outer_block --> <!-- END outer_block -->

View File

@ -1,8 +1,8 @@
{var} {var}
<!-- BEGIN old_block --> <!-- BEGIN old_block -->
old:{old_var} old:{old_var}
<!-- BEGIN old_inner_block --> <!-- BEGIN old_inner_block -->
|{old_inner_var} |{old_inner_var}
<!-- END old_inner_block --> <!-- END old_inner_block -->
# #
<!-- END old_block --> <!-- END old_block -->

View File

@ -0,0 +1,13 @@
<!-- BEGIN block_one -->
{glob}:{var1}#
<!-- END block_one -->
<!-- BEGIN block_two -->
{glob}:{var2}#
<!-- END block_two -->
<!-- BEGIN block_three -->
{glob}:{var3}
<!-- BEGIN block_four -->
|{glob}:{var4}
<!-- END block_four -->
#
<!-- END block_three -->

View File

@ -1 +1 @@
Master file; <!-- INCLUDE __include.html --> Master file; <!-- INCLUDE __include.html -->

View File

@ -1,5 +1,5 @@
replaced:{replaced_var} replaced:{replaced_var}
<!-- BEGIN new_inner_block --> <!-- BEGIN new_inner_block -->
|{replaced_inner_var} |{replaced_inner_var}
<!-- END new_inner_block --> <!-- END new_inner_block -->
# #

117
debian/changelog vendored
View File

@ -1,117 +0,0 @@
php-html-template-it (1:1.3.2-1) unstable; urgency=medium
* Bump
-- Mario Fetka <mario.fetka@gmail.com> Thu, 08 Mar 2018 14:34:32 +0100
php-html-template-it (1:1.3.1-1) UNRELEASED; urgency=medium
* Bump
-- Mario Fetka <mario.fetka@gmail.com> Thu, 08 Mar 2018 14:34:32 +0100
php-html-template-it (1:1.3.0-3) unstable; urgency=medium
* Use ${phppear:Debian-Depends/Recommends/Breaks}
* Use ${phppear:summary} and ${phppear:description}
* Bump Standard-Version to 3.9.5
* Build-depends on pkg-php-tools >= 1.10 to remove the tests.
Thanks to Andreas Beckmann
-- Prach Pongpanich <prachpub@gmail.com> Mon, 03 Feb 2014 23:37:45 +0700
php-html-template-it (1:1.3.0-2) unstable; urgency=low
* Upload to unstable
* Now running unit tests at build time:
- Build-Depends php-unit (>= 3.6)
-- Prach Pongpanich <prachpub@gmail.com> Tue, 30 Apr 2013 14:57:12 +0700
php-html-template-it (1:1.3.0-1) experimental; urgency=low
* New upstream release
* Now using PKG-PHP-PEAR team as maintainer and
add myself as uploader (Closes: #682303)
* Switch to pkg-php-tools and dh-sequencer
- Add pkg-php-tools to Build-Depends and drop {dh-make-php,cdbs}
- Add php-pear to Build-Depends-Indep
- Rewrite debian/rules
* Switch to 3.0 (quilt) source format
* Update copyright file to version 1.0 format
* Add Vcs-* fields in debian/control
* Add debian/gbp.conf
* Update debian/watch file
* Bump debhelper compat to level 9
* Bump Standards-Version 3.9.4
-- Prach Pongpanich <prachpub@gmail.com> Fri, 22 Mar 2013 16:59:52 +0700
php-html-template-it (1:1.2.1-3) unstable; urgency=low
* New maintainer (Closes: #529674)
* Removed changes made to source code (Closes: #529584)
* debian/control:
- Updated description (Closes: #488767)
- Removed uploader at his request
- Changed Section to php to fix the override disparities
- Updated Standards-Version: 3.8.3
- Added cdbs and dh-make-php to Build-Depends
- Added ${misc:Depends} to Depends
* debian/copyright: added copyright note for the different maintainers
* debian/rules:
- Modifications to use cdbs
- Added code to remove empty directories
-- Federico Gimenez Nieto <fgimenez@coit.es> Tue, 25 Aug 2009 12:25:12 +0200
php-html-template-it (1:1.2.1-2) unstable; urgency=low
* Display pages that have no variable replacements in them, thanks to
Jeff Bailey <jbailey@raspberryginger.com> (closes: #320959)
* Updated copyright with new upstream author. (closes: #454773)
* Standards-Version: 3.7.3
* Updated "Homepage:" pseudo-header as Reference 1.14.6.
* Solved binary-arch-rules-but-pkg-is-arch-indep lintian report.
-- Jose Carlos Medeiros <debian@psabs.com.br> Fri, 14 Dec 2007 19:49:53 -0200
php-html-template-it (1:1.2.1-1) unstable; urgency=low
* New upstream release.
* New mantainer. (Closes: #442048)
* Package reconstructed based on php-services-weather, rules file was
reconstructed too. (Closes: #395733)
* debian/control:
- Standards-Version: 3.7.2
- Build-Depends: debhelper (>= 5)
- Added Homepage.
- Updated php dependencies to complain with php4-removal. (Closes: #424817)
* debian/compat: DH_COMPAT 5
* Updated copyright file to new license BSD. (Closes: #332610)
* debian/watch: created.
* debian/examples: created.
-- Jose Carlos Medeiros <debian@psabs.com.br> Fri, 21 Sep 2007 23:57:52 -0300
php-html-template-it (1.10-3) unstable; urgency=low
* Change the PEAR_ROOT to new debian location /usr/share/php according to
the new specification of pear.
*
-- Polkan Alexis Garcia <pagarcia@slcolombia.org> Tue, 15 Mar 2005 15:38:22 -0500
php-html-template-it (1.10-2) unstable; urgency=low
* Remove libraries in the PEAR_ROOT/HTML (duplicated) and only remain
the existing ones in PEAR_ROOT/HTML/Template (closes: #298986)
-- Polkan Alexis Garcia <pagarcia@slcolombia.org> Tue, 15 Mar 2005 12:05:41 -0500
php-html-template-it (1.10-1) unstable; urgency=low
* Initial Release.
-- Polkan Alexis Garcia <pagarcia@slcolombia.org> Wed, 6 Oct 2004 12:31:40 -0500

1
debian/compat vendored
View File

@ -1 +0,0 @@
9

18
debian/control vendored
View File

@ -1,18 +0,0 @@
Source: php-html-template-it
Section: php
Priority: optional
Maintainer: Debian PHP PEAR Maintainers <pkg-php-pear@lists.alioth.debian.org>
Uploaders: Prach Pongpanich <prachpub@gmail.com>
Build-Depends: debhelper (>= 9), pkg-php-tools (>= 1.10), phpunit (>= 3.6)
Standards-Version: 3.9.5
Vcs-Git: git://anonscm.debian.org/pkg-php/php-html-template-it.git
Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-php/php-html-template-it.git
Homepage: http://pear.php.net/package/HTML_Template_IT/
Package: php-html-template-it
Architecture: all
Depends: ${misc:Depends}, ${phppear:Debian-Depends}
Recommends: ${phppear:Debian-Recommends}
Breaks: ${phppear:Debian-Breaks}
Description: ${phppear:summary}
${phppear:description}

41
debian/copyright vendored
View File

@ -1,41 +0,0 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Contact: David Soria Parra <dsp at php dot net>,
Pierre-Alain Joye <pajoye@php.net>,
Ulf Wendel <ulf.wendel@phpdoc.de>
Source: http://pear.php.net/package/HTML_Template_IT
Files: debian/*
Copyright: 2004-2005, Polkan Alexis Garcia <pagarcia@slcolombia.org>
2007, Jose Carlos N Medeiros <jose@psabs.com.br>
2009, Federico Gimenez Nieto <fgimenez@coit.es>
2013, Prach Pongpanich <prachpub@gmail.com>
License: BSD-3-clause
Files: *
Copyright: 1997-2007, David Soria Parra <dsp at php dot net>
1997-2007, Pierre-Alain Joye <pajoye@php.net>
1997-2007, Ulf Wendel <ulf.wendel@phpdoc.de>
License: BSD-3-clause
License: BSD-3-clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

11
debian/rules vendored
View File

@ -1,11 +0,0 @@
#!/usr/bin/make -f
%:
dh $@ --buildsystem=phppear --with phppear
#override_dh_auto_test:
#ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
# set -e ;\
# PKGDIR=$(shell ls | grep HTML) ;\
# phpunit -d include_path="/usr/share/php:$${PKGDIR}" */tests
#endif

View File

@ -1 +0,0 @@
3.0 (quilt)

2
debian/watch vendored
View File

@ -1,2 +0,0 @@
version=3
http://pear.php.net/package/HTML_Template_IT/download .*/HTML_Template_IT-(\d.*)\.(?:tgz|tar\.(?:gz|bz2|xz))

View File

@ -1,6 +0,0 @@
-----BEGIN PGP SIGNATURE-----
iF0EABECAB0WIQQQ9oz3P4qkJvYXdSlyoyG6wkXxdQUCZ0NbqAAKCRByoyG6wkXx
dVaEAKDCvxZ1ZQmbPgqRjUAkC72ylQzpOwCeO5mQBEJ3+ziJdLnBvRv7trd0l68=
=9MLm
-----END PGP SIGNATURE-----

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<package packagerversion="1.10.13" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>HTML_Template_IT</name> <name>HTML_Template_IT</name>
<channel>pear.php.net</channel> <channel>pear.php.net</channel>
<summary>Integrated Templates</summary> <summary>Integrated Templates</summary>
@ -10,7 +10,7 @@ There are two classes to use for templating. HTML_Template_IT is used for basic
<name>Gregory Currie</name> <name>Gregory Currie</name>
<user>gregorycu</user> <user>gregorycu</user>
<email>gregorycu@php.net</email> <email>gregorycu@php.net</email>
<active>no</active> <active>yes</active>
</lead> </lead>
<lead> <lead>
<name>Pierre-Alain Joye</name> <name>Pierre-Alain Joye</name>
@ -36,46 +36,61 @@ There are two classes to use for templating. HTML_Template_IT is used for basic
<email>ulf.wendel@phpdoc.de</email> <email>ulf.wendel@phpdoc.de</email>
<active>no</active> <active>no</active>
</developer> </developer>
<date>2024-11-24</date> <date>2010-03-10</date>
<time>16:59:33</time> <time>19:08:10</time>
<version> <version>
<release>1.3.2</release> <release>1.3.0</release>
<api>1.3.0</api> <api>1.3.0</api>
</version> </version>
<stability> <stability>
<release>stable</release> <release>stable</release>
<api>stable</api> <api>stable</api>
</stability> </stability>
<license>BSD-3-Clause</license> <license>Modified BSD license</license>
<notes> <notes>
- PR # 5: Support for PHP 7.2 Changes since last stable release (1.2.1):
- PR # 9: Remove unused code - Add support for pear package 2.0 format
- PR #11: fix: Array and string offset access syntax with curly braces is no longer supported - Remove support for pear package 1.0 format
- PR #12: Remove PHP under 5.6 and add last versions of PHP 7 - Fix bug #9501, doller signs disapear if preg_match is used.
- Fix bug #9783, don&apos;t remove variable which values follow the variable pattern
To allow backwards compatbility an option preserve_input is added.
If it is false, the old behaviour will be used and therefore those values will be deleted.
Default is true, so new behaviour.
- Fix bug #9853, problems with dots in placeholders or blocknames
- Fix bug #13935, docblock is wrong
- Fix bug #17129
- Add option &apos;preserve_input&apos; to only remove unkown variable that were present
during setTemplate or loadTemplatefile
which is the behaviour before 1.3.0a1
- Improved PHPCS (Request #15039)
- Added unit tests
- Fixed unit tests
</notes> </notes>
<contents> <contents>
<dir name="/"> <dir name="/">
<file md5sum="ba285cf25750a900690f2388ee31a103" name="examples/sample_it.php" role="doc" /> <file md5sum="157f1b27090288fbce921b762697c3f4" name="examples/sample_it.php" role="doc" />
<file md5sum="8da7b1692566f5f67b7070402cb949dc" name="examples/sample_itx_addblockfile.php" role="doc" /> <file md5sum="1d2363fa8640780392af6c51e9c3713f" name="examples/sample_itx_addblockfile.php" role="doc" />
<file md5sum="342278cc5fe8ca6c66591cd5ee389402" name="examples/templates/addblockfile_list.tpl.htm" role="doc" /> <file md5sum="43a3535aa4d5e9df400babae53d82a08" name="examples/templates/addblockfile_list.tpl.htm" role="doc" />
<file md5sum="697f694a67db6b96d247a24bdfd44f9b" name="examples/templates/addblockfile_main.tpl.htm" role="doc" /> <file md5sum="16f4927420fa169875167a4874e7add7" name="examples/templates/addblockfile_main.tpl.htm" role="doc" />
<file md5sum="834e1e6d40b2f34906aa17f9969bd891" name="examples/templates/main.tpl.htm" role="doc" /> <file md5sum="2c851fcec88007eef66c28a9d8f10ceb" name="examples/templates/main.tpl.htm" role="doc" />
<file md5sum="531abbcc1ca42d2bd330b7f82851a06f" name="HTML/Template/IT.php" role="php" /> <file md5sum="886a6044e8186e3b1e1d8c5b004246af" name="HTML/Template/IT.php" role="php" />
<file md5sum="aa98c643aac5305b888851bdb7bf494d" name="HTML/Template/ITX.php" role="php" /> <file md5sum="16b0300b5fbe3be7a1df976ce5d27c4f" name="HTML/Template/ITX.php" role="php" />
<file md5sum="806ee7726ac7fdf74ce13a610fb30ddc" name="HTML/Template/IT_Error.php" role="php" /> <file md5sum="484d2aa6a504a351a1d3e2b8bb39612d" name="HTML/Template/IT_Error.php" role="php" />
<file md5sum="304e1a435c31469840de4dc77dfaa2d5" name="tests/ITTest.php" role="test" /> <file md5sum="e576a94c06b323e4cfc6bcf9dda017c2" name="tests/AllTests.php" role="test" />
<file md5sum="0f23dcc3d5992a01f50c75e05c70080a" name="tests/ITXTest.php" role="test" /> <file md5sum="adabbbb8cf54dc80720b7929e594cbec" name="tests/ITTest.php" role="test" />
<file md5sum="bca97392b741f553d10203f04549a423" name="tests/templates/addblock.html" role="test" /> <file md5sum="80139a8b443488dac801fae748b6f2c2" name="tests/ITXTest.php" role="test" />
<file md5sum="d4e1caf0b07b85e49e0e82ab83e91ed3" name="tests/templates/blockiteration.html" role="test" /> <file md5sum="e50de49b74a1d96bb77ddae2d0abdfc3" name="tests/templates/addblock.html" role="test" />
<file md5sum="aa11dc0ba8c94c71f0ed6e448770f913" name="tests/templates/blocks.html" role="test" /> <file md5sum="22e56437378e53d08ba07d3dd2aa4b85" name="tests/templates/blockiteration.html" role="test" />
<file md5sum="4173bf97eec43787532e247ef9b2611a" name="tests/templates/blocks.html" role="test" />
<file md5sum="7014497a69b346957fb3d2b5fa44ffd4" name="tests/templates/bug_9853_01.tpl" role="test" /> <file md5sum="7014497a69b346957fb3d2b5fa44ffd4" name="tests/templates/bug_9853_01.tpl" role="test" />
<file md5sum="385013ff6be875da2888087e96c6a93c" name="tests/templates/bug_9853_02.tpl" role="test" /> <file md5sum="385013ff6be875da2888087e96c6a93c" name="tests/templates/bug_9853_02.tpl" role="test" />
<file md5sum="8ac12c5d1c85787dd44ed5c93a392dfe" name="tests/templates/include.html" role="test" /> <file md5sum="2611d6ec574a65716f1bc2ca95cb8c63" name="tests/templates/globals.html" role="test" />
<file md5sum="bd4c99366021b8bd88ba220ec829eae5" name="tests/templates/loadtemplatefile.html" role="test" /> <file md5sum="db5b226eff0218c831749c07042529f2" name="tests/templates/include.html" role="test" />
<file md5sum="d9a6425eebdfc6981465b4a228dbee51" name="tests/templates/loadtemplatefile.html" role="test" />
<file md5sum="8747e8c70d20b6c86d1d19af2eadd874" name="tests/templates/placeholderreplacementscope.html" role="test" /> <file md5sum="8747e8c70d20b6c86d1d19af2eadd874" name="tests/templates/placeholderreplacementscope.html" role="test" />
<file md5sum="a3d70ab52bdb9f3c14702879865a55d6" name="tests/templates/replaceblock.html" role="test" /> <file md5sum="5c7e2e9c32306db4b6667d2b57f1c0ac" name="tests/templates/replaceblock.html" role="test" />
<file md5sum="fb1681e6ffa470d92859fac3496b960e" name="tests/templates/__include.html" role="test" /> <file md5sum="310552db4653b34dbb0f993847572fc5" name="tests/templates/__include.html" role="test" />
<file md5sum="f8790e48b597dff12a643e08e9be3fab" name="LICENSE" role="doc" /> <file md5sum="7073f9a84fa6da71e7a505a777dda302" name="LICENSE" role="doc" />
</dir> </dir>
</contents> </contents>
<dependencies> <dependencies>
@ -316,38 +331,5 @@ Changes since last stable release (1.2.1):
- Fixed unit tests - Fixed unit tests
</notes> </notes>
</release> </release>
<release>
<version>
<release>1.3.1</release>
<api>1.3.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2018-01-22</date>
<license>BSD-3-Clause</license>
<notes>
- PR #2: Fixes for deprecated code
</notes>
</release>
<release>
<version>
<release>1.3.2</release>
<api>1.3.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2024-11-24</date>
<license>BSD-3-Clause</license>
<notes>
- PR #5: Support for PHP 7.2
- PR #9: Remove unused code
- PR #11: fix: Array and string offset access syntax with curly braces is no longer supported
- PR #12: Remove PHP under 5.6 and add last versions of PHP 7
</notes>
</release>
</changelog> </changelog>
</package> </package>