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 Notifier Options', 'alexking.org').'

'.__('RSS Feed of 404 Events', 'alexking.org').'

'); } function rss_feed() { global $wpdb; $events = $wpdb->get_results(" SELECT * FROM $wpdb->ak_404_log ORDER BY date_gmt DESC LIMIT $this->rss_limit "); header('Content-type: text/xml; charset=' . get_option('blog_charset'), true); echo ''; ?> <?php print(__('404 Report for: ', 'alexking.org')); bloginfo_rss('name'); ?> http://wordpress.org/?v= 0) { foreach ($events as $event) { $content = '

'.__('404 URL: ', 'alexking.org').''.$event->url_404.'

'.__('Referring URL: ', 'alexking.org').''.$event->url_refer.'

'.__('User Agent: ', 'alexking.org').$event->user_agent.'

'; ?> <![CDATA[<?php print('404: '.htmlspecialchars($event->url_404)); ?>]]> url_404); ?>]]> date_gmt, false); ?> id); ?> ]]> ]]>
ak_404_log = $table_prefix.'ak_404_log'; // CHECK FOR 404 NOTIFIER TABLES if (isset($_GET['activate']) && $_GET['activate'] == 'true') { $result = mysql_list_tables(DB_NAME); $tables = array(); while ($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } if (!in_array($wpdb->ak_404_log, $tables)) { $ak404->install(); } } $ak404->get_settings(); function ak404_log() { if (is_404()) { global $ak404; $ak404->log_404(); } } add_action('shutdown', 'ak404_log'); function ak404_options() { if (function_exists('add_options_page')) { add_options_page( __('404 Notifier Options', 'alexking.org') , __('404 Notifier', 'alexking.org') , 10 , basename(__FILE__) , 'ak404_options_form' ); } } add_action('admin_menu', 'ak404_options'); function ak404_options_form() { global $ak404; $ak404->options_form(); } function ak404_request_handler() { $ak404 = new ak_404; if (!empty($_POST['ak_action'])) { switch($_POST['ak_action']) { case 'update_404_settings': $ak404->update_settings(); break; } } if (!empty($_GET['ak_action'])) { switch($_GET['ak_action']) { case '404_feed': $ak404->rss_feed(); break; } } } add_action('init', 'ak404_request_handler'); ?>