/** * assigns values to template variables by reference * * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param string $tpl_var the template variable name * @param $value * @param boolean $nocache if true any output of this variable will be not cached * * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty */ public function assignByRef(Smarty_Internal_Data $data, $tpl_var, &$value, $nocache) { if ($tpl_var != '') { $data->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); $data->tpl_vars[$tpl_var]->value =& $value; if ($data->_isTplObj() && $data->scope) { $data->ext->_updateScope->_updateScope($data, $tpl_var); } } return $data; }
/** * load a config file, optionally load just selected sections * * @api Smarty::configLoad() * @link http://www.smarty.net/docs/en/api.config.load.tpl * * @param \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template $data * @param string $config_file filename * @param mixed $sections array of section names, single * section or null * @param int $scope scope into which config variables * shall be loaded * * @return \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template * @throws \SmartyException */ public function _loadConfigFile(Smarty_Internal_Data $data, $config_file, $sections = null, $scope = 0) { /* @var \Smarty $smarty */ $smarty = $data->_getSmartyObj(); /* @var \Smarty_Internal_Template $confObj */ $confObj = new Smarty_Internal_Template($config_file, $smarty, $data, null, null, null, null, true); $confObj->caching = Smarty::CACHING_OFF; $confObj->source->config_sections = $sections; $confObj->source->scope = $scope; $confObj->compiled = Smarty_Template_Compiled::load($confObj); $confObj->compiled->render($confObj); if ($data->_isTplObj()) { $data->compiled->file_dependency[$confObj->source->uid] = array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type); } }
/** * appends values to template variables by reference * * @api Smarty::appendByRef() * @link http://www.smarty.net/docs/en/api.append.by.ref.tpl * * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param string $tpl_var the template variable name * @param mixed &$value the referenced value to append * @param bool $merge flag if array elements shall be merged * * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty */ public static function appendByRef(Smarty_Internal_Data $data, $tpl_var, &$value, $merge = false) { if ($tpl_var != '' && isset($value)) { if (!isset($data->tpl_vars[$tpl_var])) { $data->tpl_vars[$tpl_var] = new Smarty_Variable(); } if (!is_array($data->tpl_vars[$tpl_var]->value)) { settype($data->tpl_vars[$tpl_var]->value, 'array'); } if ($merge && is_array($value)) { foreach ($value as $_key => $_val) { $data->tpl_vars[$tpl_var]->value[$_key] =& $value[$_key]; } } else { $data->tpl_vars[$tpl_var]->value[] =& $value; } if ($data->_isTplObj() && $data->scope) { $data->ext->_updateScope->_updateScope($data, $tpl_var); } } return $data; }
/** * Returns a single or all template variables * * @api Smarty::getTemplateVars() * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl * * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param string $varname variable name or null * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object * @param bool $search_parents include parent templates? * * @return mixed variable value or or array of variables */ public function getTemplateVars(Smarty_Internal_Data $data, $varname = null, Smarty_Internal_Data $_ptr = null, $search_parents = true) { if (isset($varname)) { $_var = $data->_getVariable($varname, $_ptr, $search_parents, false); if (is_object($_var)) { return $_var->value; } else { return null; } } else { $_result = array(); if ($_ptr === null) { $_ptr = $data; } while ($_ptr !== null) { foreach ($_ptr->tpl_vars as $key => $var) { if (!array_key_exists($key, $_result)) { $_result[$key] = $var->value; } } // not found, try at parent if ($search_parents) { $_ptr = $_ptr->parent; } else { $_ptr = null; } } if ($search_parents && isset(Smarty::$global_tpl_vars)) { foreach (Smarty::$global_tpl_vars as $key => $var) { if (!array_key_exists($key, $_result)) { $_result[$key] = $var->value; } } } return $_result; } }
/** * Follow the parent chain an merge template and config variables * * @param \Smarty_Internal_Data|null $data */ public function _mergeVars(Smarty_Internal_Data $data = null) { if (isset($data)) { if (!empty($this->tpl_vars)) { $data->tpl_vars = array_merge($this->tpl_vars, $data->tpl_vars); } if (!empty($this->config_vars)) { $data->config_vars = array_merge($this->config_vars, $data->config_vars); } } else { $data = $this; } if (isset($this->parent)) { $this->parent->_mergeVars($data); } }
/** * create Smarty data object * * @param Smarty|array $_parent parent template * @param Smarty|Smarty_Internal_Template $smarty global smarty instance * @param string $name optional data block name * * @throws SmartyException */ public function __construct($_parent = null, $smarty = null, $name = null) { parent::__construct(); self::$count++; $this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count); $this->smarty = $smarty; if (is_object($_parent)) { // when object set up back pointer $this->parent = $_parent; } elseif (is_array($_parent)) { // set up variable values foreach ($_parent as $_key => $_val) { $this->tpl_vars[$_key] = new Smarty_Variable($_val); } } elseif ($_parent != null) { throw new SmartyException("Wrong type for template variables"); } }