. */ class wpgb { function get_default_options() { return array( 'before_greet' => '
', 'after_greet' => '
', 'before_icon' => '
', 'after_icon' => '
', 'before_text' => '
', 'after_text' => '
', 'exclude_referrer' => 'friendfeed.com'.chr(10).'google.com/reader', 'can_close' => 1, 'regex_rules' => 0, 'show_post' => 1, 'show_page' => 0, 'position' => 'before', 'show_link' => 1, 'show_advanced_options' => 0, 'show_related' => 1, 'show_related_excerpt' => 1, 'related_limit' => 5, 'related_excerpt_len' => 20, 'rss_link' => get_bloginfo('rss_url'), 'message_default' => array( 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'rss_icon.png', 'timeout' => 14400, 'text' => 'Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.' ), 'message_noscript' => array( 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'rss_icon.png', 'text' => 'Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.' ), 'messages' => array( array( 'referrer' => 'del.icio.us, delicious.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'delicious_icon.png', 'timeout' => 0, 'text' => 'Hello fellow Delicious user! Feel free to bookmark this page for future reference if you like it!' ), array( 'referrer' => 'digg.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'digg_icon.png', 'timeout' => 0, 'text' => 'Hello fellow Digger! If you like this article, please help me out by giving me some digg love!' ), array( 'referrer' => 'google.*', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'google_icon.png', 'timeout' => 1440, 'text' => 'Welcome Googler! If you find this page useful, you might want to subscribe to the RSS feed for updates on this topic.' ), array( 'referrer' => 'stumbleupon.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'stumbleupon_icon.png', 'timeout' => 0, 'text' => 'Hello fellow Stumbler! Don\'t forget to give me a thumbs up and subscribe to the RSS feed if you like this page!' ), array( 'referrer' => 'technorati.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'technorati_icon.png', 'timeout' => 0, 'text' => 'Hello fellow Technorati user! Don\'t forget to favorite this blog if you like it!' ), array( 'referrer' => 'twitter.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'twitter_icon.png', 'timeout' => 0, 'text' => 'Hello fellow Twitter user! Don\'t forget to Twit this post if you like it, or follow me on Twitter if you find me interesting.' ), array( 'referrer' => 'search.yahoo.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'yahoo_icon.png', 'timeout' => 1440, 'text' => 'Welcome fellow Yahooligan! If you find this page useful, you might want to subscribe to the RSS feed for updates on this topic.' ), array( 'referrer' => 'search.live.com, search.msn.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'live_icon.png', 'timeout' => 1440, 'text' => 'Hello there Live-ly searcher! If you find this page useful, you might want to subscribe to the RSS feed for updates on this topic.' ), array( 'referrer' => 'blinklist.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'blinklist_icon.png', 'timeout' => 0, 'text' => 'Hello there fellow Blinklist user! Feel free to bookmark this page for future reference if you like it!' ), array( 'referrer' => 'blogmarks.net', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'blogmarks_icon.png', 'timeout' => 0, 'text' => 'Hello there Blogmarks user! Feel free to bookmark this page for future reference if you like it!' ), array( 'referrer' => 'diigo.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'diigo_icon.png', 'timeout' => 0, 'text' => 'Hello there Diigo user! Feel free to bookmark this page for future reference if you like it!' ), array( 'referrer' => 'facebook.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'facebook_icon.png', 'timeout' => 0, 'text' => 'Hello there Facebook friend! If you like this article, please help spread the word by sharing this post with your friends.' ), array( 'referrer' => 'furl.net', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'furl_icon.png', 'timeout' => 0, 'text' => 'Hello there Furl user! Please feel free to bookmark this page for future reference if you like it.' ), array( 'referrer' => 'ma.gnolia.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'magnolia_icon.png', 'timeout' => 0, 'text' => 'Hello there Magnolia user! Please feel free to bookmark this page for future reference if you like it.' ), array( 'referrer' => 'mister-wong.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'mrwong_icon.png', 'timeout' => 0, 'text' => 'Hello there Mister Wong user! Please feel free to bookmark this page for future reference if you like it.' ), array( 'referrer' => 'myspace.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'myspace_icon.png', 'timeout' => 0, 'text' => 'Hello there friend of MySpace! If you like this article, please help spread the word by sharing this post with your friends.' ), array( 'referrer' => 'newsvine.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'newsvine_icon.png', 'timeout' => 0, 'text' => 'Hello there Newsvine user! If you find this article useful, please remember to vote for this article on Newsvine.' ), array( 'referrer' => 'reddit.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'reddit_icon.png', 'timeout' => 0, 'text' => 'Hello there follow Reddit user! If you like this article, please remember to vote for this article on Reddit.' ), array( 'referrer' => 'simpy.com', 'disable' => 0, 'icon' => wpgb::get_plugin_url().'/images/'.'simpy_icon.png', 'timeout' => 0, 'text' => 'Hello there Simpy user! Please feel free to bookmark this page for future reference if you like it.' ), array( 'referrer' => 'example.com', 'disable' => 1, 'icon' => wpgb::get_plugin_url().'/images/'.'favorite_icon.png', 'timeout' => 0, 'text' => 'Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.' ), array( 'referrer' => 'netvibes.com', 'disable' => 1, 'icon' => wpgb::get_plugin_url().'/images/'.'netvibes_icon.png', 'timeout' => 0, 'text' => 'Hello there Netvibes user! If you find this article useful, then you should consider subscribing to the RSS feed in your feed reader.' ), array( 'referrer' => 'youtube.com', 'disable' => 1, 'icon' => wpgb::get_plugin_url().'/images/'.'youtube_icon.png', 'timeout' => 0, 'text' => 'Hello there YouTuber! If you like my videos, feel free to subscribe to my RSS feed for more of my video updates.' ), array( 'referrer' => 'flickr.com', 'disable' => 1, 'icon' => wpgb::get_plugin_url().'/images/'.'flickr_icon.png', 'timeout' => 0, 'text' => 'Hello there Flickr user! If you like my photo, you might want to subscribe to my RSS feed to receive regular photo updates.' ) ) ); } function activate() { global $wpdb; $wpdb->hide_errors(); $wpdb->query('ALTER TABLE '.$wpdb->posts.' ENGINE = MYISAM;'); $wpdb->query('ALTER TABLE '.$wpdb->posts.' ADD FULLTEXT '.wpgb::get_name().'_post_related (post_title, post_content);'); $wpdb->show_errors(); wpgb::upgrade_options(); } function load_admin_scripts() { echo( ''. '' ); // Generate admin_onload.js for security reasons. ?> '. '' ); } function load_styles() { $style= wpgb::get_plugin_url().'/css/wp-greet-box.css'; wp_register_style(wpgb::get_name().'_style', $style); wp_enqueue_style(wpgb::get_name().'_style'); } function queue_jquery() { wp_enqueue_script('jquery'); } function display_default_row($type, $wrap=true) { extract(get_option(wpgb::get_name())); if($type == "default"){ $m = $message_default; $type = 'default'; } else{ $m = $message_noscript; $type = 'noscript'; } if($m['disable']){ $a_action = 'activate'; $a_class = 'inactive'; $a_text= 'Activate'; } else{ $a_action = 'deactivate'; $a_class = 'active'; $a_text = 'Deactivate'; } if($wrap){ echo( '
'. '
' ); } echo( '
'.strtoupper($type).' 
'. '
WP Greet Box icon 
'. '
'.$m['text'].' 
'. '
'. '
loading...
'. 'Edit | '. ''.$a_text.''. '
'. '
' ); if($wrap){ echo( '
'. ''. '
'. '
' ); } } function display_message_row($id, $wrap=true) { extract(get_option(wpgb::get_name())); if($messages[$id]['disable']){ $a_action = 'activate'; $a_class = 'inactive'; $a_text= 'Activate'; } else{ $a_action = 'deactivate'; $a_class = 'active'; $a_text = 'Deactivate'; } if($wrap){ echo( '
'. '
' ); } echo( '
'.$messages[$id]['referrer'].' 
'. '
WP Greet Box icon 
'. '
'.$messages[$id]['text'].' 
'. '
'. '
loading...
'. 'Edit | '. 'Delete | '. ''.$a_text.''. '
'. '
' ); if($wrap){ echo( '
'. ''. '
'. '
' ); } } function admin_ajax_update_custom($id, $wpgb_message) { // convert "on" to 1 and "off" to 0 for checkbox fields // and set defaults for fields that are left blank if ( $wpgb_message['disable'] == 'off' ) $wpgb_message['disable'] = 0; elseif ( $wpgb_message['disable'] == 'on' ) $wpgb_message['disable'] = 1; if ( !$wpgb_message['timeout'] ) $wpgb_message['timeout'] = 0; // Update options $wpgb_options = get_option(wpgb::get_name()); $wpgb_options['messages'][$id] = $wpgb_message; update_option(wpgb::get_name(), $wpgb_options ); } function admin_ajax_update_default($type, $wpgb_message) { // convert "on" to 1 and "off" to 0 for checkbox fields // and set defaults for fields that are left blank if ( $wpgb_message['disable'] == 'off' ) $wpgb_message['disable'] = 0; elseif ( $wpgb_message['disable'] == 'on' ) $wpgb_message['disable'] = 1; if ( !$wpgb_message['timeout'] ) $wpgb_message['timeout'] = 0; // Update options $wpgb_options = get_option(wpgb::get_name()); $wpgb_options['message_'.$type] = $wpgb_message; update_option(wpgb::get_name(), $wpgb_options ); } function update_options_exclusion() { $wpgb_options_exclusion = stripslashes_deep($_POST['wpgb_options_exclusion']); // convert "on" to 1 and "off" to 0 for checkbox fields // and set defaults for fields that are left blank if ( isset($wpgb_options_exclusion['regex_rules']) ) $wpgb_options_exclusion['regex_rules'] = 1; else $wpgb_options_exclusion['regex_rules'] = 0; // Update options $wpgb_options = get_option(wpgb::get_name()); foreach($wpgb_options_exclusion as $key => $value) { $wpgb_options[$key] = $value; } update_option(wpgb::get_name(), $wpgb_options); } function update_options_general() { $wpgb_options_general = stripslashes_deep($_POST['wpgb_options_general']); // convert "on" to 1 and "off" to 0 for checkbox fields // and set defaults for fields that are left blank if ( isset($wpgb_options_general['show_page']) ) $wpgb_options_general['show_page'] = 1; else $wpgb_options_general['show_page'] = 0; if ( isset($wpgb_options_general['show_post']) ) $wpgb_options_general['show_post'] = 1; else $wpgb_options_general['show_post'] = 0; if ( isset($wpgb_options_general['regex_rules']) ) $wpgb_options_general['regex_rules'] = 1; else $wpgb_options_general['regex_rules'] = 0; if ( isset($wpgb_options_general['can_close']) ) $wpgb_options_general['can_close'] = 1; else $wpgb_options_general['can_close'] = 0; if ( isset($wpgb_options_general['show_link']) && $wpgb_options_general['show_link'] == 'off' ) $wpgb_options_general['show_link'] = 0; else $wpgb_options_general['show_link'] = 1; if ( isset($wpgb_options_general['show_related']) ) $wpgb_options_general['show_related'] = 1; else $wpgb_options_general['show_related'] = 0; if ( isset($wpgb_options_general['show_related_excerpt']) ) $wpgb_options_general['show_related_excerpt'] = 1; else $wpgb_options_general['show_related_excerpt'] = 0; if ( !isset($wpgb_options_general['related_limit']) || $wpgb_options_general['related_limit'] == '' || !is_numeric($wpgb_options_general['related_limit'])) $wpgb_options_general['related_limit'] = 5; if ( !isset($wpgb_options_general['related_excerpt_len']) || $wpgb_options_general['related_excerpt_len'] == '' || !is_numeric($wpgb_options_general['related_excerpt_len'])) $wpgb_options_general['related_excerpt_len'] = 20; // set defaults if some fields that are left blank if ( !$wpgb_options_general['rss_link'] ) $wpgb_options_general['rss_link'] = get_bloginfo('rss_url'); // Update options $wpgb_options = get_option(wpgb::get_name()); foreach($wpgb_options_general as $key => $value) { $wpgb_options[$key] = $value; } update_option(wpgb::get_name(), $wpgb_options); } function admin_ajax_add($wpgb_message) { // convert "on" to 1 and "off" to 0 for checkbox fields // and set defaults for fields that are left blank if ( $wpgb_message['disable'] == 'off' ) $wpgb_message['disable'] = 0; elseif ( $wpgb_message['disable'] == 'on' ) $wpgb_message['disable'] = 1; if ( !$wpgb_message['timeout'] ) $wpgb_message['timeout'] = 0; // Add to options $wpgb_options = get_option(wpgb::get_name()); $wpgb_options['messages'][] = $wpgb_message; update_option(wpgb::get_name(), $wpgb_options ); return sizeof($wpgb_options['messages']) - 1; } function admin_ajax_delete($id) { $wpgb_options = get_option(wpgb::get_name()); // delete item but can't reindex yet unset($wpgb_options['messages'][$id]); // Update options update_option(wpgb::get_name(), $wpgb_options ); return sizeof($wpgb_options['messages']) - 1; } function upgrade_options() { $wpgb_options = get_option(wpgb::get_name()); if ( !$wpgb_options ) { add_option(wpgb::get_name(), wpgb::get_default_options()); } else { $default_options = wpgb::get_default_options(); foreach($default_options as $option_name => $option_value) { if(!isset($wpgb_options[$option_name])) { $wpgb_options[$option_name] = $option_value; } } foreach($default_options['messages'] as $def_message) { $found = false; foreach($wpgb_options['messages'] as $message) { if($message['referrer'] == $def_message['referrer']) { $found = true; break; } } if(!$found) { $wpgb_options['messages'][] = $def_message; } } update_option(wpgb::get_name(), $wpgb_options); } } function reset_options() { if ( !get_option(wpgb::get_name()) ) { add_option(wpgb::get_name(), wpgb::get_default_options()); } else { update_option(wpgb::get_name(), wpgb::get_default_options()); } } function get_nonce() { return wp_create_nonce(wpgb::get_name()); } function get_name() { return 'wp_greet_box'; } function get_plugin_dir() { // Pre-2.6 compatibility if ( !defined('WP_CONTENT_DIR') ) define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); return WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__)); } function get_plugin_url() { // Pre-2.6 compatibility if ( !defined('WP_CONTENT_URL') ) define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); return WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)); } function get_current_page_url() { $isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on"); $port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443"))); $port = ($port) ? ':'.$_SERVER["SERVER_PORT"] : ''; $url = ($isHTTPS ? 'https://' : 'http://').$_SERVER["SERVER_NAME"].$port.$_SERVER["REQUEST_URI"]; return $url; } function get_icon_html($icon_file) { return 'WP Greet Box icon'; } function get_greet_html($icon_file, $text, $http_referrer='', $page_url='', $page_title='', $close=true) { extract(get_option(wpgb::get_name())); $greet_html = $before_greet.$before_text; if ( strlen ( $icon_file ) > 0 ) { // do not show icon if there is no icon url $greet_html .= $before_icon.wpgb::get_icon_html($icon_file).$after_icon; } if($close && $can_close) { $greet_html .= '
X
'; } $greet_html .= $text; if($show_related && wpgb::get_ref_info('isref', $http_referrer)) { $greet_html .= '
'; } if($show_link) { $greet_html .= '
Powered by WP Greet Box
'; } $greet_html .= $after_text.$after_greet; // use default title and URL if none is passed if($page_url == '') $permalink_r = wpgb::get_current_page_url(); else $permalink_r = $page_url; if($page_title == '') $title_r = wp_title('', false); else $title_r = $page_title; // replace tags $greet_html = str_replace('[[rss-link]]', $rss_link, $greet_html); $greet_html = str_replace('[[permalink]]', $permalink_r, $greet_html); $greet_html = str_replace('[[escaped-permalink]]', rawurlencode($permalink_r), $greet_html); $greet_html = str_replace('[[title]]', $title_r, $greet_html); $greet_html = str_replace('[[escaped-title]]', rawurlencode($title_r), $greet_html); return $greet_html; } function is_excluded($referrer) { extract(get_option(wpgb::get_name())); if(!isset($exclude_referrer) || !strlen($exclude_referrer)) { return false; } $rules = split(chr(10), $exclude_referrer); foreach( $rules as $rule ) { if($regex_rules) { $rule = str_replace('/', '\\/', $rule); if(preg_match('/'.$rule.'/', $referrer)) { return true; } } else { if(strlen($rule) > 0 && stristr($referrer, $rule)) { return true; } } } return false; } function find_greet_html($http_referrer, $visit_delta, $page_url, $page_title) { extract(get_option(wpgb::get_name())); $referrer_domain = wpgb::get_ref_domain($http_referrer, false); if(strlen(trim($referrer_domain)) > 0 && stristr(get_option('siteurl'), $referrer_domain)) { return ""; // if self referral } if(!wpgb::is_excluded($http_referrer)) { // if not one of the excluded URLs if(strlen(trim($referrer_domain)) > 0){ // if referrer is defined and is a regular URL foreach($messages as $message){ if(!$message['disable'] && strlen(trim($message['referrer'])) > 0 && strlen(trim($message['text'])) > 0){ // if message referrer & text is defined and message is enabled // prepare regex for matching $referrer_regex = str_replace(' ', '', $message['referrer']); $referrer_regex = str_replace('.', '\\.', $referrer_regex); $referrer_regex = str_replace('/', '\\/', $referrer_regex); $referrer_regex = str_replace(',', '|', $referrer_regex); $referrer_regex = str_replace('*', '.*', $referrer_regex); $referrer_regex = '/'.$referrer_regex.'/'; // compare regex if(preg_match($referrer_regex, $http_referrer)){ if($visit_delta < 0 || $visit_delta >= $message['timeout']){ return wpgb::get_greet_html($message['icon'], $message['text'], $http_referrer, $page_url, $page_title); } } } } } // if referrer not defined or no custom greeting messages match, display default if(!$message_default['disable'] && strlen(trim($message_default['text'])) > 0){ if($visit_delta < 0 || $visit_delta >= $message_default['timeout']){ return wpgb::get_greet_html($message_default['icon'], $message_default['text'], $http_referrer, $page_url, $page_title); } } } else{ // if it is an excluded referrer then return nothing return ""; } } function get_ref_delim($http_referrer) { $ref = wpgb::get_ref_domain($http_referrer); // Search engine match array // Used for fast delimiter lookup for single host search engines. // Non .com Google/MSN/Yahoo referrals are checked for after this array is checked $search_engines = array( 'google.fr' => 'q', 'google.com' => 'q', 'search.yahoo.com' => 'p', 'fr.search.yahoo.com' => 'p', 'search.msn.com' => 'q', 'search.live.com' => 'q', 'rechercher.aliceadsl.fr' => 'qs', 'vachercher.lycos.fr' => 'query', 'search.lycos.com' => 'query', 'alltheweb.com' => 'q', 'search.aol.com' => 'query', 'search.ke.voila.fr' => 'rdata', 'recherche.club-internet.fr' => 'q', 'ask.com' => 'q', 'hotbot.com' => 'query', 'overture.com' => 'Keywords', 'search.netscape.com' => 'query', 'search.looksmart.com' => 'qt', 'search.earthlink.net' => 'q', 'search.viewpoint.com' => 'k', 'mamma.com' => 'query' ); $delim = false; // Check to see if we have a host match in our lookup array if (isset($search_engines[$ref])) { $delim = $search_engines[$ref]; } else { // Lets check for referrals for international TLDs and sites with strange formats if (strpos($ref, 'google.') !== false && strpos($ref, 'reader') === false) $delim = 'q'; elseif (strpos($ref, 'search.msn.') !== false) $delim = 'q'; elseif (strpos($ref, '.search.yahoo.') !== false) $delim = 'q'; elseif (strpos($ref, 'exalead.') !== false) $delim = 'q'; elseif (strpos($ref, 'search.aol.') !== false) $delim = 'query'; elseif (strpos($ref, '.ask.com') !== false) $delim = 'q'; elseif (strpos($ref, 'recherche.aol.fr') !== false) $delim = (strpos($http_referrer, 'query')!==false)?'query':'q'; } return $delim; } function get_ref_terms($http_referrer) { $terms = null; $delimiter = wpgb::get_ref_delim($http_referrer); if($delimiter) { $query_array = array(); $query_terms = null; // Get raw query $query = explode($delimiter.'=', $http_referrer); $query = explode('&', $query[1]); $query = urldecode($query[0]); // Remove quotes, split into words, and format for HTML display $query = str_replace("'", '', $query); $query = str_replace('"', '', $query); $query_array = preg_split('/[\s,\+\.]+/',$query); $query_terms = implode(' ', $query_array); $terms = htmlspecialchars(urldecode($query_terms)); } return $terms; } function get_ref_domain($http_referrer, $strip_www=true) { // Break out quickly so we don't waste CPU cycles on non referrals if (!isset($http_referrer) || ($http_referrer == '')) return false; $referer_info = parse_url($http_referrer); $referer = $referer_info['host']; if($strip_www && substr($referer, 0, 4) == 'www.') { // Remove www. if necessary $referer = substr($referer, 4); } return $referer; } function get_ref_related($http_referrer, $limit=5, $before_title='', $after_title='', $before_post='', $after_post='', $show_pass_post=false, $show_excerpt=false, $excerpt_len=20) { global $wpdb, $id; // Is this a supported search engine? if (!wpgb::get_ref_domain($http_referrer)) return false; $terms = $wpdb->escape(wpgb::get_ref_terms($http_referrer)); if ($terms) { $time_difference = get_option('gmt_offset'); $now = gmdate("Y-m-d H:i:s", (time()+($time_difference*3600))); // Primary SQL query $sql = 'SELECT ID, post_title, post_content,' . "MATCH (post_title, post_content) AGAINST ('".$terms."') AS score " . 'FROM '.$wpdb->posts.' WHERE ' . "MATCH (post_title, post_content) AGAINST ('".$terms."') " . "AND post_date <= '".$now."' " . "AND (post_status IN ( 'publish', 'static' )) " . "AND post_type = 'post' "; if ($show_pass_post == false) { $sql .= "AND post_password = '' "; } $sql .= "ORDER BY score DESC LIMIT $limit"; $results = $wpdb->get_results($sql); $output = ''; if ($results) { foreach ($results as $result) { $title = stripslashes(apply_filters('the_title', $result->post_title)); $permalink = get_permalink($result->ID); $post_content = strip_tags($result->post_content); $post_content = stripslashes($post_content); $output .= $before_title . '' . $title . '' . $after_title; if ($show_excerpt) { $words=split(" ",$post_content); $post_strip = join(" ", array_slice($words,0,$excerpt_len)); $output .= $before_post . $post_strip . $after_post; } } return $output; } else { return $before_title.__('No related posts.').$after_title; } } } // Return true if the referer is a search engine function get_ref_info($what, $http_referrer) { // Is this a supported search engine? if (!wpgb::get_ref_domain($http_referrer)) return false; $terms = wpgb::get_ref_terms($http_referrer); if($terms) { if ($what == 'isref') { return ($terms != ''?true:false); } if ($what == 'terms') { return $terms; } } } function get_html() { $html .= '
'; extract(get_option(wpgb::get_name())); if(!$message_noscript['disable']) { $html .= ''; } $html .= '
'; return $html; } function display() { global $wpgb_shown; extract(get_option(wpgb::get_name())); if(is_feed() || ($show_page && is_page()) || ($show_post && is_single())){ return; } else{ $wpgb_shown = true; echo wpgb::get_html(); } } function filter_content($content) { global $wpgb_shown; extract(get_option(wpgb::get_name())); if((is_page() && $show_page) || (is_single() && $show_post)) { if($position == 'after') { $wpgb_shown = true; return $content . wpgb::get_html(); } else { $wpgb_shown = true; return wpgb::get_html() . $content; } } else { return $content; } } function admin_request_handler() { check_ajax_referer(wpgb::get_name()); if(isset($_POST['wpgb_action'])){ if(isset($_POST['wpgb_id'])){ if ( strtolower($_POST['wpgb_action']) == 'activate' ) { wpgb::admin_ajax_activate($_POST['wpgb_id']); } elseif ( strtolower($_POST['wpgb_action']) == 'deactivate' ) { wpgb::admin_ajax_deactivate($_POST['wpgb_id']); } elseif ( strtolower($_POST['wpgb_action']) == 'delete' ) { wpgb::admin_ajax_delete($_POST['wpgb_id']); } elseif ( strtolower($_POST['wpgb_action']) == 'get_add_form' ) { wpgb::admin_ajax_get_add_form($_POST['wpgb_id']); } elseif ( strtolower($_POST['wpgb_action']) == 'get_edit_form' ) { if(is_numeric($_POST['wpgb_id'])){ wpgb::admin_ajax_get_edit_form($_POST['wpgb_id']); } else{ wpgb::admin_ajax_get_edit_form_default($_POST['wpgb_id']); } } elseif ( strtolower($_POST['wpgb_action']) == 'update' ) { if(is_numeric($_POST['wpgb_id'])){ wpgb::admin_ajax_update_custom($_POST['wpgb_id'], stripslashes_deep($_POST['wpgb_message'])); wpgb::display_message_row($_POST['wpgb_id'], false); } else{ wpgb::admin_ajax_update_default($_POST['wpgb_id'], stripslashes_deep($_POST['wpgb_message'])); wpgb::display_default_row($_POST['wpgb_id'], false); } } else { echo 'Invalid wpgb_action.'; } } else{ if ( strtolower($_POST['wpgb_action']) == 'add' ) { $id = wpgb::admin_ajax_add(stripslashes_deep($_POST['wpgb_message'])); wpgb::display_message_row($id, true); } elseif ( strtolower($_POST['wpgb_action']) == 'show_advanced_options' ) { wpgb::admin_ajax_enable_advanced_options(true); } elseif ( strtolower($_POST['wpgb_action']) == 'hide_advanced_options' ) { wpgb::admin_ajax_enable_advanced_options(false); } else { echo 'Invalid wpgb_action.'; } } exit(); } } function set_header() { if (wpgb::get_ref_info('isref', $_SCRIPT['HTTP_REFERER'])) header('Vary: Referer', false); } function public_request_handler() { if(isset($_GET['wpgb_public_action'])){ if ( strtolower($_GET['wpgb_public_action']) == 'query' ) { echo wpgb::find_greet_html(urldecode($_GET['referrer']),$_GET['visit_delta'],urldecode($_GET['url']),urldecode($_GET['title'])); } exit; } } function admin_ajax_activate($id) { $wpgb_options = get_option(wpgb::get_name()); if($id == 'default'){ $wpgb_options['message_default']['disable'] = 0; } elseif($id == 'noscript'){ $wpgb_options['message_noscript']['disable'] = 0; } else{ $wpgb_options['messages'][$id]['disable'] = 0; } update_option(wpgb::get_name(), $wpgb_options ); } function admin_ajax_deactivate($id) { $wpgb_options = get_option(wpgb::get_name()); if($id == 'default'){ $wpgb_options['message_default']['disable'] = 1; } elseif($id == 'noscript'){ $wpgb_options['message_noscript']['disable'] = 1; } else{ $wpgb_options['messages'][$id]['disable'] = 1; } update_option(wpgb::get_name(), $wpgb_options ); } function admin_ajax_get_add_form($status) { extract(get_option(wpgb::get_name())); if($status == 'active'){ $disable = 'off'; } else{ $disable = 'on'; } echo( '
'. '
'. '
'. 'Referrer URL:
'. '

'. 'Visitor Timeout (minutes):
'. '

'. 'Greeting Icon (optional):'. '

'. 'Greeting message:'. '

'. ''. '

'. ''. ''. '

'. ''. '
'. '
'. '
' ); } function admin_ajax_get_edit_form($id) { extract(get_option(wpgb::get_name())); if ( $messages[$id]['disable'] ) $checkmark = 'checked'; else $checkmark = ''; echo( '
'. 'Referrer URL:
'. '

'. 'Visitor Timeout (minutes):
'. '

'. 'Greeting Icon (optional):'. '

'. 'Greeting message:'. '

'. '

'. ''. ''. '

'. ''. ''. '
' ); } function admin_ajax_get_edit_form_default($type) { extract(get_option(wpgb::get_name())); if($type == "default"){ $m = $message_default; $type = 'default'; $visitor_timeout = 'Visitor Timeout (minutes):


'; } else{ $m = $message_noscript; $type = 'noscript'; $visitor_timeout = ''; } if ( $m['disable'] ) $checkmark = 'checked'; else $checkmark = ''; echo( '
'. $visitor_timeout. 'Greeting Icon (optional):'. '

'. 'Greeting message:'. '

'. '

'. ''. ''. '

'. ''. ''. '
' ); } function admin_ajax_enable_advanced_options($enable) { $wpgb_options = get_option(wpgb::get_name()); if($enable == true){ $wpgb_options['show_advanced_options'] = 1; } else{ $wpgb_options['show_advanced_options'] = 0; } update_option(wpgb::get_name(), $wpgb_options ); } function admin_menu() { $options_page = add_options_page('WP Greet Box', 'WP Greet Box', 'manage_options', 'wp-greet-box', array('wpgb', 'admin_page')); add_action('admin_head-'.$options_page, array('wpgb', 'load_admin_scripts')); } function admin_page() { if ( isset($_POST['wpgb_options_general_submit']) ) { check_admin_referer('wpgb'); wpgb::update_options_general(); echo '

WP Greet Box options updated.

'; } elseif ( isset($_POST['wpgb_options_exclusion_submit']) ) { check_admin_referer('wpgb'); wpgb::update_options_exclusion(); echo '

WP Greet Box options updated.

'; } elseif ( isset($_POST['wpgb_options_upgrade']) ) { check_admin_referer('wpgb'); wpgb::upgrade_options(); echo '

WP Greet Box options has been upgraded.

'; } elseif ( isset($_POST['wpgb_options_reset']) ) { // if user wants to reset all options check_admin_referer('wpgb'); wpgb::reset_options(); echo '

WP Greet Box options has been reset.

'; } $wpgb_options = get_option(wpgb::get_name()); // reindex here when we get the chance to reload page $wpgb_options['messages'] = array_values($wpgb_options['messages']); // Update options update_option(wpgb::get_name(), $wpgb_options ); extract(get_option(wpgb::get_name())); ?>

WP Greet Box Options

Greeting Messages |  Exclusion Rules |  General Configurations |  Documentation