function Smarty_Compiler::_compile_smarty_ref in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/lib/smarty/Smarty_Compiler.class.php \Smarty_Compiler::_compile_smarty_ref()
Compiles references of type $smarty.foo
Parameters
string $indexes:
Return value
string
1 call to Smarty_Compiler::_compile_smarty_ref()
- Smarty_Compiler::_parse_var in includes/
moodle/ lib/ smarty/ Smarty_Compiler.class.php - parse variable expression into PHP code
File
- includes/
moodle/ lib/ smarty/ Smarty_Compiler.class.php, line 1968
Class
- Smarty_Compiler
- Template compiling class @package Smarty
Code
function _compile_smarty_ref(&$indexes) {
/* Extract the reference name. */
$_ref = substr($indexes[0], 1);
foreach ($indexes as $_index_no => $_index) {
if ($_index[0] != '.' && $_index_no < 2 || !preg_match('~^(\\.|\\[|->)~', $_index)) {
$this
->_syntax_error('$smarty' . implode('', array_slice($indexes, 0, 2)) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
}
}
switch ($_ref) {
case 'now':
$compiled_ref = 'time()';
$_max_index = 1;
break;
case 'foreach':
array_shift($indexes);
$_var = $this
->_parse_var_props(substr($indexes[0], 1));
$_propname = substr($indexes[1], 1);
$_max_index = 1;
switch ($_propname) {
case 'index':
array_shift($indexes);
$compiled_ref = "(\$this->_foreach[{$_var}]['iteration']-1)";
break;
case 'first':
array_shift($indexes);
$compiled_ref = "(\$this->_foreach[{$_var}]['iteration'] <= 1)";
break;
case 'last':
array_shift($indexes);
$compiled_ref = "(\$this->_foreach[{$_var}]['iteration'] == \$this->_foreach[{$_var}]['total'])";
break;
case 'show':
array_shift($indexes);
$compiled_ref = "(\$this->_foreach[{$_var}]['total'] > 0)";
break;
default:
unset($_max_index);
$compiled_ref = "\$this->_foreach[{$_var}]";
}
break;
case 'section':
array_shift($indexes);
$_var = $this
->_parse_var_props(substr($indexes[0], 1));
$compiled_ref = "\$this->_sections[{$_var}]";
break;
case 'get':
$compiled_ref = $this->request_use_auto_globals ? '$_GET' : "\$GLOBALS['HTTP_GET_VARS']";
break;
case 'post':
$compiled_ref = $this->request_use_auto_globals ? '$_POST' : "\$GLOBALS['HTTP_POST_VARS']";
break;
case 'cookies':
$compiled_ref = $this->request_use_auto_globals ? '$_COOKIE' : "\$GLOBALS['HTTP_COOKIE_VARS']";
break;
case 'env':
$compiled_ref = $this->request_use_auto_globals ? '$_ENV' : "\$GLOBALS['HTTP_ENV_VARS']";
break;
case 'server':
$compiled_ref = $this->request_use_auto_globals ? '$_SERVER' : "\$GLOBALS['HTTP_SERVER_VARS']";
break;
case 'session':
$compiled_ref = $this->request_use_auto_globals ? '$_SESSION' : "\$GLOBALS['HTTP_SESSION_VARS']";
break;
/*
* These cases are handled either at run-time or elsewhere in the
* compiler.
*/
case 'request':
if ($this->request_use_auto_globals) {
$compiled_ref = '$_REQUEST';
break;
}
else {
$this->_init_smarty_vars = true;
}
return null;
case 'capture':
return null;
case 'template':
$compiled_ref = "'{$this->_current_file}'";
$_max_index = 1;
break;
case 'version':
$compiled_ref = "'{$this->_version}'";
$_max_index = 1;
break;
case 'const':
if ($this->security && !$this->security_settings['ALLOW_CONSTANTS']) {
$this
->_syntax_error("(secure mode) constants not permitted", E_USER_WARNING, __FILE__, __LINE__);
return;
}
array_shift($indexes);
if (preg_match('!^\\.\\w+$!', $indexes[0])) {
$compiled_ref = '@' . substr($indexes[0], 1);
}
else {
$_val = $this
->_parse_var_props(substr($indexes[0], 1));
$compiled_ref = '@constant(' . $_val . ')';
}
$_max_index = 1;
break;
case 'config':
$compiled_ref = "\$this->_config[0]['vars']";
$_max_index = 3;
break;
case 'ldelim':
$compiled_ref = "'{$this->left_delimiter}'";
break;
case 'rdelim':
$compiled_ref = "'{$this->right_delimiter}'";
break;
default:
$this
->_syntax_error('$smarty.' . $_ref . ' is an unknown reference', E_USER_ERROR, __FILE__, __LINE__);
break;
}
if (isset($_max_index) && count($indexes) > $_max_index) {
$this
->_syntax_error('$smarty' . implode('', $indexes) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
}
array_shift($indexes);
return $compiled_ref;
}