ontions = $options; } function exec(&$Doc) { if ($this->isBot()) { header('HTTP/1.0 301 Moved Permanently'); header('Location: '.BASE_URL); exit; } header('HTTP/1.0 404 Not Found'); $Doc->addContent(array('tpl' => SiteMap::getPath('NotFound/tpl/not_found_404.tpl'), 'alias' => CURR_PAGE_FULL)); $this->sendMail(); } function isBot() { if (empty($_SERVER['HTTP_USER_AGENT'])) { return false; } if (false !== ($bot_list = $this->getBotList())) { foreach ($bot_list as $bot_name) { if (false !== stripos($_SERVER['HTTP_USER_AGENT'], $bot_name)) { return true; } } } return false; } function getBotList() { $fileName = WWW_PATH.'/_sys/bot_list.txt'; if (file_exists($fileName) && is_file($fileName)) { $bot_list = file($fileName); foreach($bot_list as $k=>&$v) { $v = trim($v); } $bot_list = array_filter($bot_list, 'strlen'); if (!empty($bot_list)) { return $bot_list; } } return false; } function sendMail() { if (!constant('DEBUG_DEVELOPER_EMAIL_404')) { return false; } $emails = split('[, ;]', DEBUG_DEVELOPER_EMAIL_404); if (!is_array($emails) || empty($emails)) { return false; } $url = BASE_URL.'/'.CURR_PAGE_FULL; if (!empty($_SERVER['QUERY_STRING'])) { $url .= '?'.$_SERVER['QUERY_STRING']; } $text = 'URL: '.$url."\n\n"; $serverVariables = array('HTTP_REFERER', 'HTTP_USER_AGENT', 'X_REQUESTED_WITH', 'REMOTE_ADDR'); foreach ($serverVariables as $name) { if (!empty($_SERVER[$name])) { $text .= $name.': '.$_SERVER[$name]."\n\n"; } } //$text .= print_r($_SERVER, 1); $subject = '404 on mncar.org'; $headers = 'From: debug404@'.$_SERVER['SERVER_NAME'] . "\n" . 'X-Mailer: PHP/' . phpversion(); foreach ($emails as $email) { mail($email, $subject, $text, $headers); } } }