Quick Adsense - Version 1.0

Version Description

Download this release

Release Info

Developer philipze
Plugin Icon 128x128 Quick Adsense
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (5) hide show
  1. quick-adsense-admin.php +216 -0
  2. quick-adsense.php +334 -0
  3. readme.txt +53 -0
  4. screenshot-1.png +0 -0
  5. screenshot-2.png +0 -0
quick-adsense-admin.php ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Copyright 2009 Philip Ze [ http://techmilieu.com/quick-adsense ]
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+ ?>
21
+
22
+ <?php
23
+ global $QData;
24
+ $dis = get_option('AdsDisp');
25
+ $ra1 = get_option('BegnAds');
26
+ $ra2 = get_option('BegnRnd');
27
+ $rb1 = get_option('EndiAds');
28
+ $rb2 = get_option('EndiRnd');
29
+ $aps = get_option('AppPost');
30
+ $apg = get_option('AppPage');
31
+ $ahm = get_option('AppHome');
32
+ $act = get_option('AppCate');
33
+ $aar = get_option('AppArch');
34
+ $atg = get_option('AppTags');
35
+ $aqt = get_option('QckTags');
36
+ $optionsupdate =
37
+ "AdsDisp,".
38
+ "BegnAds,EndiAds,BegnRnd,EndiRnd,".
39
+ "AppHome,AppPost,AppPage,AppCate,AppArch,AppTags,".
40
+ "QckTags";
41
+
42
+ function truefalse($arg) {
43
+ if($arg){ return 'true';}else{ return 'false';}
44
+ }
45
+ ?>
46
+
47
+ <script type="text/javascript">
48
+ function defaultoptions() {
49
+ document.getElementById("DisTot<?php echo($QData['Default']['AdsDisp']) ?>").selected = true;
50
+ document.getElementById("BegnAds").checked = <?php echo(truefalse($QData['Default']['BegnAds'])) ?>;
51
+ document.getElementById("BegnRnd").selectedIndex = <?php echo($QData['Default']['BegnRnd']) ?>;
52
+ document.getElementById("EndiAds").checked = <?php echo(truefalse($QData['Default']['EndiAds'])) ?>;
53
+ document.getElementById("EndiRnd").selectedIndex = <?php echo($QData['Default']['EndiRnd']) ?>;
54
+ document.getElementById("AppHome").checked = <?php echo(truefalse($QData['Default']['AppHome'])) ?>;
55
+ document.getElementById("AppPost").checked = <?php echo(truefalse($QData['Default']['AppPost'])) ?>;
56
+ document.getElementById("AppPage").checked = <?php echo(truefalse($QData['Default']['AppPage'])) ?>;
57
+ document.getElementById("AppCate").checked = <?php echo(truefalse($QData['Default']['AppCate'])) ?>;
58
+ document.getElementById("AppArch").checked = <?php echo(truefalse($QData['Default']['AppArch'])) ?>;
59
+ document.getElementById("AppTags").checked = <?php echo(truefalse($QData['Default']['AppTags'])) ?>;
60
+ document.getElementById("QckTags").checked = <?php echo(truefalse($QData['Default']['QckTags'])) ?>;
61
+ for(i=1;i<=<?php echo($QData['Ads']) ?>;i++){
62
+ tp=document.getElementById("AdsCode"+i.toString()).innerHTML;
63
+ if(tp==''){
64
+ document.getElementById("AdsMargin"+i.toString()).value = "<?php echo($QData['Default']['AdsMargin']) ?>";
65
+ document.getElementById("OptAgn"+i.toString()+"<?php echo($QData['Default']['AdsAlign']) ?>").selected = true;
66
+ }
67
+ }
68
+ deftcheckinfo();
69
+ }
70
+ function selectinfo(ts) {
71
+ if (ts.selectedIndex == 0) { return; }
72
+ begnrnd = document.getElementById('BegnRnd');
73
+ endirnd = document.getElementById('EndiRnd');
74
+ if (ts == begnrnd) {
75
+ if (ts.selectedIndex == endirnd.selectedIndex) {
76
+ endirnd.selectedIndex += (endirnd.selectedIndex == <?php echo($QData['Ads']) ?>)?-1:1 ;
77
+ }
78
+ }
79
+ if (ts == endirnd) {
80
+ if (ts.selectedIndex == begnrnd.selectedIndex) {
81
+ begnrnd.selectedIndex += (begnrnd.selectedIndex == 0)?1:-1 ;
82
+ }
83
+ }
84
+ }
85
+ function checkinfo(selnme,ts) {
86
+ document.getElementById(selnme).disabled=!ts.checked;
87
+ }
88
+ function deftcheckinfo() {
89
+ checkinfo('BegnRnd',document.getElementById('BegnAds'));
90
+ checkinfo('EndiRnd',document.getElementById('EndiAds'));
91
+ }
92
+ </script>
93
+
94
+ <div class="wrap">
95
+ <h2>Quick Adsense <?php _e('Setting'); ?> <span style="font-size:9pt;font-style:italic">( Version <?php echo($QData['Version']) ?> )</span></h2>
96
+
97
+ <form method="post" action="options.php">
98
+ <?php wp_nonce_field('update-options'); ?>
99
+
100
+ <h3 style="font-size:120%"><?php _e('Options'); ?></h3>
101
+
102
+ <table border="0" cellspacing="0" cellpadding="0">
103
+ <tr valign="top">
104
+ <td style="width:110px"><?php _e('Adsense :'); ?></td>
105
+ <td><?php _e('Place up to '); ?><select name="AdsDisp" style="width:50px;font-weight:bold">
106
+ <option id="DisTot0" value="0" <?php if($dis=="0"){echo('selected');} ?>>0</option>
107
+ <option id="DisTot1" value="1" <?php if($dis=="1"){echo('selected');} ?>>1</option>
108
+ <option id="DisTot2" value="2" <?php if($dis=="2"){echo('selected');} ?>>2</option>
109
+ <option id="DisTot3" value="3" <?php if($dis=="3"){echo('selected');} ?>>3</option></select><?php _e(' Ads on a page.'); ?><br/>
110
+ <span class="description"><?php _e('(Google allows publishers to place up to <b>three</b> AdSense for Content Units on a page. If you have placed these ads somewhere in the page, you will need to take those into account.)'); ?></span><br/>
111
+ <br/>
112
+ </td>
113
+ </tr>
114
+ <tr valign="top">
115
+ <td style="width:110px"><?php _e('Position :'); ?></td>
116
+ <td>
117
+ <input type="checkbox" id="BegnAds" name="BegnAds" value="true" <?php if($ra1){echo('checked');} ?> onchange="checkinfo('BegnRnd',this)" /> <?php _e('Assign') ; ?> <select id="BegnRnd" name="BegnRnd" onchange="selectinfo(this)">
118
+ <?php for ($i=0;$i<=$QData['Ads'];$i++) { ?>
119
+ <option id="OptBegn<?php echo $i; ?>" value="<?php echo $i; ?>" <?php if($ra2==(string)$i){echo('selected');} ?>><?php _e(($i==0)?'Random Ads':'Ads'.$i) ; ?></option>
120
+ <?php } ?></select> <?php _e('to the <b>Begining of Post') ?></b><br/>
121
+ <input type="checkbox" id="EndiAds" name="EndiAds" value="false" <?php if($rb1){echo('checked');} ?> onchange="checkinfo('EndiRnd',this)" /> <?php _e('Assign') ; ?> <select id="EndiRnd" name="EndiRnd" onchange="selectinfo(this)">
122
+ <?php for ($i=0;$i<=$QData['Ads'];$i++) { ?>
123
+ <option id="OptEndi<?php echo $i; ?>" value="<?php echo $i; ?>" <?php if($rb2==(string)$i){echo('selected');} ?>><?php _e(($i==0)?'Random Ads':'Ads'.$i) ; ?></option>
124
+ <?php } ?></select> <?php _e('to the <b>End of Post') ?></b><br/>
125
+ <br/>
126
+ <script type="text/javascript">deftcheckinfo();</script>
127
+ </td>
128
+ </tr>
129
+ <tr valign="top">
130
+ <td style="width:110px"><?php _e('Appearance :'); ?></td>
131
+ <td>
132
+ <input type="checkbox" id="AppPost" name="AppPost" value="true" <?php if($aps){echo('checked');} ?> /> <?php _e('Posts'); ?>
133
+ <input type="checkbox" id="AppPage" name="AppPage" value="true" <?php if($apg){echo('checked');} ?> /> <?php _e('Pages'); ?><span> &nbsp;|&nbsp; </span>
134
+ <input type="checkbox" id="AppHome" name="AppHome" value="true" <?php if($ahm){echo('checked');} ?> /> <?php _e('Homepage'); ?>
135
+ <input type="checkbox" id="AppCate" name="AppCate" value="true" <?php if($act){echo('checked');} ?> /> <?php _e('Categories'); ?>
136
+ <input type="checkbox" id="AppArch" name="AppArch" value="true" <?php if($aar){echo('checked');} ?> /> <?php _e('Archives'); ?>
137
+ <input type="checkbox" id="AppTags" name="AppTags" value="true" <?php if($atg){echo('checked');} ?> /> <?php _e('Tags'); ?><br/>
138
+ <br/>
139
+ </td>
140
+ </tr>
141
+ <tr valign="top">
142
+ <td style="width:110px"><?php _e('Quicktag :'); ?></td>
143
+ <td><input type="checkbox" id="QckTags" name="QckTags" value="true" <?php if($aqt){echo('checked');} ?> /> <?php _e('Show Quicktag Buttons on the HTML Edit Post SubPanel.'); ?><br/>
144
+ <ol style="margin-top:5px;">
145
+ <li><?php _e('Insert a <span style="font-family:Courier New,Courier,Fixed;color:#050">&lt;!--Ads1--&gt;</span>, <span style="font-family:Courier New,Courier,Fixed;color:#050">&lt;!--Ads2--&gt;</span>, etc. into a post to show the <b>Particular Ads</b> at specific location.'); ?></li>
146
+ <li><?php _e('Insert a <span style="font-family:Courier New,Courier,Fixed;color:#050">&lt;!--RndAds--&gt;</span> (or more) into a post to show the <b>Random Ads</b> at specific location.'); ?></li>
147
+ <li><?php _e('Insert a <span style="font-family:Courier New,Courier,Fixed;color:#050">&lt;!--NoAds--&gt;</span> to <b>Disable Ads</b> in a post.'); ?></li>
148
+ <li><?php _e('Insert a <span style="font-family:Courier New,Courier,Fixed;color:#050">&lt;!--OffAds--&gt;</span> to <b>Disable All Ads</b> including AdsWidget.'); ?></li>
149
+ </ol>
150
+ <span class="description"><?php _e('(Tags above tags can be inserted into a post via the additional Quicktag Buttons added to the HTML Edit Post SubPanel.)'); ?></span><br/>
151
+ <br/>
152
+ </td>
153
+ </tr>
154
+ <tr valign="top">
155
+ <td style="width:110px"><?php _e('Infomation :'); ?></td>
156
+ <td>
157
+ <?php echo(__(
158
+ 'Visit <a href="http://techmilieu.com/quick-adsense" target="_blank">http://techmilieu.com/quick-adsense</a> for more information and updates about this plugin. '.
159
+ 'A link from your blog to http://techmilieu.com/ would be highly appreciated.')); ?><br/>
160
+ </tr>
161
+ </table>
162
+
163
+ <br/>
164
+ <h3 style="font-size:120%;margin-bottom:5px"><?php _e('Adsense Codes'); ?></h3>
165
+ <p style="margin-top:0px"><span class="description"><?php _e('Paste up to <b>'.$QData['Ads'].' Ads codes</b> on Post Body, according to the options as assigned above, and <b>'.$QData['AdsWid'].' Ads codes</b> on Sidebar Widget. Ads codes provided must be identical, repeated codes may result the Ads not being display correctly.') ?></span></p>
166
+
167
+ <h4><?php _e('Ads on Post Body :'); ?></h4>
168
+ <table border="0" cellspacing="0" cellpadding="0">
169
+ <?php for ($i=1;$i<=$QData['Ads'];$i++) {
170
+ $cod = get_option('AdsCode'.$i);
171
+ $agn = get_option('AdsAlign'.$i);
172
+ $mar = get_option('AdsMargin'.$i);
173
+ $optionsupdate .= ',AdsCode'.$i.',AdsAlign'.$i.',AdsMargin'.$i;
174
+ ?>
175
+ <tr valign="top">
176
+ <td align="left" style="width:100px">Ads<?php echo $i; ?> :</td>
177
+ <td align="left"><textarea style="margin:0 5px 3px 0" id="AdsCode<?php echo $i; ?>" name="AdsCode<?php echo $i; ?>" rows="3" cols="50"><?php echo $cod; ?></textarea></td>
178
+ <td align="left">
179
+ <select name="AdsAlign<?php echo $i; ?>">
180
+ <option id="OptAgn<?php echo $i; ?>1" value="1" <?php if($agn=="1"){echo('selected');} ?>><?php _e('Left') ; ?></option>
181
+ <option id="OptAgn<?php echo $i; ?>2" value="2" <?php if($agn=="2"){echo('selected');} ?>><?php _e('Center') ; ?></option>
182
+ <option id="OptAgn<?php echo $i; ?>3" value="3" <?php if($agn=="3"){echo('selected');} ?>><?php _e('Right') ; ?></option>
183
+ <option id="OptAgn<?php echo $i; ?>4" value="4" <?php if($agn=="4"){echo('selected');} ?>><?php _e('None') ; ?></option></select> <?php _e('alignment'); ?><br/>
184
+ <input style="width:35px;text-align:right;" id="AdsMargin<?php echo $i; ?>" name="AdsMargin<?php echo $i; ?>" value="<?php echo stripslashes(htmlspecialchars($mar)); ?>" />px <?php _e('margin'); ?><br/>
185
+ </td>
186
+ </tr>
187
+ <?php } ?>
188
+ </table>
189
+
190
+ <h4><?php _e('Ads on Sidebar Widget '); ?><span style="font-weight:normal">(<a href="widgets.php"><?php _e('Setting'); ?></a>)</span> :</h4>
191
+ <table border="0" cellspacing="0" cellpadding="0">
192
+ <?php for ($i=1;$i<=$QData['AdsWid'];$i++) {
193
+ $cod = get_option('WidCode'.$i);
194
+ $optionsupdate .= ',WidCode'.$i;
195
+ ?>
196
+ <tr valign="top">
197
+ <td align="left" style="width:100px">AdsWidget<?php echo $i; ?> :</td>
198
+ <td align="left"><textarea style="margin:0 5px 3px 0" id="WidCode<?php echo $i; ?>" name="WidCode<?php echo $i; ?>" rows="3" cols="50"><?php echo $cod; ?></textarea></td>
199
+ </tr>
200
+ <?php } ?>
201
+ </table>
202
+
203
+ <input type="hidden" name="action" value="update" />
204
+ <input type="hidden" name="page_options" value="<?php echo $optionsupdate; ?>" />
205
+ <div style="width:580px">
206
+ <span style="float:right;padding-top:18px">[ <a href="javascript:defaultoptions()"><?php _e('Load Default Setting') ?></a> ]</span>
207
+ <p class="submit">
208
+ <input type="submit" value="<?php _e('Save Changes') ?>" />
209
+ </p>
210
+ </div>
211
+
212
+ </form>
213
+
214
+ </div>
215
+
216
+
quick-adsense.php ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ Plugin Name: Quick Adsense
5
+ Plugin URI: http://techmilieu.com/quick-adsense
6
+ Description: Quick Adsense offers a quicker & flexible way to insert Google Adsense or any Ads code into a blog post.
7
+ Author: Philip Ze
8
+ Version: 1.0
9
+ Author URI: http://techmilieu.com/
10
+ */
11
+
12
+ /* Copyright 2009 Philip Ze [ http://techmilieu.com/quick-adsense ]
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+
29
+
30
+
31
+
32
+ global $QData;
33
+
34
+ $QData['AdsWid'] = 3; /* Ads on Widget */
35
+ $QData['Ads'] = 10; /* Ads on Post body */
36
+ $QData['Name'] = 'Quick Adsense';
37
+ $QData['Version'] = '1.0';
38
+ $QData['URI'] = 'http://techmilieu.com/quick-adsense';
39
+ $QData['AdsWidName'] = 'AdsWidget%d (Quick Adsense)';
40
+ $QData['Default'] = array(
41
+ 'AdsDisp'=>'3',
42
+ 'BegnAds'=>true,'BegnRnd'=>'1','EndiAds'=>true,'EndiRnd'=>'0',
43
+ 'AppPost'=>true,'AppPage'=>true,'AppHome'=>false,'AppCate'=>false,'AppArch'=>false,'AppTags'=>false,
44
+ 'QckTags'=>true,
45
+ 'AdsMargin'=>'10','AdsAlign'=>'2'
46
+ );
47
+
48
+ function ads_admin_page_inc() {
49
+ include('quick-adsense-admin.php');
50
+ }
51
+ function ads_admin_page() {
52
+ add_options_page("Quick Adsense Options", "Quick Adsense", 1, basename(__FILE__), "ads_admin_page_inc");
53
+ }
54
+ if(is_admin()) {
55
+ add_action('admin_menu', 'ads_admin_page');
56
+ }
57
+
58
+
59
+ function ads_plugin_links($links,$file) {
60
+ if($file==plugin_basename(__FILE__)) {
61
+ array_unshift($links,'<a href="options-general.php?page='.basename(__FILE__).'">'.__('Setting').'</a>');
62
+ }
63
+ return $links;
64
+ }
65
+ add_filter('plugin_action_links','ads_plugin_links',10,2);
66
+
67
+
68
+ function plugin_activated() {
69
+ global $QData;
70
+ update_option('AdsDisp', $QData['Default']['AdsDisp']);
71
+ update_option('BegnAds', $QData['Default']['BegnAds']);
72
+ update_option('BegnRnd', $QData['Default']['BegnRnd']);
73
+ update_option('EndiAds', $QData['Default']['EndiAds']);
74
+ update_option('EndiRnd', $QData['Default']['EndiRnd']);
75
+ update_option('AppPost', $QData['Default']['AppPost']);
76
+ update_option('AppPage', $QData['Default']['AppPage']);
77
+ update_option('AppHome', $QData['Default']['AppHome']);
78
+ update_option('AppCate', $QData['Default']['AppCate']);
79
+ update_option('AppArch', $QData['Default']['AppArch']);
80
+ update_option('AppTags', $QData['Default']['AppTags']);
81
+ update_option('QckTags', $QData['Default']['QckTags']);
82
+ for ($i=1;$i<=$QData['Ads'];$i++) {
83
+ $tp=get_option('AdsCode'.$i);
84
+ if(empty($tp)) {
85
+ update_option('AdsMargin'.$i, $QData['Default']['AdsMargin']);
86
+ update_option('AdsAlign'.$i, $QData['Default']['AdsAlign']);
87
+ }
88
+ }
89
+ }
90
+ register_activation_hook( __FILE__, 'plugin_activated' );
91
+
92
+
93
+ function ads_head_java() {
94
+ global $QData;
95
+ $tp = get_option('QckTags');
96
+ if ($tp) { ?>
97
+ <script type="text/javascript">
98
+ if(typeof(edButtons)!='undefined') {
99
+ for(i=1;i<=<?php echo($QData['Ads']) ?>;i++) {
100
+ edButtons[edButtons.length]=new edButton("ads"+i.toString(),"Ads"+i.toString(),"\n<!--Ads"+i.toString()+"-->\n","","",-1);
101
+ }
102
+ edButtons[edButtons.length]=new edButton("random_ads","RndAds","\n<!--RndAds-->\n","","",-1);
103
+ edButtons[edButtons.length]=new edButton("no_ads","NoAds","\n<!--NoAds-->\n","","",-1);
104
+ edButtons[edButtons.length]=new edButton("off_ads","OffAds","\n<!--OffAds-->\n","","",-1);
105
+ };
106
+ </script> <?php
107
+ }
108
+ }
109
+ add_action('admin_head', 'ads_head_java');
110
+
111
+
112
+ $ShownAds = 0;
113
+ $AdsId = array();
114
+ $beginend = 0;
115
+
116
+ function process_content($content)
117
+ {
118
+ global $QData;
119
+ global $ShownAds;
120
+ global $AdsId;
121
+ global $beginend;
122
+
123
+ /* verifying */
124
+ if( (strpos($content,'<!--NoAds-->')) ||
125
+ (strpos($content,'<!--OffAds-->')) ||
126
+ (is_single() && !(get_option('AppPost'))) ||
127
+ (is_page() && !(get_option('AppPage'))) ||
128
+ (is_home() && !(get_option('AppHome'))) ||
129
+ (is_category() && !(get_option('AppCate'))) ||
130
+ (is_archive() && !(get_option('AppArch'))) ||
131
+ (is_tag() && !(get_option('AppTags'))) ) {
132
+ $content = clean_tags($content); return $content;
133
+ }
134
+
135
+ $AdsToShow = get_option('AdsDisp');
136
+ for($i=1;$i<=$QData['AdsWid'];$i++) {
137
+ $wadsid = sanitize_title(sprintf($QData['AdsWidName'],$i));
138
+ $AdsToShow -= (is_active_widget(true, $wadsid)) ? 1 : 0 ;
139
+ }
140
+ if( $ShownAds >= $AdsToShow ) { $content = clean_tags($content); return $content; };
141
+
142
+ if( !count($AdsId) ) {
143
+ for($i=1;$i<=$QData['Ads'];$i++) {
144
+ $tmp = trim(get_option('AdsCode'.$i));
145
+ if( !empty($tmp) ) {
146
+ array_push($AdsId, $i);
147
+ }
148
+ }
149
+ }
150
+ if( !count($AdsId) ) { $content = clean_tags($content); return $content; };
151
+
152
+ /* ... Tidy up content ... */
153
+ $AdsIdCus = array();
154
+ $cusads = 'CusAds'; $cusrnd = 'CusRnd';
155
+ $begn1 = get_option('BegnAds'); $begn2 = get_option('BegnRnd');
156
+ $endi1 = get_option('EndiAds'); $endi2 = get_option('EndiRnd');
157
+ if ( $begn2 == 0 ) { $b1 = $cusrnd; } else { $b1 = $cusads.$begn2; array_push($AdsIdCus, $begn2); };
158
+ if ( $endi2 == 0 ) { $b2 = $cusrnd; } else { $b2 = $cusads.$endi2; array_push($AdsIdCus, $endi2); };
159
+ if( $begn1 && $endi1 ) {
160
+ $content = '<!--'.$b1.'-->'.$content.'<!--'.$b2.'-->' ;
161
+ } else if( $begn1 ) {
162
+ $content = '<!--'.$b1.'-->'.$content;
163
+ } else if( $endi1 ) {
164
+ $content = $content.'<!--'.$b1.'-->';
165
+ }
166
+ $content = '<!--EmptyClear-->'.$content.PHP_EOL.'<div style="font-size:0px;height:1px;line-height:0px;margin:0;padding:0;clear:both"></div>';
167
+ clean_tags($content, true);
168
+ $ismany = (!is_single() && !is_page());
169
+
170
+ /* ... Replace Begining/End Ads1-10 ... */
171
+ for( $i=1; $i<=count($AdsIdCus); $i++ ) {
172
+ if( !$ismany || $beginend != $i ) {
173
+ if( strpos($content, '<!--'.$cusads.$AdsIdCus[$i-1].'-->') && in_array($AdsIdCus[$i-1], $AdsId)) {
174
+ $content = replace_ads( $content, $cusads.$AdsIdCus[$i-1], $AdsIdCus[$i-1] ); $AdsId = del_element($AdsId, array_search($AdsIdCus[$i-1], $AdsId)) ;
175
+ $ShownAds += 1; if( $ShownAds >= $AdsToShow || !count($AdsId) ){ $content = clean_tags($content); return $content; };
176
+ $beginend = $i; if($ismany){break;}
177
+ }
178
+ }
179
+ }
180
+ /* ... Replace Ads1 to Ads10 ... */
181
+ if( !$ismany ) {
182
+ $tcn = count($AdsId); $tt = 0;
183
+ for( $i=1; $i<=$tcn; $i++ ) {
184
+ if( strpos($content, '<!--Ads'.$AdsId[$tt].'-->') ) {
185
+ $content = replace_ads( $content, 'Ads'.$AdsId[$tt], $AdsId[$tt] ); $AdsId = del_element($AdsId, $tt) ;
186
+ $ShownAds += 1; if( $ShownAds >= $AdsToShow || !count($AdsId) ){ $content = clean_tags($content); return $content; };
187
+ } else {
188
+ $tt += 1;
189
+ }
190
+ }
191
+ }
192
+ /* ... Replace Begining/End random Ads ... */
193
+ if( strpos($content, '<!--'.$cusrnd.'-->') && !$ismany ) {
194
+ $tcx = count($AdsId);
195
+ $tcy = substr_count($content, '<!--'.$cusrnd.'-->');
196
+ for( $i=$tcx; $i<=$tcy-1; $i++ ) {
197
+ array_push($AdsId, -1);
198
+ }
199
+ shuffle($AdsId);
200
+ for( $i=1; $i<=$tcy; $i++ ) {
201
+ $content = replace_ads( $content, $cusrnd, $AdsId[0] ); $AdsId = del_element($AdsId, 0) ;
202
+ $ShownAds += 1; if( $ShownAds >= $AdsToShow || !count($AdsId) ){ $content = clean_tags($content); return $content; };
203
+ }
204
+ }
205
+ /* ... Replace RndAds ... */
206
+ if( strpos($content, '<!--RndAds-->') && !$ismany ) {
207
+ $AdsIdTmp = array();
208
+ shuffle($AdsId);
209
+ for( $i=1; $i<=$AdsToShow-$ShownAds; $i++ ) {
210
+ if( $i <= count($AdsId) ) {
211
+ array_push($AdsIdTmp, $AdsId[$i-1]);
212
+ }
213
+ }
214
+ $tcx = count($AdsIdTmp);
215
+ $tcy = substr_count($content, '<!--RndAds-->');
216
+ for( $i=$tcx; $i<=$tcy-1; $i++ ) {
217
+ array_push($AdsIdTmp, -1);
218
+ }
219
+ shuffle($AdsIdTmp);
220
+ for( $i=1; $i<=$tcy; $i++ ) {
221
+ $tmp = $AdsIdTmp[0];
222
+ $content = replace_ads( $content, 'RndAds', $AdsIdTmp[0] ); $AdsIdTmp = del_element($AdsIdTmp, 0) ;
223
+ if($tmp != -1){$ShownAds += 1;}; if( $ShownAds >= $AdsToShow || !count($AdsIdTmp) ){ $content = clean_tags($content); return $content; };
224
+ }
225
+ }
226
+
227
+ /* ... That's it. DONE :) ... */
228
+ $content = clean_tags($content); return $content;
229
+ }
230
+ function clean_tags($content, $trimonly = false) {
231
+ global $QData;
232
+ $tagnames = array('EmptyClear','RndAds','NoAds','OffAds','CusRnd');
233
+ for($i=1;$i<=$QData['Ads'];$i++) { array_push($tagnames, 'CusAds'.$i); array_push($tagnames, 'Ads'.$i); };
234
+ foreach ($tagnames as $tgn) {
235
+ if(strpos($content,'<!--'.$tgn.'-->') || $tgn=='EmptyClear') {
236
+ if($trimonly) {
237
+ $content = str_replace('<p><!--'.$tgn.'--></p>', '<!--'.$tgn.'-->', $content);
238
+ }else{
239
+ $content = str_replace(array('<p><!--'.$tgn.'--></p>','<!--'.$tgn.'-->'), '', $content);
240
+ }
241
+ }
242
+ }
243
+ return $content;
244
+ }
245
+ function replace_ads($content, $nme, $adn) {
246
+ if( !strpos($content,'<!--'.$nme.'-->') ) { return $content; }
247
+ global $QData;
248
+ if ($adn != -1) {
249
+ $arr = array('',
250
+ 'float:left;margin:%1$dpx %1$dpx %1$dpx 0;',
251
+ 'float:none;margin:%1$dpx 0 %1$dpx 0;text-align:center;',
252
+ 'float:right;margin:%1$dpx 0 %1$dpx %1$dpx;',
253
+ 'float:none;margin:0px;');
254
+ $adsalign = get_option('AdsAlign'.$adn);
255
+ $adsmargin = get_option('AdsMargin'.$adn);
256
+ $style = sprintf($arr[(int)$adsalign], $adsmargin);
257
+ $adscode = get_option('AdsCode'.$adn);
258
+ $adscode =
259
+ PHP_EOL.'<!-- '.$QData['Name'].' Wordpress Plugin: '.$QData['URI'].' -->'.PHP_EOL.
260
+ '<div style="'.$style.'">'.PHP_EOL.
261
+ $adscode.PHP_EOL.
262
+ '</div>'.PHP_EOL;
263
+ } else {
264
+ $adscode ='';
265
+ }
266
+ $cont = explode('<!--'.$nme.'-->', $content, 2);
267
+ return $cont[0].$adscode.$cont[1];
268
+ }
269
+ function del_element($array, $idx) {
270
+ $copy = array();
271
+ for( $i=0; $i<count($array) ;$i++) {
272
+ if ( $idx != $i ) {
273
+ array_push($copy, $array[$i]);
274
+ }
275
+ }
276
+ return $copy;
277
+ }
278
+ add_filter('the_content', 'process_content');
279
+
280
+
281
+ function ads_widget_register() {
282
+ global $QData;
283
+ if (!function_exists('register_sidebar_widget') || !function_exists('register_widget_control')) { return; };
284
+ for($i=1;$i<=$QData['AdsWid'];$i++) {
285
+ $displaystr =
286
+ '$cont = get_the_content("",0,"");'.
287
+ 'if(!strpos($cont,"<!--OffAds-->")) {'.
288
+ 'extract($args);'.
289
+ '$title = get_option("WidCode-title-'.$i.'");'.
290
+ '$codetxt = get_option("WidCode'.$i.'");'.
291
+ 'echo $before_widget;'.
292
+ 'if (!empty($title)) { echo $before_title.$title.$after_title; };'.
293
+ 'echo $codetxt;'.
294
+ 'echo $after_widget;'.
295
+ '}';
296
+ $controlstr =
297
+ 'if ($_POST["WidCodeSubmit'.$i.'"]) {'.
298
+ ' update_option_en("WidCode-title-'.$i.'", $_POST["WidCode-title-'.$i.'"], "strip_tags");'.
299
+ ' update_option_en("WidCode'.$i.'", $_POST["WidCode'.$i.'"]);'.
300
+ '}'.
301
+ '$title = get_option_en("WidCode-title-'.$i.'");'.
302
+ '$codetxt = get_option_en("WidCode'.$i.'");'.
303
+ 'echo "<p><label>'.__('Title:').'</label>";'.
304
+ 'echo "<input style=\"width:100%;\" id=\"WidCode-title-'.$i.'\" name=\"WidCode-title-'.$i.'\" type=\"text\" value=\"".$title."\" />";'.
305
+ 'echo "<p><textarea style=\"width:100%;height:150px;\" id=\"WidCode'.$i.'\" name=\"WidCode'.$i.'\">".$codetxt."</textarea><br\>";'.
306
+ 'echo "<a style=\"font-size:8pt;text-decoration:none\" href=\"options-general.php?page='.basename(__FILE__).'\">'.__('Quick Adsense Setting').'</a></p>";'.
307
+ 'echo "<input type=\"hidden\" id=\"WidCodeSubmit'.$i.'\" name=\"WidCodeSubmit'.$i.'\" value=\"true\" />";';
308
+ $displaycall[$i] = create_function('$args', $displaystr);
309
+ $controlcall[$i] = create_function('', $controlstr);
310
+ }
311
+ for($i=1;$i<=$QData['AdsWid'];$i++) {
312
+ $wadsid = sprintf($QData['AdsWidName'],$i);
313
+ register_sidebar_widget($wadsid, $displaycall[$i]);
314
+ register_widget_control($wadsid, $controlcall[$i]);
315
+ }
316
+ }
317
+ function get_option_en($nameid)
318
+ {
319
+ $txt = get_option($nameid);
320
+ $txt = htmlspecialchars($txt, ENT_QUOTES);
321
+ if(!empty($txt)) { return $txt; }else{ return ""; };
322
+ }
323
+ function update_option_en($nameid, $text, $opt='')
324
+ {
325
+ $txt = stripslashes($text);
326
+ if ($opt=='strip_tags') { $txt = strip_tags($txt); };
327
+ update_option($nameid, $txt);
328
+ if(!empty($txt)) { return $txt; }else{ return ""; };
329
+ }
330
+ add_action('init', ads_widget_register);
331
+
332
+
333
+
334
+ ?>
readme.txt ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Quick Adsense ===
2
+ Contributors: Philip Ze
3
+ Donate link: http://techmilieu.com/quick-adsense/
4
+ Tags: WordPress Plugin, adsense, google adsense, random adsense, random ads, advertising, adsense insertion, ad manager, ad, yahoo, google, ads, text insertion, widget, sidebar, admin, posts, plugin
5
+ Requires at least: 2.5
6
+ Tested up to: 2.8.4
7
+ Stable tag: 1.0
8
+
9
+ Quick Adsense offers a quicker & flexible way to insert Google Adsense or any Ads code into a blog post.
10
+
11
+ == Description ==
12
+
13
+ **Quick Adsense** is an Ads management Wordpress plugin. It offers a quicker & flexible way to insert Adsense or any Ads code into a blog post. Besides, it can randomly place the Ads anywhere within a post. It comes with a simple setting page, and it does not overwhelm you with complicated customizable options.
14
+
15
+ In general, placing Adsense randomly within a post is a good way to experiment a variety of ads formats & placements besides optimizing your Adsense. If you have many regular visitors who frequently revisit your blog, the **randomization** will likely catch their attention.
16
+
17
+ Here are some **features** that come with this plugin:
18
+
19
+ 1. Absolutely NO author revenue reward or revenue sharing from your Adsense or that kind of features.
20
+ 1. Flexible Ads placement, insert Ads specifically or randomly anywhere within a post, including at the beginning or end of post.
21
+ 1. Simple configuration interface, requires no coding knowledge: Just copy and paste AdSense code, tick & select options, the plugin will then do the rest for you.
22
+ 1. Support any Ads code, not limited to Adsense code only.
23
+ 1. Display up to a maximum of 3 Ads on a page.
24
+ 1. Support up to a maximum of 3 Ads codes on Sidebar Widgets.
25
+ 1. Support up to a maximum of 10 Ads codes for Randomization within a post.
26
+ 1. Ads placement on the fly, simply insert &lt;!--Ads1--&gt;, &lt;!--Ads2--&gt; ... , &lt;!--RndAds--&gt;, &lt;!--NoAds--&gt;, &lt;!--OffAds--&gt; to a post to accomplish this.
27
+ 1. Tags above can be inserted into a post easily via the additional Quicktag Buttons added to the HTML Edit Post SubPanel.
28
+
29
+ Sign up for a [Google Adsense Account](http://adsense.google.com/) to generate revenue from your blog, if you don't have one.
30
+
31
+ [Download](http://wordpress.org/extend/plugins/quick-adsense/download/) | [Installation](http://wordpress.org/extend/plugins/quick-adsense/installation/) | [Screen Shots](http://wordpress.org/extend/plugins/quick-adsense/screenshots/) | [Plugin Homepage](http://techmilieu.com/quick-adsense)
32
+
33
+ == Screenshots ==
34
+
35
+ 1. Screen shot showing the additional Quicktag Buttons added to the HTML Edit Post SubPanel.
36
+ 2. The Settings page from Quick Adsense plugin. There are many ways to configure your Ads display, specifically or randomly as you wish.
37
+
38
+ == Installation ==
39
+
40
+ 1. Unzip the downloaded plugin and upload the folder "quick-adsense" to the "/wp-content/plugins/" directory.
41
+ 1. Go to the plugin menu in WordPress and activate the plugin.
42
+ 1. Go to the "Settings-&gt;Quick Adsense" page and configure the options. Paste the Ads codes to the respective text box.
43
+ 1. Optionally, insert the trigger Tags into a post via the additional Quicktag Buttons added to the HTML Edit Post SubPanel.
44
+
45
+ == Frequently Asked Questions ==
46
+
47
+ Please feedback to [http://techmilieu.com/quick-adsense](http://techmilieu.com/quick-adsense) for any bug you might have found, or any suggestion you like to add.
48
+
49
+ == Change Log ==
50
+
51
+ * 1.0 Initial public release. [September 21, 2009]
52
+
53
+
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file