Advertisement
Guest User

kaiser / Wordpress 404-Mail-Notification

a guest
Feb 26th, 2010
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.26 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: 404-Deamon
  4. Plugin URI: http://not-going-to-come-anytime.com
  5. 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).
  6. Version: 0.1
  7. Author: Franz Josef Kaiser, Thomas Scholz a.k.a toscho
  8. Author URI: http://unserkaiser.com, http://toscho.de
  9. License: GPL2
  10. */
  11.  
  12.     // for Wordpress only: Your WP-URL
  13.     $page_uri = get_bloginfo('url');
  14.         // if you, like me: LOOOOOVE Pods, then go and grap a copy over at http://podscms.com
  15.         if (function_exists(pods_url_variable)) {
  16.             $page_uri_last = pods_url_variable('last');
  17.         }
  18.  
  19.     // or stick with a simple PHP-Function
  20.     // if you don't use WP, then use the following lines
  21.     function full_non_wp_uri() {
  22.         $page_uri_basic = 'http';
  23.         if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
  24.             $page_uri_basic .= "://";
  25.         if ($_SERVER["SERVER_PORT"] != "80") {
  26.             $page_uri_basic .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  27.         } else {
  28.             $page_uri_basic .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  29.         }
  30.         return $page_uri_basic;
  31.     }
  32.  
  33.     // non-WP Users won't need to following lines too
  34.     // set up the current User to get some data about him/her
  35.     global $current_user;
  36.     get_currentuserinfo();
  37.         // Let's see, if it's registered User, or an unknown Guest
  38.         if( is_user_logged_in() ) {
  39.             $user_mail = "The User ";
  40.             $user_mail .= $current_user->user_login;
  41.             $user_mail .= " (Mail: ";
  42.             $user_mail .= $current_user->user_email;
  43.             $user_mail .= ") has ";
  44.         } elseif( !is_user_logged_in() ) {
  45.             $user_mail = "A guest has ";
  46.         }
  47.     /* END WP-KILL HERE */
  48.  
  49.     // get some additional data about our users and guest
  50.     // don´t forget to delete the data if it´s no enemy
  51.     // we want to save the privacy of our users and guests
  52.     (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $look_up_ip = $_SERVER['HTTP_X_FORWARDED_FOR'] : $look_up_ip = $_SERVER['REMOTE_ADDR'] );
  53.     (isset($_SERVER['HTTP_USER_AGENT']) ? $guest_user_agent = addslashes($_SERVER['HTTP_USER_AGENT']) : '');
  54.     (isset($_SERVER['HTTP_REFERER']) ? $guest_referer = addslashes($_SERVER['HTTP_REFERER']) : '');
  55.     $guest_req_method = $_SERVER['REQUEST_METHOD'] . ' http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  56.  
  57.     // the WP-way to give you some love
  58.     $to = get_bloginfo('admin_email');
  59.     $subject = "(ae) - 404";
  60.     $message = "Dear Admin!\n\n";
  61.         $message .= "Notification:\n";
  62.         $message .= $user_mail;
  63.         $message .= "tried to reach a page that\'s not here (";
  64.         $message .= $page_uri;
  65.         // quick'n'dirrrrty @pods
  66.         if (function_exists(pods_url_variable)) {
  67.             $message .= $page_uri;
  68.             $message .= "/";
  69.             $message .= $page_uri_last;
  70.         } else {
  71.             $message .= $page_uri_basic;
  72.         }
  73.         $message .= ") aufzurufen.\n\n";
  74.         $message .= "Users Agent:";
  75.         $message .= $guest_user_agent;
  76.         $message .= "\n";
  77.         $message .= "Referer:";
  78.         $message .= $guest_referer;
  79.         $message .= "\n";
  80.         $message .= "Request Method:";
  81.         $message .= $guest_req_method;
  82.         $message .= "\n";
  83.         $message .= "IP: http://ip-lookup.net/?ip=";
  84.         $message .= $look_up_ip;
  85.         $message .= "\n\n";
  86.             $message .= "Yours friendly 404-Deamon from the neighborhood\n";
  87.             $message .= "-----------\n";
  88.             $message .= "That\'s an automatic mail.\n";
  89.             $message .= "Please don\'t answer.\n";
  90.             $message .= "I\'m too shy to reply.\n";
  91.             $message .= "-----------";
  92.  
  93.     $headers = "From: from 404-Deamon with love <fehler_404@aerztejobs10.at>\r\n\\";
  94.     $attachments = '';
  95.  
  96.     // Start: This part isn't working at the moment.. don't know why
  97.     $content_type = "text/html";
  98.     apply_filters( 'wp_mail_content_type', $content_type );
  99.     // End: but it doesn't hurt anyway
  100.  
  101.         if( $current_user->user_email == get_bloginfo('admin_email') ) {
  102.         } elseif( ! ( FALSE !== strpos($_SERVER['REQUEST_URI'], 'noexist' ) or FALSE !== strpos($_SERVER['REQUEST_URI'], 'SlurpConfirm') ) ) {
  103.         } else {
  104.             // Let's go with WP. The WP-Filter-Deamon will handle this for us (hopefully)
  105.             add_filter('404_template', 'notify_404');
  106.  
  107.             function notify_404($deamon)
  108.             {
  109.                 wp_mail( $to, $subject, $message, $headers, $attachments );
  110.             return $deamon;
  111.             }
  112.         }
  113.  
  114.     // the PHP & toscho way to give you some love
  115.     /*
  116.     'MIME-Version: 1.0' . "\r\n"
  117.         . 'Content-Type: text/plain; charset=UTF-8' . "\r\n"
  118.         . 'Content-Transfer-Encoding: 8bit' . "\r\n"
  119.         . 'From: from 404-Deamon with love <mail@' . $_SERVER['HTTP_HOST'] . '>' . "\r\n"
  120.         . 'List-Id: "404" 404.List' . "\r\n"
  121.     );
  122.     */
  123.  
  124. // that's all folks
  125. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement