78 if (isset($config_path))
90 if (!empty($config_path)) {
91 if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) {
99 $this->_config_path = $config_path;
112 function get($file_name, $section_name = NULL, $var_name = NULL)
114 if (empty($file_name)) {
118 $file_name = $this->_config_path . $file_name;
119 if (!isset($this->_config_data[$file_name]))
123 if (!empty($var_name)) {
124 if (empty($section_name)) {
125 return $this->_config_data[$file_name][
"vars"][$var_name];
127 if(isset($this->_config_data[$file_name][
"sections"][$section_name][
"vars"][$var_name]))
128 return $this->_config_data[$file_name][
"sections"][$section_name][
"vars"][$var_name];
133 if (empty($section_name)) {
134 return (array)$this->_config_data[$file_name][
"vars"];
136 if(isset($this->_config_data[$file_name][
"sections"][$section_name][
"vars"]))
137 return (array)$this->_config_data[$file_name][
"sections"][$section_name][
"vars"];
154 list($file_name, $section_name, $var_name) = explode(
'/', $config_key, 3);
155 $result = &$this->
get($file_name, $section_name, $var_name);
166 return array_keys($this->_config_data);
178 $file_name = $this->_config_path . $file_name;
179 if (!isset($this->_config_data[$file_name])) {
184 return array_keys($this->_config_data[$file_name][
"sections"]);
197 if (empty($file_name)) {
200 }
else if (!isset($this->_config_data[$file_name])) {
206 return array_keys($this->_config_data[$file_name][
"vars"]);
208 return array_keys($this->_config_data[$file_name][
"sections"][$section][
"vars"]);
219 if ($file_name === NULL)
220 $this->_config_data = array();
221 else if (isset($this->_config_data[$file_name]))
222 $this->_config_data[$file_name] = array();
235 if ($prepend_path && $this->_config_path !=
"")
236 $config_file = $this->_config_path . $file_name;
238 $config_file = $file_name;
240 ini_set(
'track_errors',
true);
241 $fp = @fopen($config_file,
"r");
242 if (!is_resource($fp)) {
247 $contents = ($size = filesize($config_file)) ? fread($fp, $size) :
'';
250 $this->_config_data[$config_file] = $this->
parse_contents($contents);
262 $this->_config_data[$config_file] = $this->
parse_contents($contents);
273 if($this->fix_newlines) {
275 $contents = preg_replace(
'!\r\n?!',
"\n", $contents);
278 $config_data = array();
279 $config_data[
'sections'] = array();
280 $config_data[
'vars'] = array();
283 $vars =& $config_data[
'vars'];
286 preg_match_all(
'!^.*\r?\n?!m', $contents, $match);
288 for (
$i=0, $count=count($lines);
$i<$count;
$i++) {
290 if (empty($line))
continue;
292 if ( substr($line, 0, 1) ==
'[' && preg_match(
'!^\[(.*?)\]!', $line, $match) ) {
294 if (substr($match[1], 0, 1) ==
'.') {
296 if ($this->read_hidden) {
297 $section_name = substr($match[1], 1);
305 $section_name = $match[1];
307 if (!isset($config_data[
'sections'][$section_name]))
308 $config_data[
'sections'][$section_name] = array(
'vars' => array());
309 $vars =& $config_data[
'sections'][$section_name][
'vars'];
313 if (preg_match(
'/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
315 $var_name = rtrim($match[1]);
316 if (strpos($match[2],
'"""') === 0) {
318 $lines[
$i] = substr($match[2], 3);
321 if ((
$pos = strpos($lines[
$i],
'"""')) ===
false) {
322 $var_value .= $lines[$i++];
325 $var_value .= substr($lines[$i], 0,
$pos);
333 $var_value = preg_replace(
'/^([\'"])(.*)\1$/',
'\2', rtrim($match[2]));
354 if (substr($var_name, 0, 1) ==
'.') {
355 if (!$this->read_hidden)
358 $var_name = substr($var_name, 1);
361 if (!preg_match(
"/^[a-zA-Z_]\w*$/", $var_name)) {
367 if (preg_match(
"/^(on|true|yes)$/i", $var_value))
369 else if (preg_match(
"/^(off|false|no)$/i", $var_value))
373 if (!isset($container[$var_name]) || $this->overwrite)
374 $container[$var_name] = $var_value;
376 settype($container[$var_name],
'array');
377 $container[$var_name][] = $var_value;
388 trigger_error(
"Config_File error: $error_msg", $error_type);