. */ // don't load directly - exit if add_action or plugins_url functions do not exist if ( ! defined( 'ABSPATH' ) || ! function_exists( 'add_action' ) || ! function_exists( 'plugins_url' ) ) die( 'death by askapache firing squad' ); if ( ! class_exists( 'AA_G404' ) ) : /** * Defines whether ISCLOG class for custom logging exists * * This can not be defined elsewhere * * @since 5.0.1 * @var bool */ define( 'AA_G404_HAS_ISCLOG', (bool)( class_exists( 'ISCLOG' ) ) ); /** * Defines whether debugging is enabled or not. * * This can be defined in wp-config.php which overwrites it here. * * @since 5.0.1 * @var bool */ ! defined( 'AA_G404_DEBUG' ) && define( 'AA_G404_DEBUG', ( WP_DEBUG ) ); /** * Defines whether to debug start and stop of functions * * This can be defined in wp-config.php which overwrites it here. * * @since 5.0.1 * @var bool */ ! defined( 'AA_G404_DEBUG_FUNCTIONS' ) && define( 'AA_G404_DEBUG_FUNCTIONS', ( WP_DEBUG ) ); /** * Defines whether to debug * * This can not be defined elsewhere and requires ISCLOG and AA_G404_DEBUG_FUNCTIONS==true * * @since 5.0.1 * @var bool */ define( 'AA_G404D_F', (bool)( AA_G404_HAS_ISCLOG && AA_G404_DEBUG_FUNCTIONS ) ); /** * Defines whether to debug * * This can not be defined elsewhere and requires ISCLOG and AA_G404_DEBUG==true * * @since 5.0.1 * @var bool */ define( 'AA_G404D', (bool)( AA_G404_HAS_ISCLOG && AA_G404_DEBUG ) ); /** * AA_G404 * * @package WordPress * @author AskApache * @version 4.10 * @copyright Copyright (C) www.askapache.com * @access public * @link http://googlesystem.blogspot.com/2008/02/google-toolbar-and-404-error-pages.html */ class AA_G404 { // an array of options and values var $options = array(); // array to hold plugin information var $plugin = array(); // array to hold the css, javascript, and html var $code = array( 'css' => '', 'javascript' => '', 'html' => '' ); /** AA_DEBUG::__construct() * * @return void */ function __construct() { ( AA_G404D_F ) && ISCLOG::ti(); // define this in case it isn't ( php < 5.2.7 ) ! defined( '__DIR__' ) && define( '__DIR__', realpath( dirname( __FILE__ ) ) ); ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::init() * Loads the options into the class vars. * Adds this plugins 'load' function to the 'load-plugin' hook. * * @return void */ function init() { ( AA_G404D_F ) && ISCLOG::ti(); // load $this->plugin, $this->options $this->load_options(); if ( is_admin() ) { // add options page add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); // add load add_action( "load-{$this->plugin['hook']}", array( &$this, 'load' ) ); } else { // hook 404_template to show our 404 template, but only if enabled if ( ( '1' == $this->options['enabled'] ) ) { add_filter( '404_template', array( &$this, 'get_404_template' ), 2000, 1 ); } } ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::load() * The load function executed by the load-plugin hook. Passes control of request handling to the 'handle_post' function. * Adds the meta-boxes and the contextual help. * Enqueues the neccessary js and css files for plugin adminstration. * * @return void */ function load() { ( AA_G404D_F ) && ISCLOG::ti(); ( AA_G404D ) && ISCLOG::tw( ( is_404() ? 'is_404: TRUE' : ' is_404: FALSE' ) ); // load code $this->load_code(); // add contextual help add_action( "admin_head-{$this->plugin['hook']}", array( &$this, 'add_help' ) ); // enqueue css - wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) wp_enqueue_style( $this->plugin['pagenice'], plugins_url( 'f/admin.css', __FILE__ ), array( 'wp-jquery-ui-dialog', 'thickbox' ), $this->plugin['version'], 'all' ); // enqueue javascript - wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) wp_enqueue_script( $this->plugin['pagenice'], plugins_url( 'f/admin.js', __FILE__ ), array( 'jquery', 'jquery-ui-dialog', 'jquery-ui-tabs', 'jquery-ui-progressbar', 'postbox', 'thickbox' ), $this->plugin['version'], true ); // parse and handle post requests to plugin if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) $this->handle_post(); ( AA_G404D ) && ISCLOG::tw( ( is_404() ? 'is_404: TRUE' : ' is_404: FALSE' ) ); ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::get_404_template() * The main function that lets this plugin handle errors instead of WP's builtin error handling. * * @param string $template The template file * * @return string absolute path of php template */ function get_404_template($template) { ( AA_G404D_F ) && ISCLOG::ti(); ( AA_G404D ) && ISCLOG::tw( ( is_404() ? 'is_404: TRUE' : ' is_404: FALSE' ) ); // load code $this->load_code(); // construct handler class global $AA_G404_Handler; if ( ! is_object( $AA_G404_Handler ) ) { ( AA_G404D ) && ISCLOG::tw( 'AA_G404_Handler NOT AN OBJECT' ); $AA_G404_Handler = aa_g404_get_handler_object(); } // Now handle the incoming request with AA_G404_Handler::handle_it $AA_G404_Handler->handle_it(); // Loads the 404 error template specified by the 404_handler option if ( file_exists( $this->options['404_handler'] ) ) { ( AA_G404D ) && ISCLOG::tw( 'loading: ' . $this->options['404_handler'] ); ( AA_G404D_F ) && ISCLOG::ti(); return $this->options['404_handler']; } // return for the template_redirect ( AA_G404D ) && ISCLOG::tw( ( is_404() ? 'is_404: TRUE' : ' is_404: FALSE' ) ); ( AA_G404D_F ) && ISCLOG::ti(); return $template; } /** AA_G404::upgrade_settings() * currently code is not saved across upgrades due to a potential security issue * * @return void */ function upgrade_settings() { ( AA_G404D_F ) && ISCLOG::ti(); // upgrade plugin settings $this->plugin = $this->get_plugin_data( true ); // current code $code = get_option( 'askapache_google_404_code' ); // code base64_decoded $codeb64 = ( ( $code !== false && strlen( $code ) > 2 ) ? base64_decode( $code ) : '' ); // if 46 empty $codeb64_len = strlen( $codeb64 ); if ( substr( $codeb64, 0, 2 ) == 'a:' ) { ( AA_G404D ) && ISCLOG::tw('code looks to be uncompressed: ' . $codeb64); $code = base64_encode( gzdeflate( $codeb64, 1 ) ); if ( strlen( $code ) > 46 ) { ( AA_G404D ) && ISCLOG::tw('saving askapache_google_404_code: ' . $code); $this->code = $code; update_option( 'askapache_google_404_code', $code ); } } else { ( AA_G404D ) && ISCLOG::tw('code is compressed: ' . $codeb64_len ); $this->code = unserialize( gzinflate( $codeb64 ) ); } // first check $code is valid if ( $code === false || strlen( $code ) < 20 ) { ( AA_G404D ) && ISCLOG::epx( array( 'code === false', $code ) ); // set code to defaults $this->code = $this->get_default_code(); } elseif ( @unserialize( $codeb64 ) !== false ) { ( AA_G404D ) && ISCLOG::tw( 'IS OLD VERSION' ); $old_code = unserialize( $codeb64 ); $new_code_compressed = base64_encode( gzdeflate( serialize( $old_code ), 1 ) ); $new_code_uncompressed = unserialize( gzinflate( base64_decode( $new_code_compressed ) ) ); if ( $new_code_uncompressed === $old_code ) { ( AA_G404D ) && ISCLOG::tw( 'SWITCHING TO NEW VERSION' ); $this->code = $old_code; delete_option( 'askapache_google_404_code' ); add_option( 'askapache_google_404_code', $new_code_compressed, '', 'no' ); } else { ( AA_G404D ) && ISCLOG::tw( 'NOT SWITCHING TO NEW VERSION' ); } } else { ( AA_G404D ) && ISCLOG::tw( 'NEW VERSION ALREADY' ); $this->code = $code; } // default options $default_options = $this->get_default_options(); // current options $options = get_option( 'askapache_google_404_options' ); // first check $options is valid or set to defaults if ( $options === false || ! is_array( $options ) ) { ( AA_G404D ) && ISCLOG::epx( 'options === false or not array!' ); $options = $default_options; } else { // the default_options keys $default_options_keys = array_keys( $default_options ); sort( $default_options_keys ); // keys to current options $options_keys = array_keys( $options ); sort( $options_keys ); if ( $default_options_keys != $options_keys ) { ( AA_G404D ) && ISCLOG::epx( 'default_options_keys != options_keys' ); foreach ( $options as $k => $v ) { ( AA_G404D ) && ISCLOG::tw( "{$k} => {$v}" ); if ( array_key_exists( $k, $default_options ) ) { ( AA_G404D ) && ISCLOG::epx( "{$k} => {$v}" ); $default_options[ $k ] = $v; } } // no set the options to the newly updated default_options $options = $default_options; } } // get legacy adsense key and save to options if ( ! array_key_exists( 'adsense_key', $options ) || empty( $options['adsense_key'] ) ) { ( AA_G404D ) && ISCLOG::tw('searching for adsense_key'); $adsense_key = get_option( 'aa_google_404_adsense_key' ); // pub-4356884677303281 $options['adsense_key'] = ( $adsense_key !== false && strlen( $adsense_key ) > 3 ) ? $adsense_key : ''; } // get legacy analytics_key and save to options if ( ! array_key_exists( 'analytics_key', $options ) || empty( $options['analytics_key'] ) ) { ( AA_G404D ) && ISCLOG::tw('searching for analytics_key'); $analytics_key = get_option( 'aa_google_404_analytics_key' ); // UA-732153-7 $options['analytics_key'] = ( $analytics_key !== false && strlen( $analytics_key ) > 3 ) ? $analytics_key : ''; } // get legacy mobile_analytics_key and save to options if ( ! array_key_exists( 'mobile_analytics_key', $options ) || empty( $options['mobile_analytics_key'] ) ) { ( AA_G404D ) && ISCLOG::tw('searching for mobile_analytics_key'); $mana_key = get_option( 'aa_google_404_mobile_analytics_key' ); // MO-732153-7 $options['mobile_analytics_key'] = ( $mana_key !== false && strlen( $mana_key ) > 3 ) ? $mana_key : ''; } // update iframe_url in case of siteurl changed if ( strpos( $options['iframe_url'], '/f2?') !== false ) $options['iframe_url'] = WP_SITEURL . '/wordpress-google-AskApache/f3?askapache=htaccess-plugin&missing-5+this-post'; // update 404_handler in case of __DIR__ changed if ( strpos( $options['404_handler'], 'plugins/askapache-google-404/404.php' ) !== false ) $options['404_handler'] = __DIR__ . '/404.php'; // now set this->options to newly created options $this->options = $options; // ------------------------------------------------------------------------------------------------------ // delete these unused options delete_option( 'aa_google_404_api_key' ); delete_option( 'aa_google_404_adsense_key' ); delete_option( 'aa_google_404_analytics_key' ); // Save all these variables to database $this->save_options(); ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::load_code() * Loads this->code * * @return void */ function load_code() { ( AA_G404D_F ) && ISCLOG::ti(); // get code $code = get_option( 'askapache_google_404_code' ); // code decoded $code_decoded = ( $code !== false ) ? base64_decode( $code ) : ''; // if 46 empty $code_decoded_len = strlen( $code_decoded ); if ( $code_decoded_len == 46 ) { ( AA_G404D ) && ISCLOG::tw('code is empty! Getting and saving default code' ); // original code that comes with plugin $this->code = $this->get_default_code(); $this->save_options(); ( AA_G404D_F ) && ISCLOG::ti(); return; } // check if code is serialized already, indicating it is not using the newer compression if ( substr( $code_decoded, 0, 2 ) == 'a:' ) { ( AA_G404D ) && ISCLOG::tw('code looks to be uncompressed: ' . $code_decoded); $code = base64_encode( gzdeflate( $code_decoded, 1 ) ); if ( strlen( $code ) > 4 ) { $this->code = $code; update_option( 'askapache_google_404_code', $code ); } } else { ( AA_G404D ) && ISCLOG::tw('code is compressed: ' . $code_decoded_len ); $this->code = unserialize( gzinflate( $code_decoded ) ); ( AA_G404D ) && ISCLOG::epx( $this->code ); } ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::load_options() * Loads options named by opts array into correspondingly named class vars * * @return void */ function load_options() { ( AA_G404D_F ) && ISCLOG::ti(); // get options $this->options = get_option( 'askapache_google_404_options' ); // first try get_option, then parse this __FILE__ $this->plugin = $this->get_plugin_data(); ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::save_options() * Saves options from class vars passed in by opts array and the adsense key and api key * * @return void */ function save_options() { ( AA_G404D_F ) && ISCLOG::ti(); // save options update_option( 'askapache_google_404_options', $this->options ); // save plugin update_option( 'askapache_google_404_plugin', $this->plugin ); // save code if ( ! empty( $this->code ) && is_array( $this->code) && array_key_exists( 'css', $this->code ) ) { //$code = base64_encode( serialize( $this->code ) ); $code = base64_encode( gzdeflate( serialize( $this->code ), 1 ) ); if ( strlen( $code ) > 46 ) { ( AA_G404D ) && ISCLOG::tw( "saving askapache_google_404_code as: {$code}" ); update_option( 'askapache_google_404_code', $code ); } else { ( AA_G404D ) && ISCLOG::tw( "NOT saving askapache_google_404_code as: {$code}" ); } } else { ( AA_G404D ) && ISCLOG::tw( "this->code is empty! not saving" ); } ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::handle_post() * this plugin has to protect the code as it is displayed live on error pages, a prime target for malicious crackers and spammers * can someone help me add the proper code to make sure everything is escaped correctly? * * @return void */ function handle_post() { ( AA_G404D_F ) && ISCLOG::ti(); // if current user does not have manage_options rights, then DIE if ( ! current_user_can( 'manage_options' ) ) wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) ); // verify nonce, if not verified, then DIE if ( isset( $_POST[ "_{$this->plugin['nonce']}" ] ) ) { wp_verify_nonce( $_POST[ "_{$this->plugin['nonce']}" ], $this->plugin['nonce'] ) || wp_die( __( 'ERROR: Incorrect Form Submission, please try again.' ) ); } elseif ( isset($_POST['ag4_action_reset'] ) ) { wp_verify_nonce($_POST['ag4_action_reset'], 'ag4_action_reset_nonce' ) || wp_die( __( 'ERROR: Incorrect Form Submission, please try again.' ) ); } // resets options to default values if ( isset( $_POST['ag4_action_reset'] ) ) { $this->reset_options(); return; } // load up the current options from the database $this->load_options(); // setup proper mobile_analytics_key if ( isset( $_POST['ag4_analytics_key'], $_POST['ag4_mobile_analytics_key'] ) && strlen( $_POST['ag4_mobile_analytics_key'] ) < 4 && strpos( $_POST['ag4_analytics_key'], 'UA-' ) !== false ) $this->options['mobile_analytics_key'] = str_replace( 'UA-', 'MO-', $_POST['ag4_analytics_key'] ); // process absolute integer options foreach ( array( 'related_num', 'related_length', 'recent_num', 'tag_cloud_num' ) as $k ) { $this->options[ $k ] = ( ( isset( $_POST[ "ag4_{$k}" ] ) ) ? absint( $_POST[ "ag4_{$k}" ] ) : absint( $this->options[ $k ] ) ); } // process options of type string foreach ( array( 'api_key', 'adsense_key', 'analytics_key', 'mobile_analytics_key', 'robots_tag', '404_handler', 'iframe_url' ) as $k ) { $this->options[ $k ] = ( ( isset( $_POST[ "ag4_{$k}" ] ) && ! empty( $_POST[ "ag4_{$k}" ] ) ) ? $_POST[ "ag4_{$k}" ] : $this->options[ $k ] ); } // process on ('1' ) or off ('0' ) options $on_off_options = array( 'enabled', 'iframe_preview', 'robots_meta', 'google_404', 'related_posts', 'recent_posts', 'google_ajax', 'tag_cloud', 'analytics_log', 'mobile_analytics_log', 'show_result_site', 'show_result_video', 'show_result_blogs', 'show_result_cse', 'show_result_image', 'show_result_news', 'show_result_web', 'show_result_local' ); foreach ( $on_off_options as $k ) $this->options[ $k ] = ( ( ! isset( $_POST[ "ag4_{$k}" ] ) ) ? '0' : '1' ); // TODO: Nothing :) foreach ( array( 'analytics_url' ) as $k ) { if ( isset( $_POST[ "ag4_{$k}" ] ) ) { $this->options[ $k ] = stripslashes( $_POST[ "ag4_{$k}" ] ); } } // process incoming unfiltered code foreach ( array( 'css', 'html', 'javascript' ) as $k ) { if ( isset( $_POST[ "ag4_{$k}" ] ) && strlen( $_POST[ "ag4_{$k}" ] ) > 10 ) { $this->code[ $k ] = stripslashes( $_POST[ "ag4_{$k}" ] ); } } // Save code and options arrays to database $this->save_options(); ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::reset_options() * Gets and sets the default values for the plugin options, then saves them * * @return void */ function reset_options() { ( AA_G404D_F ) && ISCLOG::ti(); // get all the plugin array data $this->plugin = $this->get_plugin_data( true ); // original code that comes with plugin $this->code = $this->get_default_code(); // get default options $this->options = $this->get_default_options(); // Save all these variables to database $this->save_options(); ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::get_default_options() * Gets the default $this->options * * @return array Array of options */ function get_default_options() { ( AA_G404D_F ) && ISCLOG::ti(); // default options $options = array( 'api_key' => 'ABQIAAAAGpnYzhlFfhxcnc02U1NT1hSrXMCP0pDj9HHVk8NG53Pp2_-7KxSdZ5paIt0ciL3cNLv20-kmmxlTcA', 'adsense_key' => '', // pub-4356884677303281 'analytics_key' => '', // UA-732153-7 'mobile_analytics_key' => '', // MO-732153-7 'analytics_url' => '"/404/?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer', 'enabled' => '1', // 404 error handling is ON by default 'google_ajax' => '1', // google ajax search results are ON by default 'google_404' => '0', // googles new 404 script is OFF by default 'analytics_log' => '1', // 'mobile_analytics_log' => '0', 'robots_meta' => '1', // adding noindex,follow robot meta tag to error pages is ON by default 'robots_tag' => 'noindex,follow', // the value of the robot meta on error pages 'related_posts' => '1', // showing related posts on error pages is ON by default 'related_num' => 20, // number of related posts to show 'related_length'=> 240, // length of related posts excerpts 'recent_posts' => '1', // showing recent posts on error pages is ON by default 'recent_num' => 6, // number of recent posts to show 'tag_cloud' => '1', // showing a tag cloud on error pages is ON by default 'tag_cloud_num' => 100, // number tags used to create cloud 'show_result_site' => '1', 'show_result_video' => '1', 'show_result_blogs' => '1', 'show_result_cse' => '1', 'show_result_image' => '1', 'show_result_news' => '1', 'show_result_web' => '1', 'show_result_local' => '1', '404_handler' => __DIR__ . '/404.php', // the file location of 404 template 'iframe_preview'=> '0', // iframe preview in admin area is OFF by default 'iframe_url' => WP_SITEURL . '/wordpress-google-AskApache/f2?askapache=htaccess-plugin&missing-5+this-post' // the url for the iframe preview ); ( AA_G404D_F ) && ISCLOG::ti(); return $options; } /** AA_G404::get_default_code() * Gets the default code for css, html, and javascript by reading the original file in this plugins folder/f/orig.(css|js|html) * * @return array original_code with 3 keys */ function get_default_code() { ( AA_G404D_F ) && ISCLOG::ti(); $original_code = array( 'css' => '', 'html' => '', 'javascript' => '' ); // default css code $original_code['css'] = $this->read_file( __DIR__ . '/f/o/orig.css' ); // default javascript code $original_code['javascript'] = $this->read_file( __DIR__ . '/f/o/orig.js' ); // default html code $original_code['html'] = $this->read_file( __DIR__ . '/f/o/orig.html' ); /* $oc = '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'; $original_code = unserialize( gzinflate( base64_decode( $oc ) ) ); */ ( AA_G404D_F ) && ISCLOG::ti(); return $original_code; } /** AA_G404::admin_menu() * * @return void */ function admin_menu() { ( AA_G404D_F ) && ISCLOG::ti(); // add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { add_options_page( $this->plugin['plugin-name'], $this->plugin['short-name'], 'manage_options', $this->plugin['page'], array( &$this, 'options_page' ) ); ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::options_page() * * @return void */ function options_page() { ( AA_G404D_F ) && ISCLOG::ti(); if ( ! current_user_can( 'manage_options' ) ) wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) ); echo '
'; if ( function_exists( 'screen_icon' ) ) screen_icon(); echo '

' . $this->plugin['plugin-name'] . '

'; echo '
'; // print form nonce echo '

'; echo '

'; echo '

Preview

'; // if iframe_preview is enabled, show the preview if ( $this->options['iframe_preview'] == '1' ) echo '
'; $section_names = array( 'general' => 'General', 'output' => '404 Output Options', 'ajax' => 'Google Search Options', 'tracking' => 'Tracking/Logging', 'css' => 'CSS Editor', 'js' => 'JS Editor', 'html' => 'HTML Editor' ); echo '
'; ?>
    $section_name) printf('
  • %s
  • ', esc_attr( $section_id ), $section_name ); ?>

General

'; echo ''; echo '
Enable/Disable Plugin
Enable/Disable handling errors'; echo '
'; echo '
'; echo '
404.php Template File'; echo '
404.php Template File'; $error_templates = array( __DIR__ . '/404.php', get_404_template(), TEMPLATEPATH . '/404.php', dirname( TEMPLATEPATH ) . '/default/404.php', 'Custom File Location' ); $error_templates = array_unique( $error_templates ); foreach ( $error_templates as $v => $k ) { if ( $k=='Custom File Location' ) { echo '
'; } elseif ( file_exists( $k ) ) { echo '
'; } } echo '
'; echo '

To use your own custom 404.php file in your template directory:
Add if ( function_exists("aa_google_404"))aa_google_404(); between get_header and get_footer and save as 404.php in your template folder. (based off your current index.php perhaps)
Also: try adding an ob_start(); as the first command in the file, before get_header();, and add an exit; as the last command before the closing ?>
- See the included 404.php file for a simple working example.

'; $this->form_field( 1, 'Show Google AJAX Search', 'google_ajax', 'Displays Google AJAX Search Results' ); /*$this->form_field( 2, 'Google API Key Get One', 'api_key', 'This identifies your blog to Google.' ); echo '

You need a Google API Key for this site to display the ajax results. Go ahead and add your AdSense ID as future versions of this plugin will allow you to incorporate AdSense setups compliant with Google Guidelines.

'; */ /* $this->form_field( 2, 'Your Google AdSense Publisher ID Get One', 'adsense_key', 'This tells Google who to pay.' ); echo '

COMING TO THIS PLUGIN ON NEXT UPDATE:
Use Google AdSense to generate revenue, using several policy-conforming and user-friendly ways allowed by Google. For the AskApache Google 404\'s next upgrade I will be adding alot of adsense/analytics features, one will be geared so users that are running this plugin on a new blog with no content can automatically generate revenue through AdSense for domains. And of course the biggest thing I\'m adding is AdSense incorporated into the search. Both static non-google search results through AdSense for Search Ads Only, and also using the newest AdSense for Ajax. Both are basically Google BETA at the moment.

'; */ $this->form_field( 1, 'Add robots meta to prevent indexing', 'robots_meta', 'Prevent 404 pages from being indexed.' ); $this->form_field( 2, 'Robots meta tag value (?)', 'robots_tag', 'Value of robots meta tag.' ); echo '

This prevents your error pages from being indexed by Google and other search engines, which saves your PageRank for your non-error pages. Highly recommended, Google recommended.

'; $this->form_field( 1, 'Display a preview of your 404 page (below)', 'iframe_preview', 'Display a preview of your 404 page.' ); $this->form_field( 2, 'URL of Preview', 'iframe_url', 'Url (bad) of the preview iframe.' ); echo '
'; echo '

Google Search Results

'; $this->form_field( 1, 'Show Site Results', 'show_result_site', 'Display Site Results' ); $this->form_field( 1, 'Show Video Results', 'show_result_video', 'Display Video Results' ); $this->form_field( 1, 'Show Image Results', 'show_result_image', 'Display Image Results' ); $this->form_field( 1, 'Show Blogs Results', 'show_result_blogs', 'Display Blogs Results' ); $this->form_field( 1, 'Show Web Results', 'show_result_web', 'Display Web Results' ); $this->form_field( 1, 'Show News Results', 'show_result_news', 'Display News Results' ); $this->form_field( 1, 'Show CSE Results', 'show_result_cse', 'Display CSE Results' ); $this->form_field( 1, 'Show Local Results', 'show_result_local', 'Display Local Results' ); echo '
'; echo '

404 Output Options

'; $this->form_field( 1, 'Show Google 404 Helper', 'google_404', 'Displays Google New 404 Helper' ); echo '

Use Google Webmaster Tools 404 widget on the error page to automatically provide users with helpful suggestions instead of error messages.

'; $this->form_field( 1, 'Show Recent Posts', 'recent_posts', 'Displays List of Recent Posts' ); $this->form_field( 3, 'Recent Posts # to Show', 'recent_num', 'How many recent posts to show..' ); echo '

Shows a list of Recent Posts on your blog.

'; $this->form_field( 1, 'Show Related Posts', 'related_posts', 'Displays List of Posts similar to the query' ); $this->form_field( 3, 'Related Posts # to Show', 'related_num', 'How many related posts to show..' ); $this->form_field( 3, 'Related Posts Excerpt Length', 'related_length', 'How many related posts to show..' ); echo '

Shows a list of single posts on your blog that are related to the keywords auto-parsed from the bad url.

'; $this->form_field( 1, 'Show Popular Tag Cloud', 'tag_cloud', 'Displays Popular Tag Cloud' ); $this->form_field( 3, 'Tag # to Use', 'tag_cloud_num', 'How many tags to use, otherwise ALL tags..' ); echo '

Displays a tag cloud (heatmap) from provided data. of your popular tags where each tag is displayed with a font-size showing how popular the tag is, more popular tags are larger.

'; echo '
'; echo '

404 Tracking/Logging

'; echo '

Use Google Analytics to Track/Log Errors.

'; $this->form_field( 1, 'Track Errors with Google Analytics', 'analytics_log', 'Use Google Analytics to Track/Log Errors' ); $this->form_field( 2, 'Google Analytics Key UA-733153-7Get One', 'analytics_key', 'The tracking ID for this site.' ); echo '

This is clever as instead of using your server and database to store 404s, which results in crazy additional server-load, this method uses javascript so google machines will do all the work. "/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer

'; $this->form_field( '2j', 'Tracking URL for reports Get One', 'analytics_url', 'Lets you view errors in analytics!' ); $this->form_field( 1, 'Track activity for mobile browsers with Google Analytics', 'mobile_analytics_log', 'Use Google Analytics for Mobile Websites' ); $this->form_field( 2, 'Google Mobile Analytics Key MO-733153-7Get One', 'mobile_analytics_key', 'The tracking ID for this site.' ); echo '
'; echo '

HTML Editor

'; $this->form_field( 5, '', 'html','This controls the output of the plugin. Move stuff around, change what you want, and load the default if you mess up too much.' ); echo '

This lets you determine the placement and any extra html you want output by this plugin.

%error_title% - replaced with the status code and error phrase - 404 Not Found
%related_posts% - replaced with your related posts html if enabled
%tag_cloud% - replaced with your tag cloud if enabled
%recent_posts% - replaced with the recent posts html if enabled
%google_helper% - replaced with the Google Fixurl Help box.

'; echo '
'; echo '

CSS Editor

'; $this->form_field( 5, '', 'css','The css that controls the google ajax search results.. (and anything else on the page)' ); echo '

Modify the css that is output (inline) on your 404 error pages. Changes the appearance of, well, everything.

'; echo '
'; echo '

Javascript Editor

'; $this->form_field( 5, '', 'javascript','The javascript that runs the google ajax search.. (and anything else on the page)' ); echo '

For advanced users only. Future versions will provide much more control over this without having to code.

'; echo '
'; echo '
'; echo '





    '; echo '

'; echo '
'; // just a temp solution.. will be cleaned for next release echo ""; echo "

Save



"; echo '

'; echo "RESET TO DEFAULTS      "; echo "ADVANCED"; echo '


'; echo '


Articles from AskApache

'; echo '
'; echo '

More Info from Google


'; echo ''; ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::add_help() * * @return void */ function add_help() { ( AA_G404D_F ) && ISCLOG::ti(); $current_screen = get_current_screen(); $help = '

Fixing Status Headers

'; $help .= '

For super-advanced users, or those with access and knowledge of Apache .htaccess/httpd.conf files'; $help .=' you should check that your error pages are correctly returning a 404 Not Found'; $help .=' HTTP Header and not a 200 OK Header which appears to be the default for many WP installs, this plugin attempts to fix this using PHP, but the best way I have found'; $help .=' is to add the following to your .htaccess file.

'; $help .= '
ErrorDocument 404 /index.php?error=404'."\n".'Redirect 404 /index.php?error=404
'; $help .= '

You can check your headers by requesting a bad url on your site using my online tool Advanced HTTP Headers.

'; $help .= '

Future Awesomeness

'; $help .= '

The goal of this plugin is to boost your sites SEO by telling search engines to ignore your error pages, with the focus on human users to increase people staying on your site and being'; $help .= ' able to find what they were originally looking for on your site. Because I am obsessed with fast web pages, many various speed/efficiency improvements are also on the horizon.

'; $help .= '

Another feature that I am using with beta versions of this plugin, is tracking information for you to go over at your leisure, to fix recurring problems. The information is collected'; $help .= ' is the requested url that wasnt found, the referring url that contains the invalid link.

'; $help .= '

The reason I didnt include it in this release is because for sites like AskApache with a very high volume of traffic (and thus 404 requests) this feature can create a bottleneck and '; $help .= 'slow down or freeze a blog if thousands of 404 errors are being requested and saved to the database. This could also very quickly be used by malicious entities as a Denial of Service '; $help .= 'attack. So I am figuring out and putting into place limits.. like once a specific requested url resulting in a not found error has been requested 100x in a day, an email is sent to the '; $help .= 'blog administrator. But to prevent Email DoS and similar problems with the number and interval of emails allowed by your email provider other considerations on limits need to be examined.

'; $help .= '
FAST! CACHE! SPEED!
'; $help .= '

Future versions of this plugin will add this option for everyone.. Basically, there will be an option to switch to using a 100% javascript (instead of javascript + php) method of '; $help .= 'handling 404 errors, this will be BIG because the plugin will simply create 1 static html file named 404.html and then use .htaccess ErrorDocument to redirect all 404 errors to this '; $help .= 'static html file. The downside is the only way to get stuff like related posts and recent posts would be to use ajax or to create the 404.html static file at regular intervals or for '; $help .= 'multiple error requests. This will help tremendously in keeping your site and server speedy as it will reduce CPU/Memory/Disk IO/and Database Queries to almost nothing. Stay tuned.

'; $help .= '

One other big improvement or feature-add is to show the admin a list of error urls and allow the admin to specify the correct url that the error url should point to. Then using mod_rewrite '; $help .= 'rules automatically generated by the plugin and added to .htaccess these error urls will 301 redirect to the correct urls, boosting your SEO further and also helping your visitors. A '; $help .= 'big difference between this method and other redirection plugins is that it will use mod_rewrite, I would really like to avoid using php to redirect or rewrite to other urls, as this method'; $help .= ' has a HUGE downside in terms of your site and servers speed, bandwidth usage, CPU/Memory usage, Disk Input/Output (writes/reads), security issues, Database Usage, among other problems.

'; $help .= '
Generating Revenue
'; $help .= '

Anyone smart enough to find and use this plugin deserves to earn a little income too, so I am working on integrating AdSense into the Search Results. Currently this is very new and not '; $help .= 'enabled or allowed by Google in certain circumstances and just isnt a feature yet of the Google AJAX API. At the very least I am going to add a custom search engine results for your site '; $help .= 'that will allow you to display relevant ads, but I am still waiting for some clarification from my Google Homeslices on whether we can use the AJAX API to display ADS on 404 error pages '; $help .= 'automatically based on the requested url or if that violates the Google TOS, which is something I would never condone or even get close to violating. If not then we will have to settle '; $help .= 'for no ADS being displayed automatically and only being displayed if the user actually types something in the search box. So go get your AdSense account (free) and also sign up for a '; $help .= 'Google CSE (custom search engine) as soon as possible.

'; $help .= '
Comments/Questions

Please visit AskApache.com or send me an email at webmaster@askapache.com

'; add_contextual_help( $current_screen, $help ); ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404::form_field($w = 1, $title = '', $id = '', $desc = '' ) * Clean way to add html for form fields * * @return void */ function form_field($w = 1, $title = '', $id = '', $desc = '' ) { echo '
'; switch ($w) : case 1: echo "

options[$id],false)." />"; echo "

"; break; case 2: echo "


"; echo "

"; break; case '2j': echo "


"; echo "

"; break; case '2h': echo "


"; echo "

"; break; case 3: echo "


"; break; case 5: echo "

{$title}
"; echo "
"; break; endswitch; echo '
'; } /** AA_G404::get_plugin_data($force=false,$type='settings') * * 'plugin-name' => 'AskApache Google 404', * 'short-name' => ' AA Google 404', * 'description' => 'Displays unbeatable information to site visitors arriving at a non-existant page (from a bad link). Major SEO with Google AJAX, Google 404 Helper, Related Posts, Recent Posts, etc..', * 'author' => 'askapache', * 'contributors' => 'askapache', * 'version' => '4.10', * 'updated' => '9/12/2014', * 'requires-at-least' => '2.7', * 'tested-up-to' => '4.0', * 'tags' => 'google, 404, lost, oops, errordocument, htaccess, error, notfound, ajax, search, seo, mistyped, urls, news, videos, images, blogs, optimized, askapache, post, admin, askapache, ajax, missing, admin, template, traffic', * 'wordpress-uri' => 'http://wordpress.org/extend/plugins/askapache-google-404/', * 'author-uri' => 'http://www.askapache.com/', * 'donate-uri' => 'http://www.askapache.com/donate/', * 'plugin-uri' => 'http://www.askapache.com/seo/404-google-wordpress-plugin.html', * 'file' => '/plugins/askapache-google-404/askapache-google-404.php', * 'title' => 'AskApache Google 404', * 'page' => 'askapache-google-404.php', * 'pagenice' => 'askapache-google-404', * 'nonce' => 'form_askapache-google-404', * 'hook' => 'settings_page_askapache-google-404', * 'action' => 'options-general.php?page=askapache-google-404.php' * * @return array Plugin data */ function get_plugin_data($force=false,$type='settings') { ( AA_G404D_F ) && ISCLOG::ti(); ( AA_G404D ) && ISCLOG::tw( ( $force ? 'force: TRUE' : 'force: FALSE' ) ); $plugin = get_option( 'askapache_google_404_plugin' ); if ( $force === true || $plugin === false || ! is_array( $plugin ) || ! array_key_exists( 'file', $plugin ) || "{$plugin['file']}" != __FILE__ ) { clearstatcache(); $data = $this->read_file( __FILE__, 1450 ); $mtx = $plugin = array(); preg_match_all( '/[^a-z0-9]+((?:[a-z0-9]{2,25})(?:\ ?[a-z0-9]{2,25})?(?:\ ?[a-z0-9]{2,25})?)\:[\s\t]*(.+)/i', $data, $mtx, PREG_SET_ORDER ); $valids = array ( 'plugin-name', 'short-name', //'description', 'author', //'contributors', 'version', //'updated', //'requires-at-least', //'tested-up-to', //'tags', 'wordpress-uri', 'author-uri', //'donate-uri', 'plugin-uri', 'file', 'title', 'page', 'pagenice', 'nonce', 'hook', 'action' ); foreach ( $mtx as $m ) { $mm = trim( str_replace( ' ', '-', strtolower( $m[1] ) ) ); if ( in_array( $mm, $valids ) ) { $plugin[ $mm ] = str_replace( array( "\r", "\n", "\t" ), '', trim( $m[2] ) ); } } $plugin['file'] = __FILE__; $plugin['title'] = '' . esc_attr( $plugin['plugin-name'] ) . ''; $plugin['author'] = '' . esc_attr( $plugin['author'] ) . ''; $plugin['page'] = basename( __FILE__ ); $plugin['pagenice'] = rtrim( $plugin['page'], '.php' ); $plugin['nonce'] = 'form_' . $plugin['pagenice']; $plugin['hook'] = $type . '_page_' . $plugin['pagenice']; $plugin['action'] = ( ( $type == 'settings' ) ? 'options-general' : $type ) . '.php?page=' . $plugin['page']; } if ( array_key_exists( 'short-name', $plugin ) && strpos( $plugin['short-name'], '<' . 'img' ) === false ) { $plugin['short-name'] = ' ' . $plugin['short-name']; } ( AA_G404D ) && ISCLOG::tw( ( $force ? 'force: TRUE' : 'force: FALSE' ) ); ( AA_G404D_F ) && ISCLOG::ti(); return $plugin; } /** AA_G404::read_file($f, $b = false) * Reads a file with fopen and fread for a binary-safe read. $f is the file and $b is how many bytes to return, useful when you dont want to read the whole file (saving mem) * * @return string|bool - the content of the file or false on error */ function read_file($f, $b = false) { ( AA_G404D_F ) && ISCLOG::ti(); // file pointer $fp = null; // data read $d = ''; // if no size specified, read entire file if ( $b === false ) { $b = @filesize( $f ); // in case filesize failed if ( $b === false ) $b = 4098; } // return false on failures if ( ! ( $b > 0 ) || ! false === ( $fp = fopen( $f, 'rb' ) ) || ! is_resource( $fp ) ) { ( AA_G404D ) && ISCLOG::tw('ERROR OPENING FILE!!! ' . $f ); ( AA_G404D_F ) && ISCLOG::ti(); return false; } // if read_length greater than 512 bytes, if ( $b > 8192 ) { ( AA_G404D ) && ISCLOG::tw( basename( $f ) . ': READ/REQUESTED = ' . $b . '/' . strlen( $d ) . ' read size is > 8192 bytes so read in the data in 128 byte increments' ); // Read in the data in 128 byte increments while ( ! feof( $fp ) && strlen( $d ) < $b ) { $d .= fread( $fp, 128 ); } } else { ( AA_G404D ) && ISCLOG::tw( basename( $f ) . ': READ/REQUESTED = ' . $b . '/' . strlen( $d ) . ' read size is < 8192 bytes' ); // if read size is < than 8192 bytes, read it all in straight $d = fread( $fp, $b ); } // close file pointer if still open if ( is_resource( $fp ) ) fclose( $fp ); ( AA_G404D_F ) && ISCLOG::ti(); // return read data return $d; } } /** * AA_G404_Handler * * @package * @author * @copyright Produke * @version 2009 * @access public */ class AA_G404_Handler { var $reason = ''; var $uri = ''; var $sc = 404; var $req_method = 'UNKNOWN'; var $protocol = 'HTTP/1.1'; var $msg = 'The server encountered an internal error or misconfiguration and was unable to complete your request.'; /** AA_G404_Handler::__construct() * * @return void */ function __construct() { ( AA_G404D_F ) && ISCLOG::ti(); // Adds the AA_G404_Handler::output_head function to the wp_head action add_action( 'wp_head', array( &$this, 'output_head' ) ); // Modifies the title for error pages to be descriptive (in describing the error) add_filter( 'wp_title', array( &$this, 'wp_title' ), 99999, 1 ); ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404_Handler::wp_title($title) * Modifies the title for error pages to be descriptive (in describing the error) * * @param string $title The title * * @return string the title */ function wp_title($title) { ( AA_G404D_F ) && ISCLOG::ti(); $title = $this->sc . ' ' . $this->reason; ( AA_G404D_F ) && ISCLOG::ti(); return $title; } /** AA_G404_Handler::handle_it() * * @return void */ function handle_it() { ( AA_G404D_F ) && ISCLOG::ti(); //( AA_G404D ) && ISCLOG::epx( array( 'SERVER'=>$_SERVER, 'REQUEST'=>$_REQUEST ) ); // status code $this->sc = (int) ( isset( $_SERVER['REDIRECT_STATUS'] ) && $_SERVER['REDIRECT_STATUS'] != 200 ) ? $_SERVER['REDIRECT_STATUS'] : ( ! isset( $_REQUEST['error'] ) ? 404 : $_REQUEST['error'] ); // set server protocol and check version if ( ! in_array( $_SERVER['SERVER_PROTOCOL'], array( 'HTTP/1.1', 'HTTP/1.0' ) ) ) { // use 1.0 since this is indicative of a malicious request $this->protocol = 'HTTP/1.0'; // 505 HTTP Version Not Supported $this->sc = 505; } // description of status code $this->reason = get_status_header_desc( $this->sc ); // requested uri $this->uri = esc_attr( stripslashes( $_SERVER['REQUEST_URI'] ) ); // request_method or UNKNOWN if ( in_array( $_SERVER['REQUEST_METHOD'], array( 'GET', 'PUT', 'HEAD', 'POST', 'OPTIONS', 'TRACE' ) ) ) $this->req_method = $_SERVER['REQUEST_METHOD']; // set error message if ( ! in_array( $this->sc, array( 402, 409, 425, 500, 505 ) ) ) { $asc = array( 400 => 'Your browser sent a request that this server could not understand.', 401 => 'This server could not verify that you are authorized to access the document requested.', 403 => 'You don\'t have permission to access %U% on this server.', 404 => 'We couldn\'t find that uri on our server, though it\'s most certainly not your fault.', 405 => 'The requested method %M% is not allowed for the URL %U%.', 406 => 'An appropriate representation of the requested resource %U% could not be found on this server.', 407 => 'An appropriate representation of the requested resource %U% could not be found on this server.', 408 => 'Server timeout waiting for the HTTP request from the client.', 410 => 'The requested resource %U% is no longer available on this server and there is no forwarding address. Please remove all references to this resource.', 411 => 'A request of the requested method GET requires a valid Content-length.', 412 => 'The precondition on the request for the URL %U% evaluated to false.', 413 => 'The requested resource %U% does not allow request data with GET requests, or the amount of data provided in the request exceeds the capacity limit.', 414 => 'The requested URL\'s length exceeds the capacity limit for this server.', 415 => 'The supplied request data is not in a format acceptable for processing by this resource.', 416 => 'Requested Range Not Satisfiable', 417 => 'The expectation given in the Expect request-header field could not be met by this server. The client sent Expect:', 422 => 'The server understands the media type of the request entity, but was unable to process the contained instructions.', 423 => 'The requested resource is currently locked. The lock must be released or proper identification given before the method can be applied.', 424 => 'The method could not be performed on the resource because the requested action depended on another action and that other action failed.', 426 => 'The requested resource can only be retrieved using SSL. Either upgrade your client, or try requesting the page using https://', 501 => '%M% to %U% not supported.', 502 => 'The proxy server received an invalid response from an upstream server.', 503 => 'The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.', 504 => 'The proxy server did not receive a timely response from the upstream server.', 506 => 'A variant for the requested resource %U% is itself a negotiable resource. This indicates a configuration error.', 507 => 'The method could not be performed. There is insufficient free space left in your storage allocation.', 510 => 'A mandatory extension policy in the request is not accepted by the server for this resource.' ); $this->msg = ( array_key_exists( $this->sc, $asc ) ? str_replace( array( '%U%', '%M%' ), array( $this->uri, $this->req_method ), $asc[ $this->sc ] ) : 'Error' ); unset( $asc ); } // send headers @header( "{$this->protocol} {$this->sc} {$this->reason}", 1, $this->sc ); @header( "Status: {$this->sc} {$this->reason}", 1, $this->sc ); // Always close connections @header( 'Connection: close', 1 ); if ( in_array( $this->sc, array( 400, 403, 405 ) ) || $this->sc > 499 ) { // Method Not Allowed if ( $this->sc == 405 ) @header( 'Allow: GET,HEAD,POST,OPTIONS,TRACE', 1, 405 ); echo "\n\n" . esc_html( $this->sc . ' ' . $this->reason ) . "\n\n"; echo "\n

" . esc_html( $this->reason ) . "

\n

" . esc_html( $this->msg ) . "
\n

\n"; // die here and now, skip loading template ( AA_G404D_F ) && ISCLOG::ti(); die(); } ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404_Handler::output() * * @return void */ function output() { ( AA_G404D_F ) && ISCLOG::ti(); global $AA_G404; if ( ! is_object( $AA_G404 ) ) { ( AA_G404D ) && ISCLOG::tw( 'AA_G404 NOT AN OBJECT' ); $AA_G404 = aa_g404_get_object(); } // load code $AA_G404->load_code(); // if aa_google_404 function called from within template but plugin not enabled, ditch if ( '1' != $AA_G404->options['enabled'] ) { ( AA_G404D_F ) && ISCLOG::ti(); return ''; } if ( $AA_G404->options['google_ajax'] == '1' ) { $google_helper = ( ( $AA_G404->options['google_404'] == '1' ) ? '' : '' ); $recent = ( ( $AA_G404->options['recent_posts'] == '1' ) ? '' : '' ); $related = ( ( $AA_G404->options['related_posts'] == '1' ) ? $this->related_posts( (int)$AA_G404->options['related_num'], (int)$AA_G404->options['related_length'] ) : '' ); $tag_cloud = ( ( $AA_G404->options['tag_cloud'] == '1' ) ? '

' . wp_tag_cloud( array( 'echo' => false ) ) . '

' : '' ); $sr = array( '%error_title%' => $this->sc . ' ' . $this->reason, '%related_posts%' => $related, '%recent_posts%' => $recent, '%google_helper%' => $google_helper, '%tag_cloud%' => $tag_cloud, ); echo str_replace( array_keys( $sr ), array_values( $sr ), $AA_G404->code['html'] ); } if ( $AA_G404->options['mobile_analytics_log'] == '1' ) echo $this->mobile_tracker_image(); ( AA_G404D_F ) && ISCLOG::ti(); } /** AA_G404_Handler::output_head() * * @return void */ function output_head() { ( AA_G404D_F ) && ISCLOG::ti(); global $AA_G404; if ( ! is_object( $AA_G404 ) ) { ( AA_G404D ) && ISCLOG::tw( 'AA_G404 NOT AN OBJECT' ); $AA_G404 = aa_g404_get_object(); } if ( $AA_G404->options['analytics_log'] == '1' ) : ?> options['google_ajax'] == '1' ) { $sr = array(); if ( $AA_G404->options['show_result_site'] != '1' ) $sr['this.rCT.addSearcher(gSearchSite);'] = '/*this.rCT.addSearcher(gSearchSite);*/'; if ( $AA_G404->options['show_result_video'] != '1' ) $sr['this.lCT.addSearcher(gSearchVideo, sOPT);'] = '/*this.lCT.addSearcher(gSearchVideo, sOPT);*/'; if ( $AA_G404->options['show_result_image'] != '1' ) $sr['this.lCT.addSearcher(gSearchImage, sOPT);'] = '/*this.lCT.addSearcher(gSearchImage, sOPT);*/'; if ( $AA_G404->options['show_result_blogs'] != '1' ) $sr['this.rCT.addSearcher(gSearchBlog);'] = '/*this.rCT.addSearcher(gSearchBlog);*/'; if ( $AA_G404->options['show_result_web'] != '1' ) $sr['this.rCT.addSearcher(gSearchWeb);'] = '/*this.rCT.addSearcher(gSearchWeb);*/'; if ( $AA_G404->options['show_result_news'] != '1' ) $sr['this.rCT.addSearcher(gSearchNews);'] = '/*this.rCT.addSearcher(gSearchNews);*/'; if ( $AA_G404->options['show_result_cse'] != '1' ) $sr['this.rCT.addSearcher(gSearchCSE);'] = '/*this.rCT.addSearcher(gSearchCSE);*/'; if ( $AA_G404->options['show_result_local'] != '1' ) $sr['this.rCT.addSearcher(gSearchLocal);'] = '/*this.rCT.addSearcher(gSearchLocal);*/'; // do all the str_replace in 1 go if ( sizeof( $sr ) > 0 ) { if ( AA_G404D ) { foreach( $sr as $k => $v ) { if ( strpos( $AA_G404->code['javascript'], $k ) === false ) { ISCLOG::tw( 'ERROR ERROR $k NOT FOUND IN javascript' ); } } } $AA_G404->code['javascript'] = str_replace( array_keys( $sr ), array_values( $sr ), $AA_G404->code['javascript'] ); } unset( $sr ); } ?> options['robots_meta'] == '1' ) echo '' . "\n"; ?> $v ) { if ( ! in_array( $v, $stopwords ) ) { $comp_words[] = $v; } } if ( sizeof( (array) $comp_words ) > 0 ) { if ( sizeof( $comp_words ) > $num ) { array_splice( $comp_words, $num++ ); } ( AA_G404D_F ) && ISCLOG::ti(); return ( ( sizeof( $comp_words ) > 0 ) ? trim( implode( $sep, $comp_words ) ) : $host ); } ( AA_G404D_F ) && ISCLOG::ti(); return $host; } /** AA_G404_Handler::array_iunique( $array ) */ function array_iunique( $array ) { ( AA_G404D_F ) && ISCLOG::ti(); $ret = array_intersect_key( (array) $array, array_unique( array_map( 'strtolower', (array) $array ) ) ); ( AA_G404D_F ) && ISCLOG::ti(); return $ret; } /** AA_G404_Handler::related_posts($limit = 15, $l = 120) */ function related_posts($limit = 15, $l = 120) { ( AA_G404D_F ) && ISCLOG::ti(); global $wpdb; $terms = $rr = $out = ''; $terms = $this->get_keywords( ' ' ); // quit if less than 3 if ( strlen( $terms ) < 3 ) { ( AA_G404D_F ) && ISCLOG::ti(); return; } $terms = @explode( ' ', $terms ); $terms = array_map( 'trim', $terms ); $terms = $this->array_iunique( $terms ); $terms = array_map( 'sanitize_text_field', $terms ); $terms = array_map( 'wp_strip_all_tags', $terms ); if ( sizeof( $terms ) > 3 ) { array_splice( $terms, 3 ); } elseif ( sizeof( $terms ) < 1 ) { ( AA_G404D_F ) && ISCLOG::ti(); return ''; } $results1 = $results2 = array(); $vars = array(); $sql = "SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type IN('post','page') AND ( ("; foreach ( $terms as $t ) { $sql .= 'OR post_title LIKE %s '; $vars[] = '%' . $t . '%'; } $sql .= ') ) ORDER BY post_modified DESC LIMIT 0, %d'; $vars[] = $limit; $sql = str_replace(' (OR',' (', $sql); $results1 = $wpdb->get_col( $wpdb->prepare( $sql, $vars ) ); if ( is_array( $results1 ) && count( $results1 ) <= ( $limit - 1 ) ) { $vars = array(); $sql = "SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type IN('post','page') AND ( ("; foreach ( $terms as $t ) { $sql .= 'OR post_content LIKE %s '; $vars[] = '%' . $t . '%'; } $sql .= ') ) ORDER BY post_modified DESC LIMIT 0, %d'; $vars[] = intval( $limit ); $sql = str_replace(' (OR',' (', $sql); $results2 = $wpdb->get_col( $wpdb->prepare( $sql, $vars ) ); $results = array_merge( $results1, $results2 ); } else { $results = $results1; } if ( count( $results ) > $limit ) { $results = array_slice( $results, 0, $limit ); } if ( is_array( $results ) && count( $results ) > 0 ) { $ex_len = apply_filters( 'excerpt_length', 50 ); foreach ( $results as $rid) { $p = get_post( $rid ); if ( empty( $p ) || ! $p || ! is_object( $p ) || ! isset( $p->ID, $p->post_content ) ) continue; if ( ! empty( $p->post_excerpt ) ) { $ex = apply_filters( 'the_excerpt', $p->post_excerpt ); } else { $ex = str_replace(']]>', ']]>', apply_filters( 'the_content', strip_shortcodes( $p->post_content ) ) ); $ex = wp_trim_words( $ex, $ex_len, '… ' ); $ex = shortcode_unautop( wpautop( convert_chars( wptexturize( $ex ) ) ) ); } $out .= sprintf('%4$s

%2$s

%4$s
%4$s

%3$s...

%4$s
%4$s', get_permalink( $rid ), get_the_title( $rid ), $ex, "\n"); } } ( AA_G404D_F ) && ISCLOG::ti(); return $out; } /** AA_G404_Handler::mobile_tracker_image() */ function mobile_tracker_image() { ( AA_G404D_F ) && ISCLOG::ti(); $img = ''; ( AA_G404D_F ) && ISCLOG::ti(); return $img; } /** AA_G404_Handler::get_ga_image_url() */ function get_ga_image_url() { ( AA_G404D_F ) && ISCLOG::ti(); global $AA_G404; if ( ! is_object( $AA_G404 ) ) { ( AA_G404D ) && ISCLOG::tw( 'AA_G404 NOT AN OBJECT' ); $AA_G404 = aa_g404_get_object(); } $GA_ACCOUNT = $AA_G404->options['mobile_analytics_key']; $GA_PIXEL = plugins_url( 'ga.php', __FILE__ ); $url = $GA_PIXEL . '?'; $url .= 'utmac=' . $GA_ACCOUNT; $url .= '&utmn=' . rand( 0, 0x7fffffff ); $referer = ( isset( $_SERVER['HTTP_REFERER'] ) && ! empty( $_SERVER['HTTP_REFERER'] ) ) ? $_SERVER['HTTP_REFERER'] : '-'; $query = isset( $_SERVER['QUERY_STRING'] ) ? $_SERVER['QUERY_STRING'] : ''; $path = $_SERVER['REQUEST_URI']; $url .= '&utmr=' . urlencode( $referer ); if ( ! empty( $path) ) { $url .= '&utmp=' . urlencode( $path ); } $url .= '&guid=ON'; ( AA_G404D_F ) && ISCLOG::ti(); return $url; } } endif; // AA_G404 CLASS EXISTS if ( ! function_exists( 'aa_google_404' ) ) : /** aa_g404_get_object() * Singleton return of AA_G404 * * @return object AA_G404 object */ function aa_g404_get_object() { ( AA_G404D_F ) && ISCLOG::ti(); static $aa_google_404_object = null; if ( null === $aa_google_404_object ) { $aa_google_404_object = new AA_G404(); $GLOBALS['AA_G404'] =& $aa_google_404_object; } ( AA_G404D_F ) && ISCLOG::ti(); return $aa_google_404_object; } /** aa_g404_get_handler_object() * Singleton return of AA_G404_Handler * * @return object AA_G404_Handler object */ function aa_g404_get_handler_object() { ( AA_G404D_F ) && ISCLOG::ti(); static $aa_google_404_handler_object = null; if ( null === $aa_google_404_handler_object ) { $aa_google_404_handler_object = new AA_G404_Handler(); $GLOBALS['AA_G404_Handler'] =& $aa_google_404_handler_object; } ( AA_G404D_F ) && ISCLOG::ti(); return $aa_google_404_handler_object; } /** aa_google_404() * Displays generated 404 content * * @return void */ function aa_google_404() { ( AA_G404D_F ) && ISCLOG::ti(); global $AA_G404_Handler; if ( ! is_object( $AA_G404_Handler ) ) { ( AA_G404D ) && ISCLOG::tw( 'AA_G404_Handler NOT AN OBJECT' ); $AA_G404_Handler = aa_g404_get_handler_object(); } $AA_G404_Handler->output(); ( AA_G404D_F ) && ISCLOG::ti(); } /** aa_g404_init() * A super efficient way to add the AA_G404->init() function to wordpress actions on init. * * @return void */ function aa_g404_init() { ( AA_G404D_F ) && ISCLOG::ti(); global $AA_G404; if ( ! is_object( $AA_G404 ) ) { ( AA_G404D ) && ISCLOG::tw( 'AA_G404 NOT AN OBJECT' ); $AA_G404 = aa_g404_get_object(); } $AA_G404->init(); ( AA_G404D_F ) && ISCLOG::ti(); } add_action( 'init', 'aa_g404_init', 0 ); endif; // ! function_exists( 'aa_google_404' ) if ( is_admin() ) : /** aa_g404_activate() * * * @return void */ function aa_g404_activate() { ( AA_G404D_F ) && ISCLOG::ti(); global $wp_version; // Version check, only 3.3+ if ( ! version_compare( $wp_version, '3.3', '>=' ) ) { if ( function_exists( 'deactivate_plugins' ) ) { deactivate_plugins( __FILE__ ); } wp_die( 'AskApache Google 404 requires WordPress 3.3 or later' ); } global $AA_G404; if ( ! is_object( $AA_G404 ) ) { ( AA_G404D ) && ISCLOG::tw( 'AA_G404 NOT AN OBJECT' ); $AA_G404 = aa_g404_get_object(); } $AA_G404->upgrade_settings(); ( AA_G404D_F ) && ISCLOG::ti(); } register_activation_hook( __FILE__, 'aa_g404_activate' ); /** aa_g404_deactivate() * * * @return void */ function aa_g404_deactivate() { ( AA_G404D_F ) && ISCLOG::ti(); // delete plugin option delete_option( 'askapache_google_404_plugin' ); ( AA_G404D_F ) && ISCLOG::ti(); } register_deactivation_hook( __FILE__, 'aa_g404_deactivate' ); /** aa_g404_uninstall() * * * @return void */ function aa_g404_uninstall() { ( AA_G404D_F ) && ISCLOG::ti(); // delete options delete_option( 'askapache_google_404_plugin' ); delete_option( 'askapache_google_404_code' ); delete_option( 'askapache_google_404_options' ); delete_option( 'askapache_google_404_orig_code' ); delete_option( 'askapache_google_404_iframe_one_time' ); delete_option( 'aa_google_404_api_key' ); delete_option( 'aa_google_404_adsense_key' ); delete_option( 'aa_google_404_analytics_key' ); ( AA_G404D_F ) && ISCLOG::ti(); } register_uninstall_hook( __FILE__, 'aa_g404_uninstall' ); /** aa_g404_plugin_action_links($l) * * * @return void */ function aa_g404_plugin_action_links($l) { return array_merge( array( 'Settings' ), $l ); } add_filter( 'plugin_action_links_askapache-google-404/askapache-google-404.php', 'aa_g404_plugin_action_links' ); /** aa_g404_admin_footer_settings_page() * * * @return void */ function aa_g404_admin_footer_settings_page() { ( AA_G404D_F ) && ISCLOG::ti(); ?> #ag4 #icon-askapache {background-image:url("'.plugins_url("f/i/icon-askapache.png",__FILE__).'");}'; ( AA_G404D_F ) && ISCLOG::ti(); } add_action( 'admin_print_styles-settings_page_askapache-google-404', 'aa_g404_admin_print_styles' ); endif; // EOF