Version Description
New option to add spacing above and below widgets. New options for randomly aligning random/top/bottom ads. Fixes for several bugs reported over Christmas.
Download this release
Release Info
Developer | reviewmylife |
Plugin | Ad Injection |
Version | 0.9.5 |
Comparing to | |
See all releases |
Code changes from version 0.9.4.6 to 0.9.5
- ad-injection-admin.php +58 -25
- ad-injection-widget.php +24 -15
- ad-injection.php +78 -66
- adshow.php +166 -7
- readme.txt +10 -2
ad-injection-admin.php
CHANGED
@@ -26,8 +26,10 @@ $adinj_warning_msg_chmod = "";
|
|
26 |
$adinj_warning_msg_filewrite = "";
|
27 |
|
28 |
function adinj_checkNonce(){
|
29 |
-
if (empty($_POST)
|
30 |
-
|
|
|
|
|
31 |
exit();
|
32 |
}
|
33 |
}
|
@@ -111,6 +113,7 @@ function adinj_write_config_file(){
|
|
111 |
$sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false';
|
112 |
$debug_mode = adinj_ticked('debug_mode')?'true':'false';
|
113 |
|
|
|
114 |
$rnd_func = adinj_add_tags(NULL, 'rnd_', 'adinj_config_add_tags_rnd');
|
115 |
$top_func = adinj_add_tags(NULL, 'top_', 'adinj_config_add_tags_top');
|
116 |
$bottom_func = adinj_add_tags(NULL, 'bottom_', 'adinj_config_add_tags_bottom');
|
@@ -187,7 +190,7 @@ function adinj_options_page(){
|
|
187 |
}
|
188 |
}
|
189 |
|
190 |
-
echo '<div class="wrap">';
|
191 |
|
192 |
if (adinj_problem_with_wpminify_check()){
|
193 |
echo '<div id="ad-injection-warning" class="error"><p><strong>';
|
@@ -224,7 +227,7 @@ function adinj_options_page(){
|
|
224 |
|
225 |
} else {
|
226 |
echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
|
227 |
-
echo "
|
228 |
echo '</strong></p></div>';
|
229 |
}
|
230 |
?>
|
@@ -360,7 +363,7 @@ function adinj_options_page(){
|
|
360 |
<p><a href="#random">Random ads</a> | <a href="#topad">Top</a> | <a href="#bottomad">Bottom</a> | <a href="#widgets">Widgets</a> | <a href="#restrictions">Ad insert mode/dynamic restrictions</a> | <a href="#debugging">Debug</a> | <a href="#docs">Quick Start</a> | <a href="#testads">Test ads</a></p>
|
361 |
|
362 |
<form name="adinjform" method="post" action="">
|
363 |
-
<?php wp_nonce_field('_adinj_form'
|
364 |
|
365 |
|
366 |
<?php adinj_postbox_start(__("Global settings", 'adinj'), 'global'); ?>
|
@@ -535,7 +538,7 @@ function adinj_options_page(){
|
|
535 |
<?php
|
536 |
_e("Only show top ad on pages longer than: ", 'adinj');
|
537 |
adinj_selection_box("top_ad_if_longer_than",
|
538 |
-
array(
|
539 |
|
540 |
?>
|
541 |
|
@@ -560,7 +563,7 @@ function adinj_options_page(){
|
|
560 |
<?php
|
561 |
_e("Only show bottom ad on pages longer than: ", 'adinj');
|
562 |
adinj_selection_box("bottom_ad_if_longer_than",
|
563 |
-
array(
|
564 |
?>
|
565 |
|
566 |
<br clear="all"/>
|
@@ -835,7 +838,7 @@ function adinj_get_status($name){
|
|
835 |
return $status;
|
836 |
}
|
837 |
$val = $ops['top_ad_if_longer_than'];
|
838 |
-
if ($val
|
839 |
$status[0] = 'red';
|
840 |
$status[1] = 'off';
|
841 |
} else {
|
@@ -850,7 +853,7 @@ function adinj_get_status($name){
|
|
850 |
return $status;
|
851 |
}
|
852 |
$val = $ops['bottom_ad_if_longer_than'];
|
853 |
-
if ($val
|
854 |
$status[0] = 'red';
|
855 |
$status[1] = 'off';
|
856 |
} else {
|
@@ -908,10 +911,23 @@ function adinj_dot($colour){
|
|
908 |
return '<span style="color:'.$colour.'">●</span>';
|
909 |
}
|
910 |
|
911 |
-
function adinj_selection_box($name, $values, $type=NULL){
|
912 |
echo "<select name='$name'>";
|
913 |
-
|
914 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
915 |
foreach ($values as $value){
|
916 |
echo "<option value=\"$value\" ";
|
917 |
if($selected_value == "$value") echo 'selected="selected"';
|
@@ -920,7 +936,7 @@ function adinj_selection_box($name, $values, $type=NULL){
|
|
920 |
} else {
|
921 |
$typetxt = $type;
|
922 |
}
|
923 |
-
if ($value
|
924 |
echo ">$value $typetxt</option>";
|
925 |
}
|
926 |
echo "</select>";
|
@@ -994,28 +1010,45 @@ function adinj_add_alignment_options($prefix){
|
|
994 |
_e("Alignment", 'adinj');
|
995 |
echo "<br />";
|
996 |
adinj_selection_box($prefix.'align',
|
997 |
-
array(
|
998 |
|
999 |
echo "<br />";
|
1000 |
|
1001 |
_e("Clear (CSS)", 'adinj');
|
1002 |
echo "<br />";
|
1003 |
adinj_selection_box($prefix.'clear',
|
1004 |
-
array(
|
1005 |
|
1006 |
echo "<br />";
|
1007 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1008 |
_e("Margin top", 'adinj');
|
1009 |
echo "<br />";
|
1010 |
-
adinj_selection_box($
|
1011 |
-
array(
|
1012 |
|
1013 |
echo "<br />";
|
1014 |
|
1015 |
_e("Margin bottom", 'adinj');
|
1016 |
echo "<br />";
|
1017 |
-
adinj_selection_box($
|
1018 |
-
array(
|
1019 |
}
|
1020 |
|
1021 |
function adinj_debug_information(){
|
@@ -1190,8 +1223,8 @@ function adinj_default_options(){
|
|
1190 |
'three_ads_if_shorter_than' => ADINJ_RULE_DISABLED,
|
1191 |
'top_ad_if_longer_than' => ADINJ_RULE_DISABLED,
|
1192 |
'bottom_ad_if_longer_than' => ADINJ_RULE_DISABLED,
|
1193 |
-
'rnd_align' =>
|
1194 |
-
'rnd_clear' =>
|
1195 |
'rnd_margin_top' => '3',
|
1196 |
'rnd_margin_bottom' => '3',
|
1197 |
'first_paragraph_ad' => '',
|
@@ -1200,14 +1233,14 @@ function adinj_default_options(){
|
|
1200 |
'max_num_of_ads_home_page' => '3',
|
1201 |
// top
|
1202 |
'ad_code_top_1' => '',
|
1203 |
-
'top_align' =>
|
1204 |
-
'top_clear' =>
|
1205 |
'top_margin_top' => '3',
|
1206 |
'top_margin_bottom' => '3',
|
1207 |
// bottom
|
1208 |
'ad_code_bottom_1' => '',
|
1209 |
-
'bottom_align' =>
|
1210 |
-
'bottom_clear' =>
|
1211 |
'bottom_margin_top' => '3',
|
1212 |
'bottom_margin_bottom' => '3',
|
1213 |
// widgets
|
26 |
$adinj_warning_msg_filewrite = "";
|
27 |
|
28 |
function adinj_checkNonce(){
|
29 |
+
if (!empty($_POST) && check_admin_referer('_adinj_form')){
|
30 |
+
// ok
|
31 |
+
} else {
|
32 |
+
echo 'Ad Injection: Nonce check has failed.';
|
33 |
exit();
|
34 |
}
|
35 |
}
|
113 |
$sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false';
|
114 |
$debug_mode = adinj_ticked('debug_mode')?'true':'false';
|
115 |
|
116 |
+
// TODO remove these from config file later...
|
117 |
$rnd_func = adinj_add_tags(NULL, 'rnd_', 'adinj_config_add_tags_rnd');
|
118 |
$top_func = adinj_add_tags(NULL, 'top_', 'adinj_config_add_tags_top');
|
119 |
$bottom_func = adinj_add_tags(NULL, 'bottom_', 'adinj_config_add_tags_bottom');
|
190 |
}
|
191 |
}
|
192 |
|
193 |
+
echo '<div class="wrap" style="width:950px;">';
|
194 |
|
195 |
if (adinj_problem_with_wpminify_check()){
|
196 |
echo '<div id="ad-injection-warning" class="error"><p><strong>';
|
227 |
|
228 |
} else {
|
229 |
echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
|
230 |
+
echo "6th January 2011: Added top/bottom spacing options for widgets and new random align option. Plus bug fixes. This release contains some 'under the hood' changes to prepare for the new features that will be released later in January. If you spot any bugs, or odd behaviour please let me know via the ".'<a href="https://spreadsheets.google.com/viewform?formkey=dFUwZzBYcG1HNzNKMmJZdWFDdFhkY0E6MQ" target="_new">feedback form</a>.';
|
231 |
echo '</strong></p></div>';
|
232 |
}
|
233 |
?>
|
363 |
<p><a href="#random">Random ads</a> | <a href="#topad">Top</a> | <a href="#bottomad">Bottom</a> | <a href="#widgets">Widgets</a> | <a href="#restrictions">Ad insert mode/dynamic restrictions</a> | <a href="#debugging">Debug</a> | <a href="#docs">Quick Start</a> | <a href="#testads">Test ads</a></p>
|
364 |
|
365 |
<form name="adinjform" method="post" action="">
|
366 |
+
<?php wp_nonce_field('_adinj_form'); ?>
|
367 |
|
368 |
|
369 |
<?php adinj_postbox_start(__("Global settings", 'adinj'), 'global'); ?>
|
538 |
<?php
|
539 |
_e("Only show top ad on pages longer than: ", 'adinj');
|
540 |
adinj_selection_box("top_ad_if_longer_than",
|
541 |
+
array(ADINJ_DISABLED, ADINJ_ALWAYS_SHOW, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000));
|
542 |
|
543 |
?>
|
544 |
|
563 |
<?php
|
564 |
_e("Only show bottom ad on pages longer than: ", 'adinj');
|
565 |
adinj_selection_box("bottom_ad_if_longer_than",
|
566 |
+
array(ADINJ_DISABLED, ADINJ_ALWAYS_SHOW, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000));
|
567 |
?>
|
568 |
|
569 |
<br clear="all"/>
|
838 |
return $status;
|
839 |
}
|
840 |
$val = $ops['top_ad_if_longer_than'];
|
841 |
+
if (adinj_disabled($val)){
|
842 |
$status[0] = 'red';
|
843 |
$status[1] = 'off';
|
844 |
} else {
|
853 |
return $status;
|
854 |
}
|
855 |
$val = $ops['bottom_ad_if_longer_than'];
|
856 |
+
if (adinj_disabled($val)){
|
857 |
$status[0] = 'red';
|
858 |
$status[1] = 'off';
|
859 |
} else {
|
911 |
return '<span style="color:'.$colour.'">●</span>';
|
912 |
}
|
913 |
|
914 |
+
function adinj_selection_box($name, $values, $type=NULL, $options=NULL, $selected_value_name=NULL){
|
915 |
echo "<select name='$name'>";
|
916 |
+
|
917 |
+
$ops = "";
|
918 |
+
if ($options != NULL){
|
919 |
+
$ops = $options;
|
920 |
+
} else {
|
921 |
+
$ops = adinj_options();
|
922 |
+
}
|
923 |
+
|
924 |
+
$selected_value = "";
|
925 |
+
if ($selected_value_name != NULL){
|
926 |
+
$selected_value = $ops[$selected_value_name];
|
927 |
+
} else {
|
928 |
+
$selected_value = $ops[$name];
|
929 |
+
}
|
930 |
+
|
931 |
foreach ($values as $value){
|
932 |
echo "<option value=\"$value\" ";
|
933 |
if($selected_value == "$value") echo 'selected="selected"';
|
936 |
} else {
|
937 |
$typetxt = $type;
|
938 |
}
|
939 |
+
if (adinj_disabled($value)) $typetxt = "";
|
940 |
echo ">$value $typetxt</option>";
|
941 |
}
|
942 |
echo "</select>";
|
1010 |
_e("Alignment", 'adinj');
|
1011 |
echo "<br />";
|
1012 |
adinj_selection_box($prefix.'align',
|
1013 |
+
array(ADINJ_DISABLED, 'left', 'center', 'right', 'float left', 'float right', 'rand lcr', 'rand float lr', 'rand all'));
|
1014 |
|
1015 |
echo "<br />";
|
1016 |
|
1017 |
_e("Clear (CSS)", 'adinj');
|
1018 |
echo "<br />";
|
1019 |
adinj_selection_box($prefix.'clear',
|
1020 |
+
array(ADINJ_DISABLED, 'left', 'right', 'both'));
|
1021 |
|
1022 |
echo "<br />";
|
1023 |
|
1024 |
+
adinj_add_margin_top_bottom_options($prefix);
|
1025 |
+
}
|
1026 |
+
|
1027 |
+
function adinj_add_margin_top_bottom_options($prefix, $options=NULL, $topname=NULL, $bottomname=NULL){
|
1028 |
+
$tname = $prefix.'margin_top';
|
1029 |
+
$bname = $prefix.'margin_bottom';
|
1030 |
+
$tdefault = NULL;
|
1031 |
+
$bdefault = NULL;
|
1032 |
+
if ($topname != NULL){
|
1033 |
+
$tname = $topname;
|
1034 |
+
$tdefault = "margin_top";
|
1035 |
+
}
|
1036 |
+
if ($bottomname != NULL){
|
1037 |
+
$bname = $bottomname;
|
1038 |
+
$bdefault = "margin_bottom";
|
1039 |
+
}
|
1040 |
+
|
1041 |
_e("Margin top", 'adinj');
|
1042 |
echo "<br />";
|
1043 |
+
adinj_selection_box($tname,
|
1044 |
+
array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options, $tdefault);
|
1045 |
|
1046 |
echo "<br />";
|
1047 |
|
1048 |
_e("Margin bottom", 'adinj');
|
1049 |
echo "<br />";
|
1050 |
+
adinj_selection_box($bname,
|
1051 |
+
array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options, $bdefault);
|
1052 |
}
|
1053 |
|
1054 |
function adinj_debug_information(){
|
1223 |
'three_ads_if_shorter_than' => ADINJ_RULE_DISABLED,
|
1224 |
'top_ad_if_longer_than' => ADINJ_RULE_DISABLED,
|
1225 |
'bottom_ad_if_longer_than' => ADINJ_RULE_DISABLED,
|
1226 |
+
'rnd_align' => ADINJ_DISABLED,
|
1227 |
+
'rnd_clear' => ADINJ_DISABLED,
|
1228 |
'rnd_margin_top' => '3',
|
1229 |
'rnd_margin_bottom' => '3',
|
1230 |
'first_paragraph_ad' => '',
|
1233 |
'max_num_of_ads_home_page' => '3',
|
1234 |
// top
|
1235 |
'ad_code_top_1' => '',
|
1236 |
+
'top_align' => ADINJ_DISABLED,
|
1237 |
+
'top_clear' => ADINJ_DISABLED,
|
1238 |
'top_margin_top' => '3',
|
1239 |
'top_margin_bottom' => '3',
|
1240 |
// bottom
|
1241 |
'ad_code_bottom_1' => '',
|
1242 |
+
'bottom_align' => ADINJ_DISABLED,
|
1243 |
+
'bottom_clear' => ADINJ_DISABLED,
|
1244 |
'bottom_margin_top' => '3',
|
1245 |
'bottom_margin_bottom' => '3',
|
1246 |
// widgets
|
ad-injection-widget.php
CHANGED
@@ -7,13 +7,12 @@ http://www.reviewmylife.co.uk/
|
|
7 |
class Ad_Injection_Widget extends WP_Widget {
|
8 |
function Ad_Injection_Widget() {
|
9 |
$widget_ops = array( 'classname' => 'adinjwidget', 'description' => 'Insert Ad Injection adverts into your sidebars/widget areas.' );
|
10 |
-
$control_ops = array( 'width' =>
|
11 |
$this->WP_Widget( 'adinj', 'Ad Injection', $widget_ops, $control_ops );
|
12 |
}
|
13 |
|
14 |
function widget( $args, $instance ) {
|
15 |
if (adinj_ads_completely_disabled_from_page()) return;
|
16 |
-
$options = adinj_options();
|
17 |
|
18 |
if ((is_home() && adinj_ticked('widget_exclude_home')) ||
|
19 |
(is_page() && adinj_ticked('widget_exclude_page')) ||
|
@@ -22,8 +21,9 @@ class Ad_Injection_Widget extends WP_Widget {
|
|
22 |
return;
|
23 |
}
|
24 |
|
25 |
-
|
26 |
-
|
|
|
27 |
return;
|
28 |
}
|
29 |
}
|
@@ -40,11 +40,11 @@ class Ad_Injection_Widget extends WP_Widget {
|
|
40 |
|
41 |
$adcode = "";
|
42 |
$include = "";
|
43 |
-
if ($
|
44 |
$include = adinj_ad_code_include();
|
45 |
-
$adcode = adinj_get_mfunc_code($this->get_ad_file_name());
|
46 |
} else {
|
47 |
-
$adcode = $advert;
|
48 |
}
|
49 |
$adcode = adinj_ad_code_eval($adcode);
|
50 |
|
@@ -62,9 +62,10 @@ class Ad_Injection_Widget extends WP_Widget {
|
|
62 |
/* Strip tags (if needed) and update the widget settings. */
|
63 |
$instance['title'] = strip_tags( $new_instance['title'] );
|
64 |
$instance['advert'] = $new_instance['advert'];
|
65 |
-
|
66 |
-
$
|
67 |
-
|
|
|
68 |
|
69 |
return $instance;
|
70 |
}
|
@@ -72,7 +73,11 @@ class Ad_Injection_Widget extends WP_Widget {
|
|
72 |
function form( $instance ) {
|
73 |
|
74 |
/* Set up some default widget settings. */
|
75 |
-
$defaults = array(
|
|
|
|
|
|
|
|
|
76 |
$instance = wp_parse_args( (array) $instance, $defaults );
|
77 |
?>
|
78 |
|
@@ -83,10 +88,14 @@ class Ad_Injection_Widget extends WP_Widget {
|
|
83 |
<span style="font-size:10px;">Make sure any label complies with your ad provider's TOS. More info for <a href="http://adsense.blogspot.com/2007/04/encouraging-clicks.html" target="_new">AdSense</a> users.</span>
|
84 |
</p>
|
85 |
|
86 |
-
<
|
|
|
87 |
<label for="<?php echo $this->get_field_id('advert'); ?>">Ad code:</label>
|
88 |
-
<textarea class="widefat" rows="12" cols="
|
89 |
-
</
|
|
|
|
|
|
|
90 |
|
91 |
<p>The following dynamic options to define who sees these adverts are on the main <a href='options-general.php?page=ad-injection.php'>Ad Injection settings page</a>. The title will however always be displayed. If you want the title to be dynamic as well you should embed it in the ad code text box.</p>
|
92 |
|
@@ -103,7 +112,7 @@ class Ad_Injection_Widget extends WP_Widget {
|
|
103 |
<?php
|
104 |
}
|
105 |
|
106 |
-
function
|
107 |
return ADINJ_AD_PATH.'/'.$this->get_ad_file_name();
|
108 |
}
|
109 |
|
7 |
class Ad_Injection_Widget extends WP_Widget {
|
8 |
function Ad_Injection_Widget() {
|
9 |
$widget_ops = array( 'classname' => 'adinjwidget', 'description' => 'Insert Ad Injection adverts into your sidebars/widget areas.' );
|
10 |
+
$control_ops = array( 'width' => 450, 'height' => 300, 'id_base' => 'adinj' );
|
11 |
$this->WP_Widget( 'adinj', 'Ad Injection', $widget_ops, $control_ops );
|
12 |
}
|
13 |
|
14 |
function widget( $args, $instance ) {
|
15 |
if (adinj_ads_completely_disabled_from_page()) return;
|
|
|
16 |
|
17 |
if ((is_home() && adinj_ticked('widget_exclude_home')) ||
|
18 |
(is_page() && adinj_ticked('widget_exclude_page')) ||
|
21 |
return;
|
22 |
}
|
23 |
|
24 |
+
$ops = adinj_options();
|
25 |
+
if ($ops['ad_insertion_mode'] == 'direct_dynamic'){
|
26 |
+
if (adshow_show_adverts() !== true){
|
27 |
return;
|
28 |
}
|
29 |
}
|
40 |
|
41 |
$adcode = "";
|
42 |
$include = "";
|
43 |
+
if ($ops['ad_insertion_mode'] == 'mfunc'){
|
44 |
$include = adinj_ad_code_include();
|
45 |
+
$adcode = adinj_get_mfunc_code($this->get_ad_file_name(), $instance);
|
46 |
} else {
|
47 |
+
$adcode = adshow_add_formatting($advert, adinj_formatting_options('widget_1', "array"));
|
48 |
}
|
49 |
$adcode = adinj_ad_code_eval($adcode);
|
50 |
|
62 |
/* Strip tags (if needed) and update the widget settings. */
|
63 |
$instance['title'] = strip_tags( $new_instance['title'] );
|
64 |
$instance['advert'] = $new_instance['advert'];
|
65 |
+
$instance['margin_top'] = $new_instance['margin_top'];
|
66 |
+
$instance['margin_bottom'] = $new_instance['margin_bottom'];
|
67 |
+
|
68 |
+
write_ad_to_file($instance['advert'], $this->get_ad_file_path());
|
69 |
|
70 |
return $instance;
|
71 |
}
|
73 |
function form( $instance ) {
|
74 |
|
75 |
/* Set up some default widget settings. */
|
76 |
+
$defaults = array(
|
77 |
+
'title' => '',
|
78 |
+
'advert' => '',
|
79 |
+
'margin_top' => ADINJ_DISABLED,
|
80 |
+
'margin_bottom' => ADINJ_DISABLED);
|
81 |
$instance = wp_parse_args( (array) $instance, $defaults );
|
82 |
?>
|
83 |
|
88 |
<span style="font-size:10px;">Make sure any label complies with your ad provider's TOS. More info for <a href="http://adsense.blogspot.com/2007/04/encouraging-clicks.html" target="_new">AdSense</a> users.</span>
|
89 |
</p>
|
90 |
|
91 |
+
<table border="0" cellspacing="5">
|
92 |
+
<tr><td style="vertical-align: top">
|
93 |
<label for="<?php echo $this->get_field_id('advert'); ?>">Ad code:</label>
|
94 |
+
<textarea class="widefat" rows="12" cols="30" id="<?php echo $this->get_field_id('advert'); ?>" name="<?php echo $this->get_field_name('advert'); ?>"><?php echo $instance['advert']; ?></textarea>
|
95 |
+
</td><td style="vertical-align: top">
|
96 |
+
<?php adinj_add_margin_top_bottom_options('widget_', $instance, $this->get_field_name('margin_top'), $this->get_field_name('margin_bottom') ); ?>
|
97 |
+
</td></tr>
|
98 |
+
</table>
|
99 |
|
100 |
<p>The following dynamic options to define who sees these adverts are on the main <a href='options-general.php?page=ad-injection.php'>Ad Injection settings page</a>. The title will however always be displayed. If you want the title to be dynamic as well you should embed it in the ad code text box.</p>
|
101 |
|
112 |
<?php
|
113 |
}
|
114 |
|
115 |
+
function get_ad_file_path(){
|
116 |
return ADINJ_AD_PATH.'/'.$this->get_ad_file_name();
|
117 |
}
|
118 |
|
ad-injection.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Ad Injection
|
4 |
Plugin URI: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
|
5 |
Description: Injects any advert (e.g. AdSense) into your WordPress posts or widget area. Restrict who sees the ads by post length, age, referrer or IP. Cache compatible.
|
6 |
-
Version: 0.9.
|
7 |
Author: reviewmylife
|
8 |
Author URI: http://www.reviewmylife.co.uk/
|
9 |
License: GPLv2
|
@@ -13,6 +13,9 @@ License: GPLv2
|
|
13 |
|
14 |
//error_reporting(E_ALL ^ E_STRICT);
|
15 |
|
|
|
|
|
|
|
16 |
// Files
|
17 |
define('ADINJ_PATH', WP_PLUGIN_DIR.'/ad-injection');
|
18 |
define('ADINJ_CONFIG_FILE', WP_CONTENT_DIR . '/ad-injection-config.php'); // same directory as WP Super Cache config file
|
@@ -22,6 +25,7 @@ define('ADINJ_AD_TOP_FILE', 'ad_top_1.txt');
|
|
22 |
define('ADINJ_AD_BOTTOM_FILE', 'ad_bottom_1.txt');
|
23 |
|
24 |
// Constants
|
|
|
25 |
define('ADINJ_RULE_DISABLED', 'Rule Disabled');
|
26 |
define('ADINJ_ALWAYS_SHOW', 'Always show');
|
27 |
//
|
@@ -33,6 +37,7 @@ $adinj_total_rand_ads_used = 0;
|
|
33 |
$adinj_total_all_ads_used = 0;
|
34 |
$adinj_data = array();
|
35 |
|
|
|
36 |
if (is_admin()){
|
37 |
require_once(ADINJ_PATH . '/ad-injection-admin.php');
|
38 |
}
|
@@ -112,17 +117,60 @@ function adinj_addsevjs_hook(){
|
|
112 |
wp_enqueue_script('adinj_sev', WP_PLUGIN_URL.'/ad-injection/adinj-sev.js', NULL, NULL, true);
|
113 |
}
|
114 |
|
115 |
-
function adinj_get_mfunc_code($adfile){
|
|
|
116 |
return "\n
|
117 |
-
<!--mfunc
|
118 |
-
<?php
|
119 |
<!--/mfunc-->
|
120 |
";
|
121 |
}
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
function adinj_ad_code_eval($ad){
|
|
|
124 |
if (stripos($ad, '<?php') !== false){
|
125 |
-
return
|
126 |
}
|
127 |
return $ad;
|
128 |
}
|
@@ -141,21 +189,21 @@ function adinj_ad_code_include(){
|
|
141 |
<!--/mfunc-->
|
142 |
";
|
143 |
}
|
144 |
-
return
|
145 |
}
|
146 |
|
147 |
function adinj_add_tags($ad, $prefix, $func=NULL){
|
148 |
$ops = adinj_options();
|
149 |
-
if ($ops[$prefix . 'align']
|
150 |
-
$ops[$prefix . 'clear']
|
151 |
-
$ops[$prefix . 'margin_top']
|
152 |
-
$ops[$prefix . 'margin_bottom']
|
153 |
$clear = "";
|
154 |
$top = "";
|
155 |
$bottom = "";
|
156 |
-
if ($ops[$prefix . 'clear']
|
157 |
-
if ($ops[$prefix . 'margin_top']
|
158 |
-
if ($ops[$prefix . 'margin_bottom']
|
159 |
$cssrules = $clear . $top . $bottom;
|
160 |
|
161 |
if ($ops[$prefix . 'align'] == 'left'){
|
@@ -191,7 +239,7 @@ function adinj_ad_code_random(){
|
|
191 |
if ($ops['ad_insertion_mode'] == 'mfunc'){
|
192 |
$ad = adinj_get_mfunc_code(ADINJ_AD_RANDOM_FILE);
|
193 |
} else {
|
194 |
-
$ad =
|
195 |
}
|
196 |
return adinj_ad_code_eval($ad);
|
197 |
}
|
@@ -203,7 +251,7 @@ function adinj_ad_code_top(){
|
|
203 |
if ($ops['ad_insertion_mode'] == 'mfunc'){
|
204 |
$ad = adinj_get_mfunc_code(ADINJ_AD_TOP_FILE);
|
205 |
} else {
|
206 |
-
$ad =
|
207 |
}
|
208 |
global $adinj_total_all_ads_used;
|
209 |
++$adinj_total_all_ads_used;
|
@@ -217,7 +265,7 @@ function adinj_ad_code_bottom(){
|
|
217 |
if ($ops['ad_insertion_mode'] == 'mfunc'){
|
218 |
$ad = adinj_get_mfunc_code(ADINJ_AD_BOTTOM_FILE);
|
219 |
} else {
|
220 |
-
$ad =
|
221 |
}
|
222 |
global $adinj_total_all_ads_used;
|
223 |
++$adinj_total_all_ads_used;
|
@@ -261,53 +309,6 @@ function adinj_adverts_disabled_flag(){
|
|
261 |
return 0;
|
262 |
}
|
263 |
|
264 |
-
//////////For runtime ads - i.e. when caching is off and config.php not loaded
|
265 |
-
function adinj_search_engine_referrers(){
|
266 |
-
$list = adinj_quote_list('ad_referrers');
|
267 |
-
return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
|
268 |
-
}
|
269 |
-
function adinj_blocked_ips(){
|
270 |
-
$list = adinj_quote_list('blocked_ips');
|
271 |
-
return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
|
272 |
-
}
|
273 |
-
function adinj_fromasearchengine(){
|
274 |
-
$referrer = $_SERVER['HTTP_REFERER'];
|
275 |
-
$searchengines = adinj_search_engine_referrers();
|
276 |
-
foreach ($searchengines as $se) {
|
277 |
-
if (stripos($referrer, $se) !== false) {
|
278 |
-
return true;
|
279 |
-
}
|
280 |
-
}
|
281 |
-
// Also return true if the visitor has recently come from a search engine
|
282 |
-
// and has the adinj cookie set.
|
283 |
-
return ($_COOKIE["adinj"]==1);
|
284 |
-
}
|
285 |
-
function adinj_blocked_ip(){
|
286 |
-
$visitorIP = $_SERVER['REMOTE_ADDR'];
|
287 |
-
return in_array($visitorIP, adinj_blocked_ips());
|
288 |
-
}
|
289 |
-
function adinj_show_adverts(){
|
290 |
-
if (adinj_blocked_ip()){
|
291 |
-
return "blockedip";
|
292 |
-
}
|
293 |
-
if (adinj_ticked('sevisitors_only')){
|
294 |
-
if (!adinj_fromasearchengine()){
|
295 |
-
return "blockedreferrer";
|
296 |
-
}
|
297 |
-
}
|
298 |
-
return true;
|
299 |
-
}
|
300 |
-
// From: Exec-PHP plugin
|
301 |
-
function adinj_eval_php($code) {
|
302 |
-
if (strlen($code) == 0) return $code;
|
303 |
-
ob_start();
|
304 |
-
eval("?>$code<?php ");
|
305 |
-
$output = ob_get_contents();
|
306 |
-
ob_end_clean();
|
307 |
-
return $output;
|
308 |
-
}
|
309 |
-
//////////For runtime ads
|
310 |
-
|
311 |
function adinj($content, $message){
|
312 |
if (!adinj_ticked('debug_mode')) return $content;
|
313 |
global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
|
@@ -422,6 +423,11 @@ function adinj_allowed_in_tag($scope){
|
|
422 |
}
|
423 |
|
424 |
function adinj_inject_hook($content){
|
|
|
|
|
|
|
|
|
|
|
425 |
if (is_feed()) return $content;
|
426 |
|
427 |
$reason = adinj_ads_completely_disabled_from_page($content);
|
@@ -432,9 +438,10 @@ function adinj_inject_hook($content){
|
|
432 |
$ops = adinj_options();
|
433 |
|
434 |
if ($ops['ad_insertion_mode'] == 'direct_dynamic'){
|
435 |
-
$showads =
|
436 |
if ($showads !== true){
|
437 |
return adinj($content, "NOADS: ad blocked at run time reason=$showads");
|
|
|
438 |
}
|
439 |
}
|
440 |
|
@@ -627,15 +634,20 @@ function adinj_num_rand_ads_to_insert($content_length){
|
|
627 |
|
628 |
function adinj_do_rule_if($rule_value, $condition, $content_length){
|
629 |
if ($rule_value == ADINJ_ALWAYS_SHOW) return true;
|
|
|
630 |
if ($condition == '>'){
|
631 |
-
return ($rule_value
|
632 |
} else if ($condition == '<'){
|
633 |
-
return ($rule_value
|
634 |
} else {
|
635 |
die("adinj_do_rule_if bad condition: $condition");
|
636 |
}
|
637 |
}
|
638 |
|
|
|
|
|
|
|
|
|
639 |
function adinj_ticked($option){
|
640 |
$ops = adinj_options();
|
641 |
if (!empty($ops[$option])) return 'checked="checked"';
|
3 |
Plugin Name: Ad Injection
|
4 |
Plugin URI: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
|
5 |
Description: Injects any advert (e.g. AdSense) into your WordPress posts or widget area. Restrict who sees the ads by post length, age, referrer or IP. Cache compatible.
|
6 |
+
Version: 0.9.5
|
7 |
Author: reviewmylife
|
8 |
Author URI: http://www.reviewmylife.co.uk/
|
9 |
License: GPLv2
|
13 |
|
14 |
//error_reporting(E_ALL ^ E_STRICT);
|
15 |
|
16 |
+
//
|
17 |
+
define('ADINJ_NO_CONFIG_FILE', 1);
|
18 |
+
|
19 |
// Files
|
20 |
define('ADINJ_PATH', WP_PLUGIN_DIR.'/ad-injection');
|
21 |
define('ADINJ_CONFIG_FILE', WP_CONTENT_DIR . '/ad-injection-config.php'); // same directory as WP Super Cache config file
|
25 |
define('ADINJ_AD_BOTTOM_FILE', 'ad_bottom_1.txt');
|
26 |
|
27 |
// Constants
|
28 |
+
define('ADINJ_DISABLED', 'Disabled');
|
29 |
define('ADINJ_RULE_DISABLED', 'Rule Disabled');
|
30 |
define('ADINJ_ALWAYS_SHOW', 'Always show');
|
31 |
//
|
37 |
$adinj_total_all_ads_used = 0;
|
38 |
$adinj_data = array();
|
39 |
|
40 |
+
require_once(ADINJ_PATH . '/adshow.php');
|
41 |
if (is_admin()){
|
42 |
require_once(ADINJ_PATH . '/ad-injection-admin.php');
|
43 |
}
|
117 |
wp_enqueue_script('adinj_sev', WP_PLUGIN_URL.'/ad-injection/adinj-sev.js', NULL, NULL, true);
|
118 |
}
|
119 |
|
120 |
+
function adinj_get_mfunc_code($adfile, $options = array()){
|
121 |
+
$options = adinj_formatting_options($adfile, "string", $options);
|
122 |
return "\n
|
123 |
+
<!--mfunc adshow_display_ad_file_v2('$adfile', NULL, array($options)) -->
|
124 |
+
<?php adshow_display_ad_file_v2('$adfile', NULL, array($options)); ?>
|
125 |
<!--/mfunc-->
|
126 |
";
|
127 |
}
|
128 |
|
129 |
+
// adname could either be the name of the adfile or the database row
|
130 |
+
function adinj_formatting_options($adname, $output_type="string", $options = array()){
|
131 |
+
$ops = adinj_options();
|
132 |
+
$align = "";
|
133 |
+
$clear = "";
|
134 |
+
$margin_top = "";
|
135 |
+
$margin_bottom = "";
|
136 |
+
if (preg_match("/random_[\d+]/i", $adname)){
|
137 |
+
$align = $ops['rnd_align'];
|
138 |
+
$clear = $ops['rnd_clear'];
|
139 |
+
$margin_top = $ops['rnd_margin_top'];
|
140 |
+
$margin_bottom = $ops['rnd_margin_bottom'];
|
141 |
+
} else if (preg_match("/top_[\d+]/i", $adname)){
|
142 |
+
$align = $ops['top_align'];
|
143 |
+
$clear = $ops['top_clear'];
|
144 |
+
$margin_top = $ops['top_margin_top'];
|
145 |
+
$margin_bottom = $ops['top_margin_bottom'];
|
146 |
+
} else if (preg_match("/bottom_[\d+]/i", $adname)){
|
147 |
+
$align = $ops['bottom_align'];
|
148 |
+
$clear = $ops['bottom_clear'];
|
149 |
+
$margin_top = $ops['bottom_margin_top'];
|
150 |
+
$margin_bottom = $ops['bottom_margin_bottom'];
|
151 |
+
} else if (preg_match("/widget_[\d+]/i", $adname)){
|
152 |
+
$align = $options['align'];
|
153 |
+
$clear = $options['clear'];
|
154 |
+
$margin_top = $options['margin_top'];
|
155 |
+
$margin_bottom = $options['margin_bottom'];
|
156 |
+
}
|
157 |
+
|
158 |
+
if (adinj_disabled($align)) $align = "";
|
159 |
+
if (adinj_disabled($clear)) $clear = "";
|
160 |
+
if (adinj_disabled($margin_top)) $margin_top = "";
|
161 |
+
if (adinj_disabled($margin_bottom)) $margin_bottom = "";
|
162 |
+
|
163 |
+
if ($output_type == "string"){
|
164 |
+
return "'align' => '$align', 'clear' => '$clear', 'margin_top' => '$margin_top', 'margin_bottom' => '$margin_bottom'";
|
165 |
+
} else {
|
166 |
+
return array('align' => $align, 'clear' => $clear, 'margin_top' => $margin_top, 'margin_bottom' => $margin_bottom);
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
function adinj_ad_code_eval($ad){
|
171 |
+
if (strlen($ad) == 0) return $ad;
|
172 |
if (stripos($ad, '<?php') !== false){
|
173 |
+
return adshow_eval_php($ad);
|
174 |
}
|
175 |
return $ad;
|
176 |
}
|
189 |
<!--/mfunc-->
|
190 |
";
|
191 |
}
|
192 |
+
return adinj_ad_code_eval($ad);
|
193 |
}
|
194 |
|
195 |
function adinj_add_tags($ad, $prefix, $func=NULL){
|
196 |
$ops = adinj_options();
|
197 |
+
if (!adinj_disabled($ops[$prefix . 'align']) ||
|
198 |
+
!adinj_disabled($ops[$prefix . 'clear']) ||
|
199 |
+
!adinj_disabled($ops[$prefix . 'margin_top']) ||
|
200 |
+
!adinj_disabled($ops[$prefix . 'margin_bottom'])) {
|
201 |
$clear = "";
|
202 |
$top = "";
|
203 |
$bottom = "";
|
204 |
+
if (!adinj_disabled($ops[$prefix . 'clear'])) $clear="clear:" . $ops[$prefix . 'clear'] . ";";
|
205 |
+
if (!adinj_disabled($ops[$prefix . 'margin_top'])) $top="margin-top:" . $ops[$prefix . 'margin_top'] . "px;";
|
206 |
+
if (!adinj_disabled($ops[$prefix . 'margin_bottom'])) $bottom="margin-bottom:" . $ops[$prefix . 'margin_bottom'] . "px;";
|
207 |
$cssrules = $clear . $top . $bottom;
|
208 |
|
209 |
if ($ops[$prefix . 'align'] == 'left'){
|
239 |
if ($ops['ad_insertion_mode'] == 'mfunc'){
|
240 |
$ad = adinj_get_mfunc_code(ADINJ_AD_RANDOM_FILE);
|
241 |
} else {
|
242 |
+
$ad = adshow_add_formatting($ad, adinj_formatting_options('ad_code_random_1', "array"));
|
243 |
}
|
244 |
return adinj_ad_code_eval($ad);
|
245 |
}
|
251 |
if ($ops['ad_insertion_mode'] == 'mfunc'){
|
252 |
$ad = adinj_get_mfunc_code(ADINJ_AD_TOP_FILE);
|
253 |
} else {
|
254 |
+
$ad = adshow_add_formatting($ad, adinj_formatting_options('ad_code_top_1', "array"));
|
255 |
}
|
256 |
global $adinj_total_all_ads_used;
|
257 |
++$adinj_total_all_ads_used;
|
265 |
if ($ops['ad_insertion_mode'] == 'mfunc'){
|
266 |
$ad = adinj_get_mfunc_code(ADINJ_AD_BOTTOM_FILE);
|
267 |
} else {
|
268 |
+
$ad = adshow_add_formatting($ad, adinj_formatting_options('ad_code_bottom_1', "array"));
|
269 |
}
|
270 |
global $adinj_total_all_ads_used;
|
271 |
++$adinj_total_all_ads_used;
|
309 |
return 0;
|
310 |
}
|
311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
function adinj($content, $message){
|
313 |
if (!adinj_ticked('debug_mode')) return $content;
|
314 |
global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
|
423 |
}
|
424 |
|
425 |
function adinj_inject_hook($content){
|
426 |
+
global $adinj_total_rand_ads_used;
|
427 |
+
if(is_page() || is_single()){
|
428 |
+
// TODO hack for no random ads bug
|
429 |
+
$adinj_total_rand_ads_used = 0;
|
430 |
+
}
|
431 |
if (is_feed()) return $content;
|
432 |
|
433 |
$reason = adinj_ads_completely_disabled_from_page($content);
|
438 |
$ops = adinj_options();
|
439 |
|
440 |
if ($ops['ad_insertion_mode'] == 'direct_dynamic'){
|
441 |
+
$showads = adshow_show_adverts();
|
442 |
if ($showads !== true){
|
443 |
return adinj($content, "NOADS: ad blocked at run time reason=$showads");
|
444 |
+
// TODO alt content
|
445 |
}
|
446 |
}
|
447 |
|
634 |
|
635 |
function adinj_do_rule_if($rule_value, $condition, $content_length){
|
636 |
if ($rule_value == ADINJ_ALWAYS_SHOW) return true;
|
637 |
+
if (adinj_disabled($rule_value)) return false;
|
638 |
if ($condition == '>'){
|
639 |
+
return ($rule_value > $content_length);
|
640 |
} else if ($condition == '<'){
|
641 |
+
return ($rule_value < $content_length);
|
642 |
} else {
|
643 |
die("adinj_do_rule_if bad condition: $condition");
|
644 |
}
|
645 |
}
|
646 |
|
647 |
+
function adinj_disabled($value){
|
648 |
+
return $value === ADINJ_RULE_DISABLED || $value === ADINJ_DISABLED || $value === '';
|
649 |
+
}
|
650 |
+
|
651 |
function adinj_ticked($option){
|
652 |
$ops = adinj_options();
|
653 |
if (!empty($ops[$option])) return 'checked="checked"';
|
adshow.php
CHANGED
@@ -4,6 +4,7 @@ Part of the Ad Injection plugin for WordPress
|
|
4 |
http://www.reviewmylife.co.uk/
|
5 |
*/
|
6 |
|
|
|
7 |
$adinj_dir = dirname(__FILE__);
|
8 |
if (file_exists($adinj_dir.'/ad-injection-config.php')){
|
9 |
include_once($adinj_dir.'/ad-injection-config.php');
|
@@ -12,6 +13,7 @@ if (file_exists($adinj_dir.'/ad-injection-config.php')){
|
|
12 |
} else {
|
13 |
echo '<!--ADINJ DEBUG: ad-injection-config.php could not be found. Re-save your settings to re-generate it.-->';
|
14 |
}
|
|
|
15 |
|
16 |
//////////////////////////////////////////////////////////////////////////////
|
17 |
|
@@ -19,13 +21,15 @@ if (!function_exists('adshow_functions_exist')){
|
|
19 |
// Used to downgrade fatal errors to printed errors to make debugging easier
|
20 |
// and so that a problem doesn't disable the whole website.
|
21 |
function adshow_functions_exist(){
|
22 |
-
if (!
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
return true;
|
30 |
}
|
31 |
function adshow_functions_exist_impl($function){
|
@@ -37,6 +41,28 @@ function adshow_functions_exist_impl($function){
|
|
37 |
}
|
38 |
}
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
if (!function_exists('adshow_display_ad_file')){
|
41 |
function adshow_display_ad_file($adfile){
|
42 |
if (!adshow_functions_exist()){ return false; }
|
@@ -96,6 +122,139 @@ function adshow_display_ad_full_path($ad_path){
|
|
96 |
|
97 |
//////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
if (!function_exists('adshow_fromasearchengine')){
|
100 |
function adshow_fromasearchengine(){
|
101 |
if (!adshow_functions_exist()){ return false; }
|
4 |
http://www.reviewmylife.co.uk/
|
5 |
*/
|
6 |
|
7 |
+
if (!defined('ADINJ_NO_CONFIG_FILE')){
|
8 |
$adinj_dir = dirname(__FILE__);
|
9 |
if (file_exists($adinj_dir.'/ad-injection-config.php')){
|
10 |
include_once($adinj_dir.'/ad-injection-config.php');
|
13 |
} else {
|
14 |
echo '<!--ADINJ DEBUG: ad-injection-config.php could not be found. Re-save your settings to re-generate it.-->';
|
15 |
}
|
16 |
+
}
|
17 |
|
18 |
//////////////////////////////////////////////////////////////////////////////
|
19 |
|
21 |
// Used to downgrade fatal errors to printed errors to make debugging easier
|
22 |
// and so that a problem doesn't disable the whole website.
|
23 |
function adshow_functions_exist(){
|
24 |
+
if (!defined('ADINJ_NO_CONFIG_FILE')){
|
25 |
+
if (!adshow_functions_exist_impl('adinj_config_add_tags_rnd')){ return false; }
|
26 |
+
if (!adshow_functions_exist_impl('adinj_config_add_tags_top')){ return false; }
|
27 |
+
if (!adshow_functions_exist_impl('adinj_config_add_tags_bottom')){ return false; }
|
28 |
+
if (!adshow_functions_exist_impl('adinj_config_sevisitors_only')){ return false; }
|
29 |
+
if (!adshow_functions_exist_impl('adinj_config_search_engine_referrers')){ return false; }
|
30 |
+
if (!adshow_functions_exist_impl('adinj_config_blocked_ips')){ return false; }
|
31 |
+
if (!adshow_functions_exist_impl('adinj_config_debug_mode')){ return false; }
|
32 |
+
}
|
33 |
return true;
|
34 |
}
|
35 |
function adshow_functions_exist_impl($function){
|
41 |
}
|
42 |
}
|
43 |
|
44 |
+
if (defined('ADINJ_NO_CONFIG_FILE')){
|
45 |
+
function adinj_config_sevisitors_only() {
|
46 |
+
return adinj_ticked('sevisitors_only');
|
47 |
+
}
|
48 |
+
|
49 |
+
function adinj_config_search_engine_referrers() {
|
50 |
+
$list = adinj_quote_list('ad_referrers');
|
51 |
+
return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
|
52 |
+
}
|
53 |
+
|
54 |
+
function adinj_config_blocked_ips() {
|
55 |
+
$list = adinj_quote_list('blocked_ips');
|
56 |
+
return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
|
57 |
+
}
|
58 |
+
|
59 |
+
function adinj_config_debug_mode() {
|
60 |
+
return adinj_ticked('debug_mode');
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
//////////////////////////////////////////////////////////////////////////////
|
65 |
+
|
66 |
if (!function_exists('adshow_display_ad_file')){
|
67 |
function adshow_display_ad_file($adfile){
|
68 |
if (!adshow_functions_exist()){ return false; }
|
122 |
|
123 |
//////////////////////////////////////////////////////////////////////////////
|
124 |
|
125 |
+
if (!function_exists('adshow_display_ad_file_v2')){
|
126 |
+
function adshow_display_ad_file_v2($adfiles, $adfiles_frequency = array(), $options = array(), $altfiles = array(), $altfiles_frequency = array()){
|
127 |
+
if (!adshow_functions_exist()){ return false; }
|
128 |
+
if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: adshow_display_ad_file() quantity=".sizeof($adfiles)."-->\n"; }
|
129 |
+
|
130 |
+
if (empty($adfiles)){
|
131 |
+
echo "<!--ADINJ DEBUG: Error: adfiles is empty-->\n";
|
132 |
+
return false;
|
133 |
+
}
|
134 |
+
|
135 |
+
$adfile = "";
|
136 |
+
|
137 |
+
$showads = adshow_show_adverts();
|
138 |
+
if ($showads !== true){
|
139 |
+
if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: ad blocked at run time reason=$showads-->\n"; }
|
140 |
+
$alt_content_file = adshow_pick_value($altfiles, $altfiles_frequency);
|
141 |
+
if (!empty($alt_content_file)){
|
142 |
+
if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: alt content file defined:$alt_content_file-->\n"; }
|
143 |
+
$adfile = $alt_content_file;
|
144 |
+
} else {
|
145 |
+
return false;
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
if (empty($adfile)){
|
150 |
+
$adfile = adshow_pick_value($adfiles, $adfiles_frequency);
|
151 |
+
}
|
152 |
+
|
153 |
+
if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: adshow_display_ad_file($adfile)-->"; }
|
154 |
+
|
155 |
+
$plugin_dir = dirname(__FILE__);
|
156 |
+
|
157 |
+
$ad_path = dirname($plugin_dir).'/ad-injection-data/'.$adfile;
|
158 |
+
if (file_exists($ad_path)){
|
159 |
+
adshow_display_ad_full_path_v2($ad_path, $options);
|
160 |
+
return;
|
161 |
+
}
|
162 |
+
echo "
|
163 |
+
<!--ADINJ DEBUG: could not read ad: $ad_path
|
164 |
+
If you have just upgraded you may need to re-save your ads to regenerate the ad files.
|
165 |
+
-->";
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
if (!function_exists('adshow_pick_value')){
|
170 |
+
function adshow_pick_value($values, $frequency){
|
171 |
+
if (!is_array($values)){
|
172 |
+
// single value passed in
|
173 |
+
return $values;
|
174 |
+
}
|
175 |
+
$val = NULL;
|
176 |
+
|
177 |
+
// values is an array
|
178 |
+
if (empty($frequency)){
|
179 |
+
// each value has an equal chance of being picked
|
180 |
+
$val = array_rand(array_flip($values));
|
181 |
+
} else {
|
182 |
+
// each value has its own probability of being picked
|
183 |
+
$count = sizeof($values);
|
184 |
+
if ($count != sizeof($frequency)){
|
185 |
+
echo "<!--ADINJ DEBUG: size of arrays don't match ".$count."!=".sizeof($frequency)."-->";
|
186 |
+
return NULL;
|
187 |
+
}
|
188 |
+
$total = array_sum($frequency);
|
189 |
+
$rand = rand(0, $total);
|
190 |
+
$cumulative = 0;
|
191 |
+
for ($i=0; $i<$count; ++$i){
|
192 |
+
$cumulative += $frequency[$i];
|
193 |
+
if ($rand <= $cumulative){
|
194 |
+
$val = $values[$i];
|
195 |
+
if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: picked value at position $i:$val-->"; }
|
196 |
+
break;
|
197 |
+
}
|
198 |
+
}
|
199 |
+
}
|
200 |
+
return $val;
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
if (!function_exists('adshow_display_ad_full_path_v2')){
|
205 |
+
function adshow_display_ad_full_path_v2($ad_path, $ops = array()){
|
206 |
+
if (!adshow_functions_exist()){ return false; }
|
207 |
+
|
208 |
+
if (!file_exists($ad_path)){
|
209 |
+
echo "\n<!--ADINJ DEBUG: ad file does not exist: $ad_path.\nIf you have just upgraded you may need to re-save your ads to regenerate the ad files.\n-->";
|
210 |
+
return false;
|
211 |
+
}
|
212 |
+
|
213 |
+
$ad = file_get_contents($ad_path);
|
214 |
+
if ($ad === false) echo "\n<!--ADINJ DEBUG: could not read ad from file: $ad_path-->";
|
215 |
+
$ad = adshow_eval_php($ad);
|
216 |
+
echo adshow_add_formatting($ad, $ops);
|
217 |
+
}
|
218 |
+
}
|
219 |
+
|
220 |
+
if (!function_exists('adshow_add_formatting')){
|
221 |
+
function adshow_add_formatting($ad, $ops = array()){
|
222 |
+
if (strlen($ops['align']) > 0 ||
|
223 |
+
strlen($ops['clear']) > 0 ||
|
224 |
+
strlen($ops['margin_top']) > 0 ||
|
225 |
+
strlen($ops['margin_bottom']) > 0) {
|
226 |
+
$clear = "";
|
227 |
+
$top = "";
|
228 |
+
$bottom = "";
|
229 |
+
if (strlen($ops['clear']) > 0) $clear="clear:" . $ops['clear'] . ";";
|
230 |
+
if (strlen($ops['margin_top']) > 0) $top="margin-top:" . $ops['margin_top'] . "px;";
|
231 |
+
if (strlen($ops['margin_bottom']) > 0) $bottom="margin-bottom:" . $ops['margin_bottom'] . "px;";
|
232 |
+
$cssrules = $clear . $top . $bottom;
|
233 |
+
|
234 |
+
if ($ops['align'] == 'rand lcr') $ops['align'] = array_rand(array_flip(array('left', 'center', 'right')));
|
235 |
+
if ($ops['align'] == 'rand float lr') $ops['align'] = array_rand(array_flip(array('float left', 'float right')));
|
236 |
+
if ($ops['align'] == 'rand all') $ops['align'] = array_rand(array_flip(array('left', 'center', 'right', 'float left', 'float right')));
|
237 |
+
|
238 |
+
if ($ops['align'] == 'left'){
|
239 |
+
$ad = "\n<div style='float:left;" . $cssrules . "'>$ad</div><br clear='all' />";
|
240 |
+
} else if ($ops['align'] == 'center'){
|
241 |
+
$ad = "\n<div style='" . $cssrules . "'><center>$ad</center></div>";
|
242 |
+
} else if ($ops['align'] == 'right'){
|
243 |
+
$ad = "\n<div style='float:right;" . $cssrules . "'>$ad</div><br clear='all' />";
|
244 |
+
} else if ($ops['align'] == 'float left'){
|
245 |
+
$ad = "\n<div style='float:left;" . $cssrules . "margin-right:5px;'>$ad</div>";
|
246 |
+
} else if ($ops['align'] == 'float right'){
|
247 |
+
$ad = "\n<div style='float:right;" . $cssrules . "margin-left:5px;'>$ad</div>";
|
248 |
+
} else {
|
249 |
+
$ad = "\n<div style='" . $cssrules . "'>$ad</div>";
|
250 |
+
}
|
251 |
+
}
|
252 |
+
return $ad;
|
253 |
+
}
|
254 |
+
}
|
255 |
+
|
256 |
+
//////////////////////////////////////////////////////////////////////////////
|
257 |
+
|
258 |
if (!function_exists('adshow_fromasearchengine')){
|
259 |
function adshow_fromasearchengine(){
|
260 |
if (!adshow_functions_exist()){ return false; }
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: reviewmylife
|
|
3 |
Donate link: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
|
4 |
Tags: ad injection, adsense, advert injection, advert, ad, injection, advertising, affiliate, inject, injection, insert, widget, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, Adsense Injection, free
|
5 |
Requires at least: 2.8.6
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 0.9.
|
8 |
|
9 |
Injects any adverts (e.g. AdSense) into the WordPress posts or widget area. Restrict who sees ads by post length/age/referrer or IP. Cache compatible.
|
10 |
|
@@ -226,6 +226,11 @@ If you do get any errors please use the 'Report a bug or give feedback' link on
|
|
226 |
|
227 |
== Changelog ==
|
228 |
|
|
|
|
|
|
|
|
|
|
|
229 |
= 0.9.4.6 =
|
230 |
Save options in admin_menu hook so that WordPress is correctly initialised when saving. Allows 'pluggable' include to be removed, which should fix 'Cannot redeclare get_userdatabylogin' conflict with vbbridge.
|
231 |
|
@@ -309,6 +314,9 @@ Fix 'Something badly wrong in num_rand_ads_to_insert' message that occurs on pag
|
|
309 |
|
310 |
== Upgrade Notice ==
|
311 |
|
|
|
|
|
|
|
312 |
= 0.9.4.6 =
|
313 |
If you are using mfunc mode or switch to mfunc and have added ad widgets you may need to re-save them to regenerate the ad files.
|
314 |
|
3 |
Donate link: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
|
4 |
Tags: ad injection, adsense, advert injection, advert, ad, injection, advertising, affiliate, inject, injection, insert, widget, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, Adsense Injection, free
|
5 |
Requires at least: 2.8.6
|
6 |
+
Tested up to: 3.1
|
7 |
+
Stable tag: 0.9.5
|
8 |
|
9 |
Injects any adverts (e.g. AdSense) into the WordPress posts or widget area. Restrict who sees ads by post length/age/referrer or IP. Cache compatible.
|
10 |
|
226 |
|
227 |
== Changelog ==
|
228 |
|
229 |
+
= 0.9.5 =
|
230 |
+
New option to add spacing above and below widgets.
|
231 |
+
New options for randomly aligning random/top/bottom ads.
|
232 |
+
Fixes for several bugs reported over Christmas.
|
233 |
+
|
234 |
= 0.9.4.6 =
|
235 |
Save options in admin_menu hook so that WordPress is correctly initialised when saving. Allows 'pluggable' include to be removed, which should fix 'Cannot redeclare get_userdatabylogin' conflict with vbbridge.
|
236 |
|
314 |
|
315 |
== Upgrade Notice ==
|
316 |
|
317 |
+
= 0.9.5 =
|
318 |
+
New spacing/alignment options, and misc fixes.
|
319 |
+
|
320 |
= 0.9.4.6 =
|
321 |
If you are using mfunc mode or switch to mfunc and have added ad widgets you may need to re-save them to regenerate the ad files.
|
322 |
|