| 1 |
<?php |
| 2 |
$wpInsertPostInstance; |
| 3 |
$wpInsertAdInstance; |
| 4 |
add_action('the_content', 'wp_insert_track_post_instance', 1); |
| 5 |
function wp_insert_track_post_instance($content) { |
| 6 |
global $wpInsertPostInstance; |
| 7 |
if($wpInsertPostInstance == '') { |
| 8 |
$wpInsertPostInstance = 1; |
| 9 |
} else { |
| 10 |
$wpInsertPostInstance++; |
| 11 |
} |
| 12 |
return $content; |
| 13 |
} |
| 14 |
|
| 15 |
add_action('wp', 'wp_insert_track_ad_instance', 1); |
| 16 |
function wp_insert_track_ad_instance($content) { |
| 17 |
global $wpInsertAdInstance; |
| 18 |
$networkCount = get_option('wp-insert-multiple-network-status'); |
| 19 |
$wpInsertAdInstance = rand(1, $networkCount); |
| 20 |
} |
| 21 |
|
| 22 |
function wp_insert_get_page_details() { |
| 23 |
global $post; |
| 24 |
$page_details = array( |
| 25 |
'type' => 'POST', |
| 26 |
'ID' => $post->ID |
| 27 |
); |
| 28 |
if(is_home() || is_front_page()) { |
| 29 |
$page_details['type'] = 'HOME'; |
| 30 |
} else if(is_category()) { |
| 31 |
$page_details['type'] = 'CATEGORY'; |
| 32 |
$page_details['ID'] = get_query_var('cat'); |
| 33 |
} else if(is_archive()) { |
| 34 |
$page_details['type'] = 'ARCHIVE'; |
| 35 |
} else if(is_search()) { |
| 36 |
$page_details['type'] = 'SEARCH'; |
| 37 |
} else if(is_page()) { |
| 38 |
$page_details['type'] = 'PAGE'; |
| 39 |
} else if(is_single()) { |
| 40 |
$page_details['type'] = 'POST'; |
| 41 |
} |
| 42 |
|
| 43 |
return $page_details; |
| 44 |
} |
| 45 |
|
| 46 |
function wp_insert_get_ad_status($rules) { |
| 47 |
if(!$rules['status']) { |
| 48 |
return false; |
| 49 |
} |
| 50 |
global $wpInsertPostInstance; |
| 51 |
$page_details = wp_insert_get_page_details(); |
| 52 |
switch($page_details['type']) { |
| 53 |
case 'HOME': |
| 54 |
if($rules['rules_exclude_home']) { |
| 55 |
return false; |
| 56 |
} else if($rules['rules_home_instances'] && (in_array($wpInsertPostInstance, split(',', $rules['rules_home_instances'])))) { |
| 57 |
return false; |
| 58 |
} |
| 59 |
break; |
| 60 |
case 'ARCHIVE': |
| 61 |
if($rules['rules_exclude_archives']) { |
| 62 |
return false; |
| 63 |
} else if($rules['rules_archives_instances'] && (in_array($wpInsertPostInstance, split(',', $rules['rules_archives_instances'])))) { |
| 64 |
return false; |
| 65 |
} |
| 66 |
break; |
| 67 |
case 'CATEGORY': |
| 68 |
if($rules['rules_exclude_categories']) { |
| 69 |
return false; |
| 70 |
} else if($rules['rules_categories_exceptions'] && (in_array($page_details['ID'], split(',', $rules['rules_categories_exceptions'])))) { |
| 71 |
return false; |
| 72 |
} else if($rules['rules_categories_instances'] && (in_array($wpInsertPostInstance, split(',', $rules['rules_categories_instances'])))) { |
| 73 |
return false; |
| 74 |
} |
| 75 |
break; |
| 76 |
case 'SEARCH': |
| 77 |
if($rules['rules_exclude_search']) { |
| 78 |
return false; |
| 79 |
} else if($rules['rules_search_instances'] && (in_array($wpInsertPostInstance, split(',', $rules['rules_search_instances'])))) { |
| 80 |
return false; |
| 81 |
} |
| 82 |
break; |
| 83 |
case 'PAGE': |
| 84 |
if($rules['rules_exclude_page']) { |
| 85 |
return false; |
| 86 |
} else if($rules['rules_page_exceptions'] && (in_array($page_details['ID'], split(',', $rules['rules_page_exceptions'])))) { |
| 87 |
return false; |
| 88 |
} |
| 89 |
break; |
| 90 |
case 'POST': |
| 91 |
if($rules['rules_exclude_post']) { |
| 92 |
return false; |
| 93 |
} else if($rules['rules_post_exceptions'] && (in_array($page_details['ID'], split(',', $rules['rules_post_exceptions'])))) { |
| 94 |
return false; |
| 95 |
} |
| 96 |
break; |
| 97 |
} |
| 98 |
return true; |
| 99 |
} |
| 100 |
?> |