/** * compiled function plugin : display a constant. Not available in untrusted templates * * <pre>{const 'foo'}</pre> * @param jTplCompiler $compiler the template compiler * @param array $param 0=>$string the constant name * @return string the php code corresponding to the function content */ function jtpl_cfunction_xul_const($compiler, $param = array()) { if (!$compiler->trusted) { $compiler->doError1('errors.tplplugin.untrusted.not.available', 'const'); return ''; } if (count($param) == 1) { return 'echo htmlspecialchars(constant(' . $param[0] . '));'; } else { $compiler->doError2('errors.tplplugin.cfunction.bad.argument.number', 'const', '1'); return ''; } }
/** * a special if block to test easily if the current user is connected * * <pre>{ifuserconnected} ..here generated content if the user is connected {/ifuserconnected}</pre> * @param jTplCompiler $compiler the template compiler * @param boolean $begin true if it is the begin of block, else false * @param array $params no parameters. array should be empty * @return string the php code corresponding to the begin or end of the block */ function jtpl_block_common_ifuserconnected($compiler, $begin, $params = array()) { if ($begin) { if (count($params)) { $content = ''; $compiler->doError1('errors.tplplugin.block.too.many.arguments', 'ifuserconnected'); } else { $content = ' if(jAuth::isConnected()):'; } } else { $content = ' endif; '; } return $content; }
/** * function plugin : include a template into another template * * <pre>{include 'myModule~foo'}</pre> * @param jTplCompiler $compiler the template compiler * @param array $param 0=>$string the template selector (string) * @return string the php code corresponding to the function content */ function jtpl_cfunction_common_include($compiler, $param = array()) { if (!$compiler->trusted) { $compiler->doError1('errors.tplplugin.untrusted.not.available', 'include'); return ''; } if (count($param) == 1) { $compiler->addMetaContent('$t->meta(' . $param[0] . ');'); return '$t->display(' . $param[0] . ');'; } else { $compiler->doError2('errors.tplplugin.cfunction.bad.argument.number', 'include', '1'); return ''; } }
/** * function plugin : generate an event, and listeners are supposed to return template selector, to include * these template * * <pre>{hookinclude 'the_event', $parameters}</pre> * @param jTplCompiler $compiler the template compiler * @param array $param 0=>$the_event the event name, 1=>event parameters * @return string the php code corresponding to the function content */ function jtpl_cfunction_common_hookinclude($compiler, $param = array()) { if (!$compiler->trusted) { $compiler->doError1('errors.tplplugin.untrusted.not.available', 'hookinclude'); return ''; } if (count($param) == 1 || count($param) == 2) { return ' $hookincevents = jEvent::notify(' . $param[0] . ',' . $param[1] . ')->getResponse(); foreach ($hookincevents as $hookincevent) $t->display($hookincevent);'; } else { $compiler->doError2('errors.tplplugin.cfunction.bad.argument.number', 'hookinclude', '1-2'); return ''; } }
/** * a special if block to test easily the current control name * TO BE USED inside a {formcontrols} block * * {ifctrl 'name1','name2',...} some tpl {else} some other tpl {/ifctrl} * @param jTplCompiler $compiler the template compiler * @param boolean $begin true if it is the begin of block, else false * @param array $params 0=>'name',etc. to match against current control name * @return string the php code corresponding to the begin or end of the block */ function jtpl_block_html_ifctrl($compiler, $begin, $params = array()) { if ($begin) { if (count($params) == 0) { $content = ''; $compiler->doError1('errors.tplplugin.block.bad.argument.number', 'ifctrl', '1+'); } else { $content = ' if(isset($t->_privateVars[\'__ctrlref\'])&&('; foreach ($params as $ctrlname) { $content .= '$t->_privateVars[\'__ctrlref\']==' . $ctrlname . ' || '; } $content = substr($content, 0, -4); $content .= ')):'; } } else { $content = ' endif; '; } return $content; }