public function parseLines(array $lines)
{
$config = new SiteConfig();
foreach ($lines 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', 'strip', 'strip_id_or_class', 'strip_image_src', 'single_page_link', 'next_page_link', 'test_url', 'find_string', 'replace_string', 'login_extra_fields'))) {
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', 'requires_login'))) {
$config->{$command} = $val == 'yes' || $val == 'true';
// check for single statement commands stored as strings
} elseif (in_array($command, array('parser', 'login_username_field', 'login_password_field', 'not_logged_in_xpath', 'login_uri'))) {
$config->{$command} = $val;
// check for replace_string(find): replace
} elseif (substr($command, -1) == ')' && preg_match('!^([a-z0-9_]+)\\((.*?)\\)$!i', $command, $match) && $match[1] == 'replace_string') {
array_push($config->find_string, $match[2]);
array_push($config->replace_string, $val);
} elseif (substr($command, -1) == ')' && preg_match('!^([a-z0-9_]+)\\(([a-z0-9_-]+)\\)$!i', $command, $match) && $match[1] == 'http_header' && in_array($match[2], array('user-agent', 'referer'))) {
$config->http_header[$match[2]] = $val;
}
}
return $config;
}