Version Description
Download this release
Release Info
Developer | mutube |
Plugin | AdSense Manager |
Version | 2.0 |
Comparing to | |
See all releases |
Code changes from version 1.8 to 2.0
- adsense-manager.php +317 -137
- readme.txt +9 -3
adsense-manager.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: AdSense Manager
|
|
4 |
PLugin URI: http://www.mutube.com/projects/wordpress/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:
|
8 |
Author URI: http://www.mutube.com/
|
9 |
*/
|
10 |
|
@@ -17,7 +17,7 @@ Defaults
|
|
17 |
|
18 |
*/
|
19 |
|
20 |
-
@define("ADSENSEM_VERSION", "
|
21 |
@define('ADSENSEM_DIRPATH','/wp-content/plugins' . strrchr(dirname(__FILE__),'/') . "/");
|
22 |
|
23 |
/*
|
@@ -28,8 +28,6 @@ Defaults
|
|
28 |
@define("ADSENSEM_MAX_ADS", 7); //Max Google Ad units
|
29 |
@define("ADSENSEM_MAX_REFERRALS", 7); //Max Google Referral units
|
30 |
|
31 |
-
|
32 |
-
|
33 |
/*
|
34 |
AdSense Manager is a plugin to help manage generating income from your Wordpress blogs. Because it's a money-generating plugin it would be nice (for me) if some of that income found
|
35 |
it's way back to supporting the development and hosting of my free plugins.
|
@@ -52,7 +50,11 @@ Developer, mutube.com
|
|
52 |
//the % defined by the user. For example, if the user specifies 5% and there
|
53 |
//are two id's defined each will get 2.5% of the niceness.
|
54 |
//You may also want to change the text on the options pages to reflect this (line 569).
|
55 |
-
|
|
|
|
|
|
|
|
|
56 |
//$ADSENSEM_PUBLISHER['adsense-id']='channel-id';
|
57 |
|
58 |
/* Copyright 2006 MARTIN FITZPATRICK (email : martin.fitzpatrick@gmail.com)
|
@@ -95,7 +97,7 @@ function adsensem_ad($name=false) {
|
|
95 |
else
|
96 |
{$ad=$options['ads'][$name];}
|
97 |
|
98 |
-
echo $adsensem->get_ad($ad);
|
99 |
}
|
100 |
|
101 |
}
|
@@ -113,7 +115,7 @@ class adsensem {
|
|
113 |
|
114 |
var $benice=true;
|
115 |
|
116 |
-
function get_ad_inline($ad=false) {
|
117 |
|
118 |
$options = get_option('plugin_adsensem');
|
119 |
|
@@ -129,79 +131,139 @@ class adsensem {
|
|
129 |
(($ad['show-archive']=='yes') && is_archive()) ||
|
130 |
(($ad['show-search']=='yes') && is_search()) )
|
131 |
{ /* We passed the test, display the Ad */
|
132 |
-
$code.=$this->get_ad($ad);
|
133 |
}
|
134 |
return $code;
|
135 |
}
|
136 |
|
137 |
-
function get_ad($ad=false) {
|
138 |
global $ADSENSEM_PUBLISHER;
|
139 |
|
140 |
$options = get_option('plugin_adsensem');
|
141 |
|
142 |
if($ad===false){$ad=$options['ads'][$options['defaults']['ad']];}
|
143 |
$ad=$this->merge_defaults($ad); //Apply defaults
|
144 |
-
|
145 |
$code='';
|
146 |
|
147 |
/* Valid entry */
|
148 |
if(is_array($ad)){
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
158 |
|
|
|
|
|
159 |
|
160 |
-
|
161 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
|
164 |
if($_GET['preview']){
|
|
|
165 |
/* We are in the editor, output fake */
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
} else {
|
170 |
|
171 |
-
$code
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
if($this->benice){
|
174 |
-
$
|
175 |
-
$
|
176 |
-
$ad['channel']=$ADSENSEM_PUBLISHER[$key];
|
177 |
}
|
178 |
-
|
179 |
-
|
|
|
180 |
$code.= 'google_ad_client = "pub-' . $options['adsense-account'] . '";' . "\n";
|
|
|
|
|
181 |
|
182 |
-
if($ad['
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
186 |
$code.= 'google_ad_format = "' . $format . '"' . ";\n";
|
187 |
|
188 |
if($ad['alternate-url']!=''){ $code.= 'google_alternate_ad_url = "' . $ad['alternate-url'] . '";' . "\n";}
|
189 |
else if($ad['alternate-color']!=''){ $code.= 'google_alternate_color = "' . $ad['alternate-color'] . '";' . "\n";}
|
190 |
|
191 |
//Default to Ads
|
192 |
-
if($ad['product']
|
193 |
-
|
194 |
-
$
|
195 |
-
$code.=
|
196 |
-
|
197 |
-
$
|
198 |
-
|
199 |
-
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
201 |
|
202 |
$code.= '<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>' . "\n";
|
|
|
|
|
|
|
203 |
}
|
204 |
-
|
|
|
205 |
|
206 |
}
|
207 |
|
@@ -282,20 +344,42 @@ class adsensem {
|
|
282 |
{
|
283 |
?><option <?php if($key==$selected){ echo "selected"; }?> value="<?php echo $key; ?>"> <?php echo $value; ?></option><?php
|
284 |
}
|
285 |
-
}
|
286 |
-
|
287 |
/* ADMIN Settings - Editing form for each Ad and defaults, reusable */
|
288 |
function admin_settingsform($settings=array('colors'=>array()),$name=false)
|
289 |
{
|
290 |
|
291 |
$colors = $settings['colors'];
|
292 |
-
|
293 |
-
// $options = get_option('plugin_adsensem');
|
294 |
-
// $defaults = $options['defaults'];
|
295 |
|
296 |
if($settings['product']==''){$settings['product']='ad';}
|
297 |
-
|
298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
|
300 |
<script type="text/javascript">
|
301 |
|
@@ -308,53 +392,39 @@ class adsensem {
|
|
308 |
}
|
309 |
}
|
310 |
|
311 |
-
function adsensem_product_options(
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
break;
|
317 |
-
case '
|
318 |
-
|
319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
}
|
321 |
|
322 |
-
|
323 |
-
|
324 |
-
document.getElementById('table-' + show + 'settings').style.display='';
|
325 |
-
|
326 |
-
|
327 |
-
}
|
328 |
-
|
329 |
</script>
|
330 |
|
331 |
<table style="width:100%;">
|
332 |
<tr valign="top"><td class="wrap">
|
333 |
|
334 |
-
<?php
|
335 |
-
|
336 |
-
$formats['default']=array('' => 'Use Default');
|
337 |
-
|
338 |
-
$formats['ads']['horizontal']=array('728x90' => '728 x 90 Leaderboard', '468x60' => '468 x 60 Banner', '234x60' => '234 x 60 Half Banner');
|
339 |
-
$formats['ads']['vertical']=array('120x600' => '120 x 600 Skyscraper', '160x600' => '160 x 600 Wide Skyscraper', '120x240' => '120 x 240 Vertical Banner');
|
340 |
-
$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');
|
341 |
-
|
342 |
-
$formats['links']['horizontal']=array('728x15' => '728 x 15', '468x15' => '468 x 15');
|
343 |
-
$formats['links']['square']=array('200x90' => '200 x 90', '180x90' => '180 x 90', '160x90' => '160 x 90', '120x90' => '120 x 90');
|
344 |
-
|
345 |
-
$adtypes=array('text_image' => 'Text & Image', 'image' => 'Image Only', 'text' => 'Text Only');
|
346 |
-
|
347 |
-
$linktypes=array('_0ads_al' => '4 Ads Per Unit', '_0ads_al_s' => '5 Ads Per Unit');
|
348 |
-
|
349 |
-
$yesno=array("yes" => 'Yes', "no" => 'No');
|
350 |
-
$default=array('' => 'Use Default');
|
351 |
-
|
352 |
-
$products=array('ad' => 'Ad Unit','link' => 'Link Unit');
|
353 |
-
?>
|
354 |
-
|
355 |
-
|
356 |
<h4>Basic</h4>
|
357 |
-
<table
|
358 |
<?php if($name!==false){ ?>
|
359 |
<tr><td><label for="adsensem-name">Name:</label></td>
|
360 |
<td><input style="border:2px solid #000" name="adsensem-name" size="15" value="<?php echo htmlspecialchars($name, ENT_QUOTES); ?>" />
|
@@ -367,14 +437,20 @@ class adsensem {
|
|
367 |
<?php if($name!==false){ ?>
|
368 |
<tr><td><label for="adsensem-product">Product:</label></td>
|
369 |
<td><select name="adsensem-product" onchange="adsensem_product_options(this.value);">
|
|
|
370 |
<?php $this->output_select($products,$settings['product']);?>
|
|
|
|
|
|
|
|
|
371 |
</select></tr>
|
372 |
<?php } ?>
|
373 |
</table>
|
374 |
|
375 |
-
<
|
376 |
-
<
|
377 |
-
<
|
|
|
378 |
<td>
|
379 |
<select name="adsensem-adformat">
|
380 |
<!-- Options taken from Google AdSense setup pages -->
|
@@ -394,10 +470,12 @@ class adsensem {
|
|
394 |
</select>
|
395 |
</td></tr>
|
396 |
</table>
|
|
|
397 |
|
398 |
-
<
|
399 |
-
|
400 |
-
<
|
|
|
401 |
<td>
|
402 |
<select name="adsensem-linkformat">
|
403 |
<!-- Options taken from Google AdSense setup pages -->
|
@@ -415,19 +493,47 @@ class adsensem {
|
|
415 |
<?php $this->output_select($linktypes,$settings['linktype']);?>
|
416 |
</select>
|
417 |
</td></tr>
|
418 |
-
|
419 |
-
|
420 |
</table>
|
|
|
421 |
|
|
|
|
|
422 |
|
423 |
-
|
424 |
-
<
|
425 |
-
|
426 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
427 |
|
428 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
<h4>Ad Colours</h4>
|
430 |
-
<table
|
431 |
<tr><td><label for="adsensem-colors-border">Border:</label></td>
|
432 |
<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>
|
433 |
<tr><td><label for="adsensem-colors-link">Title:</label></td>
|
@@ -470,7 +576,7 @@ class adsensem {
|
|
470 |
|
471 |
<h4>Show Inline Ads</h4>
|
472 |
|
473 |
-
<table
|
474 |
<tr><td><label for="adsensem-show-home">On Homepage</label></td>
|
475 |
<td><select name="adsensem-show-home">
|
476 |
|
@@ -496,26 +602,30 @@ class adsensem {
|
|
496 |
|
497 |
|
498 |
<h4>HTML Markup (Optional)</h4>
|
499 |
-
<table
|
500 |
<tr><td><label for="adsensem-html-before">Before:</label></td>
|
501 |
<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>
|
502 |
<tr><td><label for="adsensem-html-after">After:</label></td>
|
503 |
<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>
|
504 |
</table>
|
505 |
|
|
|
506 |
<h4>Alternate Ads (Optional)</h4>
|
507 |
-
<table
|
508 |
<tr><td><label for="adsensem-alternate-url">URL:</label></td>
|
509 |
<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>
|
510 |
<tr><td><label for="adsensem-alternate-color">Color:</label></td>
|
511 |
<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>
|
512 |
</table>
|
|
|
513 |
|
514 |
|
515 |
|
516 |
</td></tr>
|
517 |
</table>
|
518 |
-
<?
|
|
|
|
|
519 |
}
|
520 |
|
521 |
/*
|
@@ -575,21 +685,72 @@ class adsensem {
|
|
575 |
|
576 |
<?php
|
577 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
578 |
|
579 |
function admin_save_settings($ad=array()) {
|
580 |
|
581 |
$ad['channel']=strip_tags(stripslashes($_POST['adsensem-channel']));
|
582 |
|
583 |
-
|
584 |
$ad['product']=$_POST['adsensem-product'];
|
585 |
|
586 |
-
|
587 |
$ad['adformat']=strip_tags(stripslashes($_POST['adsensem-adformat']));
|
588 |
$ad['adtype']=strip_tags(stripslashes($_POST['adsensem-adtype']));
|
589 |
|
590 |
$ad['linkformat']=strip_tags(stripslashes($_POST['adsensem-linkformat']));
|
591 |
$ad['linktype']=strip_tags(stripslashes($_POST['adsensem-linktype']));
|
592 |
|
|
|
|
|
|
|
|
|
|
|
593 |
$ad['html-before']=stripslashes($_POST['adsensem-html-before']);
|
594 |
$ad['html-after']=stripslashes($_POST['adsensem-html-after']);
|
595 |
|
@@ -632,9 +793,13 @@ class adsensem {
|
|
632 |
|
633 |
} else {
|
634 |
|
|
|
|
|
|
|
|
|
|
|
635 |
if($_POST['adsensem-name']==''){
|
636 |
-
$a=0;
|
637 |
-
do { $a++; $_POST['adsensem-name']='Ad-' . $a; } while (isset($options['ads'][$_POST['adsensem-name']]));
|
638 |
}
|
639 |
|
640 |
$name=sanitize_title($_POST['adsensem-name']);
|
@@ -651,7 +816,7 @@ class adsensem {
|
|
651 |
|
652 |
$options['ads'][$name]=$this->admin_save_settings($options['ads'][$name]);
|
653 |
}
|
654 |
-
|
655 |
update_option('plugin_adsensem', $options);
|
656 |
|
657 |
}
|
@@ -675,6 +840,13 @@ class adsensem {
|
|
675 |
update_option('plugin_adsensem', $options);
|
676 |
}
|
677 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
678 |
?>
|
679 |
<div class="wrap">
|
680 |
<h2>Manage Ads</h2>
|
@@ -682,9 +854,10 @@ class adsensem {
|
|
682 |
|
683 |
<form action="" method="post" id="adsensem-config" enctype="multipart/form-data">
|
684 |
|
685 |
-
<input type="hidden" name="adsensem-
|
686 |
<input type="hidden" name="adsensem-delete-name" id="adsensem-delete-name">
|
687 |
<input type="hidden" name="adsensem-default-name" id="adsensem-default-name">
|
|
|
688 |
|
689 |
<style type="text/css">
|
690 |
th {border-bottom:2px solid #000;}
|
@@ -697,15 +870,15 @@ class adsensem {
|
|
697 |
<tr style="background-color:#ddd;" id="default-options">
|
698 |
<td style="font-weight:bold;">Default Settings</td>
|
699 |
<td><?php echo htmlspecialchars($options['defaults']['channel'], ENT_QUOTES); ?></td>
|
700 |
-
<td
|
701 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['border'], ENT_QUOTES); ?>"> </td>
|
702 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['link'], ENT_QUOTES); ?>"> </td>
|
703 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['bg'], ENT_QUOTES); ?>"> </td>
|
704 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['text'], ENT_QUOTES); ?>"> </td>
|
705 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['url'], ENT_QUOTES); ?>"> </td>
|
706 |
<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>
|
707 |
-
<td style="width:
|
708 |
-
<td colspan=
|
709 |
</tr>
|
710 |
|
711 |
<?php
|
@@ -716,17 +889,23 @@ class adsensem {
|
|
716 |
?><tr <?php if($name==$options['defaults']['ad']){?>style="background-color:#eee;"<?php } ?>>
|
717 |
<td><?php echo htmlspecialchars($name, ENT_QUOTES); ?></td>
|
718 |
<td><?php echo htmlspecialchars($ad['channel'], ENT_QUOTES); ?></td>
|
719 |
-
<td style="text-align:center;"><?php echo htmlspecialchars(
|
|
|
|
|
720 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['border'], ENT_QUOTES); ?>"> </td>
|
721 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['link'], ENT_QUOTES); ?>"> </td>
|
722 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['bg'], ENT_QUOTES); ?>"> </td>
|
723 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['text'], ENT_QUOTES); ?>"> </td>
|
724 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['url'], ENT_QUOTES); ?>"> </td>
|
725 |
-
|
726 |
-
|
|
|
|
|
|
|
|
|
727 |
<?php if($name!=$options['defaults']['ad']){?>
|
728 |
-
<td style="width:
|
729 |
-
<td style="width:
|
730 |
<?php } else { ?><td style="width:50px"><strong>Default Ad</strong></td><td></td><?php } ?>
|
731 |
|
732 |
</tr>
|
@@ -753,9 +932,10 @@ Ads can be inserted into <strong>posts / pages</strong> using <code><!--adsen
|
|
753 |
|
754 |
<?php
|
755 |
|
756 |
-
if( ($_POST['adsensem-edit']) && ($_POST['adsensem-edit-name'])=="")
|
757 |
-
|
758 |
-
else
|
|
|
759 |
|
760 |
if($_POST['adsensem-edit']){ ?>
|
761 |
|
@@ -854,9 +1034,15 @@ else { $EDIT_DEFAULT = false; }
|
|
854 |
{
|
855 |
add_submenu_page('edit.php',"Ads", "Ads", 10, "adsense-manager", array(&$this,'admin_manage'));
|
856 |
add_options_page("AdSense Manager Options", "AdSense Manager", 10, "adsense-manager", array(&$this,'admin_options'));
|
857 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
858 |
/* Add the blocks to the Widget panel for positioning */
|
859 |
-
if (function_exists('register_sidebar_widget') )
|
860 |
{
|
861 |
|
862 |
/* Loop through available ads and generate widget one at a time */
|
@@ -864,14 +1050,13 @@ else { $EDIT_DEFAULT = false; }
|
|
864 |
|
865 |
foreach($options['ads'] as $name => $ad){
|
866 |
$widget=array('Ad #%s', '', $name);
|
867 |
-
register_sidebar_widget($widget, array(&$this,'widget'),$name);
|
868 |
register_widget_control($widget, array(&$this,'widget_control'), 300, 80, $name);
|
869 |
}
|
870 |
}
|
871 |
|
872 |
}
|
873 |
|
874 |
-
|
875 |
}
|
876 |
|
877 |
|
@@ -884,11 +1069,11 @@ else { $EDIT_DEFAULT = false; }
|
|
884 |
if(is_array($options['ads'])){
|
885 |
|
886 |
//Insert default ad first
|
887 |
-
$content=str_replace("<!--adsense-->",$this->get_ad_inline(),$content);
|
888 |
|
889 |
foreach($options['ads'] as $name=>$ad)
|
890 |
{
|
891 |
-
$content = str_replace("<!--adsense#" . $name . "-->", $this->get_ad_inline($ad), $content);
|
892 |
}
|
893 |
|
894 |
}
|
@@ -1012,25 +1197,20 @@ else { $EDIT_DEFAULT = false; }
|
|
1012 |
|
1013 |
add_action('admin_footer', array(&$this,'admin_callback_editor'));
|
1014 |
|
|
|
1015 |
/* If SBM installed output the Kludge functions for compatibility */
|
1016 |
/* These use the #id pased via the module name because of inability to pass
|
1017 |
references to functions using class definitions under SBM */
|
1018 |
if (function_exists('sbm_get_option') )
|
1019 |
-
{
|
1020 |
-
register_sidebar_widget('AdSense Ad', 'adsensem_sbm_widget');
|
1021 |
-
register_widget_control('AdSense Ad', 'adsensem_sbm_widget_control', 300, 80);
|
1022 |
-
}
|
1023 |
/* Add the blocks to the Widget panel for positioning */
|
1024 |
else if (function_exists('register_sidebar_widget') )
|
1025 |
{
|
1026 |
-
|
1027 |
/* Loop through available ads and generate widget one at a time */
|
1028 |
if(is_array($options['ads'])){
|
1029 |
-
|
1030 |
foreach($options['ads'] as $name => $ad){
|
1031 |
$widget=array('Ad #%s', '', $name);
|
1032 |
register_sidebar_widget($widget, array(&$this,'widget'), $name);
|
1033 |
-
register_widget_control($widget, array(&$this,'widget_control'), 300, 80, $name);
|
1034 |
}
|
1035 |
}
|
1036 |
|
4 |
PLugin URI: http://www.mutube.com/projects/wordpress/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.0
|
8 |
Author URI: http://www.mutube.com/
|
9 |
*/
|
10 |
|
17 |
|
18 |
*/
|
19 |
|
20 |
+
@define("ADSENSEM_VERSION", "2.0");
|
21 |
@define('ADSENSEM_DIRPATH','/wp-content/plugins' . strrchr(dirname(__FILE__),'/') . "/");
|
22 |
|
23 |
/*
|
28 |
@define("ADSENSEM_MAX_ADS", 7); //Max Google Ad units
|
29 |
@define("ADSENSEM_MAX_REFERRALS", 7); //Max Google Referral units
|
30 |
|
|
|
|
|
31 |
/*
|
32 |
AdSense Manager is a plugin to help manage generating income from your Wordpress blogs. Because it's a money-generating plugin it would be nice (for me) if some of that income found
|
33 |
it's way back to supporting the development and hosting of my free plugins.
|
50 |
//the % defined by the user. For example, if the user specifies 5% and there
|
51 |
//are two id's defined each will get 2.5% of the niceness.
|
52 |
//You may also want to change the text on the options pages to reflect this (line 569).
|
53 |
+
//Note that Ad & Referrals have different channels
|
54 |
+
|
55 |
+
//NOTE: NEW FORMAT SINCE PREVIOUS VERSION, AS REFERRALS USE DIFFERENT CHANNELS
|
56 |
+
$ADSENSEM_PUBLISHER['3287067876809234']['ad']='7935832546';
|
57 |
+
$ADSENSEM_PUBLISHER['3287067876809234']['referral']='2726944614';
|
58 |
//$ADSENSEM_PUBLISHER['adsense-id']='channel-id';
|
59 |
|
60 |
/* Copyright 2006 MARTIN FITZPATRICK (email : martin.fitzpatrick@gmail.com)
|
97 |
else
|
98 |
{$ad=$options['ads'][$name];}
|
99 |
|
100 |
+
echo $adsensem->get_ad($ad,$name);
|
101 |
}
|
102 |
|
103 |
}
|
115 |
|
116 |
var $benice=true;
|
117 |
|
118 |
+
function get_ad_inline($ad=false,$name /* passthru */) {
|
119 |
|
120 |
$options = get_option('plugin_adsensem');
|
121 |
|
131 |
(($ad['show-archive']=='yes') && is_archive()) ||
|
132 |
(($ad['show-search']=='yes') && is_search()) )
|
133 |
{ /* We passed the test, display the Ad */
|
134 |
+
$code.=$this->get_ad($ad,$name);
|
135 |
}
|
136 |
return $code;
|
137 |
}
|
138 |
|
139 |
+
function get_ad($ad=false,$name='') {
|
140 |
global $ADSENSEM_PUBLISHER;
|
141 |
|
142 |
$options = get_option('plugin_adsensem');
|
143 |
|
144 |
if($ad===false){$ad=$options['ads'][$options['defaults']['ad']];}
|
145 |
$ad=$this->merge_defaults($ad); //Apply defaults
|
146 |
+
|
147 |
$code='';
|
148 |
|
149 |
/* Valid entry */
|
150 |
if(is_array($ad)){
|
151 |
|
152 |
+
//Default to Ad
|
153 |
+
if($ad['product']=='link'){
|
154 |
+
$format = $ad['linkformat'] . $ad['linktype'];
|
155 |
+
list($width,$height,$null)=split('[x]',$ad['linkformat']);
|
156 |
+
} else if($ad['product']=='referral-image') {
|
157 |
+
$format = $ad['referralformat'] . '_as_rimg';
|
158 |
+
list($width,$height,$null)=split('[x]',$ad['referralformat']);
|
159 |
+
} else if($ad['product']=='referral-text') {
|
160 |
+
$format = 'ref_text';
|
161 |
+
} else {
|
162 |
+
$format = $ad['adformat'] . '_as';
|
163 |
+
list($width,$height,$null)=split('[x]',$ad['adformat']);
|
164 |
+
}
|
165 |
|
166 |
+
if($this->benice){
|
167 |
+
$bn_publisher=array_rand($ADSENSEM_PUBLISHER);
|
168 |
|
169 |
+
//Referrals use different Channels. Boo.
|
170 |
+
if ( ($ad['product']=='referral-image') || ($ad['product']=='referral-text') )
|
171 |
+
{ $bn_channel=$ADSENSEM_PUBLISHER[$bn_publisher]['referral']; }
|
172 |
+
else
|
173 |
+
{ $bn_channel=$ADSENSEM_PUBLISHER[$bn_publisher]['ad']; }
|
174 |
+
}
|
175 |
+
|
176 |
+
|
177 |
+
$code .= $ad['html-before'];
|
178 |
|
179 |
|
180 |
if($_GET['preview']){
|
181 |
+
|
182 |
/* We are in the editor, output fake */
|
183 |
+
if($ad['product']=='code'){
|
184 |
+
//Complicated to extract dimensions from code, for now just output "default" sized object.
|
185 |
+
$code .= '<div style="text-align:center;border:1px solid #000;font-size:25px;width:250px;height:100px">';
|
186 |
+
$code .= 'AdSense Code Unit<br />#' . $name;
|
187 |
+
$code .= '</div>';
|
188 |
+
} else if($ad['product']=='referral-text'){
|
189 |
+
//Text link referral
|
190 |
+
$code .= '<span style="text-decoration:underline;color:#00f">AdSense Referral Link #' . $name . '</span>';
|
191 |
+
} else {
|
192 |
+
/* We are in the editor, output fake */
|
193 |
+
$code .= '<div style="text-align:center;border:1px solid #000;font-size:' . round($height/4,0) . 'px;width:' . $width . 'px;height:' . $height . 'px">';
|
194 |
+
$code .= 'AdSense ' . ucwords(str_replace("-"," ",$ad['product'])) . '<br />#' . $name;
|
195 |
+
$code .= '</div>';
|
196 |
+
}
|
197 |
+
|
198 |
} else {
|
199 |
|
200 |
+
if($ad['product']=='code'){
|
201 |
+
|
202 |
+
$code.=$ad['code'];
|
203 |
+
|
204 |
+
/* Be-Nice replace in the code - only do for code for speed */
|
205 |
+
if($this->benice){
|
206 |
+
|
207 |
+
$code=preg_replace('/google_ad_client = "(.*)"/','google_ad_client = "pub-' . $bn_publisher . '"',$code);
|
208 |
+
|
209 |
+
if(strstr($code,'google_ad_channel')!==false){
|
210 |
+
/* Replace Channel if it already exists */
|
211 |
+
$code=preg_replace('/google_ad_channel = "(.*)"/','google_ad_channel = "' . $bn_channel . '"',$code);
|
212 |
+
} else {
|
213 |
+
/* Insert the Channel if not defined in code */
|
214 |
+
$code=preg_replace('/(.*)google_ad_client/','google_ad_channel = "' . $bn_channel . '";' . "\ngoogle_ad_client",$code);
|
215 |
+
}
|
216 |
+
|
217 |
+
}
|
218 |
+
/* End Be-Nice for Code */
|
219 |
+
|
220 |
+
} else {
|
221 |
+
|
222 |
+
/* Be Nice by replacing settings retrieved from db */
|
223 |
if($this->benice){
|
224 |
+
$options['adsense-account']=$bn_publisher;
|
225 |
+
$ad['channel']=$bn_channel;
|
|
|
226 |
}
|
227 |
+
/* End Be-Nice */
|
228 |
+
|
229 |
+
$code .= '<script type="text/javascript"><!--' . "\n";
|
230 |
$code.= 'google_ad_client = "pub-' . $options['adsense-account'] . '";' . "\n";
|
231 |
+
|
232 |
+
if($ad['channel']!==''){ $code.= 'google_ad_channel = "' . $ad['channel'] . '";' . "\n"; }
|
233 |
|
234 |
+
if(($ad['product']=='ad') || ($ad['product']=='link') || ($ad['product']=='referral-image')){
|
235 |
+
$code.= 'google_ad_width = ' . $width . ";\n";
|
236 |
+
$code.= 'google_ad_height = ' . $height . ";\n";
|
237 |
+
}
|
238 |
+
|
239 |
$code.= 'google_ad_format = "' . $format . '"' . ";\n";
|
240 |
|
241 |
if($ad['alternate-url']!=''){ $code.= 'google_alternate_ad_url = "' . $ad['alternate-url'] . '";' . "\n";}
|
242 |
else if($ad['alternate-color']!=''){ $code.= 'google_alternate_color = "' . $ad['alternate-color'] . '";' . "\n";}
|
243 |
|
244 |
//Default to Ads
|
245 |
+
if($ad['product']=='ad'){ $code.= 'google_ad_type = "' . $ad['adtype'] . '"' . ";\n"; }
|
246 |
+
|
247 |
+
if($ad['product']=='referral-text'){$code.='google_ad_output = "textlink"' . ";\n";}
|
248 |
+
if(($ad['product']=='referral-text') || ($ad['product']=='referral-image')){$code.='google_cpa_choice = "' . $ad['referral'] . '"' . ";\n";}
|
249 |
+
|
250 |
+
if(($ad['product']=='ad') || ($ad['product']=='link')){
|
251 |
+
$code.= 'google_color_border = "' . $ad['colors']['border'] . '"' . ";\n";
|
252 |
+
$code.= 'google_color_bg = "' . $ad['colors']['bg'] . '"' . ";\n";
|
253 |
+
$code.= 'google_color_link = "' . $ad['colors']['link'] . '"' . ";\n";
|
254 |
+
$code.= 'google_color_text = "' . $ad['colors']['text'] . '"' . ";\n";
|
255 |
+
$code.= 'google_color_url = "' . $ad['colors']['url'] . '"' . ";\n";
|
256 |
+
}
|
257 |
+
|
258 |
+
$code.= "\n" . '//--></script>' . "\n";
|
259 |
|
260 |
$code.= '<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>' . "\n";
|
261 |
+
|
262 |
+
}
|
263 |
+
|
264 |
}
|
265 |
+
|
266 |
+
$code.=$ad['html-after'];
|
267 |
|
268 |
}
|
269 |
|
344 |
{
|
345 |
?><option <?php if($key==$selected){ echo "selected"; }?> value="<?php echo $key; ?>"> <?php echo $value; ?></option><?php
|
346 |
}
|
347 |
+
}
|
348 |
+
|
349 |
/* ADMIN Settings - Editing form for each Ad and defaults, reusable */
|
350 |
function admin_settingsform($settings=array('colors'=>array()),$name=false)
|
351 |
{
|
352 |
|
353 |
$colors = $settings['colors'];
|
|
|
|
|
|
|
354 |
|
355 |
if($settings['product']==''){$settings['product']='ad';}
|
356 |
+
|
357 |
+
//Google AdSense data
|
358 |
+
|
359 |
+
$formats['default']=array('' => 'Use Default');
|
360 |
+
|
361 |
+
$formats['ads']['horizontal']=array('728x90' => '728 x 90 Leaderboard', '468x60' => '468 x 60 Banner', '234x60' => '234 x 60 Half Banner');
|
362 |
+
$formats['ads']['vertical']=array('120x600' => '120 x 600 Skyscraper', '160x600' => '160 x 600 Wide Skyscraper', '120x240' => '120 x 240 Vertical Banner');
|
363 |
+
$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');
|
364 |
+
|
365 |
+
$adtypes=array('text_image' => 'Text & Image', 'image' => 'Image Only', 'text' => 'Text Only');
|
366 |
+
|
367 |
+
$formats['links']['horizontal']=array('728x15' => '728 x 15', '468x15' => '468 x 15');
|
368 |
+
$formats['links']['square']=array('200x90' => '200 x 90', '180x90' => '180 x 90', '160x90' => '160 x 90', '120x90' => '120 x 90');
|
369 |
+
|
370 |
+
$linktypes=array('_0ads_al' => '4 Ads Per Unit', '_0ads_al_s' => '5 Ads Per Unit');
|
371 |
+
|
372 |
+
$formats['referrals']['horizontal']=array('110x32' => '110 x 32', '120x60' => '120 x 60', '180x60' => '180 x 60', '468x60' => '468 x 60');
|
373 |
+
$formats['referrals']['square']=array('125x125' => '125 x 125');
|
374 |
+
$formats['referrals']['vertical']=array('120x240' => '120 x 240');
|
375 |
+
|
376 |
+
$yesno=array("yes" => 'Yes', "no" => 'No');
|
377 |
+
$default=array('' => 'Use Default');
|
378 |
+
|
379 |
+
$products=array('ad' => 'Ad Unit','link' => 'Link Unit','referral-text' => "Referral (Text)",'referral-image' => "Referral (Image)");
|
380 |
+
$productsextra=array('code' => 'Direct Code Ad');
|
381 |
+
?>
|
382 |
+
|
383 |
|
384 |
<script type="text/javascript">
|
385 |
|
392 |
}
|
393 |
}
|
394 |
|
395 |
+
function adsensem_product_options(product){
|
396 |
+
|
397 |
+
all=Array('ad','link','color','referral','referral-format','code','alternate');
|
398 |
+
|
399 |
+
switch (product){
|
400 |
+
case 'link': show = Array('link','color','alternate');
|
401 |
+
break;
|
402 |
+
case 'ad': show = Array('ad','color','alternate');
|
403 |
+
break;
|
404 |
+
case 'referral-text':show = Array('referral');
|
405 |
+
break;
|
406 |
+
case 'referral-image':show = Array('referral','referral-format');
|
407 |
break;
|
408 |
+
case 'code': show = Array('code');
|
409 |
+
break;
|
410 |
+
}
|
411 |
+
|
412 |
+
for(a=0;a<all.length;a++){
|
413 |
+
found=false;
|
414 |
+
for(s=0;s<show.length;s++){if(show[s]==all[a]){found=true;}}
|
415 |
+
if(found){document.getElementById('adsensem-settings-' + all[a]).style.display=''}
|
416 |
+
else {document.getElementById('adsensem-settings-' + all[a]).style.display='none'}
|
417 |
}
|
418 |
|
419 |
+
}
|
420 |
+
|
|
|
|
|
|
|
|
|
|
|
421 |
</script>
|
422 |
|
423 |
<table style="width:100%;">
|
424 |
<tr valign="top"><td class="wrap">
|
425 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
426 |
<h4>Basic</h4>
|
427 |
+
<table>
|
428 |
<?php if($name!==false){ ?>
|
429 |
<tr><td><label for="adsensem-name">Name:</label></td>
|
430 |
<td><input style="border:2px solid #000" name="adsensem-name" size="15" value="<?php echo htmlspecialchars($name, ENT_QUOTES); ?>" />
|
437 |
<?php if($name!==false){ ?>
|
438 |
<tr><td><label for="adsensem-product">Product:</label></td>
|
439 |
<td><select name="adsensem-product" onchange="adsensem_product_options(this.value);">
|
440 |
+
<optgroup label="Google">
|
441 |
<?php $this->output_select($products,$settings['product']);?>
|
442 |
+
</optgroup>
|
443 |
+
<optgroup label="Extra">
|
444 |
+
<?php $this->output_select($productsextra,$settings['product']);?>
|
445 |
+
</optgroup>
|
446 |
</select></tr>
|
447 |
<?php } ?>
|
448 |
</table>
|
449 |
|
450 |
+
<div id="adsensem-settings-ad">
|
451 |
+
<h4>Ad Unit Settings</h4>
|
452 |
+
<table style="padding-bottom:1em;">
|
453 |
+
<tr id="row-adformat"><td><label for="adsensem-adformat"><a href="https://www.google.com/adsense/adformats" target="_new">Format:</a></label></td>
|
454 |
<td>
|
455 |
<select name="adsensem-adformat">
|
456 |
<!-- Options taken from Google AdSense setup pages -->
|
470 |
</select>
|
471 |
</td></tr>
|
472 |
</table>
|
473 |
+
</div>
|
474 |
|
475 |
+
<div id="adsensem-settings-link">
|
476 |
+
<h4>Link Unit Settings</h4>
|
477 |
+
<table style="padding-bottom:1em;">
|
478 |
+
<tr id="row-linkformat"><td><label for="adsensem-linkformat"><a href="https://www.google.com/adsense/adformats" target="_new">Format:</a></label></td>
|
479 |
<td>
|
480 |
<select name="adsensem-linkformat">
|
481 |
<!-- Options taken from Google AdSense setup pages -->
|
493 |
<?php $this->output_select($linktypes,$settings['linktype']);?>
|
494 |
</select>
|
495 |
</td></tr>
|
|
|
|
|
496 |
</table>
|
497 |
+
</div>
|
498 |
|
499 |
+
<?php //Referral units & code have no "defaults" so cannot be set up in this way
|
500 |
+
if($name!==false){ ?>
|
501 |
|
502 |
+
<div id="adsensem-settings-referral">
|
503 |
+
<h4>Referral Settings</h4>
|
504 |
+
<table style="padding-bottom:1em;">
|
505 |
+
<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>
|
506 |
+
<td>
|
507 |
+
<select name="adsensem-referralformat" id="adsensem-referralformat">
|
508 |
+
<!-- Options taken from Google AdSense setup pages -->
|
509 |
+
<optgroup label="Horizontal"><?php $this->output_select($formats['referrals']['horizontal'],$settings['referralformat']);?></optgroup>
|
510 |
+
<optgroup label="Square"><?php $this->output_select($formats['referrals']['square'],$settings['referralformat']);?></optgroup>
|
511 |
+
<optgroup label="Vertical"><?php $this->output_select($formats['referrals']['vertical'],$settings['referralformat']);?></optgroup>
|
512 |
+
</select>
|
513 |
+
</td></tr>
|
514 |
+
|
515 |
+
<tr><td><label for="adsensem-referral">Referral Code:</label></td>
|
516 |
+
<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>
|
517 |
+
</table>
|
518 |
+
</div>
|
519 |
|
520 |
+
<div id="adsensem-settings-code">
|
521 |
+
<h4>Code Settings</h4>
|
522 |
+
<table id="adsensem-settings-code" style="padding-bottom:1em;">
|
523 |
+
|
524 |
+
<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>
|
525 |
+
<td>
|
526 |
+
<textarea rows="5" cols="30" name="adsensem-code"><?php echo htmlspecialchars($settings['code'], ENT_QUOTES); ?></textarea>
|
527 |
+
</td></tr>
|
528 |
+
|
529 |
+
<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>
|
530 |
+
</table>
|
531 |
+
</div><?php } ?>
|
532 |
+
|
533 |
+
</td><td class="wrap" id="adsensem-settings-color">
|
534 |
+
|
535 |
<h4>Ad Colours</h4>
|
536 |
+
<table>
|
537 |
<tr><td><label for="adsensem-colors-border">Border:</label></td>
|
538 |
<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>
|
539 |
<tr><td><label for="adsensem-colors-link">Title:</label></td>
|
576 |
|
577 |
<h4>Show Inline Ads</h4>
|
578 |
|
579 |
+
<table>
|
580 |
<tr><td><label for="adsensem-show-home">On Homepage</label></td>
|
581 |
<td><select name="adsensem-show-home">
|
582 |
|
602 |
|
603 |
|
604 |
<h4>HTML Markup (Optional)</h4>
|
605 |
+
<table>
|
606 |
<tr><td><label for="adsensem-html-before">Before:</label></td>
|
607 |
<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>
|
608 |
<tr><td><label for="adsensem-html-after">After:</label></td>
|
609 |
<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>
|
610 |
</table>
|
611 |
|
612 |
+
<div id="adsensem-settings-alternate">
|
613 |
<h4>Alternate Ads (Optional)</h4>
|
614 |
+
<table>
|
615 |
<tr><td><label for="adsensem-alternate-url">URL:</label></td>
|
616 |
<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>
|
617 |
<tr><td><label for="adsensem-alternate-color">Color:</label></td>
|
618 |
<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>
|
619 |
</table>
|
620 |
+
</div>
|
621 |
|
622 |
|
623 |
|
624 |
</td></tr>
|
625 |
</table>
|
626 |
+
<?php if($name!==false){ ?>
|
627 |
+
<script>adsensem_product_options('<?php echo $settings['product']; ?>');</script>
|
628 |
+
<?php }
|
629 |
}
|
630 |
|
631 |
/*
|
685 |
|
686 |
<?php
|
687 |
}
|
688 |
+
|
689 |
+
function admin_adsense_code_convert() {
|
690 |
+
|
691 |
+
$code=stripslashes($_POST['adsensem-code']);
|
692 |
+
|
693 |
+
if(preg_match('/google_ad_channel = "(.*)"/', $code, $matches)!=0){ $_POST['adsensem-channel'] = $matches[1]; }
|
694 |
+
if(preg_match('/google_alternate_ad_url = "(.*)"/', $code, $matches)!=0){ $_POST['adsensem-alternate-url'] = $matches[1]; }
|
695 |
+
if(preg_match('/google_alternate_color = "(.*)"/', $code, $matches)!=0){ $_POST['adsensem-alternate-color'] = $matches[1]; }
|
696 |
+
|
697 |
+
$width=false; $height=false;
|
698 |
+
if(preg_match('/google_ad_width = (\d*);/', $code, $matches)!=0){ $width = $matches[1]; }
|
699 |
+
if(preg_match('/google_ad_height = (\d*);/', $code, $matches)!=0){ $height = $matches[1]; }
|
700 |
+
if( ($width!==false) && ($height!==false) ) { $format = $width . "x" . $height; }
|
701 |
+
|
702 |
+
//as_rimg - Referral (Image)
|
703 |
+
//ref_text - Referral (Text)
|
704 |
+
//_0ads_al - Link Unit
|
705 |
+
//_as - Ad Unit
|
706 |
+
|
707 |
+
if(preg_match('/google_ad_format = "(.*)"/', $code, $matches)!=0){
|
708 |
+
|
709 |
+
$adformat=$matches[1];
|
710 |
+
if(strstr($adformat,'_as_rimg')!==false){
|
711 |
+
preg_match('/google_cpa_choice = "(.*)"/', $code, $matches);
|
712 |
+
$_POST['adsensem-referral']=$matches[1];
|
713 |
+
$_POST['adsensem-product']='referral-image';
|
714 |
+
$_POST['adsensem-referralformat']=$format; }
|
715 |
+
else if(strstr($adformat,'ref_text')!==false){
|
716 |
+
preg_match('/google_cpa_choice = "(.*)"/', $code, $matches);
|
717 |
+
$_POST['adsensem-referral']=$matches[1];
|
718 |
+
$_POST['adsensem-product']='referral-text';
|
719 |
+
} else if(strstr($adformat,'_0adsl_al')!==false){
|
720 |
+
$_POST['adsensem-product']='link';
|
721 |
+
$_POST['adsensem-linkformat']=$format;
|
722 |
+
if(strstr($adformat,'_0adsl_al_s')){ $_POST['linktype']="_0adsl_al_s"; } else { $_POST['linktype']="_0adsl_al"; }
|
723 |
+
} else if(strstr($adformat,'_as')!==false){
|
724 |
+
$_POST['adsensem-product']='ad';
|
725 |
+
$_POST['adsensem-adformat']=$format;
|
726 |
+
}
|
727 |
+
}
|
728 |
+
|
729 |
+
if(preg_match('/google_color_border = "(.*)"/', $code, $matches)!=0){$_POST['adsensem-colors-border']=$matches[1];}
|
730 |
+
if(preg_match('/google_color_bg = "(.*)"/', $code, $matches)!=0){$_POST['adsensem-colors-link']=$matches[1];}
|
731 |
+
if(preg_match('/google_color_link = "(.*)"/', $code, $matches)!=0){$_POST['adsensem-colors-bg']=$matches[1];}
|
732 |
+
if(preg_match('/google_color_text = "(.*)"/', $code, $matches)!=0){$_POST['adsensem-colors-text']=$matches[1];}
|
733 |
+
if(preg_match('/google_color_url = "(.*)"/', $code, $matches)!=0){$_POST['adsensem-colors-url']=$matches[1];}
|
734 |
+
|
735 |
+
}
|
736 |
|
737 |
function admin_save_settings($ad=array()) {
|
738 |
|
739 |
$ad['channel']=strip_tags(stripslashes($_POST['adsensem-channel']));
|
740 |
|
|
|
741 |
$ad['product']=$_POST['adsensem-product'];
|
742 |
|
|
|
743 |
$ad['adformat']=strip_tags(stripslashes($_POST['adsensem-adformat']));
|
744 |
$ad['adtype']=strip_tags(stripslashes($_POST['adsensem-adtype']));
|
745 |
|
746 |
$ad['linkformat']=strip_tags(stripslashes($_POST['adsensem-linkformat']));
|
747 |
$ad['linktype']=strip_tags(stripslashes($_POST['adsensem-linktype']));
|
748 |
|
749 |
+
$ad['referralformat']=strip_tags(stripslashes($_POST['adsensem-referralformat']));
|
750 |
+
$ad['referral']=strip_tags(stripslashes($_POST['adsensem-referral']));
|
751 |
+
|
752 |
+
$ad['code']=stripslashes($_POST['adsensem-code']);
|
753 |
+
|
754 |
$ad['html-before']=stripslashes($_POST['adsensem-html-before']);
|
755 |
$ad['html-after']=stripslashes($_POST['adsensem-html-after']);
|
756 |
|
793 |
|
794 |
} else {
|
795 |
|
796 |
+
if( $_POST['adsensem-code-convert'] ){
|
797 |
+
//Extract code into $_POST variables, to simulate normal submission
|
798 |
+
$this->admin_adsense_code_convert();
|
799 |
+
}
|
800 |
+
|
801 |
if($_POST['adsensem-name']==''){
|
802 |
+
$a=0; do { $a++; $_POST['adsensem-name']='Ad-' . $a; } while (isset($options['ads'][$_POST['adsensem-name']]));
|
|
|
803 |
}
|
804 |
|
805 |
$name=sanitize_title($_POST['adsensem-name']);
|
816 |
|
817 |
$options['ads'][$name]=$this->admin_save_settings($options['ads'][$name]);
|
818 |
}
|
819 |
+
|
820 |
update_option('plugin_adsensem', $options);
|
821 |
|
822 |
}
|
840 |
update_option('plugin_adsensem', $options);
|
841 |
}
|
842 |
|
843 |
+
if ( $_POST['adsensem-copy'] ) {
|
844 |
+
//Copy selected advert
|
845 |
+
$a=0; do { $a++; $copyto=$_POST['adsensem-copy-name'] . '-' . $a; } while (isset($options['ads'][$copyto]));
|
846 |
+
$options['ads'][$copyto]=$options['ads'][$_POST['adsensem-copy-name']];
|
847 |
+
update_option('plugin_adsensem', $options);
|
848 |
+
}
|
849 |
+
|
850 |
?>
|
851 |
<div class="wrap">
|
852 |
<h2>Manage Ads</h2>
|
854 |
|
855 |
<form action="" method="post" id="adsensem-config" enctype="multipart/form-data">
|
856 |
|
857 |
+
<input type="hidden" name="adsensem-copy-name" id="adsensem-copy-name">
|
858 |
<input type="hidden" name="adsensem-delete-name" id="adsensem-delete-name">
|
859 |
<input type="hidden" name="adsensem-default-name" id="adsensem-default-name">
|
860 |
+
<input type="hidden" name="adsensem-edit-name" id="adsensem-edit-name">
|
861 |
|
862 |
<style type="text/css">
|
863 |
th {border-bottom:2px solid #000;}
|
870 |
<tr style="background-color:#ddd;" id="default-options">
|
871 |
<td style="font-weight:bold;">Default Settings</td>
|
872 |
<td><?php echo htmlspecialchars($options['defaults']['channel'], ENT_QUOTES); ?></td>
|
873 |
+
<td></td>
|
874 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['border'], ENT_QUOTES); ?>"> </td>
|
875 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['link'], ENT_QUOTES); ?>"> </td>
|
876 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['bg'], ENT_QUOTES); ?>"> </td>
|
877 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['text'], ENT_QUOTES); ?>"> </td>
|
878 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($options['defaults']['colors']['url'], ENT_QUOTES); ?>"> </td>
|
879 |
<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>
|
880 |
+
<td style="width:10px;"><input name="adsensem-edit" type="submit" value="Edit" onClick="document.getElementById('adsensem-edit-name').value='';"></td>
|
881 |
+
<td colspan="3"></td>
|
882 |
</tr>
|
883 |
|
884 |
<?php
|
889 |
?><tr <?php if($name==$options['defaults']['ad']){?>style="background-color:#eee;"<?php } ?>>
|
890 |
<td><?php echo htmlspecialchars($name, ENT_QUOTES); ?></td>
|
891 |
<td><?php echo htmlspecialchars($ad['channel'], ENT_QUOTES); ?></td>
|
892 |
+
<td style="text-align:center;"><?php echo htmlspecialchars(ucwords(str_replace("-"," ",$ad['product'])), ENT_QUOTES); ?></td>
|
893 |
+
|
894 |
+
<?php if(($ad['product']=='ad') || ($ad['product']=='link')) { ?>
|
895 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['border'], ENT_QUOTES); ?>"> </td>
|
896 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['link'], ENT_QUOTES); ?>"> </td>
|
897 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['bg'], ENT_QUOTES); ?>"> </td>
|
898 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['text'], ENT_QUOTES); ?>"> </td>
|
899 |
<td style="width:16px;background-color:#<?php echo htmlspecialchars($ad['colors']['url'], ENT_QUOTES); ?>"> </td>
|
900 |
+
<?php } else { ?><td colspan="5"></td><?php } ?>
|
901 |
+
|
902 |
+
<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>
|
903 |
+
<td style="width:10px;"><input name="adsensem-edit" type="submit" value="Edit" onClick="document.getElementById('adsensem-edit-name').value='<?php echo $name; ?>';"></td>
|
904 |
+
<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>
|
905 |
+
|
906 |
<?php if($name!=$options['defaults']['ad']){?>
|
907 |
+
<td style="width:30px"><input name="adsensem-default" type="submit" value="Set Default" onClick="document.getElementById('adsensem-default-name').value='<?php echo $name; ?>';"></td>
|
908 |
+
<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>
|
909 |
<?php } else { ?><td style="width:50px"><strong>Default Ad</strong></td><td></td><?php } ?>
|
910 |
|
911 |
</tr>
|
932 |
|
933 |
<?php
|
934 |
|
935 |
+
if( ($_POST['adsensem-edit']) && ($_POST['adsensem-edit-name'])=="")
|
936 |
+
{ $EDIT_DEFAULT = true; }
|
937 |
+
else
|
938 |
+
{ $EDIT_DEFAULT = false; }
|
939 |
|
940 |
if($_POST['adsensem-edit']){ ?>
|
941 |
|
1034 |
{
|
1035 |
add_submenu_page('edit.php',"Ads", "Ads", 10, "adsense-manager", array(&$this,'admin_manage'));
|
1036 |
add_options_page("AdSense Manager Options", "AdSense Manager", 10, "adsense-manager", array(&$this,'admin_options'));
|
1037 |
+
|
1038 |
+
/* ADMIN SECTION: WIDGET CONTROL CODE
|
1039 |
+
/* If SBM installed output the Kludge functions for compatibility */
|
1040 |
+
/* These use the #id pased via the module name because of inability to pass
|
1041 |
+
references to functions using class definitions under SBM */
|
1042 |
+
if (function_exists('sbm_get_option') )
|
1043 |
+
{register_widget_control('AdSense Ad', 'adsensem_sbm_widget_control', 300, 80);}
|
1044 |
/* Add the blocks to the Widget panel for positioning */
|
1045 |
+
else if (function_exists('register_sidebar_widget') )
|
1046 |
{
|
1047 |
|
1048 |
/* Loop through available ads and generate widget one at a time */
|
1050 |
|
1051 |
foreach($options['ads'] as $name => $ad){
|
1052 |
$widget=array('Ad #%s', '', $name);
|
|
|
1053 |
register_widget_control($widget, array(&$this,'widget_control'), 300, 80, $name);
|
1054 |
}
|
1055 |
}
|
1056 |
|
1057 |
}
|
1058 |
|
1059 |
+
|
1060 |
}
|
1061 |
|
1062 |
|
1069 |
if(is_array($options['ads'])){
|
1070 |
|
1071 |
//Insert default ad first
|
1072 |
+
$content=str_replace("<!--adsense-->",$this->get_ad_inline(false,'default'),$content);
|
1073 |
|
1074 |
foreach($options['ads'] as $name=>$ad)
|
1075 |
{
|
1076 |
+
$content = str_replace("<!--adsense#" . $name . "-->", $this->get_ad_inline($ad,$name), $content);
|
1077 |
}
|
1078 |
|
1079 |
}
|
1197 |
|
1198 |
add_action('admin_footer', array(&$this,'admin_callback_editor'));
|
1199 |
|
1200 |
+
/* SITE SECTION: WIDGET DISPLAY CODE
|
1201 |
/* If SBM installed output the Kludge functions for compatibility */
|
1202 |
/* These use the #id pased via the module name because of inability to pass
|
1203 |
references to functions using class definitions under SBM */
|
1204 |
if (function_exists('sbm_get_option') )
|
1205 |
+
{register_sidebar_widget('AdSense Ad', 'adsensem_sbm_widget');}
|
|
|
|
|
|
|
1206 |
/* Add the blocks to the Widget panel for positioning */
|
1207 |
else if (function_exists('register_sidebar_widget') )
|
1208 |
{
|
|
|
1209 |
/* Loop through available ads and generate widget one at a time */
|
1210 |
if(is_array($options['ads'])){
|
|
|
1211 |
foreach($options['ads'] as $name => $ad){
|
1212 |
$widget=array('Ad #%s', '', $name);
|
1213 |
register_sidebar_widget($widget, array(&$this,'widget'), $name);
|
|
|
1214 |
}
|
1215 |
}
|
1216 |
|
readme.txt
CHANGED
@@ -4,9 +4,9 @@ Donate link: http://www.mutube.com/about/be-nice/
|
|
4 |
Tags: adsense, ads, manage, widget, google
|
5 |
Requires at least: 2.0.2
|
6 |
Tested up to: 2.1
|
7 |
-
Stable tag:
|
8 |
|
9 |
-
AdSense Manager is a new Wordpress plugin for managing AdSense ads on your blog. Generates code automatically and allows positioning with Widgets.
|
10 |
|
11 |
== Description ==
|
12 |
|
@@ -14,7 +14,13 @@ Adsense Manager is a new Wordpress plugin to help manage Adsense ads on your blo
|
|
14 |
|
15 |
You can modify Ads right from your Wordpress admin panel - change colours, type and size of ads with a push of a button. On Wordpress Widgets enabled blogs you can also drag the Ads around your Sidebar to position them as you like.
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
== Installation ==
|
20 |
|
4 |
Tags: adsense, ads, manage, widget, google
|
5 |
Requires at least: 2.0.2
|
6 |
Tested up to: 2.1
|
7 |
+
Stable tag: 2.0
|
8 |
|
9 |
+
AdSense Manager is a new Wordpress plugin for managing AdSense ads on your blog. Generates code automatically and allows positioning with Widgets. Now supports Referral ads.
|
10 |
|
11 |
== Description ==
|
12 |
|
14 |
|
15 |
You can modify Ads right from your Wordpress admin panel - change colours, type and size of ads with a push of a button. On Wordpress Widgets enabled blogs you can also drag the Ads around your Sidebar to position them as you like.
|
16 |
|
17 |
+
Version 2.0 now supports:
|
18 |
+
* Referral Ads (Text & Image)
|
19 |
+
* Direct Code Ads (allows for non AdSense ad positioning)
|
20 |
+
* Code Converter (import Google generated Ads to configurable Ad units)
|
21 |
+
* Sidebar Modules (as used in the popular K2 theme)
|
22 |
+
* [New extended instructions available.](http://www.mutube.com/projects/wordpress/adsense-manager/instructions)
|
23 |
+
|
24 |
|
25 |
== Installation ==
|
26 |
|