prefix."ad_buttons"; $structure = "CREATE TABLE $table ( id INT(9) NOT NULL AUTO_INCREMENT, ad_picture VARCHAR(100) NOT NULL, ad_link VARCHAR(80) NOT NULL, ad_text VARCHAR(80) NOT NULL, ad_views INT(9) DEFAULT 0, ad_clicks INT(9) DEFAULT 0, ad_active TINYINT(1) NOT NULL DEFAULT 0, UNIQUE KEY id (id) );"; $wpdb->query($structure); $wpdb->query("INSERT INTO $table(id, ad_picture, ad_link, ad_text, ad_views, ad_clicks, ad_active) VALUES(1, 'http://www.phpinclude.net/images/wordpress125.gif', 'http://wordpress.org/', 'Powered by WordPress', 1, 0, 1)"); } add_action('activate_ad buttons/adbuttons.php', 'ad_buttons_install'); //check if user is a bot of some sort function is_bot() { $bots = array('google','yahoo','msn','jeeves','lycos','ArchitectSpider','whatuseek','BSDSeek','BullsEye'); //takes the list above and returns (google)|(yahoo)|(msn)... $regex = '('.implode($bots, ')|(').')'; //uses the generated regex above to see if those keywords are contained in the user agent variable return eregi($regex, $_SERVER['HTTP_USER_AGENT']); } function ad_buttons() { global $wpdb; $widget_adbuttons_cfg = array( 'ab_dspcnt' => '' ); $widget_adbuttons_cfg = get_option('widget_adbuttons_cfg'); $wp_root = get_option('home'); $ab_count = 0; $results = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."ad_buttons WHERE ad_active = 1 ORDER BY RAND()"); foreach($results as $result){ if ($ab_count < $widget_adbuttons_cfg['ab_dspcnt']) { echo"id\" target=\"_blank\" title=\"$result->ad_text\">ad_picture\" alt=\"$result->ad_text\" vspace=\"1\" hspace=\"1\" border=\"0\">"; $ab_count = $ab_count + 1; // update view counter on the ad button if(!is_bot()) { $wpdb->query("UPDATE ".$wpdb->prefix."ad_buttons SET ad_views = ad_views + 1 WHERE id = ".$result->id); } } } } // add rewrite rules to support click tracking function ad_click_rewrite() { global $wp_rewrite; // add rewrite tokens $recon = '%reconments%'; $wp_rewrite->add_rewrite_tag($recon, '([A-Za-z0-9_]*)', 'reconments='); $keywords_structure = $wp_rewrite->root . "reconments/$recon/"; $keywords_rewrite = $wp_rewrite->generate_rewrite_rules($keywords_structure); $wp_rewrite->rules = $keywords_rewrite + $wp_rewrite->rules; return $wp_rewrite->rules; } add_action('generate_rewrite_rules', 'createRewriteRules'); function ad_buttons_menu() { global $wpdb; include 'adbuttonsadmin.php'; } function ad_buttons_admin_actions() { add_options_page("Ad Buttons", "Ad Buttons", 1, "ad-buttons", "ad_buttons_menu"); } add_action('admin_menu', 'ad_buttons_admin_actions'); function ad_buttons_stats() { global $wpdb; include 'adbuttonsstats.php'; } function ad_buttons_top() { global $wpdb; include 'adbuttonstop.php'; } function ad_buttons_act() { global $wpdb; include 'adbuttonsact.php'; } function ad_buttons_stats_actions() { add_menu_page('Ad Buttons', 'Ad Buttons', 9, __FILE__, 'ad_buttons_top'); // Add a submenu to the custom top-level menu: add_submenu_page(__FILE__, 'Active Ad Buttons', 'Active Ad Buttons', 9, 'ad-buttons-act', 'ad_buttons_act'); } add_action('admin_menu', 'ad_buttons_stats_actions'); function widget_ad_buttons($args) { extract($args); // Collect our widget's options, or define their defaults. $options['title'] = 'Sponsored Links'; update_option('widget_adbuttons', $options); $options = get_option('widget_adbuttons'); $title = empty($options['title']) ? 'My Widget' : $options['title']; echo $before_widget; echo $before_title . $title . $after_title; ad_buttons(); echo $after_widget; } // This is the function that outputs the form to let users edit // the widget's title and so on. It's an optional feature, but // we'll use it because we can! function widget_ad_buttons_control() { // Collect our widget's options. $options = get_option('widget_adbuttons'); // This is for handing the control form submission. if ( $_POST['adbuttons-submit'] ) { // Clean up control form submission options $newoptions['title'] = strip_tags(stripslashes($_POST['adbuttons-title'])); } // If original widget options do not match control form // submission options, update them. if ( $options != $newoptions ) { $options = $newoptions; update_option('widget_adbuttons', $options); } // Format options as valid HTML. Hey, why not. $title = htmlspecialchars($options['title'], ENT_QUOTES); // The HTML below is the control form for editing options. ?>
get_results("SELECT ad_link FROM ".$wpdb->prefix."ad_buttons WHERE id = $ad_id "); foreach($results as $result){ $send_to_url = $result->ad_link; if(!is_bot()) { $wpdb->query("UPDATE ".$wpdb->prefix."ad_buttons SET ad_clicks = ad_clicks + 1 WHERE id = ".$ad_id); } //redirect header("Location: ".$send_to_url); } } } } add_action("init", "adbuttons_getclick"); ?>