$opts) { fwrite($fp, "[$section]\n"); foreach ($opts as $k => $v) { $v = addcslashes($v, "\"\r\n\t"); fwrite($fp, "$k = \"$v\"\n"); } fwrite($fp, "\n"); } flock($fp, LOCK_UN); $fp = null; } static function get($section, $option) { self::parseIni(); return self::_get($section, $option); } static function _get($section, $option) { $ini = self::$ini; if (isset(self::$ini[$section][$option])) { $val = self::$ini[$section][$option]; } else if (isset(self::$runtime[$section][$option])) { $val = self::$runtime[$section][$option]; } else { return null; } while (preg_match('/@\{([a-zA-Z0-9_]+):([a-zA-Z0-9_]+)\}/', $val, $M)) { $rep = self::_get($M[1], $M[2]); $val = str_replace($M[0], $rep, $val); } return $val; } static function getSection($section) { self::parseIni(); if (isset(self::$ini[$section])) { $S = self::$ini[$section]; } else { $S = null; } if (isset(self::$runtime[$section])) { $R = self::$runtime[$section]; } else { $R = null; } if ($S && $R) { return array_merge($S, $R); } if ($S) { return $S; } if ($R) { return $R; } return array(); } static function append($section, $option, $value) { if (self::$ini[$section][$option] != $value) { $location = self::getLocation(); $data = file_get_contents($location); $data .= "\n[$section]\n$option = $value\n"; file_put_contents($location, $data); self::$ini[$section][$option] = $value; } } /* loads plugins */ static function boot() { if (isset($_GLOBALS['MTRACK_CONFIG_SKIP_BOOT'])) { return; } $inc = self::get('core', 'includes'); if ($inc !== null) { foreach (preg_split("/\s*,\s*/", $inc) as $filename) { require_once $filename; } } $plugins = self::getSection('plugins'); if (is_array($plugins)) foreach ($plugins as $classpat => $paramline) { $params = preg_split("/\s*,\s*/", $paramline); $rcls = new ReflectionClass($classpat); $obj = $rcls->newInstanceArgs($params); } } static function checkInitializing() { if (file_exists(MTrackConfig::get('core', 'vardir') . '/.initializing')) { echo "System not set up yet"; exit(0); } } }