parent
53ea877a50
commit
07933bf52c
@ -1,389 +1,393 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Config_File class.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* @link http://smarty.php.net/
|
||||
* @version 2.6.9
|
||||
* @copyright Copyright: 2001-2005 New Digital Group, Inc.
|
||||
* @author Andrei Zmievski <andrei@php.net>
|
||||
* @access public
|
||||
* @package Smarty
|
||||
*/
|
||||
|
||||
/* $Id: Config_File.class.php,v 1.1 2006/05/29 16:38:21 powles Exp $ */
|
||||
|
||||
/**
|
||||
* Config file reading class
|
||||
* @package Smarty
|
||||
*/
|
||||
class Config_File {
|
||||
/**#@+
|
||||
* Options
|
||||
* @var boolean
|
||||
*/
|
||||
/**
|
||||
* Controls whether variables with the same name overwrite each other.
|
||||
*/
|
||||
var $overwrite = true;
|
||||
|
||||
/**
|
||||
* Controls whether config values of on/true/yes and off/false/no get
|
||||
* converted to boolean values automatically.
|
||||
*/
|
||||
var $booleanize = true;
|
||||
|
||||
/**
|
||||
* Controls whether hidden config sections/vars are read from the file.
|
||||
*/
|
||||
var $read_hidden = true;
|
||||
|
||||
/**
|
||||
* Controls whether or not to fix mac or dos formatted newlines.
|
||||
* If set to true, \r or \r\n will be changed to \n.
|
||||
*/
|
||||
var $fix_newlines = true;
|
||||
/**#@-*/
|
||||
|
||||
/** @access private */
|
||||
var $_config_path = "";
|
||||
var $_config_data = array();
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructs a new config file class.
|
||||
*
|
||||
* @param string $config_path (optional) path to the config files
|
||||
*/
|
||||
function Config_File($config_path = NULL)
|
||||
{
|
||||
if (isset($config_path))
|
||||
$this->set_path($config_path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the path where configuration files can be found.
|
||||
*
|
||||
* @param string $config_path path to the config files
|
||||
*/
|
||||
function set_path($config_path)
|
||||
{
|
||||
if (!empty($config_path)) {
|
||||
if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) {
|
||||
$this->_trigger_error_msg("Bad config file path '$config_path'");
|
||||
return;
|
||||
}
|
||||
if(substr($config_path, -1) != DIRECTORY_SEPARATOR) {
|
||||
$config_path .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$this->_config_path = $config_path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves config info based on the file, section, and variable name.
|
||||
*
|
||||
* @param string $file_name config file to get info for
|
||||
* @param string $section_name (optional) section to get info for
|
||||
* @param string $var_name (optional) variable to get info for
|
||||
* @return string|array a value or array of values
|
||||
*/
|
||||
function &get($file_name, $section_name = NULL, $var_name = NULL)
|
||||
{
|
||||
if (empty($file_name)) {
|
||||
$this->_trigger_error_msg('Empty config file name');
|
||||
return;
|
||||
} else {
|
||||
$file_name = $this->_config_path . $file_name;
|
||||
if (!isset($this->_config_data[$file_name]))
|
||||
$this->load_file($file_name, false);
|
||||
}
|
||||
|
||||
if (!empty($var_name)) {
|
||||
if (empty($section_name)) {
|
||||
return $this->_config_data[$file_name]["vars"][$var_name];
|
||||
} else {
|
||||
if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name]))
|
||||
return $this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
} else {
|
||||
if (empty($section_name)) {
|
||||
return (array)$this->_config_data[$file_name]["vars"];
|
||||
} else {
|
||||
if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"]))
|
||||
return (array)$this->_config_data[$file_name]["sections"][$section_name]["vars"];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves config info based on the key.
|
||||
*
|
||||
* @param $file_name string config key (filename/section/var)
|
||||
* @return string|array same as get()
|
||||
* @uses get() retrieves information from config file and returns it
|
||||
*/
|
||||
function &get_key($config_key)
|
||||
{
|
||||
list($file_name, $section_name, $var_name) = explode('/', $config_key, 3);
|
||||
$result = &$this->get($file_name, $section_name, $var_name);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all loaded config file names.
|
||||
*
|
||||
* @return array an array of loaded config file names
|
||||
*/
|
||||
function get_file_names()
|
||||
{
|
||||
return array_keys($this->_config_data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all section names from a loaded file.
|
||||
*
|
||||
* @param string $file_name config file to get section names from
|
||||
* @return array an array of section names from the specified file
|
||||
*/
|
||||
function get_section_names($file_name)
|
||||
{
|
||||
$file_name = $this->_config_path . $file_name;
|
||||
if (!isset($this->_config_data[$file_name])) {
|
||||
$this->_trigger_error_msg("Unknown config file '$file_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
return array_keys($this->_config_data[$file_name]["sections"]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all global or section variable names.
|
||||
*
|
||||
* @param string $file_name config file to get info for
|
||||
* @param string $section_name (optional) section to get info for
|
||||
* @return array an array of variables names from the specified file/section
|
||||
*/
|
||||
function get_var_names($file_name, $section = NULL)
|
||||
{
|
||||
if (empty($file_name)) {
|
||||
$this->_trigger_error_msg('Empty config file name');
|
||||
return;
|
||||
} else if (!isset($this->_config_data[$file_name])) {
|
||||
$this->_trigger_error_msg("Unknown config file '$file_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($section))
|
||||
return array_keys($this->_config_data[$file_name]["vars"]);
|
||||
else
|
||||
return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear loaded config data for a certain file or all files.
|
||||
*
|
||||
* @param string $file_name file to clear config data for
|
||||
*/
|
||||
function clear($file_name = NULL)
|
||||
{
|
||||
if ($file_name === NULL)
|
||||
$this->_config_data = array();
|
||||
else if (isset($this->_config_data[$file_name]))
|
||||
$this->_config_data[$file_name] = array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a configuration file manually.
|
||||
*
|
||||
* @param string $file_name file name to load
|
||||
* @param boolean $prepend_path whether current config path should be
|
||||
* prepended to the filename
|
||||
*/
|
||||
function load_file($file_name, $prepend_path = true)
|
||||
{
|
||||
if ($prepend_path && $this->_config_path != "")
|
||||
$config_file = $this->_config_path . $file_name;
|
||||
else
|
||||
$config_file = $file_name;
|
||||
|
||||
ini_set('track_errors', true);
|
||||
$fp = @fopen($config_file, "r");
|
||||
if (!is_resource($fp)) {
|
||||
$this->_trigger_error_msg("Could not open config file '$config_file'");
|
||||
return false;
|
||||
}
|
||||
|
||||
$contents = ($size = filesize($config_file)) ? fread($fp, $size) : '';
|
||||
fclose($fp);
|
||||
|
||||
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the contents of a file manually.
|
||||
*
|
||||
* @param string $config_file file name of the related contents
|
||||
* @param string $contents the file-contents to parse
|
||||
*/
|
||||
function set_file_contents($config_file, $contents)
|
||||
{
|
||||
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the source of a configuration file manually.
|
||||
*
|
||||
* @param string $contents the file-contents to parse
|
||||
*/
|
||||
function parse_contents($contents)
|
||||
{
|
||||
if($this->fix_newlines) {
|
||||
// fix mac/dos formatted newlines
|
||||
$contents = preg_replace('!\r\n?!', "\n", $contents);
|
||||
}
|
||||
|
||||
$config_data = array();
|
||||
$config_data['sections'] = array();
|
||||
$config_data['vars'] = array();
|
||||
|
||||
/* reference to fill with data */
|
||||
$vars =& $config_data['vars'];
|
||||
|
||||
/* parse file line by line */
|
||||
preg_match_all('!^.*\r?\n?!m', $contents, $match);
|
||||
$lines = $match[0];
|
||||
for ($i=0, $count=count($lines); $i<$count; $i++) {
|
||||
$line = $lines[$i];
|
||||
if (empty($line)) continue;
|
||||
|
||||
if ( $line{0} == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
|
||||
/* section found */
|
||||
if ($match[1]{0} == '.') {
|
||||
/* hidden section */
|
||||
if ($this->read_hidden) {
|
||||
$section_name = substr($match[1], 1);
|
||||
} else {
|
||||
/* break reference to $vars to ignore hidden section */
|
||||
unset($vars);
|
||||
$vars = array();
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$section_name = $match[1];
|
||||
}
|
||||
if (!isset($config_data['sections'][$section_name]))
|
||||
$config_data['sections'][$section_name] = array('vars' => array());
|
||||
$vars =& $config_data['sections'][$section_name]['vars'];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
|
||||
/* variable found */
|
||||
$var_name = rtrim($match[1]);
|
||||
if (strpos($match[2], '"""') === 0) {
|
||||
/* handle multiline-value */
|
||||
$lines[$i] = substr($match[2], 3);
|
||||
$var_value = '';
|
||||
while ($i<$count) {
|
||||
if (($pos = strpos($lines[$i], '"""')) === false) {
|
||||
$var_value .= $lines[$i++];
|
||||
} else {
|
||||
/* end of multiline-value */
|
||||
$var_value .= substr($lines[$i], 0, $pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$booleanize = false;
|
||||
|
||||
} else {
|
||||
/* handle simple value */
|
||||
$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
|
||||
$booleanize = $this->booleanize;
|
||||
|
||||
}
|
||||
$this->_set_config_var($vars, $var_name, $var_value, $booleanize);
|
||||
}
|
||||
/* else unparsable line / means it is a comment / means ignore it */
|
||||
}
|
||||
return $config_data;
|
||||
}
|
||||
|
||||
/**#@+ @access private */
|
||||
/**
|
||||
* @param array &$container
|
||||
* @param string $var_name
|
||||
* @param mixed $var_value
|
||||
* @param boolean $booleanize determines whether $var_value is converted to
|
||||
* to true/false
|
||||
*/
|
||||
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)) {
|
||||
$this->_trigger_error_msg("Bad variable name '$var_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($booleanize) {
|
||||
if (preg_match("/^(on|true|yes)$/i", $var_value))
|
||||
$var_value = true;
|
||||
else if (preg_match("/^(off|false|no)$/i", $var_value))
|
||||
$var_value = false;
|
||||
}
|
||||
|
||||
if (!isset($container[$var_name]) || $this->overwrite)
|
||||
$container[$var_name] = $var_value;
|
||||
else {
|
||||
settype($container[$var_name], 'array');
|
||||
$container[$var_name][] = $var_value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses trigger_error() creates a PHP warning/error
|
||||
* @param string $error_msg
|
||||
* @param integer $error_type one of
|
||||
*/
|
||||
function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)
|
||||
{
|
||||
trigger_error("Config_File error: $error_msg", $error_type);
|
||||
}
|
||||
/**#@-*/
|
||||
}
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Config_File class.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* For questions, help, comments, discussion, etc., please join the
|
||||
* Smarty mailing list. Send a blank e-mail to
|
||||
* smarty-discussion-subscribe@googlegroups.com
|
||||
*
|
||||
* @link http://www.smarty.net/
|
||||
* @version 2.6.25-dev
|
||||
* @copyright Copyright: 2001-2005 New Digital Group, Inc.
|
||||
* @author Andrei Zmievski <andrei@php.net>
|
||||
* @access public
|
||||
* @package Smarty
|
||||
*/
|
||||
|
||||
/* $Id: Config_File.class.php 3149 2009-05-23 20:59:25Z monte.ohrt $ */
|
||||
|
||||
/**
|
||||
* Config file reading class
|
||||
* @package Smarty
|
||||
*/
|
||||
class Config_File {
|
||||
/**#@+
|
||||
* Options
|
||||
* @var boolean
|
||||
*/
|
||||
/**
|
||||
* Controls whether variables with the same name overwrite each other.
|
||||
*/
|
||||
var $overwrite = true;
|
||||
|
||||
/**
|
||||
* Controls whether config values of on/true/yes and off/false/no get
|
||||
* converted to boolean values automatically.
|
||||
*/
|
||||
var $booleanize = true;
|
||||
|
||||
/**
|
||||
* Controls whether hidden config sections/vars are read from the file.
|
||||
*/
|
||||
var $read_hidden = true;
|
||||
|
||||
/**
|
||||
* Controls whether or not to fix mac or dos formatted newlines.
|
||||
* If set to true, \r or \r\n will be changed to \n.
|
||||
*/
|
||||
var $fix_newlines = true;
|
||||
/**#@-*/
|
||||
|
||||
/** @access private */
|
||||
var $_config_path = "";
|
||||
var $_config_data = array();
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructs a new config file class.
|
||||
*
|
||||
* @param string $config_path (optional) path to the config files
|
||||
*/
|
||||
function Config_File($config_path = NULL)
|
||||
{
|
||||
if (isset($config_path))
|
||||
$this->set_path($config_path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the path where configuration files can be found.
|
||||
*
|
||||
* @param string $config_path path to the config files
|
||||
*/
|
||||
function set_path($config_path)
|
||||
{
|
||||
if (!empty($config_path)) {
|
||||
if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) {
|
||||
$this->_trigger_error_msg("Bad config file path '$config_path'");
|
||||
return;
|
||||
}
|
||||
if(substr($config_path, -1) != DIRECTORY_SEPARATOR) {
|
||||
$config_path .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$this->_config_path = $config_path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves config info based on the file, section, and variable name.
|
||||
*
|
||||
* @param string $file_name config file to get info for
|
||||
* @param string $section_name (optional) section to get info for
|
||||
* @param string $var_name (optional) variable to get info for
|
||||
* @return string|array a value or array of values
|
||||
*/
|
||||
function get($file_name, $section_name = NULL, $var_name = NULL)
|
||||
{
|
||||
if (empty($file_name)) {
|
||||
$this->_trigger_error_msg('Empty config file name');
|
||||
return;
|
||||
} else {
|
||||
$file_name = $this->_config_path . $file_name;
|
||||
if (!isset($this->_config_data[$file_name]))
|
||||
$this->load_file($file_name, false);
|
||||
}
|
||||
|
||||
if (!empty($var_name)) {
|
||||
if (empty($section_name)) {
|
||||
return $this->_config_data[$file_name]["vars"][$var_name];
|
||||
} else {
|
||||
if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name]))
|
||||
return $this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
} else {
|
||||
if (empty($section_name)) {
|
||||
return (array)$this->_config_data[$file_name]["vars"];
|
||||
} else {
|
||||
if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"]))
|
||||
return (array)$this->_config_data[$file_name]["sections"][$section_name]["vars"];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves config info based on the key.
|
||||
*
|
||||
* @param $file_name string config key (filename/section/var)
|
||||
* @return string|array same as get()
|
||||
* @uses get() retrieves information from config file and returns it
|
||||
*/
|
||||
function &get_key($config_key)
|
||||
{
|
||||
list($file_name, $section_name, $var_name) = explode('/', $config_key, 3);
|
||||
$result = &$this->get($file_name, $section_name, $var_name);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all loaded config file names.
|
||||
*
|
||||
* @return array an array of loaded config file names
|
||||
*/
|
||||
function get_file_names()
|
||||
{
|
||||
return array_keys($this->_config_data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all section names from a loaded file.
|
||||
*
|
||||
* @param string $file_name config file to get section names from
|
||||
* @return array an array of section names from the specified file
|
||||
*/
|
||||
function get_section_names($file_name)
|
||||
{
|
||||
$file_name = $this->_config_path . $file_name;
|
||||
if (!isset($this->_config_data[$file_name])) {
|
||||
$this->_trigger_error_msg("Unknown config file '$file_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
return array_keys($this->_config_data[$file_name]["sections"]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all global or section variable names.
|
||||
*
|
||||
* @param string $file_name config file to get info for
|
||||
* @param string $section_name (optional) section to get info for
|
||||
* @return array an array of variables names from the specified file/section
|
||||
*/
|
||||
function get_var_names($file_name, $section = NULL)
|
||||
{
|
||||
if (empty($file_name)) {
|
||||
$this->_trigger_error_msg('Empty config file name');
|
||||
return;
|
||||
} else if (!isset($this->_config_data[$file_name])) {
|
||||
$this->_trigger_error_msg("Unknown config file '$file_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($section))
|
||||
return array_keys($this->_config_data[$file_name]["vars"]);
|
||||
else
|
||||
return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear loaded config data for a certain file or all files.
|
||||
*
|
||||
* @param string $file_name file to clear config data for
|
||||
*/
|
||||
function clear($file_name = NULL)
|
||||
{
|
||||
if ($file_name === NULL)
|
||||
$this->_config_data = array();
|
||||
else if (isset($this->_config_data[$file_name]))
|
||||
$this->_config_data[$file_name] = array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a configuration file manually.
|
||||
*
|
||||
* @param string $file_name file name to load
|
||||
* @param boolean $prepend_path whether current config path should be
|
||||
* prepended to the filename
|
||||
*/
|
||||
function load_file($file_name, $prepend_path = true)
|
||||
{
|
||||
if ($prepend_path && $this->_config_path != "")
|
||||
$config_file = $this->_config_path . $file_name;
|
||||
else
|
||||
$config_file = $file_name;
|
||||
|
||||
ini_set('track_errors', true);
|
||||
$fp = @fopen($config_file, "r");
|
||||
if (!is_resource($fp)) {
|
||||
$this->_trigger_error_msg("Could not open config file '$config_file'");
|
||||
return false;
|
||||
}
|
||||
|
||||
$contents = ($size = filesize($config_file)) ? fread($fp, $size) : '';
|
||||
fclose($fp);
|
||||
|
||||
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the contents of a file manually.
|
||||
*
|
||||
* @param string $config_file file name of the related contents
|
||||
* @param string $contents the file-contents to parse
|
||||
*/
|
||||
function set_file_contents($config_file, $contents)
|
||||
{
|
||||
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the source of a configuration file manually.
|
||||
*
|
||||
* @param string $contents the file-contents to parse
|
||||
*/
|
||||
function parse_contents($contents)
|
||||
{
|
||||
if($this->fix_newlines) {
|
||||
// fix mac/dos formatted newlines
|
||||
$contents = preg_replace('!\r\n?!', "\n", $contents);
|
||||
}
|
||||
|
||||
$config_data = array();
|
||||
$config_data['sections'] = array();
|
||||
$config_data['vars'] = array();
|
||||
|
||||
/* reference to fill with data */
|
||||
$vars =& $config_data['vars'];
|
||||
|
||||
/* parse file line by line */
|
||||
preg_match_all('!^.*\r?\n?!m', $contents, $match);
|
||||
$lines = $match[0];
|
||||
for ($i=0, $count=count($lines); $i<$count; $i++) {
|
||||
$line = $lines[$i];
|
||||
if (empty($line)) continue;
|
||||
|
||||
if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
|
||||
/* section found */
|
||||
if (substr($match[1], 0, 1) == '.') {
|
||||
/* hidden section */
|
||||
if ($this->read_hidden) {
|
||||
$section_name = substr($match[1], 1);
|
||||
} else {
|
||||
/* break reference to $vars to ignore hidden section */
|
||||
unset($vars);
|
||||
$vars = array();
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$section_name = $match[1];
|
||||
}
|
||||
if (!isset($config_data['sections'][$section_name]))
|
||||
$config_data['sections'][$section_name] = array('vars' => array());
|
||||
$vars =& $config_data['sections'][$section_name]['vars'];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
|
||||
/* variable found */
|
||||
$var_name = rtrim($match[1]);
|
||||
if (strpos($match[2], '"""') === 0) {
|
||||
/* handle multiline-value */
|
||||
$lines[$i] = substr($match[2], 3);
|
||||
$var_value = '';
|
||||
while ($i<$count) {
|
||||
if (($pos = strpos($lines[$i], '"""')) === false) {
|
||||
$var_value .= $lines[$i++];
|
||||
} else {
|
||||
/* end of multiline-value */
|
||||
$var_value .= substr($lines[$i], 0, $pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$booleanize = false;
|
||||
|
||||
} else {
|
||||
/* handle simple value */
|
||||
$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
|
||||
$booleanize = $this->booleanize;
|
||||
|
||||
}
|
||||
$this->_set_config_var($vars, $var_name, $var_value, $booleanize);
|
||||
}
|
||||
/* else unparsable line / means it is a comment / means ignore it */
|
||||
}
|
||||
return $config_data;
|
||||
}
|
||||
|
||||
/**#@+ @access private */
|
||||
/**
|
||||
* @param array &$container
|
||||
* @param string $var_name
|
||||
* @param mixed $var_value
|
||||
* @param boolean $booleanize determines whether $var_value is converted to
|
||||
* to true/false
|
||||
*/
|
||||
function _set_config_var(&$container, $var_name, $var_value, $booleanize)
|
||||
{
|
||||
if (substr($var_name, 0, 1) == '.') {
|
||||
if (!$this->read_hidden)
|
||||
return;
|
||||
else
|
||||
$var_name = substr($var_name, 1);
|
||||
}
|
||||
|
||||
if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) {
|
||||
$this->_trigger_error_msg("Bad variable name '$var_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($booleanize) {
|
||||
if (preg_match("/^(on|true|yes)$/i", $var_value))
|
||||
$var_value = true;
|
||||
else if (preg_match("/^(off|false|no)$/i", $var_value))
|
||||
$var_value = false;
|
||||
}
|
||||
|
||||
if (!isset($container[$var_name]) || $this->overwrite)
|
||||
$container[$var_name] = $var_value;
|
||||
else {
|
||||
settype($container[$var_name], 'array');
|
||||
$container[$var_name][] = $var_value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses trigger_error() creates a PHP warning/error
|
||||
* @param string $error_msg
|
||||
* @param integer $error_type one of
|
||||
*/
|
||||
function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)
|
||||
{
|
||||
trigger_error("Config_File error: $error_msg", $error_type);
|
||||
}
|
||||
/**#@-*/
|
||||
}
|
||||
|
||||
?>
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,64 +1,157 @@
|
||||
{* Smarty *}
|
||||
{* debug.tpl, last updated version 2.1.0 *}
|
||||
{assign_debug_info}
|
||||
{capture assign=debug_output}
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>Smarty Debug Console</title>
|
||||
{literal}
|
||||
<style type="text/css">
|
||||
/* <![CDATA[ */
|
||||
body, h1, h2, td, th, p {
|
||||
font-family: sans-serif;
|
||||
font-weight: normal;
|
||||
font-size: 0.9em;
|
||||
margin: 1px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
{* debug.tpl, last updated version 2.0.1 *}
|
||||
h1 {
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
padding: 2px;
|
||||
background-color: #f0c040;
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
{assign_debug_info}
|
||||
h2 {
|
||||
background-color: #9B410E;
|
||||
color: white;
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
padding: 2px;
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
|
||||
body {
|
||||
background: black;
|
||||
}
|
||||
|
||||
p, table, div {
|
||||
background: #f0ead8;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-style: italic;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th, td {
|
||||
font-family: monospace;
|
||||
vertical-align: top;
|
||||
text-align: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
td {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.odd {
|
||||
background-color: #eeeeee;
|
||||
}
|
||||
|
||||
.even {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
.exectime {
|
||||
font-size: 0.8em;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
#table_assigned_vars th {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
#table_config_vars th {
|
||||
color: maroon;
|
||||
}
|
||||
/* ]]> */
|
||||
</style>
|
||||
{/literal}
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Smarty Debug Console</h1>
|
||||
|
||||
<h2>included templates & config files (load time in seconds)</h2>
|
||||
|
||||
<div>
|
||||
{section name=templates loop=$_debug_tpls}
|
||||
{section name=indent loop=$_debug_tpls[templates].depth} {/section}
|
||||
<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>
|
||||
{$_debug_tpls[templates].filename|escape:html}</font>
|
||||
{if isset($_debug_tpls[templates].exec_time)}
|
||||
<span class="exectime">
|
||||
({$_debug_tpls[templates].exec_time|string_format:"%.5f"})
|
||||
{if %templates.index% eq 0}(total){/if}
|
||||
</span>
|
||||
{/if}
|
||||
<br />
|
||||
{sectionelse}
|
||||
<p>no templates included</p>
|
||||
{/section}
|
||||
</div>
|
||||
|
||||
<h2>assigned template variables</h2>
|
||||
|
||||
<table id="table_assigned_vars">
|
||||
{section name=vars loop=$_debug_keys}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<th>{ldelim}${$_debug_keys[vars]|escape:'html'}{rdelim}</th>
|
||||
<td>{$_debug_vals[vars]|@debug_print_var}</td></tr>
|
||||
{sectionelse}
|
||||
<tr><td><p>no template variables assigned</p></td></tr>
|
||||
{/section}
|
||||
</table>
|
||||
|
||||
<h2>assigned config file variables (outer template scope)</h2>
|
||||
|
||||
<table id="table_config_vars">
|
||||
{section name=config_vars loop=$_debug_config_keys}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<th>{ldelim}#{$_debug_config_keys[config_vars]|escape:'html'}#{rdelim}</th>
|
||||
<td>{$_debug_config_vals[config_vars]|@debug_print_var}</td></tr>
|
||||
{sectionelse}
|
||||
<tr><td><p>no config vars assigned</p></td></tr>
|
||||
{/section}
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
{/capture}
|
||||
{if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"}
|
||||
<table border=0 width=100%>
|
||||
<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>
|
||||
<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>
|
||||
{section name=templates loop=$_debug_tpls}
|
||||
<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth} {/section}<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>{$_debug_tpls[templates].filename|escape:html}</font>{if isset($_debug_tpls[templates].exec_time)} <font size=-1><i>({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}</i></font>{/if}</tt></td></tr>
|
||||
{sectionelse}
|
||||
<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>
|
||||
{/section}
|
||||
<tr bgcolor=#cccccc><td colspan=2><b>assigned template variables:</b></td></tr>
|
||||
{section name=vars loop=$_debug_keys}
|
||||
<tr bgcolor={if %vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=blue>{ldelim}${$_debug_keys[vars]}{rdelim}</font></tt></td><td nowrap><tt><font color=green>{$_debug_vals[vars]|@debug_print_var}</font></tt></td></tr>
|
||||
{sectionelse}
|
||||
<tr bgcolor=#eeeeee><td colspan=2><tt><i>no template variables assigned</i></tt></td></tr>
|
||||
{/section}
|
||||
<tr bgcolor=#cccccc><td colspan=2><b>assigned config file variables (outer template scope):</b></td></tr>
|
||||
{section name=config_vars loop=$_debug_config_keys}
|
||||
<tr bgcolor={if %config_vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=maroon>{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></tt></td><td><tt><font color=green>{$_debug_config_vals[config_vars]|@debug_print_var}</font></tt></td></tr>
|
||||
{sectionelse}
|
||||
<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>
|
||||
{/section}
|
||||
</table>
|
||||
</BODY></HTML>
|
||||
{$debug_output}
|
||||
{else}
|
||||
<SCRIPT language=javascript>
|
||||
if( self.name == '' ) {ldelim}
|
||||
var title = 'Console';
|
||||
{rdelim}
|
||||
else {ldelim}
|
||||
var title = 'Console_' + self.name;
|
||||
{rdelim}
|
||||
_smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
|
||||
_smarty_console.document.write("<HTML><HEAD><TITLE>Smarty Debug Console_"+self.name+"</TITLE></HEAD><BODY bgcolor=#ffffff>");
|
||||
_smarty_console.document.write("<table border=0 width=100%>");
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>");
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>");
|
||||
{section name=templates loop=$_debug_tpls}
|
||||
_smarty_console.document.write("<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth} {/section}<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>{$_debug_tpls[templates].filename|escape:html|escape:javascript}</font>{if isset($_debug_tpls[templates].exec_time)} <font size=-1><i>({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}</i></font>{/if}</tt></td></tr>");
|
||||
{sectionelse}
|
||||
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>");
|
||||
{/section}
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>assigned template variables:</b></td></tr>");
|
||||
{section name=vars loop=$_debug_keys}
|
||||
_smarty_console.document.write("<tr bgcolor={if %vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=blue>{ldelim}${$_debug_keys[vars]}{rdelim}</font></tt></td><td nowrap><tt><font color=green>{$_debug_vals[vars]|@debug_print_var|escape:javascript}</font></tt></td></tr>");
|
||||
{sectionelse}
|
||||
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no template variables assigned</i></tt></td></tr>");
|
||||
{/section}
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>assigned config file variables (outer template scope):</b></td></tr>");
|
||||
{section name=config_vars loop=$_debug_config_keys}
|
||||
_smarty_console.document.write("<tr bgcolor={if %config_vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=maroon>{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></tt></td><td><tt><font color=green>{$_debug_config_vals[config_vars]|@debug_print_var|escape:javascript}</font></tt></td></tr>");
|
||||
{sectionelse}
|
||||
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>");
|
||||
{/section}
|
||||
_smarty_console.document.write("</table>");
|
||||
_smarty_console.document.write("</BODY></HTML>");
|
||||
_smarty_console.document.close();
|
||||
</SCRIPT>
|
||||
{/if}
|
||||
<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
if ( self.name == '' ) {ldelim}
|
||||
var title = 'Console';
|
||||
{rdelim}
|
||||
else {ldelim}
|
||||
var title = 'Console_' + self.name;
|
||||
{rdelim}
|
||||
_smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
|
||||
_smarty_console.document.write('{$debug_output|escape:'javascript'}');
|
||||
_smarty_console.document.close();
|
||||
// ]]>
|
||||
</script>
|
||||
{/if}
|
Loading…
Reference in New Issue