- bugfix on changes of 05/02/2010

This commit is contained in:
Uwe.Tews
2010-02-07 22:21:37 +00:00
parent d19fbb19d9
commit 7bfa54f067

View File

@@ -167,7 +167,7 @@ class Smarty extends Smarty_Internal_Data {
// config var settings // config var settings
public $config_overwrite = true; //Controls whether variables with the same name overwrite each other. public $config_overwrite = true; //Controls whether variables with the same name overwrite each other.
public $config_booleanize = true; //Controls whether config values of on/true/yes and off/false/no get converted to boolean public $config_booleanize = true; //Controls whether config values of on/true/yes and off/false/no get converted to boolean
public $config_read_hidden = true; //Controls whether hidden config sections/vars are read from the file. public $config_read_hidden = true; //Controls whether hidden config sections/vars are read from the file.
// config vars // config vars
public $config_vars = array(); public $config_vars = array();
// assigned tpl vars // assigned tpl vars
@@ -219,7 +219,9 @@ class Smarty extends Smarty_Internal_Data {
// default dir permissions // default dir permissions
public $_dir_perms = 0771; public $_dir_perms = 0771;
// smarty object reference // smarty object reference
public $smarty = null; public $smarty = null;
// block data at template inheritance
public $block_data = array();
// generate deprecated function call notices? // generate deprecated function call notices?
public $deprecation_notices = true; public $deprecation_notices = true;
@@ -354,7 +356,7 @@ class Smarty extends Smarty_Internal_Data {
} }
// return cache status of template // return cache status of template
return $template->isCached(); return $template->isCached();
} }
/** /**
* creates a data object * creates a data object
@@ -428,6 +430,13 @@ class Smarty extends Smarty_Internal_Data {
} }
} }
/**
* Disable security
*/
public function disableSecurity() {
$this->security = true;
}
/** /**
* Set template directory * Set template directory
* *
@@ -448,28 +457,20 @@ class Smarty extends Smarty_Internal_Data {
$this->template_dir = array_unique($this->template_dir); $this->template_dir = array_unique($this->template_dir);
return; return;
} }
/**
* Enable Caching
*/
public function enableCaching() {
$this->caching = SMARTY_CACHING_LIFETIME_CURRENT;
return;
}
/** /**
* Check if a template resource exists * Check if a template resource exists
* *
* @param string $resource_name template name * @param string $resource_name template name
* @return boolean status * @return boolean status
*/ */
function templateExists($resource_name) function templateExists($resource_name) {
{
// create template object // create template object
$tpl = new $this->template_class($resource_name, $this); $tpl = new $this->template_class($resource_name, $this);
// check if it does exists // check if it does exists
return $tpl->isExisting(); return $tpl->isExisting();
} }
/** /**
* Takes unknown classes and loads plugin files for them * Takes unknown classes and loads plugin files for them
@@ -524,24 +525,23 @@ class Smarty extends Smarty_Internal_Data {
* *
* @param string $type filter type * @param string $type filter type
* @param string $name filter name * @param string $name filter name
* @return bool * @return bool
*/ */
function loadFilter($type, $name) function loadFilter($type, $name) {
{
$_plugin = "smarty_{$type}filter_{$name}"; $_plugin = "smarty_{$type}filter_{$name}";
$_filter_name = $_plugin; $_filter_name = $_plugin;
if ($this->loadPlugin($_plugin)) { if ($this->loadPlugin($_plugin)) {
if (class_exists($_plugin, false)) { if (class_exists($_plugin, false)) {
$_plugin = array($_plugin, 'execute'); $_plugin = array($_plugin, 'execute');
} }
if (is_callable($_plugin)) { if (is_callable($_plugin)) {
return $this->registered_filters[$type][$_filter_name] = $_plugin; return $this->registered_filters[$type][$_filter_name] = $_plugin;
} }
} }
throw new Exception("{$type}filter \"{$name}\" not callable"); throw new Exception("{$type}filter \"{$name}\" not callable");
return false; return false;
} }
/** /**
* Sets the exception handler for Smarty. * Sets the exception handler for Smarty.
* *
@@ -568,17 +568,16 @@ class Smarty extends Smarty_Internal_Data {
* *
* @param callback $function_name * @param callback $function_name
*/ */
public function _get_filter_name($function_name) public function _get_filter_name($function_name) {
{ if (is_array($function_name)) {
if (is_array($function_name)) { $_class_name = (is_object($function_name[0]) ?
$_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]);
get_class($function_name[0]) : $function_name[0]); return $_class_name . '_' . $function_name[1];
return $_class_name . '_' . $function_name[1]; }
} else {
else { return $function_name;
return $function_name; }
} }
}
/** /**
* Adds directory of plugin files * Adds directory of plugin files
@@ -587,13 +586,12 @@ class Smarty extends Smarty_Internal_Data {
* @param string $ |array $ plugins folder * @param string $ |array $ plugins folder
* @return * @return
*/ */
function addPluginsDir($plugins_dir) function addPluginsDir($plugins_dir) {
{
$this->plugins_dir = array_merge((array)$this->plugins_dir, (array)$plugins_dir); $this->plugins_dir = array_merge((array)$this->plugins_dir, (array)$plugins_dir);
$this->plugins_dir = array_unique($this->plugins_dir); $this->plugins_dir = array_unique($this->plugins_dir);
return; return;
} }
/** /**
* Returns a single or all global variables * Returns a single or all global variables
* *
@@ -601,22 +599,23 @@ class Smarty extends Smarty_Internal_Data {
* @param string $varname variable name or null * @param string $varname variable name or null
* @return string variable value or or array of variables * @return string variable value or or array of variables
*/ */
function getGlobal($varname = null) function getGlobal($varname = null) {
{
if (isset($varname)) { if (isset($varname)) {
if (isset($this->global_tpl_vars[$varname])) { if (isset($this->global_tpl_vars[$varname])) {
return $this->global_tpl_vars[$varname]->value; return $this->global_tpl_vars[$varname]->value;
} else { }
else {
return ''; return '';
} }
} else { }
else {
$_result = array(); $_result = array();
foreach ($this->global_tpl_vars AS $key => $var) { foreach ($this->global_tpl_vars AS $key => $var) {
$_result[$key] = $var->value; $_result[$key] = $var->value;
} }
return $_result; return $_result;
} }
} }
/** /**
* return a reference to a registered object * return a reference to a registered object
@@ -624,51 +623,48 @@ class Smarty extends Smarty_Internal_Data {
* @param string $name object name * @param string $name object name
* @return object * @return object
*/ */
function getRegisteredObject($name) function getRegisteredObject($name) {
{
if (!isset($this->registered_objects[$name])) if (!isset($this->registered_objects[$name]))
throw new Exception("'$name' is not a registered object"); throw new Exception("'$name' is not a registered object");
if (!is_object($this->registered_objects[$name][0])) if (!is_object($this->registered_objects[$name][0]))
throw new Exception("registered '$name' is not an object"); throw new Exception("registered '$name' is not an object");
return $this->registered_objects[$name][0]; return $this->registered_objects[$name][0];
} }
/** /**
* return name of debugging template * return name of debugging template
* *
* @return string * @return string
*/ */
function getDebugTemplate() function getDebugTemplate() {
{
return $this->debug_tpl; return $this->debug_tpl;
} }
/** /**
* set the debug template * set the debug template
* *
* @param string $tpl_name * @param string $tpl_name
* @return bool * @return bool
*/ */
function setDebugTemplate($tpl_name) function setDebugTemplate($tpl_name) {
{
return $this->debug_tpl = $tpl_name; return $this->debug_tpl = $tpl_name;
} }
/** /**
* lazy loads (valid) property objects * lazy loads (valid) property objects
* *
* @param string $name property name * @param string $name property name
*/ */
public function __get($name) { public function __get($name) {
if(in_array($name,array('register','unregister','utility','cache'))) { if(in_array($name, array('register', 'unregister', 'utility', 'cache'))) {
$class = "Smarty_Internal_".ucfirst($name); $class = "Smarty_Internal_" . ucfirst($name);
return new $class($this); return new $class($this);
} }
return false; return false;
} }
/** /**
* Takes unknown class methods and lazy loads sysplugin files for them * Takes unknown class methods and lazy loads sysplugin files for them
* class name format: Smarty_Method_MethodName * class name format: Smarty_Method_MethodName
@@ -680,37 +676,35 @@ class Smarty extends Smarty_Internal_Data {
public function __call($name, $args) { public function __call($name, $args) {
static $camel_func; static $camel_func;
if(!isset($camel_func)) if(!isset($camel_func))
$camel_func = create_function('$c', 'return "_" . strtolower($c[1]);'); $camel_func = create_function('$c', 'return "_" . strtolower($c[1]);');
// PHP4 call to constructor? // PHP4 call to constructor?
if (strtolower($name) == 'smarty') { if (strtolower($name) == 'smarty') {
throw new Exception('Please use parent::__construct() to call parent constuctor'); throw new Exception('Please use parent::__construct() to call parent constuctor');
return false; return false;
} }
// see if this is a set/get for a property // see if this is a set/get for a property
$first3 = strtolower(substr($name,0,3)); $first3 = strtolower(substr($name, 0, 3));
if(in_array($first3,array('set','get')) && substr($name,3,1) !== '_') { if(in_array($first3, array('set', 'get')) && substr($name, 3, 1) !== '_') {
// try to keep case correct for future PHP 6.0 case-sensitive class methods // try to keep case correct for future PHP 6.0 case-sensitive class methods
// lcfirst() not available < PHP 5.3.0, so improvise // lcfirst() not available < PHP 5.3.0, so improvise
$property_name = strtolower(substr($name,3,1)).substr($name,4); $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
// convert camel case to underscored name // convert camel case to underscored name
$property_name = preg_replace_callback('/([A-Z])/', $camel_func, $property_name); $property_name = preg_replace_callback('/([A-Z])/', $camel_func, $property_name);
if(!property_exists($this,$property_name)) { if(!property_exists($this, $property_name)) {
throw new Exception("property '$property_name' does not exist."); throw new Exception("property '$property_name' does not exist.");
return false; return false;
} }
if($first3 == 'get') if($first3 == 'get')
return $this->$property_name; return $this->$property_name;
else else
return $this->$property_name = $args[0]; return $this->$property_name = $args[0];
} }
// Smarty Backward Compatible wrapper // Smarty Backward Compatible wrapper
if(!isset($this->wrapper)) { if(!isset($this->wrapper)) {
$this->wrapper = new Smarty_Internal_Wrapper($this); $this->wrapper = new Smarty_Internal_Wrapper($this);
} }
return $this->wrapper->convert($name, $args); return $this->wrapper->convert($name, $args);
/* /*
$name = strtolower($name); $name = strtolower($name);
if ($name == 'smarty') { if ($name == 'smarty') {