public static function parse() { if (!file_exists(self::$filename) && $check) { core::alog('ERROR: ' . self::$filename . ' cannot be found.', 'BASIC'); core::save_logs(); // force a log save } // check if it exists $lines = file(self::$filename); // open the file foreach ($lines as $num => $line) { $line = trim($line); if (substr($line, -1) == ';') { $line = substr($line, 0, -1); } $line = preg_replace('/\\s+/', ' ', $line); // clear the crap out of it. if (self::check_comment($line) == 'open') { self::$comment_opened = true; } if (self::check_comment($line) == 'close') { self::$comment_opened = false; } if (self::check_comment($line) == 'comment') { continue; } if ($line == '{' || self::$comment_opened) { continue; } // skip it if it's just { // or, a multiline comment is open if ($line == '}') { self::$sub_open = false; self::$opened = false; self::$opened_dir = ''; self::$opened_sub = ''; continue; } // stop parsing the data for that dir // once we've hit }; if (trim($lines[$num + 1]) == '{' || substr($line, -1) == '{') { $rvar = explode(' ', $line); $var = trim($rvar[0]); // grab the variable, eg. uplink, server. etc preg_match("/\"(.*)\"/", $line, $matches); $sub_var = isset($matches[1]) ? $matches[1] : ''; // format our data if (in_array($var, self::$multiple)) { if (count($matches) == 2) { self::$config[$var][$sub_var][$var] = trim($matches[1]); } elseif ($line != '{' && $line != '};') { self::$config[$var][$sub_var] = array(); } // does this directive allow multiple entries? self::$sub_open = true; self::$opened_sub = $sub_var; } else { if (count($matches) == 2) { self::$config[$var][$var] = trim($matches[1]); } elseif ($line != '{' && $line != '};') { self::$config[$var] = array(); } // if it doesn't allow multiple entries } self::$opened = true; self::$opened_dir = $var; // so, what we do here, we check if we have any "quoted info" // for instance uplink "server.name" { // if we do, we grab server.name. continue; } // so, we're dealing with a // "something {" scenario. if (self::$opened && $line != '{' && $line != '}') { $rvar = explode(' ', $line); $var = trim($rvar[0]); unset($rvar[0]); $value = isset($rvar[1]) ? implode(' ', $rvar) : ''; // here we create our var and value variables, fixing a bug // with spaces not working in values earlier :@ if (substr($var, -2) == '[]') { $var = substr($var, 0, -2); // strip the [] preg_match("/\"(.*)\"/", $value, $matches); if (count($matches) == 2) { if (self::$sub_open) { self::$config[self::$opened_dir][self::$opened_sub][$var][] = trim($matches[1]); } else { self::$config[self::$opened_dir][$var][] = trim($matches[1]); } } continue; } // are we dealing with an array, inside of {} // we only use the [] formats inside of {} // outside it, it's pointless as we can just use {} if ($value == '') { preg_match("/\"(.*)\"/", $var, $matches); if (count($matches) == 2) { if (self::$sub_open) { self::$config[self::$opened_dir][self::$opened_sub][] = trim($matches[1]); } else { self::$config[self::$opened_dir][] = trim($matches[1]); } } } else { preg_match("/\"(.*)\"/", $value, $matches); if (count($matches) == 2) { if (self::$sub_open) { self::$config[self::$opened_dir][self::$opened_sub][$var] = trim($matches[1]); } else { self::$config[self::$opened_dir][$var] = trim($matches[1]); } } } // is it a standalone value? eg "test"; or a defined value // eg variable "test"; ? continue; } // parse the data inside of { }; } // loooop }