'adswidgetlight', 'description' => __('Display HTML selectively based on simple rules', 'adswidgetlight') ); $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'adswidgetlight'); $this->WP_Widget( 'adswidgetlight', __('Ads Widget', 'adswidgetlight'), $widget_ops, $control_ops ); } function is_fromsearchengine() { $ref = $_SERVER['HTTP_REFERER']; $SE = array('/search?', '.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.', '.bing.' ); foreach ($SE as $url) { if (strpos($ref,$url)!==false) return true; } return false; } function is_ie() { if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) return true; else return false; } function hit_selective($selectives = array()) { if(!empty($selectives)) { foreach($selectives as $key => $value) { switch($key) { case 'notloggedin': if(!is_user_logged_in()) { return true; } break; case 'isloggedin': if(is_user_logged_in()) { return true; } break; case 'notcommented': if ( !isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { return true; } break; case 'issearched': if($this->is_fromsearchengine()) { return true; } break; case 'isexternal': if(!empty($_SERVER['HTTP_REFERER'])) { $internal = str_replace('http://','',get_option('siteurl')); if(!preg_match( '/' . addcslashes($internal,"/") . '/i', $_SERVER['HTTP_REFERER'] )) { return true; } } break; case 'isie': if($this->is_ie()) { return true; } break; case 'notsupporter': if(function_exists('is_supporter') && !is_supporter()) { return true; } break; case 'none': break; default: if(has_filter('adswidget_process_rule_' . $key)) { if(apply_filters( 'adswidget_process_rule_' . $key, false )) { return true; } } } } return false; } else { return true; } } function widget( $args, $instance ) { extract( $args ); $options = array( 'notloggedin' => '0', 'isloggedin' => '0', 'notcommented' => '0', 'issearched' => '0', 'isexternal' => '0', 'isie' => '0', 'notsupporter' => '0' ); $options = apply_filters('adswidget_additional_checks', $options); foreach($options as $key => $value) { if(isset($instance[$key])) { $options[$key] = $instance[$key]; } else { unset($options[$key]); } } if($this->hit_selective($options) || empty($options)) { echo $before_widget; $title = apply_filters('widget_title', $instance['title'] ); if ( $title ) { echo $before_title . $title . $after_title; } if ( !empty( $instance['content'] ) ) { echo '