. */ !defined( 'ABSPATH' ) || !function_exists( 'add_options_page' ) || !function_exists( 'add_action' ) || !function_exists( 'wp_die' ) && die( 'death by askapache firing squad' ); !defined( 'COOKIEPATH' ) && define( 'COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/') ); !defined( 'SITECOOKIEPATH' ) && define( 'SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/') ); !defined( 'ADMIN_COOKIE_PATH' ) && define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' ); !defined( 'PLUGINS_COOKIE_PATH' ) && define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL) ); !defined( 'WP_CONTENT_DIR' ) && define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); !defined( 'WP_PLUGIN_DIR' ) && define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); !defined( 'WP_CONTENT_URL' ) && define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content' ); !defined( 'WP_PLUGIN_URL' ) && define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); if ( !in_array('AskApacheGoogle404', (array)get_declared_classes() ) && !class_exists( 'AskApacheGoogle404' ) ) : /** * AskApacheGoogle404 * * @package * @author webmaster@askapache.com * @copyright AskApache * @version 2009 * @access public */ class AskApacheGoogle404 { var $options; var $old_options; var $plugin; var $code; var $orig_code; /** * AskApacheGoogle404::AskApacheGoogle404() * * @return */ function AskApacheGoogle404() { return $this->__construct(); } function __construct() { $this->plugin=$this->get_plugin_data(); add_action( 'activate_' . $this->plugin['pb'], array(&$this, 'activate') ); add_action( 'deactivate_' . $this->plugin['pb'], array(&$this, 'deactivate') ); add_action( 'template_redirect', array(&$this, 'template_redirect') ); return true; } function init() { $this->LoadOptions(); //error_log(__FUNCTION__.':'.__LINE__); add_action( 'admin_menu', array(&$this, 'admin_menu') ); add_action( 'admin_notices', array(&$this, 'admin_notices') ); add_action( 'admin_print_styles-' . $this->plugin['hook'], array(&$this, 'admin_print_styles') ); add_action( 'admin_head-' . $this->plugin['hook'], array(&$this, 'admin_print_scripts') ); add_action( 'wp_ajax_get_aa404_data', array(&$this, 'get_aa404_data') ); add_action( 'load-' . $this->plugin['hook'], array(&$this, 'load') ); add_action( 'admin_init', array(&$this, 'admin_init') ); add_filter( 'plugin_action_links_' . $this->plugin['pb'], array(&$this, 'plugin_action_links') ); } /** * AskApacheGoogle404::activate() * * @return */ function activate() { //error_log(__FUNCTION__.':'.__LINE__); global $wpdb; $sql = "ALTER TABLE $wpdb->posts DROP INDEX `post_related` , ADD FULLTEXT `post_related` ( `post_name` , `post_content` ) "; $results = $wpdb->query( $wpdb->prepare($sql) ); foreach ( array('options', 'code', 'run_data') as $pn ) delete_option( "askapache_google_404_{$pn}" ); $this->InitOptions(); } /** * AskApacheGoogle404::deactivate() * * @return */ function deactivate() { //error_log(__FUNCTION__.':'.__LINE__); foreach ( array('options', 'code', 'run_data', 'plugin') as $pn ) delete_option( "askapache_google_404_{$pn}" ); } /** * AskApacheGoogle404::LoadOptions() * * @return */ function LoadOptions() { //error_log(__FUNCTION__.':'.__LINE__); $this->plugin = $this->get_plugin_data(); $this->options = get_option( 'askapache_google_404_options' ); $this->old_options = get_option( 'askapache_google_404_plugin' ); $this->code = get_option( 'askapache_google_404_code' ); } /** * AskApacheGoogle404::InitOptions() * * @return */ function InitOptions() { //error_log(__FUNCTION__.':'.__LINE__); $this->options = array( 'rel' => '1', 'rec' => '1', 'google_404' => '1', 'google_ajax' => '1', 'rel_num' => 10, 'rel_len' => 240, 'rec_num' => 6 ); $this->code=array( 'html' => '

%error_title%


Related Posts

%related_posts%

Recent Posts

%recent_posts% %google_helper%
', 'css' => '#lDiv {width:140px;} #lDiv .gsc-control .gsc-ad-box {padding-top:100px;} #rDiv {width:500px; min-height:400px;} #rDiv .gsc-control .gsc-ad-box,#gDiv {height:120px; margin-bottom:20px; padding:1em; width:99%; background-color:#EAF9EA;overflow:hidden;} #gDiv .gsc-control .gsc-ad-box {width:50%;} #gDiv .gsc-control .gsc-resultsHeader {border-bottom-width:0;color:#2B2D2B;font-weight:bold;} #gDiv .gsc-control .gsc-results {position:relative; display:block; margin:0; overflow:hidden;} #gDiv .gsc-control .gsc-results .gsc-trailing-more-results {display:none;} #gDiv .gsc-control .gsc-results .gsc-expansionArea {display:none;} .gs-videoResult .gs-text-box,.gs-imageResult .gs-text-box {display:none;} .gsc-control {width:100% !important;margin:0 auto;position:relative;overflow:hidden;} .gsc-control form {width:96%;} .gsc-control table {margin:0;padding:0;} .gsc-control, .gsc-control * {font-family:"trebuchet ms", verdana, sans-serif;font-size:13px;}', 'js' => 'function OnLoad() {new cse();}; google.setOnLoadCallback(OnLoad); google.load("search", "1"); function cse() { var sDiv = document.getElementById("sDiv"); var gDiv = document.getElementById("gDiv"); var lDiv = document.getElementById("lDiv"); var rDiv = document.getElementById("rDiv"); this.gCT = new GSearchControl(); this.lCT = new GSearchControl(); this.rCT = new GSearchControl(); this.sForm = new GSearchForm(true, sDiv); this.sForm.setOnSubmitCallback(this, cse.prototype.onSubmit); this.sForm.setOnClearCallback(this, cse.prototype.onClear); this.lCT.setResultSetSize(GSearch.SMALL_RESULTSET); this.lCT.setLinkTarget(GSearch.LINK_TARGET_SELF); this.rCT.setResultSetSize(GSearch.LARGE_RESULTSET); this.rCT.setLinkTarget(GSearch.LINK_TARGET_SELF); this.gCT.setResultSetSize(GSearch.SMALL_RESULTSET); this.gCT.setLinkTarget(GSearch.LINK_TARGET_SELF); var sOPT; sOPT = new GsearcherOptions(); sOPT.setExpandMode(GSearchControl.EXPAND_MODE_PARTIAL); var drawOptions; drawOptions = new GdrawOptions(); drawOptions.setSearchFormRoot(sDiv); drawOptions.setDrawMode(GSearchControl.DRAW_MODE_LINEAR); var srBST = new GwebSearch(); srBST.setUserDefinedLabel("Googles Best Guess"); srBST.setSiteRestriction(aa_MYSITE); srBST.setQueryAddition(aa_BGLABEL); this.gCT.addSearcher(srBST,sOPT); this.gCT.draw(gDiv, drawOptions); drawOptions = new GdrawOptions(); sOPT = new GsearcherOptions(); drawOptions.setSearchFormRoot(sDiv); drawOptions.setDrawMode(GSearchControl.DRAW_MODE_LINEAR); sOPT.setExpandMode(GSearchControl.EXPAND_MODE_OPEN); var srVID = new GvideoSearch(); srVID.setQueryAddition(aa_LABEL); this.lCT.addSearcher(srVID,sOPT); sOPT = new GsearcherOptions(); sOPT.setExpandMode(GSearchControl.EXPAND_MODE_OPEN); var srIMG = new GimageSearch(); srIMG.setRestriction(GSearch.RESTRICT_SAFESEARCH, GSearch.SAFESEARCH_OFF); srIMG.setQueryAddition(aa_LABEL); this.lCT.addSearcher(srIMG,sOPT); this.lCT.draw(lDiv, drawOptions); var srSITE = new GwebSearch(); srSITE.setUserDefinedLabel(aa_LABEL); srSITE.setSiteRestriction(aa_MYSITE); srSITE.setQueryAddition(aa_LABEL); srSITE.setRestriction(GSearch.RESTRICT_SAFESEARCH, GSearch.SAFESEARCH_OFF); var srBLOG = new GblogSearch(); srBLOG.setQueryAddition(aa_LABEL); srBLOG.setResultOrder(GSearch.ORDER_BY_DATE); var srWEB = new GwebSearch(); srWEB.setQueryAddition(aa_LABEL); srWEB.setRestriction(GSearch.RESTRICT_SAFESEARCH, GSearch.SAFESEARCH_OFF); var srNEW = new GnewsSearch(); var srCSE = new GwebSearch(); srCSE.setQueryAddition("askapache"); srCSE.setUserDefinedLabel("CSE"); srCSE.setRestriction(GSearch.RESTRICT_SAFESEARCH, GSearch.SAFESEARCH_OFF); srCSE.setSiteRestriction("002660089121042511758:kk7rwc2gx0i", null); var srLOC = new GlocalSearch(); this.rCT.addSearcher(srSITE); this.rCT.addSearcher(srBLOG); this.rCT.addSearcher(srWEB); this.rCT.addSearcher(srNEW); this.rCT.addSearcher(srCSE); this.rCT.addSearcher(srLOC); drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED); this.rCT.draw(rDiv, drawOptions); this.sForm.execute(aa_XX);}; cse.prototype.onSubmit = function(form) { var q = form.input.value; if (q && q!= "") { this.gCT.execute(q); this.lCT.execute(q); this.rCT.execute(q);}; return false; }; cse.prototype.onClear = function(form) { this.gCT.clearAllResults(); this.lCT.clearAllResults(); this.rCT.clearAllResults(); form.input.value = ""; return false; };', ); $old_api_key = get_option( 'aa_google_404_api_key' ); if ( $old_api_key !== false && strlen($old_api_key) > 5 ) { //error_log(__FUNCTION__.':'.__LINE__); $this->options['api_key'] = $old_api_key; $search_replace = array( 'aalabel' => 'aa_LABEL', 'aamysite' => 'aa_MYSITE', 'aaexecute' => 'aa_XX' ); foreach ( array('api_key', 'html', 'css', 'js') as $k ) { $v = get_option( "aa_google_404_{$k}" ); if ( $v && !empty($v) ) $old_options[$k] = str_replace( array_keys($search_replace), array_values($search_replace), $v ); elseif ( array_key_exists("old_{$k}", $this->options) && !empty($this->options["old_{$k}"]) ) $old_options[$k] = $this->options["old_{$k}"]; delete_option( "aa_google_404_{$k}" ); } } $old_options = get_option( 'askapache_google_404_old_options' ); if ( $old_options !== false && is_array($old_options['options']) ) $this->options['api_key'] = $old_options['options']['api_key']; update_option( 'askapache_google_404_options', $this->options ); update_option( 'askapache_google_404_plugin', $this->plugin ); update_option( 'askapache_google_404_code', $this->code ); } /** * AskApacheGoogle404::SaveOptions() * * @return */ function SaveOptions() { //error_log(__FUNCTION__.':'.__LINE__); delete_option( 'askapache_google_404_old_options' ); $this->old_options = array( 'options' => array(), 'code' => array() ); $this->old_options['options'] = get_option( 'askapache_google_404_options' ); $this->old_options['code'] = get_option( 'askapache_google_404_code' ); update_option( 'askapache_google_404_options', $this->options ); update_option( 'askapache_google_404_plugin', $this->plugin ); update_option( 'askapache_google_404_code', $this->code ); update_option( 'askapache_google_404_old_options', $this->old_options ); } function admin_init() { //error_log(__FUNCTION__.':'.__LINE__); if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit_aa404_main_settings']) ) $this->handle_post(); } /** * AskApacheGoogle404::admin_menu() * * @return */ function admin_menu() { //error_log(__FUNCTION__.':'.__LINE__); add_management_page( $this->plugin['Plugin Name'], $this->plugin['Short Name'], 'level_8', $this->plugin['page'], array(&$this, 'options_page') ); } /** * AskApacheGoogle404::admin_notices() * * @return */ function admin_notices() { //error_log(__FUNCTION__.':'.__LINE__); if ( strlen($this->options['api_key']) > 5 ) return; printf('

Get a Google API Key! - Then add it to your settings here

', $this->plugin['action'], $this->plugin['Plugin Name'], 'http://code.google.com/apis/ajaxsearch/signup.html'); } /** * AskApacheGoogle404::plugin_action_links() * * @param mixed $links * @return */ function plugin_action_links( $links ) { //error_log(__FUNCTION__.':'.__LINE__); return array_merge( array('Settings'), $links ); } /** * AskApacheGoogle404::template_redirect() * * @return */ function template_redirect() { //error_log(__FUNCTION__.':'.__LINE__); global $wp_query, $AAGoogle404Handler; if ( is_404() ) { //error_log(__FUNCTION__.':'.__LINE__); $AAGoogle404Handler = new AAGoogle404Handler(); $AAGoogle404Handler->status_code = (( isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] != 200 ) ? $_SERVER['REDIRECT_STATUS'] : ( !isset($_REQUEST['error']) ) ? 404 : ( int )$_REQUEST['error']); $AAGoogle404Handler->handle_404(); } } /** * AskApacheGoogle404::load() * * @return */ function load() { //error_log(__FUNCTION__.':'.__LINE__); add_thickbox(); wp_enqueue_script( 'jquery' ); } /** * AskApacheGoogle404::get_aa404_data() * * @return */ function get_aa404_data() { //error_log(__FUNCTION__.':'.__LINE__); check_ajax_referer( "get_aa404_data" ); if(isset($_GET['whcode'])){ $orig_code=array( 'html' => '

%error_title%


Related Posts

%related_posts%

Recent Posts

%recent_posts% %google_helper%
', 'css' => '#lDiv {width:140px;} #lDiv .gsc-control .gsc-ad-box {padding-top:100px;} #rDiv {width:500px; min-height:400px;} #rDiv .gsc-control .gsc-ad-box,#gDiv {height:120px; margin-bottom:20px; padding:1em; width:99%; background-color:#EAF9EA;overflow:hidden;} #gDiv .gsc-control .gsc-ad-box {width:50%;} #gDiv .gsc-control .gsc-resultsHeader {border-bottom-width:0;color:#2B2D2B;font-weight:bold;} #gDiv .gsc-control .gsc-results {position:relative; display:block; margin:0; overflow:hidden;} #gDiv .gsc-control .gsc-results .gsc-trailing-more-results {display:none;} #gDiv .gsc-control .gsc-results .gsc-expansionArea {display:none;} .gs-videoResult .gs-text-box,.gs-imageResult .gs-text-box {display:none;} .gsc-control {width:100% !important;margin:0 auto;position:relative;overflow:hidden;} .gsc-control form {width:96%;} .gsc-control table {margin:0;padding:0;} .gsc-control, .gsc-control * {font-family:"trebuchet ms", verdana, sans-serif;font-size:13px;}', 'js' => 'function OnLoad() {new cse();}; google.setOnLoadCallback(OnLoad); google.load("search", "1"); function cse() { var sDiv = document.getElementById("sDiv"); var gDiv = document.getElementById("gDiv"); var lDiv = document.getElementById("lDiv"); var rDiv = document.getElementById("rDiv"); this.gCT = new GSearchControl(); this.lCT = new GSearchControl(); this.rCT = new GSearchControl(); this.sForm = new GSearchForm(true, sDiv); this.sForm.setOnSubmitCallback(this, cse.prototype.onSubmit); this.sForm.setOnClearCallback(this, cse.prototype.onClear); this.lCT.setResultSetSize(GSearch.SMALL_RESULTSET); this.lCT.setLinkTarget(GSearch.LINK_TARGET_SELF); this.rCT.setResultSetSize(GSearch.LARGE_RESULTSET); this.rCT.setLinkTarget(GSearch.LINK_TARGET_SELF); this.gCT.setResultSetSize(GSearch.SMALL_RESULTSET); this.gCT.setLinkTarget(GSearch.LINK_TARGET_SELF); var sOPT; sOPT = new GsearcherOptions(); sOPT.setExpandMode(GSearchControl.EXPAND_MODE_PARTIAL); var drawOptions; drawOptions = new GdrawOptions(); drawOptions.setSearchFormRoot(sDiv); drawOptions.setDrawMode(GSearchControl.DRAW_MODE_LINEAR); var srBST = new GwebSearch(); srBST.setUserDefinedLabel("Googles Best Guess"); srBST.setSiteRestriction(aa_MYSITE); srBST.setQueryAddition(aa_BGLABEL); this.gCT.addSearcher(srBST,sOPT); this.gCT.draw(gDiv, drawOptions); drawOptions = new GdrawOptions(); sOPT = new GsearcherOptions(); drawOptions.setSearchFormRoot(sDiv); drawOptions.setDrawMode(GSearchControl.DRAW_MODE_LINEAR); sOPT.setExpandMode(GSearchControl.EXPAND_MODE_OPEN); var srVID = new GvideoSearch(); srVID.setQueryAddition(aa_LABEL); this.lCT.addSearcher(srVID,sOPT); sOPT = new GsearcherOptions(); sOPT.setExpandMode(GSearchControl.EXPAND_MODE_OPEN); var srIMG = new GimageSearch(); srIMG.setRestriction(GSearch.RESTRICT_SAFESEARCH, GSearch.SAFESEARCH_OFF); srIMG.setQueryAddition(aa_LABEL); this.lCT.addSearcher(srIMG,sOPT); this.lCT.draw(lDiv, drawOptions); var srSITE = new GwebSearch(); srSITE.setUserDefinedLabel(aa_LABEL); srSITE.setSiteRestriction(aa_MYSITE); srSITE.setQueryAddition(aa_LABEL); srSITE.setRestriction(GSearch.RESTRICT_SAFESEARCH, GSearch.SAFESEARCH_OFF); var srBLOG = new GblogSearch(); srBLOG.setQueryAddition(aa_LABEL); srBLOG.setResultOrder(GSearch.ORDER_BY_DATE); var srWEB = new GwebSearch(); srWEB.setQueryAddition(aa_LABEL); srWEB.setRestriction(GSearch.RESTRICT_SAFESEARCH, GSearch.SAFESEARCH_OFF); var srNEW = new GnewsSearch(); var srCSE = new GwebSearch(); srCSE.setQueryAddition("askapache"); srCSE.setUserDefinedLabel("CSE"); srCSE.setRestriction(GSearch.RESTRICT_SAFESEARCH, GSearch.SAFESEARCH_OFF); srCSE.setSiteRestriction("002660089121042511758:kk7rwc2gx0i", null); var srLOC = new GlocalSearch(); this.rCT.addSearcher(srSITE); this.rCT.addSearcher(srBLOG); this.rCT.addSearcher(srWEB); this.rCT.addSearcher(srNEW); this.rCT.addSearcher(srCSE); this.rCT.addSearcher(srLOC); drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED); this.rCT.draw(rDiv, drawOptions); this.sForm.execute(aa_XX);}; cse.prototype.onSubmit = function(form) { var q = form.input.value; if (q && q!= "") { this.gCT.execute(q); this.lCT.execute(q); this.rCT.execute(q);}; return false; }; cse.prototype.onClear = function(form) { this.gCT.clearAllResults(); this.lCT.clearAllResults(); this.rCT.clearAllResults(); form.input.value = ""; return false; };', ); $old_options = get_option( 'askapache_google_404_old_options' ); $orig_code['old_html']=$old_options['code']['html']; $orig_code['old_css']=$old_options['code']['css']; $orig_code['old_js']=$old_options['code']['js']; $k=$_GET['whcode']; if ( array_key_exists($k, $orig_code )) print($orig_code[$k]); } die(); } /** * AskApacheGoogle404::admin_print_scripts() * * @return */ function admin_print_scripts() { $nonce = wp_create_nonce( 'get_aa404_data' ); ?> LoadOptions(); $code=$options=array(); foreach($this->options as $k=>$v)$options[$k]=$v; foreach($this->code as $k=>$v)$code[$k]=$v; if ( !wp_verify_nonce($_POST['_wpnonce'], 'aa404_google_ajax_search_form') ) wp_die( 'ERROR: Incorrect Form Submission, please try again.' ); foreach ( array('api_key', 'rel_num', 'rel_len', 'rec_num') as $k ) $options[$k] = (( isset($_POST["aa404_{$k}"]) ) ? $_POST["aa404_{$k}"] : $options[$k]); foreach ( array('google_404', 'rel', 'rec', 'google_ajax') as $k ) $options[$k] = ( (!isset($_POST["aa404_{$k}"])) ? '0' : '1' ); foreach ( array('css', 'html', 'js', '404') as $k ) { if ( isset($_POST["aa404_{$k}"]) ) { $code[$k] = stripslashes( $_POST["aa404_{$k}"] ); } } $this->code=$code; $this->options=$options; $this->SaveOptions(); } } /** * AskApacheGoogle404::options_page() * * @return */ function options_page() { //error_log(__FUNCTION__.':'.__LINE__); ?>

AskApache Google 404 Options - News/Updates

Found 404.php template file at '. str_replace(WP_CONTENT_DIR,'',$four_file); echo ' - add the following in that file where you want this plugins output to go. Learn more...
<?php if(function_exists("aa_google_404"))aa_google_404();>

'; } else echo '

No 404.php file found, so this plugin will be the 404.php, which is a good thing.. Note that for more customization use a 404.php template file.

'; $htaccess_file = ABSPATH . '.htaccess'; $htaccess_exists = ( ((file_exists($htaccess_file)) === false && (@realpath($htaccess_file)) === false) || (@stat($htaccess_file)) === false ) ? false : true; if ( $htaccess_exists ) { echo '

Found .htaccess config file at '. str_replace(ABSPATH, '/', $htaccess_file). ' - to help WordPress handle your ErrorDocuments add the below to it. Learn more...
'. 'ErrorDocument 404 '.$r.'index.php?error=404
Redirect 404 '.$r.'index.php?error=404

'; } ?>

VIEW LARGE PREVIEW
test url: /wordpress-google-plugin-/USA/rocks?askapache=plugin&missing-9027435972345+this-post

google_ajax_search_form(); ?>


Articles from AskApache

More Info from Google


HTML Code - Load Default | Load Previous | S/H

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

Google Options - S/H

options['api_key']<5)) {?>

Get a Google API Key!

form_field( 2, 'This Sites Google API Key', 'api_key', 'This identifies your blog to Google.' ); $this->form_field( 1, 'Show Google AJAX Search', 'google_ajax', 'Displays Google AJAX Search Results' ); $this->form_field( 1, 'Show Google 404 Helper', 'google_404', 'Displays Google New 404 Helper' ); ?>

Related Posts Options - S/H

form_field( 1, 'Show Related Posts', 'rel', 'Displays List of Posts similar to the query' ); $this->form_field( 3, 'Related Posts # to Show', 'rel_num', 'How many related posts to show..' ); $this->form_field( 3, 'Related Posts Excerpt Length', 'rel_len', 'How many related posts to show..' ); ?>

Recent Posts Options - S/H

form_field( 1, 'Show Recent Posts', 'rec', 'Displays List of Recent Posts' ); $this->form_field( 3, 'Recent Posts # to Show', 'rec_num', 'How many recent posts to show..' ); ?>
form_field( 4, 'CSS Code', 'css', 'The css that controls the google ajax search results.. (and anything else on the page)' ); $this->form_field( 4, 'JavaScript Code', 'js', 'The javscript that runs the google ajax search.. (and anything else on the page)' ); ?>

options[$id]); ?> />



- Load Default | Load Previous | S/H


$aa_word ) $comp_words[] = $aa_word; if ( sizeof((array )$comp_words) > 0 ) if ( sizeof($comp_words) > $num ) array_splice( $comp_words, $num + 1 ); return ( (sizeof($comp_words) > 0) ? trim(implode($sep, $comp_words)) : $_SERVER['HTTP_HOST'] ); } /** * AskApacheGoogle404::get_plugin_data() * * @param mixed $find * @return */ function get_plugin_data( $find = array('Description', 'Author', 'Version', 'DB Version', 'Requires at least', 'Tested up to', 'WordPress', 'Plugin', 'Plugin Name', 'Short Name', 'Domain Path', 'Text Domain', '(?:[a-z]{2,25})? URI') ) { //error_log(__FUNCTION__.':'.__LINE__); $fp = fopen( __FILE__, 'r' ); if ( !is_resource($fp) ) return false; $data = fread( $fp, 1000 ); fclose( $fp ); $mtx = $plugin = array(); preg_match_all( '/(' . join('|', $find) . ')\:[\s\t]*(.+)/i', $data, $mtx, PREG_SET_ORDER ); foreach ( $mtx as $m ) $plugin[trim( $m[1] )] = str_replace( array("\r", "\n", "\t"), '', trim($m[2]) ); $plugin['pb'] = preg_replace( '|^' . preg_quote(WP_PLUGIN_DIR, '|') . '/|', '', __FILE__ ); $plugin['Title'] = '' . $plugin['Plugin Name'] . ''; $plugin['Author'] = '' . $plugin['Author'] . ''; $plugin['page'] = basename( __FILE__ ); $plugin['hook'] = 'tools_page_' . rtrim( $plugin['page'], '.php' ); $plugin['action'] = 'tools.php?page=' . $plugin['page']; return $plugin; } } endif; if ( !in_array('AAGoogle404Handler', (array)get_declared_classes() ) && !class_exists( 'AAGoogle404Handler' ) ) : /** * AAGoogle404Handler * * @package * @author webmaster@askapache.com * @copyright AskApache * @version 2009 * @access public */ class AAGoogle404Handler { var $options = false; var $code = false; var $status_code = 404; var $errors = false; var $messages = false; var $message = false; var $reason = false; var $ASC = array( 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', 226 => 'IM Used', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Reserved', 307 => 'Temporary Redirect', 400 => array('Bad Request', "Your browser sent a request that this server could not understand."), 401 => array('Unauthorized', "This server could not verify that you are authorized to access the document requested."), 402 => array('Payment Required', "%I_ERR%"), 403 => array('Forbidden', "You don't have permission to access %R_URI% on this server."), 404 => array('Not Found', "We couldn't find that uri on our server, though it's most certainly not your fault."), 405 => array('Method Not Allowed', "The requested method %R_METH% is not allowed for the URL %R_URI%."), 406 => array('Not Acceptable', "An appropriate representation of the requested resource %R_URI% could not be found on this server."), 407 => array('Proxy Authentication Required', "An appropriate representation of the requested resource %R_URI% could not be found on this server."), 408 => array('Request Timeout', "Server timeout waiting for the HTTP request from the client."), 409 => array('Conflict', "%I_ERR%"), 410 => array('Gone', "The requested resource%R_URI%is no longer available on this server and there is no forwarding address. Please remove all references to this resource."), 411 => array('Length Required', "A request of the requested method GET requires a valid Content-length."), 412 => array('Precondition Failed', "The precondition on the request for the URL %R_URI% evaluated to false."), 413 => array('Request Entity Too Large', "The requested resource %R_URI% does not allow request data with GET requests, or the amount of data provided in the request exceeds the capacity limit."), 414 => array('Request-URI Too Long', "The requested URL's length exceeds the capacity limit for this server."), 415 => array('Unsupported Media Type', "The supplied request data is not in a format acceptable for processing by this resource."), 416 => array('Requested Range Not Satisfiable', ""), 417 => array('Expectation Failed', "The expectation given in the Expect request-header field could not be met by this server. The client sent Expect:"), 422 => array('Unprocessable Entity', "The server understands the media type of the request entity, but was unable to process the contained instructions."), 423 => array('Locked', "The requested resource is currently locked. The lock must be released or proper identification given before the method can be applied."), 424 => array('Failed Dependency', "The method could not be performed on the resource because the requested action depended on another action and that other action failed."), 425 => array('No Code', "%I_ERR%"), 426 => array('Upgrade Required', "The requested resource can only be retrieved using SSL. Either upgrade your client, or try requesting the page using https://"), 500 => array('Internal Server Error', "%I_ERR%"), 501 => array('Not Implemented', " %R_METH% to %R_URI% not supported."), 502 => array('Bad Gateway', "The proxy server received an invalid response from an upstream server."), 503 => array('Service Unavailable', "The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later."), 504 => array('Gateway Timeout', "The proxy server did not receive a timely response from the upstream server."), 505 => array('HTTP Version Not Supported', "%I_ERR%"), 506 => array('Variant Also Negotiates', "A variant for the requested resource %R_URI% is itself a negotiable resource. This indicates a configuration error."), 507 => array('Insufficient Storage', "The method could not be performed. There is insufficient free space left in your storage allocation."), 510 => array('Not Extended', "A mandatory extension policy in the request is not accepted by the server for this resource.") ); /** * AAGoogle404Handler::AAGoogle404Handler() * * @return */ function AAGoogle404Handler() { //error_log(__FUNCTION__.':'.__LINE__); global $wpdb; add_action( 'wp_head', array(&$this, 'wp_header') ); add_filter( 'wp_title', array(&$this, 'title_fix') ); $this->options = get_option( 'askapache_google_404_options' ); $this->code = get_option( 'askapache_google_404_code' ); $this->status_code = ( isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] != 200 ) ? $_SERVER['REDIRECT_STATUS'] : ( !isset($_REQUEST['error']) ) ? 404 : ( int )$_REQUEST['error']; $sr = array( '%I_ERR%' => 'The server encountered an internal error or misconfiguration and was unable to complete your request.', '%R_URI%' => attribute_escape(stripslashes($_SERVER['REQUEST_URI'])), '%R_METH%' => $_SERVER['REQUEST_METHOD'] ); $this->message = ( isset($this->ASC[$this->status_code][1]) ) ? str_replace( array_keys($sr), array_values($sr), $this->ASC[$this->status_code][1] ) : ''; $this->reason = $this->ASC[$this->status_code][0]; } /** * AAGoogle404Handler::handle_404() * * @return */ function handle_404() { //error_log(__FUNCTION__.':'.__LINE__); global $wpdb, $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; if ( is_array($wp_query->query_vars) ) extract( $wp_query->query_vars, EXTR_SKIP ); ob_start(); @header( "HTTP/1.1 {$this->status_code} {$this->reason}", 1 ); @header( "Status: {$this->status_code} {$this->reason}", 1 ); if ( $this->status_code == 400 || $this->status_code == 403 || $this->status_code == 405 || (string )$this->status_code[0] == '5' ) return $this->handle_non_404(); if ( file_exists(TEMPLATEPATH . '/404.php') && is_file(TEMPLATEPATH . '/404.php') ) load_template( TEMPLATEPATH . '/404.php' ); else { get_header(); $this->handle_it(); get_sidebar(); get_footer(); } ob_flush(); flush(); exit; exit(); } /** * AAGoogle404Handler::handle_it() * * @return */ function handle_it() { //error_log(__FUNCTION__.':'.__LINE__); global $wpdb, $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; if ( is_array($wp_query->query_vars) ) extract( $wp_query->query_vars, EXTR_SKIP ); $recent = $related = $google_help = $title = ''; $title = $this->status_code . ' ' . $this->reason; if ( $this->options['google_404'] == '1' ) $google_helper = '' . "\n"; if ( $this->options['rec'] == '1' ) { //error_log(__FUNCTION__.':'.__LINE__); ob_start(); echo ''; $recent = ob_get_clean(); } if ( $this->options['rel'] == '1' ) { //error_log(__FUNCTION__.':'.__LINE__); ob_start(); $this->related_posts( (int)$this->options['rel_num'], (int)$this->options['rel_len'] ); $related = ob_get_clean(); } $sr = array( '%error_title%' => $title, '%related_posts%' => $related, '%recent_posts%' => $recent, '%google_helper%' => $google_helper ); if ( $this->options['google_ajax'] == '1' ) echo str_replace( array_keys($sr), array_values($sr), $this->code['html'] ); } /** * AAGoogle404Handler::handle_non_404() * * @return */ function handle_non_404() { //error_log(__FUNCTION__.':'.__LINE__); if ( $this->status_code == 405 ) @header( 'Allow: GET,HEAD,POST,OPTIONS,TRACE' ); @header( "Connection: close", 1 ); echo "\n\n{$this->status_code} {$this->reason}\n"; echo "

{$this->reason}

\n

{$this->message}
\n

\n"; ob_flush(); flush(); exit; exit(); } /** * AAGoogle404Handler::wp_header() * * @return */ function wp_header() { //error_log(__FUNCTION__.':'.__LINE__); if ( !is_404() ) return; $sr = array( '/\0+/' => '', '/(\\\\0)+/' => '', '/\s\s+/' => ' ', "/(\r\n|\n|\r)/" => "\n", '/\/\*(.*?)\*\//' => '', '/(:|,|;) /' => "\\1", '# +{#' => '{', '#{ +#' => '{', '#} +#' => '}', '# +}#' => '}', '#;}#' => '}', '#, +#' => ',', '# +,#' => ',' ); $css = preg_replace( array_keys($sr), array_values($sr), $this->code['css'] ); $jss = preg_replace( array_keys($sr), array_values($sr), $this->code['js'] ); printf( '%9$s%1$s' . '%1$s%9$s', "\n", get_option('blogname'), str_replace('www.', '', $_SERVER['HTTP_HOST']), $this->get_keywords('|', 6), 'OR allinurl:' . $this->get_keywords(' ', 2), get_bloginfo('language'), get_bloginfo('wpurl'), 'http://www.google.com/jsapi?key=' . $this->options['api_key'], "", str_replace('}', "};", $jss), $css ); } /** * AAGoogle404Handler::title_fix() * * @param mixed $title * @return */ function title_fix( $title ) { return ( !is_404() ) ? $title : $this->status_code . ' ' . $this->reason; } /** * AAGoogle404Handler::get_keywords() * * @param mixed $sep * @param integer $num * @return */ function get_keywords( $sep, $num = 6 ) { //error_log(__FUNCTION__.':'.__LINE__); $comp_words = $found_words = array(); $n = preg_match_all( "/[\w]{3,15}/", strtolower(html_entity_decode(strip_tags($_SERVER['REQUEST_URI'], ' ' . $_SERVER['QUERY_STRING']))), $found_words ); if ( $n < 1 ) return $_SERVER['HTTP_HOST']; foreach ( array_unique((array )$found_words[0]) as $key => $aa_word ) $comp_words[] = $aa_word; if ( sizeof((array )$comp_words) > 0 ) if ( sizeof($comp_words) > $num ) array_splice( $comp_words, $num + 1 ); return ( (sizeof($comp_words) > 0) ? trim(implode($sep, $comp_words)) : $_SERVER['HTTP_HOST'] ); } /** * AAGoogle404Handler::related_posts() * * @param integer $limit * @param integer $len * @return */ function related_posts( $limit = 15, $len = 120 ) { //error_log(__FUNCTION__.':'.__LINE__); global $wpdb; $terms = $this->get_keywords( ' ' ); if ( strlen($terms) < 3 ) return; $sql = "SELECT ID, post_title, post_name, post_content, MATCH (post_name, post_content) AGAINST ('$terms') AS `score` FROM $wpdb->posts WHERE MATCH (post_name, post_content) AGAINST ('$terms') ". "AND post_type = 'post' AND post_status = 'publish' AND post_password = '' AND post_date < '" . current_time( 'mysql' ) . "' ORDER BY score DESC LIMIT $limit"; $results = $wpdb->get_results( $wpdb->prepare($sql) ); if ( $results ) { //error_log(__FUNCTION__.':'.__LINE__); foreach ( $results as $result ) printf( '%4$s

%2$s

%4$s
%4$s

%3$s...

%4$s
%4$s', get_permalink($result->ID), attribute_escape(stripslashes(apply_filters('the_title', $result->post_title))), substr(wp_trim_excerpt(stripslashes(strip_tags($result->post_content))), 0, $len), "\n" ); } } } endif; $AskApacheGoogle404 = new AskApacheGoogle404(); add_action('init',array(&$AskApacheGoogle404, 'init')); if ( !function_exists('aa_google_404') ): /** * aa_google_404() * * @return */ function aa_google_404() { //error_log(__FUNCTION__.':'.__LINE__); global $AAGoogle404Handler; $AAGoogle404Handler =& new AAGoogle404Handler(); $AAGoogle404Handler->handle_it(); } endif; ?>