diff --git a/README b/README index f0b94859..d81790cc 100644 --- a/README +++ b/README @@ -104,7 +104,7 @@ $smarty->display('string:This is my template, {$foo}!'); You can use complex expressions almost anywhere. {$x+$y} will output the sum of x and y. -PHP functions can be used in expressions unless they are not disabled by the security policy. +PHP functions can be used in expressions unless they are disabled by the security policy. {assign var=foo value=2*(3+sqrt($bar))} You can define arrays. diff --git a/change_log.txt b/change_log.txt index af57575a..509188a5 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,7 @@ +04/06/2009 +- variable scopes LOCAL_SCOPE, PARENT_SCOPE, ROOT_SCOPE +- more getter/setter methodes + 04/05/2009 - replaced new array looping syntax {for $foo in $array} with {foreach $foo in $array} to avoid confusion - added append array for short form of assign {$foo[]='bar'} and allow assignments to nested arrays {$foo['bla']['blue']='bar'} diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 83a52d6f..c020ec03 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -35,10 +35,16 @@ * if not defined, include_path will be used. Sets SMARTY_DIR only if user * application has not already defined it. */ - if (!defined('SMARTY_DIR')) { define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); -} +} + +/** +* define variable scopes +*/ +define('LOCAL_SCOPE',0); +define('PARENT_SCOPE',1); +define('ROOT_SCOPE',2); /** * load required base class for creation of the smarty object diff --git a/libs/sysplugins/internal.compile_include.php b/libs/sysplugins/internal.compile_include.php index 368c372e..5ec33158 100644 --- a/libs/sysplugins/internal.compile_include.php +++ b/libs/sysplugins/internal.compile_include.php @@ -34,12 +34,12 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { $_assign = $_attr['assign']; } - $_parent_scope = '0'; + $_parent_scope = LOCAL_SCOPE; if (isset($_attr['scope'])) { if ($_attr['scope'] == '\'parent\'') { - $_parent_scope = '1'; + $_parent_scope = PARENT_SCOPE; } elseif ($_attr['scope'] == '\'root\'') { - $_parent_scope = '2'; + $_parent_scope = ROOT_SCOPE; } } @@ -69,13 +69,13 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { unset($_attr['file'], $_attr['assign'], $_attr['caching_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope']); // remaining attributes must be assigned as smarty variable if (!empty($_attr)) { - if ($_parent_scope == '0') { + if ($_parent_scope == LOCAL_SCOPE) { // create variables foreach ($_attr as $_key => $_value) { $_output .= "\$_template->assign('$_key',$_value);"; } } else { - $this->compiler->trigger_template_error('variable passing not allowed in parent scope'); + $this->compiler->trigger_template_error('variable passing not allowed in parent/global scope'); } } // add caching parameter if required diff --git a/libs/sysplugins/internal.template.php b/libs/sysplugins/internal.template.php index af8cca7c..5d1bc871 100644 --- a/libs/sysplugins/internal.template.php +++ b/libs/sysplugins/internal.template.php @@ -387,9 +387,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { // disable caching for evaluated code if ($this->isEvaluated()) { $this->caching = false; - } - // checks if template exists - $this->getTemplateFilepath(); + } + // checks if template exists + $this->getTemplateFilepath(); // read from cache or render if ($this->rendered_content === null && !$this->isCached()) { // render template (not loaded and not in cache) @@ -546,25 +546,26 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { /** * Update Smarty variables in parent variable object */ - public function updateParentVariables ($mode = 0) - { - // do we have a back pointer? - if (is_object($this->parent)) { - if ($mode == 2) { - $_ptr = $this->smarty; - } else { - $_ptr = $this->parent; + public function updateParentVariables ($scope = LOCAL_SCOPE) + { + foreach ($this->tpl_vars as $_key => $_value) { + // copy global vars back to parent + if (isset($this->parent) && ($scope == PARENT_SCOPE || $this->tpl_vars[$_key]->global)) { + if (isset($this->parent->tpl_vars[$_key])) { + // variable is already defined in parent, copy value + $this->parent->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value; + } else { + // create variable in parent + $this->parent->tpl_vars[$_key] = clone $_value; + } } - foreach ($this->tpl_vars as $_key => $_value) { - // copy global vars back to parent - if ($mode > 0 || $this->tpl_vars[$_key]->global) { - if (isset($this->parent->tpl_vars[$_key])) { - // variable is already defined in parent, copy value - $this->parent->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value; - } else { - // create variable in parent - $this->parent->tpl_vars[$_key] = clone $_value; - } + if ($scope == ROOT_SCOPE) { + if (isset($this->smarty->tpl_vars[$_key])) { + // variable is already defined in root, copy value + $this->smarty->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value; + } else { + // create variable in root + $this->smarty->tpl_vars[$_key] = clone $_value; } } } diff --git a/libs/sysplugins/method.disablecachemodifycheck.php b/libs/sysplugins/method.disablecachemodifycheck.php index 46d2e8cb..5a8a71a6 100644 --- a/libs/sysplugins/method.disablecachemodifycheck.php +++ b/libs/sysplugins/method.disablecachemodifycheck.php @@ -18,7 +18,8 @@ class Smarty_Method_disableCacheModifyCheck extends Smarty_Internal_Base { public function execute() { - return $this->smarty->cache_modified_check = false; + $this->smarty->cache_modified_check = false; + return ; } } diff --git a/libs/sysplugins/method.disablecaching.php b/libs/sysplugins/method.disablecaching.php index f4a5cb8e..efa92410 100644 --- a/libs/sysplugins/method.disablecaching.php +++ b/libs/sysplugins/method.disablecaching.php @@ -18,7 +18,8 @@ class Smarty_Method_DisableCaching extends Smarty_Internal_Base { public function execute() { - return $this->smarty->caching = false; + $this->smarty->caching = false; + return; } } diff --git a/libs/sysplugins/method.disablecompilecheck.php b/libs/sysplugins/method.disablecompilecheck.php index 80c6f5f4..c46889aa 100644 --- a/libs/sysplugins/method.disablecompilecheck.php +++ b/libs/sysplugins/method.disablecompilecheck.php @@ -18,7 +18,8 @@ class Smarty_Method_DisableCompileCheck extends Smarty_Internal_Base { public function execute() { - return $this->smarty->compile_check = false; + $this->smarty->compile_check = false; + return; } } diff --git a/libs/sysplugins/method.disableconfigbooleanize.php b/libs/sysplugins/method.disableconfigbooleanize.php index 6ec056f0..04956b97 100644 --- a/libs/sysplugins/method.disableconfigbooleanize.php +++ b/libs/sysplugins/method.disableconfigbooleanize.php @@ -18,7 +18,8 @@ class Smarty_Method_disableConfigBooleanize extends Smarty_Internal_Base { public function execute() { - return $this->smarty->config_booleanize = false; + $this->smarty->config_booleanize = false; + return; } } diff --git a/libs/sysplugins/method.disableconfigoverwrite.php b/libs/sysplugins/method.disableconfigoverwrite.php index 3b9f5cd0..98993c6c 100644 --- a/libs/sysplugins/method.disableconfigoverwrite.php +++ b/libs/sysplugins/method.disableconfigoverwrite.php @@ -18,7 +18,8 @@ class Smarty_Method_disableConfigOverwrite extends Smarty_Internal_Base { public function execute() { - return $this->smarty->config_overwrite = false; + $this->smarty->config_overwrite = false; + return ; } } diff --git a/libs/sysplugins/method.disableconfigreadhidden.php b/libs/sysplugins/method.disableconfigreadhidden.php index bebfbaa8..9db5000a 100644 --- a/libs/sysplugins/method.disableconfigreadhidden.php +++ b/libs/sysplugins/method.disableconfigreadhidden.php @@ -18,7 +18,8 @@ class Smarty_Method_disableConfigReadHidden extends Smarty_Internal_Base { public function execute() { - return $this->smarty->config_read_hidden = false; + $this->smarty->config_read_hidden = false; + return; } } diff --git a/libs/sysplugins/method.disabledebugging.php b/libs/sysplugins/method.disabledebugging.php index 984eb81d..3cd1b597 100644 --- a/libs/sysplugins/method.disabledebugging.php +++ b/libs/sysplugins/method.disabledebugging.php @@ -18,7 +18,8 @@ class Smarty_Method_DisableDebugging extends Smarty_Internal_Base { public function execute() { - return $this->smarty->debugging = false; + $this->smarty->debugging = false; + return; } } diff --git a/libs/sysplugins/method.disabledebuggingurlctrl.php b/libs/sysplugins/method.disabledebuggingurlctrl.php index 51bb47d8..6cb873c8 100644 --- a/libs/sysplugins/method.disabledebuggingurlctrl.php +++ b/libs/sysplugins/method.disabledebuggingurlctrl.php @@ -18,7 +18,8 @@ class Smarty_Method_disableDebuggingUrlCtrl extends Smarty_Internal_Base { public function execute() { - return $this->smarty->debugging_ctrl = 'none'; + $this->smarty->debugging_ctrl = 'none'; + return; } } diff --git a/libs/sysplugins/method.disabledefaulttimezone.php b/libs/sysplugins/method.disabledefaulttimezone.php index fc2145e5..688a0b78 100644 --- a/libs/sysplugins/method.disabledefaulttimezone.php +++ b/libs/sysplugins/method.disabledefaulttimezone.php @@ -18,7 +18,8 @@ class Smarty_Method_disableDefaultTimezone extends Smarty_Internal_Base { public function execute() { - return $this->smarty->set_timezone = false; + $this->smarty->set_timezone = false; + return; } } diff --git a/libs/sysplugins/method.disableforcecompile.php b/libs/sysplugins/method.disableforcecompile.php index f09771fa..c3798d44 100644 --- a/libs/sysplugins/method.disableforcecompile.php +++ b/libs/sysplugins/method.disableforcecompile.php @@ -18,7 +18,8 @@ class Smarty_Method_DisableForceCompile extends Smarty_Internal_Base { public function execute() { - return $this->smarty->force_compile = false; + $this->smarty->force_compile = false; + return; } } diff --git a/libs/sysplugins/method.enablecachemodifycheck.php b/libs/sysplugins/method.enablecachemodifycheck.php index 268ee71f..c5baee02 100644 --- a/libs/sysplugins/method.enablecachemodifycheck.php +++ b/libs/sysplugins/method.enablecachemodifycheck.php @@ -18,7 +18,8 @@ class Smarty_Method_enableCacheModifyCheck extends Smarty_Internal_Base { public function execute() { - return $this->smarty->cache_modified_check = true; + $this->smarty->cache_modified_check = true; + return; } } diff --git a/libs/sysplugins/method.enablecompilecheck.php b/libs/sysplugins/method.enablecompilecheck.php index ad98db48..d2ded7f8 100644 --- a/libs/sysplugins/method.enablecompilecheck.php +++ b/libs/sysplugins/method.enablecompilecheck.php @@ -18,7 +18,8 @@ class Smarty_Method_EnableCompileCheck extends Smarty_Internal_Base { public function execute() { - return $this->smarty->compile_check = true; + $this->smarty->compile_check = true; + return; } } diff --git a/libs/sysplugins/method.enableconfigbooleanize.php b/libs/sysplugins/method.enableconfigbooleanize.php index 8edead27..920eb361 100644 --- a/libs/sysplugins/method.enableconfigbooleanize.php +++ b/libs/sysplugins/method.enableconfigbooleanize.php @@ -18,7 +18,8 @@ class Smarty_Method_enableConfigBooleanize extends Smarty_Internal_Base { public function execute() { - return $this->smarty->config_booleanize = true; + $this->smarty->config_booleanize = true; + return; } } diff --git a/libs/sysplugins/method.enableconfigoverwrite.php b/libs/sysplugins/method.enableconfigoverwrite.php index 364d491e..a56f952a 100644 --- a/libs/sysplugins/method.enableconfigoverwrite.php +++ b/libs/sysplugins/method.enableconfigoverwrite.php @@ -18,7 +18,8 @@ class Smarty_Method_enableConfigOverwrite extends Smarty_Internal_Base { public function execute() { - return $this->smarty->config_overwrite = true; + $this->smarty->config_overwrite = true; + return; } } diff --git a/libs/sysplugins/method.enableconfigreadhidden.php b/libs/sysplugins/method.enableconfigreadhidden.php index a87a8c2c..b78b41ee 100644 --- a/libs/sysplugins/method.enableconfigreadhidden.php +++ b/libs/sysplugins/method.enableconfigreadhidden.php @@ -18,7 +18,8 @@ class Smarty_Method_enableConfigReadHidden extends Smarty_Internal_Base { public function execute() { - return $this->smarty->config_read_hidden = true; + $this->smarty->config_read_hidden = true; + return; } } diff --git a/libs/sysplugins/method.enabledebugging.php b/libs/sysplugins/method.enabledebugging.php index 46d459da..ec534749 100644 --- a/libs/sysplugins/method.enabledebugging.php +++ b/libs/sysplugins/method.enabledebugging.php @@ -18,7 +18,8 @@ class Smarty_Method_EnableDebugging extends Smarty_Internal_Base { public function execute() { - return $this->smarty->debugging = true; + $this->smarty->debugging = true; + return; } } diff --git a/libs/sysplugins/method.enabledebuggingurlctrl.php b/libs/sysplugins/method.enabledebuggingurlctrl.php index c47a666f..219b718a 100644 --- a/libs/sysplugins/method.enabledebuggingurlctrl.php +++ b/libs/sysplugins/method.enabledebuggingurlctrl.php @@ -18,7 +18,8 @@ class Smarty_Method_EnableDebuggingUrlCtrl extends Smarty_Internal_Base { public function execute() { - return $this->smarty->debugging_ctrl = 'URL'; + $this->smarty->debugging_ctrl = 'URL'; + return; } } diff --git a/libs/sysplugins/method.enabledefaulttimezone.php b/libs/sysplugins/method.enabledefaulttimezone.php index 466be0a0..6c1f50a4 100644 --- a/libs/sysplugins/method.enabledefaulttimezone.php +++ b/libs/sysplugins/method.enabledefaulttimezone.php @@ -18,7 +18,8 @@ class Smarty_Method_enableDefaultTimezone extends Smarty_Internal_Base { public function execute() { - return $this->smarty->set_timezone = true; + $this->smarty->set_timezone = true; + return; } } diff --git a/libs/sysplugins/method.enableforcecompile.php b/libs/sysplugins/method.enableforcecompile.php index 523b519d..a2ca55d3 100644 --- a/libs/sysplugins/method.enableforcecompile.php +++ b/libs/sysplugins/method.enableforcecompile.php @@ -18,7 +18,8 @@ class Smarty_Method_enableForceCompile extends Smarty_Internal_Base { public function execute() { - return $this->smarty->force_compile = true; + $this->smarty->force_compile = true; + return; } } diff --git a/libs/sysplugins/method.iscachemodifycheck.php b/libs/sysplugins/method.iscachemodifycheck.php new file mode 100644 index 00000000..7a26908c --- /dev/null +++ b/libs/sysplugins/method.iscachemodifycheck.php @@ -0,0 +1,25 @@ +smarty->cache_modified_check; + } +} + +?> diff --git a/libs/sysplugins/method.iscaching.php b/libs/sysplugins/method.iscaching.php new file mode 100644 index 00000000..c8d8d84d --- /dev/null +++ b/libs/sysplugins/method.iscaching.php @@ -0,0 +1,25 @@ +smarty->caching; + } +} + +?> diff --git a/libs/sysplugins/method.iscompilecheck.php b/libs/sysplugins/method.iscompilecheck.php new file mode 100644 index 00000000..d41fe7ac --- /dev/null +++ b/libs/sysplugins/method.iscompilecheck.php @@ -0,0 +1,25 @@ +smarty->compile_check; + } +} + +?> diff --git a/libs/sysplugins/method.isconfigbooleanize.php b/libs/sysplugins/method.isconfigbooleanize.php new file mode 100644 index 00000000..760ed051 --- /dev/null +++ b/libs/sysplugins/method.isconfigbooleanize.php @@ -0,0 +1,25 @@ +smarty->config_booleanize; + } +} + +?> diff --git a/libs/sysplugins/method.isconfigoverwrite.php b/libs/sysplugins/method.isconfigoverwrite.php new file mode 100644 index 00000000..aebea554 --- /dev/null +++ b/libs/sysplugins/method.isconfigoverwrite.php @@ -0,0 +1,26 @@ +smarty->config_overwrite; + + } +} + +?> diff --git a/libs/sysplugins/method.isconfigreadhidden.php b/libs/sysplugins/method.isconfigreadhidden.php new file mode 100644 index 00000000..ceab8d7e --- /dev/null +++ b/libs/sysplugins/method.isconfigreadhidden.php @@ -0,0 +1,25 @@ +smarty->config_read_hidden; + } +} + +?> diff --git a/libs/sysplugins/method.isdebugging.php b/libs/sysplugins/method.isdebugging.php new file mode 100644 index 00000000..e973d80d --- /dev/null +++ b/libs/sysplugins/method.isdebugging.php @@ -0,0 +1,25 @@ +smarty->debugging; + } +} + +?> diff --git a/libs/sysplugins/method.isdebuggingurlctrl.php b/libs/sysplugins/method.isdebuggingurlctrl.php new file mode 100644 index 00000000..6b8f4269 --- /dev/null +++ b/libs/sysplugins/method.isdebuggingurlctrl.php @@ -0,0 +1,25 @@ +smarty->debugging_ctrl != 'none'; + } +} + +?> diff --git a/libs/sysplugins/method.isdefaulttimezone.php b/libs/sysplugins/method.isdefaulttimezone.php new file mode 100644 index 00000000..a1b5a048 --- /dev/null +++ b/libs/sysplugins/method.isdefaulttimezone.php @@ -0,0 +1,25 @@ +smarty->set_timezone = false; + } +} + +?> diff --git a/libs/sysplugins/method.isforcecompile.php b/libs/sysplugins/method.isforcecompile.php new file mode 100644 index 00000000..91da3079 --- /dev/null +++ b/libs/sysplugins/method.isforcecompile.php @@ -0,0 +1,25 @@ +smarty->force_compile; + } +} + +?> diff --git a/libs/sysplugins/method.setconfigdir.php b/libs/sysplugins/method.setconfigdir.php index 1956c1af..348ae36a 100644 --- a/libs/sysplugins/method.setconfigdir.php +++ b/libs/sysplugins/method.setconfigdir.php @@ -26,6 +26,7 @@ class Smarty_Method_SetConfigDir extends Smarty_Internal_Base { public function execute($config_dir) { $this->smarty->config_dir = $config_dir; + return; } } diff --git a/libs/sysplugins/method.setpluginsdir.php b/libs/sysplugins/method.setpluginsdir.php index cbd6dc00..00410a41 100644 --- a/libs/sysplugins/method.setpluginsdir.php +++ b/libs/sysplugins/method.setpluginsdir.php @@ -26,6 +26,7 @@ class Smarty_Method_SetPluginsDir extends Smarty_Internal_Base { public function execute($plugins_dir) { $this->smarty->plugins_dir = (array)$plugins_dir; + return; } }