mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
add support for restriction to registered methods
This commit is contained in:
@@ -338,10 +338,12 @@ class Smarty
|
|||||||
Function: register_object
|
Function: register_object
|
||||||
Purpose: Registers object to be used in templates
|
Purpose: Registers object to be used in templates
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function register_object($object, &$object_impl, $smarty_args = true)
|
function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true)
|
||||||
{
|
{
|
||||||
|
settype($allowed, 'array');
|
||||||
|
settype($smarty_args, 'boolean');
|
||||||
$this->_reg_objects[$object] =
|
$this->_reg_objects[$object] =
|
||||||
array(&$object_impl, $smarty_args);
|
array(&$object_impl, $allowed, $smarty_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
@@ -1908,7 +1910,7 @@ function _run_insert_handler($args)
|
|||||||
if (isset($plugin)) {
|
if (isset($plugin)) {
|
||||||
if (!$plugin[3]) {
|
if (!$plugin[3]) {
|
||||||
if (!function_exists($plugin[0])) {
|
if (!function_exists($plugin[0])) {
|
||||||
$this->_trigger_plugin_error("$type '$name' is not implemented", $tpl_file, $tpl_line);
|
$this->_trigger_fatal_error("[plugin] $type '$name' is not implemented", $tpl_file, $tpl_line, __FILE__, __LINE__);
|
||||||
} else {
|
} else {
|
||||||
$plugin[1] = $tpl_file;
|
$plugin[1] = $tpl_file;
|
||||||
$plugin[2] = $tpl_line;
|
$plugin[2] = $tpl_line;
|
||||||
@@ -1944,7 +1946,7 @@ function _run_insert_handler($args)
|
|||||||
|
|
||||||
$plugin_func = 'smarty_' . $type . '_' . $name;
|
$plugin_func = 'smarty_' . $type . '_' . $name;
|
||||||
if (!function_exists($plugin_func)) {
|
if (!function_exists($plugin_func)) {
|
||||||
$this->_trigger_plugin_error("plugin function $plugin_func() not found in $plugin_file", $tpl_file, $tpl_line, __FILE__, __LINE__);
|
$this->_trigger_fatal_error("[plugin] function $plugin_func() not found in $plugin_file", $tpl_file, $tpl_line, __FILE__, __LINE__);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1989,7 +1991,7 @@ function _run_insert_handler($args)
|
|||||||
$this->_plugins[$type][$name] = array($plugin_func, $tpl_file, $tpl_line, true);
|
$this->_plugins[$type][$name] = array($plugin_func, $tpl_file, $tpl_line, true);
|
||||||
} else {
|
} else {
|
||||||
// output error
|
// output error
|
||||||
$this->_trigger_plugin_error($message, $tpl_file, $tpl_line, __FILE__, __LINE__);
|
$this->_trigger_fatal_error('[plugin] ' . $message, $tpl_file, $tpl_line, __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2020,7 +2022,7 @@ function _run_insert_handler($args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$plugin[1]) {
|
if (!$plugin[1]) {
|
||||||
$this->_trigger_plugin_error("resource '$type' is not implemented", null, null, __FILE__, __LINE__);
|
$this->_trigger_fatal_error("[plugin] resource '$type' is not implemented", null, null, __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -2043,7 +2045,7 @@ function _run_insert_handler($args)
|
|||||||
foreach ($resource_ops as $op) {
|
foreach ($resource_ops as $op) {
|
||||||
$plugin_func = 'smarty_resource_' . $type . '_' . $op;
|
$plugin_func = 'smarty_resource_' . $type . '_' . $op;
|
||||||
if (!function_exists($plugin_func)) {
|
if (!function_exists($plugin_func)) {
|
||||||
$this->_trigger_plugin_error("plugin function $plugin_func() not found in $plugin_file", null, null, __FILE__, __LINE__);
|
$this->_trigger_fatal_error("[plugin] function $plugin_func() not found in $plugin_file", null, null, __FILE__, __LINE__);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
$resource_funcs[] = $plugin_func;
|
$resource_funcs[] = $plugin_func;
|
||||||
@@ -2078,10 +2080,10 @@ function _run_insert_handler($args)
|
|||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _trigger_plugin_error
|
Function: _trigger_fatal_error
|
||||||
Purpose: trigger Smarty plugin error
|
Purpose: trigger Smarty plugin error
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function _trigger_plugin_error($error_msg, $tpl_file = null, $tpl_line = null,
|
function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null,
|
||||||
$file = null, $line = null, $error_type = E_USER_ERROR)
|
$file = null, $line = null, $error_type = E_USER_ERROR)
|
||||||
{
|
{
|
||||||
if(isset($file) && isset($line)) {
|
if(isset($file) && isset($line)) {
|
||||||
@@ -2090,10 +2092,10 @@ function _run_insert_handler($args)
|
|||||||
$info = null;
|
$info = null;
|
||||||
}
|
}
|
||||||
if (isset($tpl_line) && isset($tpl_file)) {
|
if (isset($tpl_line) && isset($tpl_file)) {
|
||||||
trigger_error("Smarty plugin error: [in " . $tpl_file . " line " .
|
trigger_error("Smarty error: [in " . $tpl_file . " line " .
|
||||||
$tpl_line . "]: $error_msg$info", $error_type);
|
$tpl_line . "]: $error_msg$info", $error_type);
|
||||||
} else {
|
} else {
|
||||||
trigger_error("Smarty plugin error: $error_msg$info", $error_type);
|
trigger_error("Smarty error: $error_msg$info", $error_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -209,7 +209,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$template_source = $prefilter[0]($template_source, $this);
|
$template_source = $prefilter[0]($template_source, $this);
|
||||||
$this->_plugins['prefilter'][$filter_name][3] = true;
|
$this->_plugins['prefilter'][$filter_name][3] = true;
|
||||||
} else {
|
} else {
|
||||||
$this->_trigger_plugin_error("Smarty plugin error: prefilter '$filter_name' is not implemented");
|
$this->_trigger_fatal_error("[plugin] prefilter '$filter_name' is not implemented");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -663,12 +663,14 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$arg_list[] = "'$arg_name' => $arg_value";
|
$arg_list[] = "'$arg_name' => $arg_value";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->_reg_objects[$object][0]) {
|
if(!$this->_reg_objects[$object][0]) {
|
||||||
$this->trigger_error("Smarty error: registered '$object' is not an object");
|
$this->_trigger_fatal_error("registered '$object' is not an object");
|
||||||
|
} elseif(!empty($this->_reg_objects[$object][1]) && !in_array($obj_comp, $this->_reg_objects[$object][1])) {
|
||||||
|
$this->_trigger_fatal_error("'$obj_comp' is not a registered component of object '$object'");
|
||||||
} elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) {
|
} elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) {
|
||||||
// method
|
// method
|
||||||
if($this->_reg_objects[$object][1]) {
|
if($this->_reg_objects[$object][2]) {
|
||||||
// smarty object argument format
|
// smarty object argument format
|
||||||
$return = "\$this->_reg_objects['$object'][0]->$obj_comp(array(".implode(',', (array)$arg_list)."), \$this)";
|
$return = "\$this->_reg_objects['$object'][0]->$obj_comp(array(".implode(',', (array)$arg_list)."), \$this)";
|
||||||
} else {
|
} else {
|
||||||
|
@@ -338,10 +338,12 @@ class Smarty
|
|||||||
Function: register_object
|
Function: register_object
|
||||||
Purpose: Registers object to be used in templates
|
Purpose: Registers object to be used in templates
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function register_object($object, &$object_impl, $smarty_args = true)
|
function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true)
|
||||||
{
|
{
|
||||||
|
settype($allowed, 'array');
|
||||||
|
settype($smarty_args, 'boolean');
|
||||||
$this->_reg_objects[$object] =
|
$this->_reg_objects[$object] =
|
||||||
array(&$object_impl, $smarty_args);
|
array(&$object_impl, $allowed, $smarty_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
@@ -1908,7 +1910,7 @@ function _run_insert_handler($args)
|
|||||||
if (isset($plugin)) {
|
if (isset($plugin)) {
|
||||||
if (!$plugin[3]) {
|
if (!$plugin[3]) {
|
||||||
if (!function_exists($plugin[0])) {
|
if (!function_exists($plugin[0])) {
|
||||||
$this->_trigger_plugin_error("$type '$name' is not implemented", $tpl_file, $tpl_line);
|
$this->_trigger_fatal_error("[plugin] $type '$name' is not implemented", $tpl_file, $tpl_line, __FILE__, __LINE__);
|
||||||
} else {
|
} else {
|
||||||
$plugin[1] = $tpl_file;
|
$plugin[1] = $tpl_file;
|
||||||
$plugin[2] = $tpl_line;
|
$plugin[2] = $tpl_line;
|
||||||
@@ -1944,7 +1946,7 @@ function _run_insert_handler($args)
|
|||||||
|
|
||||||
$plugin_func = 'smarty_' . $type . '_' . $name;
|
$plugin_func = 'smarty_' . $type . '_' . $name;
|
||||||
if (!function_exists($plugin_func)) {
|
if (!function_exists($plugin_func)) {
|
||||||
$this->_trigger_plugin_error("plugin function $plugin_func() not found in $plugin_file", $tpl_file, $tpl_line, __FILE__, __LINE__);
|
$this->_trigger_fatal_error("[plugin] function $plugin_func() not found in $plugin_file", $tpl_file, $tpl_line, __FILE__, __LINE__);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1989,7 +1991,7 @@ function _run_insert_handler($args)
|
|||||||
$this->_plugins[$type][$name] = array($plugin_func, $tpl_file, $tpl_line, true);
|
$this->_plugins[$type][$name] = array($plugin_func, $tpl_file, $tpl_line, true);
|
||||||
} else {
|
} else {
|
||||||
// output error
|
// output error
|
||||||
$this->_trigger_plugin_error($message, $tpl_file, $tpl_line, __FILE__, __LINE__);
|
$this->_trigger_fatal_error('[plugin] ' . $message, $tpl_file, $tpl_line, __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2020,7 +2022,7 @@ function _run_insert_handler($args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$plugin[1]) {
|
if (!$plugin[1]) {
|
||||||
$this->_trigger_plugin_error("resource '$type' is not implemented", null, null, __FILE__, __LINE__);
|
$this->_trigger_fatal_error("[plugin] resource '$type' is not implemented", null, null, __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -2043,7 +2045,7 @@ function _run_insert_handler($args)
|
|||||||
foreach ($resource_ops as $op) {
|
foreach ($resource_ops as $op) {
|
||||||
$plugin_func = 'smarty_resource_' . $type . '_' . $op;
|
$plugin_func = 'smarty_resource_' . $type . '_' . $op;
|
||||||
if (!function_exists($plugin_func)) {
|
if (!function_exists($plugin_func)) {
|
||||||
$this->_trigger_plugin_error("plugin function $plugin_func() not found in $plugin_file", null, null, __FILE__, __LINE__);
|
$this->_trigger_fatal_error("[plugin] function $plugin_func() not found in $plugin_file", null, null, __FILE__, __LINE__);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
$resource_funcs[] = $plugin_func;
|
$resource_funcs[] = $plugin_func;
|
||||||
@@ -2078,10 +2080,10 @@ function _run_insert_handler($args)
|
|||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _trigger_plugin_error
|
Function: _trigger_fatal_error
|
||||||
Purpose: trigger Smarty plugin error
|
Purpose: trigger Smarty plugin error
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function _trigger_plugin_error($error_msg, $tpl_file = null, $tpl_line = null,
|
function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null,
|
||||||
$file = null, $line = null, $error_type = E_USER_ERROR)
|
$file = null, $line = null, $error_type = E_USER_ERROR)
|
||||||
{
|
{
|
||||||
if(isset($file) && isset($line)) {
|
if(isset($file) && isset($line)) {
|
||||||
@@ -2090,10 +2092,10 @@ function _run_insert_handler($args)
|
|||||||
$info = null;
|
$info = null;
|
||||||
}
|
}
|
||||||
if (isset($tpl_line) && isset($tpl_file)) {
|
if (isset($tpl_line) && isset($tpl_file)) {
|
||||||
trigger_error("Smarty plugin error: [in " . $tpl_file . " line " .
|
trigger_error("Smarty error: [in " . $tpl_file . " line " .
|
||||||
$tpl_line . "]: $error_msg$info", $error_type);
|
$tpl_line . "]: $error_msg$info", $error_type);
|
||||||
} else {
|
} else {
|
||||||
trigger_error("Smarty plugin error: $error_msg$info", $error_type);
|
trigger_error("Smarty error: $error_msg$info", $error_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -209,7 +209,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$template_source = $prefilter[0]($template_source, $this);
|
$template_source = $prefilter[0]($template_source, $this);
|
||||||
$this->_plugins['prefilter'][$filter_name][3] = true;
|
$this->_plugins['prefilter'][$filter_name][3] = true;
|
||||||
} else {
|
} else {
|
||||||
$this->_trigger_plugin_error("Smarty plugin error: prefilter '$filter_name' is not implemented");
|
$this->_trigger_fatal_error("[plugin] prefilter '$filter_name' is not implemented");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -663,12 +663,14 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$arg_list[] = "'$arg_name' => $arg_value";
|
$arg_list[] = "'$arg_name' => $arg_value";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->_reg_objects[$object][0]) {
|
if(!$this->_reg_objects[$object][0]) {
|
||||||
$this->trigger_error("Smarty error: registered '$object' is not an object");
|
$this->_trigger_fatal_error("registered '$object' is not an object");
|
||||||
|
} elseif(!empty($this->_reg_objects[$object][1]) && !in_array($obj_comp, $this->_reg_objects[$object][1])) {
|
||||||
|
$this->_trigger_fatal_error("'$obj_comp' is not a registered component of object '$object'");
|
||||||
} elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) {
|
} elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) {
|
||||||
// method
|
// method
|
||||||
if($this->_reg_objects[$object][1]) {
|
if($this->_reg_objects[$object][2]) {
|
||||||
// smarty object argument format
|
// smarty object argument format
|
||||||
$return = "\$this->_reg_objects['$object'][0]->$obj_comp(array(".implode(',', (array)$arg_list)."), \$this)";
|
$return = "\$this->_reg_objects['$object'][0]->$obj_comp(array(".implode(',', (array)$arg_list)."), \$this)";
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user