ak_404_log)) { $wpdb->ak_404_log = $wpdb->prefix.'ak_404_log'; } $this->url_404 = isset($_SERVER['REQUEST_URI']) ? 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] : ''; $this->url_refer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $this->remote_addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $this->remote_host = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : ''; $this->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $this->mailto = ''; $this->mail_enabled = 0; $this->rss_limit = 100; $this->date = gmdate('Y-m-d H:i:s'); $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 , `remote_addr` VARCHAR(255) NULL , `remote_host` TEXT NULL , `user_agent` TEXT NULL , `date_gmt` DATETIME NOT NULL ) "); add_option('ak404_mailto', $this->mailto); add_option('ak404_mail_enabled', $this->mail_enabled); add_option('ak404_rss_limit', $this->rss_limit); } function upgrade() { global $wpdb; $col_data = $wpdb->get_results(" SHOW COLUMNS FROM $wpdb->ak_404_log "); $cols = array(); foreach ($col_data as $col) { $cols[] = $col->Field; } // 1.3 schema upgrade if (!in_array('remote_addr', $cols)) { $wpdb->query(" ALTER TABLE `$wpdb->ak_404_log` ADD `remote_addr` VARCHAR(255) DEFAULT NULL AFTER `url_refer` "); } if (!in_array('remote_host', $cols)) { $wpdb->query(" ALTER TABLE `$wpdb->ak_404_log` ADD `remote_host` VARCHAR(255) DEFAULT NULL AFTER `remote_addr` "); } } function update_settings() { if (!current_user_can('manage_options')) { return; } $options_arr = array(); 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]); } $options_arr['ak404_'.$option] .= $value; } else { $options_arr['ak404_'.$option] .= $this->options; } } update_option('ak404_options', serialize($options_arr)); $this->upgrade(); } function get_settings() { $settings = unserialize(get_option('ak404_options')); foreach ($this->options as $option => $type) { if (empty($settings)) { $this->$option = get_option('ak404_'.$option); } else { $this->$option = $settings['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; } $result = $wpdb->insert( $wpdb->ak_404_log, array( 'url_404' => $this->url_404, 'url_refer' => $this->url_refer, 'remote_addr' => $this->remote_addr, 'remote_host' => $this->remote_host, 'user_agent' => $this->user_agent, 'date_gmt' => $this->date ) ); if ($result === false) { return false; } $this->mail_404(); } function surpress_notification($regexs = array()) { $regexs = apply_filters('ak404_surpress_notification', $regexs); if (count($regexs)) { foreach ($regexes as $regex) { if (preg_match($regex, $this->url_404)) { return true; } } } return false; } function mail_404() { if (!empty($this->mailto) && $this->mail_enabled){//} && !$this->surpress_notification()) { $to = esc_html($this->mailto); $subject = __('404: ', '404-notifier').esc_html($this->url_404); $message = __('404 Report - a file not found error was registered on your site.', '404-notifier')."\n\n" .__('404 URL: ', '404-notifier').esc_html($this->url_404)."\n\n" .__('Referred by: ', '404-notifier').esc_html($this->url_refer)."\n\n" .__('Remote Address: ', '404-notifier').esc_html($this->remote_addr)."\n\n" .__('Remote Host: ', '404-notifier').esc_html($this->remote_host)."\n\n" .__('User Agent: ', '404-notifier').esc_html($this->user_agent)."\n\n" .__('Time: ', '404-notifier').esc_html(mysql2date('Y-m-d H:i:s', $this->date))."\n\n"; $headers = 'From: '.esc_html($this->mailto)."\r\n" .'Reply-To: '.esc_html($this->mailto)."\r\n" .'X-Mailer: PHP/'.phpversion(); wp_mail($to, $subject, $message, $headers); } } function dashboard_page() { global $wpdb; echo('
| '.__('404 URL', '404-notifier').' | '.__('Referring URL', '404-notifier').' | '.__('Remote Address', '404-notifier').' | '.__('Remote Host', '404-notifier').' | '.__('User Agent', '404-notifier').' | '.__('Date', '404-notifier').' |
|---|---|---|---|---|---|
| '.__('404 URL', '404-notifier').' | '.__('Referring URL', '404-notifier').' | '.__('Remote Address', '404-notifier').' | '.__('Remote Host', '404-notifier').' | '.__('User Agent', '404-notifier').' | '.__('Date', '404-notifier').' |
| '.esc_html($event->url_404).' | '.(isset($event->url_refer) && !empty($event->url_refer) ? ''.esc_html($event->url_refer).'' : ''.__('N/A', '404-notifier').'').' | '.(isset($event->remote_addr) && !empty($event->remote_addr) ? esc_html($event->remote_addr) : ''.__('N/A', '404-notifier').'').' | '.(isset($event->remote_host) && !empty($event->remote_host) ? esc_html($event->remote_host) : ''.__('N/A', '404-notifier').'').' | '.(isset($event->user_agent) && !empty($event->user_agent) ? esc_html($event->user_agent) : ''.__('N/A', '404-notifier').'').' | '.esc_html(mysql2date('D, d M Y H:i:s', $event->date_gmt, false)).' |
'.__('No logs to display…', '404-notifier').'
'; } echo ''.__('404 URL: ', '404-notifier').''.esc_url($event->url_404).'
'."\n".''.__('Referring URL: ', '404-notifier').''.esc_url($event->url_refer).'
'.__('User Agent: ', '404-notifier').esc_html($event->user_agent).'
'; ?>'.__('No logs to display…', '404-notifier').'
'; } } function ak404_add_dashboard_widgets() { wp_add_dashboard_widget('ak404_dashboard_widget', __('Recent 404 Logs', '404-notifier'), 'ak404_main_dashboard_widget'); } add_action('wp_dashboard_setup', 'ak404_add_dashboard_widgets'); //Multisite utility and integration functions function ak404_is_multisite() { return CF_Admin::is_multisite(); } function ak404_is_network_activation() { return CF_Admin::is_network_activation(); } function ak404_activate_for_network() { CF_Admin::activate_for_network('ak404_activate_single'); } function ak404_activate_plugin_for_new_blog($blog_id) { CF_Admin::activate_plugin_for_new_blog(N404_FILE, $blog_id, 'ak404_activate_single'); } add_action( 'wpmu_new_blog', 'ak404_new_blog'); function ak404_switch_blog() { global $wpdb; $wpdb->ak_404_log = $wpdb->prefix.'ak_404_log'; } add_action('switch_blog' , 'ak404_switch_blog'); ?>