Source for file SimpleTags.php
Documentation is available at SimpleTags.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Alan Knowles <alan@akbkhome.com>
// +----------------------------------------------------------------------+
* The Standard Tag filter
* does all the clever stuff...
* Templates should not originate from untrusted sources,
* - the method(#.....#) could be regarded as insecure.
* - there is no attempt to protect your from <script / <?php in templates.
* @package HTML_Template_Flexy
* @var object HTML_Template_Flexy the main engine
var $engine; // the engine (with options)
* @var string $start the start tag for the template (escaped for regex)
* @var string $stop the stopt tag for the template (escaped for regex)
* @var string $error show/hide the PHP error messages on/off in templates
var $error = "@"; // change to blank to debug errors.
* @param object HTML_Template_Flexy the main engine
function _set_engine (&$engine) {
if ($this->engine->options ['debug']) {
* Standard Variable replacement
* {i.xyz} maps to <?php echo htmlspecialchars($i->xyz)?>
* {i.xyz:h} maps to <?php echo $i->xyz?>
* {i.xyz:u} maps to <?php echo urlencode($i->xyz)?>
* {i.xyz:ru} maps to <?php echo rawurlencode($i->xyz)?>
* {i.xyz:r} maps to <PRE><?php echo print_r($i->xyz)?></PRE>
* {i.xyz:n} maps to <?php echo nl2br(htmlspecialchars($i->xyz))?>
* @param string $input the template
* @return string the result of the filtering
"/". $this->start. "([a-z0-9_.]+)". $this->stop. "/ie",
"'<?php echo htmlspecialchars(". $this->error. "$'.str_replace('.','->','\\1').')?>'",
"/". $this->start. "([a-z0-9_.]+):h". $this->stop. "/ie",
"'<?php echo ". $this->error. "$'.str_replace('.','->','\\1').'?>'",
"/". $this->start. "([a-z0-9_.]+):u". $this->stop. "/ie",
"'<?php echo urlencode(". $this->error. "$'.str_replace('.','->','\\1').')?>'",
"/". $this->start. "([a-z0-9_.]+):ru". $this->stop. "/ie",
"'<?php echo rawurlencode(". $this->error. "$'.str_replace('.','->','\\1').')?>'",
"/". $this->start. "([a-z0-9_.]+):r". $this->stop. "/ie",
"'<PRE><?php echo print_r($'.str_replace('.','->','\\1').')?></PRE>'",
"/". $this->start. "([a-z0-9_.]+):n". $this->stop. "/ie",
"'<?php echo nl2br(htmlspecialchars(". $this->error. "$'.str_replace('.','->','\\1').'))?>'",
* Urlencoded Variable replacement
* Often when you use a WYSISYG editor, it replaces { in
* the href="{somevar}" with the urlencoded version, this bit fixes it.
* %??i.xyz%?? maps to <?php echo htmlspecialchars($i->xyz)?>
* %??i.xyz:h%?? maps to <?php echo $i->xyz?>
* %??i.xyz:u%?? maps to <?php echo urlencode($i->xyz)?>
* %??i.xyz:ru%?? maps to <?php echo urlencode($i->xyz)?>
* THIS IS PROBABLY THE ONE TO USE!
* %??i.xyz:uu%?? maps to <?php echo urlencode(urlencode($i->xyz))?>
* @param string $input the template
* @return string the result of the filtering
"'<?php echo htmlspecialchars(". $this->error. "$'.str_replace('.','->','\\1').')?>'",
"'<?php echo ". $this->error. "$'.str_replace('.','->','\\1').'?>'",
"'<?php echo urlencode(". $this->error. "$'.str_replace('.','->','\\1').')?>'",
"'<?php echo urlencode(urlencode(". $this->error. "$'.str_replace('.','->','\\1').'))?>'",
* This allows you to call methods of your application
* {t.xxxx_xxxx()} maps to <?php echo htmlspecialchars($t->xxxx_xxxx())?>
* {t.xxxx_xxxx():h} maps to <?php echo $t->xxxx_xxxx()?>
* {t.xxxx_xxxx(sssss.dddd)} maps to <?php echo htmlspecialchars($t->xxxx_xxxx($ssss->dddd))?>
* {t.xxxx_xxxx(sssss.dddd):h} maps to <?php echo $t->xxxx_xxxx($ssss->dddd)?>
* {t.xxxx_xxxx(sssss.dddd):s} maps to <?php highlight_string($t->xxxx_xxxx($ssss->dddd))?>
* {t.xxxx_xxxx(#XXXXX#)} maps to <?php echo htmlspecialchars($t->xxxx_xxxx('XXXXXX'))?>
* {t.xxxx_xxxx(#XXXXX#):h} maps to <?php echo $t->xxxx_xxxx('XXXXXX')?>
* {t.xxxx_xxxx(sss.ddd,sss.ddd)} maps to <?php echo htmlspecialchars($t->xxxx_xxxx($sss->ddd,$sss->ddd))?>
* {t.xxxx_xxxx(#aaaa#,sss.ddd)} maps to <?php echo htmlspecialchars($t->xxxx_xxxx("aaaa",$sss->ddd))?>
* {t.xxxx_xxxx(sss.ddd,#aaaa#)} maps to <?php echo htmlspecialchars($t->xxxx_xxxx($sss->ddd,"aaaa"))?>
* @param string $input the template
* @return string the result of the filtering
"/". $this->start. "([a-z0-9_.]+)\(\)". $this->stop. "/ie",
"'<?php echo htmlspecialchars(". $this->error. "$'.str_replace('.','->','\\1').'())?>'",
"/". $this->start. "([a-z0-9_.]+)\(\):h". $this->stop. "/ie",
"'<?php echo ". $this->error. "$'.str_replace('.','->','\\1').'()?>'",
"/". $this->start. "([a-z0-9_.]+)\(([a-z0-9_.]+)\)". $this->stop. "/ie",
"'<?php echo htmlspecialchars(". $this->error. "$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . '))?>'",
"/". $this->start. "([a-z0-9_.]+)\(([a-z0-9_.]+)\):h". $this->stop. "/ie",
"'<?php echo ". $this->error. "$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ')?>'",
"/". $this->start. "([a-z0-9_.]+)\(([a-z0-9_.]+)\):s". $this->stop. "/ie",
"'<?php highlight_string($'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . '));?>'",
"/". $this->start. "([a-z0-9_.]+)\(([a-z0-9_.]+),([a-z0-9_.]+)\)". $this->stop. "/ie",
"'<?php echo htmlspecialchars(". $this->error. "$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ',$' . str_replace('.','->','\\3') . '))?>'",
/* double vars:: # #'d ,var */
"/". $this->start. "([a-z0-9_.]+)\(\#([^\#]+)\#,([a-z0-9_.]+)\)". $this->stop. "/ie",
"'<?php echo htmlspecialchars(". $this->error. "$'.str_replace('.','->','\\1').'(\''. str_replace(\"'\",\"\\\'\",'\\2') . '\',$' . str_replace('.','->','\\3') . '))?>'",
/* double vars:: var , # #'d */
"/". $this->start. "([a-z0-9_.]+)\(([a-z0-9_.]+),\#([^\#]+)\#\)". $this->stop. "/ie",
"'<?php echo htmlspecialchars(". $this->error. "$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ',\''. str_replace(\"'\",\"\\\'\",'\\3') . '\'))?>'",
"/". $this->start. "([a-z0-9_.]+)\(\#([^\#]+)\#\)". $this->stop. "/ie",
"'<?php echo htmlspecialchars(\$'.str_replace('.','->','\\1') . '(\''. str_replace(\"'\",\"\\\'\",'\\2') . '\'))?>'",
"/". $this->start. "([a-z0-9_.]+)\(\#([^\#]+)\#\):h". $this->stop. "/ie",
"'<?php echo ". $this->error. "$'.str_replace('.','->','\\1').'(\"' . str_replace(\"'\",\"\\\'\",'\\2') . '\")?>'",
* This allows you to do loops on variables (eg. nested/ repeated blocks!)
* {foreach:t.xyz,zzz} maps to <?php if ($i->xyz) foreach ($t->xyz as $zzz) { ?>
* {foreach:t.xyz,xxx,zzz} maps to <?php if ($i->xyz) foreach ($t->xyz as $xxx=>$zzz) { ?>
* {end:} maps to <?php }?>
* {else:} maps to <?php }else{?>
* @param string $input the template
* @return string the result of the filtering
"/". $this->start. "foreach:([a-z0-9_.]+),([a-z0-9_.]+)". $this->stop. "/ie",
"'<?php if (". $this->error. "$' . str_replace('.','->','\\1') . ') foreach( $' . str_replace('.','->','\\1') . ' as $' . str_replace('.','->','\\2') . ') { ?>'",
"/". $this->start. "foreach:([a-z0-9_.]+),([a-z0-9_.]+),([a-z0-9_.]+)". $this->stop. "/ie",
"'<?php if (". $this->error. "$' . str_replace('.','->','\\1') . ') foreach( $' . str_replace('.','->','\\1') . ' as $' . str_replace('.','->','\\2') . '=>$' . str_replace('.','->','\\3') .') { ?>'",
* This allows you to do conditional inclusion (eg. blocks!)
* {if:t.xxxx} => <?php if ($t->xxxx) { ?>
* {if:t.x_xxx()} => <?php if ($t->x_xxx()) { ?>
* @param string $input the template
* @return string the result of the filtering
"/". $this->start. "if:([a-z0-9_.]+)". $this->stop. "/ie",
"'<?php if (". $this->error. "$' . str_replace('.','->','\\1') . ') { ?>'",
"/". $this->start. "if:([a-z0-9_.]+)\(\)". $this->stop. "/ie",
"'<?php if (". $this->error. "$' . str_replace('.','->','\\1') . '()) { ?>'",
* This allows you to do include other files (either flat or generated templates.).
* {include:t.abcdef} maps to <?php
* if($t->abcdef && file_exists($compileDir . "/". $t->abcdef . "en.php"))
* include($compileDir . "/". $t->abcdef . ".en.php");
* include abcdef.en.php (Eg. hard coded compiled template
* {include:#abcdef#} => <?php
* if(file_exists($compileDir . "/abcdef.en.php"))
* include($compileDir . "/abcdef.en.php");
* {t_include:#abcdef.html#} => <?php
* if(file_exists($templateDir . "/abcdef.html"))
* include($compileDir . "/abcdef.html");
* {q_include:#abcdef.html#} => <?php
* HTML_Template_Flexy::staticQuickTemplate('abcedef.html',$t);
* @param string $input the template
* @return string the result of the filtering
// array not supported for this type of template.
"/". $this->start. "include:([a-z0-9_.]+)". $this->stop. "/ie",
if ((". $this->error. "$' . str_replace('.','->','\\1') . ') &&
file_exists(\"" . $this->engine->options ['compileDir'] .
"/\{$' . str_replace('.','->','\\1') . '}.en.php\"))
include(\"" . $this->engine->options ['compileDir'] .
"/\{$' . str_replace('.','->','\\1') . '}.en.php\");?>'",
"/". $this->start. "include:#([a-z0-9_.]+)#". $this->stop. "/ie",
"'<?php if (file_exists(\"" . $this->engine->options ['compileDir'] . "/\\1.en.php\")) include(\"" .
$this->engine->options ['compileDir'] . "/\\1.en.php\");?>'",
"/". $this->start. "t_include:#([a-z0-9_.]+)#". $this->stop. "/ie",
"'<?php if (file_exists(\"" . $this->engine->options ['templateDir'] .
"/\\1\")) include(\"" . $this->engine->options ['templateDir'] . "/\\1\");?>'",
"/". $this->start. "q_include:#([a-z0-9_.]+)#". $this->stop. "/ie",
"'<?php HTML_Template_Flexy::staticQuickTemplate(\"\\1\",\$t); ?>'",
Documentation generated on Mon, 11 Mar 2019 15:59:57 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|