'ids')); $post_term = wp_get_post_categories($GLOBALS['post']->ID); $wd_ads_group = ''; foreach ($terms_ids as $term_id) { $tax_options = get_option(WD_ADS_PLUGIN_PREFIX . '_manage_groups_' . $term_id); $categories_to_show_in = json_decode($tax_options['categories'], true); $posts_to_show_in = json_decode($tax_options['posts'], true); $placement = $tax_options['placement']; $inside_content = $tax_options['inside_content'];; if ($categories_to_show_in == 0) continue; if($posts_to_show_in!=0 && $tax_options['show_in_posts'] != 0) { $continue=0; foreach ($posts_to_show_in as $post_to_show_id => $value) { if ($post_to_show_id == $GLOBALS['post']->ID) { $continue=1; } } if($continue==1 or in_array('all',$posts_to_show_in)) continue; } //$categories_to_show_in = array_keys($categories_to_show_in); $check_array = array_intersect($post_term, $categories_to_show_in); if ($tax_options['show_in_cats'] == 1 and $GLOBALS['post']->post_type == 'post' and count($check_array) > 0 or in_array('all',$categories_to_show_in)) { $wd_ads_html = do_shortcode('[wd_ads group=' . $term_id . ']'); $content = wd_ads_show_in_content($content, $placement, $wd_ads_html, $inside_content); } } return $content; } function wd_ads_show_group_in_posts($content) { $terms_ids = get_terms('wd_ads_manage_groups', array('fields' => 'ids')); $wd_ads_group = ''; foreach ($terms_ids as $term_id) { $tax_options = get_option(WD_ADS_PLUGIN_PREFIX . '_manage_groups_' . $term_id); $posts_to_show_in = json_decode($tax_options['posts'], true); $placement = $tax_options['placement']; $inside_content = $tax_options['inside_content'];; if ($posts_to_show_in == 0) continue; // $posts_to_show_in = array_keys($posts_to_show_in); if ($tax_options['show_in_posts'] == 1 and $GLOBALS['post']->post_type == 'post' and in_array($GLOBALS['post']->ID, $posts_to_show_in) or ($tax_options['show_in_posts'] == 1 and $GLOBALS['post']->post_type == 'post' and in_array('all', $posts_to_show_in))) { $wd_ads_html = do_shortcode('[wd_ads group=' . $term_id . ']'); $content = wd_ads_show_in_content($content, $placement, $wd_ads_html, $inside_content); } } return $content; } function wd_ads_show_group_in_pages($content) { $terms_ids = get_terms('wd_ads_manage_groups', array('fields' => 'ids')); $wd_ads_group = ''; foreach ($terms_ids as $term_id) { $tax_options = get_option(WD_ADS_PLUGIN_PREFIX . '_manage_groups_' . $term_id); $pages_to_show_in = json_decode($tax_options['pages'], true); if ($pages_to_show_in == 0) continue; // $pages_to_show_in = array_keys($pages_to_show_in); $placement = $tax_options['placement']; $inside_content = $tax_options['inside_content'];; if ($tax_options['show_in_pages'] == 1 and $GLOBALS['post']->post_type == 'page' and in_array($GLOBALS['post']->ID, $pages_to_show_in) or ($tax_options['show_in_pages'] == 1 and $GLOBALS['post']->post_type == 'page' and in_array('all', $pages_to_show_in)) ) { $wd_ads_html = do_shortcode('[wd_ads group=' . $term_id . ']'); $content = wd_ads_show_in_content($content, $placement, $wd_ads_html, $inside_content); } } return $content; } function wd_ads_show_advert_in_category($content) { $posts_ids = get_posts(array('post_type' => WD_ADS_PLUGIN_PREFIX . '_ads', 'fields' => 'ids', 'meta_key' => 'show_in_cats', 'meta_value' => '1')); $wd_ads = ''; $post_term = wp_get_post_categories($GLOBALS['post']->ID); foreach ($posts_ids as $post_id) { $categories_to_show_in = get_post_meta($post_id, 'categories', true); $placement = get_post_meta($post_id, 'placement', true); $inside_content = get_post_meta($post_id, 'inside_content', true); $show_in_posts = get_post_meta($post_id, 'show_in_posts', true); $categories_to_show_in = json_decode($categories_to_show_in, true); $posts_to_show_in = get_post_meta($post_id, 'posts', true); $posts_to_show_in = json_decode($posts_to_show_in, true); if ($categories_to_show_in == 0) continue; if($posts_to_show_in!=0 && $show_in_posts!=0) { $continue=0; foreach ($posts_to_show_in as $post_to_show_id => $value) { if ($post_to_show_id == $GLOBALS['post']->ID) { $continue=1; } } if($continue==1 or in_array('all',$posts_to_show_in)) continue; } // $categories_to_show_in = array_keys($categories_to_show_in); $check_array = array_intersect($post_term, $categories_to_show_in); if ($GLOBALS['post']->post_type == 'post' and count($check_array) > 0 ) { $wd_ads_html = do_shortcode('[wd_ads advert=' . $post_id . ']'); $content = wd_ads_show_in_content($content, $placement, $wd_ads_html, $inside_content); } } return $content; } function wd_ads_show_in_posts($content) { $posts_ids = get_posts(array('post_type' => WD_ADS_PLUGIN_PREFIX . '_ads', 'fields' => 'ids', 'meta_key' => 'show_in_posts', 'meta_value' => '1')); $wd_ads = ''; foreach ($posts_ids as $post_id) { $posts_to_show_in = get_post_meta($post_id, 'posts', true); $placement = get_post_meta($post_id, 'placement', true); $inside_content = get_post_meta($post_id, 'inside_content', true); $posts_to_show_in = json_decode($posts_to_show_in, true); if ($posts_to_show_in == 0) continue; // $posts_to_show_in = $posts_to_show_in; if ($GLOBALS['post']->post_type == 'post' and in_array($GLOBALS['post']->ID, $posts_to_show_in) or ($GLOBALS['post']->post_type == 'post' and in_array('all',$posts_to_show_in))) { $wd_ads_html = do_shortcode('[wd_ads advert=' . $post_id . ']'); $content = wd_ads_show_in_content($content, $placement, $wd_ads_html, $inside_content); } } return $content; } function wd_ads_show_in_pages($content) { $pages_ids = get_posts(array('post_type' => WD_ADS_PLUGIN_PREFIX . '_ads', 'fields' => 'ids', 'meta_key' => 'show_in_pages', 'meta_value' => '1')); $wd_ads = ''; foreach ($pages_ids as $page_id) { $pages_to_show_in = get_post_meta($page_id, 'pages', true); $placement = get_post_meta($page_id, 'placement', true); $inside_content = get_post_meta($page_id, 'inside_content', true); $pages_to_show_in = json_decode($pages_to_show_in, true); if ($pages_to_show_in == 0) continue; //$pages_to_show_in = array_keys($pages_to_show_in); if ($GLOBALS['post']->post_type == 'page' and in_array($GLOBALS['post']->ID, $pages_to_show_in) or ($GLOBALS['post']->post_type == 'page' and in_array('all', $pages_to_show_in)) ) { $wd_ads_html = do_shortcode('[wd_ads advert=' . $page_id . ']'); $content = wd_ads_show_in_content($content, $placement, $wd_ads_html, $inside_content); } } return $content; } function wd_ads_show_in_content( $content, $placement, $html, $place = 0 ) { switch ( $placement ) { case 'before': return $html . $content; break; case 'after': return $content . $html; break; case 'before_after': return $html . $content . $html; break; case 'inside': $paragraphs = explode( '
', $content ); $par_num = count( $paragraphs ) - 1; $content_modified = ''; if ( $par_num <= $place ) { return $content . $html; } foreach ( $paragraphs as $key => $paragraph ) { if ( $key == ( $place - 1 ) ) { $paragraph .= $html; } $content_modified .= $paragraph . ''; } return $content_modified; break; } } function wd_ads_show_single_advert( $id, $from_group = 0, $margin = 0 ) { $area_code = get_post_meta( $id, 'area_code', TRUE ); $statistics = get_post_meta( $id, 'statistics', TRUE ); $published = get_post_meta( $id, 'published', TRUE ); $responsive = get_post_meta( $id, 'responsive', TRUE ); $sortorder = get_post_meta( $id, 'sortorder', TRUE ); $city_state = get_post_meta( $id, 'city_state', TRUE ); $countries_meta = get_post_meta( $id, 'countries', TRUE ); $wrapper_before = get_post_meta( $id, 'wrapper_before', TRUE ); $wrapper_after = get_post_meta( $id, 'wrapper_after', TRUE ); $clicks = get_post_meta( $id, 'clicks', TRUE ); $impressions = get_post_meta( $id, 'impressions', TRUE ); $enable_responsive = get_post_meta( $id, 'enable_responsive', TRUE ); $schedules = get_post_meta( $id, 'schedule', TRUE ); $schedules = json_decode( $schedules, TRUE ); if ( $schedules != 0 ) { $schedules = array_keys( $schedules ); } else { $schedules = array(); } $now = time(); $wd_ads_validate = FALSE; $wd_ads_options = wd_ads_get_settings(); foreach ( $schedules as $schedule ) { $schedule_start_date_meta = get_post_meta( $schedule, 'start_date', TRUE ); $schedule_end_date_meta = get_post_meta( $schedule, 'end_date', TRUE ); $schedule_weekdays = get_post_meta( $schedule, 'weekdays', TRUE ); $schedule_weekdays = json_decode( $schedule_weekdays, TRUE ); if ( $schedule_weekdays != 0 ) { $schedule_weekdays = array_keys( $schedule_weekdays ); } $daily_start_hour = get_post_meta( $schedule, 'daily_start_hour', TRUE ); $daily_start_min = get_post_meta( $schedule, 'daily_start_min', TRUE ); $daily_end_hour = get_post_meta( $schedule, 'daily_end_hour', TRUE ); $daily_end_min = get_post_meta( $schedule, 'daily_end_min', TRUE ); $max_clicks = get_post_meta( $schedule, 'max_clicks', TRUE ); if ( $max_clicks == 0 ) { $max_clicks = $clicks + 1; } $max_impressions = get_post_meta( $schedule, 'max_impressions', TRUE ); if ( $max_impressions == 0 ) { $max_impressions = $impressions + 1; } $daily_start_time = mktime( (int) $daily_start_hour, (int) $daily_start_min, 0, date( 'n' ), date( 'd' ), date( 'Y' ) ); $daily_end_time = mktime( (int) $daily_end_hour, (int) $daily_end_min, 0, date( 'n' ), date( 'd' ), date( 'Y' ) ); if ( (int) $daily_end_min == 0 AND (int) $daily_end_hour == 0 AND (int) $daily_start_min == 0 AND (int) $daily_start_hour == 0 ) { $daily_start_time = $now - 1; $daily_end_time = $now + 1; } if ( $schedule_start_date_meta <= $now and $schedule_end_date_meta >= $now AND in_array( date( 'N', $now ), $schedule_weekdays ) and $daily_start_time < $now and $daily_end_time > $now and $max_clicks > $clicks and $max_impressions > $impressions ) { $wd_ads_validate = TRUE; break; } } if ( $from_group == 0 ) { if ( ! wd_ads_filter_device( $id ) ) { return FALSE; } } /*if ( $from_group == 0 AND $wd_ads_options['geo_targeting'] > 1 ) { if ( ! wd_ads_filter_post_ids_geo( $id, 'single' ) ) { return FALSE; } }*/ if ( ! $wd_ads_validate and count( $schedules ) != 0 ) { /* if ($from_group == 1) return show_advert_group($group_id); else*/ return FALSE; } $banner_asset = wp_get_attachment_url( get_post_thumbnail_id( $id ) ); if ( $enable_responsive == 1 ) { $banner_phone = get_post_meta( $id, 'img_phone', TRUE ); $banner_tablet = get_post_meta( $id, 'img_tablet', TRUE ); if ( wd_ads::$device == "smartphone" && $banner_phone != '' ) { $banner_asset = $banner_phone; } if ( wd_ads::$device == "tablet" && $banner_tablet != '' ) { $banner_asset = $banner_tablet; } } $advert_title = get_the_title( $id ); $area_code = str_replace( '%featured_image%', $banner_asset, $area_code ); $area_code = str_replace( '%title%', $advert_title, $area_code ); $tracking = ''; if ( $statistics == 1 ) { ///////////////INTERNAL TRACKER if ( $wd_ads_options['stats_track'] == 1 ) { $tracking = "wd_ads_tracking=" . $id . " "; } ///////////////Google Analytics if ( $wd_ads_options['stats_track'] == 3 ) { $tracking = "wd_ads_tracking_analytics=" . $advert_title . " "; } ///////////////Piwik Analytics if ( $wd_ads_options['stats_track'] == 2 ) { $tracking = "wd_ads_tracking_piwik=" . $advert_title . " "; } } $result = $wrapper_before; $result .= '