diff --git a/NEWS b/NEWS index 2d00a6a7..1b4bf03f 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ + - implemented access to request variables via auto-assigned $smarty + template variable. (Andrei) - fixed a bug with parsing function arguments inside {if} tags if a comma was present. (Andrei) - updated debug console with config file vars. (Monte) diff --git a/Smarty.class.php b/Smarty.class.php index 8e727b5f..c32a58d3 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -172,22 +172,26 @@ class Smarty var $prefilter_funcs = array(); // what functions templates are prefiltered through // before being compiled + var $request_vars_order = "EGPCS"; // the order in which request variables are + // registered, similar to variables_order + // in php.ini + /**************************************************************************/ /* END SMARTY CONFIGURATION SECTION */ /* There should be no need to touch anything below this line. */ /**************************************************************************/ // internal vars - var $_error_msg = false; // error messages. true/false - var $_tpl_vars = array(); // where assigned template vars are kept - var $_sections = array(); // keeps track of sections - var $_conf_obj = null; // configuration object - var $_config = array(); // loaded configuration settings - var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' - var $_version = '1.4.3'; // Smarty version number - var $_extract = false; // flag for custom functions - var $_included_tpls = array(); // list of run-time included templates - var $_inclusion_depth = 0; // current template inclusion depth + var $_error_msg = false; // error messages. true/false + var $_tpl_vars = array(); // where assigned template vars are kept + var $_sections = array(); // keeps track of sections + var $_conf_obj = null; // configuration object + var $_config = array(); // loaded configuration settings + var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' + var $_version = '1.4.3'; // Smarty version number + var $_extract = false; // flag for custom functions + var $_included_tpls = array(); // list of run-time included templates + var $_inclusion_depth = 0; // current template inclusion depth /*======================================================================*\ @@ -538,6 +542,8 @@ class Smarty } } + $this->_assign_smarty_interface(); + if ($this->_conf_obj === null) { /* Prepare the configuration object. */ if (!class_exists('Config_File')) @@ -598,6 +604,54 @@ class Smarty } } + +/*======================================================================*\ + Function: _assign_smarty_interface + Purpose: assign $smarty interface variable +\*======================================================================*/ + function _assign_smarty_interface() + { + $smarty = array('get' => $GLOBALS['HTTP_GET_VARS'], + 'post' => $GLOBALS['HTTP_POST_VARS'], + 'cookies' => $GLOBALS['HTTP_COOKIE_VARS'], + 'session' => $GLOBALS['HTTP_SESSION_VARS'], + 'server' => $GLOBALS['HTTP_SERVER_VARS'], + 'env' => $GLOBALS['HTTP_ENV_VARS']); + + $smarty['request'] = array(); + foreach (preg_split('!!', $this->request_vars_order) as $c) { + switch (strtolower($c)) { + case 'p': + $smarty['request'] = array_merge($smarty['request'], + $GLOBALS['HTTP_POST_VARS']); + break; + + case 'c': + $smarty['request'] = array_merge($smarty['request'], + $GLOBALS['HTTP_COOKIE_VARS']); + break; + + case 'g': + $smarty['request'] = array_merge($smarty['request'], + $GLOBALS['HTTP_GET_VARS']); + break; + + case 'e': + $smarty['request'] = array_merge($smarty['request'], + $GLOBALS['HTTP_ENV_VARS']); + break; + + case 's': + $smarty['request'] = array_merge($smarty['request'], + $GLOBALS['HTTP_SERVER_VARS']); + break; + } + } + + $this->assign('smarty', $smarty); + } + + /*======================================================================*\ Function: _generate_debug_output() Purpose: generate debug output diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 8e727b5f..c32a58d3 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -172,22 +172,26 @@ class Smarty var $prefilter_funcs = array(); // what functions templates are prefiltered through // before being compiled + var $request_vars_order = "EGPCS"; // the order in which request variables are + // registered, similar to variables_order + // in php.ini + /**************************************************************************/ /* END SMARTY CONFIGURATION SECTION */ /* There should be no need to touch anything below this line. */ /**************************************************************************/ // internal vars - var $_error_msg = false; // error messages. true/false - var $_tpl_vars = array(); // where assigned template vars are kept - var $_sections = array(); // keeps track of sections - var $_conf_obj = null; // configuration object - var $_config = array(); // loaded configuration settings - var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' - var $_version = '1.4.3'; // Smarty version number - var $_extract = false; // flag for custom functions - var $_included_tpls = array(); // list of run-time included templates - var $_inclusion_depth = 0; // current template inclusion depth + var $_error_msg = false; // error messages. true/false + var $_tpl_vars = array(); // where assigned template vars are kept + var $_sections = array(); // keeps track of sections + var $_conf_obj = null; // configuration object + var $_config = array(); // loaded configuration settings + var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' + var $_version = '1.4.3'; // Smarty version number + var $_extract = false; // flag for custom functions + var $_included_tpls = array(); // list of run-time included templates + var $_inclusion_depth = 0; // current template inclusion depth /*======================================================================*\ @@ -538,6 +542,8 @@ class Smarty } } + $this->_assign_smarty_interface(); + if ($this->_conf_obj === null) { /* Prepare the configuration object. */ if (!class_exists('Config_File')) @@ -598,6 +604,54 @@ class Smarty } } + +/*======================================================================*\ + Function: _assign_smarty_interface + Purpose: assign $smarty interface variable +\*======================================================================*/ + function _assign_smarty_interface() + { + $smarty = array('get' => $GLOBALS['HTTP_GET_VARS'], + 'post' => $GLOBALS['HTTP_POST_VARS'], + 'cookies' => $GLOBALS['HTTP_COOKIE_VARS'], + 'session' => $GLOBALS['HTTP_SESSION_VARS'], + 'server' => $GLOBALS['HTTP_SERVER_VARS'], + 'env' => $GLOBALS['HTTP_ENV_VARS']); + + $smarty['request'] = array(); + foreach (preg_split('!!', $this->request_vars_order) as $c) { + switch (strtolower($c)) { + case 'p': + $smarty['request'] = array_merge($smarty['request'], + $GLOBALS['HTTP_POST_VARS']); + break; + + case 'c': + $smarty['request'] = array_merge($smarty['request'], + $GLOBALS['HTTP_COOKIE_VARS']); + break; + + case 'g': + $smarty['request'] = array_merge($smarty['request'], + $GLOBALS['HTTP_GET_VARS']); + break; + + case 'e': + $smarty['request'] = array_merge($smarty['request'], + $GLOBALS['HTTP_ENV_VARS']); + break; + + case 's': + $smarty['request'] = array_merge($smarty['request'], + $GLOBALS['HTTP_SERVER_VARS']); + break; + } + } + + $this->assign('smarty', $smarty); + } + + /*======================================================================*\ Function: _generate_debug_output() Purpose: generate debug output