You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.9 KiB
PHTML
113 lines
3.9 KiB
PHTML
9 years ago
|
<?php
|
||
|
|
||
|
/**
|
||
|
* Smarty Method GetTemplateVars
|
||
|
*
|
||
|
* Smarty::getTemplateVars() method
|
||
|
*
|
||
|
* @package Smarty
|
||
|
* @subpackage PluginsInternal
|
||
|
* @author Uwe Tews
|
||
|
*/
|
||
|
class Smarty_Internal_Method_GetTemplateVars
|
||
|
{
|
||
|
/**
|
||
|
* Valid for all objects
|
||
|
*
|
||
|
* @var int
|
||
|
*/
|
||
|
public $objMap = 7;
|
||
|
|
||
|
/**
|
||
|
* 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
|
||
7 years ago
|
* @param string $varName variable name or null
|
||
|
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
|
||
9 years ago
|
* @param bool $searchParents include parent templates?
|
||
|
*
|
||
|
* @return mixed variable value or or array of variables
|
||
|
*/
|
||
7 years ago
|
public function getTemplateVars(Smarty_Internal_Data $data, $varName = null, Smarty_Internal_Data $_ptr = null,
|
||
|
$searchParents = true)
|
||
9 years ago
|
{
|
||
|
if (isset($varName)) {
|
||
|
$_var = $this->_getVariable($data, $varName, $_ptr, $searchParents, 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)) {
|
||
7 years ago
|
$_result[ $key ] = $var->value;
|
||
9 years ago
|
}
|
||
|
}
|
||
|
// not found, try at parent
|
||
7 years ago
|
if ($searchParents && isset($_ptr->parent)) {
|
||
9 years ago
|
$_ptr = $_ptr->parent;
|
||
|
} else {
|
||
|
$_ptr = null;
|
||
|
}
|
||
|
}
|
||
|
if ($searchParents && isset(Smarty::$global_tpl_vars)) {
|
||
|
foreach (Smarty::$global_tpl_vars AS $key => $var) {
|
||
|
if (!array_key_exists($key, $_result)) {
|
||
7 years ago
|
$_result[ $key ] = $var->value;
|
||
9 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
return $_result;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* gets the object of a Smarty variable
|
||
|
*
|
||
|
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
|
||
7 years ago
|
* @param string $varName the name of the Smarty variable
|
||
|
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
|
||
|
* @param bool $searchParents search also in parent data
|
||
9 years ago
|
* @param bool $errorEnable
|
||
|
*
|
||
|
* @return \Smarty_Variable
|
||
|
*/
|
||
7 years ago
|
public function _getVariable(Smarty_Internal_Data $data, $varName, Smarty_Internal_Data $_ptr = null,
|
||
|
$searchParents = true, $errorEnable = true)
|
||
9 years ago
|
{
|
||
|
if ($_ptr === null) {
|
||
|
$_ptr = $data;
|
||
|
}
|
||
|
while ($_ptr !== null) {
|
||
7 years ago
|
if (isset($_ptr->tpl_vars[ $varName ])) {
|
||
9 years ago
|
// found it, return it
|
||
7 years ago
|
return $_ptr->tpl_vars[ $varName ];
|
||
9 years ago
|
}
|
||
|
// not found, try at parent
|
||
7 years ago
|
if ($searchParents && isset($_ptr->parent)) {
|
||
9 years ago
|
$_ptr = $_ptr->parent;
|
||
|
} else {
|
||
|
$_ptr = null;
|
||
|
}
|
||
|
}
|
||
7 years ago
|
if (isset(Smarty::$global_tpl_vars[ $varName ])) {
|
||
9 years ago
|
// found it, return it
|
||
7 years ago
|
return Smarty::$global_tpl_vars[ $varName ];
|
||
9 years ago
|
}
|
||
7 years ago
|
if ($errorEnable && $data->_getSmartyObj()->error_unassigned) {
|
||
9 years ago
|
// force a notice
|
||
|
$x = $$varName;
|
||
|
}
|
||
|
|
||
|
return new Smarty_Undefined_Variable;
|
||
|
}
|
||
|
}
|