"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libs/sysplugins/smarty_internal_runtime_tplfunction.php" between
smarty-3.1.32.tar.gz and smarty-3.1.33.tar.gz

About: Smarty is a "compiling" template engine for PHP.

smarty_internal_runtime_tplfunction.php  (smarty-3.1.32):smarty_internal_runtime_tplfunction.php  (smarty-3.1.33)
<?php <?php
/** /**
* TplFunction Runtime Methods callTemplateFunction * TplFunction Runtime Methods callTemplateFunction
* *
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Uwe Tews * @author Uwe Tews
*
**/ **/
class Smarty_Internal_Runtime_TplFunction class Smarty_Internal_Runtime_TplFunction
{ {
/** /**
* Call template function * Call template function
* *
* @param \Smarty_Internal_Template $tpl template object * @param \Smarty_Internal_Template $tpl template object
* @param string $name template function name * @param string $name template function name
* @param array $params parameter array * @param array $params parameter array
* @param bool $nocache true if called nocache * @param bool $nocache true if called nocache
skipping to change at line 39 skipping to change at line 38
$function = $funcParam[ 'call_name' ]; $function = $funcParam[ 'call_name' ];
} else { } else {
if (isset($funcParam[ 'call_name_caching' ])) { if (isset($funcParam[ 'call_name_caching' ])) {
$function = $funcParam[ 'call_name_caching' ]; $function = $funcParam[ 'call_name_caching' ];
} else { } else {
$function = $funcParam[ 'call_name' ]; $function = $funcParam[ 'call_name' ];
} }
} }
if (function_exists($function)) { if (function_exists($function)) {
$this->saveTemplateVariables($tpl, $name); $this->saveTemplateVariables($tpl, $name);
$function ($tpl, $params); $function($tpl, $params);
$this->restoreTemplateVariables($tpl, $name); $this->restoreTemplateVariables($tpl, $name);
return; return;
} }
// try to load template function dynamically // try to load template function dynamically
if ($this->addTplFuncToCache($tpl, $name, $function)) { if ($this->addTplFuncToCache($tpl, $name, $function)) {
$this->saveTemplateVariables($tpl, $name); $this->saveTemplateVariables($tpl, $name);
$function ($tpl, $params); $function($tpl, $params);
$this->restoreTemplateVariables($tpl, $name); $this->restoreTemplateVariables($tpl, $name);
return; return;
} }
} }
throw new SmartyException("Unable to find template function '{$name}'"); throw new SmartyException("Unable to find template function '{$name}'");
} }
/** /**
* Register template functions defined by template * Register template functions defined by template
* *
* @param \Smarty|\Smarty_Internal_Template|\Smarty_Internal_TemplateBase $o bj * @param \Smarty|\Smarty_Internal_Template|\Smarty_Internal_TemplateBase $o bj
* @param array $t * @param array $t
plFunctions source information array of template functions defined in template plFunctions source information array of
* @param bool $o *
verride if true replace existing functions with same name template functions defined
*
in template
* @param bool $o
verride if true replace existing
*
functions with same name
*/ */
public function registerTplFunctions(Smarty_Internal_TemplateBase $obj, $tpl Functions, $override = true) public function registerTplFunctions(Smarty_Internal_TemplateBase $obj, $tpl Functions, $override = true)
{ {
$obj->tplFunctions = $obj->tplFunctions =
$override ? array_merge($obj->tplFunctions, $tplFunctions) : array_m erge($tplFunctions, $obj->tplFunctions); $override ? array_merge($obj->tplFunctions, $tplFunctions) : array_m erge($tplFunctions, $obj->tplFunctions);
// make sure that the template functions are known in parent templates // make sure that the template functions are known in parent templates
if ($obj->_isSubTpl()) { if ($obj->_isSubTpl()) {
$obj->smarty->ext->_tplFunction->registerTplFunctions($obj->parent, $tplFunctions, false); $obj->smarty->ext->_tplFunction->registerTplFunctions($obj->parent, $tplFunctions, false);
} else { } else {
$obj->smarty->tplFunctions = $override ? array_merge($obj->smarty->t plFunctions, $tplFunctions) : $obj->smarty->tplFunctions = $override ? array_merge($obj->smarty->t plFunctions, $tplFunctions) :
skipping to change at line 93 skipping to change at line 95
{ {
if (isset($name)) { if (isset($name)) {
return isset($tpl->tplFunctions[ $name ]) ? $tpl->tplFunctions[ $nam e ] : return isset($tpl->tplFunctions[ $name ]) ? $tpl->tplFunctions[ $nam e ] :
(isset($tpl->smarty->tplFunctions[ $name ]) ? $tpl->smarty->tplF unctions[ $name ] : false); (isset($tpl->smarty->tplFunctions[ $name ]) ? $tpl->smarty->tplF unctions[ $name ] : false);
} else { } else {
return empty($tpl->tplFunctions) ? $tpl->smarty->tplFunctions : $tpl ->tplFunctions; return empty($tpl->tplFunctions) ? $tpl->smarty->tplFunctions : $tpl ->tplFunctions;
} }
} }
/** /**
*
* Add template function to cache file for nocache calls * Add template function to cache file for nocache calls
* *
* @param Smarty_Internal_Template $tpl * @param Smarty_Internal_Template $tpl
* @param string $_name template function name * @param string $_name template function name
* @param string $_function PHP function name * @param string $_function PHP function name
* *
* @return bool * @return bool
*/ */
public function addTplFuncToCache(Smarty_Internal_Template $tpl, $_name, $_f unction) public function addTplFuncToCache(Smarty_Internal_Template $tpl, $_name, $_f unction)
{ {
skipping to change at line 129 skipping to change at line 130
$tplPtr = $tplPtr->parent; $tplPtr = $tplPtr->parent;
} }
// add template function code to cache file // add template function code to cache file
if (isset($tplPtr->cached)) { if (isset($tplPtr->cached)) {
$content = $tplPtr->cached->read($tplPtr); $content = $tplPtr->cached->read($tplPtr);
if ($content) { if ($content) {
// check if we must update file dependency // check if we must update file dependency
if (!preg_match("/'{$funcParam['uid']}'(.*?)'nocache _hash'/", $content, $match2)) { if (!preg_match("/'{$funcParam['uid']}'(.*?)'nocache _hash'/", $content, $match2)) {
$content = preg_replace("/('file_dependency'(.*? )\()/", "\\1{$match1[0]}", $content); $content = preg_replace("/('file_dependency'(.*? )\()/", "\\1{$match1[0]}", $content);
} }
$tplPtr->smarty->ext->_updateCache->write($tplPtr, $tplPtr->smarty->ext->_updateCache->write(
preg_repla $tplPtr,
ce('/\s*\?>\s*$/', "\n", $content) . preg_replace('/\s*\?>\s*$/', "\n", $content) .
"\n" . pre "\n" . preg_replace(
g_replace(array('/^\s*<\?php\s+/', array(
'/^\s*<\?php\s+/',
'/\s*\?>\s*$/',), "\n", '/\s*\?>\s*$/',
),
$match[ 0 ])); "\n",
$match[ 0 ]
)
);
} }
} }
return true; return true;
} }
} }
} }
return false; return false;
} }
/** /**
* Save current template variables on stack * Save current template variables on stack
* *
* @param \Smarty_Internal_Template $tpl * @param \Smarty_Internal_Template $tpl
* @param string $name stack name * @param string $name stack name
*/ */
public function saveTemplateVariables(Smarty_Internal_Template $tpl, $name) public function saveTemplateVariables(Smarty_Internal_Template $tpl, $name)
{ {
$tpl->_cache[ 'varStack' ][] = $tpl->_cache[ 'varStack' ][] =
array('tpl' => $tpl->tpl_vars, 'config' => $tpl->config_vars, 'name' => "_tplFunction_{$name}"); array('tpl' => $tpl->tpl_vars, 'config' => $tpl->config_vars, 'name' => "_tplFunction_{$name}");
} }
/** /**
* Restore saved variables into template objects * Restore saved variables into template objects
* *
* @param \Smarty_Internal_Template $tpl * @param \Smarty_Internal_Template $tpl
* @param string $name stack name * @param string $name stack name
*/ */
public function restoreTemplateVariables(Smarty_Internal_Template $tpl, $nam e) public function restoreTemplateVariables(Smarty_Internal_Template $tpl, $nam e)
{ {
if (isset($tpl->_cache[ 'varStack' ])) { if (isset($tpl->_cache[ 'varStack' ])) {
$vars = array_pop($tpl->_cache[ 'varStack' ]); $vars = array_pop($tpl->_cache[ 'varStack' ]);
$tpl->tpl_vars = $vars[ 'tpl' ]; $tpl->tpl_vars = $vars[ 'tpl' ];
$tpl->config_vars = $vars[ 'config' ]; $tpl->config_vars = $vars[ 'config' ];
} }
} }
} }
 End of changes. 8 change blocks. 
19 lines changed or deleted 26 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)