200) || !preg_match(self::HOSTNAME_REGEX, $host)) return false; // check for site configuration $try = array($host); $split = explode('.', $host); if (count($split) > 1) { array_shift($split); $try[] = implode('.', $split); } foreach ($try as $h) { if (array_key_exists($h, self::$config_cache)) { self::debug("... cached ($h)"); return self::$config_cache[$h]; } elseif (file_exists(self::$config_path."/$h.txt")) { self::debug("... from file ($h)"); $file = self::$config_path."/$h.txt"; break; } } if (!isset($file)) { if (isset(self::$config_path_fallback)) { self::debug("... trying fallback ($host)"); foreach ($try as $h) { if (file_exists(self::$config_path_fallback."/$h.txt")) { self::debug("... from fallback file ($h)"); $file = self::$config_path_fallback."/$h.txt"; break; } } if (!isset($file)) { self::debug("... no match in fallback directory"); return false; } } else { self::debug("... no match ($host)"); return false; } } $config_file = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!$config_file || !is_array($config_file)) return false; $config = new SiteConfig(); foreach ($config_file as $line) { $line = trim($line); // skip comments, empty lines if ($line == '' || $line[0] == '#') continue; // get command $command = explode(':', $line, 2); // if there's no colon ':', skip this line if (count($command) != 2) continue; $val = trim($command[1]); $command = trim($command[0]); if ($command == '' || $val == '') continue; // check for commands where we accept multiple statements if (in_array($command, array('title', 'body', 'author', 'date', 'strip', 'strip_id_or_class', 'strip_image_src', 'single_page_link', 'single_page_link_in_feed', 'http_header'))) { array_push($config->$command, $val); // check for single statement commands that evaluate to true or false } elseif (in_array($command, array('tidy', 'prune', 'autodetect_on_failure'))) { $config->$command = ($val == 'yes'); // check for single statement commands stored as strings } elseif (in_array($command, array('test_url', 'parser'))) { $config->$command = $val; } elseif ((substr($command, -1) == ')') && preg_match('!^([a-z0-9_]+)\((.*?)\)$!i', $command, $match)) { if (in_array($match[1], array('replace_string'))) { $command = $match[1]; array_push($config->$command, array($match[2], $val)); } } } return $config; } } ?>