mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- move $smarty->getTemplateVars() into extension
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
- move $smarty->enableSecurity() into Smarty_Security class
|
||||
- optimize security isTrustedResourceDir()
|
||||
- move auto load filter methods into extension
|
||||
- move $smarty->getTemplateVars() into extension
|
||||
|
||||
27.06.2015
|
||||
- bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64
|
||||
|
@@ -81,6 +81,7 @@ class Smarty_Autoloader
|
||||
'smarty_internal_extension_object' => true,
|
||||
'smarty_internal_extension_loadplugin' => true,
|
||||
'smarty_internal_extension_clearcompiled' => true,
|
||||
'smarty_internal_extension_getvars' => true,
|
||||
'smarty_internal_filter_handler' => true,
|
||||
'smarty_internal_function_call_handler' => true,
|
||||
'smarty_internal_cacheresource_file' => true,
|
||||
|
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.28-dev/14';
|
||||
const SMARTY_VERSION = '3.1.28-dev/15';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -212,41 +212,7 @@ class Smarty_Internal_Data
|
||||
*/
|
||||
public function getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
|
||||
{
|
||||
if (isset($varname)) {
|
||||
$_var = $this->getVariable($varname, $_ptr, $search_parents, false);
|
||||
if (is_object($_var)) {
|
||||
return $_var->value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
$_result = array();
|
||||
if ($_ptr === null) {
|
||||
$_ptr = $this;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return Smarty_Internal_Extension_GetVars::getTemplateVars($this, $varname, $_ptr, $search_parents);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -308,32 +274,7 @@ class Smarty_Internal_Data
|
||||
*/
|
||||
public function getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true)
|
||||
{
|
||||
if ($_ptr === null) {
|
||||
$_ptr = $this;
|
||||
}
|
||||
while ($_ptr !== null) {
|
||||
if (isset($_ptr->tpl_vars[$variable])) {
|
||||
// found it, return it
|
||||
return $_ptr->tpl_vars[$variable];
|
||||
}
|
||||
// not found, try at parent
|
||||
if ($search_parents) {
|
||||
$_ptr = $_ptr->parent;
|
||||
} else {
|
||||
$_ptr = null;
|
||||
}
|
||||
}
|
||||
if (isset(Smarty::$global_tpl_vars[$variable])) {
|
||||
// found it, return it
|
||||
return Smarty::$global_tpl_vars[$variable];
|
||||
}
|
||||
$smarty = isset($this->smarty) ? $this->smarty : $this;
|
||||
if ($smarty->error_unassigned && $error_enable) {
|
||||
// force a notice
|
||||
$x = $$variable;
|
||||
}
|
||||
|
||||
return new Smarty_Undefined_Variable;
|
||||
return Smarty_Internal_Extension_GetVars::getVariable($this, $variable, $_ptr, $search_parents, $error_enable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
103
libs/sysplugins/smarty_internal_extension_getvars.php
Normal file
103
libs/sysplugins/smarty_internal_extension_getvars.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Extension GetVars
|
||||
*
|
||||
* Auto load filter methods
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_Internal_Extension_GetVars
|
||||
{
|
||||
/**
|
||||
* Returns a single or all template variables
|
||||
*
|
||||
* @param $obj
|
||||
* @param string $varname variable name or null
|
||||
* @param object $_ptr optional pointer to data object
|
||||
* @param boolean $search_parents include parent templates?
|
||||
*
|
||||
* @return string variable value or or array of variables
|
||||
*/
|
||||
public static function getTemplateVars($obj, $varname, $_ptr, $search_parents)
|
||||
{
|
||||
if (isset($varname)) {
|
||||
$_var = self::getVariable($obj, $varname, $_ptr, $search_parents, false);
|
||||
if (is_object($_var)) {
|
||||
return $_var->value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
$_result = array();
|
||||
if ($_ptr === null) {
|
||||
$_ptr = $obj;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the object of a Smarty variable
|
||||
*
|
||||
* @param $obj
|
||||
* @param string $variable the name of the Smarty variable
|
||||
* @param object $_ptr optional pointer to data object
|
||||
* @param boolean $search_parents search also in parent data
|
||||
* @param bool $error_enable
|
||||
*
|
||||
* @return object the object of the variable
|
||||
*/
|
||||
public static function getVariable($obj, $variable, $_ptr, $search_parents, $error_enable)
|
||||
{
|
||||
if ($_ptr === null) {
|
||||
$_ptr = $obj;
|
||||
}
|
||||
while ($_ptr !== null) {
|
||||
if (isset($_ptr->tpl_vars[$variable])) {
|
||||
// found it, return it
|
||||
return $_ptr->tpl_vars[$variable];
|
||||
}
|
||||
// not found, try at parent
|
||||
if ($search_parents) {
|
||||
$_ptr = $_ptr->parent;
|
||||
} else {
|
||||
$_ptr = null;
|
||||
}
|
||||
}
|
||||
if (isset(Smarty::$global_tpl_vars[$variable])) {
|
||||
// found it, return it
|
||||
return Smarty::$global_tpl_vars[$variable];
|
||||
}
|
||||
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
|
||||
if ($smarty->error_unassigned && $error_enable) {
|
||||
// force a notice
|
||||
$x = $$variable;
|
||||
}
|
||||
|
||||
return new Smarty_Undefined_Variable;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user