0 AND $block < 1) { $select_banner = " AND `id` = '$banner_id'"; } else { $select_banner = ""; } if($preview == false) { $active_banner = " AND `active` = 'yes' AND '$now' >= `startshow` AND '$now' <= `endshow`"; } $rawbanners = $wpdb->get_results("SELECT `id`, `tracker`, `clicks`, `maxclicks`, `shown`, `maxshown` FROM `".$wpdb->prefix."adrotate` WHERE `group` = '$group_ids[$x]' ".$select_banner.$active_banner); if($rawbanners) { foreach($rawbanners as $raw) { $selected[] = $raw->id; if($raw->clicks >= $raw->maxclicks AND $raw->maxclicks > 0 AND $raw->tracker == "Y") { $selected = array_diff($selected, array($raw->id)); } if($raw->shown >= $raw->maxshown AND $raw->maxshown > 0 AND in_array($raw->id, $selected)) { $selected = array_diff($selected, array($raw->id)); } } if($block > 0 AND $banner_id < 1) { shuffle($selected); $chosen = $selected; $limit = $block; } else if($banner_id > 0) { $chosen = array($banner_id); $limit = 1; } else { $y = array_rand($selected, 1); $chosen = array($selected[$y]); $limit = count($chosen); } if(count($selected) > 0) { $output = ''; for($i=0;$i<$limit;$i++) { $banner = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."adrotate` WHERE `id` = '".$chosen[$i]."'"); $banner_output = $banner->bannercode; if($banner->tracker == "Y") { $banner_output = str_replace('%link%', get_option('siteurl').'/wp-content/plugins/adrotate/adrotate-out.php?trackerid='.$banner->id, $banner_output); } else { $banner_output = str_replace('%link%', $banner->link, $banner_output); } $banner_output = str_replace('%image%', get_option('siteurl').'/wp-content/banners/'.$banner->image, $banner_output); $output .= $banner_output; if($preview == false) { $wpdb->query("UPDATE `".$wpdb->prefix."adrotate` SET `shown` = `shown` + 1 WHERE `id` = '$banner->id'"); } } } else { $output = ''; } } else { $output = ''; } } else { $output = 'Error, no group_id specified! Check your syntax or contact an administrator!'; } $output = stripslashes(html_entity_decode($output, ENT_QUOTES)); return $output; } /*------------------------------------------------------------- Name: adrotate_shortcode Purpose: Show a banner as requested in a post or page using shortcodes Receive: $atts, $content Return: adrotate_banner() -------------------------------------------------------------*/ function adrotate_shortcode($atts, $content = null) { if(!empty($atts['group'])) $group_ids = $atts['group']; else $group_ids = ''; if(!empty($atts['block'])) $block = $atts['block']; else $block = 0; if(!empty($atts['banner'])) $banner_id = $atts['banner']; else $banner_id = 0; return adrotate_banner($group_ids, $banner_id, $block, false); } /*------------------------------------------------------------- Name: adrotate_clean_trackerdata Purpose: Removes old trackerdata Receive: -none- Return: -none- -------------------------------------------------------------*/ function adrotate_clean_trackerdata() { global $wpdb; if(empty($_SERVER["HTTP_X_FORWARDED_FOR"])) { $remote_ip = $_SERVER["REMOTE_ADDR"]; } else { $remote_ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } $buffer = explode(',', $remote_ip, 2); $removeme = current_time('timestamp') - 86400; $wpdb->query("DELETE FROM `".$wpdb->prefix."adrotate_tracker` WHERE `timer` < ".$removeme." AND `ipaddress` = '$buffer[0]'"); } /*------------------------------------------------------------- Name: adrotate_expired_banners Purpose: Notify user of expired banners Receive: -none- Return: -none- -------------------------------------------------------------*/ function adrotate_expired_banners() { global $wpdb; $now = current_time('timestamp'); $count = $wpdb->get_var("SELECT COUNT(*) FROM `".$wpdb->prefix."adrotate` WHERE `active` = 'yes' AND `endshow` <= $now"); if($count > 0) { if($count == 1) $tell = '1 banner is'; else $tell = $count.' banners are'; echo '

'.$tell.' expired. Take action!

'; } } /*------------------------------------------------------------- Name: adrotate_credits Purpose: Credits Receive: -none- Return: -none- -------------------------------------------------------------*/ function adrotate_credits() { echo ''; echo ''; echo ''; echo ' '; echo ''; echo ''; echo ''; echo ''; echo ' '; echo ''; echo ''; echo 'I'm using AdRotate\n"; } } /*------------------------------------------------------------- Name: adrotate_check_config Purpose: Create or update the options Receive: -none- Return: -none- -------------------------------------------------------------*/ function adrotate_check_config() { if ( !$config = get_option('adrotate_config') ) { $config['credits'] = 'Y'; update_option('adrotate_config', $config); } } /*------------------------------------------------------------- Name: adrotate_options_submit Purpose: Save options from dashboard Receive: $_POST Return: -none- -------------------------------------------------------------*/ function adrotate_options_submit() { // Prepare Tracker settings if(isset($_POST['adrotate_credits'])) $config['credits'] = 'Y'; else $config['credits'] = 'N'; update_option('adrotate_config', $config); } /*------------------------------------------------------------- Name: adrotate_folder_contents Purpose: List folder contents Receive: $current Return: $output -------------------------------------------------------------*/ function adrotate_folder_contents($current) { global $wpdb; if ($handle = opendir(ABSPATH.'/wp-content/banners/')) { $output = ''; while (false !== ($file = readdir($handle))) { $fileinfo = pathinfo($file); if ($file != "." && $file != ".." AND (strtolower($fileinfo['extension']) == "jpg" OR strtolower($fileinfo['extension']) == "gif" OR strtolower($fileinfo['extension']) == "png" OR strtolower($fileinfo['extension']) == "jpeg" OR strtolower($fileinfo['extension']) == "swf" OR strtolower($fileinfo['extension']) == "flv")) { $output .= "
AdRotate for Awesome!
Find me on meandmymac.net.
'; echo ' The plugin homepage is at http://meandmymac.net/plugins/adrotate/.
'; echo ' Read about updates! http://meandmymac.net/tag/adrotate/.
'; echo ' Need help? forum.at.meandmymac.net.
'; echo ' Like my software? Did i help you? Show your appreciation. Thanks!