From fb7161d4ee39f22d82b9ca3d615098d9e6ccdcc0 Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 9 Oct 2001 16:29:10 +0000 Subject: [PATCH] Added support for hidden config vars. --- Config_File.class.php | 21 ++++++++++++++++++++- NEWS | 6 ++++-- Smarty.class.php | 1 + TODO | 1 + libs/Config_File.class.php | 21 ++++++++++++++++++++- libs/Smarty.class.php | 1 + 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Config_File.class.php b/Config_File.class.php index fa65e4d4..617b8424 100644 --- a/Config_File.class.php +++ b/Config_File.class.php @@ -46,6 +46,7 @@ class Config_File extends PEAR { * @access public */ var $overwrite = true; + /** * Controls whether config values of on/true/yes and off/false/no get * converted to boolean values automatically. @@ -54,6 +55,13 @@ class Config_File extends PEAR { */ var $booleanize = true; + /** + * Controls whether hidden config sections/vars are read from the file. + * + * @access public + */ + var $read_hidden = true; + /* Private variables */ var $_config_path = ""; var $_config_data = array(); @@ -247,7 +255,11 @@ class Config_File extends PEAR { $config_data["sections"] = array(); preg_match_all("/^\[(.*?)\]/m", $contents, $match); foreach ($match[1] as $section) { + if ($section{0} == '.' && !$this->read_hidden) + continue; if (preg_match("/\[".preg_quote($section)."\](.*?)(\n\[|\Z)/s", $contents, $match)) + if ($section{0} == '.') + $section = substr($section, 1); $config_data["sections"][$section]["vars"] = $this->_parse_config_block($match[1]); } @@ -271,7 +283,7 @@ class Config_File extends PEAR { $config_lines = preg_split("/\n+/", $config_block); foreach ($config_lines as $line) { - if (preg_match("/^\s*(\w+)\s*=(.*)/", $line, $match)) { + if (preg_match("/^\s*(\.?\w+)\s*=(.*)/", $line, $match)) { $var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', trim($match[2])); $this->_set_config_var($vars, trim($match[1]), $var_value, $this->booleanize); } @@ -282,6 +294,13 @@ class Config_File extends PEAR { function _set_config_var(&$container, $var_name, $var_value, $booleanize) { + if ($var_name{0} == '.') { + if (!$this->read_hidden) + return; + else + $var_name = substr($var_name, 1); + } + if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) return new Config_File_Error("Bad variable name '$var_name'"); diff --git a/NEWS b/NEWS index cb892447..a0eefd40 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ - - added execution time to DEBUG console (Monte) - - fixed bug where DEBUG console would not appear with cached content (Monte) + - added support for hidden config variables that cannot be read by + templates. (Andrei) + - added execution time to DEBUG console. (Monte) + - fixed bug where DEBUG console would not appear with cached content. (Monte) - added support for postfilter functions that are applied to compiled template right after compilation. (Andrei) - fixed the name of clear_compile_tpl() API function to clear_compiled_tpl. diff --git a/Smarty.class.php b/Smarty.class.php index 4a837b98..423e73fe 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -548,6 +548,7 @@ class Smarty if (!class_exists('Config_File')) include_once SMARTY_DIR.'Config_File.class.php'; $this->_conf_obj = new Config_File($this->config_dir); + $this->_conf_obj->read_hidden = false; } else $this->_conf_obj->set_path($this->config_dir); diff --git a/TODO b/TODO index be72a874..8ef82450 100644 --- a/TODO +++ b/TODO @@ -13,3 +13,4 @@ * allow {custom} .. {/custom} style of custom functions * ability to concatenate values/strings together * don't load globals more than once from the same config file +* fix all E_NOTICE warnings diff --git a/libs/Config_File.class.php b/libs/Config_File.class.php index fa65e4d4..617b8424 100644 --- a/libs/Config_File.class.php +++ b/libs/Config_File.class.php @@ -46,6 +46,7 @@ class Config_File extends PEAR { * @access public */ var $overwrite = true; + /** * Controls whether config values of on/true/yes and off/false/no get * converted to boolean values automatically. @@ -54,6 +55,13 @@ class Config_File extends PEAR { */ var $booleanize = true; + /** + * Controls whether hidden config sections/vars are read from the file. + * + * @access public + */ + var $read_hidden = true; + /* Private variables */ var $_config_path = ""; var $_config_data = array(); @@ -247,7 +255,11 @@ class Config_File extends PEAR { $config_data["sections"] = array(); preg_match_all("/^\[(.*?)\]/m", $contents, $match); foreach ($match[1] as $section) { + if ($section{0} == '.' && !$this->read_hidden) + continue; if (preg_match("/\[".preg_quote($section)."\](.*?)(\n\[|\Z)/s", $contents, $match)) + if ($section{0} == '.') + $section = substr($section, 1); $config_data["sections"][$section]["vars"] = $this->_parse_config_block($match[1]); } @@ -271,7 +283,7 @@ class Config_File extends PEAR { $config_lines = preg_split("/\n+/", $config_block); foreach ($config_lines as $line) { - if (preg_match("/^\s*(\w+)\s*=(.*)/", $line, $match)) { + if (preg_match("/^\s*(\.?\w+)\s*=(.*)/", $line, $match)) { $var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', trim($match[2])); $this->_set_config_var($vars, trim($match[1]), $var_value, $this->booleanize); } @@ -282,6 +294,13 @@ class Config_File extends PEAR { function _set_config_var(&$container, $var_name, $var_value, $booleanize) { + if ($var_name{0} == '.') { + if (!$this->read_hidden) + return; + else + $var_name = substr($var_name, 1); + } + if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) return new Config_File_Error("Bad variable name '$var_name'"); diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 4a837b98..423e73fe 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -548,6 +548,7 @@ class Smarty if (!class_exists('Config_File')) include_once SMARTY_DIR.'Config_File.class.php'; $this->_conf_obj = new Config_File($this->config_dir); + $this->_conf_obj->read_hidden = false; } else $this->_conf_obj->set_path($this->config_dir);