Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: 404-Deamon
- Plugin URI: http://not-going-to-come-anytime.com
- Description: Mails you a 404-Notification. This will even send you an email if you have got a missing favicon. It can be a little bit annoying, when you get mails for all crap of stuff. Feel free to extend the exclusions at the bottom. Currently it only excludes 404 if the admin lands on non-existand URLs or google and yahoo! visits you (props: toscho).
- Version: 0.1
- Author: Franz Josef Kaiser
- Author URI: http://unserkaiser.com
- License: GPL2
- */
- // Let's go with WP. The WP-Filter-Deamon will handle this for us (hopefully)
- add_filter('404_template', 'notify_404');
- function notify_404($deamon)
- {
- // for Wordpress only: Your WP-URL
- $page_uri = get_bloginfo('url');
- // if you, like me: LOOOOOVE Pods, then go and grap a copy over at http://podscms.com
- if (function_exists(pods_url_variable)) {
- $page_uri_last = pods_url_variable('last');
- }
- // or stick with a simple PHP-Function
- // if you don't use WP, then use the following lines
- /*
- * START WP-KILL HERE
- function full_non_wp_uri() {
- $page_uri = 'http';
- if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
- $page_uri .= "://";
- if ($_SERVER["SERVER_PORT"] != "80") {
- $page_uri .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
- } else {
- $page_uri .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
- }
- return $page_uri;
- }
- */
- // non-WP Users won't need to following lines too
- // set up the current User to get some data about him/her
- global $current_user;
- get_currentuserinfo();
- // Let's see, if it's registered User, or an unknown Guest
- if( is_user_logged_in() ) {
- $user_mail = "The User ";
- $user_mail .= $current_user->user_login;
- $user_mail .= " (Mail: ";
- $user_mail .= $current_user->user_email;
- $user_mail .= ") has ";
- } elseif( !is_user_logged_in() ) {
- $user_mail = "A guest has ";
- }
- /* END WP-KILL HERE */
- // get some additional data about our users and guest
- // don´t forget to delete the data if it´s no enemy
- // we want to save the privacy of our users and guests
- if(isset($_SERVER['HTTP_USER_AGENT']) {
- $guest_user_agent = addslashes($_SERVER['HTTP_USER_AGENT']);
- }
- if(isset($_SERVER['HTTP_REFERER']) {
- $guest_referer = addslashes($_SERVER['HTTP_REFERER']);
- }
- $guest_req_method = $_SERVER['REQUEST_METHOD'] . ' http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
- // the WP-way to give you some love
- $to = get_bloginfo('admin_email');
- $subject = "(ae) - 404";
- $message = "Dear Admin!\n\n";
- $message .= "Notification:\n";
- $message .= $user_mail;
- $message .= "tried to reach a page that´s not here (";
- $message .= $page_uri;
- // quick'n'dirrrrty @pods
- if (function_exists(pods_url_variable)) {
- $message .= "/";
- $message .= $page_uri_last;
- }
- $message .= ") aufzurufen.\n\n";
- $message .= "Users Agent:";
- $message .= $guest_user_agent;
- $message .= "\n";
- $message .= "Referer:";
- $message .= $guest_referer;
- $message .= "\n";
- $message .= "Request Method:";
- $message .= $guest_req_method;
- $message .= "\n";
- $message .= "IP: http://ip-lookup.net/?ip=";
- $message .= ;
- $message .= "\n\n";
- $message .= "Yours,\n";
- $message .= "friendly 404-Deamon from the neighborhood\n";
- $message .= "-----------\n";
- $message .= "That´s an automatic mail.\n";
- $message .= "Please don´t answer.\n";
- $message .= "I\'m too shy to reply.\n";
- $message .= "-----------";
- $headers = "From: from 404-Deamon with love <fehler_404@aerztejobs10.at>\r\n\\";
- $attachments = '';
- $content_type = "text/html";
- apply_filters( 'wp_mail_content_type', $content_type );
- if( $current_user->user_email == get_bloginfo('admin_email') ) {
- } elseif( ! ( FALSE !== strpos($_SERVER['REQUEST_URI'], 'noexist' ) or FALSE !== strpos($_SERVER['REQUEST_URI'], 'SlurpConfirm') ) ) {
- } else {
- wp_mail( $to, $subject, $message, $headers, $attachments );
- }
- // the PHP & toscho way to give you some love
- /*
- 'MIME-Version: 1.0' . "\r\n"
- . 'Content-Type: text/plain; charset=UTF-8' . "\r\n"
- . 'Content-Transfer-Encoding: 8bit' . "\r\n"
- . 'From: from 404-Deamon with love <mail@' . $_SERVER['HTTP_HOST'] . '>' . "\r\n"
- . 'List-Id: "404" 404.List' . "\r\n"
- );
- */
- // that's all folks
- return $deamon;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement