configDir = $inputConfigDir; $this->load($fileName); $this->setDefaults(); if ($this->suspend and $this->urlSuspend) { header("Location: $this->urlSuspend"); exit(); } } public function load($fileName) { $path = "$this->configDir/$fileName.txt"; if (!file_exists($path)) exit("This config file does not exist: $path"); $buffer = file_get_contents($path); if ($buffer === FALSE) exit("Failed to open config file $path"); // remove comments $buffer = preg_replace(self::$blockCommentMatch, '', $buffer); $buffer = preg_replace(self::$wholeLineCommentMatch, '', $buffer); $buffer = preg_replace(self::$lineCommentMatch, '', $buffer); // print "
$buffer
"; $this->parseLines($buffer, 0); } private function setDefaults() { // set any essential missing config options if (!isset($this->debug)) $this->debug = FALSE; if (!isset($this->charset)) $this->charset = SMART_DEFAULT_CHARSET; if (!isset($this->timezone)) $this->timezone = SMART_DEFAULT_TIMEZONE; if (!isset($this->xhtml)) $this->xhtml = SMART_DEFAULT_XHTML; if (!isset($this->loginCookieName)) $this->loginCookieName = SMART_DEFAULT_LOGIN_COOKIE; if (!isset($this->sendEmailAlerts)) $this->sendEmailAlerts = FALSE; //set_magic_quotes_runtime(FALSE); //error_reporting($this->debug ? E_ALL | E_STRICT : E_ERROR); error_reporting($this->debug ? E_ALL : E_ERROR); date_default_timezone_set($this->timezone); //putenv('TZ=Etc/UTC'); setlocale(LC_ALL, "$this->timezone.$this->charset"); mb_internal_encoding($this->charset); ini_set('auto_detect_line_endings', TRUE); if (isset($this->dirHome)) { if (!isset($this->dirData)) $this->dirData = "$this->dirHome/data"; if (!isset($this->dirTemplates)) $this->dirTemplates = "$this->dirHome/templates"; } if (isset($this->dirLogs)) { if (!isset($this->fileErrorLog)) $this->fileErrorLog = "$this->dirLogs/errors.txt"; if (!isset($this->fileErrorDigest)) $this->fileErrorLog = "$this->dirLogs/errors-digest.txt"; } if (isset($this->dirSessions)) session_save_path($this->dirSessions); } private function parseLines(&$input, $offset, $blockName = NULL, $mainOffset = 0) { while (true) { // is it a regular line? $rv = preg_match(self::$lineMatch, $input, $matches, 0, $offset); if ($rv === FALSE or ($rv and count($matches) != 3)) $this->abort('line', $mainOffset + $offset); if ($rv) { // print "
$matches[0]
\n"; // replace new-style $key placeholders $value = preg_replace('/\$(.+?)[$\w\/"]/', '$this->\1', $matches[2]); // replace {{...}} placeholders with config values $value = preg_replace('/\{\{(.+?)\}\}/', '$this->\1', $matches[2]); // replace '[[...]]' with '{{...}}' (used as a template placeholder) $value = preg_replace('/\[\[(.+?)\]\]/', '{{\1}}', $value); if ($blockName) { // print "
\$this->{$blockName}->{$matches[1]} = $value;
\n"; $code = "\$this->{$blockName}->{$matches[1]} = $value;"; if (eval($code) === FALSE) print "$code failed"; } else { // print "
\$this->{$matches[1]} = $value;
\n"; eval("\$this->{$matches[1]} = $value;"); } $offset += strlen($matches[0]); } else { // is it a block of settings? // $buffer = substr($input, $offset); $rv = preg_match(self::$blockMatch, $input, $matches, 0, $offset); if ($rv === FALSE or ($rv and count($matches) != 3)) $this->abort('block', $mainOffset + $offset); if (!$rv) { // are we at the end? if (trim(substr($input, $offset)) == '') return; else $this->abort('unrecognised', $mainOffset + $offset); } $tempBlockName = $matches[1]; if (!$tempBlockName) $this->abort('block name', $offset); $this->$tempBlockName = new stdClass(); $this->parseLines($matches[2], 0, $tempBlockName, $offset); $offset += strlen($matches[0]); } } } private function abort($error, $offset) { exit("Config error ($error) at offset $offset"); } } ?>