here. Version: 1.1 Author: Alex King Author URI: http://alexking.org */ // Copyright (c) 2006-2007 Alex King. All rights reserved. // http://alexking.org/projects/wordpress // // Released under the GPL license // http://www.opensource.org/licenses/gpl-license.php // // This is an add-on for WordPress // http://wordpress.org/ // // ********************************************************************** // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // ********************************************************************** @define('AK_WPROOT', '../../'); if (!isset($wpdb)) { require(AK_WPROOT.'wp-blog-header.php'); } load_plugin_textdomain('alexking.org'); $_SERVER['REQUEST_URI'] = ( isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['SCRIPT_NAME'] . (( isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''))); class ak_404 { var $url_404; var $url_refer; var $user_agent; var $mailto; var $mail_enabled; var $rss_limit; var $options; function ak_404() { if (isset($_SERVER['REQUEST_URI'])) { $this->url_404 = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; } else { $this->url_404 = ''; } if (isset($_SERVER['HTTP_REFERER'])) { $this->url_refer = $_SERVER['HTTP_REFERER']; } else { $this->url_refer = ''; } if (isset($_SERVER['HTTP_USER_AGENT'])) { $this->user_agent = $_SERVER['HTTP_USER_AGENT']; } else { $this->user_agent = ''; } $this->mailto = ''; $this->mail_enabled = 0; $this->rss_limit = 100; $this->options = array( 'mailto' => 'email' , 'mail_enabled' => 'int' , 'rss_limit' => 'int' ); } function install() { global $wpdb; $result = $wpdb->query(" CREATE TABLE `$wpdb->ak_404_log` ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `url_404` TEXT NOT NULL , `url_refer` TEXT NULL , `user_agent` TEXT NULL , `date_gmt` DATETIME NOT NULL ) "); add_option('ak404_mailto', $this->mailto, 'Address to send mail to.'); add_option('ak404_mail_enabled', $this->mail_enabled, 'Send mail notifications?'); add_option('ak404_rss_limit', $this->rss_limit, '# of items to show at once in RSS Feed'); } function update_settings() { foreach ($this->options as $option => $type) { if (isset($_POST[$option])) { switch ($type) { case 'email': $value = stripslashes($_POST[$option]); if (!ak_check_email_address($value)) { $value = ''; } break; case 'int': $value = intval($_POST[$option]); break; default: $value = stripslashes($_POST[$option]); } update_option('ak404_'.$option, $value); } else { update_option('ak404_'.$option, $this->$option); } } header('Location: '.get_bloginfo('wpurl').'/wp-admin/options-general.php?page=404-notifier.php&updated=true'); die(); } function get_settings() { foreach ($this->options as $option => $type) { $this->$option = get_option('ak404_'.$option); switch ($type) { case 'email': $this->$option = $this->$option; break; case 'int': $this->$option = intval($this->$option); break; } } } function log_404() { global $wpdb; if (empty($this->url_404)) { return; } $wpdb->query(" INSERT INTO $wpdb->ak_404_log ( url_404 , url_refer , user_agent , date_gmt ) VALUES ( '".mysql_real_escape_string($this->url_404)."' , '".mysql_real_escape_string($this->url_refer)."' , '".mysql_real_escape_string($this->user_agent)."' , '".current_time('mysql',1)."' ) "); $this->mail_404(); } function mail_404() { if (!empty($this->mailto) && $this->mail_enabled) { $to = $this->mailto; $subject = '404: '.$this->url_404; $message = '404 Report - a file not found error was registered on your site.'."\n\n" .'404 URL: '.$this->url_404."\n\n" .'Referred by: '.$this->url_refer."\n\n" .'User Agent: '.$this->user_agent."\n\n"; $headers = 'From: '.$this->mailto . "\r\n" .'Reply-To: '.$this->mailto . "\r\n" .'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } } function options_form() { switch ($this->mail_enabled) { case '1': $enabled = ' checked="checked"'; break; case '0': $enabled = ''; break; } print('
'.__('404 URL: ', 'alexking.org').''.$event->url_404.'
'.__('Referring URL: ', 'alexking.org').''.$event->url_refer.'
'.__('User Agent: ', 'alexking.org').$event->user_agent.'
'; ?>