get_row($wpdb->prepare("SELECT `id`, `bannercode`, `tracker`, `link`, `image`, `responsive` FROM `{$wpdb->prefix}adrotate` WHERE `id` = %d AND (`type` = 'active' OR `type` = '2days' OR `type` = '7days');", $banner_id)); if($banner) { if($adrotate_debug['general'] == true) { echo "
[DEBUG][adrotate_ad()] Selected Ad ID
"; print_r($banner->id); echo ""; } $selected = array($banner->id => 0); $selected = adrotate_filter_schedule($selected, $banner); } else { $selected = false; } if($selected) { $nowrapper = ($nowrapper == 1) ? true : false; $image = str_replace('%folder%', $adrotate_config['banner_folder'], $banner->image); if($individual == true AND $nowrapper == false) $output .= ''; if($adrotate_config['stats'] == 1 AND $banner->tracker == "Y") { adrotate_count_impression($banner->id, 0, 0); } } else { $output .= adrotate_error('ad_expired', array($banner_id)); } unset($banner); } else { $output .= adrotate_error('ad_no_id'); } return $output; } /*------------------------------------------------------------- Name: adrotate_group Purpose: Fetch ads in specified group(s) and show a random ad Receive: $group_ids, $fallback, $weight, $site, $nowrapper Return: $output Since: 3.0 -------------------------------------------------------------*/ function adrotate_group($group_ids, $fallback = 0, $weight = 0, $site = 0, $nowrapper = 1) { global $wpdb, $adrotate_config, $adrotate_debug; $output = $group_select = ''; if($group_ids) { $now = adrotate_now(); $group_array = (!is_array($group_ids)) ? explode(",", $group_ids) : $group_ids; foreach($group_array as $key => $value) { $group_select .= " `{$wpdb->prefix}adrotate_linkmeta`.`group` = {$value} OR"; } $group_select = rtrim($group_select, " OR"); $group = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}adrotate_groups` WHERE `name` != '' AND `id` = %d;", $group_array[0])); if($adrotate_debug['general'] == true) { echo "
[DEBUG][adrotate_group] Selected group
"; print_r($group); echo ""; } if($group) { // Get all ads in all selected groups $ads = $wpdb->get_results( "SELECT `{$wpdb->prefix}adrotate`.`id`, `{$wpdb->prefix}adrotate`.`bannercode`, `{$wpdb->prefix}adrotate`.`link`, `{$wpdb->prefix}adrotate`.`image`, `{$wpdb->prefix}adrotate`.`responsive`, `{$wpdb->prefix}adrotate`.`tracker`, `{$wpdb->prefix}adrotate_linkmeta`.`group` FROM `{$wpdb->prefix}adrotate`, `{$wpdb->prefix}adrotate_linkmeta` WHERE ({$group_select}) AND `{$wpdb->prefix}adrotate_linkmeta`.`user` = 0 AND `{$wpdb->prefix}adrotate`.`id` = `{$wpdb->prefix}adrotate_linkmeta`.`ad` AND (`{$wpdb->prefix}adrotate`.`type` = 'active' OR `{$wpdb->prefix}adrotate`.`type` = '2days' OR `{$wpdb->prefix}adrotate`.`type` = '7days') GROUP BY `{$wpdb->prefix}adrotate`.`id` ORDER BY `{$wpdb->prefix}adrotate`.`id`;"); if($ads) { if($adrotate_debug['general'] == true) { echo "
[DEBUG][adrotate_group()] All ads in group
"; print_r($ads); echo ""; } foreach($ads as $ad) { $selected[$ad->id] = $ad; $selected = adrotate_filter_schedule($selected, $ad); } unset($ads); if($adrotate_debug['general'] == true) { echo "
[DEBUG][adrotate_group] Reduced array based on schedule restrictions
"; print_r($selected); echo ""; } $array_count = count($selected); if($array_count > 0) { $before = $after = ''; $nowrapper = ($nowrapper == 1) ? true : false; $before = str_replace('%id%', $group_array[0], stripslashes(html_entity_decode($group->wrapper_before, ENT_QUOTES))); $after = str_replace('%id%', $group_array[0], stripslashes(html_entity_decode($group->wrapper_after, ENT_QUOTES))); if($nowrapper == false AND $group->modus < 1) $output .= '
[DEBUG][adrotate_inject_posts()] group_array
"; print_r($group_array); echo ""; } unset($ids, $pages); $group_count = count($group_array); if($group_count > 0) { if($group_count > 1) { // Try to prevent the same ad from showing when there are multiple ads to show $paragraph_count = substr_count($post_content, '
'); if($paragraph_count == 0 OR $group_count < $paragraph_count) { $paragraph_count = $group_count; } $group_choice = array_rand($group_array, $paragraph_count); if(!is_array($group_choice)) $group_choice = array($group_choice); shuffle($group_choice); } else { $group_choice = array_rand($group_array, 1); $group_choice = array($group_choice,$group_choice); } if($adrotate_debug['general'] == true) { echo "
[DEBUG][adrotate_inject_posts()] Choices
"; echo "Group count: ".$group_count.""; print_r($group_choice); echo ""; } $before = $after = 0; foreach($group_choice as $key => $group_id) { if(is_page($group_array[$group_id]['pages'])) { // Advert in front of content if(($group_array[$group_id]['location'] == 1 OR $group_array[$group_id]['location'] == 3) AND $before == 0) { $post_content = adrotate_group($group_id).$post_content; $before = 1; } // Advert behind the content if(($group_array[$group_id]['location'] == 2 OR $group_array[$group_id]['location'] == 3) AND $after == 0) { $post_content = $post_content.adrotate_group($group_id); $after = 1; } // Adverts inside the content if($group_array[$group_id]['location'] == 4 AND $key == 0) { preg_match_all("/(?:.*?)
]*>(?:.*?)<\/p>(?:<\/[a-z]*?>)*/is", $post_content, $paragraphs); // $paragraphs = explode("
", $post_content); $par = 1; $post_content = ''; foreach($paragraphs[0] as &$paragraph) { // foreach($paragraphs as &$paragraph) { if($par == $group_array[$group_id]['paragraph'] OR ($par == 2 AND $group_array[$group_id]['paragraph'] == 20) OR ($par == 3 AND $group_array[$group_id]['paragraph'] == 30) OR ($par == 4 AND $group_array[$group_id]['paragraph'] == 40)) { $paragraph .= adrotate_group($group_id); $par++; if($group_array[$group_id]['paragraph'] > 1 AND $group_array[$group_id]['paragraph'] < 10) { $par = 1; } } else { $par++; } $post_content .= $paragraph; unset($paragraph); } } } } } unset($group_choice, $group_count, $group_array, $paragraph, $paragraph_count, $before, $after); } return $post_content; } /*------------------------------------------------------------- Name: adrotate_inject_posts Purpose: Add an advert to a single post Receive: $post_content Return: $post_content Added: 3.7 -------------------------------------------------------------*/ function adrotate_inject_posts($post_content) { global $wpdb, $adrotate_debug; if(is_single()) { // Inject ads into posts in specified category $ids = $wpdb->get_results("SELECT `id`, `cat`, `cat_loc`, `cat_par` FROM `{$wpdb->prefix}adrotate_groups` WHERE `cat_loc` > 0;"); $wp_categories = get_terms('category', array('fields' => 'ids')); $group_array = array(); foreach($ids as $id) { $categories = explode(",", $id->cat); if(!is_array($categories)) $categories = array(); foreach($wp_categories as &$value) { if(in_array($value, $categories)) { $group_array[$id->id] = array('location' => $id->cat_loc, 'paragraph' => $id->cat_par, 'categories' => $categories); } } } if($adrotate_debug['general'] == true) { echo "[DEBUG][adrotate_inject_posts()] group_array
"; print_r($group_array); echo ""; } unset($ids, $wp_categories, $categories); $group_count = count($group_array); if($group_count > 0) { if($group_count > 1) { // Try to prevent the same ad from showing when there are multiple ads to show $paragraph_count = substr_count($post_content, '
'); if($paragraph_count == 0 OR $group_count < $paragraph_count) { $paragraph_count = $group_count; } $group_choice = array_rand($group_array, $paragraph_count); if(!is_array($group_choice)) $group_choice = array($group_choice); shuffle($group_choice); } else { $group_choice = array_rand($group_array, 1); $group_choice = array($group_choice,$group_choice); } if($adrotate_debug['general'] == true) { echo "
[DEBUG][adrotate_inject_posts()] group_choice
"; print_r($group_choice); echo ""; } $before = $after = 0; foreach($group_choice as $key => $group_id) { if(in_category($group_array[$group_id]['categories'])) { // Advert in front of content if(($group_array[$group_id]['location'] == 1 OR $group_array[$group_id]['location'] == 3) AND $before == 0) { $post_content = adrotate_group($group_id).$post_content; $before = 1; } // Advert behind content if(($group_array[$group_id]['location'] == 2 OR $group_array[$group_id]['location'] == 3) AND $after == 0) { $post_content = $post_content.adrotate_group($group_id); $after = 1; } // Adverts inside the content if($group_array[$group_id]['location'] == 4 AND $key == 0) { preg_match_all("/(?:.*?)
]*>(?:.*?)<\/p>(?:<\/[a-z]*?>)*/is", $post_content, $paragraphs); // $paragraphs = explode("
", $post_content); $par = 1; $post_content = ''; foreach($paragraphs[0] as &$paragraph) { // foreach($paragraphs as &$paragraph) { if($par == $group_array[$group_id]['paragraph'] OR ($par == 2 AND $group_array[$group_id]['paragraph'] == 20) OR ($par == 3 AND $group_array[$group_id]['paragraph'] == 30) OR ($par == 4 AND $group_array[$group_id]['paragraph'] == 40)) { $paragraph .= adrotate_group($group_id); $par++; if($group_array[$group_id]['paragraph'] > 1 AND $group_array[$group_id]['paragraph'] < 10) { $par = 1; } } else { $par++; } $post_content .= $paragraph; unset($paragraph); } } } } } unset($group_choice, $group_count, $group_array, $paragraph, $paragraph_count, $before, $after); } return $post_content; } /*------------------------------------------------------------- Name: adrotate_block (OBSOLETE) Purpose: This function is no longer supported. Replace blocks with groups! Receive: $block_id, $weight Return: $output Since: 3.0 -------------------------------------------------------------*/ function adrotate_block($block_id = 0, $weight = 0) { return null; } /*------------------------------------------------------------- Name: adrotate_preview Purpose: Show preview of selected ad (Dashboard) Receive: $banner_id Return: $output Since: 3.0 -------------------------------------------------------------*/ function adrotate_preview($banner_id) { global $wpdb, $adrotate_debug; if($banner_id) { $now = adrotate_now(); $banner = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}adrotate` WHERE `id` = %d;", $banner_id)); if($adrotate_debug['general'] == true) { echo "[DEBUG][adrotate_preview()] Ad information
"; print_r($banner); echo ""; } if($banner) { $image = str_replace('%folder%', '/wp-content/banners/', $banner->image); $output = adrotate_ad_output($banner->id, 0, $banner->bannercode, $banner->tracker, $banner->link, $image, 'N'); } else { $output = adrotate_error('ad_expired'); } } else { $output = adrotate_error('ad_no_id'); } return $output; } /*------------------------------------------------------------- Name: adrotate_ad_output Purpose: Prepare the output for viewing Receive: $id, $group, $bannercode, $tracker, $link, $image, $responsive Return: $banner_output Since: 3.0 -------------------------------------------------------------*/ function adrotate_ad_output($id, $group = 0, $bannercode, $tracker, $link, $image, $responsive) { global $blog_id, $adrotate_debug, $adrotate_config; $banner_output = $bannercode; $banner_output = stripslashes(htmlspecialchars_decode($banner_output, ENT_QUOTES)); $banner_output = str_replace('%link%', $link, $banner_output); if($adrotate_config['stats'] > 0) { if(empty($blog_id) or $blog_id == '') { $blog_id = 0; } if($adrotate_config['stats'] == 1 AND $tracker == "Y") { // Internal tracker $banner_output = str_replace('](?:.*?)>/i', $banner_output, $matches, PREG_SET_ORDER); if(isset($matches[0])) { foreach($matches[0] as $value) { if(preg_match('/]+class=\"(.+?)\"[^>]*>/i', $value, $regs)) { $result = $regs[1]." gofollow"; $banner_output = str_replace('class="'.$regs[1].'"', 'class="'.$result.'"', $banner_output); } else { $banner_output = str_replace('](?:.*?)>/i', $banner_output, $matches, PREG_SET_ORDER); if(isset($matches[0])) { foreach($matches[0] as $value) { if(preg_match('/
'.__('WordPress was unable to verify the authenticity of the url you have clicked. Verify if the url used is valid or log in via your browser.', 'adrotate').'
'; echo ''.__('If you have received the url you want to visit via email, you are being tricked!', 'adrotate').'
'; echo ''.__('Contact support if the issue persists:', 'adrotate').' AJdG Solutions Support.
'; } /*------------------------------------------------------------- Name: adrotate_error Purpose: Show errors for problems in using AdRotate, should they occur Receive: $action, $arg Return: -none- Since: 3.0 -------------------------------------------------------------*/ function adrotate_error($action, $arg = null) { global $adrotate_debug; switch($action) { // Ads case "ad_expired" : if($adrotate_debug['general'] == true) { $result = ''.__('Error, Ad is not available at this time due to schedule/geolocation restrictions or does not exist!', 'adrotate').''; } else { $result = ''; } return $result; break; case "ad_unqualified" : if($adrotate_debug['general'] == true) { $result = ''.__('Either there are no banners, they are disabled or none qualified for this location!', 'adrotate').''; } else { $result = ''; } return $result; break; case "ad_no_id" : $result = ''.__('Error, no Ad ID set! Check your syntax!', 'adrotate').''; return $result; break; // Groups case "group_no_id" : $result = ''.__('Error, no group ID set! Check your syntax!', 'adrotate').''; return $result; break; case "group_not_found" : $result = ''.__('Error, group does not exist! Check your syntax!', 'adrotate').' (ID: '.$arg[0].')'; return $result; break; // Database case "db_error" : $result = ''.__('There was an error locating the database tables for AdRotate. Please deactivate and re-activate AdRotate from the plugin page!!', 'adrotate').''.$data['expired'].' '.__('active ad(s) expired.', 'adrotate').' '.__('Take action now', 'adrotate').'!
'.$data['expiressoon'].' '.__('active ad(s) are about to expire.', 'adrotate').' '.__('Check it out', 'adrotate').'!
There are '.$data['error'].' '.__('active ad(s) with configuration errors.', 'adrotate').' '.__('Solve this', 'adrotate').'!
'.$data['expired'].' '.__('ad(s) expired.', 'adrotate').' '.$data['expiressoon'].' '.__('ad(s) are about to expire.', 'adrotate').' There are '.$data['error'].' '.__('ad(s) with configuration errors.', 'adrotate').' '.__('Fix this as soon as possible', 'adrotate').'!
'.__('Welcome, and thanks for using AdRotate. Everything related to AdRotate is in this menu. Check out the', 'adrotate').' '.__('manuals', 'adrotate').' '.__('and', 'adrotate').' '.__('forums', 'adrotate').'.
'; $pointer_content .= 'AdRotate Professional
Did you know there is also a premium version of AdRotate? Find out how you can benefit from the extra features.
AdRotate is growing to be one of the most popular WordPress plugins for Advertising and is a household name for many companies around the world. AdRotate wouldn\'t be possible without your support and my life wouldn\'t be what it is today without your help.
- Arnan from AJdG Solutions
'. 'Add me: Twitter, Facebook. Business: ajdg.solutions Blog: meandmymac.net and adventure: floatingcoconut.net.
' ) ); } /*------------------------------------------------------------- Name: adrotate_credits Purpose: Promotional stuff shown throughout the plugin Receive: -none- Return: -none- Since: 3.7 -------------------------------------------------------------*/ function adrotate_credits() { echo '| '.__('Help AdRotate Grow', 'adrotate').' | '; echo ''.__('Brought to you by', 'adrotate').' | '; echo '||
|---|---|---|---|
![]() | ';
echo ''.__("A lot of users only think to review AdRotate when something goes wrong while thousands of people use AdRotate satisfactory. Don't let this go unnoticed.", 'adrotate').' '. __("If you find AdRotate useful please leave your honest", 'adrotate').' '.__('rating','adrotate').' '.__('and','adrotate').' '.__('review','adrotate').' '.__('on WordPress.org to help AdRotate grow in a positive way', 'adrotate').'! | '; echo '![]() | ';
echo 'AJdG Solutions - '.__('Your one stop for Webdevelopment, consultancy and anything WordPress! Find out more about what I can do for you!', 'adrotate').' '.__('Visit the', 'adrotate').' AJdG Solutions '.__('website', 'adrotate').' | '; echo '