Options configuration panel Version: 3.0 Author: AskApache Author URI: http://www.askapache.com */ /* == Installation == 1. Upload aa-google-404.zip to the /wp-content/plugins/ directory 2. Unzip into its own folder /wp-content/plugins/aa-google-404/aa-google-404.php 3. Activate the plugin through the 'Plugins' menu in WordPress by clicking "AskApache Google 404" 4. Go to your Options Panel and open the "AskApache Google 404" submenu. /wp-admin/options-general.php?page=aa-google-404.php 5. Enter in your google Ajax API Key and hit "Update" Button. 6. Add the code to your 404.php template page by including in your main content area. */ /* /--------------------------------------------------------------------\ | | | License: GPL | | | | AskApache Google 404 Plugin - Adds Ajax Powered Search to 404 Page | | Copyright (C) 2007, AskApache, www.askapache.com | | All rights reserved. | | | | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | 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. See the | | GNU General Public License for more details. | | | | You should have received a copy of the GNU General Public License | | along with this program; if not, write to the | | Free Software Foundation, Inc. | | 51 Franklin Street, Fifth Floor | | Boston, MA 02110-1301, USA | | | \--------------------------------------------------------------------/ */ $aa_num_keywords_allowed=6; $aa_disallowed_words=array('about','after','ago','all','almost','along','alot','also','and','answer','any','anybody','anybodys','anywhere','are','arent','around','askd','because','been','before','being','best','better','between','big','btw','but','can','come','could','couldnt','did','didnt','does','doesnt','dont','etc','either','ever','everybody','everybodys','everyone','far','for','found','game','going','good','got','gotten','had','has','have','havent','having','her','here','hers','him','his','how','hows','ive','isnt','its','just','know','large','less','like','liked','little','looking','look','looked','looking','lot','maybe','many','more','most','much','must','mustnt','near','need','never','new','news','none','not','nothing','now','off','often','old','once','only','oops','other','our','ours','out','over','please','put','question','questions','questioned','quote','rather','really','recent','said','saw','say','says','she','see','sees','should','small','some','something','sometime','somewhere','soon','take','than','thank','that','thatd','thats','the','their','theirs','theres','theirs','them','then','there','these','they','theyll','theyd','theyre','this','those','though','through','thus','too','under','until','untrue','upon','very','via','want','was','way','well','went','were','werent','what','when','where','which','whom','whose','why','wide','will','with','within','without','wont','world','worse','worst','would','wrote','yes','yet','you','youd','youll','your','youre','yours'); // aa_google_404_options_setup //--------------------------- function aa_google_404_options_setup() { global $aa_G404; add_options_page($aa_G404['Name'], 'AA Google 404', 8, basename(__FILE__), 'aa_google_404_page'); }//===================================================================================== // aa_google_404 //--------------------------- function aa_google_404(){ if(is_404()){ $aa_google_404_code_html = get_option('aa_google_404_code_html'); echo $aa_google_404_code_html; } }//===================================================================================== // aa_google_404_page //--------------------------- function aa_google_404_page() { global $aa_G404,$aa_google_404_api_key,$aa_google_404_code_js,$aa_google_404_code_css,$aa_google_404_code_html,$aa_status; if ( function_exists('current_user_can') && !current_user_can('manage_options') ) die(__('Cheatin’ uh?')); if (! user_can_access_admin_page()) wp_die( __('You do not have sufficient permissions to access this page.') ); $aa_template_404=TEMPLATEPATH.'/404.php'; $aa_google_404_template_404=dirname(__FILE__).'/404.php'; if(!file_exists($aa_template_404)){ if (!copy($aa_google_404_template_404,$aa_template_404))$aa_status.='

ERROR:404.php file not found.. attempting to create.. FAILED!

'; else $aa_status=$aa_status.='

Message:404.php file not found.. attempting to create.. SUCCESS!

'; } $aa_head='

[ 404 Error Page tip for Google Analytics - Home: '.$aa_G404['Title'].' - Version: '.$aa_G404['Version'].' - Author: '.$aa_G404['Author'].' ]


'; $aa_test='
'.$aa_google_404_code_html.'
'; $aa_main ='

'.$aa_G404['Name'].'

Test Your 404 Page'; _e($aa_head); _e($aa_status); _e($aa_test); _e($aa_main); aa_print_google_404_form(); aa_print_google_links(); }//===================================================================================== // aa_google_404_admin_header //--------------------------- function aa_google_404_admin_header(){ global $aa_G404,$aa_google_404_api_key,$aa_google_404_code_js,$aa_google_404_code_css,$aa_google_404_code_html,$aa_status; $aa_G404=get_plugin_data(__FILE__); if($_SERVER['REQUEST_METHOD']==='POST'){ $valid_nonce = wp_verify_nonce($_REQUEST['_wpnonce'], 'aa-google-404-update_modify'); if(isset($_POST['aagooglecodejs'])) update_option('aa_google_404_code_js',stripslashes($_POST['aagooglecodejs'])); if(isset($_POST['aagooglecodehtml'])) update_option('aa_google_404_code_html',stripslashes($_POST['aagooglecodehtml'])); if(isset($_POST['aagooglecodecss'])) update_option('aa_google_404_code_css',stripslashes($_POST['aagooglecodecss'])); if(isset($_POST['aagoogleapikey'])) update_option('aa_google_404_api_key',$_POST['aagoogleapikey']); $aa_google_404_code_html = get_option('aa_google_404_code_html'); $aa_google_404_code_js = get_option('aa_google_404_code_js'); $aa_google_404_code_css = get_option('aa_google_404_code_css'); $aa_google_404_api_key = get_option('aa_google_404_api_key'); $aa_status = '

Successfully Updated Code.

'; if(isset($_POST['aaresetgooglecode'])) { aa_google_404_activate(); $aa_status = '

Successfully Reset Plugin Options.

'; } } if(strpos($aa_google_404_api_key, 'askapache')!==false){ $aa_status = '

Warning: You need to get a free Google API Key before this plugin will fully work.

'; } $aa_google_404_code_html = get_option('aa_google_404_code_html'); $aa_google_404_code_js = get_option('aa_google_404_code_js'); $aa_google_404_code_css = get_option('aa_google_404_code_css'); $aa_google_404_api_key = get_option('aa_google_404_api_key'); $aa_label='+askapache'; $aa_execute=aa_get_keywords('|'); $aa_mysite=str_replace('www.','',$_SERVER['HTTP_HOST']); echo "\n\n".''."\n"; echo ''; echo "\n".''."\n"; echo $aa_google_404_code_js; echo $aa_google_404_code_css; echo "\n".''."\n\n"; }//===================================================================================== // aa_google_404_header //--------------------------- function aa_google_404_header(){ global $aa_google_404_api_key,$aa_google_404_code_js,$aa_google_404_code_css,$aa_google_404_code_html; if(is_404()) { $aa_google_404_code_html = get_option('aa_google_404_code_html'); $aa_google_404_code_js = get_option('aa_google_404_code_js'); $aa_google_404_code_css = get_option('aa_google_404_code_css'); $aa_google_404_api_key = get_option('aa_google_404_api_key'); $aa_google_404_api_key=str_replace('-askapache','',$aa_google_404_api_key); $aa_label=get_option('blogname'); $aa_execute=aa_get_keywords('|'); $aa_mysite=str_replace('www.','',$_SERVER['HTTP_HOST']); echo "\n\n".''."\n"; echo ''; echo "\n".''."\n"; echo $aa_google_404_code_js; echo $aa_google_404_code_css; echo "\n".''."\n\n"; } }//===================================================================================== // aa_print_google_404_form //--------------------------- function aa_print_google_404_form(){ global $aa_google_404_api_key,$aa_google_404_code_js,$aa_google_404_code_css,$aa_google_404_code_html; echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo '

'; wp_nonce_field('aa-google-404-update_modify'); echo '
'; }//===================================================================================== // aa_print_google_links //--------------------------- function aa_print_google_links(){ // Thanks Google, you Rock from the Start! echo '

More Info from Google



'; }//===================================================================================== // aa_get_keywords //--------------------------- function aa_get_keywords($sep){ global $aa_num_keywords_allowed,$aa_disallowed_words; $aa_matched_keywords=array(); $url=strtolower(html_entity_decode(strip_tags($_SERVER['REQUEST_URI']))); $t=preg_match_all("/[\w]{3,15}/", $url, $aa_matched_keywords); foreach ($aa_matched_keywords[0] as $key => $aa_word){ if(!in_array($aa_word,$aa_disallowed_words))$aa_computed_searchwords[]=$aa_word; } $aa_computed_searchwords = array_unique($aa_computed_searchwords); if(sizeof($aa_computed_searchwords)>$aa_num_keywords_allowed) array_splice($aa_computed_searchwords, $aa_num_keywords_allowed+1); $aa_computed_searchwords = implode($sep, $aa_computed_searchwords); return trim($aa_computed_searchwords); }//===================================================================================== // aa_google_404_deactivate //--------------------------- function aa_google_404_deactivate(){ delete_option('aa_google_404_url'); delete_option('aa_google_404_code_html'); delete_option('aa_google_404_code_js'); delete_option('aa_google_404_code_css'); delete_option('aa_google_404_api_key'); }//===================================================================================== // aa_google_404_activate //--------------------------- function aa_google_404_activate(){ global $aa_G404; $aa_G404=get_plugin_data(__FILE__); $aa_google_404_url = get_option('siteurl').'/wp-content/plugins/'.basename(__FILE__,'.php'); //. . trailingslashit(substr($path,strpos($path,"wp-content/"))); $aa_google_404_api_key='ABQIAAAAulvh3KQawKQWxn64grPVShSrXMCP0pDj9HHVk8NG53Pp2_-7KxQrSRl65MAnUMDqm9AubaFv5BYXEg-askapache'; $aa_google_404_code_html='
'."\n".'Wait a sec, I might be able to help...'."\n".'
'."\n".'
'."\n"; $aa_google_404_code_css= "\n".''."\n"; $aa_google_404_code_js= ''; update_option('aa_google_404_url',$aa_google_404_url); update_option('aa_google_404_api_key',$aa_google_404_api_key); update_option('aa_google_404_code_html',stripslashes($aa_google_404_code_html)); update_option('aa_google_404_code_js',stripslashes($aa_google_404_code_js)); update_option('aa_google_404_code_css',stripslashes($aa_google_404_code_css)); }//===================================================================================== add_action('admin_menu', 'aa_google_404_options_setup'); if(false!==($aa_goadm=strpos($_SERVER['REQUEST_URI'], basename(__FILE__))))add_action('admin_head', 'aa_google_404_admin_header'); add_action('wp_head', 'aa_google_404_header'); register_deactivation_hook(__FILE__, 'aa_google_404_deactivate'); register_activation_hook(__FILE__, 'aa_google_404_activate'); ?>