template improvement: added merge_block_vars method (instead of creating a

new block iteration, it merges given variables with the last block). This
is a trick available to plugins (it will avoid calling trigger_event 
every 2 lines).

git-svn-id: http://piwigo.org/svn/trunk@1587 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices
2006-10-31 03:39:39 +00:00
parent 8c4cb2d09a
commit a26ec603b9
+24
View File
@@ -243,6 +243,30 @@ class Template {
return true;
}
/**
* Block-level variable merge. Merge given variables to the last block
* iteration. This can be called several times per block iteration.
*/
function merge_block_vars($blockname, $vararray)
{
$blocks = explode('.', $blockname);
$blockcount = count($blocks);
$str = '$this->_tpldata';
for ($i = 0; $i < $blockcount; $i++)
{
$str .= '[\'' . $blocks[$i] . '.\']';
eval('$lastiteration = isset('.$str.') ? sizeof('.$str.')-1:-1;');
if ($lastiteration==-1)
{
return false;
}
$str .= '[' . $lastiteration . ']';
}
$str = $str.'=array_merge('.$str.', $vararray);';
eval($str);
return true;
}
/**
* Root-level variable assignment. Adds to current assignments, overriding
* any existing variable assignment with the same name.