removed mods directory from the ATutor codebase
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / Config_File.class.php
diff --git a/mods/phpdoc2/PhpDocumentor/phpDocumentor/Smarty-2.6.0/libs/Config_File.class.php b/mods/phpdoc2/PhpDocumentor/phpDocumentor/Smarty-2.6.0/libs/Config_File.class.php
deleted file mode 100644 (file)
index 2b99af2..0000000
+++ /dev/null
@@ -1,365 +0,0 @@
-<?php\r
-\r
-/**\r
- * Config_File class.\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2.1 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- *\r
- * You may contact the author of Config_File by e-mail at:\r
- * {@link andrei@php.net}\r
- *\r
- * The latest version of Config_File can be obtained from:\r
- * http://smarty.php.net/\r
- *\r
- * @link http://smarty.php.net/\r
- * @version 2.6.0\r
- * @copyright Copyright: 2001-2003 ispi of Lincoln, Inc.\r
- * @author Andrei Zmievski <andrei@php.net>\r
- * @access public\r
- * @package Smarty\r
- */\r
-\r
-/* $Id: Config_File.class.php,v 1.1 2005/10/17 18:37:39 jeichorn Exp $ */\r
-/**\r
- * Config file reading class\r
- * @package Smarty\r
- */\r
-class Config_File {\r
-    /**#@+\r
-     * Options\r
-     * @var boolean\r
-     */\r
-    /**\r
-     * Controls whether variables with the same name overwrite each other.\r
-     */\r
-    var $overwrite        =    true;\r
-\r
-    /**\r
-     * Controls whether config values of on/true/yes and off/false/no get\r
-     * converted to boolean values automatically.\r
-     */\r
-    var $booleanize        =    true;\r
-\r
-    /**\r
-     * Controls whether hidden config sections/vars are read from the file.\r
-     */\r
-    var $read_hidden     =    true;\r
-\r
-    /**\r
-     * Controls whether or not to fix mac or dos formatted newlines.\r
-     * If set to true, \r or \r\n will be changed to \n.\r
-     */\r
-    var $fix_newlines =    true;\r
-    /**#@-*/\r
-\r
-    /** @access private */\r
-    var $_config_path    = "";\r
-    var $_config_data    = array();\r
-    /**#@-*/\r
-\r
-    /**\r
-     * Constructs a new config file class.\r
-     *\r
-     * @param string $config_path (optional) path to the config files\r
-     */\r
-    function Config_File($config_path = NULL)\r
-    {\r
-        if (isset($config_path))\r
-            $this->set_path($config_path);\r
-    }\r
-\r
-\r
-    /**\r
-     * Set the path where configuration files can be found.\r
-     *\r
-     * @param string $config_path path to the config files\r
-     */\r
-    function set_path($config_path)\r
-    {\r
-        if (!empty($config_path)) {\r
-            if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) {\r
-                $this->_trigger_error_msg("Bad config file path '$config_path'");\r
-                return;\r
-            }\r
-            if(substr($config_path, -1) != DIRECTORY_SEPARATOR) {\r
-                $config_path .= DIRECTORY_SEPARATOR;\r
-            }\r
-\r
-            $this->_config_path = $config_path;\r
-        }\r
-    }\r
-\r
-\r
-    /**\r
-     * Retrieves config info based on the file, section, and variable name.\r
-     *\r
-     * @param string $file_name config file to get info for\r
-     * @param string $section_name (optional) section to get info for\r
-     * @param string $var_name (optional) variable to get info for\r
-     * @return string|array a value or array of values\r
-     */\r
-    function &get($file_name, $section_name = NULL, $var_name = NULL)\r
-    {\r
-        if (empty($file_name)) {\r
-            $this->_trigger_error_msg('Empty config file name');\r
-            return;\r
-        } else {\r
-            $file_name = $this->_config_path . $file_name;\r
-            if (!isset($this->_config_data[$file_name]))\r
-                $this->load_file($file_name, false);\r
-        }\r
-\r
-        if (!empty($var_name)) {\r
-            if (empty($section_name)) {\r
-                return $this->_config_data[$file_name]["vars"][$var_name];\r
-            } else {\r
-                if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name]))\r
-                    return $this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name];\r
-                else\r
-                    return array();\r
-            }\r
-        } else {\r
-            if (empty($section_name)) {\r
-                return (array)$this->_config_data[$file_name]["vars"];\r
-            } else {\r
-                if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"]))\r
-                    return (array)$this->_config_data[$file_name]["sections"][$section_name]["vars"];\r
-                else\r
-                    return array();\r
-            }\r
-        }\r
-    }\r
-\r
-\r
-    /**\r
-     * Retrieves config info based on the key.\r
-     *\r
-     * @param $file_name string config key (filename/section/var)\r
-     * @return string|array same as get()\r
-     * @uses get() retrieves information from config file and returns it\r
-     */\r
-    function &get_key($config_key)\r
-    {\r
-        list($file_name, $section_name, $var_name) = explode('/', $config_key, 3);\r
-        $result = &$this->get($file_name, $section_name, $var_name);\r
-        return $result;\r
-    }\r
-\r
-    /**\r
-     * Get all loaded config file names.\r
-     *\r
-     * @return array an array of loaded config file names\r
-     */\r
-    function get_file_names()\r
-    {\r
-        return array_keys($this->_config_data);\r
-    }\r
-\r
-\r
-    /**\r
-     * Get all section names from a loaded file.\r
-     *\r
-     * @param string $file_name config file to get section names from\r
-     * @return array an array of section names from the specified file\r
-     */\r
-    function get_section_names($file_name)\r
-    {\r
-        $file_name = $this->_config_path . $file_name;\r
-        if (!isset($this->_config_data[$file_name])) {\r
-            $this->_trigger_error_msg("Unknown config file '$file_name'");\r
-            return;\r
-        }\r
-\r
-        return array_keys($this->_config_data[$file_name]["sections"]);\r
-    }\r
-\r
-\r
-    /**\r
-     * Get all global or section variable names.\r
-     *\r
-     * @param string $file_name config file to get info for\r
-     * @param string $section_name (optional) section to get info for\r
-     * @return array an array of variables names from the specified file/section\r
-     */\r
-    function get_var_names($file_name, $section = NULL)\r
-    {\r
-        if (empty($file_name)) {\r
-            $this->_trigger_error_msg('Empty config file name');\r
-            return;\r
-        } else if (!isset($this->_config_data[$file_name])) {\r
-            $this->_trigger_error_msg("Unknown config file '$file_name'");\r
-            return;\r
-        }\r
-\r
-        if (empty($section))\r
-            return array_keys($this->_config_data[$file_name]["vars"]);\r
-        else\r
-            return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]);\r
-    }\r
-\r
-\r
-    /**\r
-     * Clear loaded config data for a certain file or all files.\r
-     *\r
-     * @param string $file_name file to clear config data for\r
-     */\r
-    function clear($file_name = NULL)\r
-    {\r
-        if ($file_name === NULL)\r
-            $this->_config_data = array();\r
-        else if (isset($this->_config_data[$file_name]))\r
-            $this->_config_data[$file_name] = array();\r
-    }\r
-\r
-\r
-    /**\r
-     * Load a configuration file manually.\r
-     *\r
-     * @param string $file_name file name to load\r
-     * @param boolean $prepend_path whether current config path should be\r
-     *                              prepended to the filename\r
-     */\r
-    function load_file($file_name, $prepend_path = true)\r
-    {\r
-        if ($prepend_path && $this->_config_path != "")\r
-            $config_file = $this->_config_path . $file_name;\r
-        else\r
-            $config_file = $file_name;\r
-\r
-        ini_set('track_errors', true);\r
-        $fp = @fopen($config_file, "r");\r
-        if (!is_resource($fp)) {\r
-            $this->_trigger_error_msg("Could not open config file '$config_file'");\r
-            return false;\r
-        }\r
-\r
-        $contents = fread($fp, filesize($config_file));\r
-        fclose($fp);\r
-\r
-        if($this->fix_newlines) {\r
-            // fix mac/dos formatted newlines\r
-            $contents = preg_replace('!\r\n?!',"\n",$contents);\r
-        }\r
-\r
-        $config_data = array();\r
-\r
-        /* replace all multi-line values by placeholders */\r
-        if (preg_match_all('/"""(.*)"""/Us', $contents, $match)) {\r
-            $_triple_quotes = $match[1];\r
-            $_i = 0;\r
-            $contents = preg_replace('/""".*"""/Use', '"\x1b\x1b\x1b".$_i++."\x1b\x1b\x1b"', $contents);\r
-        } else {\r
-            $_triple_quotes = null;\r
-        }\r
-\r
-        /* Get global variables first. */\r
-        if ($contents{0} != '[' && preg_match("/^(.*?)(\n\[|\Z)/s", $contents, $match))\r
-            $config_data["vars"] = $this->_parse_config_block($match[1], $_triple_quotes);\r
-\r
-        /* Get section variables. */\r
-        $config_data["sections"] = array();\r
-        preg_match_all("/^\[(.*?)\]/m", $contents, $match);\r
-        foreach ($match[1] as $section) {\r
-            if ($section{0} == '.' && !$this->read_hidden)\r
-                continue;\r
-            if (preg_match("/\[".preg_quote($section, '/')."\](.*?)(\n\[|\Z)/s", $contents, $match))\r
-                if ($section{0} == '.')\r
-                    $section = substr($section, 1);\r
-                $config_data["sections"][$section]["vars"] = $this->_parse_config_block($match[1], $_triple_quotes);\r
-        }\r
-\r
-        $this->_config_data[$config_file] = $config_data;\r
-\r
-        return true;\r
-    }\r
-\r
-    /**#@+ @access private */\r
-    /**\r
-     * @var string $config_block\r
-     */\r
-    function _parse_config_block($config_block, $triple_quotes)\r
-    {\r
-        $vars = array();\r
-\r
-        /* First we grab the multi-line values. */\r
-        if (preg_match_all("/^([^=\n]+)=\s*\x1b\x1b\x1b(\d+)\x1b\x1b\x1b\s*$/ms", $config_block, $match, PREG_SET_ORDER)) {\r
-            for ($i = 0; $i < count($match); $i++) {\r
-                $this->_set_config_var($vars, trim($match[$i][1]), $triple_quotes[$match[$i][2]], false);\r
-            }\r
-            $config_block = preg_replace("/^[^=\n]+=\s*\x1b\x1b\x1b\d+\x1b\x1b\x1b\s*$/ms", "", $config_block);\r
-        }\r
-\r
-\r
-        $config_lines = preg_split("/\n+/", $config_block);\r
-\r
-        foreach ($config_lines as $line) {\r
-            if (preg_match("/^\s*(\.?\w+)\s*=(.*)/", $line, $match)) {\r
-                $var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', trim($match[2]));\r
-                $this->_set_config_var($vars, trim($match[1]), $var_value, $this->booleanize);\r
-            }\r
-        }\r
-\r
-        return $vars;\r
-    }\r
-\r
-    /**\r
-     * @param array &$container\r
-     * @param string $var_name\r
-     * @param mixed $var_value\r
-     * @param boolean $booleanize determines whether $var_value is converted to\r
-     *                            to true/false\r
-     */\r
-    function _set_config_var(&$container, $var_name, $var_value, $booleanize)\r
-    {\r
-        if ($var_name{0} == '.') {\r
-            if (!$this->read_hidden)\r
-                return;\r
-            else\r
-                $var_name = substr($var_name, 1);\r
-        }\r
-\r
-        if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) {\r
-            $this->_trigger_error_msg("Bad variable name '$var_name'");\r
-            return;\r
-        }\r
-\r
-        if ($booleanize) {\r
-            if (preg_match("/^(on|true|yes)$/i", $var_value))\r
-                $var_value = true;\r
-            else if (preg_match("/^(off|false|no)$/i", $var_value))\r
-                $var_value = false;\r
-        }\r
-\r
-        if (!isset($container[$var_name]) || $this->overwrite)\r
-            $container[$var_name] = $var_value;\r
-        else {\r
-            settype($container[$var_name], 'array');\r
-            $container[$var_name][] = $var_value;\r
-        }\r
-    }\r
-\r
-    /**\r
-     * @uses trigger_error() creates a PHP warning/error\r
-     * @param string $error_msg\r
-     * @param integer $error_type one of\r
-     */\r
-    function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)\r
-    {\r
-        trigger_error("Config_File error: $error_msg", $error_type);\r
-    }\r
-    /**#@-*/\r
-}\r
-\r
-?>\r