<commit_before><?php
/**
* @package      jelix
* @subpackage   jtpl_plugin
* @author       <NAME>
* @contributor  <NAME>, <NAME>
* @copyright    2007-2010 <NAME>, 2007 <NAME>
* @copyright    2008 <NAME>
* @link         http://www.jelix.org
* @licence      GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
*/

/**
 * function plugin :  print the value of a form control. You should use this plugin inside a formcontrols block
 *
 * @param jTpl $tpl template engine
 * @param string $ctrlname  the name of the control to display (required if it is outside a formcontrols)
 * @param string $sep  separator to display values of a multi-value control
 */
function jtpl_function_html_ctrl_value($tpl, $ctrlname='', $sep =', '){

    if( (!isset($tpl->_privateVars['__ctrlref']) || $tpl->_privateVars['__ctrlref'] == '') && $ctrlname =='') {
        return;
    }
    $insideForm = isset($tpl->_privateVars['__formbuilder']);

    if($ctrlname =='') {
        $ctrl = $tpl->_privateVars['__ctrl'];
        $tpl->_privateVars['__displayed_ctrl'][$ctrlname] = true;
        $ctrlname = $tpl->_privateVars['__ctrlref'];
    } else {
        $ctrls = $tpl->_privateVars['__form']->getControls();
        if (!isset($ctrls[$ctrlname])) {
            throw new jException('jelix~formserr.unknown.control',
                array($ctrlname, $tpl->_privateVars['__form']->getSelector(),$tpl->_templateName));
        }
        $ctrl = $ctrls[$ctrlname];
    }

    $tpl->_privateVars['__displayed_ctrl'][$ctrlname] = true;

    if($ctrl->type == 'hidden' || $ctrl->type == 'captcha')
        return;

    if($ctrl->type == 'submit'  && ($ctrl->standalone || $insideForm))
        return;

    if($ctrl->type == 'reset' && $insideForm){
        return;
    }

    if(!$tpl->_privateVars['__form']->isActivated($ctrlname))
        return;

    $value = $tpl->_privateVars['__form']->getData($ctrlname);
    $value = $ctrl->getDisplayValue($value);
    if(is_array($value)){
        $s ='';
        foreach($value as $v){
            $s.=$sep.htmlspecialchars($v);
        }
        echo substr($s, strlen($sep));
    }elseif($ctrl->isHtmlContent())
        echo $value;
    else if($ctrl->type == 'textarea')
        echo nl2br(htmlspecialchars($value));
    else
        echo htmlspecialchars($value);
}<commit_msg>jForms - improved the output of values. WIP.<commit_after><?php
/**
* @package      jelix
* @subpackage   jtpl_plugin
* @author       <NAME>
* @contributor  <NAME>, <NAME>
* @copyright    2007-2010 <NAME>, 2007 <NAME>
* @copyright    2008 <NAME>
* @link         http://www.jelix.org
* @licence      GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
*/

/**
 * function plugin :  print the value of a form control. You should use this plugin inside a formcontrols block
 *
 * @param jTpl $tpl template engine
 * @param string $ctrlname  the name of the control to display (required if it is outside a formcontrols)
 * @param string $sep  separator to display values of a multi-value control
 */
function jtpl_function_html_ctrl_value($tpl, $ctrlname='', $sep =', '){

    if( (!isset($tpl->_privateVars['__ctrlref']) || $tpl->_privateVars['__ctrlref'] == '') && $ctrlname =='') {
        return;
    }
    $insideForm = isset($tpl->_privateVars['__formbuilder']);

    if($ctrlname =='') {
        $ctrl = $tpl->_privateVars['__ctrl'];
        $tpl->_privateVars['__displayed_ctrl'][$ctrlname] = true;
        $ctrlname = $tpl->_privateVars['__ctrlref'];
    } else {
        $ctrls = $tpl->_privateVars['__form']->getControls();
        if (!isset($ctrls[$ctrlname])) {
            throw new jException('jelix~formserr.unknown.control',
                array($ctrlname, $tpl->_privateVars['__form']->getSelector(),$tpl->_templateName));
        }
        $ctrl = $ctrls[$ctrlname];
    }

    $tpl->_privateVars['__displayed_ctrl'][$ctrlname] = true;

    if($ctrl->type == 'hidden' || $ctrl->type == 'captcha')
        return;

    if($ctrl->type == 'submit'  && ($ctrl->standalone || $insideForm))
        return;

    if($ctrl->type == 'reset' && $insideForm){
        return;
    }

    $form = $tpl->_privateVars['__form'];
    if(!$form->isActivated($ctrlname))
        return;
    $c = 'jFormsBuilderBase';

    if ($form instanceof $c || !$insideForm) {
        $value = $tpl->_privateVars['__form']->getData($ctrlname);
        $value = $ctrl->getDisplayValue($value);
        if(is_array($value)){
            $s ='';
            foreach($value as $v){
                $s.=$sep.htmlspecialchars($v);
            }
            echo substr($s, strlen($sep));
        }elseif($ctrl->isHtmlContent())
            echo $value;
        else if($ctrl->type == 'textarea')
            echo nl2br(htmlspecialchars($value));
        else
            echo htmlspecialchars($value);
    }
    else {
        $tpl->_privateVars['__formbuilder']->outputControlValue($ctrl, (is_array($sep)?$sep:array()));
    }

}
{'fraction_non_alphanumeric': 0.17467948717948717, 'fraction_numerical': 0.006810897435897436, 'mean_word_length': 2.9532858273950913, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5741395', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1586, 'n_words': 326}