/**
 * 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;
}
Beispiel #2
0
/**
 * 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;
}
Beispiel #3
0
/**
 * 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;
}
/**
 * cfunction plugin :  init a tinymce environnement
 *    
 * @param jTplCompiler $compiler 
 */
function jtpl_cfunction_html_tinymce($compiler, $params = array())
{
    // on génère du code php qui sera intégré dans le template compilé
    $codesource = '$rep = $GLOBALS[\'gJCoord\']->response;
                   if($rep!=null) {
                       $rep->addJSLink(\'js/tinymce/tiny_mce.js\');
                       $rep->addJSCode(\'tinyMCE.init({ mode : "textareas", theme : "simple"});\');
                    } ';
    $compiler->addMetaContent($codesource);
}
/**
 * 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;
}
/**
 * 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 '';
}
/**
 * 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 '';
    }
}
/**
 * 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 :  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 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 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;
}
Beispiel #13
0
/**
 * 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;
}
Beispiel #14
0
 function __construct()
 {
     parent::__construct();
     if (self::$castorPluginsPath === null) {
         $config = new \Jelix\Castor\Config('');
         self::$castorPluginsPath = $config->pluginPathList;
     }
 }
/**
 * swfjs plugin :  Adds html and JS code to display a swf
 *
 * Example :
 * {swfjs 'promobidon.swf',
 *         array('id'=>'promo', 'width'=>150, 'height'=>90, 'detect'=>true),
 *         array('quality'=>'hight', 'wmode'=>'transparent'),
 *         array('longeur'=>150)}
 *     {image 'toupie.png'}
 * {/swfjs}
 *
 * Render after the execution of javascript file :
 *
 * <div id="promo">
 *     <embed width="150" height="90" wmode="transparent" quality="hight"
 *            type="application/x-shockwave-flash" src="/data/fichiers/promobidon.swf"
 *            pluginspage="http://www.adobe.com/go/getflashplayer" flashvars="longeur=150"/>
 * </div>
 *
 * $params[0] url of the swf
 * $params[1]['id'] id of <object .../>
 * $params[1]['class'] class of <object .../>
 * $params[1]['width'] Width final of SWF
 * $params[1]['height'] Height final of SWF
 * $params[1]['version'] (ex: '6.0.65') Detect specific major, minor and revision versions of the Flash plugin.
 * $params[1]['expressinstall'] (true:Bool) Use Express Install, or show an update message if Flash isn't installed.
 *    OR  $params[1]['update'] (false:Bool) Or, degrade silently and gracefully.
 * $params[2][xx] Parameter of the Flash Player
 * $params[3][xx] Flashvar for the Flash Player
 *
 * @param jTplCompiler $compiler the template compiler
 * @param boolean $begin true if it is the begin of block, else false
 * @param array $params parameters for the url
 */
function jtpl_block_html_swfjs($compiler, $begin, $params)
{
    if ($begin) {
        $meta = '
        $resp = jApp::coord()->response
        if( $resp && $resp->getType() ==\'html\') {
            $src = ' . $params[0] . ';
            $options = ' . $params[1] . ';
            $params = ' . $params[2] . ';
            $flashvar = ' . $params[3] . ';

            $script = \'$(function(){\'."\\n";
            $script .= "        ".\'$("#\'.$options[\'id\'].\'").flash({\'."\\n";
            if( !empty($options[\'width\']) )
                $script .= "            ".\'width:"\'.$options[\'width\'].\'",\'."\\n";
            if( !empty($options[\'height\']) )
                $script .= "            ".\'height:"\'.$options[\'height\'].\'",\'."\\n";
            if( count($params) ) foreach($params as $key => $val)
                $script .= "            ".$key.\':"\'.$val.\'", \'."\\r";
            $script .= "            ".\'src:"\'.$src.\'"\'."\\n";
            $script .= "        ".\'}, {\'."\\n";
            if( !empty($options[\'version\']) )
                $script .= "            ".\'version:\'.$options[\'version\'];
            if( !empty($options[\'version\']) && !empty($options[\'detect\']) )
            	$script .= \',\'."\\n";
            if( !empty($options[\'detect\']) )
                $script .= "            ".\'expressInstall:\'.$options[\'detect\'].\'\'."\\n";
            $script .= "        ".\'}, function(htmlOptions) {\'."\\n";
            if( count($flashvar) ) foreach($flashvar as $key => $val)
                $script .= "            ".\'htmlOptions.flashvars.\'.$key.\' = "\'.$val.\'";\'."\\n";
            $script .= "            ".\'$(this).children().remove();\'."\\n";
            $script .= "            ".\'$(this).prepend($.fn.flash.transform(htmlOptions));\'."\\n";
            $script .= "        ".\'});\'."\\n";
            $script .= "    ".\'});\'."\\n";
            $p = jApp::config()->urlengine[\'jqueryPath\']
            $resp->addJSLink($p.\'jquery.js\');
            $resp->addJSLink($p.\'flash/jquery.flash.js\');
            $resp->addJSCode($script);
        }
        ';
        $compiler->addMetaContent($meta);
        $sortie = '
        $options = ' . $params[1] . ';

        $att = \'\';
        $atts = array(\'id\'=>\'\', \'class\'=>\'\');
        $atts = array_intersect_key($options, $atts);
        foreach( $atts as $key => $val ) if( !empty($val) )
            $att .= \' \'.$key.\'="\'.$val.\'"\';
        echo \'<div \'.$att.\'>\';
        ';
        return $sortie;
    } else {
        return 'echo \'</div>\'';
    }
}
/**
 * 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;
}
/**
 * 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;
}
Beispiel #19
0
 /**
  * Return the generated content from the given string template (virtual)
  * @param string $tpl template content
  * @param string $outputtype the type of output (html, text etc..)
  * @param boolean $trusted  says if the template file is trusted or not
  * @param boolean $callMeta false if meta should not be called
  * @return string the generated content
  */
 public function fetchFromString($tpl, $outputtype = '', $trusted = true, $callMeta = true)
 {
     $content = '';
     ob_start();
     try {
         $cachePath = jTplConfig::$cachePath . '/virtuals/';
         require_once JTPL_PATH . 'jTplCompiler.class.php';
         $previousTpl = $this->_templateName;
         $md = 'virtual_' . md5($tpl) . ($trusted ? '_t' : '');
         $this->_templateName = $md;
         if ($outputtype == '') {
             $outputtype = 'html';
         }
         $cachePath .= $outputtype . '_' . $this->_templateName . '.php';
         $mustCompile = jTplConfig::$compilationForce || !file_exists($cachePath);
         if ($mustCompile && !function_exists('template_' . $md)) {
             $compiler = new jTplCompiler();
             $compiler->outputType = $outputtype;
             $compiler->trusted = $trusted;
             $compiler->compileString($tpl, $cachePath, $this->userModifiers, $this->userFunctions, $md);
         }
         require_once $cachePath;
         if ($callMeta) {
             $fct = 'template_meta_' . $md;
             $fct($this);
         }
         $fct = 'template_' . $md;
         $fct($this);
         $content = ob_get_clean();
         $this->_templateName = $previousTpl;
     } catch (exception $e) {
         ob_end_clean();
         throw $e;
     }
     return $content;
 }
Beispiel #20
0
 /**
  * include the compiled template file and call one of the generated function
  * @param string|jSelectorTpl $tpl template selector
  * @param string $outputtype the type of output (html, text etc..)
  * @param boolean $trusted  says if the template file is trusted or not
  * @return string the suffix name of the function to call
  */
 protected function getTemplate($tpl, $outputtype = '', $trusted = true)
 {
     #ifnot JTPL_STANDALONE
     $tpl->userModifiers = $this->userModifiers;
     $tpl->userFunctions = $this->userFunctions;
     jIncluder::inc($tpl);
     return md5($tpl->module . '_' . $tpl->resource . '_' . $tpl->outputType . ($trusted ? '_t' : ''));
     #else
     $tpl = jTplConfig::$templatePath . $tpl;
     if ($outputtype == '') {
         $outputtype = 'html';
     }
     $cachefile = dirname($this->_templateName) . '/';
     if ($cachefile == './') {
         $cachefile = '';
     }
     if (jTplConfig::$cachePath == '/' || jTplConfig::$cachePath == '') {
         throw new Exception('cache path is invalid ! its value is: "' . jTplConfig::$cachePath . '".');
     }
     $cachefile = jTplConfig::$cachePath . $cachefile . $outputtype . ($trusted ? '_t' : '') . '_' . basename($tpl);
     $mustCompile = jTplConfig::$compilationForce || !file_exists($cachefile);
     if (!$mustCompile) {
         if (filemtime($tpl) > filemtime($cachefile)) {
             $mustCompile = true;
         }
     }
     if ($mustCompile) {
         include_once JTPL_PATH . 'jTplCompiler.class.php';
         $compiler = new jTplCompiler();
         $compiler->compile($this->_templateName, $tpl, $outputtype, $trusted, $this->userModifiers, $this->userFunctions);
     }
     require_once $cachefile;
     return md5($tpl . '_' . $outputtype . ($trusted ? '_t' : ''));
     #endif
 }