0), $atts ); $checker = get_post($a['location_id']); if(!$checker || $checker->post_status != 'publish'){ if( current_user_can('publish_adverts') ){ return '

AdVert Location Not Published

'; } else{ return; } } $banners4locations = new WP_Query( array('post_type'=>'advert-banner','posts_per_page'=> -1, 'meta_query' => array( array( 'key' => 'banner_location', 'value' => $a['location_id'], 'compare' => '=', ), ) )); wp_reset_postdata(); if( $banners4locations->found_posts === 0 ){ $advert_display_advertise_here = 0; if( array_key_exists('advert_display_advertise_here', $advert_options) ){ $advert_display_advertise_here = intval($advert_options['advert_display_advertise_here']); } $advert_display_advertise_here_text = ''; if( array_key_exists('advert_display_advertise_here_text', $advert_options) ){ $advert_display_advertise_here_text = htmlspecialchars_decode($advert_options['advert_display_advertise_here_text']); } if($advert_display_advertise_here === 1){ return $advert_display_advertise_here_text; } } if( array_key_exists('count_override', $atts) ){ $advert_counter = $atts['count_override']; $nowrapper = 0; } $location = new ADVERT_Shortcode($a['location_id']); if( $get_network_type === true && get_current_blog_id() != $main_site_id ){ restore_current_blog(); } return $location->html; } class AdVert_Shortcode{ /* Public variables */ public $html; public $banners; public $dummy_array1; public $dummy_array2; public $dummy_array3; public $rand_camp_id; public $rand_ad_id; public $campaigns; public $location_meta; public $advert_counter; public $nowrapper; public static $camp_meta = array('campaign_location','campaign_priority','campaign_start_date','campaign_stop_date','campaign_price_model','campaign_charges','campaign_budget','campaign_budget_value','campaign_impressions','campaign_ppimpressions', 'campaign_owner', 'campaign_viewable_status'); /* Protected variables */ protected $location_id; protected $banner_owner; protected $location; protected static $location_meta_key = array('location_rotation','location_price'); protected $location_order = 1; /* Constructor */ function __construct($location_id){ $this->location_id = $location_id; $this->get_location(); $this->get_campaigns(); //if campaigns are empty, exit if(empty($this->campaigns)){return;} $this->get_banners(); $this->get_html(); } /** Determines the location */ function get_location(){ $this->location = get_post($this->location_id); foreach(self::$location_meta_key as $key) $this->location_meta[$key] = get_post_meta($this->location->ID , $key , true); } /** Retrieves the campaigns associated with the location */ function get_campaigns(){ $query = new WP_Query( array('post_type'=>'advert-campaign','posts_per_page'=> -1,'meta_key' => 'campaign_priority','orderby' => 'meta_value_num','order' => 'DESC' , 'meta_query' => array( array( 'key' => 'campaign_location', 'value' => $this->location_id, 'compare' => '=', ), ) )); wp_reset_postdata(); $this->campaigns = $query->posts; } /** Retrieves the banners associated with the location and campaign */ function get_banners(){ $this->banners = array(); $this->dummy_array1 = array();//main $this->dummy_array2 = array();//campaign $this->dummy_array3 = array();//banner $this->dummy_campaign = array();//campaign $this->dummy_banner = array();//banner $loc_rotate = get_post_meta($this->location_id, 'location_rotation', true); //check the type of ad - image video text $loc_ad_type = array(); if(get_post_meta($this->location_id, 'location_imagead', true) === '1'){ array_push($loc_ad_type, 'image'); } if(get_post_meta($this->location_id, 'location_videoad', true) === '1'){ array_push($loc_ad_type, 'video'); } if(get_post_meta($this->location_id, 'location_textad', true) === '1'){ array_push($loc_ad_type, 'text'); } //check options global $advert_options; $advert_negative_feedback = 0; if( array_key_exists('advert_feedback_hide_negative',$advert_options) ){ $advert_negative_feedback = intval($advert_options['advert_feedback_hide_negative']); } //get banners $banners = get_posts(array('post_type'=>'advert-banner','posts_per_page'=> -1,'meta_key' => 'banner_owner','orderby' => 'meta_value_num' , 'order' => 'DESC')); //loop through each associated campaign in order to determine the banner to display using either priority or random foreach((array)$this->campaigns as $camp){ if(self::is_available($camp->ID, $this->location_id)){ //this reviews the campaign priority and location flow (random or priority) adds to the pool and the randomizers selects the campaign and banners based on probabilities in the array $i = 0; if($loc_rotate === 'random'){ $campaign_priority = 1; } else{ $campaign_priority = intval(get_post_meta($camp->ID, 'campaign_priority', true)); } while( $i <= $campaign_priority ){ foreach( $banners as $banner ){ $banner_image = ''; $banner_video = ''; $banner_text = ''; if($advert_negative_feedback === 1){ $con = '12 HOUR'; $clicked = ADVERT_Log::get_click_by('f', $banner->ID, $con, '3'); } else{ $clicked = '0'; } if($clicked === '0'){ $aid = get_post_meta($banner->ID, 'banner_owner', true); if(has_post_thumbnail($banner->ID)){ $banner_image = 'image'; } if(get_post_meta($banner->ID , 'banner_video_url' ,true) !=''){ $banner_video = 'video'; } if(get_post_meta($banner->ID , 'banner_text_ad1' ,true) !='' || get_post_meta($banner->ID , 'banner_text_ad2' ,true) !=''){ $banner_text = 'text'; } if ( $banner->banner_location == $this->location_id && intval($aid) == intval($camp->campaign_owner)){ if( in_array($banner_image, $loc_ad_type) || in_array($banner_video, $loc_ad_type) || in_array($banner_text, $loc_ad_type) ){ if($loc_rotate === 'random'){ array_push($this->dummy_array2, array($banner->ID, $camp->ID)); } else{ for($k=0; $k < $banner->banner_priority; $k++){ array_push($this->dummy_array2, array($banner->ID, $camp->ID)); } } } } } } $i++; } } } if( count($this->dummy_array2) > 0 ){ shuffle($this->dummy_array2); $rand_ids = array_rand($this->dummy_array2); $rand_ids = $this->dummy_array2[$rand_ids]; $this->dummy_array3 = $rand_ids; } else{ return; } } function get_html(){ global $advert_counter; global $nowrapper; global $advert_options; //simple counter to add if someone uses the same campaign/banner multiple times $advert_counter = $advert_counter + 1; //check the options $advert_display_advert_link = 0; $advert_display_adv = 0; $advert_feedback = 0; if( array_key_exists('advert_about_link',$advert_options) ){ $advert_display_advert_link = intval($advert_options['advert_about_link']); } if( array_key_exists('advert_identify_ad',$advert_options) ){ $advert_display_adv = intval($advert_options['advert_identify_ad']); } if( array_key_exists('advert_feedback',$advert_options) ){ $advert_feedback = intval($advert_options['advert_feedback']); } //extra varables to identify banner id and campaign id from the dummy arrays if( count($this->dummy_array3) > 0 ){ $aid = strval($this->dummy_array3[0]); $cid = strval($this->dummy_array3[1]); } //exit the function if empty ids if ( empty($aid) || empty($cid) ) return; //check if image, video or text isset if( !has_post_thumbnail($aid) && get_post_meta($aid, 'banner_video_url', true) === '' && get_post_meta($aid, 'banner_text_ad1', true) === '' && get_post_meta($aid, 'banner_text_ad2', true) === '' ) return; $curURL = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; $custom = get_post_meta($aid, 'banner_custom_html', true); $location_enforce = intval(get_post_meta($this->location->ID, 'location_enforce', true)); $theheight = get_post_meta($this->location->ID, 'location_height', true); $thewidth = get_post_meta($this->location->ID, 'location_width', true); //setup the wrapper for image, video or text and include the link (href) $link = $this->get_banner_link($aid, $cid, $curURL); $ww = ''; $wh = ''; $whww = ''; if(!empty($thewidth) || !empty($theheight)){ if($location_enforce === 1){ if($thewidth){$ww='width:'.$thewidth.'px;';} if($theheight){$wh='height:'.$theheight.'px;';} $whww = 'style="'.$ww.$wh.'"'; } else{ if($thewidth){$ww='max-width:'.$thewidth.'px;';} if($theheight){$wh='max-height:'.$theheight.'px;';} $whww = 'style="'.$ww.$wh.'"'; } } //adding a timestamp to the banner being servered date_default_timezone_set("UTC"); if($nowrapper === 1){ $wrapper = '