Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Your friendly 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.2
- Author: F. J. Kaiser
- Author URI: http://unserkaiser.com
- License: GPL2
- // Copyright (c) 2009-2010 F. J. Kaiser. All rights reserved.
- // http://unserkaiser.com
- //
- // Note: Don't expect any support for this release.
- //
- // 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.
- // **********************************************************************
- */
- load_plugin_textdomain( '404-deamon', '/wp-content/plugins/404-deamon' );
- if( !class_exists('deamon_404') ):
- class deamon_404 {
- var $page_uri;
- var $look_up_ip;
- var $guest_user_agent;
- var $guest_referer;
- // this is not necessarily the end... go further and extend
- // var ;
- function deamon_404() {
- if (function_exists(pods_url_variable)) {
- // for Wordpress only: Your WP-URL
- $this->page_uri = get_bloginfo('url');
- // if you, like me: LOOOOOVE Pods, then go and grap a copy over at http://podscms.com
- $this->page_uri .= "/" . pods_url_variable('last');
- } elseif (!function_exists(pods_url_variable)) {
- // or stick with a simple PHP-Function
- // if you don't use WP, then use the following lines
- $this->page_uri = 'http';
- // Take https if is on
- if ($_SERVER["HTTPS"] == "on") {
- $this->page_uri .= "s";
- }
- $this->page_uri_php .= "://";
- if ($_SERVER["SERVER_PORT"] != "80") {
- $this->page_uri .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
- } else {
- $this->page_uri .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
- }
- }
- // 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
- (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $this->look_up_ip = $_SERVER['HTTP_X_FORWARDED_FOR'] : $this->look_up_ip = $_SERVER['REMOTE_ADDR'] );
- (isset($_SERVER['HTTP_USER_AGENT']) ? $this->guest_user_agent = addslashes($_SERVER['HTTP_USER_AGENT']) : '');
- (isset($_SERVER['HTTP_REFERER']) ? $this->guest_referer = addslashes($_SERVER['HTTP_REFERER']) : '');
- // another type or setting the requested uri
- //$guest_req_method = $_SERVER['REQUEST_METHOD'] . ' http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
- }
- } // End deamon_404 class def
- endif;
- // add it to the 404-Template
- add_filter('404_template', 'mail_404');
- // Here goes the function to construct and send the email:
- function mail_404($deamonmail) {
- $deamon = new deamon_404();
- $sitename = get_bloginfo('url');
- $domain = str_replace('http://', '', $sitename);
- // 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_or_guest = "The User ";
- $user_or_guest .= $current_user->user_login;
- $user_or_guest .= " (Mail: ";
- $user_or_guest .= $current_user->user_email;
- $user_or_guest .= ") has ";
- } elseif( !is_user_logged_in() ) {
- $user_or_guest = "A guest has ";
- }
- $to = get_bloginfo('admin_email');
- $subject = "Some love from your friendly 404-Deamon";
- $message = "Dear Admin!\n\n";
- $message .= "Notification:\n";
- $message .= $user_or_guest;
- $message .= "tried to reach a page that's not here (";
- $message .= $deamon->page_uri;
- $message .= ").\n\n";
- $message .= "Users Agent:";
- $message .= $deamon->guest_user_agent;
- $message .= "\n";
- $message .= "Referer:";
- $message .= $deamon->guest_referer;
- $message .= "\n";
- // $message .= "Request Method:";
- // $message .= $guest_req_method;
- // $message .= "\n";
- $message .= "IP: http://ip-lookup.net/?ip=";
- $message .= $deamon->look_up_ip;
- $message .= "\n\n";
- $message .= "Your 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 .= "-----------";
- $sitename = get_bloginfo('url');
- $domain = str_replace('http://', '', $sitename);
- $headers = "From: 404-Deamon: Missing <404_deamon@";
- $headers .= $domain;
- $headers .= ">\r\n";
- $attachments = '';
- /*
- * Start: This part isn't working at the moment.. don't know why
- * but not as long as i'm not looking for a sollution it will stay this way
- $content_type = "text/html";
- apply_filters( 'wp_mail_content_type', $content_type );
- * End: but it doesn't hurt anyway
- */
- return $deamonmail;
- }
- function test_data() {
- $deamon = new deamon_404();
- // set up the current User to get some data about him/her
- global $current_user;
- get_currentuserinfo();
- echo "<div class='container'>";
- echo "<div class='span-24 last'>";
- echo 'Page URL: ' . $deamon->page_uri . "<br />";
- echo 'Username: ' . $current_user->user_login . "<br />";
- echo 'User email: ' . $current_user->user_email . "<br />";
- echo 'User level: ' . $current_user->user_level . "<br />";
- echo 'User first name: ' . $current_user->user_firstname . "<br />";
- echo 'User last name: ' . $current_user->user_lastname . "<br />";
- echo 'User display name: ' . $current_user->display_name . "<br />";
- echo 'User ID: ' . $current_user->ID . "<br />";
- echo 'User IP-LookUp: ' . $deamon->look_up_ip . "<br />";
- echo 'User-Agent: ' . $deamon->guest_user_agent . "<br />";
- echo 'User Referer: ' . $deamon->guest_referer;
- echo "</div>";
- echo "</div>";
- }
- add_action('hook_above_title', 'test_data', 0) ; // TEST
- // that's all folks
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement