]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - Classes/class-unrealconf.php
3 require_once("../inc/common.php");
7 static $settings_short = [];
8 static $settings_temp = [];
10 function __construct($filename, &$error)
12 if (!is_file($filename))
14 $error[] = "Not a valid configuration file: $filename";
18 $file = file_get_contents($filename);
19 $file = preg_replace('/\/\*(.|\s)*?\*\//', '', $file);
20 //$file = preg_replace('/\/\/(.|\s)*?\n/', '', $file);
21 $file = str_replace("\t
"," ",$file);
22 $file = str_replace("\n\n
","\n
",$file);
23 $file = str_replace("\n
", " ",$file);
24 for(; strstr($file," ");)
25 $file = str_replace(" "," ",$file);
26 $config = $this->parse_config($file, $error);
30 private function parse_config($string, &$error)
32 $tok = split($string);
38 if ($str[0] == '#' || substr($str,0,2) == "//")
43 if (!strcmp($str,"{") && mb_substr($blockstring,-2,2) !== "::")
44 strcat($blockstring,"::");
46 elseif (!strcmp($str,"}"))
48 $split = split($blockstring,"::");
49 if (BadPtr($split[sizeof($split) - 1]))
50 unset($split[sizeof($split) - 1]);
51 unset($split[sizeof($split) - 1]);
52 $blockstring = glue($split,"::");
53 if (!BadPtr($blockstring))
55 strcat($blockstring,"::");
58 // if we found a value and it's time to go to the next one
59 elseif (!BadPtr($str) && $str[strlen($str) - 1] == ";")
61 if (substr_count($str,"\"") != 1)
62 strcat($blockstring, "::".rtrim($str,";")); // finish off our item
63 else strcat($blockstring, " ".rtrim($str,";"));
64 strcat($full,str_replace(["::::", "\""],["::", ""],$blockstring)."\n"); // add the full line to our $full variable
66 /* rejig the blockstring */
67 $split = split($blockstring,"::");
68 if (BadPtr($split[sizeof($split) - 1]))
69 unset($split[sizeof($split) - 1]);
70 unset($split[sizeof($split) - 1]);
71 unset($split[sizeof($split) - 1]);
72 $blockstring = glue($split,"::");
73 if (!BadPtr($blockstring))
75 rtrim($blockstring,":");
76 strcat($blockstring,"::");
81 { if (!BadPtr($blockstring) && mb_substr($blockstring,-2,2) !== "::")
82 strcat($blockstring," ");
83 strcat($blockstring,$str);
87 $full = split($full,"\n");
88 echo highlight_string(var_export($full, true));
91 foreach($full as $config_item)
94 self
::$settings_short[] = $config_item;
95 $tok = split($config_item,"::");
96 for ($i = 0; $i <= count($tok); $i++
)
98 if (isset($tok[$i +
2]))
99 $arr = &$arr[$tok[$i]];
101 elseif (isset($tok[$i +
1]) && isset($tok[$i - 1]))
102 $arr[$tok[$i]] = $tok[$i +
1];
104 elseif (isset($tok[$i +
1]))
105 $arr[$tok[$i]][] = $tok[$i +
1];
108 self
::$settings_temp = $long;
109 $cf = &self
::$settings_temp;
113 self
::$settings_temp = [];
116 $arr = ['cfg' => $cf, 'err' => &$error];
121 self
::$settings_temp = [];
124 self
::$settings = self
::$settings_temp;
125 self
::$settings_temp = [];
127 echo highlight_string(var_export(self
::$settings, true));
131 $configFile = 'unrealircd.conf';
135 if (file_exists($configFile)) {
136 $lines = file($configFile, FILE_IGNORE_NEW_LINES
| FILE_SKIP_EMPTY_LINES
);
137 foreach ($lines as $line)
139 $config[] = trim($line);
142 echo highlight_string(var_export($config, true));
148 new Conf("unrealircd.conf", $errors);