/** * Display a full form without the use of other plugins. * usage : {formfull $theformobject,'submit_action', $submit_action_params} * * You can add this others parameters :<ul> * <li>string $builderName (default is 'html')</li> * <li>array $options for the builder. Example, for the 'html' builder : <ul> * <li>"errorDecorator"=>"name of your javascript object for error listener"</li> * <li>"method" => "post" or "get". default is "post"</li> * </ul> * </li> * </ul> * @param jTplCompiler $compiler the template compiler * @param array $param 0=>form object * 1=>selector of submit action * 2=>array of parameters for submit action * 3=>name of the builder : default is html * 4=>array of options for the builder * @return string the php code corresponding to the begin or end of the block */ function jtpl_cfunction_html_formfull($compiler, $params = array()) { global $gJConfig; if (count($params) < 2 || count($params) > 5) { $compiler->doError2('errors.tplplugin.cfunction.bad.argument.number', 'formfull', '2-5'); } if (isset($params[3]) && trim($params[3]) != '""' && trim($params[3]) != "''") { $builder = $params[3]; } else { $builder = "'" . $gJConfig->tplplugins['defaultJformsBuilder'] . "'"; } $compiler->addMetaContent('if(isset(' . $params[0] . ')) { ' . $params[0] . '->getBuilder(' . $builder . ')->outputMetaContent($t);}'); if (count($params) == 2) { $params[2] = 'array()'; } if (isset($params[4])) { $options = $params[4]; } else { $options = "array()"; } $content = ' $formfull = ' . $params[0] . '; $formfullBuilder = $formfull->getBuilder(' . $builder . '); $formfullBuilder->setAction(' . $params[1] . ',' . $params[2] . '); $formfullBuilder->outputHeader(' . $options . '); $formfullBuilder->outputAllControls(); $formfullBuilder->outputFooter();'; return $content; }
/** * a block to display only data of a form * * usage : {formdata $theformobject} here the form content {/formdata} * * @param jTplCompiler $compiler the template compiler * @param boolean $begin true if it is the begin of block, else false * @param array $param 0=>form object * @param array $param 0=>form object * 2=>name of the builder : default is html * 3=>array of options for the builder * @return string the php code corresponding to the begin or end of the block * @see jForms * @since 1.0.1 */ function jtpl_block_html_formdata($compiler, $begin, $param = array()) { if (!$begin) { return ' unset($t->_privateVars[\'__form\']); unset($t->_privateVars[\'__formbuilder\']); unset($t->_privateVars[\'__formViewMode\']); unset($t->_privateVars[\'__displayed_ctrl\']);'; } if (count($param) < 1 || count($param) > 3) { $compiler->doError2('errors.tplplugin.block.bad.argument.number', 'formdata', '1-3'); return ''; } if (isset($param[1]) && trim($param[1]) != '""' && trim($param[1]) != "''") { $builder = $param[1]; } else { $builder = "'" . jApp::config()->tplplugins['defaultJformsBuilder'] . "'"; } if (isset($param[2])) { $options = $param[2]; } else { $options = "array()"; } $content = ' $t->_privateVars[\'__form\'] = ' . $param[0] . '; $t->_privateVars[\'__formViewMode\'] = 1; $t->_privateVars[\'__formbuilder\'] = $t->_privateVars[\'__form\']->getBuilder(' . $builder . '); $t->_privateVars[\'__formbuilder\']->setOptions(' . $options . '); $t->_privateVars[\'__displayed_ctrl\'] = array(); '; return $content; }
/** * a block to display an html form, with data from a jforms * * usage : {form $theformobject,'submit_action', $submit_action_params} here form content {/form} * * You can add this others parameters :<ul> * <li>string $builderName (default is 'html')</li> * <li>array $options for the builder. Example, for the 'html' builder : <ul> * <li>"errorDecorator"=>"name of your javascript object for error listener"</li> * <li>"method" => "post" or "get". default is "post"</li> * </ul> * </li> * </ul> * * @param jTplCompiler $compiler the template compiler * @param boolean $begin true if it is the begin of block, else false * @param array $param 0=>form object * 1=>selector of submit action * 2=>array of parameters for submit action * 3=>name of the builder : default is html * 4=>array of options for the builder * @return string the php code corresponding to the begin or end of the block * @see jForms */ function jtpl_block_html_form($compiler, $begin, $param = array()) { global $gJConfig; if (!$begin) { return '$t->_privateVars[\'__formbuilder\']->outputFooter(); unset($t->_privateVars[\'__form\']); unset($t->_privateVars[\'__formbuilder\']); unset($t->_privateVars[\'__displayed_ctrl\']);'; } if (count($param) < 2 || count($param) > 5) { $compiler->doError2('errors.tplplugin.block.bad.argument.number', 'form', '2-5'); return ''; } if (count($param) == 2) { $param[2] = 'array()'; } if (isset($param[3]) && trim($param[3]) != '""' && trim($param[3]) != "''") { $builder = $param[3]; } else { $builder = "'" . $gJConfig->tplplugins['defaultJformsBuilder'] . "'"; } if (isset($param[4])) { $options = $param[4]; } else { $options = "array()"; } $content = ' $t->_privateVars[\'__form\'] = ' . $param[0] . '; $t->_privateVars[\'__formbuilder\'] = $t->_privateVars[\'__form\']->getBuilder(' . $builder . '); $t->_privateVars[\'__formbuilder\']->setAction(' . $param[1] . ',' . $param[2] . '); $t->_privateVars[\'__formbuilder\']->outputHeader(' . $options . '); $t->_privateVars[\'__displayed_ctrl\'] = array(); '; $compiler->addMetaContent('if(isset(' . $param[0] . ')) { ' . $param[0] . '->getBuilder(' . $builder . ')->outputMetaContent($t);}'); return $content; }
/** * cfunction to fetch the content of a zone into a tpl var * * <pre> {fetchzone 'myVar', 'myModule~myzone', array('foo'=>'bar)} * {if $myVar !== ''} * <div id="container"> * {$myVar} * </div> * {/if}</pre> * @param jTplCompiler $compiler the template compiler * @param array $param 0=>$string the name of the tpl var that will hold the zone's content * 1=>$string the zone selector (string) * 2=>$params parameters for the zone (array) * @return string the php code corresponding to the function content */ function jtpl_cfunction_common_fetchzone($compiler, $params = array()) { if (count($params) == 3) { return '$t->_vars[' . $params[0] . '] = jZone::get(' . $params[1] . ',' . $params[2] . ');'; } else { if (count($params) == 2) { return '$t->_vars[' . $params[0] . '] = jZone::get(' . $params[1] . ');'; } } $compiler->doError2('errors.tplplugin.cfunction.bad.argument.number', 'fetchzone', '2-3'); return ''; }
/** * cfunction plugin : include the content of a zone * * <pre> {zone 'myModule~myzone'} * {zone 'myModule~myzone',array('foo'=>'bar)}</pre> * @param jTplCompiler $compiler the template compiler * @param array $param 0=>$string the zone selector (string) * 1=>$params parameters for the zone (array) * @return string the php code corresponding to the function content */ function jtpl_cfunction_common_zone($compiler, $params = array()) { if (count($params) == 2) { $content = 'echo jZone::get(' . $params[0] . ',' . $params[1] . ');'; } elseif (count($params) == 1) { $content = 'echo jZone::get(' . $params[0] . ');'; } else { $content = ''; $compiler->doError2('errors.tplplugin.cfunction.bad.argument.number', 'zone', '1-2'); } return $content; }
/** * 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 ''; } }
/** * 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 a right value * * <pre>{ifnotacl2 'subject',54} ..here generated content if the user has NOT the right {/ifnotacl2}</pre> * @param jTplCompiler $compiler the template compiler * @param boolean $begin true if it is the begin of block, else false * @param array $params 0=>subject 1=>optional resource * @return string the php code corresponding to the begin or end of the block */ function jtpl_block_common_ifnotacl2($compiler, $begin, $params = array()) { if ($begin) { if (count($params) == 1) { $content = ' if(!jAcl2::check(' . $params[0] . ')):'; } elseif (count($params) == 2) { $content = ' if(!jAcl2::check(' . $params[0] . ',' . $params[1] . ')):'; } else { $content = ''; $compiler->doError2('errors.tplplugin.block.bad.argument.number', 'ifnotacl2', 1); } } else { $content = ' endif; '; } return $content; }
/** * a special if block to test easily a right value * * <pre>{ifacl 'subject','value', 54} ..here generated content if the user has the right {/ifacl}</pre> * @param jTplCompiler $compiler the template compiler * @param boolean true if it is the begin of block, else false * @param $param array 0=>subject 1=>right value 2=>optional resource * @return string the php code corresponding to the begin or end of the block */ function jtpl_block_common_ifacl($compiler, $begin, $param = array()) { if ($begin) { if (count($param) == 2) { $content = ' if(jAcl::check(' . $param[0] . ',' . $param[1] . ')):'; } elseif (count($param) == 3) { $content = ' if(jAcl::check(' . $param[0] . ',' . $param[1] . ',' . $param[2] . ')):'; } else { $content = ''; $compiler->doError2('errors.tplplugin.block.bad.argument.number', 'ifacl', 2); } } else { $content = ' endif; '; } return $content; }
/** * a block to display only data of a form * * usage : {formdata $theformobject} here the form content {/formdata} * * @param jTplCompiler $compiler the template compiler * @param boolean $begin true if it is the begin of block, else false * @param array $param 0=>form object * @return string the php code corresponding to the begin or end of the block * @see jForms * @since 1.0.1 */ function jtpl_block_html_formdata($compiler, $begin, $param = array()) { if (!$begin) { return ' unset($t->_privateVars[\'__form\']); unset($t->_privateVars[\'__displayed_ctrl\']);'; } if (count($param) != 1) { $compiler->doError2('errors.tplplugin.block.bad.argument.number', 'formdata', 1); return ''; } $content = ' $t->_privateVars[\'__form\'] = ' . $param[0] . '; $t->_privateVars[\'__displayed_ctrl\'] = array(); '; return $content; }
/** * a block to loop over submit button list of a form and to display them * * usage : {formsubmits} here content to display one submit {/formsubmits} * It accept also some parameters * 1) an optional jFormsBase object if the {formsubmits} is outside a {form} block * 2) an optional array of submit control names : only these controls will be displayed * * @param jTplCompiler $compiler the template compiler * @param boolean $begin true if it is the begin of block, else false * @param array $param empty array * or 0=>jFormsBase object * or 0=>jFormsBase object, 1=>array of submit names * or 0=>array of submit names * @return string the php code corresponding to the begin or end of the block * @see jForms */ function jtpl_block_html_formsubmits($compiler, $begin, $param = array()) { if (!$begin) { return '}} $t->_privateVars[\'__submitref\']=\'\';'; // if, foreach } if (count($param) > 2) { $compiler->doError2('errors.tplplugin.block.bad.argument.number', 'formsubmits', 2); return ''; } if (count($param)) { if (count($param) == 1) { $content = 'if(is_array(' . $param[0] . ')){ $submits_to_display = ' . $param[0] . '; } else { $t->_privateVars[\'__form\'] = ' . $param[0] . '; $submits_to_display=null; }'; } else { $content = ' $t->_privateVars[\'__form\'] = ' . $param[0] . ";\n"; $content .= ' $submits_to_display = ' . $param[1] . '; '; } } else { $content = '$submits_to_display=null;'; } $content .= ' if (!isset($t->_privateVars[\'__displayed_submits\'])) { $t->_privateVars[\'__displayed_submits\'] = array(); } $t->_privateVars[\'__submitref\']=\'\'; foreach($t->_privateVars[\'__form\']->getSubmits() as $ctrlref=>$ctrl){ if(!$t->_privateVars[\'__form\']->isActivated($ctrlref)) continue; if(!isset($t->_privateVars[\'__displayed_submits\'][$ctrlref]) && ( $submits_to_display===null || in_array($ctrlref, $submits_to_display))){ $t->_privateVars[\'__submitref\'] = $ctrlref; $t->_privateVars[\'__submit\'] = $ctrl; '; return $content; }
/** * a block to loop over controls list of a form and to display them * * usage : {formcontrols} here content to display one control {/formcontrols} * It accept also some parameters * 1) an optional jFormsBase object if the {formcontrols} is outside a {form} block * 2) an optional array of control names : only these controls will be displayed * * @param jTplCompiler $compiler the template compiler * @param boolean $begin true if it is the begin of block, else false * @param array $param empty array * or 0=>jFormsBase object * or 0=>jFormsBase object, 1=>array of control names * or 0=>array of control names * @return string the php code corresponding to the begin or end of the block * @see jForms */ function jtpl_block_html_formcontrols($compiler, $begin, $param = array()) { if (!$begin) { return '}} $t->_privateVars[\'__ctrlref\']=\'\';'; // if, foreach } if (count($param) > 3) { $compiler->doError2('errors.tplplugin.block.bad.argument.number', 'formcontrols', 3); return ''; } if (count($param)) { if (count($param) == 1) { $content = 'if(is_array(' . $param[0] . ')){ $ctrls_to_display = ' . $param[0] . '; $ctrls_notto_display = null; } else { $t->_privateVars[\'__form\'] = ' . $param[0] . '; $ctrls_to_display=null; $ctrls_notto_display = null; }'; } elseif (count($param) == 2) { $content = 'if(is_array(' . $param[0] . ') || ' . $param[0] . ' === null){ $ctrls_to_display = ' . $param[0] . '; $ctrls_notto_display = ' . $param[1] . '; } else { $t->_privateVars[\'__form\'] = ' . $param[0] . '; $ctrls_to_display=' . $param[1] . '; $ctrls_notto_display = null; }'; } else { $content = ' $t->_privateVars[\'__form\'] = ' . $param[0] . ";\n"; $content .= ' $ctrls_to_display = ' . $param[1] . '; '; $content .= ' $ctrls_notto_display = ' . $param[2] . '; '; } } else { $content = '$ctrls_to_display=null;'; $content .= '$ctrls_notto_display=null;'; } $_frmctrlInsideForm = $compiler->isInsideBlock('form'); $content .= ' if (!isset($t->_privateVars[\'__formbuilder\'])) { $t->_privateVars[\'__formViewMode\'] = 1; $t->_privateVars[\'__formbuilder\'] = $t->_privateVars[\'__form\']->getBuilder(\'html\'); } if (!isset($t->_privateVars[\'__displayed_ctrl\'])) { $t->_privateVars[\'__displayed_ctrl\'] = array(); } $t->_privateVars[\'__ctrlref\']=\'\'; '; $content .= ' foreach($t->_privateVars[\'__form\']->getRootControls() as $ctrlref=>$ctrl){ if(!$t->_privateVars[\'__form\']->isActivated($ctrlref)) continue; if($ctrl->type == \'reset\' || $ctrl->type == \'hidden\') continue;' . "\n"; if (!$_frmctrlInsideForm) { $content .= 'if($ctrl->type == \'submit\' && $ctrl->standalone) continue; if($ctrl->type == \'captcha\' || $ctrl->type == \'secretconfirm\') continue;' . "\n"; } else { $content .= 'if($ctrl->type == \'submit\') continue;'; } $content .= 'if(!isset($t->_privateVars[\'__displayed_ctrl\'][$ctrlref]) && ( ($ctrls_to_display===null && $ctrls_notto_display === null) || ($ctrls_to_display===null && !in_array($ctrlref, $ctrls_notto_display)) || (is_array($ctrls_to_display) && in_array($ctrlref, $ctrls_to_display) ))) { $t->_privateVars[\'__ctrlref\'] = $ctrlref; $t->_privateVars[\'__ctrl\'] = $ctrl; '; return $content; }