| 1 |
<?php |
| 2 |
function wp_insert_filter_content_ads($content, $ad_ID) { |
| 3 |
$output = ''; |
| 4 |
$page_details = wp_insert_get_current_page_details(); |
| 5 |
|
| 6 |
if(get_option('wp_insert_in_post_ad_middle_'.$ad_ID.'_enable')) { |
| 7 |
/*Finding a appropriate position near the middle of the content to insert the ad*/ |
| 8 |
$positions = array(); |
| 9 |
$endpos = -1; |
| 10 |
$trigger = "<p"; |
| 11 |
if(strpos($content, "<p") === false) |
| 12 |
$trigger = "<br"; |
| 13 |
|
| 14 |
while(strpos($content, $trigger, $endpos+1) !== false){ |
| 15 |
$endpos = strpos($content, $trigger, $endpos+1); |
| 16 |
$positions[] = $endpos; |
| 17 |
} |
| 18 |
$middle = sizeof($positions); |
| 19 |
while(sizeof($positions) > $middle) |
| 20 |
array_pop($positions); |
| 21 |
$triggerpoint = $positions[floor(sizeof($positions)/2)]; |
| 22 |
/*End of Finding a appropriate position near the middle of the content to insert the ad*/ |
| 23 |
|
| 24 |
if ($middle > 2) { |
| 25 |
if(!get_option('wp_insert_in_post_ad_middle_'.$ad_ID.'_exclude_home') && ($page_details == 'HOME')) { |
| 26 |
$content = substr_replace($content, '<div id="in_post_ad_middle_'.$ad_ID.'" style="margin:5px;">'.get_option('wp_insert_in_post_ad_middle_'.$ad_ID.'_content').'</div>'.$trigger, $triggerpoint, 2); |
| 27 |
} |
| 28 |
else if(!get_option('wp_insert_in_post_ad_middle_'.$ad_ID.'_exclude_archives') && ($page_details == 'ARCHIVE')) { |
| 29 |
$content = substr_replace($content, '<div id="in_post_ad_middle_'.$ad_ID.'" style="margin:5px;">'.get_option('wp_insert_in_post_ad_middle_'.$ad_ID.'_content').'</div>'.$trigger, $triggerpoint, 2); |
| 30 |
} |
| 31 |
else { |
| 32 |
if(is_singular()) { |
| 33 |
$page_ids = explode(',', str_replace(" ", "", get_option('wp_insert_in_post_ad_middle_'.$ad_ID.'_exclude_ids'))); |
| 34 |
if(wp_insert_is_in_array($page_details, $page_ids) =='FALSE') { |
| 35 |
$content = substr_replace($content, '<div id="in_post_ad_middle_'.$ad_ID.'" style="margin:5px;">'.get_option('wp_insert_in_post_ad_middle_'.$ad_ID.'_content').'</div>'.$trigger, $triggerpoint, 2); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
if(get_option('wp_insert_in_post_ad_top_'.$ad_ID.'_enable')) { |
| 42 |
if(!get_option('wp_insert_in_post_ad_top_'.$ad_ID.'_exclude_home') && ($page_details == 'HOME')) { |
| 43 |
$output .= '<div id="in_post_ad_top_'.$ad_ID.'" style="margin:5px;">'.get_option('wp_insert_in_post_ad_top_'.$ad_ID.'_content').'</div>'; |
| 44 |
} |
| 45 |
else if(!get_option('wp_insert_in_post_ad_top_'.$ad_ID.'_exclude_archives') && ($page_details == 'ARCHIVE')) { |
| 46 |
$output .= '<div id="in_post_ad_top_'.$ad_ID.'" style="margin:5px;">'.get_option('wp_insert_in_post_ad_top_'.$ad_ID.'_content').'</div>'; |
| 47 |
} |
| 48 |
else { |
| 49 |
if(is_singular()) { |
| 50 |
$page_ids = explode(',', str_replace(" ", "", get_option('wp_insert_in_post_ad_top_'.$ad_ID.'_exclude_ids'))); |
| 51 |
if(wp_insert_is_in_array($page_details, $page_ids) =='FALSE') { |
| 52 |
$output .= '<div id="in_post_ad_top_'.$ad_ID.'" style="margin:5px;">'.get_option('wp_insert_in_post_ad_top_'.$ad_ID.'_content').'</div>'; |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
if(get_option('wp_insert_in_post_ad_left_'.$ad_ID.'_enable')) { |
| 58 |
if(!get_option('wp_insert_in_post_ad_left_'.$ad_ID.'_exclude_home') && ($page_details == 'HOME')) { |
| 59 |
$output .= '<div id="in_post_ad_left_'.$ad_ID.'" style="margin:5px;float:left;">'.get_option('wp_insert_in_post_ad_left_'.$ad_ID.'_content').'</div>'; |
| 60 |
} |
| 61 |
else if(!get_option('wp_insert_in_post_ad_left_'.$ad_ID.'_exclude_archives') && ($page_details == 'ARCHIVE')) { |
| 62 |
$output .= '<div id="in_post_ad_left_'.$ad_ID.'" style="margin:5px;float:left;">'.get_option('wp_insert_in_post_ad_left_'.$ad_ID.'_content').'</div>'; |
| 63 |
} |
| 64 |
else { |
| 65 |
if(is_singular()) { |
| 66 |
$page_ids = explode(',', str_replace(" ", "", get_option('wp_insert_in_post_ad_left_'.$ad_ID.'_exclude_ids'))); |
| 67 |
if(wp_insert_is_in_array($page_details, $page_ids) =='FALSE') { |
| 68 |
$output .= '<div id="in_post_ad_left_'.$ad_ID.'" style="margin:5px;float:left;">'.get_option('wp_insert_in_post_ad_left_'.$ad_ID.'_content').'</div>'; |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
if(get_option('wp_insert_in_post_ad_right_'.$ad_ID.'_enable')) { |
| 74 |
if(!get_option('wp_insert_in_post_ad_right_'.$ad_ID.'_exclude_home') && ($page_details == 'HOME')) { |
| 75 |
$output .= '<div id="in_post_ad_right_'.$ad_ID.'" style="margin:5px;float:right;">'.get_option('wp_insert_in_post_ad_right_'.$ad_ID.'_content').'</div>'; |
| 76 |
} |
| 77 |
else if(!get_option('wp_insert_in_post_ad_right_'.$ad_ID.'_exclude_archives') && ($page_details == 'ARCHIVE')) { |
| 78 |
$output .= '<div id="in_post_ad_right_'.$ad_ID.'" style="margin:5px;float:right;">'.get_option('wp_insert_in_post_ad_right_'.$ad_ID.'_content').'</div>'; |
| 79 |
} |
| 80 |
else { |
| 81 |
if(is_singular()) { |
| 82 |
$page_ids = explode(',', str_replace(" ", "", get_option('wp_insert_in_post_ad_right_'.$ad_ID.'_exclude_ids'))); |
| 83 |
if(wp_insert_is_in_array($page_details, $page_ids) =='FALSE') { |
| 84 |
$output .= '<div id="in_post_ad_right_'.$ad_ID.'" style="margin:5px;float:right;">'.get_option('wp_insert_in_post_ad_right_'.$ad_ID.'_content').'</div>'; |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
if(get_option('wp_insert_in_post_ad_bottom_'.$ad_ID.'_enable')) { |
| 90 |
if(!get_option('wp_insert_in_post_ad_bottom_'.$ad_ID.'_exclude_home') && ($page_details == 'HOME')) { |
| 91 |
$content .= '<div id="in_post_ad_bottom_'.$ad_ID.'" style="margin:5px;clear:both;">'.get_option('wp_insert_in_post_ad_bottom_'.$ad_ID.'_content').'</div>'; |
| 92 |
} |
| 93 |
else if(!get_option('wp_insert_in_post_ad_bottom_'.$ad_ID.'_exclude_archives') && ($page_details == 'ARCHIVE')) { |
| 94 |
$content .= '<div id="in_post_ad_bottom_'.$ad_ID.'" style="margin:5px;clear:both;">'.get_option('wp_insert_in_post_ad_bottom_'.$ad_ID.'_content').'</div>'; |
| 95 |
} |
| 96 |
else { |
| 97 |
if(is_singular()) { |
| 98 |
$page_ids = explode(',', str_replace(" ", "", get_option('wp_insert_in_post_ad_bottom_'.$ad_ID.'_exclude_ids'))); |
| 99 |
if(wp_insert_is_in_array($page_details, $page_ids) =='FALSE') { |
| 100 |
$content .= '<div id="in_post_ad_bottom_'.$ad_ID.'" style="margin:5px;clear:both;">'.get_option('wp_insert_in_post_ad_bottom_'.$ad_ID.'_content').'</div>'; |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
$content = $output.$content."<div style='clear:both'></div>"; |
| 106 |
return $content; |
| 107 |
} |
| 108 |
?> |