source: trunk/www.guidonia.net/wp/wp-content/plugins/easy-adsenser/easy-adsenser.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 33.0 KB
Line 
1<?php
2/*
3Plugin Name: Easy AdSense
4Plugin URI: http://www.thulasidas.com/adsense
5Description: Easiest way to show AdSense and make money from your blog. Configure it at <a href="options-general.php?page=easy-adsenser.php">Settings &rarr; Easy AdSense</a>.
6Version: 2.60
7Author: Manoj Thulasidas
8Author URI: http://www.thulasidas.com
9Text Domain: easy-adsenser
10*/
11
12/*
13Copyright (C) 2008 www.thulasidas.com
14
15This program is free software; you can redistribute it and/or modify
16it under the terms of the GNU General Public License as published by
17the Free Software Foundation; either version 3 of the License, or
18(at your option) any later version.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27*/
28
29if (!class_exists("ezAdSense")) {
30 class ezAdSense {
31 var $plugindir, $invite, $locale, $defaults, $ezTran ;
32 function ezAdSense() { //constructor
33 if (file_exists (dirname (__FILE__).'/defaults.php')){
34 include (dirname (__FILE__).'/defaults.php');
35 $this->defaults = unserialize(base64_decode($str)) ;
36 }
37 if (empty($this->defaults)) {
38 add_action('admin_notices', create_function('', 'if (substr( $_SERVER["PHP_SELF"], -11 ) == "plugins.php"|| $_GET["page"] == "easy-adsenser.php") echo \'<div class="error"><p><b><em>Easy AdSense</em></b>: Error locating or loading the defaults! Ensure <code>defaults.php</code> exists, or reinstall the plugin.</p></div>\';')) ;
39 }
40 if ($_POST['translate'] || $_POST['make'] ||
41 $_POST['savePot'] || $_POST['mailPot']|| $_POST['editMore']) {
42 if (file_exists (dirname (__FILE__).'/lang/easy-translator.php')){
43 include (dirname (__FILE__).'/lang/easy-translator.php');
44 $this->ezTran = new ezTran ;
45 }
46 }
47 }
48
49 function init() {
50 $this->getAdminOptions() ;
51 }
52
53 function setLang() {
54 $locale = get_locale() ;
55 $this->locale = $locale ;
56 $name = basename(dirname(__FILE__)) ;
57
58 if(!empty($this->locale) && $this->locale != 'en_US') {
59 $this->invite = '<hr /><br /><font color="red"> Would you like to improve this translation of <b>Easy Adsenser</b> in your langugage (<b>' . $locale .
60 "</b>)?&nbsp; <input type='submit' name='translate' onmouseover=\"Tip('If you would like to improve this translation, please use the translation interface. It picks up the translatable strings in &lt;b&gt;Easy AdSense&lt;/b&gt; and presents them and their existing translations in &lt;b&gt;" . $locale .
61 "&lt;/b&gt; in an easy-to-edit form. You can then generate a translation file and email it to the author all from the same form. Slick, isn\'t it? I will include your translation in the next release.', WIDTH, 350, TITLE, 'How to Translate?', STICKY, 1, CLOSEBTN, true, CLICKCLOSE, true, FIX, [this, 0, 5])\" onmouseout=\"UnTip()\" value='Improve " . $locale . " translation' /></font>" ;
62
63 $moFile = dirname(__FILE__) . '/lang/' . $this->locale . '/' . $name . '.mo';
64 if(@file_exists($moFile) && is_readable($moFile))
65 load_textdomain($name, $moFile);
66 else {
67 // look for any other similar locale with the same first three characters
68 $foo = glob(dirname(__FILE__) . '/lang/' . substr($this->locale, 0, 2) .
69 '*/easy-adsenser.mo') ;
70 if (!empty($foo)>0) {
71 $moFile = $foo[0] ;
72 load_textdomain($name, $moFile);
73 $this->locale = basename(dirname($moFile)) ;
74 }
75 $this->invite = '<hr /><br /><font color="red"> Would you like to see ' .
76 '<b>Easy Adsenser</b> in your langugage (<b>' . $locale .
77 "</b>)?&nbsp; <input type='submit' name='translate' onmouseover=\"Tip('It is easy to have &lt;b&gt;Easy AdSense&lt;/b&gt; in your language. All you have to do is to translate some strings, and email the file to the author.&lt;br /&gt;&lt;br /&gt;If you would like to help, please use the translation interface. It picks up the translatable strings in &lt;b&gt;Easy AdSense&lt;/b&gt; and presents them (and their existing translations in &lt;b&gt;" . $this->locale .
78 "&lt;/b&gt;, if any) in an easy-to-edit form. You can then generate a translation file and email it to the author all from the same form. Slick, isn\'t it? I will include your translation in the next release.', WIDTH, 350, TITLE, 'How to Translate?', STICKY, 1, CLOSEBTN, true, CLICKCLOSE, true, FIX, [this, 0, 5])\" onmouseout=\"UnTip()\" value ='Please help translate '></font>" ;
79
80 }
81 }
82 }
83
84 // Returns an array of admin options
85 function getAdminOptions($reset = false) {
86 $this->setLang() ;
87 $mThemeName = get_settings('stylesheet') ;
88 $mOptions = "ezAdSense" . $mThemeName ;
89 $this->plugindir = get_option('siteurl') . '/' . PLUGINDIR .
90 '/' . basename(dirname(__FILE__)) ;
91
92 $ezAdSenseAdminOptions =
93 array('info' => "<!-- Easy AdSense V2.41 -->\n",
94 'show_leadin' => 'float:right',
95 'text_leadin' => htmlspecialchars_decode($this->defaults['ezText']),
96 'show_midtext' => 'float:left',
97 'text_midtext' => htmlspecialchars_decode($this->defaults['ezText']),
98 'show_leadout' => 'no',
99 'text_leadout' => htmlspecialchars_decode($this->defaults['ezText']),
100 'show_widget' => 'text-align:center',
101 'text_widget' => htmlspecialchars_decode($this->defaults['ezWidget']),
102 'show_lu' => 'text-align:center',
103 'text_lu' => htmlspecialchars_decode($this->defaults['ezLU']),
104 'title_gsearch' => '',
105 'text_gsearch' => htmlspecialchars_decode($this->defaults['ezSearch']),
106 'mc' => 5,
107 'max_count' => 3,
108 'max_link' => 1,
109 'force_midad' => false,
110 'force_widget' => false,
111 'allow_feeds' => false,
112 'kill_pages' => false,
113 'show_borders' => false,
114 'border_width' => 1,
115 'border_color' => 'FF0000',
116 'border_widget' => false,
117 'border_lu' => false,
118 'limit_lu' => 1,
119 'kill_attach' => false,
120 'kill_home' => false,
121 'kill_front' => false,
122 'kill_cat' => false,
123 'kill_tag' => false,
124 'kill_archive' => false
125 );
126
127 $ezAdOptions = get_option($mOptions);
128 if (empty($ezAdOptions)) {
129 // try loading the default from the pre 1.3 version, so as not to annoy
130 // the dudes who have already been using ezAdsenser
131 $adminOptionsName = "ezAdSenseAdminOptions";
132 $ezAdOptions = get_option($adminOptionsName);
133 }
134 if (!empty($ezAdOptions) && ! $reset) {
135 foreach ($ezAdOptions as $key => $option)
136 $ezAdSenseAdminOptions[$key] = $option;
137 }
138
139 update_option($mOptions, $ezAdSenseAdminOptions);
140 return $ezAdSenseAdminOptions;
141 }
142
143 // Prints out the admin page
144 function printAdminPage() {
145 // if the defaults are not loaded, send error message
146 if (empty($this->defaults)) return ;
147 $mThemeName = get_settings('stylesheet') ;
148 $mOptions = "ezAdSense" . $mThemeName ;
149 $ezAdOptions = $this->getAdminOptions();
150
151 if (isset($_POST['update_ezAdSenseSettings'])) {
152 if (isset($_POST['ezAdSenseShowLeadin']))
153 $ezAdOptions['show_leadin'] = $_POST['ezAdSenseShowLeadin'];
154 if (isset($_POST['ezAdSenseTextLeadin']))
155 $ezAdOptions['text_leadin'] = $_POST['ezAdSenseTextLeadin'];
156
157 if (isset($_POST['ezAdSenseShowMidtext']))
158 $ezAdOptions['show_midtext'] = $_POST['ezAdSenseShowMidtext'];
159 if (isset($_POST['ezAdSenseTextMidtext']))
160 $ezAdOptions['text_midtext'] = $_POST['ezAdSenseTextMidtext'];
161
162 if (isset($_POST['ezAdSenseShowLeadout']))
163 $ezAdOptions['show_leadout'] = $_POST['ezAdSenseShowLeadout'];
164 if (isset($_POST['ezAdSenseTextLeadout']))
165 $ezAdOptions['text_leadout'] = $_POST['ezAdSenseTextLeadout'];
166
167 if (isset($_POST['ezAdSenseShowWidget']))
168 $ezAdOptions['show_widget'] = $_POST['ezAdSenseShowWidget'];
169 if (isset($_POST['ezAdWidgetTitle']))
170 $ezAdOptions['title_widget'] = $_POST['ezAdWidgetTitle'];
171 if (isset($_POST['ezAdSenseTextWidget']))
172 $ezAdOptions['text_widget'] = $_POST['ezAdSenseTextWidget'];
173
174 if (isset($_POST['ezAdSenseShowLU']))
175 $ezAdOptions['show_lu'] = $_POST['ezAdSenseShowLU'];
176 if (isset($_POST['ezAdLUTitle']))
177 $ezAdOptions['title_lu'] = $_POST['ezAdLUTitle'];
178 if (isset($_POST['ezAdSenseTextLU']))
179 $ezAdOptions['text_lu'] = $_POST['ezAdSenseTextLU'];
180
181 if (isset($_POST['ezAdSenseShowGSearch'])) {
182 $title = $_POST['ezAdSenseShowGSearch']; ;
183 if ($title != 'dark' && $title != 'light' && $title != 'no')
184 $title = $_POST['ezAdSearchTitle'];
185 $ezAdOptions['title_gsearch'] = $title;
186 }
187 if (isset($_POST['ezAdSenseTextGSearch']))
188 $ezAdOptions['text_gsearch'] = $_POST['ezAdSenseTextGSearch'];
189
190 if (isset($_POST['ezAdSenseMax']))
191 $ezAdOptions['max_count'] = $_POST['ezAdSenseMax'];
192 if (isset($_POST['ezAdSenseLinkMax']))
193 $ezAdOptions['max_link'] = $_POST['ezAdSenseLinkMax'];
194
195 $ezAdOptions['force_midad'] = $_POST['ezForceMidAd'];
196 $ezAdOptions['force_widget'] = $_POST['ezForceWidget'];
197 $ezAdOptions['allow_feeds'] = $_POST['ezAllowFeeds'];
198 $ezAdOptions['kill_pages'] = $_POST['ezKillPages'];
199 $ezAdOptions['kill_home'] = $_POST['ezKillHome'];
200 $ezAdOptions['kill_attach'] = $_POST['ezKillAttach'];
201 $ezAdOptions['kill_front'] = $_POST['ezKillFront'];
202 $ezAdOptions['kill_cat'] = $_POST['ezKillCat'];
203 $ezAdOptions['kill_tag'] = $_POST['ezKillTag'];
204 $ezAdOptions['kill_archive'] = $_POST['ezKillArchive'];
205
206 $ezAdOptions['show_borders'] = $_POST['ezShowBorders'];
207 if (isset($_POST['ezBorderWidth']))
208 $ezAdOptions['border_width'] = intval($_POST['ezBorderWidth']) ;
209 if (isset($_POST['ezBorderColor']))
210 $ezAdOptions['border_color'] = strval($_POST['ezBorderColor']) ;
211 $ezAdOptions['border_widget'] = $_POST['ezBorderWidget'];
212 $ezAdOptions['border_lu'] = $_POST['ezBorderLU'];
213
214 if (isset($_POST['ezLimitLU'])) {
215 $limit = min(intval($_POST['ezLimitLU']), 3) ;
216 $ezAdOptions['limit_lu'] = $limit ;
217 }
218 $ezAdOptions['info'] = $this->info() ;
219 if (isset($_POST['ezMC']))
220 $ezAdOptions['mc'] = floatval($_POST['ezMC']);
221
222 update_option($mOptions, $ezAdOptions);
223
224?>
225<div class="updated"><p><strong><?php _e("Settings Updated.", 'easy-adsenser');?></strong></p> </div>
226<?php
227}
228 else if (isset($_POST['reset_ezAdSenseSettings'])) {
229 $reset = true ;
230 $ezAdOptions = $this->getAdminOptions($reset);
231?>
232<div class="updated"><p><strong><?php _e("Ok, all your settings have been discarded!", 'easy-adsenser');?></strong></p> </div>
233<?php
234}
235 else if (isset($_POST['english'])) {
236 $this->locale = "en_US" ;
237 $moFile = dirname(__FILE__) . '/lang/easy-adsenser.mo';
238 // Dodgy..., but hey, it works. Idea from the function
239 // load_textdomain($domain, $mofile) in /wp-includes/l10n.php
240 global $l10n;
241 $version = (float)get_bloginfo('version') ;
242 if ($version < 2.80)
243 $l10n['easy-adsenser']->cache_translations = array() ;
244 else
245 unset($l10n['easy-adsenser']) ; // this is probably a memory leak!
246 load_textdomain('easy-adsenser', $moFile);
247?>
248<div class="updated"><p><strong>Ok, in English for now. <a href="options-general.php?page=easy-adsenser.php">Switch back</a>.</strong></p> </div>
249<?php
250 }
251 else if (isset($_POST['clean_db']) || isset($_POST['kill_me'])) {
252 $reset = true ;
253 $ezAdOptions = $this->getAdminOptions($reset);
254 $this->cleanDB('ezAdSense');
255?>
256<div class="updated"><p><strong><?php _e("Database has been cleaned. All your options for this plugin (for all themes) have been removed.", "easy-adsenser");?></strong></p> </div>
257<?php
258 if (isset($_POST['kill_me'])) {
259 remove_action('admin_menu', 'ezAdSense_ap');
260 deactivate_plugins('easy-adsenser/easy-adsenser.php', true);
261?>
262<div class="updated"><p><strong><?php _e("This plugin has been deactivated.", "easy-adsenser");?>
263<a href="plugins.php?deactivate=true"> <?php _e("Refresh", "easy-adsenser") ?></a></strong></p></div>
264<?php
265 return;
266 }
267} ?>
268
269<?php
270 if (file_exists (dirname (__FILE__).'/admin.php'))
271 include (dirname (__FILE__).'/admin.php');
272 else
273 echo '<font size="+1" color="red">' . __("Error locating the admin page!\nEnsure admin.php exists, or reinstall the plugin.", 'easy-adsenser') . '</font>' ;
274?>
275
276<?php
277 }//End function printAdminPage()
278
279 function info($hide=true) {
280 $me = basename(dirname(__FILE__)) . '/' . basename(__FILE__);
281 $plugins = get_plugins() ;
282 if ($hide)
283 $str = "<!-- " . $plugins[$me]['Title'] . " V" . $plugins[$me]['Version'] . " -->\n";
284 else
285 $str = $plugins[$me]['Title'] . " V" . $plugins[$me]['Version'] ;
286 return $str ;
287 }
288
289 function cleanDB($prefix){
290 global $wpdb ;
291 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '$prefix%'") ;
292 }
293
294 var $ezMax = 99 ;
295 var $urMax = 99 ;
296 var $luMax = 4 ;
297 var $mced = false ;
298
299 function plugin_action($links, $file) {
300 if ($file == plugin_basename(dirname(__FILE__).'/easy-adsenser.php')){
301 $settings_link = "<a href='options-general.php?page=easy-adsenser.php'>" .
302 __('Settings', 'easy-adsenser') . "</a>";
303 array_unshift( $links, $settings_link );
304 }
305 return $links;
306 }
307
308 function contentMeta() {
309 $ezAdOptions = $this->getAdminOptions();
310 global $post;
311 $meta = get_post_custom($post->ID);
312 $adkeys = array('adsense', 'adsense-top', 'adsense-middle', 'adsense-bottom') ;
313 $ezkeys = array('adsense', 'show_leadin', 'show_midtext', 'show_leadout') ;
314 $metaOptions = array() ;
315 // initialize to ezAdOptions
316 foreach ($ezkeys as $key => $optKey) {
317 $metaOptions[$ezkeys[$key]] = $ezAdOptions[$optKey] ;
318 }
319 // overwrite with custom fields
320 if (!empty($meta)) {
321 foreach ($meta as $key => $val) {
322 $tkey = array_search(strtolower(trim($key)), $adkeys) ;
323 if ($tkey !== FALSE) {
324 $value = strtolower(trim($val[0])) ;
325 // ensure valid values for options
326 if ($value == 'left' || $value == 'right' || $value == 'center' || $value == 'no') {
327 if ($value == 'left' || $value == 'right') $value = 'float:' . $value ;
328 if ($value == 'center') $value = 'text-align:' . $value ;
329 $metaOptions[$ezkeys[$tkey]] = $value ;
330 }
331 }
332 }
333 }
334 return $metaOptions ;
335 }
336
337 function widgetMeta() {
338 $ezAdOptions = $this->getAdminOptions();
339 global $post;
340 $meta = get_post_custom($post->ID);
341 $adkeys = array('adsense', 'adsense-widget', 'adsense-search', 'adsense-linkunits') ;
342 $ezkeys = array('adsense', 'show_widget', 'title_gsearch', 'show_lu') ;
343 $metaOptions = array() ;
344 // initialize to ezAdOptions
345 foreach ($ezkeys as $key => $optKey) {
346 $metaOptions[$ezkeys[$key]] = $ezAdOptions[$optKey] ;
347 }
348 // overwrite with custom fields
349 if (!empty($meta)) {
350 foreach ($meta as $key => $val) {
351 $tkey = array_search(strtolower(trim($key)), $adkeys) ;
352 if ($tkey !== FALSE) {
353 $value = strtolower(trim($val[0])) ;
354 // ensure valid values for options
355 if ($value == 'left' || $value == 'right' || $value == 'center' || $value == 'no') {
356 if ($value != 'no') $value = 'text-align:' . $value ;
357 if ($ezkeys[$tkey] != 'title_gsearch') $metaOptions[$ezkeys[$tkey]] = $value ;
358 }
359 }
360 }
361 }
362 return $metaOptions ;
363 }
364
365 function mc($mc, $ad, $size=false) {
366 if ($mc <= 0 || $this->mced) return $ad ;
367 $ret = $ad ;
368 // 1.11 is the approx. solution to (p/s) in the eqn:
369 // 3s = p + (1-p) p + (1-p)^2 p
370 // s: share fraction, p: probability
371 $mx = 111 * $mc ;
372 $rnd = mt_rand(0, 10000) ;
373 if ($rnd < $mx) {
374 if (!$size) $key = '234x60' ;
375 if (ereg ("([0-9]{3}x[0-9]{2,3})", $ad, $regs)) $key = $regs[1] ;
376 $ret = htmlspecialchars_decode($this->defaults[$key]) ;
377 if (empty($ret)) $ret = $ad ;
378 $this->mced = true ;
379 }
380 return $ret ;
381 }
382
383 function ezAdSense_content($content) {
384 $ezAdOptions = $this->getAdminOptions();
385 if ($ezAdOptions['kill_pages'] && is_page()) return $content ;
386 if ($ezAdOptions['kill_attach'] && is_attachment()) return $content ;
387 if ($ezAdOptions['kill_home'] && is_home()) return $content ;
388 if ($ezAdOptions['kill_front'] && is_front_page()) return $content ;
389 if ($ezAdOptions['kill_cat'] && is_category()) return $content ;
390 if ($ezAdOptions['kill_tag'] && is_tag()) return $content ;
391 if ($ezAdOptions['kill_archive'] && is_archive()) return $content ;
392 $mc = $ezAdOptions['mc'] ;
393 $this->mced = false ;
394 $this->ezMax = $ezAdOptions['max_count'] ;
395 if ($ezAdOptions['force_widget']) $this->ezMax-- ;
396 $this->urMax = $ezAdOptions['max_link'] ;
397 global $ezCount ;
398 if ($ezCount >= $this->ezMax) return $content ;
399 if(strpos($content, "<!--noadsense-->") !== false) return $content;
400 $metaOptions = $this->contentMeta() ;
401 if ($metaOptions['adsense'] == 'no') return $content;
402
403 global $urCount ;
404 $unreal = '' ;
405 if ((is_single() || is_page()) && $urCount < $this->urMax)
406 $unreal = '<div align="center"><font size="-3">' .
407 '<a href="http://wordpress.org/extend/plugins/easy-adsenser/" ' .
408 'target="_blank" title="The simplest way to put AdSense to work for you!"> ' .
409 'Easy AdSense</a> by <a href="http://www.Thulasidas.com/" ' .
410 'target="_blank" title="Unreal Blog proudly brings you Easy AdSense">' .
411 'Unreal</a></font></div>';
412
413 if ($ezAdOptions['show_borders'])
414 $border='onmouseover="this.style.border=\'#' . $ezAdOptions['border_color'] .
415 ' solid ' . $ezAdOptions['border_width'] . 'px\'" ' .
416 'onmouseout="this.style.border=\'0px\'"' ;
417
418 $show_leadin = $metaOptions['show_leadin'] ;
419 $leadin = '' ;
420 if ($show_leadin != 'no') {
421 if ($ezCount < $this->ezMax) {
422 $ezCount++;
423 $leadin =
424 stripslashes($ezAdOptions['info'] . "<!-- Post[count: " . $ezCount . "] -->\n" .
425 '<div class="ezAdsense adsense adsense-leadin" style="' .
426 $show_leadin . ';margin:12px;" ' . $border. '>' .
427 $this->mc($mc, $ezAdOptions['text_leadin']) .
428 ($urCount++ < $this->urMax ? $unreal : '') .
429 $backlink .
430 '</div>') ;
431 }
432 }
433
434 $show_midtext = $metaOptions['show_midtext'] ;
435 if ($show_midtext != 'no') {
436 if ($ezCount < $this->ezMax) {
437 $poses = array();
438 $lastpos = -1;
439 $repchar = "<p";
440 if(strpos($content, "<p") === false)
441 $repchar = "<br";
442
443 while(strpos($content, $repchar, $lastpos+1) !== false){
444 $lastpos = strpos($content, $repchar, $lastpos+1);
445 $poses[] = $lastpos;
446 }
447 $half = sizeof($poses);
448 while(sizeof($poses) > $half)
449 array_pop($poses);
450 $pickme = $poses[floor(sizeof($poses)/2)];
451 if ($ezAdOptions['force_midad'] || $half > 10)
452 { // don't show if you have too few paragraphs
453 $ezCount++;
454 $midtext =
455 stripslashes($ezAdOptions['info'] . "<!-- Post[count: " . $ezCount . "] -->\n" .
456 '<div class="ezAdsense adsense adsense-midtext" style="' .
457 $show_midtext . ';margin:12px;" ' . $border. '>' .
458 $this->mc($mc, $ezAdOptions['text_midtext']) .
459 ($urCount++ < $this->urMax ? $unreal : '') .
460 '</div>') ;
461 $content = substr_replace($content, $midtext.$repchar, $pickme, 2);
462 }
463 }
464 }
465
466 $show_leadout = $metaOptions['show_leadout'] ;
467 $leadout = '' ;
468 if ($show_leadout != 'no') {
469 if ($ezCount < $this->ezMax) {
470 $ezCount++;
471 $leadout =
472 stripslashes($ezAdOptions['info'] . "<!-- Post[count: " . $ezCount . "] -->\n" .
473 '<div class="ezAdsense adsense adsense-leadout" style="' .
474 $show_leadout . ';margin:12px;" ' . $border. '>' .
475 $this->mc($mc, $ezAdOptions['text_leadout']) .
476 ($urCount++ < $this->urMax ? $unreal : '') .
477 '</div>') ;
478 }
479 }
480
481 return $leadin . $content . $leadout ;
482 }
483
484 function footer_action(){
485 $unreal = '<div align="center"><font size="-3">' .
486 '<a href="http://wordpress.org/extend/plugins/easy-adsenser/" ' .
487 'target="_blank" title="The simplest way to put AdSense to work for you!"> ' .
488 'Easy AdSense</a> by <a href="http://www.Thulasidas.com/" ' .
489 'target="_blank" title="Unreal Blog proudly brings you Easy AdSense">' .
490 'Unreal</a></font></div>';
491 echo $unreal ;
492 }
493
494 // ===== widget functions =====
495 function widget_ezAd_ads($args) {
496 extract($args);
497 $ezAdOptions = $this->getAdminOptions();
498 $metaOptions = $this->widgetMeta() ;
499 if ($metaOptions['adsense'] == 'no') return ;
500 $show_widget = $metaOptions['show_widget'] ;
501 if ($show_widget == 'no') return ;
502 $this->ezMax = $ezAdOptions['max_count'] ;
503 $this->urMax = $ezAdOptions['max_link'] ;
504 global $ezCount ;
505 global $urCount ;
506 if (!$ezAdOptions['force_widget']) {
507 if ($ezCount >= $this->ezMax) return ;
508 $ezCount++;
509 }
510 $title = empty($ezAdOptions['title_widget']) ?
511 __('Sponsored Links', 'easy-adsenser') :
512 stripslashes(htmlspecialchars($ezAdOptions['title_widget'])) ;
513 $border = '' ;
514 if ($ezAdOptions['show_borders'] && $ezAdOptions['border_widget'] )
515 $border='onmouseover="this.style.border=\'#' . $ezAdOptions['border_color'] .
516 ' solid ' . $ezAdOptions['border_width'] . 'px\'" ' .
517 'onmouseout="this.style.border=\'0px\'"' ;
518 $unreal = '<div align="center"><font size="-3">' .
519 '<a href="http://wordpress.org/extend/plugins/easy-adsenser/" ' .
520 'target="_blank" title="The simplest way to put AdSense to work for you!"> ' .
521 'Easy AdSense</a> by <a href="http://www.Thulasidas.com/" ' .
522 'target="_blank" title="Unreal Blog proudly brings you Easy AdSense">' .
523 'Unreal</a></font></div>';
524 echo $before_widget;
525 echo $before_title . $title . $after_title;
526 $mc = $ezAdOptions['mc'] ;
527 echo stripslashes($ezAdOptions['info'] . "<!-- Widg[count: " . $ezCount . "] -->\n" .
528 '<div class="ezAdsense adsense adsense-widget"><div style="' .
529 $show_widget .';margin:12px;" ' . $border. '>' .
530 $this->mc($mc, $ezAdOptions['text_widget'], true) .
531 ($urCount++ < $this->urMax ? $unreal : '') .
532 '</div></div>') ;
533 echo $after_widget;
534 }
535
536 function widget_ezAd_lu($args) {
537 extract($args);
538 $ezAdOptions = $this->getAdminOptions();
539 $title = empty($ezAdOptions['title_lu']) ? '' :
540 $before_title . stripslashes(htmlspecialchars($ezAdOptions['title_lu'])) . $after_title ;
541 $metaOptions = $this->widgetMeta() ;
542 if ($metaOptions['adsense'] == 'no') return ;
543 $show_lu = $metaOptions['show_lu'] ;
544 $border = '' ;
545 if ($ezAdOptions['show_borders'] && $ezAdOptions['border_lu'] )
546 $border='onmouseover="this.style.border=\'#' . $ezAdOptions['border_color'] .
547 ' solid ' . $ezAdOptions['border_width'] . 'px\'" ' .
548 'onmouseout="this.style.border=\'0px\'"' ;
549 if ($show_lu != 'no') {
550 echo $before_widget ;
551 echo $title ;
552 echo stripslashes('<div class="ezAdsense adsense adsense-lu"><div style="' . $show_lu .
553 ';margin:12px;" ' . $border. '>' . "\n" .
554 $ezAdOptions['text_lu'] . "\n" .
555 '</div></div>') ;
556 echo $after_widget ;
557 }
558 }
559
560 function widget_ezAd_search($args) {
561 extract($args);
562 $ezAdOptions = $this->getAdminOptions();
563 $metaOptions = $this->widgetMeta() ;
564 if ($metaOptions['adsense'] == 'no') return ;
565 $title_gsearch = $metaOptions['title_gsearch'] ;
566 if ($title_gsearch != 'no') {
567 $title = $before_title . $title_gsearch . $after_title ;
568 if ($title_gsearch == 'dark')
569 $title = '<img src=" ' . $this->plugindir . '/google-dark.gif" ' .
570 ' border="0" alt="[Google]" align="middle" />' ;
571 if ($title_gsearch == 'light')
572 $title = '<img src=" ' . $this->plugindir . '/google-light.gif" ' .
573 ' border="0" alt="[Google]" align="middle" />' ;
574 echo $before_widget ;
575 echo $title ;
576 echo stripslashes($ezAdOptions['text_gsearch']) ;
577 echo $after_widget ;
578 }
579 }
580
581 function widget_ezAd_control() {
582 echo '<p>Configure it at <br />' ;
583 echo '<a href="options-general.php?page=easy-adsenser.php"> ';
584 echo 'Settings &rarr; Easy AdSense</a>' ;
585 echo '</p>' ;
586 }
587
588 function widget_ezAd_lu_control($widget_args = 1) {
589 echo '<p>Configure it at <br />' ;
590 echo '<a href="options-general.php?page=easy-adsenser.php"> ';
591 echo 'Settings &rarr; Easy AdSense</a>' ;
592 echo '</p>' ;
593 }
594
595 function register_ezAdSenseWidgets() {
596 if (function_exists('wp_register_sidebar_widget')) {
597 $widget_ops =
598 array('classname' => 'widget_ezAd_ads', 'description' =>
599 'Easy AdSense: ' . __('Show a Google AdSense block in your sidebar as a widget',
600 'easy-adsenser'));
601 wp_register_sidebar_widget('ezAd_ads', 'Google Ads',
602 array(&$this, 'widget_ezAd_ads'), $widget_ops);
603 $widget_ops =
604 array('classname' => 'widget_ezAd_search', 'description' =>
605 'Easy AdSense: ' . __('Show a Google Search Box in your sidebar as a widget',
606 'easy-adsenser'));
607 wp_register_sidebar_widget('ezAd_search', 'Google Search',
608 array(&$this, 'widget_ezAd_search'), $widget_ops);
609 wp_register_widget_control('ezAd_ads','Google Ads',
610 array(&$this, 'widget_ezAd_control'));
611 wp_register_widget_control('ezAd_search','Google Search',
612 array(&$this, 'widget_ezAd_control'));
613 }
614 }
615
616 function register_ezAdSenseLU() {
617 if (function_exists('wp_register_sidebar_widget')) {
618 for ($id = 0; $id < $this->luMax; $id++) {
619 $reg_wid = 'ezad-lu-' . $id ;
620 $jd = $id + 1;
621 $widget_ops =
622 array('classname' => 'widget_ezAd_lu', 'description' =>
623 'Easy AdSense: ' . __('Show a Google Links Unit in your sidebar as a widget',
624 'easy-adsenser') . " ($jd)");
625 wp_register_sidebar_widget($reg_wid, 'Google Link Units' . " ($jd)",
626 array(&$this, 'widget_ezAd_lu'), $widget_ops);
627 wp_register_widget_control($reg_wid ,'Google Link Units' . " ($jd)",
628 array(&$this, 'widget_ezAd_lu_control'));
629 }
630 }
631 }
632 }
633} //End Class ezAdSense
634
635$urCount = 0 ;
636$ezCount = 0 ;
637
638// provide a replacement for htmlspecialchars_decode() (for PHP4 compatibility)
639if (!function_exists("htmlspecialchars_decode")) {
640 function htmlspecialchars_decode($string,$style=ENT_COMPAT) {
641 $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS,$style));
642 if($style === ENT_QUOTES){ $translation['&#039;'] = '\''; }
643 return strtr($string,$translation);
644 }
645}
646
647if (class_exists("ezAdSense")) {
648 $ez_ad = new ezAdSense();
649 if (isset($ez_ad) && !empty($ez_ad->defaults)) {
650 //Initialize the admin panel
651 if (!function_exists("ezAdSense_ap")) {
652 function ezAdSense_ap() {
653 global $ez_ad ;
654 if (function_exists('add_options_page')) {
655 add_options_page('Easy AdSense', 'Easy AdSense', 9,
656 basename(__FILE__), array(&$ez_ad, 'printAdminPage'));
657 }
658 }
659 }
660
661 $version = (float)get_bloginfo('version') ;
662 if ($version >= 2.80){
663 // sidebar AdSense Widget (skyscraper)
664 class ezAdsWidget extends WP_Widget {
665 function ezAdsWidget() {
666 $widget_ops =
667 array('classname' => 'ezAdsWidget',
668 'description' =>
669 __('Show a Google AdSense block in your sidebar as a widget',
670 'easy-adsenser') );
671 $this->WP_Widget('ezAdsWidget', 'Easy AdSense: Google Ads', $widget_ops);
672 }
673 function widget($args, $instance) {
674 // outputs the content of the widget
675 global $ez_ad ;
676 $ez_ad->widget_ezAd_ads($args) ;
677 }
678
679 function update($new_instance, $old_instance) {
680 // processes widget options to be saved
681 return $new_instance ;
682 }
683
684 function form($instance) {
685 // outputs the options form on admin
686 global $ez_ad ;
687 $ez_ad->widget_ezAd_control() ;
688 }
689 }
690 add_action('widgets_init',
691 create_function('', 'return register_widget("ezAdsWidget");'));
692
693 // sidebar Search Widget
694 class ezAdsSearch extends WP_Widget {
695 function ezAdsSearch() {
696 $widget_ops =
697 array('classname' => 'ezAdsSearch',
698 'description' =>
699 __('Show a Google Search Box in your sidebar as a widget',
700 'easy-adsenser') );
701 $this->WP_Widget('ezAdsSearch', 'Easy AdSense: Google Search', $widget_ops);
702 }
703 function widget($args, $instance) {
704 // outputs the content of the widget
705 global $ez_ad ;
706 $ez_ad->widget_ezAd_search($args) ;
707 }
708
709 function update($new_instance, $old_instance) {
710 // processes widget options to be saved
711 return $new_instance ;
712 }
713
714 function form($instance) {
715 // outputs the options form on admin
716 global $ez_ad ;
717 $ez_ad->widget_ezAd_control() ;
718 }
719 }
720 add_action('widgets_init',
721 create_function('', 'return register_widget("ezAdsSearch");'));
722
723 // sidebar Link Units
724 class ezAdsLU extends WP_Widget {
725 function ezAdsLU() {
726 $widget_ops =
727 array('classname' => 'ezAdsLU',
728 'description' =>
729 __('Show a Google Links Unit in your sidebar as a widget',
730 'easy-adsenser') );
731 $this->WP_Widget('ezAdsLU', 'Easy AdSense: Google Link Unit', $widget_ops);
732 }
733 function widget($args, $instance) {
734 // outputs the content of the widget
735 global $ez_ad ;
736 $ez_ad->widget_ezAd_lu($args) ;
737 }
738
739 function update($new_instance, $old_instance) {
740 // processes widget options to be saved
741 return $new_instance ;
742 }
743
744 function form($instance) {
745 // outputs the options form on admin
746 global $ez_ad ;
747 $ez_ad->widget_ezAd_control() ;
748 }
749 }
750 add_action('widgets_init',
751 create_function('', 'return register_widget("ezAdsLU");'));
752 }
753 else {
754 add_action('plugins_loaded', array($ez_ad, 'register_ezAdSenseWidgets'));
755 add_action('plugins_loaded', array($ez_ad, 'register_ezAdsenseLU')) ;
756 }
757
758 add_filter('the_content', array($ez_ad, 'ezAdSense_content'));
759 $ezAdOptions = $ez_ad->getAdminOptions();
760 $ez_ad->luMax = $ezAdOptions['limit_lu'] ;
761 if ($ezAdOptions['allow_feeds']) {
762 add_filter('the_excerpt_rss', array($ez_ad, 'ezAdSense_content'));
763 add_filter('the_content_rss', array($ez_ad, 'ezAdSense_content'));
764 }
765 else {
766 remove_filter('the_excerpt_rss', array($ez_ad, 'ezAdSense_content'));
767 remove_filter('the_content_rss', array($ez_ad, 'ezAdSense_content'));
768 }
769 add_action('admin_menu', 'ezAdSense_ap');
770 add_action('activate_' . basename(dirname(__FILE__)) . '/' . basename(__FILE__),
771 array(&$ez_ad, 'init'));
772 add_filter('plugin_action_links', array($ez_ad, 'plugin_action'), -10, 2);
773 if ($ezAdOptions['max_link'] == -1)
774 add_action('wp_footer', array($ez_ad, 'footer_action'));
775 else
776 remove_action('wp_footer', array($ez_ad, 'footer_action'));
777 }
778}
779?>
Note: See TracBrowser for help on using the repository browser.