AdSense Manager - Version 2.6

Version Description

Download this release

Release Info

Developer mutube
Plugin Icon wp plugin AdSense Manager
Version 2.6
Comparing to
See all releases

Code changes from version 2.5 to 2.6

adsense-manager.css ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ /* Can change this */
3
+ #adsensem_dbx fieldset {
4
+ margin-bottom: 1em;
5
+ }
6
+
7
+ #adsensem_dbx h3 {
8
+ padding: 3px;
9
+ font-weight: normal;
10
+ font-size: 13px;
11
+ }
12
+
13
+ #adsensem_dbx div {
14
+ margin-top: .5em;
15
+ }
16
+
17
+ #adsensem_dbx h3.dbx-handle {
18
+ margin-left: 7px;
19
+ margin-bottom: -7px;
20
+ padding: 6px 1em 0 3px;
21
+ height: 19px;
22
+ font-size: 12px;
23
+ background: #2685af url(../../../../wp-admin/images/box-head-right.gif) no-repeat top right;
24
+ }
25
+
26
+ #adsensem_dbx div.dbx-handle-wrapper {
27
+ margin: 0 0 0 -7px;
28
+ background: #fff url(../../../../wp-admin/images/box-head-left.gif) no-repeat top left;
29
+ }
30
+
31
+ #adsensem_dbx div.dbx-content {
32
+ margin-left: 8px;
33
+ background: url(../../../../wp-admin/images/box-bg-right.gif) repeat-y right;
34
+ padding: 10px 10px 15px 0;
35
+ }
36
+
37
+ #adsensem_dbx div.dbx-content-wrapper {
38
+ margin-left: -7px;
39
+ margin-right: 0;
40
+ background: url(../../../../wp-admin/images/box-bg-left.gif) repeat-y left;
41
+ }
42
+
43
+ #adsensem_dbx fieldset.dbx-box {
44
+ padding-bottom: 9px;
45
+ margin-left: 6px;
46
+ background: url(../../../../wp-admin/images/box-butt-right.gif) no-repeat bottom right;
47
+ }
48
+
49
+ #adsensem_dbx div.dbx-box-wrapper {
50
+ background: url(../../../../wp-admin/images/box-butt-left.gif) no-repeat bottom left;
51
+ }
52
+
53
+ #adsensem_dbx .dbx-box-closed div.dbx-content-wrapper {
54
+ padding-bottom: 2px;
55
+ background: url(../../../../wp-admin/images/box-butt-left.gif) no-repeat bottom left;
56
+ }
57
+
58
+ #adsensem_dbx .dbx-box {
59
+ background: url(../../../../wp-admin/images/box-butt-right.gif) no-repeat bottom right;
60
+ }
61
+
62
+ #adsensem_dbx a.dbx-toggle, #adsensem_dbx a.dbx-toggle-open:visited {
63
+ height: 22px;
64
+ width: 22px;
65
+ top: 3px;
66
+ right: 5px;
67
+ background-position: 0 -3px;
68
+ }
69
+
70
+ #adsensem_dbx a.dbx-toggle-open, #adsensem_dbx a.dbx-toggle-open:visited {
71
+ height: 22px;
72
+ width: 22px;
73
+ top: 3px;
74
+ right: 5px;
75
+ background-position: 0 -28px;
76
+ }
77
+
78
+ #adsensem_dbx .adsensem_label{
79
+ text-align:right;
80
+ width:10em;
81
+ }
82
+
83
+ th {border-bottom:2px solid #000;font-size:smaller;}
84
+ #default-options td{border-bottom:1px solid #000;}
85
+ #manage-ads {}
86
+ #manage-ads td, #manage-ads th {padding: 1px 5px;}
87
+
88
+ .network_blanking {height:20px;}
89
+ .network_header td {border-top:1px solid #000;font-weight:bold;background-color:#ddd;}
90
+ .network_admin * {font-weight:normal; text-align:center;}
91
+ .adrow td { border-bottom:1px dotted #888 }
92
+ .adrow_name { padding-left:25px;}
93
+
94
+ .disabled { background-color:#e5e5e5;}
95
+
96
+ .shade_0 {background-color:#eee;}
97
+ .shade_1 {background-color:#f5f5f5;}
98
+
99
+ #adsensem_dbx { width:100%; }
100
+ #adsensem_dbx .formlayoutsection { vertical-align:top; width:33% }
101
+
102
+ .network_header a {border-bottom:none;text-decoration:underline;}
103
+
104
+ .Ad_AdBrite {padding-left: 25px; background: transparent url(http://files.adbrite.com/mb/images/favicon.ico) no-repeat center left; }
105
+ .Ad_AdRoll {padding-left:25px;background:url(http://www.adroll.com/i/favicon.ico) left no-repeat;}
106
+ .Ad_AdSense {padding-left:25px;background:url(http://www.google.com/favicon.ico) left no-repeat;}
107
+ .Ad_AdSense_Classic {padding-left:25px;background:url(http://www.google.com/favicon.ico) left no-repeat;}
108
+ .Ad_CJ {padding-left:25px;background:url(http://www.cj.com/favicon.ico) left no-repeat;}
109
+ .Ad_Code {padding-left:25px;background:url(./code.png) left no-repeat;}
110
+ .Ad_WidgetBucks {padding-left:25px;background:url(http://www.widgetbucks.com/favicon.ico) left no-repeat;}
111
+ .Ad_ShoppingAds {padding-left:25px;background:url(./shoppingads.png) left no-repeat;}
112
+ .Ad_Adpinion {padding-left:25px;background:url(http://www.adpinion.com/static/images/logo_small.gif) left no-repeat;}
adsense-manager.js ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ function adsensem_form_update(element){
4
+ //element is the calling element, element.id has the identifier
5
+ //detect calling form element and action accordingly
6
+ switch(element.id){
7
+ /* case 'adsensem-product':adsensem_update_product(); break; */
8
+ case 'adsensem-adformat':adsensem_update_custom(); break;
9
+ case 'adsensem-adtype':adsensem_update_formats(); break;
10
+ }
11
+ }
12
+
13
+
14
+ function adsensem_update_color(element,id,what){
15
+ target=document.getElementById(id);
16
+ switch(what) {
17
+ case 'bg': target.style.background='#' + element.value; break;
18
+ case 'title': target.style.color='#' + element.value; break;
19
+ case 'text': target.style.color='#' + element.value; break;
20
+ case 'border': target.style.border='1px solid #' + element.value; break;
21
+ case 'link': target.style.color='#' + element.value; break;
22
+ }
23
+ }
24
+
25
+ function adsensem_update_formats(){
26
+
27
+ list=new Array('adformat','linkformat','referralformat');
28
+
29
+ if(document.getElementById('adsensem-adtype')){
30
+ switch(document.getElementById('adsensem-adtype').value){
31
+ case 'ad': keep='adformat'; break;
32
+ case 'link': keep='linkformat'; break;
33
+ case 'ref_image': keep='referralformat'; break;
34
+ case 'ref_text': keep=false; break;
35
+ }
36
+
37
+ for(a=0;a<list.length;a++){
38
+ if(list[a]!=keep){ document.getElementById('adsensem-form-'+list[a]).style.display='none'; }
39
+ else { document.getElementById('adsensem-form-'+list[a]).style.display=''; }
40
+ }
41
+
42
+ }
43
+ }
44
+
45
+
46
+ function adsensem_update_custom(){
47
+
48
+ if(document.getElementById('adsensem-adformat') && document.getElementById('adsensem-settings-custom')){
49
+ format=document.getElementById('adsensem-adformat').value;
50
+
51
+ if(format=='custom'){on='';} else {on='none';}
52
+ document.getElementById('adsensem-settings-custom').style.display=on
53
+ }
54
+ }
55
+
56
+
57
+ //Initialize everything (call the display/hide functions)
58
+
59
+
60
+ addLoadEvent(function(){ adsensem_update_custom()});
61
+ addLoadEvent(function(){ adsensem_update_formats()});
62
+
63
+
64
+ //End Initialise
65
+
66
+
67
+
68
+
69
+ addLoadEvent( function() {var manager = new dbxManager( 'adsensem_dbx' );} );
70
+ addLoadEvent( function()
71
+ {
72
+ var adsensem_dbx1 = new dbxGroup(
73
+ 'adsensem_dbx1', // container ID [/-_a-zA-Z0-9/]
74
+ 'vertical', // orientation ['vertical'|'horizontal']
75
+ '7', // drag threshold ['n' pixels]
76
+ 'no', // restrict drag movement to container axis ['yes'|'no']
77
+ '10', // animate re-ordering ['n' frames per transition]
78
+ 'yes', // include open/close toggle buttons ['yes'|'no']
79
+ 'open', // default state ['open'|'closed']
80
+
81
+ 'open', // word for "open", as in "open this box"
82
+ 'close', // word for "close", as in "close this box"
83
+ 'click-down and drag to move this box', // sentence for "move this box" by mouse
84
+ 'click to %toggle% this box', // pattern-match sentence for "(open|close) this box" by mouse
85
+ 'use the arrow keys to move this box', // sentence for "move this box" by keyboard
86
+ ', or press the enter key to %toggle% it', // pattern-match sentence-fragment for "(open|close) this box" by keyboard
87
+ '%mytitle% [%dbxtitle%]' // pattern-match syntax for title-attribute conflicts
88
+ );
89
+ var adsensem_dbx2 = new dbxGroup(
90
+ 'adsensem_dbx2', // container ID [/-_a-zA-Z0-9/]
91
+ 'vertical', // orientation ['vertical'|'horizontal']
92
+ '7', // drag threshold ['n' pixels]
93
+ 'no', // restrict drag movement to container axis ['yes'|'no']
94
+ '10', // animate re-ordering ['n' frames per transition]
95
+ 'yes', // include open/close toggle buttons ['yes'|'no']
96
+ 'open', // default state ['open'|'closed']
97
+
98
+ 'open', // word for "open", as in "open this box"
99
+ 'close', // word for "close", as in "close this box"
100
+ 'click-down and drag to move this box', // sentence for "move this box" by mouse
101
+ 'click to %toggle% this box', // pattern-match sentence for "(open|close) this box" by mouse
102
+ 'use the arrow keys to move this box', // sentence for "move this box" by keyboard
103
+ ', or press the enter key to %toggle% it', // pattern-match sentence-fragment for "(open|close) this box" by keyboard
104
+ '%mytitle% [%dbxtitle%]' // pattern-match syntax for title-attribute conflicts
105
+ );
106
+ var adsensem_dbx3 = new dbxGroup(
107
+ 'adsensem_dbx3', // container ID [/-_a-zA-Z0-9/]
108
+ 'vertical', // orientation ['vertical'|'horizontal']
109
+ '7', // drag threshold ['n' pixels]
110
+ 'no', // restrict drag movement to container axis ['yes'|'no']
111
+ '10', // animate re-ordering ['n' frames per transition]
112
+ 'yes', // include open/close toggle buttons ['yes'|'no']
113
+ 'open', // default state ['open'|'closed']
114
+
115
+ 'open', // word for "open", as in "open this box"
116
+ 'close', // word for "close", as in "close this box"
117
+ 'click-down and drag to move this box', // sentence for "move this box" by mouse
118
+ 'click to %toggle% this box', // pattern-match sentence for "(open|close) this box" by mouse
119
+ 'use the arrow keys to move this box', // sentence for "move this box" by keyboard
120
+ ', or press the enter key to %toggle% it', // pattern-match sentence-fragment for "(open|close) this box" by keyboard
121
+ '%mytitle% [%dbxtitle%]' // pattern-match syntax for title-attribute conflicts
122
+ );
123
+
124
+ }
125
+ );
adsense-manager.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: AdSense Manager
4
  PLugin URI: http://wordpress.org/extend/plugins/adsense-manager/
5
  Description: Control and arrange your AdSense & Referral blocks on your Wordpress blog. With Widget and inline post support, configurable colours.
6
  Author: Martin Fitzpatrick
7
- Version: 2.5
8
  Author URI: http://www.mutube.com/
9
  */
10
 
@@ -17,7 +17,7 @@ Defaults
17
 
18
  */
19
 
20
- @define("ADSENSEM_VERSION", "2.5");
21
  @define('ADSENSEM_DIRPATH','/wp-content/plugins' . strrchr(dirname(__FILE__),'/') . "/");
22
 
23
  /*
@@ -25,13 +25,10 @@ Defaults
25
  */
26
 
27
  //Currently not used
28
- @define("ADSENSEM_MAX_ADS", 7); //Max Google Ad units
29
- @define("ADSENSEM_MAX_REFERRALS", 7); //Max Google Referral units
30
 
31
  @define("ADSENSEM_BE_NICE", 3); //Default level only, can be changed in Options/AdSense Manager
32
- //Network Code: http://am.mutube.com/ad/200x5
33
- //NYUD Code: http://am.mutube.com.nyud.net:8080/ad/200x5
34
- @define("ADSENSEM_BE_NICE_BASEURL", 'http://am.mutube.com/ad/'); //Location for Be Nice ads
35
 
36
 
37
  /* Copyright 2006 MARTIN FITZPATRICK (email : martin.fitzpatrick@gmail.com)
@@ -51,6 +48,30 @@ Defaults
51
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
52
  */
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  /*
56
 
@@ -62,25 +83,18 @@ Defaults
62
  */
63
 
64
  //Kept external for backward compatibility
65
- if(!function_exists('adsensem_status')) {
66
-
67
- function adsensem_ad($name=false) {
68
-
69
- global $adsensem;
70
-
71
- $options = get_option('plugin_adsensem');
72
- if($name===false)
73
- {$ad=$options['ads'][$options['defaults']['ad']];}
74
- else
75
- {$ad=$options['ads'][$name];}
76
-
77
- echo $adsensem->get_ad($ad,$name);
78
- }
79
-
80
  }
81
 
82
 
83
-
84
  /*
85
 
86
  INITIALISATION
@@ -89,1200 +103,173 @@ function adsensem_ad($name=false) {
89
  */
90
 
91
  class adsensem {
92
-
93
- function get_ad_inline($ad=false,$name /* passthru */) {
94
-
95
- $options = get_option('plugin_adsensem');
96
-
97
- if($ad===false){$ad=$options['ads'][$options['defaults']['ad']];}
98
- $ad=$this->merge_defaults($ad); //Apply defaults
99
-
100
- $code='';
101
- /* This test block determines whether to display the Ad in the current location.
102
- The home,single,archive,search tests only apply to Ads displayed inline,
103
- so we test for that here */
104
- if( (($ad['show-home']=='yes') && is_home()) ||
105
- (($ad['show-post']=='yes') && (is_single() || is_page())) ||
106
- (($ad['show-archive']=='yes') && is_archive()) ||
107
- (($ad['show-search']=='yes') && is_search()) )
108
- { /* We passed the test, display the Ad */
109
- $code.=$this->get_ad($ad,$name);
110
- }
111
- return $code;
112
- }
113
-
114
- function get_ad($ad=false,$name='') {
115
- global $ADSENSEM_PUBLISHER;
116
-
117
- $options = get_option('plugin_adsensem');
118
-
119
- if($ad===false){$ad=$options['ads'][$options['defaults']['ad']];}
120
- $ad=$this->merge_defaults($ad); //Apply defaults
121
-
122
- $code='';
123
-
124
- /* Valid entry */
125
- if(is_array($ad)){
126
-
127
- //Default to Ad
128
- if($ad['product']=='link'){
129
- $format = $ad['linkformat'] . $ad['linktype'];
130
- list($width,$height,$null)=split('[x]',$ad['linkformat']);
131
- } else if($ad['product']=='referral-image') {
132
- $format = $ad['referralformat'] . '_as_rimg';
133
- list($width,$height,$null)=split('[x]',$ad['referralformat']);
134
- } else if($ad['product']=='referral-text') {
135
- $format = 'ref_text';
136
- } else {
137
- $format = $ad['adformat'] . '_as';
138
- list($width,$height,$null)=split('[x]',$ad['adformat']);
139
-
140
- //BENICE: Only display image/banner ads to avoid Google requirement for text ads to look different
141
- if( ($ad['adtype'] == 'text_image') || ($ad['adtype'] == 'image') ) {
142
-
143
- if(rand(1,100)<=$options['be-nice']){
144
- //$benicead = $this->be_nice_url($ad);
145
- $ad['product']='code'; //Override the actual ad format
146
- $ad['code'] = $this->be_nice_code($ad); //'<iframe frameborder="0" scrolling="no" src="' . $benicead . '" width="' . $width . '" height="' . $height . '"></iframe>';
147
- } else if( ($ad['alternate-url']=="") && ($ad['alternate-color']=="") && ($options['be-nice']!=0) ){
148
- //Output Be Nice Alternate Ad url? Only if none has been specified & it's valid place to do it. Sorted.
149
- $ad['alternate-url'] = $this->be_nice_url($ad);
150
- }
151
-
152
- }
153
- }
154
-
155
- $code .= $ad['html-before'];
156
-
157
- if($_GET['preview']){
158
-
159
- /* We are in the editor, output fake */
160
- if($ad['product']=='code'){
161
- //Complicated to extract dimensions from code, for now just output "default" sized object.
162
- $code .= '<div style="text-align:center;border:1px solid #000;font-size:25px;width:250px;height:100px">';
163
- $code .= 'AdSense Code Unit<br />#' . $name;
164
- $code .= '</div>';
165
- } else if($ad['product']=='referral-text'){
166
- //Text link referral
167
- $code .= '<span style="text-decoration:underline;color:#00f">AdSense Referral Link #' . $name . '</span>';
168
- } else {
169
- /* We are in the editor, output fake */
170
-
171
- /* Thanks to silverblood for the font-size bugfix: http://wordpress.org/support/topic/130523 */
172
- $font_size = (round($width/4,0) < round($height/4,0) )? round($width/4,0) : round($height/4,0);
173
- $code .= '<div style="text-align:center;border:1px solid #000;font-size:' . $font_size . 'px;width:' . $width . 'px;height:' . $height . 'px">';
174
- $code .= 'AdSense ' . ucwords(str_replace("-"," ",$ad['product'])) . '<br />#' . $name;
175
- $code .= '</div>';
176
- }
177
-
178
- } else {
179
-
180
- if($ad['product']=='code'){
181
- $code.=$ad['code'];
182
- } else {
183
-
184
- $code .= '<script type="text/javascript"><!--' . "\n";
185
- $code.= 'google_ad_client = "pub-' . $options['adsense-account'] . '";' . "\n";
186
-
187
- if($ad['channel']!==''){ $code.= 'google_ad_channel = "' . $ad['channel'] . '";' . "\n"; }
188
-
189
- if(($ad['product']=='ad') || ($ad['product']=='link') || ($ad['product']=='referral-image')){
190
- $code.= 'google_ad_width = ' . $width . ";\n";
191
- $code.= 'google_ad_height = ' . $height . ";\n";
192
- }
193
-
194
- $code.= 'google_ad_format = "' . $format . '"' . ";\n";
195
-
196
- if($ad['alternate-url']!=''){ $code.= 'google_alternate_ad_url = "' . $ad['alternate-url'] . '";' . "\n";}
197
- else if($ad['alternate-color']!=''){ $code.= 'google_alternate_color = "' . $ad['alternate-color'] . '";' . "\n";}
198
-
199
- //Default to Ads
200
- if($ad['product']=='ad'){ $code.= 'google_ad_type = "' . $ad['adtype'] . '"' . ";\n"; }
201
-
202
- if($ad['product']=='referral-text'){$code.='google_ad_output = "textlink"' . ";\n";}
203
- if(($ad['product']=='referral-text') || ($ad['product']=='referral-image')){$code.='google_cpa_choice = "' . $ad['referral'] . '"' . ";\n";}
204
-
205
- if(($ad['product']=='ad') || ($ad['product']=='link')){
206
- $code.= 'google_color_border = "' . $ad['colors']['border'] . '"' . ";\n";
207
- $code.= 'google_color_bg = "' . $ad['colors']['bg'] . '"' . ";\n";
208
- $code.= 'google_color_link = "' . $ad['colors']['link'] . '"' . ";\n";
209
- $code.= 'google_color_text = "' . $ad['colors']['text'] . '"' . ";\n";
210
- $code.= 'google_color_url = "' . $ad['colors']['url'] . '"' . ";\n";
211
- }
212
-
213
- $code.= "\n" . '//--></script>' . "\n";
214
-
215
- $code.= '<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>' . "\n";
216
-
217
- }
218
-
219
- }
220
-
221
- $code.=$ad['html-after'];
222
-
223
- }
224
-
225
-
226
- return $code;
227
- }
228
-
229
- /* ADMIN ELEMENTS - REUSABLE PAGE ELEMENTS FOR CONFIGURATION */
230
-
231
- function set_defaults($options,$wipebasic=false) {
232
-
233
- $options['defaults'] = array (
234
- 'colors' => array(
235
- 'border'=> 'FFFFFF',
236
- 'link' => '0000FF',
237
- 'bg' => 'FFFFFF',
238
- 'text' => '000000',
239
- 'url' => '008000'
240
- ),
241
- 'channel' => '',
242
-
243
- 'adformat' => '250x250',
244
- 'adtype' => 'text_image',
245
-
246
- 'linkformat' => '120x90',
247
- 'linktype' => '_0ads_al_s',
248
-
249
- 'show-home' => "yes",
250
- 'show-post' => "yes",
251
- 'show-archive' => "yes",
252
- 'show-search' => "yes",
253
-
254
- 'html-before' => '',
255
- 'html-after' => '',
256
-
257
- 'alternate-url' => '',
258
- 'alternate-color' => ''
259
-
260
- );
261
-
262
- if($wipebasic===true){
263
- $options['ads'] = array(
264
- 'demo-advert' => array()
265
- );
266
- $options['adsense-account']="";
267
-
268
- /* Rate is the % rate (below is the default) at which donation is made */
269
- $options['be-nice']= ADSENSEM_BE_NICE;
270
-
271
- $options['defaults']['ad'] = 'demo-advert';
272
- }
273
-
274
- return $options;
275
- }
276
-
277
- //Set up the alternate ad if it's ok to do it for this type of unit
278
- function be_nice_url($ad){
279
- $options = get_option('plugin_adsensem');
280
- $url = ADSENSEM_BE_NICE_BASEURL . $ad['adformat']; //this url will load up a network ad in the right format
281
- return $url;
282
- }
283
-
284
- function be_nice_code($ad){
285
- $adcodes = array(
286
- '728x90' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/3AXX4RVIJBCHRJTPUJHXAJ/',
287
- '468x60' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/IPCY22UCBBFBVL6HIN6X2D/',
288
- '234x60' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/H5I4KYMJE5AZFABWUYC3O3/',
289
- '120x600' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/YR67VMQYNZCUHEUPVTUTNQ/',
290
- '160x600' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/ZIQDD3H3VFA7VHXCUGEE25/',
291
- '120x240' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/F5LF4IJ5PNBJNP5534J27B/',
292
- '336x280' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/CDY6KUEZTJGO7G75A2DXJK/',
293
- '300x250' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/OMIHBI7XUBAOXLS2DRAQ4G/',
294
- '250x250' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/BOMAKAPVURD2JILCSXQ22K/',
295
- '200x200' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/P7643ZUKQ5BYDLNG6TKLMX/', //180x150 duplicated
296
- '180x150' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/P7643ZUKQ5BYDLNG6TKLMX/',
297
- '125x125' => 'http://re.adroll.com/a/D44UNLTJPNH5ZDXTTXII7V/7L73RCFU5VCG7FRNNIGH7O/'
298
- );
299
-
300
- return '<script type="text/javascript" src="' . $adcodes[$ad['adformat']] . '"></script>';
301
-
302
- }
303
-
304
-
305
-
306
- /* MERGE DEFAULTS - Merge in default settings to fill gaps in Ad setup */
307
- function merge_defaults($settings) {
308
-
309
- $options = get_option('plugin_adsensem');
310
-
311
- if(is_array($options['defaults'])){
312
- foreach($options['defaults'] as $key=>$value) {
313
- if($settings[$key]==''){$settings[$key]=$value;}
314
- }
315
- }
316
-
317
- if(is_array($options['defaults']['colors'])){
318
- foreach($options['defaults']['colors'] as $key=>$value){
319
- if($settings['colors'][$key]==''){$settings['colors'][$key]=$value;}
320
- }
321
- }
322
 
323
- return $settings;
324
-
325
- }
326
-
327
- function output_select($list,$selected)
328
- {
329
- foreach($list as $key=>$value)
330
- {
331
- ?><option <?php if($key==$selected){ echo "selected"; }?> value="<?php echo $key; ?>"> <?php echo $value; ?></option><?php
332
- }
333
- }
334
-
335
- /* ADMIN Settings - Editing form for each Ad and defaults, reusable */
336
- function admin_settingsform($settings=array('colors'=>array()),$name=false)
337
- {
338
-
339
- $colors = $settings['colors'];
340
 
341
- if($settings['product']==''){$settings['product']='ad';}
342
-
343
- //Google AdSense data
344
 
345
- $formats['default']=array('' => 'Use Default');
346
-
347
- $formats['ads']['horizontal']=array('728x90' => '728 x 90 Leaderboard', '468x60' => '468 x 60 Banner', '234x60' => '234 x 60 Half Banner');
348
- $formats['ads']['vertical']=array('120x600' => '120 x 600 Skyscraper', '160x600' => '160 x 600 Wide Skyscraper', '120x240' => '120 x 240 Vertical Banner');
349
- $formats['ads']['square']=array('336x280' => '336 x 280 Large Rectangle', '300x250' => '300 x 250 Medium Rectangle', '250x250' => '250 x 250 Square', '200x200' => '200 x 200 Small Square', '180x150' => '180 x 150 Small Rectangle', '125x125' => '125 x 125 Button');
350
-
351
- $adtypes=array('text_image' => 'Text &amp; Image', 'image' => 'Image Only', 'text' => 'Text Only');
352
-
353
- $formats['links']['horizontal']=array('728x15' => '728 x 15', '468x15' => '468 x 15');
354
- $formats['links']['square']=array('200x90' => '200 x 90', '180x90' => '180 x 90', '160x90' => '160 x 90', '120x90' => '120 x 90');
355
-
356
- $linktypes=array('_0ads_al' => '4 Ads Per Unit', '_0ads_al_s' => '5 Ads Per Unit');
357
-
358
- $formats['referrals']['horizontal']=array('110x32' => '110 x 32', '120x60' => '120 x 60', '180x60' => '180 x 60', '468x60' => '468 x 60');
359
- $formats['referrals']['square']=array('125x125' => '125 x 125');
360
- $formats['referrals']['vertical']=array('120x240' => '120 x 240');
361
-
362
- $yesno=array("yes" => 'Yes', "no" => 'No');
363
- $default=array('' => 'Use Default');
364
-
365
- $products=array('ad' => 'Ad Unit','link' => 'Link Unit','referral-text' => "Referral (Text)",'referral-image' => "Referral (Image)");
366
- $productsextra=array('code' => 'Direct Code Ad');
367
- ?>
368
-
369
 
370
- <script type="text/javascript">
 
 
371
 
372
- function adsensem_set_color(element,id,what){
373
- target=document.getElementById(id);
374
- switch(what) {
375
- case 'bg': target.style.background='#' + element.value; break;
376
- case 'color': target.style.color='#' + element.value; break;
377
- case 'border': target.style.border='1px solid #' + element.value; break;
378
- }
379
  }
380
-
381
- function adsensem_product_options(product){
382
-
383
- all=Array('ad','link','color','referral','referral-format','code','alternate');
384
 
385
- switch (product){
386
- case 'link': show = Array('link','color','alternate');
387
- break;
388
- case 'ad': show = Array('ad','color','alternate');
389
- break;
390
- case 'referral-text':show = Array('referral');
391
- break;
392
- case 'referral-image':show = Array('referral','referral-format');
393
- break;
394
- case 'code': show = Array('code');
395
- break;
396
  }
397
-
398
- for(a=0;a<all.length;a++){
399
- found=false;
400
- for(s=0;s<show.length;s++){if(show[s]==all[a]){found=true;}}
401
- if(found){document.getElementById('adsensem-settings-' + all[a]).style.display=''}
402
- else {document.getElementById('adsensem-settings-' + all[a]).style.display='none'}
403
- }
404
-
405
- }
406
-
407
- </script>
408
-
409
- <table style="width:100%;">
410
- <tr valign="top"><td class="wrap">
411
-
412
- <h4>Basic</h4>
413
- <table>
414
- <?php if($name!==false){ ?>
415
- <tr><td><label for="adsensem-name">Name:</label></td>
416
- <td><input style="border:2px solid #000" name="adsensem-name" size="15" value="<?php echo htmlspecialchars($name, ENT_QUOTES); ?>" />
417
- <input name="adsensem-name-old" type="hidden" value="<?php echo htmlspecialchars($name, ENT_QUOTES); ?>" />
418
- </td></tr>
419
- <?php } ?>
420
- <tr><td><label for="adsensem-channel">Channel:</label></td>
421
- <td><input name="adsensem-channel" size="15" title="Enter multiple Channels seperated by + signs" value="<?php echo htmlspecialchars($settings['channel'], ENT_QUOTES); ?>" /></td></tr>
422
-
423
- <?php if($name!==false){ ?>
424
- <tr><td><label for="adsensem-product">Product:</label></td>
425
- <td><select name="adsensem-product" onchange="adsensem_product_options(this.value);">
426
- <optgroup label="Google">
427
- <?php $this->output_select($products,$settings['product']);?>
428
- </optgroup>
429
- <optgroup label="Extra">
430
- <?php $this->output_select($productsextra,$settings['product']);?>
431
- </optgroup>
432
- </select></tr>
433
- <?php } ?>
434
- </table>
435
-
436
- <div id="adsensem-settings-ad">
437
- <h4>Ad Unit Settings</h4>
438
- <table style="padding-bottom:1em;">
439
- <tr id="row-adformat"><td><label for="adsensem-adformat"><a href="https://www.google.com/adsense/adformats" target="_new">Format:</a></label></td>
440
- <td>
441
- <select name="adsensem-adformat">
442
- <!-- Options taken from Google AdSense setup pages -->
443
- <?php if($name!==false){ ?><optgroup label="Default"><?php $this->output_select($formats['default'],$settings['adformat']);?></optgroup><?php } ?>
444
- <optgroup label="Horizontal"><?php $this->output_select($formats['ads']['horizontal'],$settings['adformat']);?></optgroup>
445
- <optgroup label="Vertical"><?php $this->output_select($formats['ads']['vertical'],$settings['adformat']);?></optgroup>
446
- <optgroup label="Square"><?php $this->output_select($formats['ads']['square'],$settings['adformat']);?></optgroup>
447
- </select>
448
- </td></tr>
449
-
450
- <tr id="row-adtype"><td><label for="adsensem-adtype">Ad Type:</label></td>
451
- <td>
452
- <select name="adsensem-adtype">
453
- <!-- Options taken from Google AdSense setup pages -->
454
- <?php if($name!==false){ ?><?php $this->output_select($default,$settings['adtype']);?><?php } ?>
455
- <?php $this->output_select($adtypes,$settings['adtype']);?>
456
- </select>
457
- </td></tr>
458
- </table>
459
- </div>
460
-
461
- <div id="adsensem-settings-link">
462
- <h4>Link Unit Settings</h4>
463
- <table style="padding-bottom:1em;">
464
- <tr id="row-linkformat"><td><label for="adsensem-linkformat"><a href="https://www.google.com/adsense/adformats" target="_new">Format:</a></label></td>
465
- <td>
466
- <select name="adsensem-linkformat">
467
- <!-- Options taken from Google AdSense setup pages -->
468
- <?php if($name!==false){ ?><optgroup label="Default"><?php $this->output_select($formats['default'],$settings['adformat']);?></optgroup><?php } ?>
469
- <optgroup label="Horizontal"><?php $this->output_select($formats['links']['horizontal'],$settings['adformat']);?></optgroup>
470
- <optgroup label="Square"><?php $this->output_select($formats['links']['square'],$settings['adformat']);?></optgroup>
471
- </select>
472
- </td></tr>
473
-
474
- <tr id="row-linktype"><td><label for="adsensem-linktype">Link Type:</label></td>
475
- <td>
476
- <select name="adsensem-linktype">
477
- <!-- Options taken from Google AdSense setup pages -->
478
- <?php if($name!==false){ ?><?php $this->output_select($default,$settings['linktype']);?><?php } ?>
479
- <?php $this->output_select($linktypes,$settings['linktype']);?>
480
- </select>
481
- </td></tr>
482
- </table>
483
- </div>
484
-
485
- <?php //Referral units & code have no "defaults" so cannot be set up in this way
486
- if($name!==false){ ?>
487
-
488
- <div id="adsensem-settings-referral">
489
- <h4>Referral Settings</h4>
490
- <table style="padding-bottom:1em;">
491
- <tr id="adsensem-settings-referral-format"><td style="width:7em;"><label for="adsensem-referralformat"><a href="https://www.google.com/adsense/adformats" target="_new">Format:</a></label></td>
492
- <td>
493
- <select name="adsensem-referralformat" id="adsensem-referralformat">
494
- <!-- Options taken from Google AdSense setup pages -->
495
- <optgroup label="Horizontal"><?php $this->output_select($formats['referrals']['horizontal'],$settings['referralformat']);?></optgroup>
496
- <optgroup label="Square"><?php $this->output_select($formats['referrals']['square'],$settings['referralformat']);?></optgroup>
497
- <optgroup label="Vertical"><?php $this->output_select($formats['referrals']['vertical'],$settings['referralformat']);?></optgroup>
498
- </select>
499
- </td></tr>
500
-
501
- <tr><td><label for="adsensem-referral">Referral Code:</label></td>
502
- <td><input name="adsensem-referral" size="25" title="Enter referral code from Google AdSense site" value="<?php echo htmlspecialchars($settings['referral'], ENT_QUOTES); ?>" /> (CPA)</td></tr>
503
- </table>
504
- </div>
505
-
506
- <div id="adsensem-settings-code">
507
- <h4>Code Settings</h4>
508
- <table id="adsensem-settings-code" style="padding-bottom:1em;">
509
-
510
- <tr id="row-code"><td style="width:7em;"><label for="adsensem-code"><a href="https://www.google.com/adsense/adsense-products" target="_new">Ad Unit Code:</a></label></td>
511
- <td>
512
- <textarea rows="5" cols="30" name="adsensem-code"><?php echo htmlspecialchars($settings['code'], ENT_QUOTES); ?></textarea>
513
- </td></tr>
514
-
515
- <tr id="row-code-convert"><td></td><td><input type="checkbox" name="adsensem-code-convert" value="1"> <label for="adsensem-codeconvert">convert to AdSense Manager unit [<a href="#" title="Convert AdSense code into an editable AdSense Manager unit.">?</a>]</label></td></tr>
516
- </table>
517
- </div><?php } ?>
518
-
519
- </td><td class="wrap" id="adsensem-settings-color">
520
-
521
- <h4>Ad Colours</h4>
522
- <table>
523
- <tr><td><label for="adsensem-colors-border">Border:</label></td>
524
- <td>#<input name="adsensem-colors-border" onChange="adsensem_set_color(this,'ad-color-border','border');" size="6" value="<?php echo htmlspecialchars($colors['border'], ENT_QUOTES); ?>" /></td></tr>
525
- <tr><td><label for="adsensem-colors-link">Title:</label></td>
526
- <td>#<input name="adsensem-colors-link" onChange="adsensem_set_color(this,'ad-color-link','color');" size="6" value="<?php echo htmlspecialchars($colors['link'], ENT_QUOTES); ?>" /></td></tr>
527
- <tr><td><label for="adsensem-colors-bg">Background:</label></td>
528
- <td>#<input name="adsensem-colors-bg" onChange="adsensem_set_color(this,'ad-color-bg','bg');" size="6" value="<?php echo htmlspecialchars($colors['bg'], ENT_QUOTES); ?>" /></td></tr>
529
- <tr><td><label for="adsensem-colors-text">Text:</label></td>
530
- <td>#<input name="adsensem-colors-text" onChange="adsensem_set_color(this,'ad-color-text','color');" size="6" value="<?php echo htmlspecialchars($colors['text'], ENT_QUOTES); ?>" /></td></tr>
531
- <tr><td><label for="adsensem-colors-url">URL:</label></td>
532
- <td>#<input name="adsensem-colors-url" onChange="adsensem_set_color(this,'ad-color-url','color');" size="6" value="<?php echo htmlspecialchars($colors['url'], ENT_QUOTES); ?>" /></td></tr>
533
- <tr><td colspan="2">
534
-
535
- <?php
536
-
537
- //Add in default settings for display
538
- if($name!==false){
539
- $temp=$this->merge_defaults($settings);
540
- $colors = $temp['colors'];
541
- } else {
542
- $colors = $settings['colors'];
543
- }
544
-
545
- ?>
546
- <div id="ad-color-bg" style="margin-top:1em;width:160px;background: #<?php echo htmlspecialchars($colors['bg'], ENT_QUOTES); ?>;">
547
- <div id="ad-color-border" style="font: 10px arial, sans-serif; border: 1px solid #<?php echo htmlspecialchars($colors['border'], ENT_QUOTES); ?>" class="linkunit-wrapper">
548
- <div id="ad-color-link" style="color: #<?php echo htmlspecialchars($colors['link'], ENT_QUOTES); ?>; font: 11px verdana, arial, sans-serif; padding: 2px;">
549
- <b><u>Linked Title</u></b><br /></div>
550
- <div id="ad-color-text" style="color: #<?php echo htmlspecialchars($colors['text'], ENT_QUOTES); ?>; padding: 2px;" class="text">
551
- Advertiser's ad text here<br /></div>
552
- <div id="ad-color-url" style="color: #<?php echo htmlspecialchars($colors['url'], ENT_QUOTES); ?>; font: 10px verdana, arial, sans-serif; padding: 2px;">
553
- www.advertiser-url.com<br /></div>
554
- <div style="color: #000; padding: 2px;" class="rtl-safe-align-right">
555
- &nbsp;<u>Ads by Google</u></div>
556
- </div>
557
- </div>
558
- </td></tr>
559
- </table>
560
-
561
- </td><td class="adsensemcol wrap">
562
-
563
- <h4>Show Inline Ads</h4>
564
-
565
- <table>
566
- <tr><td><label for="adsensem-show-home">On Homepage</label></td>
567
- <td><select name="adsensem-show-home">
568
-
569
- <?php if($name!==false){ ?><?php $this->output_select($default,$settings['show-home']);?><?php } ?>
570
- <?php $this->output_select($yesno,$settings['show-home']);?>
571
- </select></td></tr>
572
- <tr><td><label for="adsensem-show-post">On Posts/Pages</label></td>
573
- <td><select name="adsensem-show-post">
574
- <?php if($name!==false){ ?><?php $this->output_select($default,$settings['show-post']);?><?php } ?>
575
- <?php $this->output_select($yesno,$settings['show-post']);?>
576
- </select></td></tr>
577
- <tr><td><label for="adsensem-show-archive">On Archives</label></td>
578
- <td><select name="adsensem-show-archive">
579
- <?php if($name!==false){ ?><?php $this->output_select($default,$settings['show-archive']);?><?php } ?>
580
- <?php $this->output_select($yesno,$settings['show-archive']);?>
581
- </select></td></tr>
582
- <tr><td><label for="adsensem-show-search">On Search</label></td>
583
- <td><select name="adsensem-show-search">
584
- <?php if($name!==false){ ?><?php $this->output_select($default,$settings['show-search']);?><?php } ?>
585
- <?php $this->output_select($yesno,$settings['show-search']);?>
586
- </select></td></tr>
587
- </table>
588
-
589
-
590
- <h4>HTML Markup (Optional)</h4>
591
- <table>
592
- <tr><td><label for="adsensem-html-before">Before:</label></td>
593
- <td><input name="adsensem-html-before" size="15" title="Enter HTML to be included before Ad unit" value="<?php echo htmlspecialchars($settings['html-before'], ENT_QUOTES); ?>" /></td></tr>
594
- <tr><td><label for="adsensem-html-after">After:</label></td>
595
- <td><input name="adsensem-html-after" size="15" title="Enter HTML to be included after Ad unit" value="<?php echo htmlspecialchars($settings['html-after'], ENT_QUOTES); ?>" /></td></tr>
596
- </table>
597
-
598
- <div id="adsensem-settings-alternate">
599
- <h4>Alternate Ads (Optional)</h4>
600
- <table>
601
- <tr><td><label for="adsensem-alternate-url">URL:</label></td>
602
- <td><input name="adsensem-alternate-url" size="20" title="Enter URL to alternate Ad for display when Google Ad unavailable" value="<?php echo htmlspecialchars($settings['alternate-url'], ENT_QUOTES); ?>" /></td></tr>
603
- <tr><td><label for="adsensem-alternate-color">Color:</label></td>
604
- <td>#<input name="adsensem-alternate-color" size="6" title="Enter #COLOUR to display when Google Ad unavailable" value="<?php echo htmlspecialchars($settings['alternate-color'], ENT_QUOTES); ?>" /></td></tr>
605
- </table>
606
- </div>
607
-
608
-
609
-
610
- </td></tr>
611
- </table>
612
- <?php if($name!==false){ ?>
613
- <script>adsensem_product_options('<?php echo $settings['product']; ?>');</script>
614
- <?php }
615
- }
616
-
617
- /*
618
- ADMIN FORM FUNCTIONS
619
-
620
- */
621
-
622
- /* Define basic settings for the AdSense Manager - for block control use admin_manage */
623
-
624
- function admin_options() {
625
-
626
- // Get our options and see if we're handling a form submission.
627
- $options = get_option('plugin_adsensem');
628
-
629
- if ( $_POST['adsensem-submit'] ) {
630
-
631
- $options['adsense-account']=preg_replace('/\D/','',$_POST['adsensem-adsense-account']);
632
-
633
- $options['be-nice']=max(min($_POST['adsensem-be-nice'],100),0);
634
- if(!is_numeric($options['be-nice'])){$options['be-nice'] = ADSENSEM_BE_NICE;}
635
-
636
- update_option('plugin_adsensem', $options);
637
-
638
- }
639
-
640
- // Here is our little form segment. Notice that we don't need a
641
- // complete form. This will be embedded into the existing form.
642
-
643
- ?>
644
- <form action="" method="post" id="adsensem-manage" enctype="multipart/form-data">
645
-
646
- <div class="wrap">
647
- <h2>AdSense Manager Options</h2>
648
-
649
- <p>Configure your basic settings here, such as default colours &amp; Google account settings.
650
- Once you have set up the basics, click <strong>Save &raquo;</strong> to save changes, then go to <a href="<?php echo get_bloginfo('wpurl');?>/wp-admin/edit.php?page=adsense-manager-manage">Manage &raquo; Ads</a> to create your Ad blocks.</p>
651
-
652
- <h3>Basic Setup</h3>
653
- <p>Enter your <label for="adsensem-adsense-account">Google AdSense <strong>Account ID</strong></label>: <input name="adsensem-adsense-account" value="<?php echo strip_tags(stripslashes($options['adsense-account'])); ?>"
654
- style="<?php if($options['adsense-account']!=''){echo "font-weight:bold; color:green; ";} else { echo "border:1px solid red;"; }?>">
655
-
656
- <br />You can find this number at the bottom of your <a href="https://www.google.com/adsense/account-settings" target="_new">Account Settings</a> page.</p>
657
- </p>
658
-
659
- <p class="submit"><input type="submit" value="Save changes &raquo;"></p>
660
- </div>
661
- <input type="hidden" id="adsensem-submit" name="adsensem-submit" value="1" />
662
-
663
- <div id="message" class="updated">
664
- <p style="text-align:justify;">
665
- <?php if($options['be-nice'] == 0){?>Please <a href="http://www.mutube.com/about/be-nice">Be Nice</a> and donate more than
666
- <?php } else { ?> Thankyou for <a href="http://www.mutube.com/about/be-nice">Being Nice</a> and continuing to donate <?php } ?>
667
- <input style="border:none;text-align:right;<?php if($options['be-nice']==0){ echo 'color:red;'; } ?>" name="adsensem-be-nice" value="<?php echo htmlspecialchars($options['be-nice'], ENT_QUOTES);?>" size="1">% of your Ad space to support development of this plugin [<a href="http://wordpress.org/extend/plugins/adsense-manager/faq/" target="_blank">?</a>]
668
- <?php if($options['be-nice'] == 0){?> It didn't write itself.<?php } ?>
669
- </p>
670
- </div>
671
- z <input type="hidden" id="adsensem-submit" name="adsensem-submit" value="1" />
672
-
673
- </form>
674
-
675
- <?php
676
- }
677
-
678
- function admin_adsense_code_convert() {
679
-
680
- $code=stripslashes($_POST['adsensem-code']);
681
-
682
- if(preg_match('/google_ad_channel = "(.*)"/', $code, $matches)!=0){ $_POST['adsensem-channel'] = $matches[1]; }
683
- if(preg_match('/google_alternate_ad_url = "(.*)"/', $code, $matches)!=0){ $_POST['adsensem-alternate-url'] = $matches[1]; }
684
- if(preg_match('/google_alternate_color = "(.*)"/', $code, $matches)!=0){ $_POST['adsensem-alternate-color'] = $matches[1]; }
685
-
686
- $width=false; $height=false;
687
- if(preg_match('/google_ad_width = (\d*);/', $code, $matches)!=0){ $width = $matches[1]; }
688
- if(preg_match('/google_ad_height = (\d*);/', $code, $matches)!=0){ $height = $matches[1]; }
689
- if( ($width!==false) && ($height!==false) ) { $format = $width . "x" . $height; }
690
-
691
- //as_rimg - Referral (Image)
692
- //ref_text - Referral (Text)
693
- //_0ads_al - Link Unit
694
- //_as - Ad Unit
695
-
696
- if(preg_match('/google_ad_format = "(.*)"/', $code, $matches)!=0){
697
-
698
- $adformat=$matches[1];
699
- if(strstr($adformat,'_as_rimg')!==false){
700
- preg_match('/google_cpa_choice = "(.*)"/', $code, $matches);
701
- $_POST['adsensem-referral']=$matches[1];
702
- $_POST['adsensem-product']='referral-image';
703
- $_POST['adsensem-referralformat']=$format; }
704
- else if(strstr($adformat,'ref_text')!==false){
705
- preg_match('/google_cpa_choice = "(.*)"/', $code, $matches);
706
- $_POST['adsensem-referral']=$matches[1];
707
- $_POST['adsensem-product']='referral-text';
708
- } else if(strstr($adformat,'_0adsl_al')!==false){
709
- $_POST['adsensem-product']='link';
710
- $_POST['adsensem-linkformat']=$format;
711
- if(strstr($adformat,'_0adsl_al_s')){ $_POST['linktype']="_0adsl_al_s"; } else { $_POST['linktype']="_0adsl_al"; }
712
- } else if(strstr($adformat,'_as')!==false){
713
- $_POST['adsensem-product']='ad';
714
- $_POST['adsensem-adformat']=$format;
715
  }
716
  }
717
-
718
- if(preg_match('/google_color_border = "(.*)"/', $code, $matches)!=0){$_POST['adsensem-colors-border']=$matches[1];}
719
- if(preg_match('/google_color_bg = "(.*)"/', $code, $matches)!=0){$_POST['adsensem-colors-link']=$matches[1];}
720
- if(preg_match('/google_color_link = "(.*)"/', $code, $matches)!=0){$_POST['adsensem-colors-bg']=$matches[1];}
721
- if(preg_match('/google_color_text = "(.*)"/', $code, $matches)!=0){$_POST['adsensem-colors-text']=$matches[1];}
722
- if(preg_match('/google_color_url = "(.*)"/', $code, $matches)!=0){$_POST['adsensem-colors-url']=$matches[1];}
723
-
724
  }
725
-
726
- function admin_save_settings($ad=array()) {
727
-
728
- $ad['channel']=strip_tags(stripslashes($_POST['adsensem-channel']));
729
-
730
- $ad['product']=$_POST['adsensem-product'];
731
-
732
- $ad['adformat']=strip_tags(stripslashes($_POST['adsensem-adformat']));
733
- $ad['adtype']=strip_tags(stripslashes($_POST['adsensem-adtype']));
734
-
735
- $ad['linkformat']=strip_tags(stripslashes($_POST['adsensem-linkformat']));
736
- $ad['linktype']=strip_tags(stripslashes($_POST['adsensem-linktype']));
737
-
738
- $ad['referralformat']=strip_tags(stripslashes($_POST['adsensem-referralformat']));
739
- $ad['referral']=strip_tags(stripslashes($_POST['adsensem-referral']));
740
-
741
- $ad['code']=stripslashes($_POST['adsensem-code']);
742
-
743
- $ad['html-before']=stripslashes($_POST['adsensem-html-before']);
744
- $ad['html-after']=stripslashes($_POST['adsensem-html-after']);
745
-
746
- $ad['alternate-url']=stripslashes($_POST['adsensem-alternate-url']);
747
- $ad['alternate-color']=stripslashes($_POST['adsensem-alternate-color']);
748
-
749
- $colors['border']=strip_tags(stripslashes($_POST['adsensem-colors-border']));
750
- $colors['link']=strip_tags(stripslashes($_POST['adsensem-colors-link']));
751
- $colors['bg']=strip_tags(stripslashes($_POST['adsensem-colors-bg']));
752
- $colors['text']=strip_tags(stripslashes($_POST['adsensem-colors-text']));
753
- $colors['url']=strip_tags(stripslashes($_POST['adsensem-colors-url']));
754
-
755
- $ad['colors'] = $colors;
756
-
757
- $ad['show-home']=$_POST['adsensem-show-home'];
758
- $ad['show-post']=$_POST['adsensem-show-post'];
759
- $ad['show-archive']=$_POST['adsensem-show-archive'];
760
- $ad['show-search']=$_POST['adsensem-show-search'];
761
-
762
- return $ad;
763
-
764
- }
765
-
766
-
767
- /* Define and manage AdSense ad blocks for your Wordpress setup */
768
- function admin_manage() {
769
-
770
- // Get our options and see if we're handling a form submission.
771
- $options = get_option('plugin_adsensem');
772
-
773
- if ( $_POST['adsensem-submit'] ) {
774
-
775
- if($_POST['adsensem-edit-default']) {
776
 
777
- if($_POST['adsensem-restore-defaults']){
778
- $options = $this->set_defaults($options);
779
- } else {
780
- $options['defaults']=$this->admin_save_settings($options['defaults']);
781
- }
782
-
783
- } else {
784
-
785
- if( $_POST['adsensem-code-convert'] ){
786
- //Extract code into $_POST variables, to simulate normal submission
787
- $this->admin_adsense_code_convert();
788
- }
789
-
790
- if($_POST['adsensem-name']==''){
791
- $a=0; do { $a++; $_POST['adsensem-name']='Ad-' . $a; } while (isset($options['ads'][$_POST['adsensem-name']]));
792
- }
793
-
794
- $name=sanitize_title($_POST['adsensem-name']);
795
-
796
- /* Changing the name of an Ad, copy and delete old */
797
- if($_POST['adsensem-name']!=$_POST['adsensem-name-old']){
798
- $options['ads'][$name]=$options['ads'][$_POST['adsensem-name-old']];
799
- unset($options['ads'][$_POST['adsensem-name-old']]);
800
- /* We can now use the new $name from this point forward, lovely */
801
-
802
- /* Update default if neccessary */
803
- if($options['defaults']['ad']==$_POST['adsensem-name-old']){$options['defaults']['ad']=$name;}
804
  }
 
805
 
806
- $options['ads'][$name]=$this->admin_save_settings($options['ads'][$name]);
807
- }
808
 
809
- update_option('plugin_adsensem', $options);
810
-
811
- }
812
-
813
- if ( $_POST['adsensem-delete'] ) {
814
- //Delete selected advert
815
- if($_POST['adsensem-delete-name']!=$options['defaults']['ad']){
816
- unset($options['ads'][$_POST['adsensem-delete-name']]);
817
- update_option('plugin_adsensem', $options);
818
- }
819
- }
820
-
821
- if ( $_POST['adsensem-default'] ) {
822
- //Set selected advert as default
823
- $options['defaults']['ad']=$_POST['adsensem-default-name'];
824
- update_option('plugin_adsensem', $options);
825
- }
826
-
827
- if( ( $options['defaults']['ad']=='' ) && ( count($options['ads']>0) ) ){
828
- $options['defaults']['ad']=key($options['ads']);
829
- update_option('plugin_adsensem', $options);
830
- }
831
-
832
- if ( $_POST['adsensem-copy'] ) {
833
- //Copy selected advert
834
- $a=0; do { $a++; $copyto=$_POST['adsensem-copy-name'] . '-' . $a; } while (isset($options['ads'][$copyto]));
835
- $options['ads'][$copyto]=$options['ads'][$_POST['adsensem-copy-name']];
836
- update_option('plugin_adsensem', $options);
837
  }
838
-
839
- ?>
840
- <div class="wrap">
841
- <h2>Manage Ads</h2>
842
- <p>Below are your currently created Ads. Remember to set your <strong>Google Adsense ID</strong> at <a href="<?php echo get_bloginfo('wpurl');?>/wp-admin/options-general.php?page=adsense-manager">Options &raquo; AdSense Manager</a></p>
843
-
844
- <form action="" method="post" id="adsensem-config" enctype="multipart/form-data">
845
-
846
- <input type="hidden" name="adsensem-copy-name" id="adsensem-copy-name">
847
- <input type="hidden" name="adsensem-delete-name" id="adsensem-delete-name">
848
- <input type="hidden" name="adsensem-default-name" id="adsensem-default-name">
849
- <input type="hidden" name="adsensem-edit-name" id="adsensem-edit-name">
850
-
851
- <style type="text/css">
852
- th {border-bottom:2px solid #000;}
853
- #default-options td{border-bottom:1px solid #000;}
854
- </style>
855
-
856
- <table style="width:100%;" cellspacing="0">
857
- <tr style="height:2em;"><th>Name</th><th>Channel</th><th>Product</th><th colspan="5" style="width:80px;">Colours</th><th>Format</th><th colspan="3">Admin</th></tr>
858
-
859
- <tr style="background-color:#ddd;" id="default-options">
860
- <td style="font-weight:bold;">Default Settings</td>
861
- <td><?php echo htmlspecialchars($options['defaults']['channel'], ENT_QUOTES); ?></td>
862
- <td></td>
863
- <td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['border'], ENT_QUOTES); ?>">&nbsp;</td>
864
- <td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['link'], ENT_QUOTES); ?>">&nbsp;</td>
865
- <td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['bg'], ENT_QUOTES); ?>">&nbsp;</td>
866
- <td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['text'], ENT_QUOTES); ?>">&nbsp;</td>
867
- <td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['url'], ENT_QUOTES); ?>">&nbsp;</td>
868
- <td style="width:100px;text-align:center;"><?php echo htmlspecialchars($options['defaults']['adformat'], ENT_QUOTES); ?><br /><?php echo htmlspecialchars($options['defaults']['linkformat'], ENT_QUOTES); ?></td>
869
- <td style="width:10px;"><input name="adsensem-edit" type="submit" value="Edit" onClick="document.getElementById('adsensem-edit-name').value='';"></td>
870
- <td colspan="3"></td>
871
- </tr>
872
 
873
- <?php
874
-
875
- if(sizeof($options['ads'])!=0){
876
- foreach($options['ads'] as $name=>$ad)
877
- {
878
- ?><tr <?php if($name==$options['defaults']['ad']){?>style="background-color:#eee;"<?php } ?>>
879
- <td><?php echo htmlspecialchars($name, ENT_QUOTES); ?></td>
880
- <td><?php echo htmlspecialchars($ad['channel'], ENT_QUOTES); ?></td>
881
- <td style="text-align:center;"><?php echo htmlspecialchars(ucwords(str_replace("-"," ",$ad['product'])), ENT_QUOTES); ?></td>
882
-
883
- <?php if(($ad['product']=='ad') || ($ad['product']=='link')) { ?>
884
- <td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['border'], ENT_QUOTES); ?>">&nbsp;</td>
885
- <td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['link'], ENT_QUOTES); ?>">&nbsp;</td>
886
- <td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['bg'], ENT_QUOTES); ?>">&nbsp;</td>
887
- <td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['text'], ENT_QUOTES); ?>">&nbsp;</td>
888
- <td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['url'], ENT_QUOTES); ?>">&nbsp;</td>
889
- <?php } else { ?><td colspan="5"></td><?php } ?>
890
-
891
- <td style="width:100px;text-align:center;"><?php if($ad['product']=='link'){echo htmlspecialchars($ad['linkformat'], ENT_QUOTES);} else if ($ad['product']=='ad') {echo htmlspecialchars($ad['adformat'], ENT_QUOTES);} else if ($ad['product']=='referral-image') {echo htmlspecialchars($ad['referralformat'], ENT_QUOTES);} ?></td>
892
- <td style="width:10px;"><input name="adsensem-edit" type="submit" value="Edit" onClick="document.getElementById('adsensem-edit-name').value='<?php echo $name; ?>';"></td>
893
- <td style="width:30px;"><input name="adsensem-copy" type="submit" value="+" onClick="document.getElementById('adsensem-copy-name').value='<?php echo $name; ?>';" title="Copy to new Ad unit"></td>
894
-
895
- <?php if($name!=$options['defaults']['ad']){?>
896
- <td style="width:30px"><input name="adsensem-default" type="submit" value="Set Default" onClick="document.getElementById('adsensem-default-name').value='<?php echo $name; ?>';"></td>
897
- <td style="width:30px"><input name="adsensem-delete" type="submit" value="Delete" onClick="if(confirm('Delete <?php echo $name; ?>?')){document.getElementById('adsensem-delete-name').value='<?php echo $name; ?>';} else {return false;}"></td>
898
- <?php } else { ?><td style="width:50px"><strong>Default&nbsp;Ad</strong></td><td></td><?php } ?>
899
-
900
- </tr>
901
- <?php
902
-
903
- }
904
- } else { ?><tr><td>None.</td></tr><?php }
905
- ?>
906
-
907
- </table>
908
-
909
- <p>By changing the <strong>Default settings</strong> (shown on the top line) you can update all Ads at once.
910
- <br /><strong>Default Ad</strong> indicates which Ad will be displayed when no specific ID is used. </p>
911
- <p>Ads can be included in <strong>templates</strong> using <code>&lt;?php adsensem_ad('name'); ?&gt;</code> or <code>&lt;?php adsensem_ad(); ?&gt;</code> for the default Ad.<br />
912
- Ads can be inserted into <strong>posts / pages</strong> using <code>&lt;!--adsense#name--&gt;</code> or <code>&lt;!--adsense--&gt;</code> for the default Ad.</p>
913
-
914
- <!--adsense-->
915
-
916
- </form>
917
-
918
- <br /><br />
919
-
920
- <form action="" method="post" id="adsensem-config-edit">
921
-
922
- <?php
923
-
924
- if( ($_POST['adsensem-edit']) && ($_POST['adsensem-edit-name'])=="")
925
- { $EDIT_DEFAULT = true; }
926
- else
927
- { $EDIT_DEFAULT = false; }
928
-
929
- if($_POST['adsensem-edit']){ ?>
930
-
931
- <h2>Edit '<?php echo ( $EDIT_DEFAULT )?'Default Settings':$_POST['adsensem-edit-name']; ?>'</h2>
932
- <p>Edit the settings for your Ad below. If you want to use the default settings for any element,
933
- simply leave that section unchanged.</p>
934
- <?php
935
- if( $EDIT_DEFAULT ) {
936
- $this->admin_settingsform($options['defaults'],false);
937
- } else {
938
- $this->admin_settingsform($options['ads'][$_POST['adsensem-edit-name']],$_POST['adsensem-edit-name']);
939
- }
940
-
941
- ?>
942
-
943
- <?php } else { ?>
944
- <h2>Create New</h2>
945
- <p>Enter the settings for your new Ad below. <br />If you want to use the default settings for any element,
946
- simply leave that section unchanged.</p>
947
- <?php $this->admin_settingsform(null,''); ?>
948
-
949
-
950
- <?php } ?>
951
-
952
- <input type="hidden" id="adsensem-submit" name="adsensem-submit" value="1" />
953
- <p class="submit">
954
-
955
- <?php if( $EDIT_DEFAULT ) { ?>
956
- <input name="adsensem-restore-defaults" type="submit" value="Restore Defaults &raquo;">
957
- <input type="hidden" id="adsensem-edit-default" name="adsensem-edit-default" value="1" />
958
- <?php } ?>
959
- <input type="submit" value="Save changes &raquo;">
960
-
961
- </p>
962
-
963
- </form>
964
-
965
- </div>
966
- <?php
967
-
968
-
969
-
970
- }
971
-
972
-
973
-
974
- /*
975
- IS THE WIDGET PLUGIN LOADED?
976
- If it is, then we provide Widget positioning for ease of use.
977
- */
978
-
979
 
980
  // This is the function that outputs adsensem widget.
981
- function widget($args, $n=0) {
982
-
983
  // $args is an array of strings that help widgets to conform to
984
  // the active theme: before_widget, before_title, after_widget,
985
  // and after_title are the array keys. Default tags: li and h2.
986
  extract($args);
987
-
 
988
  // Each widget can store its own options. We keep strings here.
989
- $options = get_option('plugin_adsensem');
990
- $title = $options['ads'][$n]['title'];
991
 
992
  // These lines generate our output. Widgets can be very complex
993
  // but as you can see here, they can also be very, very simple.
994
  echo $before_widget;
995
- if($title!=''){ echo $before_title . $title . $after_title; }
996
- echo $this->get_ad($options['ads'][$n]); //Output the selected ad
997
  echo $after_widget;
998
  }
999
 
1000
-
1001
-
1002
  /* Widget admin block for each Ad element on the page, allows
1003
  movement of them around the sidebar */
1004
- function widget_control($name)
1005
  {
1006
- $options = get_option('plugin_adsensem');
1007
-
1008
  if ( $_POST['adsensem-' . $name . '-submit'] ) {
 
1009
  // Remember to sanitize and format use input appropriately.
1010
- $options['ads'][$name]['title'] = strip_tags(stripslashes($_POST['adsensem-' . $name . '-title']));
1011
- update_option('plugin_adsensem', $options);
1012
  }
1013
 
1014
  ?>
1015
- <label for="adsensem-<?php echo $name; ?>-title" >Title:</label><input style="width: 200px;" id="adsensem-<?php echo $name; ?>-title" name="adsensem-<?php echo $name; ?>-title" type="text" value="<?php echo htmlspecialchars($options['ads'][$name]['title'], ENT_QUOTES);?>" />
1016
  <input type="hidden" name="adsensem-<?php echo $name; ?>-submit" value="1">
1017
  <?php
1018
 
1019
  }
1020
-
1021
- function admin_add_pages()
1022
- {
1023
- $options = get_option('plugin_adsensem');
1024
-
1025
- add_submenu_page('edit.php',"Ads", "Ads", 10, "adsense-manager-manage", array(&$this,'admin_manage'));
1026
- add_options_page("AdSense Manager Options", "AdSense Manager", 10, "adsense-manager-options", array(&$this,'admin_options'));
1027
-
1028
- /* ADMIN SECTION: WIDGET CONTROL CODE
1029
- /* If SBM installed output the Kludge functions for compatibility */
1030
- /* These use the #id pased via the module name because of inability to pass
1031
- references to functions using class definitions under SBM */
1032
 
1033
- if (function_exists('sbm_get_option') )
1034
- {register_widget_control('AdSense Ad', 'adsensem_sbm_widget_control', 300, 80);}
1035
- /* Add the blocks to the Widget panel for positioning */
1036
- else if (function_exists('wp_register_widget_control') )
1037
- {
1038
-
1039
- /* Loop through available ads and generate widget one at a time */
1040
- if(is_array($options['ads'])){
1041
-
1042
- foreach($options['ads'] as $name => $ad){
1043
- $args = array('n' => $name, 'height' => 80, 'width' => 300);
1044
- wp_register_widget_control('adsensem-' . $name,'Ad #' . $name, array(&$this,'widget_control'), $args, $name);
1045
- }
1046
- }
1047
-
1048
- }
1049
 
1050
-
 
 
 
 
 
1051
  }
1052
 
1053
 
 
1054
  /* This filter parses post content and replaces markup with the correct ad,
1055
  <!--adsense#name--> for named ad or <!--adsense--> for default */
1056
  function filter_ads($content) {
 
1057
 
1058
- $options = get_option('plugin_adsensem');
1059
-
1060
- if(is_array($options['ads'])){
1061
-
1062
  //Insert default ad first
1063
- $content=str_replace("<!--adsense-->",$this->get_ad_inline(false,'default'),$content);
1064
-
1065
- foreach($options['ads'] as $name=>$ad)
1066
- {
1067
- $content = str_replace("<!--adsense#" . $name . "-->", $this->get_ad_inline($ad,$name), $content);
1068
- }
1069
 
 
 
1070
  }
1071
 
1072
  return $content;
1073
  }
1074
 
 
1075
 
1076
- /* Editor functions */
1077
-
1078
-
1079
- /* Add button to simple editor to include AdSense code */
1080
- function admin_callback_editor()
1081
- {
1082
-
1083
- $options = get_option('plugin_adsensem');
1084
-
1085
- //Editor page, so we need to output this editor button code
1086
- if(
1087
- strpos($_SERVER['REQUEST_URI'], 'post.php')
1088
- || strpos($_SERVER['REQUEST_URI'], 'post-new.php')
1089
- || strpos($_SERVER['REQUEST_URI'], 'page.php')
1090
- || strpos($_SERVER['REQUEST_URI'], 'page-new.php')
1091
- || strpos($_SERVER['REQUEST_URI'], 'bookmarklet.php'))
1092
- {
1093
- ?>
1094
- <script language="JavaScript" type="text/javascript">
1095
- <!--
1096
- var ed_adsensem = document.createElement("select");
1097
-
1098
- ed_adsensem.setAttribute("onchange", "add_adsensem(this)");
1099
-
1100
- ed_adsensem.setAttribute("class", "ed_button");
1101
- ed_adsensem.setAttribute("title", "Select AdSense to Add to Content");
1102
- ed_adsensem.setAttribute("id", "ed_adsensem");
1103
-
1104
- adh = document.createElement("option");
1105
- adh.value='';
1106
- adh.innerHTML='AdSense...';
1107
- adh.style.fontWeight='bold';
1108
- ed_adsensem.appendChild(adh);
1109
-
1110
- def = document.createElement("option");
1111
- def.value='';
1112
- def.innerHTML='Default Ad';
1113
-
1114
- ed_adsensem.appendChild(def);
1115
- <?php
1116
-
1117
- if(sizeof($options['ads'])!=0){
1118
- foreach($options['ads'] as $name=>$ad)
1119
- {
1120
- ?> var opt = document.createElement("option");
1121
- opt.value='<?php echo $name; ?>';
1122
- opt.innerHTML='#<?php echo $name; ?>';
1123
- ed_adsensem.appendChild(opt);
1124
- <?php
1125
- }
1126
- }
1127
-
1128
- ?>
1129
- document.getElementById("ed_toolbar").insertBefore(ed_adsensem, document.getElementById("ed_spell"));
1130
-
1131
- /* Below is a Kludge for IE, which causes it to re-read the state of onChange etc. set above. Tut tut tut */
1132
- if (navigator.appName == 'Microsoft Internet Explorer') {
1133
- document.getElementById("ed_toolbar").innerHTML=document.getElementById("ed_toolbar").innerHTML;
1134
- }
1135
-
1136
- function add_adsensem(element)
1137
- {
1138
- if(element.selectedIndex!=0){
1139
-
1140
- if(element.value=='')
1141
- {adsensem_code = '<!--adsense-->';}
1142
- else
1143
- {adsensem_code = '<!--adsense#' + element.value + '-->';}
1144
-
1145
- contentField = document.getElementById("content");
1146
- if (document.selection && !window.opera) {
1147
- // IE compatibility
1148
- contentField.value += adsensem_code;
1149
- } else
1150
- if (contentField.selectionStart || contentField.selectionStart == '0') {
1151
-
1152
- var startPos = contentField.selectionStart;
1153
- var endPos = contentField.selectionEnd;
1154
- contentField.value = contentField.value.substring(0, startPos) + adsensem_code + contentField.value.substring(endPos, contentField.value.length);
1155
-
1156
- } else {
1157
 
1158
- contentField.value += adsensem_code;
1159
- }
1160
- element.selectedIndex=0;
1161
 
1162
- }
1163
- }
1164
- // -->
1165
- </script>
1166
- <?php
1167
- }
1168
-
1169
- }
 
 
 
 
 
 
 
 
 
1170
 
1171
- function activation()
1172
- {
1173
- $options = get_option('plugin_adsensem');
1174
- $updateoptions = false;
1175
-
1176
- if ( !is_array($options) ){
1177
- $options = $this->set_defaults($options,true);
1178
- $updateoptions = true;
1179
- }
1180
-
1181
- //Import from previous versions
1182
- if(!is_numeric($options['be-nice'])){ $options['be-nice'] = ADSENSEM_BE_NICE; }
1183
- $updateoptions = true;
1184
- if($updateoptions){ update_option('plugin_adsensem', $options); }
1185
 
1186
- }
1187
-
1188
- /* Initilisation */
1189
 
1190
- function init()
1191
- {
1192
- $this->activation(); //check variable basics setup on each run...
1193
-
1194
- $options = get_option('plugin_adsensem');
1195
-
1196
- add_action('admin_menu', array(&$this,'admin_add_pages'));
1197
- add_filter('the_content', array(&$this,'filter_ads'));
1198
 
1199
- add_action('admin_footer', array(&$this,'admin_callback_editor'));
1200
-
1201
- /* SITE SECTION: WIDGET DISPLAY CODE
1202
- /* If SBM installed output the Kludge functions for compatibility */
1203
- /* These use the #id pased via the module name because of inability to pass
1204
- references to functions using class definitions under SBM */
1205
- if (function_exists('sbm_get_option') )
1206
- {register_sidebar_widget('AdSense Ad', 'adsensem_sbm_widget');}
1207
- /* Add the blocks to the Widget panel for positioning WP2.2+*/
1208
- else if (function_exists('wp_register_sidebar_widget') )
1209
- {
1210
- /* Loop through available ads and generate widget one at a time */
1211
- if(is_array($options['ads'])){
1212
- foreach($options['ads'] as $name => $ad){
1213
- $args = array('n' => $name);
1214
- //$id, $name, $output_callback, $options = array()
1215
- wp_register_sidebar_widget('adsensem-' . $name,'Ad #' . $name, array(&$this,'widget'), $args, $name);
1216
- wp_register_widget_control('adsensem-' . $name,'Ad #' . $name, array(&$this,'widget_control'), 300, 80);
1217
- }
1218
- }
1219
 
1220
- } else if (function_exists('register_sidebar_widget') )
1221
- /* Add the blocks to the Widget panel for positioning pre WP2.2*/
1222
- {
1223
- /* Loop through available ads and generate widget one at a time */
1224
- if(is_array($options['ads'])){
1225
- foreach($options['ads'] as $name => $ad){
1226
- $args = array('n' => $name);
1227
- //$id, $name, $output_callback, $options = array()
1228
- $widget=array('Ad #%s', '', $name);
1229
- register_sidebar_widget($widget, array(&$this,'widget'), $name);
1230
- register_widget_control($widget, array(&$this,'widget_control'), 300, 80, $name);
1231
- }
1232
- }
1233
-
1234
- }
1235
-
1236
-
1237
-
1238
  }
1239
-
1240
-
 
 
1241
  }
 
1242
 
1243
 
1244
- $adsensem = new adsensem();
1245
-
1246
- /*
1247
- SIDEBAR MODULES COMPATIBILITY KLUDGE
1248
- These functions are external to the class above to allow compatibility with SBM
1249
- which does not allow calls to be passed to a class member.
1250
- These functions are dummy passthru's for the real functions above
1251
-
1252
- SBM also does not pass any details about the module (e.g. module name, id, etc.) to
1253
- the callback function and it is impossible to determine anything about itself.
1254
-
1255
- For this reason the name is extracted out of the title given to the SBM and
1256
- it is not possible to modify individual modules from within the module panel.
1257
- On the upside, it does work.
1258
-
1259
- */
1260
-
1261
- function adsensem_sbm_widget($args){
1262
- global $adsensem;
1263
- extract($args);
1264
- /* The module's title is in 'title'
1265
- we can extract the "name" from this
1266
- and use it to display the correct Ad.
1267
-
1268
- If no matchable title is found, use
1269
- the default Ad */
1270
-
1271
- if( preg_match ("/#(.+)(\W+|$)/", $title, $matches) > 0 )
1272
- { $adsensem->widget($args,$matches[1]); }
1273
- else { $adsensem->widget($args); }
1274
- }
1275
-
1276
- function adsensem_sbm_widget_control(){
1277
- /*Null function, unable to edit options for multiple Widgets under SBM*/
1278
- }
1279
-
1280
- /*
1281
- END DUMMY KLUDGE
1282
- */
1283
 
1284
- // Run our code later in case this loads prior to any required plugins.
1285
- add_action('plugins_loaded', array(&$adsensem,'init'));
1286
- //register_activation_hook('adsense-manager', array(&$this,'activation'));
1287
 
1288
  ?>
4
  PLugin URI: http://wordpress.org/extend/plugins/adsense-manager/
5
  Description: Control and arrange your AdSense & Referral blocks on your Wordpress blog. With Widget and inline post support, configurable colours.
6
  Author: Martin Fitzpatrick
7
+ Version: 3.0
8
  Author URI: http://www.mutube.com/
9
  */
10
 
17
 
18
  */
19
 
20
+ @define("ADSENSEM_VERSION", "3.0");
21
  @define('ADSENSEM_DIRPATH','/wp-content/plugins' . strrchr(dirname(__FILE__),'/') . "/");
22
 
23
  /*
25
  */
26
 
27
  //Currently not used
28
+ //@define("ADSENSEM_MAX_ADS", 7); //Max Google Ad units
29
+ //@define("ADSENSEM_MAX_REFERRALS", 7); //Max Google Referral units
30
 
31
  @define("ADSENSEM_BE_NICE", 3); //Default level only, can be changed in Options/AdSense Manager
 
 
 
32
 
33
 
34
  /* Copyright 2006 MARTIN FITZPATRICK (email : martin.fitzpatrick@gmail.com)
48
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
49
  */
50
 
51
+ //Now ad networks are managed by dedicated classes. How modern.
52
+ require_once('class-generic.php');
53
+
54
+ require_once('class-adsense.php'); //Adsense (using Slots, etc.)
55
+
56
+ require_once('class-adsense-classic.php'); //AdSense units pre-slot style
57
+ require_once('class-adsense-ad.php'); //AdSense Ad units pre-slot style
58
+ require_once('class-adsense-link.php'); //AdSense Link units pre-slot style
59
+ require_once('class-adsense-referral.php'); //AdSense Referral units pre-slot style
60
+
61
+ require_once('class-adpinion.php'); //Adpinion
62
+ require_once('class-adroll.php'); //AdRoll
63
+ require_once('class-adbrite.php'); //AdBrite
64
+ require_once('class-cj.php'); //Commission Junction
65
+ //require('class-ypn.php'); //Yahoo! Publisher Network - not yet supported
66
+ require_once('class-code.php'); //HTML Code
67
+ require_once('class-shoppingads.php'); //ShoppingAds
68
+ require_once('class-widgetbucks.php'); //Widgetbucks
69
+
70
+ if(is_admin()){ require_once('class-admin.php'); } //Admin interface functions (keep out while browsing main site
71
+
72
+ $_adsensem = get_option('plugin_adsensem');
73
+ $_adsensem_notices = array();
74
+
75
 
76
  /*
77
 
83
  */
84
 
85
  //Kept external for backward compatibility
86
+ if(!function_exists('adsensem_ad')) {
87
+ function adsensem_ad($name=false) {
88
+ global $_adsensem;
89
+ if($name===false)
90
+ {$ad=$_adsensem['ads'][$_adsensem['default-ad']];}
91
+ else
92
+ {$ad=$_adsensem['ads'][$name];}
93
+ echo adsensem::get_ad($ad,$name);
94
+ }
 
 
 
 
 
 
95
  }
96
 
97
 
 
98
  /*
99
 
100
  INITIALISATION
103
  */
104
 
105
  class adsensem {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
+ //STARTUP INITIALISATION
108
+ function init(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
+ global $_adsensem;
 
 
111
 
112
+ //Only run main site code if setup & functional
113
+ if(adsensem::setup_is_valid()){
114
+ add_filter('the_content', array('adsensem','filter_ads'));
115
+ add_action('wp_footer', array('adsensem','footer'));
116
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
+ add_action('admin_menu', array('adsensem_admin','init_admin'));
119
+ add_action('admin_head', array('adsensem_admin','add_header_script'));
120
+ add_action('admin_footer', array('adsensem_admin','admin_callback_editor'));
121
 
 
 
 
 
 
 
 
122
  }
 
 
 
 
123
 
124
+ function setup_is_valid(){
125
+ global $_adsensem;
126
+ if(is_array($_adsensem)){
127
+ if(is_array($_adsensem['ads'])){
128
+ if(is_object($_adsensem['ads'][$_adsensem['default-ad']])){
129
+ return true;
 
 
 
 
 
130
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  }
132
  }
133
+ return false;
 
 
 
 
 
 
134
  }
135
+
136
+ function init_widgets()
137
+ {
138
+ global $_adsensem;
139
+ /* SITE SECTION: WIDGET DISPLAY CODE
140
+ /* Add the blocks to the Widget panel for positioning WP2.2+*/
141
+ $args = array('n' => $name, 'height' => 80, 'width' => 300);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
+ if (function_exists('wp_register_sidebar_widget') )
144
+ {
145
+ /* Loop through available ads and generate widget one at a time */
146
+ if(is_array($_adsensem['ads'])){
147
+ foreach($_adsensem['ads'] as $name => $ad){
148
+ $args = array('n' => $name, 'height' => 80, 'width' => 300);
149
+ //$id, $name, $output_callback, $_adsensem = array()
150
+ wp_register_sidebar_widget('adsensem-' . $name,'Ad #' . $name, array('adsensem','widget'), $args, $name);
151
+ wp_register_widget_control('adsensem-' . $name,'Ad #' . $name, array('adsensem','widget_control'), $args, $name);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  }
153
+ }
154
 
155
+ }
 
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158