Ad Injection - Version 0.9.6

Version Description

  • Ad rotation / A:B split testing support for random, top, bottom and widget adverts.
  • Alternate content which can be defined for users who are dynamically blocked (by IP or referrer) from seeing adverts.
  • Choose which paragraph to start the random ads via the UI.
Download this release

Release Info

Developer reviewmylife
Plugin Icon wp plugin Ad Injection
Version 0.9.6
Comparing to
See all releases

Code changes from version 0.9.5.2 to 0.9.6

Files changed (8) hide show
  1. ad-injection-admin.php +319 -766
  2. ad-injection-widget.php +169 -57
  3. ad-injection.php +242 -84
  4. adshow.php +15 -9
  5. readme.txt +61 -75
  6. ui-tab-adrotation.php +92 -0
  7. ui-tab-main.php +745 -0
  8. uninstall.php +3 -1
ad-injection-admin.php CHANGED
@@ -43,42 +43,34 @@ function adinj_update_options($ops){
43
 
44
  function adinj_save_options(){
45
  // TODO investigate register_settings for a future release
46
- if (isset($_POST['adinj_action'])){
47
  switch($_POST['adinj_action']){
48
  case 'Save all settings':
49
  adinj_checkNonce();
50
 
51
  // Extract all know options
52
  $default_options = adinj_default_options();
 
 
53
  foreach ($default_options as $key => $value){
54
  if (isset($_POST[$key])){
55
  $ops[$key] = $_POST[$key];
56
- } else {
57
- $ops[$key] = "";
58
  }
59
  }
60
 
61
- $raw_ad_code_random = stripslashes($_POST['ad_code_random_1']);
62
- $ops['ad_code_random_1'] = $raw_ad_code_random;
63
-
64
- $raw_ad_code_top = stripslashes($_POST['ad_code_top_1']);
65
- $ops['ad_code_top_1'] = $raw_ad_code_top;
66
 
67
- $raw_ad_code_bottom = stripslashes($_POST['ad_code_bottom_1']);
68
- $ops['ad_code_bottom_1'] = $raw_ad_code_bottom;
 
69
 
70
- $ad_referrers = stripslashes($_POST['ad_referrers']); // TODO do i need strip slashes?
71
- $ops['ad_referrers'] = $ad_referrers;
72
-
73
- $blocked_ips = stripslashes($_POST['blocked_ips']);
74
- $ops['blocked_ips'] = $blocked_ips;
75
 
76
  adinj_update_options($ops);
77
 
78
  if ($ops['ad_insertion_mode'] == 'mfunc') {
79
- write_ad_to_file($raw_ad_code_random, ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE);
80
- write_ad_to_file($raw_ad_code_top, ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE);
81
- write_ad_to_file($raw_ad_code_bottom, ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE);
82
  adinj_write_config_file();
83
  }
84
 
@@ -99,6 +91,25 @@ function adinj_save_options(){
99
  // TODO add option to delete ads files as well
100
  break;
101
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  }
103
  }
104
 
@@ -108,9 +119,17 @@ function adinj_save_options(){
108
  function adinj_write_config_file(){
109
  $ops = adinj_options();
110
  if ($ops['ad_insertion_mode'] != 'mfunc') return;
 
 
111
  $referrer_list = adinj_quote_list('ad_referrers');
 
 
112
  $ip_list = adinj_quote_list('blocked_ips');
113
- $sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false';
 
 
 
 
114
  $debug_mode = adinj_ticked('debug_mode')?'true':'false';
115
 
116
  // TODO remove these from config file later...
@@ -128,8 +147,16 @@ This file is generated by Ad Injection
128
 
129
  function adinj_config_sevisitors_only() { return $sevisitors_only; }
130
  function adinj_config_search_engine_referrers() { return array($referrer_list); }
 
 
131
  function adinj_config_blocked_ips() { return array($ip_list); }
 
 
 
 
 
132
  function adinj_config_debug_mode() { return $debug_mode; }
 
133
  $rnd_func
134
  $top_func
135
  $bottom_func
@@ -176,19 +203,12 @@ function adinj_get_logo(){
176
  }
177
 
178
  function adinj_options_page(){
179
- adinj_save_options();
 
 
180
 
 
181
  $ops = adinj_options();
182
- if ($ops === false || adinj_options_need_upgrading($ops)){
183
- // Upgraded via FTP without being deactivated/reactivated
184
- adinj_activate_hook();
185
- }
186
- $ops = adinj_options(1);
187
- if ($ops['ad_insertion_mode'] == 'mfunc') {
188
- if (!@file_exists(ADINJ_CONFIG_FILE)){
189
- adinj_write_config_file();
190
- }
191
- }
192
 
193
  echo '<div class="wrap" style="width:950px;">';
194
 
@@ -200,6 +220,38 @@ function adinj_options_page(){
200
 
201
  echo '<div id="icon-options-general" class="icon32"></div><h2>Ad Injection ' . adinj_get_version() . adinj_get_logo() . '</h2>';
202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  if (isset($_POST['adinj_action'])) {
204
  echo '<div id="message" class="updated below-h2"><p><strong>';
205
  echo 'All settings saved: ';
@@ -227,97 +279,18 @@ function adinj_options_page(){
227
 
228
  } else {
229
  echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
230
- echo "10th January 2011: Added new top/bottom padding options for widgets (slightly different behaviour to the existing top/bottom margin option). Plus added some fixes for the widget margins. If you spot any bugs, or odd behaviour please let me know via the ".'<a href="https://spreadsheets.google.com/viewform?formkey=dFUwZzBYcG1HNzNKMmJZdWFDdFhkY0E6MQ" target="_new">feedback form</a>.';
231
  echo '</strong></p></div>';
232
  }
233
- ?>
234
-
235
-
236
-
237
- <div style="width:258px; float:right;">
238
- <div class="postbox-container" style="width:258px;">
239
- <div class="metabox-holder">
240
- <div class="meta-box-sortables" style="min-height:50px;">
241
- <div id="toc" class="postbox">
242
- <h3 class="hndle"><span><?php echo adinj_get_logo(); ?> Status</span></h3>
243
- <div class="inside" style="margin:5px;">
244
- <table border="0" cellpadding="2">
245
- <tr><td style="text-align:right; vertical-align:top">
246
- <b><a href="#global">Ads enabled</a></b>
247
- </td><td>
248
- <?php
249
- $info = adinj_get_status('global'); echo adinj_dot($info[0]).' '.$info[1];
250
- if ($info[0] != 'red') { ?>
251
- <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('exclude_home'); ?> home
252
- <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('exclude_page'); ?> page
253
- <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('exclude_single'); ?> single
254
- <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('exclude_archive'); ?> archive
255
- </td></tr>
256
- <tr><td style="text-align:right; vertical-align:top">
257
- <b><a href="#random">Random ads</a></b>
258
- </td><td>
259
- <?php
260
- $info = adinj_get_status('random'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
261
- $info = adinj_get_status('random_home'); echo adinj_dot($info[0]).' '.$info[1];
262
- ?>
263
- </td></tr>
264
- <tr><td style="text-align:right">
265
- <b><a href="#topad">Top ad</a></b>
266
- </td><td>
267
- <?php $info = adinj_get_status('topad'); echo adinj_dot($info[0]).' '.$info[1]; ?>
268
- </td></tr>
269
- <tr><td style="text-align:right">
270
- <b><a href="#bottomad">Bottom ad</a></b>
271
- </td><td>
272
- <?php $info = adinj_get_status('bottomad'); echo adinj_dot($info[0]).' '.$info[1]; ?>
273
- </td></tr>
274
- <tr><td style="text-align:right; vertical-align:top">
275
- <b><a href="#widgets">Widgets</a></b>
276
- </td><td>
277
- <?php $info = adinj_get_status('widgets'); echo adinj_dot($info[0]).' '.$info[1];
278
- if ($info[0] != 'red') { ?>
279
- <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('widget_exclude_home'); ?> home
280
- <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('widget_exclude_page'); ?> page
281
- <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('widget_exclude_single'); ?> single
282
- <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('widget_exclude_archive'); ?> archive
283
- <?php } ?>
284
- </td></tr>
285
- <tr><td style="text-align:right">
286
- <b><a href="#restrictions">Mode</a></b>
287
- </td><td>
288
- <?php $info = adinj_get_status('mode'); echo adinj_dot($info[0]).' '.$info[1]; ?>
289
- </td></tr>
290
- <tr><td style="text-align:right">
291
- <b><a href="#dynamic">Restrictions</a></b>
292
- </td><td>
293
- <?php $info = adinj_get_status('restrictions'); echo adinj_dot($info[0]).' '.$info[1]; ?>
294
- </td></tr>
295
- <tr><td style="text-align:right">
296
- <b><a href="#debugging">Debug mode</a></b>
297
- </td><td>
298
- <?php $info = adinj_get_status('debugging'); echo adinj_dot($info[0]).' '.$info[1]; ?>
299
- </td></tr>
300
- <tr><td>
301
- </td><td>
302
- </td></tr>
303
- <tr><td>
304
- </td><td>
305
- <?php } ?>
306
- </td></tr>
307
- </table>
308
- </div>
309
- </div>
310
- </div>
311
- </div>
312
- </div>
313
-
314
- <br />
315
-
316
  <div class="postbox-container" style="width:258px;">
317
  <div class="metabox-holder">
318
  <div class="meta-box-sortables">
319
- <div id="toc" class="postbox">
320
- <h3 class="hndle"><span><?php echo adinj_get_logo(); ?> More info...</span></h3>
321
  <div class="inside" style="margin:5px;">
322
  <h4>More Ad Injection information</h4>
323
  <ul>
@@ -327,8 +300,8 @@ function adinj_options_page(){
327
  </ul>
328
  <h4>Coming in 2011</h4>
329
  <ul>
330
- <li>More precise control over which categories and tags the ads are shown in.</li>
331
- <li>Extra places where adverts can be inserted.</li>
332
  </ul>
333
 
334
  <h4><font color="red">Important!</font></h4>
@@ -347,407 +320,12 @@ function adinj_options_page(){
347
  </div>
348
  </div>
349
  </div>
350
- </div>
351
-
352
- <script type="text/javascript">
353
- function adinj_addtext(element, value) {
354
- if (value.length == 0) return;
355
- separator = ', ';
356
- if (element.value.length == 0){
357
- separator = '';
358
- }
359
- element.value += (separator + value);
360
- }
361
- </script>
362
-
363
- <p><a href="#random">Random ads</a> | <a href="#topad">Top</a> | <a href="#bottomad">Bottom</a> | <a href="#widgets">Widgets</a> | <a href="#restrictions">Ad insert mode/dynamic restrictions</a> | <a href="#debugging">Debug</a> | <a href="#docs">Quick Start</a> | <a href="#testads">Test ads</a></p>
364
-
365
- <form name="adinjform" method="post" action="">
366
- <?php wp_nonce_field('_adinj_form'); ?>
367
-
368
-
369
- <?php adinj_postbox_start(__("Global settings", 'adinj'), 'global'); ?>
370
-
371
- <p>These settings apply to all ads (random, top, bottom, and widget). They will override all other settings.</p>
372
-
373
- <input type="radio" name="ads_enabled" value="on" <?php if ($ops['ads_enabled']=='on') echo 'checked="checked"'; ?> /> <b>On: <?php _e('Ads enabled', 'adinj') ?></b><br />
374
- <input type="radio" name="ads_enabled" value="off" <?php if ($ops['ads_enabled']=='off' || $ops['ads_enabled']=='') echo 'checked="checked"'; ?> /> <b>Off</b><br />
375
- <input type="radio" name="ads_enabled" value="test" <?php if ($ops['ads_enabled']=='test') echo 'checked="checked"'; ?> /> <b>Test mode</b> - Only show ads to admin.<br />
376
- <span style="font-size:10px;color:red;">Warning: Turn any caching plugin *off* before using test mode. If you leave them on the test adverts will be cached and shown to your real visitors.</span><br />
377
-
378
- <table border="0">
379
- <tr><td>
380
- <p><?php _e("Only show ads on pages older than ", 'adinj') ?></p>
381
- </td><td>
382
- <p>
383
- <select name='ads_on_page_older_than'>
384
- <?php
385
- $older_than_days = array(0, 1, 2, 3, 5, 7, 10, 14, 21, 28, 40, 50);
386
- for ($value=0; $value<sizeof($older_than_days); ++$value){
387
- echo "<option value=\"$older_than_days[$value]\" ";
388
- if($ops['ads_on_page_older_than'] == $older_than_days[$value]) echo 'selected="selected"';
389
- echo ">$older_than_days[$value]</option>";
390
- }
391
- ?>
392
- </select><?php _e(" (days)", 'adinj') ?> - only for single posts and pages</p>
393
- </td></tr>
394
- <tr><td style="vertical-align:top">
395
- Don't show ads on these page types:
396
- </td><td>
397
- <input type="checkbox" name="exclude_home" <?php echo adinj_ticked('exclude_home'); ?> />home - <?php echo get_bloginfo('url'); ?><br />
398
- <?php
399
- $count_pages = wp_count_posts('page', 'readable');
400
- $count_posts = wp_count_posts('post', 'readable');
401
- ?>
402
- <input type="checkbox" name="exclude_page" <?php echo adinj_ticked('exclude_page'); ?> />page - <?php echo $count_pages->publish; ?> page(s)<br />
403
- <input type="checkbox" name="exclude_single" <?php echo adinj_ticked('exclude_single'); ?> />single -<?php echo $count_posts->publish; ?> individual blog post(s)<br />
404
- <input type="checkbox" name="exclude_archive" <?php echo adinj_ticked('exclude_archive'); ?> />archive - only <a href="#widgets">widgets</a> currently appear on archives<br />
405
- </td></tr>
406
- </table>
407
-
408
- <b>Category and tag conditions</b>
409
-
410
- <?php adinj_condition_table('global_category', 'category slugs. e.g: cat1, cat2, cat3', 'category'); ?>
411
-
412
- <?php adinj_condition_table('global_tag', 'tag slugs. e.g: tag1, tag2, tag3', 'tag'); ?>
413
-
414
- <?php adinj_postbox_end(); ?>
415
-
416
-
417
-
418
-
419
- <?php adinj_postbox_start(__("Randomly Injected ad code", 'adinj'), 'random'); ?>
420
-
421
- <table border="0" cellspacing="5">
422
- <tr><td style="vertical-align: top">
423
- <textarea name="ad_code_random_1" rows="10" cols="60"><?php echo $ops['ad_code_random_1']; ?></textarea>
424
- </td><td style="vertical-align: top">
425
- <?php adinj_add_alignment_options('rnd_'); ?>
426
- </td></tr>
427
- <tr><td>
428
- <?php _e("Always put the first ad after the first paragraph.", 'adinj') ?> <input type="checkbox" name="first_paragraph_ad" <?php echo adinj_ticked('first_paragraph_ad'); ?> />
429
- </td><td>
430
- </td></tr>
431
- </table>
432
-
433
-
434
- <p><span style="font-size:10px;"><b>Docs:</b> On individual posts or pages this advert is inserted between randomly selected paragraphs. On a multi-post page (e.g. home page), one ad is inserted into each post. Try a <a href="#468x60">468x60</a> or <a href="#728x90">728x90</a> banner.</span></p>
435
- <p><span style="font-size:10px;">Be especially careful if you decide to use the 'float' layout options. Make sure that you don't have adverts floated over the top of other page elements, or vice-versa.</span></p>
436
- </div>
437
-
438
- <input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
439
- <h3><?php _e("Single posts and pages: Randomly Injected ad settings", 'adinj') ?></h3>
440
- <div class="inside" style="margin:10px">
441
- <p>These random ad injection settings are specific to individual posts and pages.</p>
442
-
443
- <table border="0">
444
-
445
- <tr><td>
446
- <?php _e("Allow multiple ads to be injected at the same positions.", 'adinj') ?>
447
- </td><td>
448
- <input type="checkbox" name="multiple_ads_at_same_position" <?php echo adinj_ticked('multiple_ads_at_same_position'); ?> /> (default is to inject ads at unique positions)
449
- </td></tr>
450
-
451
-
452
- <tr><td>
453
- <?php _e("Maximum number of randomly injected ads: ", 'adinj') ?></td><td>
454
- <select name='max_num_of_ads'>
455
- <?php
456
- for ($value=0; $value<=10; ++$value){
457
- echo "<option value=\"$value\" ";
458
- if($ops['max_num_of_ads'] == $value) echo 'selected="selected"';
459
- echo ">$value</option>";
460
- }
461
- ?>
462
- </select> <?php echo adinj_getdefault('max_num_of_ads'); ?><br />
463
- </td></tr>
464
-
465
- <tr><td>
466
- <?php
467
- _e("No random ads if page shorter than: ", 'adinj');
468
- echo '</td><td>';
469
- adinj_selection_box("no_random_ads_if_shorter_than",
470
- array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000));
471
- echo adinj_getdefault('no_random_ads_if_shorter_than');
472
- ?>
473
- </td></tr>
474
-
475
- <tr><td>
476
- <?php
477
- _e("Limit of 1 ad if page shorter than: ", 'adinj');
478
- echo '</td><td>';
479
- adinj_selection_box("one_ad_if_shorter_than",
480
- array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000));
481
- echo adinj_getdefault('one_ad_if_shorter_than');
482
- ?>
483
- </td></tr>
484
-
485
- <tr><td>
486
- <?php
487
- _e("Limit of 2 ads if page shorter than: ", 'adinj');
488
- echo '</td><td>';
489
- adinj_selection_box("two_ads_if_shorter_than",
490
- array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000));
491
- echo adinj_getdefault('two_ads_if_shorter_than');
492
- ?>
493
- </td></tr>
494
-
495
- <tr><td>
496
- <?php
497
- _e("Limit of 3 ads if page shorter than: ", 'adinj');
498
- echo '</td><td>';
499
- adinj_selection_box("three_ads_if_shorter_than",
500
- array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000));
501
- echo adinj_getdefault('three_ads_if_shorter_than');
502
- ?>
503
- </td></tr>
504
- </table>
505
-
506
- <br clear="all" />
507
- <p><span style="font-size:10px;"><b>Docs:</b> The above directives are processed in order from top to bottom.</span></p>
508
-
509
-
510
- <p></p>
511
-
512
- </div>
513
-
514
- <input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
515
- <h3><a name="random_home"></a><?php _e("Home page: Randomly Injected ad settings", 'adinj') ?> (<?php echo get_bloginfo('url'); ?>)</h3>
516
- <div class="inside" style="margin:10px">
517
- <p>These random ad injection settings are specific to your home page.</p>
518
-
519
- <?php _e("Maximum number of injected ads: ", 'adinj') ?>
520
- <select name='max_num_of_ads_home_page'>
521
- <?php
522
- for ($value=0; $value<=10; ++$value){
523
- echo "<option value=\"$value\" ";
524
- if($ops['max_num_of_ads_home_page'] == $value) echo 'selected="selected"';
525
- echo ">$value</option>";
526
- }
527
- ?>
528
- </select> <?php echo adinj_getdefault('max_num_of_ads_home_page'); ?><br />
529
-
530
- <p><span style="font-size:10px;"><b>Docs:</b> On a multi-post home page, one randomly positioned advert will be inserted into each post, up to the maximum number specified here.</span></p>
531
-
532
- <?php adinj_postbox_end(); ?>
533
-
534
-
535
-
536
- <?php adinj_postbox_start(__("Optional top advert (single posts and pages only)", 'adinj'), 'topad'); ?>
537
-
538
  <?php
539
- _e("Only show top ad on pages longer than: ", 'adinj');
540
- adinj_selection_box("top_ad_if_longer_than",
541
- array(ADINJ_DISABLED, ADINJ_ALWAYS_SHOW, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000));
542
-
543
- ?>
544
-
545
- <br clear="all" />
546
-
547
- <table border="0">
548
- <tr><td>
549
- <textarea name="ad_code_top_1" rows="10" cols="60"><?php echo $ops['ad_code_top_1']; ?></textarea>
550
- </td><td style="vertical-align: top">
551
- <?php adinj_add_alignment_options('top_'); ?>
552
- </td></tr>
553
- </table>
554
- <span style="font-size:10px;">The top ad is in addition to the quantity of other ads selected.</span>
555
-
556
- <p><span style="font-size:10px;"><b>Docs:</b> The top ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a <a href="#468x15">468x15</a> or <a href="#336x280">336x280</a> advert.</span></p>
557
-
558
- <?php adinj_postbox_end(); ?>
559
-
560
-
561
- <?php adinj_postbox_start(__("Optional bottom advert (single posts and pages only)", 'adinj'), 'bottomad'); ?>
562
-
563
- <?php
564
- _e("Only show bottom ad on pages longer than: ", 'adinj');
565
- adinj_selection_box("bottom_ad_if_longer_than",
566
- array(ADINJ_DISABLED, ADINJ_ALWAYS_SHOW, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000));
567
- ?>
568
-
569
- <br clear="all"/>
570
-
571
- <table border="0">
572
- <tr><td>
573
- <textarea name="ad_code_bottom_1" rows="10" cols="60"><?php echo $ops['ad_code_bottom_1']; ?></textarea>
574
- </td><td style="vertical-align: top">
575
- <?php adinj_add_alignment_options('bottom_'); ?>
576
- </td></tr>
577
- </table>
578
- <span style="font-size:10px;">The top ad is in addition to the quantity of other ads selected.</span>
579
-
580
- <p><span style="font-size:10px;"><b>Docs:</b> The bottom ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a <a href="#336x280">336x280</a> advert.</span></p>
581
-
582
-
583
- <?php adinj_postbox_end(); ?>
584
-
585
-
586
- <?php adinj_postbox_start(__("Widget settings (sidebar ads)", 'adinj'), 'widgets'); ?>
587
-
588
- <p>You must configure your individual widgets from the <a href="widgets.php">widgets control panel</a>. However these settings are global to all widgets. Also note that the main set of <a href="#global">global settings</a> will override these ones.</p>
589
-
590
- <table border="0">
591
-
592
- <tr><td>
593
- <p>Don't show widget ads on these page types:</p>
594
- </td><td>
595
- <input type="checkbox" name="widget_exclude_home" <?php echo adinj_ticked('widget_exclude_home'); ?> />home - <?php echo get_bloginfo('url'); ?><br />
596
- <input type="checkbox" name="widget_exclude_page" <?php echo adinj_ticked('widget_exclude_page'); ?> />page - <?php echo $count_pages->publish; ?> page(s)<br />
597
- <input type="checkbox" name="widget_exclude_single" <?php echo adinj_ticked('widget_exclude_single'); ?> />single - <?php echo $count_posts->publish; ?> individual blog post(s)<br />
598
- <input type="checkbox" name="widget_exclude_archive" <?php echo adinj_ticked('widget_exclude_archive'); ?> />archive - includes category, tag, author, and date pages types<br />
599
- </td></tr>
600
-
601
- </table>
602
-
603
-
604
- <?php adinj_postbox_end(); ?>
605
-
606
-
607
- <?php adinj_postbox_start(__("Ad insertion mode and dynamic ad display restrictions", 'adinj'), 'restrictions'); ?>
608
-
609
- <h4>Ad insertion mode</h4>
610
-
611
- <blockquote>
612
- <p><input type="radio" name="ad_insertion_mode" value="mfunc" <?php if ($ops['ad_insertion_mode']=='mfunc') echo 'checked="checked"'; ?> /> <b>Use mfunc tags for dynamic features (WP Super Cache mode)</b> - Dynamic features will work with WP Super Cache. </p>
613
-
614
- <?php if (!is_plugin_active('wp-super-cache/wp-cache.php')) {
615
- echo '<p><b><span style="font-size:10px;color:red;">Note: WP Super Cache does not appear to be active. If you are not using WP Super Cache /WP Cache (or compatible) you should use one of the direct insertion modes.</span></b></p>';
616
- } ?>
617
-
618
- <?php if ($ops['ad_insertion_mode'] != 'mfunc') { ?>
619
- <script type="text/javascript">
620
- document.write('<style type="text/css" media="screen">#wp_supercache_msg { display: none; }</style>');
621
- </script>
622
- <?php } ?>
623
-
624
- <div id="wp_supercache_msg" class="wp_supercache_msg">
625
- <p>With WP Super Cache version 0.9.9.8+ you can use the fastest 'mod rewrite rules' caching mode. With older versions of WP Super Cache you'll have to use the slower 'legacy mode'.</p>
626
-
627
- <p>Go to the
628
-
629
- <?php if (is_plugin_active('wp-super-cache/wp-cache.php')) { ?>
630
- <a href='options-general.php?page=wpsupercache&amp;tab=settings'>WP Super Cache advanced options page</a>
631
- <?php } else { ?>
632
- WP Super Cache advanced options page
633
- <?php } ?>
634
- to configure the caching mode.</p>
635
-
636
- <p>Dynamic features will also work if you don't use a caching program with mfunc mode. Although if you don't use a caching program one of the 'direct' insertion modes will be more efficient.</p>
637
- </div>
638
-
639
- <p><input type="radio" name="ad_insertion_mode" value="direct_dynamic" <?php if ($ops['ad_insertion_mode']=='direct_dynamic') echo 'checked="checked"'; ?> /> <b>Direct ad insertion with dynamic features</b> - Dynamic features will work if no caching is used. Only select this if you are not using any caching plugin.</p>
640
- <p><input type="radio" name="ad_insertion_mode" value="direct_static" <?php if ($ops['ad_insertion_mode']=='direct_static') echo 'checked="checked"'; ?> /> <b>Direct static ad insertion</b> - No dynamic feature support. Select this if you are using a caching plugin which is not compatible with WP Super Cache's mfunc tags.</p>
641
- </blockquote>
642
- </div>
643
- <p></p>
644
-
645
- <script type="text/javascript">
646
- jQuery(document).ready(function(){
647
- jQuery('input[name=ad_insertion_mode]:radio').change(function() {
648
- if (jQuery('input[name=ad_insertion_mode]:checked').val() == "direct_static"){
649
- jQuery('.dynamic_features').slideUp(1000);
650
- jQuery('.dynamic_features_msg').slideDown(1000);
651
- jQuery('.wp_supercache_msg').slideUp(1000);
652
- } else if (jQuery('input[name=ad_insertion_mode]:checked').val() == "direct_dynamic"){
653
- jQuery('.dynamic_features_msg').slideUp(1000);
654
- jQuery('.dynamic_features').slideDown(1000);
655
- jQuery('.wp_supercache_msg').slideUp(1000);
656
- } else { // mfunc
657
- jQuery('.dynamic_features_msg').slideUp(1000);
658
- jQuery('.dynamic_features').slideDown(1000);
659
- jQuery('.wp_supercache_msg').slideDown(1000);
660
- }
661
- return true;
662
- });
663
- });
664
- </script>
665
-
666
- <?php if ($ops['ad_insertion_mode'] == 'direct_static') { ?>
667
- <div class="dynamic_features_msg">
668
- <?php } else { ?>
669
- <div class="dynamic_features_msg" style="display:none">
670
- <?php } ?>
671
- <div class="inside" style="margin:10px">
672
- <b><span style="font-size:10px;color:red;">Note: Dynamic features (restricting ad views by referrer and IP address) are only available in the mfunc, or direct dynamic modes.</span></b>
673
- </div>
674
- </div>
675
-
676
- <?php if ($ops['ad_insertion_mode'] == 'direct_static') { ?>
677
- <script type="text/javascript">
678
- document.write('<style type="text/css" media="screen">#dynamic_features { display: none; }</style>');
679
- </script>
680
- <?php } ?>
681
- <div id="dynamic_features" class="dynamic_features">
682
-
683
- <div class="inside" style="margin:10px">
684
-
685
- <h4><a name="dynamic"></a>Show ads only to search engine visitors (dynamic feature)</h4>
686
-
687
- <blockquote>
688
- <input type="checkbox" name="sevisitors_only" <?php echo adinj_ticked('sevisitors_only'); ?> /><?php _e("Only show ads to search engine visitors (customise search engine referrers below if necessary).", 'adinj') ?><br />
689
- <textarea name="ad_referrers" rows="2" cols="70"><?php echo $ops['ad_referrers']; ?></textarea>
690
- <p>Comma separated list e.g.: <br /><code>.google., .bing., .yahoo., .ask., search?, search., /search/</code></p>
691
- </blockquote>
692
-
693
- <h4>Blocked IP addresses (dynamic feature)</h4>
694
-
695
- <blockquote>
696
- <!--<input type="checkbox" name="block_ips" <?php echo adinj_ticked('block_ips'); ?> /><?php _e("Exclude ads from these IP addresses.", 'adinj') ?><br />-->
697
- <textarea name="blocked_ips" rows="4" cols="70"><?php echo $ops['blocked_ips']; ?></textarea>
698
- <p>Comma separated list e.g.: <br /><code>0.0.0.1, 0.0.0.2</code></p>
699
- <p>Or you can list one IP per line with optional comments e.g.</p>
700
- <code style="padding:0px 0px">192.168.0.1<br />0.0.0.2<br /><?php echo $_SERVER['REMOTE_ADDR'] ?> //my ip<br />0.0.0.3</code>
701
-
702
- <p>For reference your current IP address is <code><?php echo $_SERVER['REMOTE_ADDR'] ?></code></p>
703
- </blockquote>
704
- </div>
705
-
706
- </div>
707
-
708
- <?php adinj_postbox_end(); ?>
709
-
710
-
711
- <?php adinj_postbox_start(__("Debugging", 'adinj'), 'debugging'); ?>
712
-
713
- <input type="checkbox" name="debug_mode" <?php echo adinj_ticked('debug_mode'); ?> />Enable debug mode
714
-
715
- <p>If you are not sure why ads aren't appearing, or why they are appearing, enable debug mode and look at the debug information (search for 'ADINJ DEBUG') in the HTML of your content pages.</p>
716
-
717
- <?php
718
-
719
- if (adinj_problem_with_wpminify_check()){
720
- echo adinj_get_problem_with_wpminify_message();
721
- }
722
-
723
- adinj_debug_information();
724
- ?>
725
-
726
- <p></p>
727
-
728
- <p>If you want to restore all settings (excluding the ad contents) to their default values use this button.</p>
729
-
730
- <input type="submit" name="adinj_action" value="<?php _e('Reset to Default', 'adinj') ?>" />
731
-
732
- <p>You can delete the database settings if you are going to uninstall Ad Injection (they will be automatically deleted if you uninstall via WordPress as well).</p>
733
-
734
- <input type="submit" name="adinj_action" value="<?php _e('Delete settings from DB', 'adinj') ?>" />
735
-
736
- <p>This button will delete all your Ad Injection widgets.</p>
737
-
738
- <input type="submit" name="adinj_action" value="<?php _e('Delete widget settings from DB', 'adinj') ?>" />
739
-
740
- <?php adinj_postbox_end(); ?>
741
-
742
 
743
- <br clear="all" />
744
-
745
- <?php
746
-
747
- adinj_docs();
748
-
749
- echo '</form>';
750
- echo '</div> <!--wrap-->';
751
  }
752
 
753
  // From WP Super cache
@@ -760,13 +338,13 @@ function adinj_admin_tabs( $current = 0 ) {
760
  $current = 'main';
761
  }
762
  }
763
- $tabs = array( 'main' => __( 'Main', 'ad-injection' ), 'adrotation' => __( 'Ad Rotation / A:B Testing', 'ad-injection' ), 'alternate' => __( 'Alternate Content', 'ad-injection' ) );
764
  $links = array();
765
  foreach( $tabs as $tab => $name ) {
766
  if ( $current == $tab ) {
767
- $links[] = "<a class='nav-tab nav-tab-active' href='?page=ad-injection&tab=$tab'>$name</a>";
768
  } else {
769
- $links[] = "<a class='nav-tab' href='?page=ad-injection&tab=$tab'>$name</a>";
770
  }
771
  }
772
 
@@ -842,37 +420,51 @@ function adinj_get_status($name){
842
  $status[1] = 'test mode';
843
  }
844
  } else if ($name == 'random'){
845
- $ad = $ops['ad_code_random_1'];
846
- if (empty($ad)){
847
  $status[0] = 'red';
848
- $status[1] = 'no ad defined';
849
  return $status;
850
  }
851
  $val = $ops['max_num_of_ads'];
852
  if ($val == '0'){
853
  $status[0] = 'red';
854
- $status[1] = 'off';
855
  } else {
856
  $status[0] = 'green';
857
- $status[1] = 'max ads: ' . $val;
858
  }
 
859
  } else if ($name == 'random_home'){
860
  $val = $ops['max_num_of_ads_home_page'];
861
- $msg = '<a href="#';
862
  if ($val == 0){
863
  $status[0] = 'red';
864
- $msg .= 'random_home">0 on home';
865
- } else if ($ops['exclude_home'] == 'on'){
866
- $status[0] = 'red';
867
- $msg .= 'global">exclude from home';
868
  } else {
869
  $status[0] = 'green';
870
- $msg .= 'random_home">max ads: ' . $val .' (home)';
871
  }
872
- $status[1] = $msg.'</a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
873
  } else if ($name == 'topad'){
874
- $ad = $ops['ad_code_top_1'];
875
- if (empty($ad)){
876
  $status[0] = 'red';
877
  $status[1] = 'no ad defined';
878
  return $status;
@@ -886,8 +478,8 @@ function adinj_get_status($name){
886
  $status[1] = 'on';
887
  }
888
  } else if ($name == 'bottomad'){
889
- $ad = $ops['ad_code_bottom_1'];
890
- if (empty($ad)){
891
  $status[0] = 'red';
892
  $status[1] = 'no ad defined';
893
  return $status;
@@ -971,7 +563,7 @@ function adinj_selection_box($name, $values, $type=NULL, $options=NULL, $selecte
971
  foreach ($values as $value){
972
  echo "<option value=\"$value\" ";
973
  if($selected_value == "$value") echo 'selected="selected"';
974
- if (empty($type) && is_numeric($value)){
975
  $typetxt = "(chars)";
976
  } else {
977
  $typetxt = $type;
@@ -1018,7 +610,7 @@ function adinj_condition_table($name, $description, $type){
1018
 
1019
  <?php } else if ($type == 'tag') { ?>
1020
 
1021
- <select name="<?php echo $name; ?>_dropdown" onchange='adinj_addtext(document.adinjform.<?php echo $name; ?>_condition_entries, this.options[this.selectedIndex].value);'">
1022
 
1023
  <option value=""><?php echo 'Add ' . $type; ?></option>
1024
  <?php
@@ -1118,57 +710,6 @@ function adinj_add_padding_top_bottom_options($prefix, $options=NULL, $topname=N
1118
  array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options, $bdefault);
1119
  }
1120
 
1121
- function adinj_debug_information(){
1122
- $stored_options = adinj_options();
1123
- $default_options = adinj_default_options();
1124
- ?>
1125
- <h4>Settings dump from database (all in 'adinj_options' option)</h4>
1126
- <table border="1" style="width:610px; table-layout:fixed; word-wrap:break-word;">
1127
- <tr><td><b>Name</b></td><td><b>Stored</b></td><td><b>Default</b></td></tr>
1128
- <?php
1129
- if ($stored_options !== false){
1130
- $count = 0;
1131
- foreach ($stored_options as $key => $value){
1132
- if ($count % 2 == 0){
1133
- echo '<tr style="background-color:#cccccc"><td>';
1134
- } else {
1135
- echo '<tr><td>';
1136
- }
1137
- echo "$key";
1138
- echo "</td><td>";
1139
- $value = htmlentities($value);
1140
- echo "$value";
1141
- echo "</td><td>";
1142
- echo $default_options[$key];
1143
- echo "</td></tr>";
1144
- $count++;
1145
- }
1146
- } else {
1147
- echo "<br />No options in database!";
1148
- }
1149
- echo '</table>';
1150
-
1151
- echo '<h4>Other settings</h4><blockquote>';
1152
-
1153
- echo 'ADINJ_PATH='.ADINJ_PATH.'<br />';
1154
- echo 'ADINJ_CONFIG_FILE='.ADINJ_CONFIG_FILE.'<br />';
1155
- echo 'ADINJ_AD_PATH='.ADINJ_AD_PATH.'<br />';
1156
-
1157
- echo 'Plugin version='.adinj_get_version();
1158
- echo '</blockquote>';
1159
-
1160
- global $adinj_warning_msg_filewrite;
1161
- if (!empty($adinj_warning_msg_filewrite)){
1162
- echo "<h4>Errors on 'Save all settings'</h4><blockquote>$adinj_warning_msg_filewrite</blockquote";
1163
- }
1164
-
1165
- global $adinj_warning_msg_chmod;
1166
- if (!empty($adinj_warning_msg_chmod)){
1167
- echo "<h4>Warnings on 'Save all settings'</h4><blockquote>$adinj_warning_msg_chmod</blockquote";
1168
- }
1169
-
1170
- }
1171
-
1172
  function adinj_get_version(){
1173
  $plugin_data=get_plugin_data(ADINJ_PATH . '/ad-injection.php');
1174
  return $plugin_data['Version'];
@@ -1209,46 +750,125 @@ function adinj_compatibility_checks() {
1209
  }
1210
  }
1211
 
1212
- function adinj_activate_hook() {
1213
- $stored_options = adinj_options();
1214
- $pending_options = adinj_default_options();
1215
- if(empty($stored_options)){
1216
- // Save defaults to DB below.
1217
- if (!is_plugin_active('wp-super-cache/wp-cache.php')){
1218
- $pending_options['ad_insertion_mode'] = 'direct_dynamic';
1219
- }
1220
- } else {
1221
- // Upgrade options if necessary. Use default as a baseline,
1222
- // and then overwrite default with the saved ones.
1223
- foreach ($pending_options as $key => $value){
1224
- if (array_key_exists($key, $stored_options)){
1225
- $pending_options[$key] = $stored_options[$key];
 
 
 
 
 
 
 
 
 
1226
  }
1227
  }
1228
  }
1229
-
1230
- $random_file2 = ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE;
1231
- $top_file2 = ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE;
1232
- $bottom_file2 = ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE;
1233
- if ($pending_options['ad_insertion_mode'] == 'mfunc'){
1234
- // Restore data after automatic upgrade
1235
- // TODO could remove this code further down the line when everyone
1236
- // has moved to the new ad store location
1237
- if (!@file_exists($random_file2) && !empty($pending_options['ad_code_random_1'])){
1238
- write_ad_to_file($pending_options['ad_code_random_1'], $random_file2);
 
 
1239
  }
1240
- if (!@file_exists($top_file2) && !empty($pending_options['ad_code_top_1'])){
1241
- write_ad_to_file($pending_options['ad_code_top_1'], $top_file2);
 
 
 
 
 
 
 
 
 
 
1242
  }
1243
- if (!@file_exists($bottom_file2) && !empty($pending_options['ad_code_bottom_1'])){
1244
- write_ad_to_file($pending_options['ad_code_bottom_1'], $bottom_file2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1245
  }
1246
- if (!@file_exists(ADINJ_CONFIG_FILE)){
1247
- adinj_write_config_file();
 
 
 
 
 
1248
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1249
  }
1250
-
1251
- adinj_update_options($pending_options);
1252
  }
1253
 
1254
  // If the options in the database are out of sync with our default options
@@ -1268,11 +888,12 @@ function adinj_options_need_upgrading($stored_options){
1268
  return false;
1269
  }
1270
 
 
1271
  function adinj_default_options(){
1272
  return array(
1273
  // Global settings
1274
  'ads_enabled' => 'off',
1275
- 'ads_on_page_older_than' => '10',
1276
  'exclude_home' => '',
1277
  'exclude_page' => '',
1278
  'exclude_single' => '',
@@ -1281,8 +902,21 @@ function adinj_default_options(){
1281
  'global_category_condition_entries' => '',
1282
  'global_tag_condition_mode' => ADINJ_ONLY_SHOW_IN,
1283
  'global_tag_condition_entries' => '',
1284
- // Random ad
1285
  'ad_code_random_1' => '',
 
 
 
 
 
 
 
 
 
 
 
 
 
1286
  'max_num_of_ads' => '2', // single posts and pages
1287
  'no_random_ads_if_shorter_than' => '100',
1288
  'one_ad_if_shorter_than' => '500',
@@ -1294,34 +928,81 @@ function adinj_default_options(){
1294
  'rnd_clear' => ADINJ_DISABLED,
1295
  'rnd_margin_top' => '3',
1296
  'rnd_margin_bottom' => '3',
1297
- 'first_paragraph_ad' => '',
 
 
 
1298
  'multiple_ads_at_same_position' => '',
 
 
 
 
1299
  // Home page specific random ads
1300
  'max_num_of_ads_home_page' => '3',
1301
- // top
1302
  'ad_code_top_1' => '',
 
 
 
 
 
 
 
 
 
 
 
 
 
1303
  'top_align' => ADINJ_DISABLED,
1304
  'top_clear' => ADINJ_DISABLED,
1305
  'top_margin_top' => '3',
1306
  'top_margin_bottom' => '3',
1307
- // bottom
 
 
 
 
 
 
1308
  'ad_code_bottom_1' => '',
 
 
 
 
 
 
 
 
 
 
 
 
 
1309
  'bottom_align' => ADINJ_DISABLED,
1310
  'bottom_clear' => ADINJ_DISABLED,
1311
  'bottom_margin_top' => '3',
1312
  'bottom_margin_bottom' => '3',
 
 
 
 
 
 
1313
  // widgets
1314
  'widget_exclude_home' => '',
1315
  'widget_exclude_page' => '',
1316
  'widget_exclude_single' => '',
1317
  'widget_exclude_archive' => '',
1318
  // dynamic features
1319
- 'sevisitors_only' => '',
1320
  'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search., /search/',
1321
- 'block_ips' => 'on',
1322
  'blocked_ips' => '',
 
 
1323
  'ad_insertion_mode' => 'mfunc',
1324
- // ui
1325
  'ui_global_hide' => 'false',
1326
  'ui_random_hide' => 'false',
1327
  'ui_topad_hide' => 'false',
@@ -1331,8 +1012,16 @@ function adinj_default_options(){
1331
  'ui_debugging_hide' => 'true',
1332
  'ui_docs_hide' => 'false',
1333
  'ui_testads_hide' => 'false',
 
 
 
 
1334
  // debug
1335
- 'debug_mode' => ''
 
 
 
 
1336
  );
1337
  }
1338
 
@@ -1345,142 +1034,6 @@ function write_ad_to_file($ad, $ad_path){
1345
  adinj_write_file($ad_path, $ad, 0640);
1346
  }
1347
 
1348
- function adinj_docs(){
1349
- ?>
1350
- <hr />
1351
-
1352
- <?php adinj_postbox_start(__("Quick Start", 'adinj'), "docs", '95%'); ?>
1353
-
1354
- <p>1. Copy and paste your ad code into the ad code boxes.</p>
1355
-
1356
- <p>2. Choose how many ads of each type you want displayed.</p>
1357
-
1358
- <p>3. Configure any ad positioning (optional).</p>
1359
-
1360
- <p>4. Check the ad insertion mode (in the Insertion mode and ad display restriction section).</p>
1361
-
1362
- <p>5. If you are using a compatible ad insertion mode you may configure dynamic ad display restrictions. i.e. showing ads only to certain people (e.g. search engine visitors), or blocking ads from specific IPs.</p>
1363
-
1364
- <p>6. Enable your ads (tick box at the very top).</p>
1365
- </div>
1366
-
1367
- <h3><?php echo adinj_get_logo(); ?> Supported in-page tags</h3>
1368
- <div class="inside" style="margin:10px">
1369
-
1370
- <p>These tags can be inserted into the page source to override the configured behaviour on individual pages. Because sometimes specific pages need to be treated differently.</p>
1371
-
1372
- <ul>
1373
- <li><code>&lt;!--noadsense--&gt;</code> OR <code>&lt;!-no-adsense--&gt;</code> OR <code>&lt;!--NoAds--&gt;</code> OR <code>&lt;!--OffAds--&gt;</code> - disables all ads on this page. These tags are here to make this plugin compatible with the tags from Adsense Injection, Whydowork Adsense and Quick Adsense.</li>
1374
- </ul>
1375
-
1376
- <p></p>
1377
-
1378
- <ul>
1379
- <li><code>&lt;!--adsandwich--&gt;</code> - Inserts the top and bottom ad but no random ads. Disables all other ads.</li>
1380
- <li><code>&lt;!--adfooter--&gt;</code> - Insert a single ad at the very bottom. Disables all other ads.</li>
1381
- </ul>
1382
-
1383
- <p></p>
1384
-
1385
- <ol>
1386
- <li><code>&lt;!--adsensestart--&gt;</code> - Random ads will start from this point*. For compatibility with Adsense Injection.</li>
1387
- <li><code>&lt;!--adsenseend--&gt;</code> - Random ads will not be inserted after this point*. New tag but I've kept the Adsense Injection naming convention to make it fit with the above tag.</li>
1388
- <li><code>&lt;!--adstart--&gt;</code> - Random ads will start from this point*.</li>
1389
- <li><code>&lt;!--adend--&gt;</code> - Random ads will not be inserted after this point*.</li>
1390
- </ol>
1391
-
1392
- <p>These four tags will not affect the top and bottom ad.</p>
1393
-
1394
- <h4>Custom field for disabling adverts</h4>
1395
-
1396
- <p>To disable all adverts on the page you can also set the custom <code>disable_adverts</code> field to '1' from the WordPress post editor.</p>
1397
-
1398
-
1399
- <?php adinj_postbox_end(); ?>
1400
-
1401
-
1402
- <?php adinj_postbox_start(__("Test Adverts", 'adinj'), "testads", '95%'); ?>
1403
-
1404
- <p>You can copy and paste these adverts into the boxes above to test your ad setup before switching to your real ads.</p>
1405
-
1406
- <h4><a name="468x60"></a>468x60 banner</h4>
1407
-
1408
- <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#ff9999; width:468px; height:60px;&quot;&gt;
1409
- &lt;h5&gt;TEST ADVERT 468x60 - &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;www.reviewmylife.co.uk&lt;/a&gt;&lt;/h5&gt;
1410
- &lt;/div&gt;</textarea></p>
1411
-
1412
- <div style="background-color:#99ffff; width:468px; height:60px;">
1413
- <h5>TEST ADVERT 468x60 - <a href="http://www.reviewmylife.co.uk/">www.reviewmylife.co.uk</a></h5>
1414
- </div><p></p>
1415
-
1416
- <h4><a name="728x90"></a>728x90 banner</h4>
1417
-
1418
- <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#ff9999; width:728px; height:90px;&quot;&gt;
1419
- &lt;h5&gt;TEST ADVERT 728x90&lt;/h5&gt;
1420
- &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;www.reviewmylife.co.uk&lt;/a&gt;&lt;br /&gt;
1421
- &lt;a href=&quot;http://www.advancedhtml.co.uk/&quot;&gt;www.advancedhtml.co.uk&lt;/a&gt;
1422
- &lt;/div&gt;</textarea></p>
1423
-
1424
- <div style="background-color:#ff9999; width:728px; height:90px;">
1425
- <h5>TEST ADVERT 728x90</h5>
1426
- <a href="http://www.reviewmylife.co.uk/">www.reviewmylife.co.uk</a><br />
1427
- <a href="http://www.advancedhtml.co.uk/">www.advancedhtml.co.uk</a>
1428
- </div><p></p>
1429
-
1430
- <h4>160x90 link unit</h4>
1431
-
1432
- <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#ccff99; width:160px; height:90px;&quot;&gt;
1433
- &lt;h5&gt;TEST ADVERT 160x90&lt;/h5&gt;
1434
- &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;reviewmylife.co.uk&lt;/a&gt;&lt;br /&gt;
1435
- &lt;a href=&quot;http://www.advancedhtml.co.uk/&quot;&gt;advancedhtml.co.uk&lt;/a&gt;
1436
- &lt;/div&gt;</textarea></p>
1437
-
1438
- <div style="background-color:#ccff99; width:160px; height:90px;">
1439
- <h5>TEST ADVERT 160x90</h5>
1440
- <a href="http://www.reviewmylife.co.uk/">reviewmylife.co.uk</a>
1441
- <a href="http://www.advancedhtml.co.uk/">advancedhtml.co.uk</a><br />
1442
- </div><p></p>
1443
-
1444
- <h4><a name="468x15"></a>468x15 link unit</h4>
1445
-
1446
- <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#cccc99; width:468px; height:15px;&quot;&gt;
1447
- &lt;font size=&quot;-2&quot;&gt;&lt;b&gt;TEST ADVERT 160x90&lt;/b&gt; &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;reviewmylife.co.uk&lt;/a&gt;&lt;/font&gt;
1448
- &lt;/div&gt;</textarea></p>
1449
-
1450
- <div style="background-color:#cccc99; width:468px; height:15px;">
1451
- <font size="-2"><b>TEST ADVERT 160x90</b> <a href="http://www.reviewmylife.co.uk/">reviewmylife.co.uk</a></font>
1452
- </div><p></p>
1453
-
1454
- <h4><a name="336x280"></a>336x280 large rectangle</h4>
1455
-
1456
- <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#ccccff; width:336px; height:280px;&quot;&gt;
1457
- &lt;h5&gt;TEST ADVERT 336x280 - &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;www.reviewmylife.co.uk&lt;/a&gt;&lt;/h5&gt;
1458
- &lt;/div&gt;</textarea></p>
1459
-
1460
- <div style="background-color:#ccccff; width:336px; height:280px;">
1461
- <h5>TEST ADVERT 336x280 - <a href="http://www.reviewmylife.co.uk/">www.reviewmylife.co.uk</a></h5>
1462
- </div><p></p>
1463
-
1464
- <h4>468x60 banner with dynamic PHP</h4>
1465
-
1466
- <p>The PHP will execute if 1) WP Super Cache is turned on in legacy mode, and 2) if WP Super Cache is not installed/disabled.</p>
1467
-
1468
- <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="5">&lt;div style=&quot;background-color:#ffff99; width:468px; height:60px;&quot;&gt;
1469
- &lt;b&gt;TEST ADVERT 468x60 with date() and rand()&lt;/b&gt;&lt;br /&gt;
1470
- &lt;?php echo &quot;date=&quot;.date(&quot;Y-m-d H:i:s&quot;) .&quot; rand=&quot;.rand(); ?&gt;&lt;br /&gt;
1471
- &lt;a href=&quot;http://www.advancedhtml.co.uk/&quot;&gt;www.advancedhtml.co.uk&lt;/a&gt;
1472
- &lt;/div&gt;</textarea></p>
1473
-
1474
- <div style="background-color:#ffff99; width:468px; height:60px;">
1475
- <b>TEST ADVERT 468x60 with date() and rand()</b><br />
1476
- <?php echo "date=".date("Y-m-d H:i:s") ." rand=".rand(); ?><br />
1477
- <a href="http://www.advancedhtml.co.uk/">www.advancedhtml.co.uk</a>
1478
- </div><p></p>
1479
-
1480
- <?php adinj_postbox_end();
1481
-
1482
- }
1483
-
1484
  function adinj_init_hook() {
1485
  $ops = adinj_options();
1486
  if ($ops['ads_enabled'] != 'on') {
43
 
44
  function adinj_save_options(){
45
  // TODO investigate register_settings for a future release
 
46
  switch($_POST['adinj_action']){
47
  case 'Save all settings':
48
  adinj_checkNonce();
49
 
50
  // Extract all know options
51
  $default_options = adinj_default_options();
52
+ // TODO - should use default as baseline? This won't delete old ops?
53
+ $ops = adinj_options();
54
  foreach ($default_options as $key => $value){
55
  if (isset($_POST[$key])){
56
  $ops[$key] = $_POST[$key];
 
 
57
  }
58
  }
59
 
60
+ extract_text_args('ad_code_random_', $ops, 1, 5, ADINJ_AD_PATH.'/ad_random_');
61
+ extract_text_args('ad_code_top_', $ops, 1, 5, ADINJ_AD_PATH.'/ad_top_');
62
+ extract_text_args('ad_code_bottom_', $ops, 1, 5, ADINJ_AD_PATH.'/ad_bottom_');
 
 
63
 
64
+ extract_text_args('ad_code_random_alt_', $ops, 1, 2, ADINJ_AD_PATH.'/ad_random_alt_');
65
+ extract_text_args('ad_code_top_alt_', $ops, 1, 2, ADINJ_AD_PATH.'/ad_top_alt_');
66
+ extract_text_args('ad_code_bottom_alt_', $ops, 1, 2, ADINJ_AD_PATH.'/ad_bottom_alt_');
67
 
68
+ extract_text_args('ad_referrers', $ops);
69
+ extract_text_args('blocked_ips', $ops);
 
 
 
70
 
71
  adinj_update_options($ops);
72
 
73
  if ($ops['ad_insertion_mode'] == 'mfunc') {
 
 
 
74
  adinj_write_config_file();
75
  }
76
 
91
  // TODO add option to delete ads files as well
92
  break;
93
  }
94
+ }
95
+
96
+ function extract_text_args($name, &$ops, $start=NULL, $end=NULL, $save_path_stem=NULL){
97
+ if ($start === NULL){
98
+ if (isset($_POST[$name])){
99
+ $ops[$name] = stripslashes($_POST[$name]);
100
+ if ($save_path_stem != NULL){
101
+ write_ad_to_file($ops[$name], $save_path_stem.'1.txt');
102
+ }
103
+ }
104
+ } else {
105
+ for ($i = $start; $i<=$end; ++$i){
106
+ if (isset($_POST[$name.$i])){
107
+ $ops[$name.$i] = stripslashes($_POST[$name.$i]);
108
+ if ($save_path_stem != NULL){
109
+ write_ad_to_file($ops[$name.$i], $save_path_stem.$i.'.txt');
110
+ }
111
+ }
112
+ }
113
  }
114
  }
115
 
119
  function adinj_write_config_file(){
120
  $ops = adinj_options();
121
  if ($ops['ad_insertion_mode'] != 'mfunc') return;
122
+
123
+ $sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false';
124
  $referrer_list = adinj_quote_list('ad_referrers');
125
+
126
+ $block_ips = adinj_ticked('block_ips')?'true':'false';
127
  $ip_list = adinj_quote_list('blocked_ips');
128
+
129
+ // TODO
130
+ $block_keywords = adinj_ticked('block_keywords')?'true':'false';
131
+ $keyword_list = adinj_quote_list('blocked_keywords');
132
+
133
  $debug_mode = adinj_ticked('debug_mode')?'true':'false';
134
 
135
  // TODO remove these from config file later...
147
 
148
  function adinj_config_sevisitors_only() { return $sevisitors_only; }
149
  function adinj_config_search_engine_referrers() { return array($referrer_list); }
150
+
151
+ function adinj_config_block_ips() { return $block_ips; }
152
  function adinj_config_blocked_ips() { return array($ip_list); }
153
+
154
+ //TODO not yet implemented
155
+ function adinj_config_block_keywords() { return $block_keywords; }
156
+ function adinj_config_blocked_keywords() { return array($blocked_keywords); }
157
+
158
  function adinj_config_debug_mode() { return $debug_mode; }
159
+
160
  $rnd_func
161
  $top_func
162
  $bottom_func
203
  }
204
 
205
  function adinj_options_page(){
206
+ if (isset($_POST['adinj_action'])){
207
+ adinj_save_options();
208
+ }
209
 
210
+ adinj_upgrade_db_if_necessary();
211
  $ops = adinj_options();
 
 
 
 
 
 
 
 
 
 
212
 
213
  echo '<div class="wrap" style="width:950px;">';
214
 
220
 
221
  echo '<div id="icon-options-general" class="icon32"></div><h2>Ad Injection ' . adinj_get_version() . adinj_get_logo() . '</h2>';
222
 
223
+ adinj_top_message_box();
224
+
225
+ adinj_admin_tabs();
226
+
227
+ echo '<form name="adinjform" method="post" action="">';
228
+ wp_nonce_field('_adinj_form');
229
+
230
+ echo '<div style="width:258px; float:right;">';
231
+
232
+ switch( $_GET[ 'tab' ] ) {
233
+ case "adrotation":
234
+ require_once(ADINJ_PATH . '/ui-tab-adrotation.php');
235
+ adinj_side_info_box();
236
+ echo '</div>';
237
+ adinj_tab_adrotation();
238
+ break;
239
+ case "main":
240
+ default:
241
+ require_once(ADINJ_PATH . '/ui-tab-main.php');
242
+ adinj_side_status_box();
243
+ adinj_side_info_box();
244
+ echo '</div>';
245
+ adinj_tab_main();
246
+ break;
247
+ }
248
+
249
+ echo '</form>';
250
+ echo '</div> <!--wrap-->';
251
+ }
252
+
253
+ function adinj_top_message_box(){
254
+ $ops = adinj_options();
255
  if (isset($_POST['adinj_action'])) {
256
  echo '<div id="message" class="updated below-h2"><p><strong>';
257
  echo 'All settings saved: ';
279
 
280
  } else {
281
  echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
282
+ echo "21st January 2011: This is a big update introducing support for split testing / ad rotation. And also 'alternate content' as well as other fixes and updates. I've done my best to test this update but as the update is big there is a risk of problems. Please contact me ASAP if you spot any bugs, or odd behaviour via the ".'<a href="https://spreadsheets.google.com/viewform?formkey=dFUwZzBYcG1HNzNKMmJZdWFDdFhkY0E6MQ" target="_new">feedback form</a>.';
283
  echo '</strong></p></div>';
284
  }
285
+ }
286
+
287
+ function adinj_side_info_box(){
288
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  <div class="postbox-container" style="width:258px;">
290
  <div class="metabox-holder">
291
  <div class="meta-box-sortables">
292
+ <div class="postbox">
293
+ <h3 class="hndle"><span><?php echo adinj_get_logo(); ?> Info</span></h3>
294
  <div class="inside" style="margin:5px;">
295
  <h4>More Ad Injection information</h4>
296
  <ul>
300
  </ul>
301
  <h4>Coming in 2011</h4>
302
  <ul>
303
+ <li>Per ad control over which categories and tags the ads are shown in.</li>
304
+ <li>Extra ad locations.</li>
305
  </ul>
306
 
307
  <h4><font color="red">Important!</font></h4>
320
  </div>
321
  </div>
322
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  <?php
324
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
 
326
+ function adinj_add_checkbox($name){
327
+ echo '<input type="hidden" name="'.$name.'" value="off" />';
328
+ echo '<input type="checkbox" name="'.$name.'" '.adinj_ticked($name).' />';
 
 
 
 
 
329
  }
330
 
331
  // From WP Super cache
338
  $current = 'main';
339
  }
340
  }
341
+ $tabs = array( 'main' => __( 'Main', 'ad-injection' ), 'adrotation' => __( 'Ad pool: (Rotation / A:B Testing / Alternate content)', 'ad-injection' ) );
342
  $links = array();
343
  foreach( $tabs as $tab => $name ) {
344
  if ( $current == $tab ) {
345
+ $links[] = "<a class='nav-tab nav-tab-active' href='?page=ad-injection&nbsp;tab=$tab'>$name</a>";
346
  } else {
347
+ $links[] = "<a class='nav-tab' href='?page=ad-injection&nbsp;tab=$tab'>$name</a>";
348
  }
349
  }
350
 
420
  $status[1] = 'test mode';
421
  }
422
  } else if ($name == 'random'){
423
+ $count = adinj_count_live_ads('ad_code_random_', $ops);
424
+ if ($count == 0){
425
  $status[0] = 'red';
426
+ $status[1] = 'no ads defined';
427
  return $status;
428
  }
429
  $val = $ops['max_num_of_ads'];
430
  if ($val == '0'){
431
  $status[0] = 'red';
 
432
  } else {
433
  $status[0] = 'green';
 
434
  }
435
+ $status[1] = 'single/page: ' . $val . ' <a href="#random_single">#</a>';
436
  } else if ($name == 'random_home'){
437
  $val = $ops['max_num_of_ads_home_page'];
 
438
  if ($val == 0){
439
  $status[0] = 'red';
 
 
 
 
440
  } else {
441
  $status[0] = 'green';
 
442
  }
443
+ $status[1] = 'home: ' . $val .' <a href="#random_home">#</a>';
444
+ } else if ($name == 'random_pool'){
445
+ $count = adinj_count_live_ads('ad_code_random_', $ops);
446
+ $status[0] = $count == 0 ? 'red' : 'green';
447
+ $status[1] = "ad pool: " . $count." <a href='?page=ad-injection&amp;tab=adrotation#multiple_random'>#</a>";
448
+ } else if ($name == 'top_pool'){
449
+ $count = adinj_count_live_ads('ad_code_top_', $ops);
450
+ $status[0] = $count == 0 ? 'red' : 'green';
451
+ $status[1] = "ad pool: " . $count." <a href='?page=ad-injection&amp;tab=adrotation#multiple_top'>#</a>";
452
+ } else if ($name == 'bottom_pool'){
453
+ $count = adinj_count_live_ads('ad_code_bottom_', $ops);
454
+ $status[0] = $count == 0 ? 'red' : 'green';
455
+ $status[1] = "ad pool: " . $count." <a href='?page=ad-injection&amp;tab=adrotation#multiple_bottom'>#</a>";
456
+ } else if ($name == 'random_alt_pool'){
457
+ $count = adinj_count_live_ads('ad_code_random_alt_', $ops);
458
+ $status[1] = "alt pool: " . $count." <a href='?page=ad-injection&amp;tab=adrotation#ad_code_random_alt_1'>#</a>";
459
+ } else if ($name == 'top_alt_pool'){
460
+ $count = adinj_count_live_ads('ad_code_top_alt_', $ops);
461
+ $status[1] = "alt pool: " . $count." <a href='?page=ad-injection&amp;tab=adrotation#ad_code_top_alt_1'>#</a>";
462
+ } else if ($name == 'bottom_alt_pool'){
463
+ $count = adinj_count_live_ads('ad_code_bottom_alt_', $ops);
464
+ $status[1] = "alt pool: " . $count." <a href='?page=ad-injection&amp;tab=adrotation#ad_code_bottom_alt_1'>#</a>";
465
  } else if ($name == 'topad'){
466
+ $count = adinj_count_live_ads('ad_code_top_', $ops);
467
+ if ($count == 0){
468
  $status[0] = 'red';
469
  $status[1] = 'no ad defined';
470
  return $status;
478
  $status[1] = 'on';
479
  }
480
  } else if ($name == 'bottomad'){
481
+ $count = adinj_count_live_ads('ad_code_bottom_', $ops);
482
+ if ($count == 0){
483
  $status[0] = 'red';
484
  $status[1] = 'no ad defined';
485
  return $status;
563
  foreach ($values as $value){
564
  echo "<option value=\"$value\" ";
565
  if($selected_value == "$value") echo 'selected="selected"';
566
+ if ($type==NULL && is_numeric($value)){
567
  $typetxt = "(chars)";
568
  } else {
569
  $typetxt = $type;
610
 
611
  <?php } else if ($type == 'tag') { ?>
612
 
613
+ <select name="<?php echo $name; ?>_dropdown" onchange='adinj_addtext(document.adinjform.<?php echo $name; ?>_condition_entries, this.options[this.selectedIndex].value);'>
614
 
615
  <option value=""><?php echo 'Add ' . $type; ?></option>
616
  <?php
710
  array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options, $bdefault);
711
  }
712
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
713
  function adinj_get_version(){
714
  $plugin_data=get_plugin_data(ADINJ_PATH . '/ad-injection.php');
715
  return $plugin_data['Version'];
750
  }
751
  }
752
 
753
+ //////////////////////////////////////////////////////////////////////////////
754
+
755
+ function adinj_percentage_split($name_stem, $num, $ops, $total=NULL){
756
+ // for old db - TODO delete later
757
+ if (adinj_db_version($ops) == 1){
758
+ if ($num == 1) return '100%';
759
+ return '0%';
760
+ }
761
+
762
+ if ($total == NULL){
763
+ $total = adinj_total_split($name_stem, $ops);
764
+ }
765
+
766
+ $name = $name_stem.$num;
767
+ $namesplit = $name.'_split';
768
+
769
+ $percent = 0;
770
+ if (!empty($ops[$name])){
771
+ if ($total == 0){
772
+ $percent = 0;
773
+ } else {
774
+ if (!empty($ops[$namesplit])){
775
+ $percent = ($ops[$namesplit] / $total) * 100;
776
  }
777
  }
778
  }
779
+ $percent = number_format($percent, 1).'%';
780
+ return $percent;
781
+ }
782
+
783
+ function adinj_total_split($name_stem, $ops){
784
+ $total = 0;
785
+ for ($i=1; $i<=10; ++$i){
786
+ $split = $name_stem.$i.'_split';
787
+ if (!empty($ops[$name_stem.$i]) &&
788
+ is_numeric($ops[$split]) &&
789
+ $ops[$split] > 0){
790
+ $total += $ops[$split];
791
  }
792
+ }
793
+ return $total;
794
+ }
795
+
796
+ function adinj_count_live_ads($name_stem, $ops){
797
+ $total = 0;
798
+ for ($i=1; $i<=10; ++$i){
799
+ $split = $name_stem.$i.'_split';
800
+ if (!empty($ops[$name_stem.$i]) &&
801
+ is_numeric($ops[$split]) &&
802
+ $ops[$split] > 0){
803
+ $total += 1;
804
  }
805
+ }
806
+ return $total;
807
+ }
808
+
809
+ //////////////////////////////////////////////////////////////////////////////
810
+
811
+ // Hopefully run on install and upgrade
812
+ function adinj_activate_hook(){
813
+ $ops = adinj_options();
814
+ if(empty($ops)){
815
+ // 1st Install.
816
+ adinj_install_db();
817
+ } else {
818
+ // Upgrade check.
819
+ adinj_upgrade_db_if_necessary();
820
+ }
821
+ }
822
+
823
+ function adinj_install_db(){
824
+ $new_options = adinj_default_options();
825
+ // Dynamic defaults.
826
+ if (!is_plugin_active('wp-super-cache/wp-cache.php')){
827
+ $new_options['ad_insertion_mode'] = 'direct_dynamic';
828
+ }
829
+ adinj_update_options($new_options);
830
+ if ($new_options['ad_insertion_mode'] == 'mfunc'){
831
+ // Create config file.
832
+ adinj_write_config_file();
833
+ }
834
+ }
835
+
836
+ function adinj_upgrade_db(){
837
+ $stored_options = adinj_options();
838
+ $new_options = adinj_default_options();
839
+
840
+ $stored_dbversion = adinj_db_version($stored_options);
841
+ $new_dbversion = adinj_db_version($new_options);
842
+
843
+ // 1. Copy existing options to new array. Use default as a baseline,
844
+ // and then overwrite default with the saved ones.
845
+ foreach ($new_options as $key => $value){
846
+ if (array_key_exists($key, $stored_options)){
847
+ $new_options[$key] = $stored_options[$key];
848
  }
849
+ }
850
+
851
+ // 2. Upgrade options if necessary.
852
+ if ($stored_dbversion == 1){
853
+ // Copy this to new setting
854
+ if (adinj_ticked('first_paragraph_ad')){
855
+ $new_options['start_from_paragraph'] = 1;
856
  }
857
+ // This previously wan't configured correctly
858
+ $new_options['block_ips'] = 'on';
859
+ }
860
+
861
+ // 3. Bump up db version number.
862
+ $new_options['db_version'] = $new_dbversion;
863
+
864
+ // 4. Save upgraded options.
865
+ adinj_update_options($new_options);
866
+
867
+ // 5. Update config file.
868
+ if ($new_options['ad_insertion_mode'] == 'mfunc'){
869
+ // Update config file
870
+ adinj_write_config_file();
871
  }
 
 
872
  }
873
 
874
  // If the options in the database are out of sync with our default options
888
  return false;
889
  }
890
 
891
+ // All these stored in a single DB option row
892
  function adinj_default_options(){
893
  return array(
894
  // Global settings
895
  'ads_enabled' => 'off',
896
+ 'ads_on_page_older_than' => '0',
897
  'exclude_home' => '',
898
  'exclude_page' => '',
899
  'exclude_single' => '',
902
  'global_category_condition_entries' => '',
903
  'global_tag_condition_mode' => ADINJ_ONLY_SHOW_IN,
904
  'global_tag_condition_entries' => '',
905
+ // Random ads
906
  'ad_code_random_1' => '',
907
+ 'ad_code_random_2' => '',
908
+ 'ad_code_random_3' => '',
909
+ 'ad_code_random_4' => '',
910
+ 'ad_code_random_5' => '',
911
+ 'ad_code_random_1_split' => '100',
912
+ 'ad_code_random_2_split' => '100',
913
+ 'ad_code_random_3_split' => '100',
914
+ 'ad_code_random_4_split' => '100',
915
+ 'ad_code_random_5_split' => '100',
916
+ 'ad_code_random_alt_1' => '',
917
+ 'ad_code_random_alt_2' => '',
918
+ 'ad_code_random_alt_1_split' => '100',
919
+ 'ad_code_random_alt_2_split' => '100',
920
  'max_num_of_ads' => '2', // single posts and pages
921
  'no_random_ads_if_shorter_than' => '100',
922
  'one_ad_if_shorter_than' => '500',
928
  'rnd_clear' => ADINJ_DISABLED,
929
  'rnd_margin_top' => '3',
930
  'rnd_margin_bottom' => '3',
931
+ 'rnd_padding_top' => ADINJ_DISABLED, //TODO
932
+ 'rnd_padding_bottom' => ADINJ_DISABLED, //TODO
933
+ 'first_paragraph_ad' => '', // TODO delete
934
+ 'start_from_paragraph' => ADINJ_DISABLED, //TODO
935
  'multiple_ads_at_same_position' => '',
936
+ 'rnd_category_condition_mode' => ADINJ_ONLY_SHOW_IN, //TODO
937
+ 'rnd_category_condition_entries' => '', //TODO
938
+ 'rnd_tag_condition_mode' => ADINJ_ONLY_SHOW_IN, //TODO
939
+ 'rnd_tag_condition_entries' => '', //TODO
940
  // Home page specific random ads
941
  'max_num_of_ads_home_page' => '3',
942
+ // Top ads
943
  'ad_code_top_1' => '',
944
+ 'ad_code_top_2' => '',
945
+ 'ad_code_top_3' => '',
946
+ 'ad_code_top_4' => '',
947
+ 'ad_code_top_5' => '',
948
+ 'ad_code_top_1_split' => '100',
949
+ 'ad_code_top_2_split' => '100',
950
+ 'ad_code_top_3_split' => '100',
951
+ 'ad_code_top_4_split' => '100',
952
+ 'ad_code_top_5_split' => '100',
953
+ 'ad_code_top_alt_1' => '',
954
+ 'ad_code_top_alt_2' => '',
955
+ 'ad_code_top_alt_1_split' => '100',
956
+ 'ad_code_top_alt_2_split' => '100',
957
  'top_align' => ADINJ_DISABLED,
958
  'top_clear' => ADINJ_DISABLED,
959
  'top_margin_top' => '3',
960
  'top_margin_bottom' => '3',
961
+ 'top_padding_top' => ADINJ_DISABLED, //TODO
962
+ 'top_padding_bottom' => ADINJ_DISABLED, //TODO
963
+ 'top_category_condition_mode' => ADINJ_ONLY_SHOW_IN, //TODO
964
+ 'top_category_condition_entries' => '', //TODO
965
+ 'top_tag_condition_mode' => ADINJ_ONLY_SHOW_IN, //TODO
966
+ 'top_tag_condition_entries' => '', //TODO
967
+ // Bottom ads
968
  'ad_code_bottom_1' => '',
969
+ 'ad_code_bottom_2' => '',
970
+ 'ad_code_bottom_3' => '',
971
+ 'ad_code_bottom_4' => '',
972
+ 'ad_code_bottom_5' => '',
973
+ 'ad_code_bottom_1_split' => '100',
974
+ 'ad_code_bottom_2_split' => '100',
975
+ 'ad_code_bottom_3_split' => '100',
976
+ 'ad_code_bottom_4_split' => '100',
977
+ 'ad_code_bottom_5_split' => '100',
978
+ 'ad_code_bottom_alt_1' => '',
979
+ 'ad_code_bottom_alt_2' => '',
980
+ 'ad_code_bottom_alt_1_split' => '100',
981
+ 'ad_code_bottom_alt_2_split' => '100',
982
  'bottom_align' => ADINJ_DISABLED,
983
  'bottom_clear' => ADINJ_DISABLED,
984
  'bottom_margin_top' => '3',
985
  'bottom_margin_bottom' => '3',
986
+ 'bottom_padding_top' => ADINJ_DISABLED, //TODO
987
+ 'bottom_padding_bottom' => ADINJ_DISABLED, //TODO
988
+ 'bottom_category_condition_mode' => ADINJ_ONLY_SHOW_IN, //TODO
989
+ 'bottom_category_condition_entries' => '', //TODO
990
+ 'bottom_tag_condition_mode' => ADINJ_ONLY_SHOW_IN, //TODO
991
+ 'bottom_tag_condition_entries' => '', //TODO
992
  // widgets
993
  'widget_exclude_home' => '',
994
  'widget_exclude_page' => '',
995
  'widget_exclude_single' => '',
996
  'widget_exclude_archive' => '',
997
  // dynamic features
998
+ 'sevisitors_only' => 'off',
999
  'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search., /search/',
1000
+ 'block_ips' => 'on', //TODO
1001
  'blocked_ips' => '',
1002
+ 'block_keywords' => 'off', //TODO
1003
+ 'blocked_keywords' => '', //TODO
1004
  'ad_insertion_mode' => 'mfunc',
1005
+ // ui main tab
1006
  'ui_global_hide' => 'false',
1007
  'ui_random_hide' => 'false',
1008
  'ui_topad_hide' => 'false',
1012
  'ui_debugging_hide' => 'true',
1013
  'ui_docs_hide' => 'false',
1014
  'ui_testads_hide' => 'false',
1015
+ // ui ad rotation tab
1016
+ 'ui_multiple_random_hide' => 'false',
1017
+ 'ui_multiple_top_hide' => 'false',
1018
+ 'ui_multiple_bottom_hide' => 'false',
1019
  // debug
1020
+ 'debug_mode' => '',
1021
+ // version
1022
+ // _ = before split testing
1023
+ // 2 = split testing support
1024
+ 'db_version' => ADINJ_DB_VERSION
1025
  );
1026
  }
1027
 
1034
  adinj_write_file($ad_path, $ad, 0640);
1035
  }
1036
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1037
  function adinj_init_hook() {
1038
  $ops = adinj_options();
1039
  if ($ops['ads_enabled'] != 'on') {
ad-injection-widget.php CHANGED
@@ -4,6 +4,8 @@ Part of the Ad Injection plugin for WordPress
4
  http://www.reviewmylife.co.uk/
5
  */
6
 
 
 
7
  class Ad_Injection_Widget extends WP_Widget {
8
  function Ad_Injection_Widget() {
9
  $widget_ops = array( 'classname' => 'adinjwidget', 'description' => 'Insert Ad Injection adverts into your sidebars/widget areas.' );
@@ -21,34 +23,29 @@ class Ad_Injection_Widget extends WP_Widget {
21
  return;
22
  }
23
 
 
 
24
  $ops = adinj_options();
25
- if ($ops['ad_insertion_mode'] == 'direct_dynamic'){
26
- if (adshow_show_adverts() !== true){
27
- return;
28
- }
29
  }
30
 
31
- extract( $args );
32
-
33
  $title = apply_filters('widget_title', $instance['title'] );
34
- $advert = $instance['advert'];
 
 
 
 
 
35
 
36
  echo $before_widget;
37
  if ( $title ) {
38
  echo $before_title . $title . $after_title;
39
- }
40
-
41
- $adcode = "";
42
- $include = "";
43
- if ($ops['ad_insertion_mode'] == 'mfunc'){
44
- $include = adinj_ad_code_include();
45
- $adcode = adinj_get_mfunc_code($this->get_ad_file_name(), $instance);
46
- } else {
47
- $adcode = adshow_add_formatting($advert, $instance);
48
- }
49
- $adcode = adinj_ad_code_eval($adcode);
50
 
51
- if ( $advert ){
52
  echo $include;
53
  echo $adcode;
54
  }
@@ -56,35 +53,82 @@ class Ad_Injection_Widget extends WP_Widget {
56
  echo $after_widget;
57
  }
58
 
59
- function update( $new_instance, $old_instance ) {
60
- $instance = $old_instance;
61
-
62
- /* Strip tags (if needed) and update the widget settings. */
63
- $instance['title'] = strip_tags( $new_instance['title'] );
64
- $instance['advert'] = $new_instance['advert'];
65
- $instance['margin_top'] = $new_instance['margin_top'];
66
- $instance['margin_bottom'] = $new_instance['margin_bottom'];
67
- $instance['padding_top'] = $new_instance['padding_top'];
68
- $instance['padding_bottom'] = $new_instance['padding_bottom'];
69
 
70
- write_ad_to_file($instance['advert'], $this->get_ad_file_path());
 
 
 
 
71
 
72
- return $instance;
73
  }
74
 
75
- function form( $instance ) {
76
-
77
  /* Set up some default widget settings. */
78
- $defaults = array(
79
  'title' => '',
80
- 'advert' => '',
 
 
 
 
 
 
 
 
 
 
 
81
  'margin_top' => ADINJ_DISABLED,
82
  'margin_bottom' => ADINJ_DISABLED,
83
  'padding_top' => ADINJ_DISABLED,
84
- 'padding_bottom' => ADINJ_DISABLED);
85
- $instance = wp_parse_args( (array) $instance, $defaults );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  ?>
87
 
 
 
88
  <p>
89
  <label for="<?php echo $this->get_field_id('title'); ?>">Title:</label>
90
  <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
@@ -92,42 +136,110 @@ class Ad_Injection_Widget extends WP_Widget {
92
  <span style="font-size:10px;">Make sure any label complies with your ad provider's TOS. More info for <a href="http://adsense.blogspot.com/2007/04/encouraging-clicks.html" target="_new">AdSense</a> users.</span>
93
  </p>
94
 
95
- <table border="0" cellspacing="5">
96
- <tr><td style="vertical-align: top">
97
- <label for="<?php echo $this->get_field_id('advert'); ?>">Ad code:</label>
98
- <textarea class="widefat" rows="12" cols="30" id="<?php echo $this->get_field_id('advert'); ?>" name="<?php echo $this->get_field_name('advert'); ?>"><?php echo $instance['advert']; ?></textarea>
99
- </td><td style="vertical-align: top">
 
 
 
 
100
  <?php adinj_add_margin_top_bottom_options('widget_', $instance, $this->get_field_name('margin_top'), $this->get_field_name('margin_bottom') ); ?>
101
- <br />
102
  <?php adinj_add_padding_top_bottom_options('widget_', $instance, $this->get_field_name('padding_top'), $this->get_field_name('padding_bottom') ); ?>
103
  </td></tr>
104
- </table>
105
 
106
- <p>The following dynamic options to define who sees these adverts are on the main <a href='options-general.php?page=ad-injection.php'>Ad Injection settings page</a>. The title will however always be displayed. If you want the title to be dynamic as well you should embed it in the ad code text box.</p>
 
 
 
 
 
 
 
107
 
108
- <blockquote>
109
- <ul>
110
- <li>Ads on pages older than...</li>
111
- <li>Ads for search engine visitors only.</li>
112
- <li>Block ads by IP.</li>
113
- </ul>
114
- </blockquote>
115
 
116
  <p>You can also set which <a href='options-general.php?page=ad-injection.php#widgets'>page types</a> the widgets appear on.</p>
117
 
118
  <?php
119
  }
120
 
121
- function get_ad_file_path(){
122
- return ADINJ_AD_PATH.'/'.$this->get_ad_file_name();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  }
124
 
125
- function get_ad_file_name(){
126
- return 'ad_widget_'.$this->get_id().'.txt';
127
  }
128
 
129
  function get_id(){
130
- $field = $this->get_field_id('advert');
 
131
  preg_match('/-(\d+)-/', $field, $matches);
132
  return $matches[1];
133
  }
4
  http://www.reviewmylife.co.uk/
5
  */
6
 
7
+ define('ADINJ_WIDGET_DB_VERSION', 2);
8
+
9
  class Ad_Injection_Widget extends WP_Widget {
10
  function Ad_Injection_Widget() {
11
  $widget_ops = array( 'classname' => 'adinjwidget', 'description' => 'Insert Ad Injection adverts into your sidebars/widget areas.' );
23
  return;
24
  }
25
 
26
+ extract( $args );
27
+
28
  $ops = adinj_options();
29
+
30
+ $include = "";
31
+ if ($ops['ad_insertion_mode'] == 'mfunc'){
32
+ $include = adinj_ad_code_include();
33
  }
34
 
 
 
35
  $title = apply_filters('widget_title', $instance['title'] );
36
+
37
+ // The old 'non upgraded' db will be passed here if the widget hasn't
38
+ // been resaved. We can't upgrade as doing so would mean we'd have to
39
+ // re-save the widget files - which we can't do as we can't re-write
40
+ // the settings back to the db (at least not without a bit more work)
41
+ $adcode = adinj_get_ad_code('widget_'.$this->get_id(), $instance);
42
 
43
  echo $before_widget;
44
  if ( $title ) {
45
  echo $before_title . $title . $after_title;
46
+ }
 
 
 
 
 
 
 
 
 
 
47
 
48
+ if ( !empty($adcode) ){
49
  echo $include;
50
  echo $adcode;
51
  }
53
  echo $after_widget;
54
  }
55
 
56
+ function update( $new_instance, $old_instance ){
57
+ $updated = $this->adinj_upgrade_widget_db($new_instance, $old_instance);
58
+
59
+ // Only strip tags when potential for updated title
60
+ $updated['title'] = strip_tags( $new_instance['title'] );
 
 
 
 
 
61
 
62
+ write_ad_to_file($updated['advert_1'], $this->get_ad_file_path(1));
63
+ write_ad_to_file($updated['advert_2'], $this->get_ad_file_path(2));
64
+ write_ad_to_file($updated['advert_3'], $this->get_ad_file_path(3));
65
+ write_ad_to_file($updated['advert_alt_1'], $this->get_alt_file_path(1));
66
+ write_ad_to_file($updated['advert_alt_2'], $this->get_alt_file_path(2));
67
 
68
+ return $updated;
69
  }
70
 
71
+ function default_options(){
 
72
  /* Set up some default widget settings. */
73
+ return array(
74
  'title' => '',
75
+ //adverts
76
+ 'advert_1' => '',
77
+ 'advert_1_split' => '100',
78
+ 'advert_2' => '',
79
+ 'advert_2_split' => '100',
80
+ 'advert_3' => '',
81
+ 'advert_3_split' => '100',
82
+ 'advert_alt_1' => '',
83
+ 'advert_alt_1_split' => '100',
84
+ 'advert_alt_2' => '',
85
+ 'advert_alt_2_split' => '100',
86
+ //settings
87
  'margin_top' => ADINJ_DISABLED,
88
  'margin_bottom' => ADINJ_DISABLED,
89
  'padding_top' => ADINJ_DISABLED,
90
+ 'padding_bottom' => ADINJ_DISABLED,
91
+ //ui
92
+ 'ui_ad_1_show' => 'true',
93
+ 'ui_ad_2_show' => 'false',
94
+ 'ui_ad_3_show' => 'false',
95
+ 'ui_alt_1_show' => 'false',
96
+ 'ui_alt_2_show' => 'false',
97
+ //
98
+ 'db_version' => '2'
99
+ );
100
+ }
101
+
102
+ function adinj_upgrade_widget_db($new_instance, $old_instance){
103
+ // Copy old values across to default
104
+ $updated = $this->default_options();
105
+ foreach ($updated as $key => $value){
106
+ if (array_key_exists($key, $new_instance)){
107
+ $updated[$key] = $new_instance[$key];
108
+ }
109
+ }
110
+
111
+ // Upgrade any options as necessary
112
+ $old_dbversion = adinj_db_version($old_instance);
113
+ if ($old_dbversion == 1){
114
+ $updated['advert_1'] = $old_instance['advert'];
115
+ }
116
+
117
+ $updated['db_version'] = ADINJ_WIDGET_DB_VERSION;
118
+
119
+ return $updated;
120
+ }
121
+
122
+ function form( $instance ) {
123
+ $instance = $this->adinj_upgrade_widget_db($instance, $instance);
124
+
125
+ $total_ad_split = adinj_total_split('advert_', $instance);
126
+ $total_alt_split = adinj_total_split('advert_alt_', $instance);
127
+
128
  ?>
129
 
130
+ <input type='hidden' <?php $this->add_id_and_name('db_version'); ?> value='<?php echo $defaults['db_version']; ?>' />
131
+
132
  <p>
133
  <label for="<?php echo $this->get_field_id('title'); ?>">Title:</label>
134
  <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
136
  <span style="font-size:10px;">Make sure any label complies with your ad provider's TOS. More info for <a href="http://adsense.blogspot.com/2007/04/encouraging-clicks.html" target="_new">AdSense</a> users.</span>
137
  </p>
138
 
139
+ <style type="text/css">
140
+ .adinjtable td { vertical-align: top; }
141
+ </style>
142
+
143
+ <table border="0" cellspacing="5" width="100% "class="adinjtable">
144
+ <?php
145
+ $this->add_row('advert_', 1, 'Ad code 1', 'ui_ad_1_show', $total_ad_split, $instance);
146
+ ?>
147
+ <tr><td>
148
  <?php adinj_add_margin_top_bottom_options('widget_', $instance, $this->get_field_name('margin_top'), $this->get_field_name('margin_bottom') ); ?>
149
+ </td><td>
150
  <?php adinj_add_padding_top_bottom_options('widget_', $instance, $this->get_field_name('padding_top'), $this->get_field_name('padding_bottom') ); ?>
151
  </td></tr>
 
152
 
153
+ <?php
154
+ $this->add_row('advert_', 2, 'Ad code 2', 'ui_ad_2_show', $total_ad_split, $instance);
155
+ $this->add_row('advert_', 3, 'Ad code 3', 'ui_ad_3_show', $total_ad_split, $instance);
156
+ $this->add_row('advert_alt_', 1, 'Alt content 1', 'ui_alt_1_show', $total_alt_split, $instance);
157
+ $this->add_row('advert_alt_', 2, 'Alt content 2', 'ui_alt_2_show', $total_alt_split, $instance);
158
+ ?>
159
+
160
+ </table>
161
 
162
+ <p>Other options to define who sees these adverts (by page age, IP, referrer) are on the main <a href='options-general.php?page=ad-injection.php'>Ad Injection settings page</a>. The title will however always be displayed. If you want the title to be dynamic as well you should embed it in the ad code text box.</p>
 
 
 
 
 
 
163
 
164
  <p>You can also set which <a href='options-general.php?page=ad-injection.php#widgets'>page types</a> the widgets appear on.</p>
165
 
166
  <?php
167
  }
168
 
169
+ function add_row($op_stem, $num, $label, $show_op, $total_split, $ops){
170
+ $op = $op_stem.$num;
171
+ $op_split = $op.'_split';
172
+ $anchorid = $op_stem.uniqid().'_'.$num;
173
+ $anchorclick = $anchorid.'_click';
174
+ $show = $ops[$show_op];
175
+ $hiddenfieldid = $this->get_field_id($show_op);
176
+ $percentage_split = adinj_percentage_split($op_stem, $num, $ops, $total_split);
177
+ ?>
178
+ <tr><td colspan='2'>
179
+ <textarea style="float:right" <?php $this->add_id_and_name($op_split); ?> rows="1" cols="4"><?php echo $ops[$op_split]; ?></textarea>
180
+
181
+ <?php
182
+ echo <<<HTML
183
+ <a href='#' onclick='javascript:$anchorclick();return false;' style='float:left;display:none' id='toggle-$anchorid' class='button'>+/-</a>
184
+
185
+ <label><b> $label</b></label> <label style='float:right'>(Rotation: $percentage_split)</label>
186
+
187
+ <script type="text/javascript">
188
+ jQuery(document).ready(function(){
189
+ jQuery('a#toggle-$anchorid').show();
190
+ if ('$show' == 'false') jQuery('.$anchorid-box').hide();
191
+ });
192
+ function $anchorclick(){
193
+ jQuery('#$hiddenfieldid').val(jQuery('.$anchorid-box').is(":hidden"));
194
+ jQuery('.$anchorid-box').slideToggle(1000);
195
+ }
196
+ </script>
197
+
198
+ </td></tr>
199
+ <tr><td colspan='2'>
200
+
201
+ <div id="$anchorid-box" class="$anchorid-box">
202
+
203
+ HTML;
204
+
205
+ if ($op_stem == 'advert_' && $num == 2){
206
+ echo '<span style="font-size:10px;">These boxes are for defining rotated adverts which replace the original advert according to the percentages defined. If you want multiple sidebar/widget ads you need to drag another widget into the sidebar.</span><br />';
207
+ }
208
+ if ($op_stem == 'advert_alt_' && $num == 1){
209
+ echo '<span style="font-size:10px;">Here you can define content which is shown if ads are blocked for the viewer (only for mfunc and dynamic ad insertion modes).</span><br />';
210
+ }
211
+
212
+ ?>
213
+ <input type='hidden' <?php $this->add_id_and_name($show_op); ?> value='<?php echo $ops[$show_op]; ?>' />
214
+ <textarea class="widefat" rows="8" cols="50" width="100%" <?php $this->add_id_and_name($op); ?>><?php echo $ops[$op]; ?></textarea>
215
+ </div>
216
+ </td></tr>
217
+ <?php
218
+ }
219
+
220
+ function add_id_and_name($op){
221
+ echo 'id="'.$this->get_field_id($op).'" name="'.$this->get_field_name($op).'"';
222
+ }
223
+
224
+ function get_ad_file_path($num){
225
+ return ADINJ_AD_PATH.'/'.$this->get_ad_file_name($num);
226
+ }
227
+
228
+ function get_alt_file_path($num){
229
+ return ADINJ_AD_PATH.'/'.$this->get_alt_file_name($num);
230
+ }
231
+
232
+ function get_ad_file_name($num){
233
+ return 'ad_widget_'.$this->get_id().'_'.$num.'.txt';
234
  }
235
 
236
+ function get_alt_file_name($num){
237
+ return 'ad_widget_'.$this->get_id().'_alt_'.$num.'.txt';
238
  }
239
 
240
  function get_id(){
241
+ //return $widget_id;
242
+ $field = $this->get_field_id('advert_1');
243
  preg_match('/-(\d+)-/', $field, $matches);
244
  return $matches[1];
245
  }
ad-injection.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Ad Injection
4
  Plugin URI: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
5
  Description: Injects any advert (e.g. AdSense) into your WordPress posts or widget area. Restrict who sees the ads by post length, age, referrer or IP. Cache compatible.
6
- Version: 0.9.5.2
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
@@ -16,6 +16,9 @@ License: GPLv2
16
  //
17
  define('ADINJ_NO_CONFIG_FILE', 1);
18
 
 
 
 
19
  // Files
20
  define('ADINJ_PATH', WP_PLUGIN_DIR.'/ad-injection');
21
  define('ADINJ_CONFIG_FILE', WP_CONTENT_DIR . '/ad-injection-config.php'); // same directory as WP Super Cache config file
@@ -117,17 +120,147 @@ function adinj_addsevjs_hook(){
117
  wp_enqueue_script('adinj_sev', WP_PLUGIN_URL.'/ad-injection/adinj-sev.js', NULL, NULL, true);
118
  }
119
 
120
- function adinj_get_mfunc_code($adfile, $options = array()){
121
- $options = adinj_formatting_options($adfile, "string", $options);
122
- return "\n
123
- <!--mfunc adshow_display_ad_file_v2('$adfile', NULL, array($options)) -->
124
- <?php adshow_display_ad_file_v2('$adfile', NULL, array($options)); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  <!--/mfunc-->
126
- ";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  }
128
 
129
- // adname could either be the name of the adfile or the database row
130
- function adinj_formatting_options($adname, $output_type="string", $options = array()){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  $ops = adinj_options();
132
  $align = "";
133
  $clear = "";
@@ -135,22 +268,22 @@ function adinj_formatting_options($adname, $output_type="string", $options = arr
135
  $margin_bottom = "";
136
  $padding_top = "";
137
  $padding_bottom = "";
138
- if (preg_match("/random_[\d+]/i", $adname)){
 
139
  $align = $ops['rnd_align'];
140
  $clear = $ops['rnd_clear'];
141
  $margin_top = $ops['rnd_margin_top'];
142
  $margin_bottom = $ops['rnd_margin_bottom'];
143
- } else if (preg_match("/top_[\d+]/i", $adname)){
144
- $align = $ops['top_align'];
145
- $clear = $ops['top_clear'];
146
- $margin_top = $ops['top_margin_top'];
147
- $margin_bottom = $ops['top_margin_bottom'];
148
- } else if (preg_match("/bottom_[\d+]/i", $adname)){
149
- $align = $ops['bottom_align'];
150
- $clear = $ops['bottom_clear'];
151
- $margin_top = $ops['bottom_margin_top'];
152
- $margin_bottom = $ops['bottom_margin_bottom'];
153
- } else if (preg_match("/widget_[\d+]/i", $adname)){
154
  $align = $options['align'];
155
  $clear = $options['clear'];
156
  $margin_top = $options['margin_top'];
@@ -203,19 +336,26 @@ function adinj_ad_code_include(){
203
  return adinj_ad_code_eval($ad);
204
  }
205
 
 
206
  function adinj_add_tags($ad, $prefix, $func=NULL){
207
  $ops = adinj_options();
208
  if (!adinj_disabled($ops[$prefix . 'align']) ||
209
  !adinj_disabled($ops[$prefix . 'clear']) ||
210
  !adinj_disabled($ops[$prefix . 'margin_top']) ||
211
- !adinj_disabled($ops[$prefix . 'margin_bottom'])) {
 
 
212
  $clear = "";
213
  $top = "";
214
  $bottom = "";
 
 
215
  if (!adinj_disabled($ops[$prefix . 'clear'])) $clear="clear:" . $ops[$prefix . 'clear'] . ";";
216
  if (!adinj_disabled($ops[$prefix . 'margin_top'])) $top="margin-top:" . $ops[$prefix . 'margin_top'] . "px;";
217
  if (!adinj_disabled($ops[$prefix . 'margin_bottom'])) $bottom="margin-bottom:" . $ops[$prefix . 'margin_bottom'] . "px;";
218
- $cssrules = $clear . $top . $bottom;
 
 
219
 
220
  if ($ops[$prefix . 'align'] == 'left'){
221
  $div = "<div style='float:left;" . $cssrules . "'>ADCODE</div><br clear='all' />";
@@ -243,46 +383,6 @@ function adinj_add_tags($ad, $prefix, $func=NULL){
243
  return $ad;
244
  }
245
 
246
- function adinj_ad_code_random(){
247
- $ops = adinj_options();
248
- $ad = $ops['ad_code_random_1'];
249
- if (empty($ad)) return false;
250
- if ($ops['ad_insertion_mode'] == 'mfunc'){
251
- $ad = adinj_get_mfunc_code(ADINJ_AD_RANDOM_FILE);
252
- } else {
253
- $ad = adshow_add_formatting($ad, adinj_formatting_options('ad_code_random_1', "array"));
254
- }
255
- return adinj_ad_code_eval($ad);
256
- }
257
-
258
- function adinj_ad_code_top(){
259
- $ops = adinj_options();
260
- $ad = $ops['ad_code_top_1'];
261
- if (empty($ad)) return "<!--ADINJ DEBUG: no top ad defined. Either define it or turn the ad off-->";
262
- if ($ops['ad_insertion_mode'] == 'mfunc'){
263
- $ad = adinj_get_mfunc_code(ADINJ_AD_TOP_FILE);
264
- } else {
265
- $ad = adshow_add_formatting($ad, adinj_formatting_options('ad_code_top_1', "array"));
266
- }
267
- global $adinj_total_all_ads_used;
268
- ++$adinj_total_all_ads_used;
269
- return adinj_ad_code_eval($ad);
270
- }
271
-
272
- function adinj_ad_code_bottom(){
273
- $ops = adinj_options();
274
- $ad = $ops['ad_code_bottom_1'];
275
- if (empty($ad)) return "<!--ADINJ DEBUG: no bottom ad defined. Either define it or turn the ad off-->";
276
- if ($ops['ad_insertion_mode'] == 'mfunc'){
277
- $ad = adinj_get_mfunc_code(ADINJ_AD_BOTTOM_FILE);
278
- } else {
279
- $ad = adshow_add_formatting($ad, adinj_formatting_options('ad_code_bottom_1', "array"));
280
- }
281
- global $adinj_total_all_ads_used;
282
- ++$adinj_total_all_ads_used;
283
- return adinj_ad_code_eval($ad);
284
- }
285
-
286
  function read_ad_from_file($ad_path){
287
  $contents = "";
288
  if (file_exists($ad_path)){
@@ -325,6 +425,7 @@ function adinj($content, $message){
325
  global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
326
  $path = ADINJ_AD_PATH;
327
  $ops = adinj_options();
 
328
  $mode = $ops['ad_insertion_mode'];
329
  return $content."
330
  <!--
@@ -333,6 +434,7 @@ $message
333
  content length=".strlen($content)."
334
  \$adinj_total_rand_ads_used=$adinj_total_rand_ads_used
335
  \$adinj_total_all_ads_used=$adinj_total_all_ads_used
 
336
  injection mode=$mode
337
  ADINJ_AD_PATH=$path
338
  //-->\n";
@@ -387,13 +489,16 @@ function adinj_allowed_in_category($scope){
387
 
388
  $cat_mode = $ops[$scope.'_category_condition_mode'];
389
  global $post;
390
- foreach(get_the_category($post->ID) as $allcats) {
391
- $postcat = $allcats->category_nicename;
392
- if (in_array($postcat, $cat_array)){
393
- if ($cat_mode == ADINJ_ONLY_SHOW_IN){
394
- return true;
395
- } else if ($cat_mode == ADINJ_NEVER_SHOW_IN){
396
- return false;
 
 
 
397
  }
398
  }
399
  }
@@ -414,13 +519,16 @@ function adinj_allowed_in_tag($scope){
414
 
415
  $tag_mode = $ops[$scope.'_tag_condition_mode'];
416
  global $post;
417
- foreach(get_the_tags($post->ID) as $alltags) {
418
- $posttag = $alltags->slug;
419
- if (in_array($posttag, $tag_array)){
420
- if ($tag_mode == ADINJ_ONLY_SHOW_IN){
421
- return true;
422
- } else if ($tag_mode == ADINJ_NEVER_SHOW_IN){
423
- return false;
 
 
 
424
  }
425
  }
426
  }
@@ -435,12 +543,15 @@ function adinj_allowed_in_tag($scope){
435
 
436
  function adinj_inject_hook($content){
437
  global $adinj_total_rand_ads_used;
 
 
 
 
438
  if(is_page() || is_single()){
439
  // TODO hack for no random ads bug
440
  $adinj_total_rand_ads_used = 0;
441
  }
442
- if (is_feed()) return $content;
443
-
444
  $reason = adinj_ads_completely_disabled_from_page($content);
445
  if ($reason !== false){
446
  return adinj($content, $reason);
@@ -543,9 +654,17 @@ function adinj_inject_hook($content){
543
 
544
  $inj_positions = array();
545
 
546
- if (adinj_ticked('first_paragraph_ad')){
547
- $inj_positions[] = array_shift($potential_inj_positions);
548
- --$num_rand_ads_to_insert;
 
 
 
 
 
 
 
 
549
  }
550
 
551
  // Pick the correct number of random injection points
@@ -595,6 +714,19 @@ function adinj_inject_hook($content){
595
  return adinj($content_adfree_header.$content.$content_adfree_footer, "Ads injected: " . $debug);
596
  }
597
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  function adinj_split_by_tag($content, $tag, &$debugtags){
599
  $ret = array();
600
  if (strpos($content, $tag) !== false){
@@ -656,15 +788,41 @@ function adinj_do_rule_if($rule_value, $condition, $content_length){
656
  }
657
 
658
  function adinj_disabled($value){
659
- return $value === ADINJ_RULE_DISABLED || $value === ADINJ_DISABLED || $value === '';
660
  }
661
 
662
  function adinj_ticked($option){
663
  $ops = adinj_options();
664
- if (!empty($ops[$option])) return 'checked="checked"';
665
  return false;
666
  }
667
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
668
  // Widget support
669
  require_once('ad-injection-widget.php');
670
  add_action('widgets_init', 'adinj_widgets_init');
3
  Plugin Name: Ad Injection
4
  Plugin URI: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
5
  Description: Injects any advert (e.g. AdSense) into your WordPress posts or widget area. Restrict who sees the ads by post length, age, referrer or IP. Cache compatible.
6
+ Version: 0.9.6
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
16
  //
17
  define('ADINJ_NO_CONFIG_FILE', 1);
18
 
19
+ //
20
+ define('ADINJ_DB_VERSION', 2);
21
+
22
  // Files
23
  define('ADINJ_PATH', WP_PLUGIN_DIR.'/ad-injection');
24
  define('ADINJ_CONFIG_FILE', WP_CONTENT_DIR . '/ad-injection-config.php'); // same directory as WP Super Cache config file
120
  wp_enqueue_script('adinj_sev', WP_PLUGIN_URL.'/ad-injection/adinj-sev.js', NULL, NULL, true);
121
  }
122
 
123
+ function adinj_get_ad_code($adtype, $ads_db){
124
+ $ops = adinj_options();
125
+ $ads_live = NULL;
126
+ $ads_split = NULL;
127
+ $alt_live = NULL;
128
+ $alt_split = NULL;
129
+ if ($ops['ad_insertion_mode'] == 'mfunc'){
130
+ adinj_live_ads_array($adtype, $ads_db, $ads_live, $ads_split, 'string');
131
+ if (adinj_db_version($ads_db) >= 2){
132
+ adinj_live_ads_array($adtype.'_alt', $ads_db, $alt_live, $alt_split, 'string');
133
+ }
134
+ $formatting = adinj_formatting_options($adtype, 'string');
135
+ } else {
136
+ $ads_live = array();
137
+ $ads_split = array();
138
+ $alt_live = array();
139
+ $alt_split = array();
140
+ adinj_live_ads_array($adtype, $ads_db, $ads_live, $ads_split, 'array');
141
+ if (adinj_db_version($ads_db) >= 2){
142
+ adinj_live_ads_array($adtype.'_alt', $ads_db, $alt_live, $alt_split, 'array');
143
+ }
144
+ $formatting = adinj_formatting_options($adtype, 'array');
145
+ }
146
+ if (empty($ads_live) && empty($alt_live)) return "<!--ADINJ DEBUG: ads_live and alt_live are empty-->";
147
+
148
+ if ($ops['ad_insertion_mode'] == 'mfunc'){
149
+ return adinj_ad_code_eval("\n
150
+ <!--mfunc adshow_display_ad_file_v2(array($ads_live), array($ads_split), array($formatting), array($alt_live), array($alt_split)) -->
151
+ <?php adshow_display_ad_file_v2(array($ads_live), array($ads_split), array($formatting), array($alt_live), array($alt_split)); ?>
152
  <!--/mfunc-->
153
+ ");
154
+ }
155
+
156
+ // else dynamic ad
157
+ if ($ops['ad_insertion_mode'] == 'direct_dynamic' && adshow_show_adverts() !== true){
158
+ $adname = adshow_pick_value($alt_live, $alt_split);
159
+ } else {
160
+ $adname = adshow_pick_value($ads_live, $ads_split);
161
+ }
162
+
163
+ $ad = adshow_add_formatting($ads_db[$adname], $formatting);
164
+ return adinj_ad_code_eval($ad);
165
+ }
166
+
167
+ function adinj_ad_code_random(){
168
+ return adinj_get_ad_code('random', adinj_options());
169
+ }
170
+
171
+ function adinj_ad_code_top(){
172
+ $ad = adinj_get_ad_code('top', adinj_options());
173
+ global $adinj_total_all_ads_used;
174
+ ++$adinj_total_all_ads_used;
175
+ return $ad;
176
  }
177
 
178
+ function adinj_ad_code_bottom(){
179
+ $ad = adinj_get_ad_code('bottom', adinj_options());
180
+ global $adinj_total_all_ads_used;
181
+ ++$adinj_total_all_ads_used;
182
+ return $ad;
183
+ }
184
+
185
+ /**
186
+ Old:
187
+ ad_code_random_1 <-> ad_random_1.txt
188
+
189
+ New:
190
+ ad_code_random_1:ad_code_random_1_split <-> ad_random_1.txt
191
+ ad_code_random_alt_1:ad_code_random_alt_1_split <-> ad_random-alt_1.txt
192
+ */
193
+ function adinj_live_ads_array($type, $ads_option, &$ads, &$split, $output_type="string"){
194
+ $op_stem = "";
195
+ $file_stem = "";
196
+
197
+ if ($type == 'random' || $type == 'top' || $type == 'bottom' ||
198
+ $type == 'random_alt' || $type == 'top_alt' || $type == 'bottom_alt'){
199
+ $op_stem = 'ad_code_'.$type.'_';
200
+ $file_stem = 'ad_'.$type.'_';
201
+ } else if (preg_match("/widget_[\d+]/i", $type)){
202
+ if (strpos($type, '_alt') === false){
203
+ $op_stem = 'advert_';
204
+ $file_stem = 'ad_'.$type.'_';
205
+ } else {
206
+ $op_stem = 'advert_alt_';
207
+ $file_stem = 'ad_'.$type.'_';
208
+ }
209
+ }
210
+
211
+ if (adinj_db_version($ads_option) == 1){
212
+ // old DB support (no ad rotation support) - TODO delete later
213
+ if ($type == 'random'){
214
+ if ($output_type == "string"){
215
+ $ads = "'ad_random_1.txt'";
216
+ } else {
217
+ $ads[] = 'ad_code_random_1';
218
+ }
219
+ } else if ($type == 'top'){
220
+ if ($output_type == "string"){
221
+ $ads = "'ad_top_1.txt'";
222
+ } else {
223
+ $ads[] = 'ad_code_top_1';
224
+ }
225
+ } else if ($type == 'bottom'){
226
+ if ($output_type == "string"){
227
+ $ads = "'ad_bottom_1.txt'";
228
+ } else {
229
+ $ads[] = 'ad_code_bottom_1';
230
+ }
231
+ } else if (preg_match("/widget_[\d+]/i", $type)){
232
+ if ($output_type == "string"){
233
+ $ads = "'ad_".$type.".txt'";
234
+ } else {
235
+ $ads[] = 'advert';
236
+ }
237
+ }
238
+ return;
239
+ }
240
+
241
+ // DB with support for ad rotation
242
+ for ($i=1; $i<=10; ++$i){
243
+ $ad_name = $op_stem.$i;
244
+ if (!array_key_exists($ad_name.'_split', $ads_option)) return;
245
+
246
+ $split_val = $ads_option[$ad_name.'_split'];
247
+
248
+ if (!empty($ads_option[$ad_name]) && is_numeric($split_val) && $split_val > 0){
249
+ //echo "<br />$ad_name $i size:".sizeof($ads_option[$ad_name]);
250
+ if ($output_type == "string"){
251
+ if (!empty($ads)) $ads .= ",";
252
+ $ads .= "'".$file_stem."$i.txt'";
253
+ if (!empty($split)) $split .= ",";
254
+ $split .= $split_val;
255
+ } else {
256
+ $ads[] = $ad_name;
257
+ $split[] = $split_val;
258
+ }
259
+ }
260
+ }
261
+ }
262
+
263
+ function adinj_formatting_options($adtype, $output_type="string", $options = array()){
264
  $ops = adinj_options();
265
  $align = "";
266
  $clear = "";
268
  $margin_bottom = "";
269
  $padding_top = "";
270
  $padding_bottom = "";
271
+
272
+ if ($adtype == 'random'){
273
  $align = $ops['rnd_align'];
274
  $clear = $ops['rnd_clear'];
275
  $margin_top = $ops['rnd_margin_top'];
276
  $margin_bottom = $ops['rnd_margin_bottom'];
277
+ $padding_top = $options['rnd_padding_top'];
278
+ $padding_bottom = $options['rnd_padding_bottom'];
279
+ } else if ($adtype == 'top' || $adtype == 'bottom'){
280
+ $align = $ops[$adtype.'_align'];
281
+ $clear = $ops[$adtype.'_clear'];
282
+ $margin_top = $ops[$adtype.'_margin_top'];
283
+ $margin_bottom = $ops[$adtype.'_margin_bottom'];
284
+ $padding_top = $options[$adtype.'_padding_top'];
285
+ $padding_bottom = $options[$adtype.'_padding_bottom'];
286
+ } else if ($adtype == 'widget'){
 
287
  $align = $options['align'];
288
  $clear = $options['clear'];
289
  $margin_top = $options['margin_top'];
336
  return adinj_ad_code_eval($ad);
337
  }
338
 
339
+ //TODO delete this
340
  function adinj_add_tags($ad, $prefix, $func=NULL){
341
  $ops = adinj_options();
342
  if (!adinj_disabled($ops[$prefix . 'align']) ||
343
  !adinj_disabled($ops[$prefix . 'clear']) ||
344
  !adinj_disabled($ops[$prefix . 'margin_top']) ||
345
+ !adinj_disabled($ops[$prefix . 'margin_bottom']) ||
346
+ !adinj_disabled($ops[$prefix . 'padding_top']) ||
347
+ !adinj_disabled($ops[$prefix . 'padding_bottom'])) {
348
  $clear = "";
349
  $top = "";
350
  $bottom = "";
351
+ $ptop = "";
352
+ $pbottom = "";
353
  if (!adinj_disabled($ops[$prefix . 'clear'])) $clear="clear:" . $ops[$prefix . 'clear'] . ";";
354
  if (!adinj_disabled($ops[$prefix . 'margin_top'])) $top="margin-top:" . $ops[$prefix . 'margin_top'] . "px;";
355
  if (!adinj_disabled($ops[$prefix . 'margin_bottom'])) $bottom="margin-bottom:" . $ops[$prefix . 'margin_bottom'] . "px;";
356
+ if (!adinj_disabled($ops[$prefix . 'padding_top'])) $ptop="padding-top:" . $ops[$prefix . 'padding_top'] . "px;";
357
+ if (!adinj_disabled($ops[$prefix . 'padding_bottom'])) $pbottom="padding-bottom:" . $ops[$prefix . 'padding_bottom'] . "px;";
358
+ $cssrules = $clear . $top . $bottom . $ptop . $pbottom;
359
 
360
  if ($ops[$prefix . 'align'] == 'left'){
361
  $div = "<div style='float:left;" . $cssrules . "'>ADCODE</div><br clear='all' />";
383
  return $ad;
384
  }
385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
  function read_ad_from_file($ad_path){
387
  $contents = "";
388
  if (file_exists($ad_path)){
425
  global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
426
  $path = ADINJ_AD_PATH;
427
  $ops = adinj_options();
428
+ $para = adinj_paragraph_to_start_ads();
429
  $mode = $ops['ad_insertion_mode'];
430
  return $content."
431
  <!--
434
  content length=".strlen($content)."
435
  \$adinj_total_rand_ads_used=$adinj_total_rand_ads_used
436
  \$adinj_total_all_ads_used=$adinj_total_all_ads_used
437
+ paragraphtostartads=$para (fyi: -1 is disabled)
438
  injection mode=$mode
439
  ADINJ_AD_PATH=$path
440
  //-->\n";
489
 
490
  $cat_mode = $ops[$scope.'_category_condition_mode'];
491
  global $post;
492
+ $postcategories = get_the_category($post->ID);
493
+ if (is_array($postcategories)){
494
+ foreach($postcategories as $cat) {
495
+ $postcat = $cat->category_nicename;
496
+ if (in_array($postcat, $cat_array)){
497
+ if ($cat_mode == ADINJ_ONLY_SHOW_IN){
498
+ return true;
499
+ } else if ($cat_mode == ADINJ_NEVER_SHOW_IN){
500
+ return false;
501
+ }
502
  }
503
  }
504
  }
519
 
520
  $tag_mode = $ops[$scope.'_tag_condition_mode'];
521
  global $post;
522
+ $posttags = get_the_tags($post->ID);
523
+ if (is_array($posttags)){
524
+ foreach($posttags as $tag) {
525
+ $posttag = $tag->slug;
526
+ if (in_array($posttag, $tag_array)){
527
+ if ($tag_mode == ADINJ_ONLY_SHOW_IN){
528
+ return true;
529
+ } else if ($tag_mode == ADINJ_NEVER_SHOW_IN){
530
+ return false;
531
+ }
532
  }
533
  }
534
  }
543
 
544
  function adinj_inject_hook($content){
545
  global $adinj_total_rand_ads_used;
546
+ if (is_feed()) return $content; // TODO feed specific ads
547
+
548
+ adinj_upgrade_db_if_necessary();
549
+
550
  if(is_page() || is_single()){
551
  // TODO hack for no random ads bug
552
  $adinj_total_rand_ads_used = 0;
553
  }
554
+
 
555
  $reason = adinj_ads_completely_disabled_from_page($content);
556
  if ($reason !== false){
557
  return adinj($content, $reason);
654
 
655
  $inj_positions = array();
656
 
657
+ $startparagraph = adinj_paragraph_to_start_ads();
658
+ if ($startparagraph > 0){
659
+ $pos = NULL;
660
+ for ($i=0; $i<$startparagraph; ++$i){
661
+ // discard positions until we get to the starting paragraph
662
+ $pos = array_shift($potential_inj_positions);
663
+ }
664
+ if ($pos != NULL){
665
+ $inj_positions[] = $pos;
666
+ --$num_rand_ads_to_insert;
667
+ }
668
  }
669
 
670
  // Pick the correct number of random injection points
714
  return adinj($content_adfree_header.$content.$content_adfree_footer, "Ads injected: " . $debug);
715
  }
716
 
717
+ function adinj_paragraph_to_start_ads(){
718
+ $ops = adinj_options();
719
+ if (adinj_db_version($ops) == 1){
720
+ if (adinj_ticked('first_paragraph_ad')) return 1;
721
+ return -1;
722
+ }
723
+ if (adinj_disabled('start_from_paragraph')){
724
+ return -1;
725
+ } else {
726
+ return $ops['start_from_paragraph'];
727
+ }
728
+ }
729
+
730
  function adinj_split_by_tag($content, $tag, &$debugtags){
731
  $ret = array();
732
  if (strpos($content, $tag) !== false){
788
  }
789
 
790
  function adinj_disabled($value){
791
+ return $value == ADINJ_RULE_DISABLED || $value == ADINJ_DISABLED || $value == '';
792
  }
793
 
794
  function adinj_ticked($option){
795
  $ops = adinj_options();
796
+ if (!empty($ops[$option]) && $ops[$option] != 'off') return 'checked="checked"';
797
  return false;
798
  }
799
 
800
+ function adinj_upgrade_db_if_necessary(){
801
+ $stored_options = adinj_options();
802
+ if(empty($stored_options)){
803
+ // 1st Install.
804
+ adinj_install_db();
805
+ return;
806
+ }
807
+
808
+ $stored_dbversion = adinj_db_version($stored_options);
809
+
810
+ if (ADINJ_DB_VERSION != $stored_dbversion){
811
+ require_once(ADINJ_PATH . '/ad-injection-admin.php');
812
+ adinj_upgrade_db();
813
+ }
814
+ }
815
+
816
+ // Main options table and widgets could have different db version at the same
817
+ // time depending on when the settings were last saved
818
+ function adinj_db_version($ops){
819
+ if (!array_key_exists('db_version', $ops)){
820
+ return 1;
821
+ } else {
822
+ return $ops['db_version'];
823
+ }
824
+ }
825
+
826
  // Widget support
827
  require_once('ad-injection-widget.php');
828
  add_action('widgets_init', 'adinj_widgets_init');
adshow.php CHANGED
@@ -27,6 +27,7 @@ function adshow_functions_exist(){
27
  if (!adshow_functions_exist_impl('adinj_config_add_tags_bottom')){ return false; }
28
  if (!adshow_functions_exist_impl('adinj_config_sevisitors_only')){ return false; }
29
  if (!adshow_functions_exist_impl('adinj_config_search_engine_referrers')){ return false; }
 
30
  if (!adshow_functions_exist_impl('adinj_config_blocked_ips')){ return false; }
31
  if (!adshow_functions_exist_impl('adinj_config_debug_mode')){ return false; }
32
  }
@@ -34,7 +35,7 @@ function adshow_functions_exist(){
34
  }
35
  function adshow_functions_exist_impl($function){
36
  if (!function_exists($function)){
37
- echo "<!--ADINJ DEBUG:".__FILE__." Error: $function does not exist. Might be because config file is missing. Re-save settings to fix. -->";
38
  return false;
39
  }
40
  return true;
@@ -51,6 +52,10 @@ function adinj_config_search_engine_referrers() {
51
  return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
52
  }
53
 
 
 
 
 
54
  function adinj_config_blocked_ips() {
55
  $list = adinj_quote_list('blocked_ips');
56
  return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
@@ -104,7 +109,7 @@ function adshow_display_ad_full_path($ad_path){
104
  }
105
  if (file_exists($ad_path)){
106
  $ad = file_get_contents($ad_path);
107
- if ($ad === false) echo "\n<!--ADINJ DEBUG: could not read ad from file: $ad_path-->";
108
  if (stripos($ad_path, 'random_1.txt') > 0){ // TODO something better than this
109
  echo adinj_config_add_tags_rnd(adshow_eval_php($ad));
110
  } else if (stripos($ad_path, 'top_1.txt') > 0){
@@ -127,8 +132,8 @@ function adshow_display_ad_file_v2($adfiles, $adfiles_frequency = array(), $opti
127
  if (!adshow_functions_exist()){ return false; }
128
  if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: adshow_display_ad_file() quantity=".sizeof($adfiles)."-->\n"; }
129
 
130
- if (empty($adfiles)){
131
- echo "<!--ADINJ DEBUG: Error: adfiles is empty-->\n";
132
  return false;
133
  }
134
 
@@ -142,6 +147,7 @@ function adshow_display_ad_file_v2($adfiles, $adfiles_frequency = array(), $opti
142
  if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: alt content file defined:$alt_content_file-->\n"; }
143
  $adfile = $alt_content_file;
144
  } else {
 
145
  return false;
146
  }
147
  }
@@ -150,7 +156,7 @@ function adshow_display_ad_file_v2($adfiles, $adfiles_frequency = array(), $opti
150
  $adfile = adshow_pick_value($adfiles, $adfiles_frequency);
151
  }
152
 
153
- if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: adshow_display_ad_file($adfile)-->"; }
154
 
155
  $plugin_dir = dirname(__FILE__);
156
 
@@ -182,7 +188,7 @@ function adshow_pick_value($values, $frequency){
182
  // each value has its own probability of being picked
183
  $count = sizeof($values);
184
  if ($count != sizeof($frequency)){
185
- echo "<!--ADINJ DEBUG: size of arrays don't match ".$count."!=".sizeof($frequency)."-->";
186
  return NULL;
187
  }
188
  $total = array_sum($frequency);
@@ -192,7 +198,7 @@ function adshow_pick_value($values, $frequency){
192
  $cumulative += $frequency[$i];
193
  if ($rand <= $cumulative){
194
  $val = $values[$i];
195
- if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: picked value at position $i:$val-->"; }
196
  break;
197
  }
198
  }
@@ -206,12 +212,12 @@ function adshow_display_ad_full_path_v2($ad_path, $ops = array()){
206
  if (!adshow_functions_exist()){ return false; }
207
 
208
  if (!file_exists($ad_path)){
209
- echo "\n<!--ADINJ DEBUG: ad file does not exist: $ad_path.\nIf you have just upgraded you may need to re-save your ads to regenerate the ad files.\n-->";
210
  return false;
211
  }
212
 
213
  $ad = file_get_contents($ad_path);
214
- if ($ad === false) echo "\n<!--ADINJ DEBUG: could not read ad from file: $ad_path-->";
215
  $ad = adshow_eval_php($ad);
216
  echo adshow_add_formatting($ad, $ops);
217
  }
27
  if (!adshow_functions_exist_impl('adinj_config_add_tags_bottom')){ return false; }
28
  if (!adshow_functions_exist_impl('adinj_config_sevisitors_only')){ return false; }
29
  if (!adshow_functions_exist_impl('adinj_config_search_engine_referrers')){ return false; }
30
+ //if (!adshow_functions_exist_impl('adinj_config_block_ips')){ return false; } // TODO enable
31
  if (!adshow_functions_exist_impl('adinj_config_blocked_ips')){ return false; }
32
  if (!adshow_functions_exist_impl('adinj_config_debug_mode')){ return false; }
33
  }
35
  }
36
  function adshow_functions_exist_impl($function){
37
  if (!function_exists($function)){
38
+ echo "<!--ADINJ DEBUG:".__FILE__." Error: $function does not exist. Might be because config file is missing or out of date. Re-save settings to fix. -->";
39
  return false;
40
  }
41
  return true;
52
  return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
53
  }
54
 
55
+ function adinj_config_block_ips() { // TODO use this
56
+ return adinj_ticked('block_ips');
57
+ }
58
+
59
  function adinj_config_blocked_ips() {
60
  $list = adinj_quote_list('blocked_ips');
61
  return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
109
  }
110
  if (file_exists($ad_path)){
111
  $ad = file_get_contents($ad_path);
112
+ if ($ad === false) echo "<!--ADINJ DEBUG: could not read ad from file: $ad_path-->\n";
113
  if (stripos($ad_path, 'random_1.txt') > 0){ // TODO something better than this
114
  echo adinj_config_add_tags_rnd(adshow_eval_php($ad));
115
  } else if (stripos($ad_path, 'top_1.txt') > 0){
132
  if (!adshow_functions_exist()){ return false; }
133
  if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: adshow_display_ad_file() quantity=".sizeof($adfiles)."-->\n"; }
134
 
135
+ if (empty($adfiles) && empty($altfiles)){
136
+ echo "<!--ADINJ DEBUG: Error: adfiles and altfiles are empty-->\n";
137
  return false;
138
  }
139
 
147
  if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: alt content file defined:$alt_content_file-->\n"; }
148
  $adfile = $alt_content_file;
149
  } else {
150
+ if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: no alt content file defined-->\n"; }
151
  return false;
152
  }
153
  }
156
  $adfile = adshow_pick_value($adfiles, $adfiles_frequency);
157
  }
158
 
159
+ if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: adshow_display_ad_file($adfile)-->\n"; }
160
 
161
  $plugin_dir = dirname(__FILE__);
162
 
188
  // each value has its own probability of being picked
189
  $count = sizeof($values);
190
  if ($count != sizeof($frequency)){
191
+ echo "<!--ADINJ DEBUG: size of arrays don't match ".$count."!=".sizeof($frequency)."-->\n";
192
  return NULL;
193
  }
194
  $total = array_sum($frequency);
198
  $cumulative += $frequency[$i];
199
  if ($rand <= $cumulative){
200
  $val = $values[$i];
201
+ if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: picked value at position $i: $val-->\n"; }
202
  break;
203
  }
204
  }
212
  if (!adshow_functions_exist()){ return false; }
213
 
214
  if (!file_exists($ad_path)){
215
+ echo "<!--ADINJ DEBUG: ad file does not exist: $ad_path.\nIf you have just upgraded you may need to re-save your ads to regenerate the ad files.\n-->\n";
216
  return false;
217
  }
218
 
219
  $ad = file_get_contents($ad_path);
220
+ if ($ad === false) echo "<!--ADINJ DEBUG: could not read ad from file: $ad_path-->\n";
221
  $ad = adshow_eval_php($ad);
222
  echo adshow_add_formatting($ad, $ops);
223
  }
readme.txt CHANGED
@@ -1,25 +1,35 @@
1
  === Ad Injection ===
2
  Contributors: reviewmylife
3
  Donate link: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
4
- Tags: ad injection, adsense, advert injection, advert, ad, injection, advertising, affiliate, inject, injection, insert, widget, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, Adsense Injection, free, blog
5
  Requires at least: 2.8.6
6
  Tested up to: 3.1
7
- Stable tag: 0.9.5.2
8
 
9
  Injects any adverts (e.g. AdSense) into the WordPress posts or widget area. Restrict who sees ads by post length/age/referrer or IP. Cache compatible.
10
 
11
  == Description ==
12
 
13
- It injects any kind of advert (e.g. Google AdSense, Amazon Associates, ClickBank, TradeDoubler, etc) into the existing content of your WordPress posts and pages. You can control the number of adverts based on the post length, and it can restrict who sees adverts by post age, visitor referrer and IP address. And the dynamic restrictions (by IP and referrer) work with WP Super Cache!
 
 
 
 
 
 
14
 
15
  = Automatic advert injection =
16
 
17
- The ads can be injected into existing posts without requiring any modification of the post. The injection can be done randomly between paragraphs, and there is an option to always inject the first advert after the first paragraph. Randomly positioning the adverts helps to reduce 'ad blindness'. Two separate adverts can be defined for the top and bottom of the content. Widget adverts can be defined as well.
18
 
19
  = Widget support =
20
 
21
  Widgets can be added to your sidebars, or other widget areas on any pages. The same ad display restrictions that you setup for your other ads will also apply to the widgets.
22
 
 
 
 
 
23
  = Ad quantity by post length =
24
 
25
  The number of adverts can be set based on the length of the post. It is a good idea for longer posts to have more adverts than shorter posts for example. Adverts can also be turned off for very short posts.
@@ -36,13 +46,17 @@ Adverts can be restricted to posts that are more than a defined numbers of days
36
 
37
  IP addresses of people who shouldn't see your ads can be defined. These could be the IP addresses of your friends, family, or even yourself.
38
 
 
 
 
 
39
  = Not tied to any ad provider =
40
 
41
  The advert code can be copied and pasted directly from your ad provider (Google AdSense, adBrite, ClickBank, etc) which will help you to comply with any terms of service (TOS) that state their ad code may not be modified.
42
 
43
  = Flexible ad positioning =
44
 
45
- Easy positioning options are provided for left, right, center, float left, and float right (or a random variant of these). Extra spacing can be set above and below the ad using the CSS margin and padding boxes. Or if that isn't flexible enough, you can write your own positioning code using HTML and CSS.
46
 
47
  = Works with WP Super Cache =
48
 
@@ -151,10 +165,24 @@ Yes you can do this, there are two ways.
151
  1. In the 'Single posts and pages' setting set the number of injected ads to 0. Then in the 'Home page' settings set the number of ads to whatever you want.
152
  2. Alternatively use the global exclude options at the top to exclude ads from all page types except the home page.
153
 
 
 
 
 
 
 
 
 
154
  = My adverts are overlapping with other page elements (e.g. images) =
155
 
156
  You can try defining the 'clear' display setting so that multiple floated parts of your page do not overlap.
157
 
 
 
 
 
 
 
158
  = What if I am using an incompatible caching plugin? =
159
 
160
  Don't worry - everything will still work except for:
@@ -166,8 +194,28 @@ If you aren't interested in these features then it doesn't matter! Just make sur
166
 
167
  = Are there any known plugin conflicts? =
168
 
 
 
 
 
169
  If you use WP Minify and WP Super Cache in combination with this plugin, you'll need to turn off the HTML minification in WP Minify. This is because HTML minification strips out the mfunc tags that Ad Injection uses. You can leave the CSS and JavaScript minification on if you already use them.
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  = Some technical details =
172
 
173
  * Plugin stores all its settings in a single option (adinj_options).
@@ -232,6 +280,11 @@ If you do get any errors please use the 'Report a bug or give feedback' link on
232
 
233
  == Changelog ==
234
 
 
 
 
 
 
235
  = 0.9.5.2 =
236
  New CSS padding options for widgets. Fixes for CSS margin options.
237
  Update docs for due to new mfunc support in WP Super Cache. If you are using mfunc mode and upgrade to the latest version of WP Super Cache (0.9.9.8) you can now use the faster mod_rewrite mode or PHP mode instead of legacy mode.
@@ -328,80 +381,13 @@ Fix 'Something badly wrong in num_rand_ads_to_insert' message that occurs on pag
328
 
329
  == Upgrade Notice ==
330
 
331
- = 0.9.5.2 =
332
- New CSS padding options for widgets. Fixes for CSS margin options.
333
- If you are using WP Super Cache 0.9.9.8 you can now switch to its faster mod_rewrite or PHP modes.
334
 
335
- = 0.9.5.1 =
336
  New CSS padding options for widgets. Fixes for CSS margin options.
337
  If you are using WP Super Cache 0.9.9.8 you can now switch to its faster mod_rewrite or PHP modes.
338
 
339
- = 0.9.5 =
340
- New spacing/alignment options, and misc fixes.
341
-
342
- = 0.9.4.6 =
343
- If you are using mfunc mode or switch to mfunc and have added ad widgets you may need to re-save them to regenerate the ad files.
344
-
345
- = 0.9.4.5 =
346
- If you are using mfunc mode or switch to mfunc and have added ad widgets you may need to re-save them to regenerate the ad files.
347
-
348
- = 0.9.4.4 =
349
- If you are using mfunc mode or switch to mfunc and have added ad widgets you may need to re-save them to regenerate the ad files.
350
-
351
- = 0.9.4.3 =
352
- If you are using mfunc mode and have added ad widgets with a version prior to 0.9.2 please re-save them to regenerate the ad files (fixed for upgrades from 0.9.2).
353
-
354
- = 0.9.4.2 =
355
- If you are using mfunc mode and have added ad widgets with a version prior to 0.9.2 please re-save them to regenerate the ad files (fixed for upgrades from 0.9.2).
356
-
357
- = 0.9.4.1 =
358
- If you are using mfunc mode and have added ad widgets with a version prior to 0.9.2 please re-save them to regenerate the ad files (fixed for upgrades from 0.9.2).
359
-
360
- = 0.9.4 =
361
- If you are using mfunc mode and have added ad widgets with a version prior to 0.9.2 please re-save them to regenerate the ad files (fixed for upgrades from 0.9.2).
362
-
363
- = 0.9.3.4 =
364
- If you are using mfunc mode and have added ad widgets with a version prior to 0.9.2 please re-save them to regenerate the ad files (fixed for upgrades from 0.9.2).
365
-
366
- = 0.9.3.3 =
367
- If you are using mfunc mode and have added ad widgets with a version prior to 0.9.2 please re-save them to regenerate the ad files (fixed for upgrades from 0.9.2).
368
-
369
- = 0.9.3.2 =
370
- If you are using mfunc mode and have added ad widgets with a version prior to 0.9.2 please re-save them to regenerate the ad files (fixed for upgrades from 0.9.2).
371
-
372
- = 0.9.3.1 =
373
- If you are using mfunc mode and have added ad widgets with a version prior to 0.9.2 please re-save them to regenerate the ad files (fixed for upgrades from 0.9.2).
374
-
375
- = 0.9.3 =
376
- If you are using mfunc mode and have added ad widgets please re-save them to regenerate the ad files (fixed from 0.9.2).
377
-
378
- = 0.9.2 =
379
- If you are using mfunc mode and have added ad widgets please re-save them to regenerate the ad files (fixed from 0.9.2).
380
-
381
- = 0.9.1 =
382
- Fix dynamic checking for widgets. Fix potential PHP error message with widgets.
383
-
384
- = 0.9.0 =
385
- Widget support and other fixes.
386
-
387
- = 0.8.9 =
388
- Upgrade to this version by going to the plugins tab and upgrading the individual plugin. If you upgrade from the bulk updator the mfunc config file will be lost and you would have to go to 'Save all settings' to re-generate it. This version attempts to solve the bulk update problem.
389
-
390
- = 0.8.8 =
391
- Try to make sure ads don't appear on archive pages, 404s or search results, in case theme is working in a non-standard way. Reduce dependency on files.
392
-
393
- = 0.8.7 =
394
- More fault tolerant mfunc support.
395
-
396
- = 0.8.6 =
397
- Fix problems relating to over strict chmod usage. And add save message.
398
-
399
- = 0.8.5 =
400
- If you get a 'Something badly wrong in num_rand_ads_to_insert' message install this update.
401
-
402
- = 0.8.4 =
403
- If you have already configured your ad code then this update will delete the ads. Sorry - this update fixes that bug. Before upgrading please save your ads. All other settings will be carried over.
404
-
405
  = 0.8.3 =
406
  First public release.
407
 
1
  === Ad Injection ===
2
  Contributors: reviewmylife
3
  Donate link: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
4
+ Tags: ad injection, adsense, advert injection, advert, ad, injection, advertising, affiliate, inject, injection, insert, widget, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, Adsense Injection, free, blog, ad rotation, A:B testing, split testing
5
  Requires at least: 2.8.6
6
  Tested up to: 3.1
7
+ Stable tag: 0.9.6
8
 
9
  Injects any adverts (e.g. AdSense) into the WordPress posts or widget area. Restrict who sees ads by post length/age/referrer or IP. Cache compatible.
10
 
11
  == Description ==
12
 
13
+ Ad Injection injects any kind of advert (e.g. Google AdSense, Amazon Associates, ClickBank, TradeDoubler, etc) into the existing content of your WordPress posts and pages. You can control the number of adverts based on the post length, and it can restrict who sees adverts by post age, visitor referrer and IP address. Adverts can be configured in the post (random, top, and bottom positions) or in any widget/sidebar area. There's support for A:B split testing / ad rotation. And the dynamic restrictions (by IP and referrer) work with WP Super Cache!
14
+
15
+ **New Features 0.9.6.x**
16
+
17
+ * Ad rotation / A:B split testing support for random, top, bottom and widget/sidebar adverts.
18
+ * Alternate content which can be defined for users who are dynamically blocked (by IP or referrer) from seeing adverts.
19
+ * Choose which paragraph to start the random ads via the UI.
20
 
21
  = Automatic advert injection =
22
 
23
+ The ads can be injected into existing posts without requiring any modification of the post. The injection can be done randomly between paragraphs, and there is an option to always inject the first advert at a specified paragraph (e.g. the first or second). Randomly positioning the adverts helps to reduce 'ad blindness'. Two separate adverts can be defined for the top and bottom of the content. Widget adverts can be defined as well.
24
 
25
  = Widget support =
26
 
27
  Widgets can be added to your sidebars, or other widget areas on any pages. The same ad display restrictions that you setup for your other ads will also apply to the widgets.
28
 
29
+ = Ad rotation / split testing =
30
+
31
+ You can define multiple adverts for the same ad space which are rotated according to the ratios you define. Works with random, top, bottom and sidget/sidebar ads.
32
+
33
  = Ad quantity by post length =
34
 
35
  The number of adverts can be set based on the length of the post. It is a good idea for longer posts to have more adverts than shorter posts for example. Adverts can also be turned off for very short posts.
46
 
47
  IP addresses of people who shouldn't see your ads can be defined. These could be the IP addresses of your friends, family, or even yourself.
48
 
49
+ = Alternate content =
50
+
51
+ This is content that is displayed when ads are blocked for the user. Ads can only be blocked for specific users if you use one of the dynamic modes (mfunc or direct_dynamic). You could use this alternate content to show other content, some kind of layout filler, or even a different type of ad. I've added support for rotation of alternate content as well.
52
+
53
  = Not tied to any ad provider =
54
 
55
  The advert code can be copied and pasted directly from your ad provider (Google AdSense, adBrite, ClickBank, etc) which will help you to comply with any terms of service (TOS) that state their ad code may not be modified.
56
 
57
  = Flexible ad positioning =
58
 
59
+ Easy positioning options are provided for left, right, center, float left, and float right (or a random variant of these). Extra spacing can be set above and below the ad using the CSS margin and padding boxes. Or if that isn't flexible enough, you can write your own positioning code using HTML and CSS. And you can select which paragraph random ads should start from.
60
 
61
  = Works with WP Super Cache =
62
 
165
  1. In the 'Single posts and pages' setting set the number of injected ads to 0. Then in the 'Home page' settings set the number of ads to whatever you want.
166
  2. Alternatively use the global exclude options at the top to exclude ads from all page types except the home page.
167
 
168
+ = How do I stop adverts from appearing on my contacts form page? =
169
+
170
+ To stop ads appearing on the contact page (or any other post/page) you have many of options. Here are three to choose from:
171
+
172
+ 1. Add (copy and paste) <!--NoAds--> into the content of the post/page with the contact form. Just edit the contact page and paste this in - it will be invisible to the reader.
173
+ 2. Add a disable_adverts custom field to the post/page containing the contact form and set the value to 1 (the number one as a single digit).
174
+ 3. Add a tag to the page to mean that it shouldn't have adverts, and then add that tag to the tag filtering condition in the global settings area of the plugin configuration page.
175
+
176
  = My adverts are overlapping with other page elements (e.g. images) =
177
 
178
  You can try defining the 'clear' display setting so that multiple floated parts of your page do not overlap.
179
 
180
+ If you always have a floated image at the top of the page you can set which paragraph the first random advert will start from. If you needed finer control over where the random adverts appear you can use the <!--adstart--> and <!--adend--> tags in the page.
181
+
182
+ = I have configured four Google AdSense ad units but only three are showing. Why? =
183
+
184
+ Google's AdSense TOS only allow allow three ad units, and three link units per page. If you have for example tried to insert four ad units on your page then Google will (probably) disable the forth one automatically. Read Google's AdSense [program policies](https://www.google.com/adsense/support/bin/answer.py?hl=en&answer=48182 "AdSense program policies") for more info.
185
+
186
  = What if I am using an incompatible caching plugin? =
187
 
188
  Don't worry - everything will still work except for:
194
 
195
  = Are there any known plugin conflicts? =
196
 
197
+ **WP Minify**
198
+
199
+ Problem: No ads appear when using mfunc mode.
200
+
201
  If you use WP Minify and WP Super Cache in combination with this plugin, you'll need to turn off the HTML minification in WP Minify. This is because HTML minification strips out the mfunc tags that Ad Injection uses. You can leave the CSS and JavaScript minification on if you already use them.
202
 
203
+ **FeedWordPress**
204
+
205
+ Problem: Random, top and bottom ads don't appear on syndicated posts.
206
+
207
+ By default FeedWordPress prevents the syndicated post contents from being passed to 'the_content' hook which is where the random, top and bottom ads are added. There's an easy fix:
208
+
209
+ From the FeedWordPress settings page go to 'Posts & Links' and then in the 'Formatting' section set 'Formatting filters' to 'Expose syndicated posts to formatting filters'.
210
+
211
+ **W3 Total Cache (and other caching programs)**
212
+
213
+ Problem: Dynamic features don't work.
214
+
215
+ I don't think the dynamic features (restricting ads by IP and referrer) will work with any caching programs other than WP Super Cache and WP Cache. With other caching programs you should use the 'direct_static' mode.
216
+
217
+ It is on my TODO list to try to make Ad Injection work with W3 Total Cache.
218
+
219
  = Some technical details =
220
 
221
  * Plugin stores all its settings in a single option (adinj_options).
280
 
281
  == Changelog ==
282
 
283
+ = 0.9.6 =
284
+ * Ad rotation / A:B split testing support for random, top, bottom and widget adverts.
285
+ * Alternate content which can be defined for users who are dynamically blocked (by IP or referrer) from seeing adverts.
286
+ * Choose which paragraph to start the random ads via the UI.
287
+
288
  = 0.9.5.2 =
289
  New CSS padding options for widgets. Fixes for CSS margin options.
290
  Update docs for due to new mfunc support in WP Super Cache. If you are using mfunc mode and upgrade to the latest version of WP Super Cache (0.9.9.8) you can now use the faster mod_rewrite mode or PHP mode instead of legacy mode.
381
 
382
  == Upgrade Notice ==
383
 
384
+ = 0.9.6 =
385
+ New split testing, ad rotation and alternate content features. If you have any problems with disappearing ads re-save them to make them appear again.
 
386
 
387
+ = 0.9.5.2 =
388
  New CSS padding options for widgets. Fixes for CSS margin options.
389
  If you are using WP Super Cache 0.9.9.8 you can now switch to its faster mod_rewrite or PHP modes.
390
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  = 0.8.3 =
392
  First public release.
393
 
ui-tab-adrotation.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Part of the Ad Injection plugin for WordPress
4
+ http://www.reviewmylife.co.uk/
5
+ */
6
+
7
+ if (!is_admin()) return;
8
+
9
+ function adinj_tab_adrotation(){
10
+ $ops = adinj_options();
11
+
12
+ echo <<<DOCS
13
+ <p><a href="#multiple_random">Random adverts</a> | <a href="#multiple_top">Top adverts</a> | <a href="#multiple_bottom">Bottom adverts</a></p>
14
+
15
+ <p>Ad rotation / split testing and alternate content are advanced features. If you don't understand these features you probably don't need them and can therefore ignore this tab. In summary:</p>
16
+
17
+ <ul>
18
+ <li><b>Ad rotation / split testing:</b> You can define multiple adverts for the same ad space which are rotated according to the ratios you define. The percentage of views that each ad will be shows is displated beneath the ratio text box. For example if you define two ads and set both to have a ratio of '50' they will each be shown (roughly) 50% of the time. The numbers don't have to add up to 100 as the ratio is calculated based on the total. e.g. if you have two advert - one is set with a ratio of '1' and the other '3' the ratios will be 25% and 75%. Please remember this isn't strict ad rotation, it is random selection based on ratios so the ratios will be correct over a large sample of ad views, not a small sample.</li>
19
+ <li><b>Alternate content:</b> This is content that is displayed when ads are blocked for the user. Ads can only be blocked for specific users if you use one of the dynamic modes (mfunc or direct_dynamic). You could use this alternate content to show other content, some kind of layout filler, or even a different type of ad. I've added support for rotation of alternate content as well.</li>
20
+ </ul>
21
+
22
+ DOCS;
23
+
24
+ $total_rand_split = adinj_total_split('ad_code_random_', $ops);
25
+ $total_rand_alt_split = adinj_total_split('ad_code_random_alt_', $ops);
26
+
27
+ $total_top_split = adinj_total_split('ad_code_top_', $ops);
28
+ $total_top_alt_split = adinj_total_split('ad_code_top_alt_', $ops);
29
+
30
+ $total_bottom_split = adinj_total_split('ad_code_bottom_', $ops);
31
+ $total_bottom_alt_split = adinj_total_split('ad_code_bottom_alt_', $ops);
32
+ ?>
33
+
34
+ <style type="text/css">
35
+ .adinjtable td { vertical-align: top; }
36
+ </style>
37
+
38
+ <?php
39
+ adinj_postbox_start(__("Random adverts", 'adinj'), 'multiple_random');
40
+ echo '<table border="0" cellspacing="5" class="adinjtable">';
41
+ for ($i=1; $i<=5; ++$i){
42
+ adinj_add_row_with_text_box('ad_code_random_', $i, 'Ad code', $total_rand_split);
43
+ }
44
+ adinj_add_row_with_text_box('ad_code_random_alt_', 1, 'Alt content', $total_rand_alt_split);
45
+ adinj_add_row_with_text_box('ad_code_random_alt_', 2, 'Alt content', $total_rand_alt_split);
46
+ echo '</table>';
47
+ adinj_postbox_end();
48
+
49
+
50
+ adinj_postbox_start(__("Top adverts", 'adinj'), 'multiple_top');
51
+ echo '<table border="0" cellspacing="5" class="adinjtable">';
52
+ for ($i=1; $i<=5; ++$i){
53
+ adinj_add_row_with_text_box('ad_code_top_', $i, 'Ad code', $total_top_split);
54
+ }
55
+ adinj_add_row_with_text_box('ad_code_top_alt_', 1, 'Alt content', $total_top_alt_split);
56
+ adinj_add_row_with_text_box('ad_code_top_alt_', 2, 'Alt content', $total_top_alt_split);
57
+ echo '</table>';
58
+ adinj_postbox_end();
59
+
60
+
61
+ adinj_postbox_start(__("Bottom adverts", 'adinj'), 'multiple_bottom');
62
+ echo '<table border="0" cellspacing="5" class="adinjtable">';
63
+ for ($i=1; $i<=5; ++$i){
64
+ adinj_add_row_with_text_box('ad_code_bottom_', $i, 'Ad code', $total_bottom_split);
65
+ }
66
+ adinj_add_row_with_text_box('ad_code_bottom_alt_', 1, 'Alt content', $total_bottom_alt_split);
67
+ adinj_add_row_with_text_box('ad_code_bottom_alt_', 2, 'Alt content', $total_bottom_alt_split);
68
+ echo '</table>';
69
+ adinj_postbox_end();
70
+
71
+ }
72
+
73
+ function adinj_add_row_with_text_box($name_stem, $num, $title, $total){
74
+ $ops = adinj_options();
75
+ $name = $name_stem.$num;
76
+ $namesplit = $name.'_split';
77
+ $percent = adinj_percentage_split($name_stem, $num, $ops, $total);
78
+ echo <<<EOT
79
+ <tr><td>
80
+ <a name="$name"></a>
81
+ <span style="font-size:10px;"><b>$title $num</b></span><br />
82
+ <textarea name="$name" rows="8" cols="60">$ops[$name]</textarea>
83
+ </td><td>
84
+ <textarea name="$namesplit" rows="1" cols="7">$ops[$namesplit]</textarea>
85
+ <br />
86
+ $percent
87
+ </td></tr>
88
+ EOT;
89
+ }
90
+
91
+
92
+ ?>
ui-tab-main.php ADDED
@@ -0,0 +1,745 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Part of the Ad Injection plugin for WordPress
4
+ http://www.reviewmylife.co.uk/
5
+ */
6
+
7
+ if (!is_admin()) return;
8
+
9
+ function adinj_tab_main(){
10
+ $ops = adinj_options();
11
+ ?>
12
+ <script type="text/javascript">
13
+ function adinj_addtext(element, value) {
14
+ if (value.length == 0) return;
15
+ separator = ', ';
16
+ if (element.value.length == 0){
17
+ separator = '';
18
+ }
19
+ element.value += (separator + value);
20
+ }
21
+ </script>
22
+
23
+ <p><a href="#random">Random ads</a> | <a href="#topad">Top</a> | <a href="#bottomad">Bottom</a> | <a href="#widgets">Widgets</a> | <a href="#restrictions">Ad insert mode/dynamic restrictions</a> | <a href="#debugging">Debug</a> | <a href="#docs">Quick Start</a> | <a href="#testads">Test ads</a></p>
24
+
25
+
26
+
27
+
28
+ <?php adinj_postbox_start(__("Global settings", 'adinj'), 'global'); ?>
29
+
30
+ <p>These settings apply to all ads (random, top, bottom, and widget). They will override all other settings.</p>
31
+
32
+ <input type="radio" name="ads_enabled" value="on" <?php if ($ops['ads_enabled']=='on') echo 'checked="checked"'; ?> /> <b>On: <?php _e('Ads enabled', 'adinj') ?></b><br />
33
+ <input type="radio" name="ads_enabled" value="off" <?php if ($ops['ads_enabled']=='off' || $ops['ads_enabled']=='') echo 'checked="checked"'; ?> /> <b>Off</b><br />
34
+ <input type="radio" name="ads_enabled" value="test" <?php if ($ops['ads_enabled']=='test') echo 'checked="checked"'; ?> /> <b>Test mode</b> - Only show ads to admin.<br />
35
+ <span style="font-size:10px;color:red;">Warning: Turn any caching plugin *off* before using test mode. If you leave them on the test adverts will be cached and shown to your real visitors.</span><br />
36
+
37
+ <table border="0">
38
+ <tr><td>
39
+ <p><?php _e("Only show ads on pages older than ", 'adinj') ?></p>
40
+ </td><td>
41
+ <p>
42
+ <select name='ads_on_page_older_than'>
43
+ <?php
44
+ $older_than_days = array(0, 1, 2, 3, 5, 7, 10, 14, 21, 28, 40, 50);
45
+ for ($value=0; $value<sizeof($older_than_days); ++$value){
46
+ echo "<option value=\"$older_than_days[$value]\" ";
47
+ if($ops['ads_on_page_older_than'] == $older_than_days[$value]) echo 'selected="selected"';
48
+ echo ">$older_than_days[$value]</option>";
49
+ }
50
+ ?>
51
+ </select><?php _e(" (days)", 'adinj') ?> - only for single posts and pages</p>
52
+ </td></tr>
53
+ <tr><td style="vertical-align:top">
54
+ Don't show ads on these page types:
55
+ </td><td>
56
+ <?php adinj_add_checkbox('exclude_home') ?>home - <?php echo get_bloginfo('url'); ?><br />
57
+ <?php
58
+ $count_pages = wp_count_posts('page', 'readable');
59
+ $count_posts = wp_count_posts('post', 'readable');
60
+ ?>
61
+ <?php adinj_add_checkbox('exclude_page') ?>page - <?php echo $count_pages->publish; ?> page(s)<br />
62
+ <?php adinj_add_checkbox('exclude_single') ?>single -<?php echo $count_posts->publish; ?> individual blog post(s)<br />
63
+ <?php adinj_add_checkbox('exclude_archive') ?>archive - only <a href="#widgets">widgets</a> currently appear on archives<br />
64
+ </td></tr>
65
+ </table>
66
+
67
+ <b>Category and tag conditions</b>
68
+
69
+ <?php adinj_condition_table('global_category', 'category slugs. e.g: cat1, cat2, cat3', 'category'); ?>
70
+
71
+ <?php adinj_condition_table('global_tag', 'tag slugs. e.g: tag1, tag2, tag3', 'tag'); ?>
72
+
73
+ <?php adinj_postbox_end(); ?>
74
+
75
+
76
+ <?php adinj_postbox_start(__("Randomly Injected ad code", 'adinj'), 'random'); ?>
77
+
78
+ <table border="0" cellspacing="5">
79
+ <tr><td style="vertical-align: top">
80
+ <textarea name="ad_code_random_1" rows="10" cols="60"><?php echo $ops['ad_code_random_1']; ?></textarea>
81
+ </td><td style="vertical-align: top">
82
+ <?php
83
+ adinj_add_alignment_options('rnd_');
84
+ echo "<br /><b><a href='?page=ad-injection&amp;tab=adrotation#multiple_random'>Rotation:<br />".adinj_percentage_split('ad_code_random_', 1, $ops)."</a></b>";
85
+
86
+ ?>
87
+ </td></tr>
88
+ <tr><td>
89
+ <?php
90
+ _e("Always put the first ad after paragraph: ", 'adinj');
91
+ adinj_selection_box("start_from_paragraph",
92
+ array(ADINJ_DISABLED, 1, 2, 3, 4, 5), " ");
93
+ ?>
94
+
95
+ </td><td>
96
+ </td></tr>
97
+ </table>
98
+
99
+
100
+ <p><span style="font-size:10px;"><b>Docs:</b> On individual posts or pages this advert is inserted between randomly selected paragraphs. On a multi-post page (e.g. home page), one ad is inserted into each post. Try a <a href="#468x60">468x60</a> or <a href="#728x90">728x90</a> banner.</span></p>
101
+ <p><span style="font-size:10px;">Be especially careful if you decide to use the 'float' layout options. Make sure that you don't have adverts floated over the top of other page elements, or vice-versa.</span></p>
102
+ </div>
103
+
104
+ <input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
105
+ <h3><a name="random_single"></a><?php _e("Single posts and pages: Randomly Injected ad settings", 'adinj') ?></h3>
106
+ <div class="inside" style="margin:10px">
107
+ <p>These random ad injection settings are specific to individual posts and pages.</p>
108
+
109
+ <table border="0">
110
+
111
+ <tr><td>
112
+ <?php _e("Allow multiple ads to be injected at the same positions.", 'adinj') ?>
113
+ </td><td>
114
+ <?php adinj_add_checkbox('multiple_ads_at_same_position') ?> (default is to inject ads at unique positions)
115
+ </td></tr>
116
+
117
+
118
+ <tr><td>
119
+ <?php _e("Maximum number of randomly injected ads: ", 'adinj') ?></td><td>
120
+ <select name='max_num_of_ads'>
121
+ <?php
122
+ for ($value=0; $value<=10; ++$value){
123
+ echo "<option value=\"$value\" ";
124
+ if($ops['max_num_of_ads'] == $value) echo 'selected="selected"';
125
+ echo ">$value</option>";
126
+ }
127
+ ?>
128
+ </select> <?php echo adinj_getdefault('max_num_of_ads'); ?><br />
129
+ </td></tr>
130
+
131
+ <tr><td>
132
+ <?php
133
+ _e("No random ads if page shorter than: ", 'adinj');
134
+ echo '</td><td>';
135
+ adinj_selection_box("no_random_ads_if_shorter_than",
136
+ array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000));
137
+ echo adinj_getdefault('no_random_ads_if_shorter_than');
138
+ ?>
139
+ </td></tr>
140
+
141
+ <tr><td>
142
+ <?php
143
+ _e("Limit of 1 ad if page shorter than: ", 'adinj');
144
+ echo '</td><td>';
145
+ adinj_selection_box("one_ad_if_shorter_than",
146
+ array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000));
147
+ echo adinj_getdefault('one_ad_if_shorter_than');
148
+ ?>
149
+ </td></tr>
150
+
151
+ <tr><td>
152
+ <?php
153
+ _e("Limit of 2 ads if page shorter than: ", 'adinj');
154
+ echo '</td><td>';
155
+ adinj_selection_box("two_ads_if_shorter_than",
156
+ array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000));
157
+ echo adinj_getdefault('two_ads_if_shorter_than');
158
+ ?>
159
+ </td></tr>
160
+
161
+ <tr><td>
162
+ <?php
163
+ _e("Limit of 3 ads if page shorter than: ", 'adinj');
164
+ echo '</td><td>';
165
+ adinj_selection_box("three_ads_if_shorter_than",
166
+ array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000));
167
+ echo adinj_getdefault('three_ads_if_shorter_than');
168
+ ?>
169
+ </td></tr>
170
+ </table>
171
+
172
+ <br clear="all" />
173
+ <p><span style="font-size:10px;"><b>Docs:</b> The above directives are processed in order from top to bottom.</span></p>
174
+
175
+
176
+ <p></p>
177
+
178
+ </div>
179
+
180
+ <input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
181
+ <h3><a name="random_home"></a><?php _e("Home page: Randomly Injected ad settings", 'adinj') ?> (<?php echo get_bloginfo('url'); ?>)</h3>
182
+ <div class="inside" style="margin:10px">
183
+ <p>These random ad injection settings are specific to your home page.</p>
184
+
185
+ <?php _e("Maximum number of injected ads: ", 'adinj') ?>
186
+ <select name='max_num_of_ads_home_page'>
187
+ <?php
188
+ for ($value=0; $value<=10; ++$value){
189
+ echo "<option value=\"$value\" ";
190
+ if($ops['max_num_of_ads_home_page'] == $value) echo 'selected="selected"';
191
+ echo ">$value</option>";
192
+ }
193
+ ?>
194
+ </select> <?php echo adinj_getdefault('max_num_of_ads_home_page'); ?><br />
195
+
196
+ <p><span style="font-size:10px;"><b>Docs:</b> On a multi-post home page, one randomly positioned advert will be inserted into each post, up to the maximum number specified here.</span></p>
197
+
198
+ <?php adinj_postbox_end(); ?>
199
+
200
+
201
+
202
+ <?php adinj_postbox_start(__("Optional top advert (single posts and pages only)", 'adinj'), 'topad'); ?>
203
+
204
+ <?php
205
+ _e("Only show top ad on pages longer than: ", 'adinj');
206
+ adinj_selection_box("top_ad_if_longer_than",
207
+ array(ADINJ_DISABLED, ADINJ_ALWAYS_SHOW, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000));
208
+
209
+ ?>
210
+
211
+ <br clear="all" />
212
+
213
+ <table border="0">
214
+ <tr><td>
215
+ <textarea name="ad_code_top_1" rows="10" cols="60"><?php echo $ops['ad_code_top_1']; ?></textarea>
216
+ </td><td style="vertical-align: top">
217
+ <?php
218
+ adinj_add_alignment_options('top_');
219
+ echo "<br /><b><a href='?page=ad-injection&amp;tab=adrotation#multiple_top'>Rotation:<br />".adinj_percentage_split('ad_code_top_', 1, $ops)."</a></b>";
220
+ ?>
221
+ </td></tr>
222
+ </table>
223
+ <span style="font-size:10px;">The top ad is in addition to the quantity of other ads selected.</span>
224
+
225
+ <p><span style="font-size:10px;"><b>Docs:</b> The top ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a <a href="#468x15">468x15</a> or <a href="#336x280">336x280</a> advert.</span></p>
226
+
227
+ <?php adinj_postbox_end(); ?>
228
+
229
+
230
+ <?php adinj_postbox_start(__("Optional bottom advert (single posts and pages only)", 'adinj'), 'bottomad'); ?>
231
+
232
+ <?php
233
+ _e("Only show bottom ad on pages longer than: ", 'adinj');
234
+ adinj_selection_box("bottom_ad_if_longer_than",
235
+ array(ADINJ_DISABLED, ADINJ_ALWAYS_SHOW, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000));
236
+ ?>
237
+
238
+ <br clear="all"/>
239
+
240
+ <table border="0">
241
+ <tr><td>
242
+ <textarea name="ad_code_bottom_1" rows="10" cols="60"><?php echo $ops['ad_code_bottom_1']; ?></textarea>
243
+ </td><td style="vertical-align: top">
244
+ <?php
245
+ adinj_add_alignment_options('bottom_');
246
+ echo "<br /><b><a href='?page=ad-injection&amp;tab=adrotation#multiple_bottom'>Rotation:<br />".adinj_percentage_split('ad_code_bottom_', 1, $ops)."</a></b>";
247
+ ?>
248
+ </td></tr>
249
+ </table>
250
+ <span style="font-size:10px;">The top ad is in addition to the quantity of other ads selected.</span>
251
+
252
+ <p><span style="font-size:10px;"><b>Docs:</b> The bottom ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a <a href="#336x280">336x280</a> advert.</span></p>
253
+
254
+
255
+ <?php adinj_postbox_end(); ?>
256
+
257
+
258
+ <?php adinj_postbox_start(__("Widget settings (sidebar ads)", 'adinj'), 'widgets'); ?>
259
+
260
+ <p>You must configure your individual widgets from the <a href="widgets.php">widgets control panel</a>. However these settings are global to all widgets. Also note that the main set of <a href="#global">global settings</a> will override these ones.</p>
261
+
262
+ <table border="0">
263
+
264
+ <tr><td>
265
+ <p>Don't show widget ads on these page types:</p>
266
+ </td><td>
267
+ <?php adinj_add_checkbox('widget_exclude_home') ?>home - <?php echo get_bloginfo('url'); ?><br />
268
+ <?php adinj_add_checkbox('widget_exclude_page') ?>page - <?php echo $count_pages->publish; ?> page(s)<br />
269
+ <?php adinj_add_checkbox('widget_exclude_single') ?>single - <?php echo $count_posts->publish; ?> individual blog post(s)<br />
270
+ <?php adinj_add_checkbox('widget_exclude_archive') ?>archive - includes category, tag, author, and date pages types<br />
271
+ </td></tr>
272
+
273
+ </table>
274
+
275
+
276
+ <?php adinj_postbox_end(); ?>
277
+
278
+
279
+ <?php adinj_postbox_start(__("Ad insertion mode and dynamic ad display restrictions", 'adinj'), 'restrictions'); ?>
280
+
281
+ <h4>Ad insertion mode</h4>
282
+
283
+ <blockquote>
284
+ <p><input type="radio" name="ad_insertion_mode" value="mfunc" <?php if ($ops['ad_insertion_mode']=='mfunc') echo 'checked="checked"'; ?> /> <b>Use mfunc tags for dynamic features (WP Super Cache mode)</b> - Dynamic features will work with WP Super Cache. </p>
285
+
286
+ <?php if (!is_plugin_active('wp-super-cache/wp-cache.php')) {
287
+ echo '<p><b><span style="font-size:10px;color:red;">Note: WP Super Cache does not appear to be active. If you are not using WP Super Cache /WP Cache (or compatible) you should use one of the direct insertion modes.</span></b></p>';
288
+ } ?>
289
+
290
+ <?php if ($ops['ad_insertion_mode'] != 'mfunc') { ?>
291
+ <script type="text/javascript">
292
+ document.write('<style type="text/css" media="screen">#wp_supercache_msg { display: none; }</style>');
293
+ </script>
294
+ <?php } ?>
295
+
296
+ <div id="wp_supercache_msg" class="wp_supercache_msg">
297
+ <p>With WP Super Cache version 0.9.9.8+ you can use the fastest 'mod rewrite rules' caching mode. With older versions of WP Super Cache you'll have to use the slower 'legacy mode'.</p>
298
+
299
+ <p>Go to the
300
+
301
+ <?php if (is_plugin_active('wp-super-cache/wp-cache.php')) { ?>
302
+ <a href='options-general.php?page=wpsupercache&amp;tab=settings'>WP Super Cache advanced options page</a>
303
+ <?php } else { ?>
304
+ WP Super Cache advanced options page
305
+ <?php } ?>
306
+ to configure the caching mode.</p>
307
+
308
+ <p>Dynamic features will also work if you don't use a caching program with mfunc mode. Although if you don't use a caching program one of the 'direct' insertion modes will be more efficient.</p>
309
+ </div>
310
+
311
+ <p><input type="radio" name="ad_insertion_mode" value="direct_dynamic" <?php if ($ops['ad_insertion_mode']=='direct_dynamic') echo 'checked="checked"'; ?> /> <b>Direct ad insertion with dynamic features</b> - Dynamic features will work if no caching is used. Only select this if you are not using any caching plugin.</p>
312
+ <p><input type="radio" name="ad_insertion_mode" value="direct_static" <?php if ($ops['ad_insertion_mode']=='direct_static') echo 'checked="checked"'; ?> /> <b>Direct static ad insertion</b> - No dynamic feature support. Select this if you are using a caching plugin which is not compatible with WP Super Cache's mfunc tags.</p>
313
+ </blockquote>
314
+ </div>
315
+ <p></p>
316
+
317
+ <script type="text/javascript">
318
+ jQuery(document).ready(function(){
319
+ jQuery('input[name=ad_insertion_mode]:radio').change(function() {
320
+ if (jQuery('input[name=ad_insertion_mode]:checked').val() == "direct_static"){
321
+ jQuery('.dynamic_features').slideUp(1000);
322
+ jQuery('.dynamic_features_msg').slideDown(1000);
323
+ jQuery('.wp_supercache_msg').slideUp(1000);
324
+ } else if (jQuery('input[name=ad_insertion_mode]:checked').val() == "direct_dynamic"){
325
+ jQuery('.dynamic_features_msg').slideUp(1000);
326
+ jQuery('.dynamic_features').slideDown(1000);
327
+ jQuery('.wp_supercache_msg').slideUp(1000);
328
+ } else { // mfunc
329
+ jQuery('.dynamic_features_msg').slideUp(1000);
330
+ jQuery('.dynamic_features').slideDown(1000);
331
+ jQuery('.wp_supercache_msg').slideDown(1000);
332
+ }
333
+ return true;
334
+ });
335
+ });
336
+ </script>
337
+
338
+ <?php if ($ops['ad_insertion_mode'] == 'direct_static') { ?>
339
+ <div class="dynamic_features_msg">
340
+ <?php } else { ?>
341
+ <div class="dynamic_features_msg" style="display:none">
342
+ <?php } ?>
343
+ <div class="inside" style="margin:10px">
344
+ <b><span style="font-size:10px;color:red;">Note: Dynamic features (restricting ad views by referrer and IP address) are only available in the mfunc, or direct dynamic modes.</span></b>
345
+ </div>
346
+ </div>
347
+
348
+ <?php if ($ops['ad_insertion_mode'] == 'direct_static') { ?>
349
+ <script type="text/javascript">
350
+ document.write('<style type="text/css" media="screen">#dynamic_features { display: none; }</style>');
351
+ </script>
352
+ <?php } ?>
353
+ <div id="dynamic_features" class="dynamic_features">
354
+
355
+ <div class="inside" style="margin:10px">
356
+
357
+ <h4><a name="dynamic"></a>Show ads only to search engine visitors (dynamic feature)</h4>
358
+
359
+ <blockquote>
360
+ <?php adinj_add_checkbox('sevisitors_only') ?><?php _e("Only show ads to search engine visitors (customise search engine referrers below if necessary).", 'adinj') ?><br />
361
+ <textarea name="ad_referrers" rows="2" cols="70"><?php echo $ops['ad_referrers']; ?></textarea>
362
+ <p>Comma separated list e.g.: <br /><code>.google., .bing., .yahoo., .ask., search?, search., /search/</code></p>
363
+ </blockquote>
364
+
365
+ <h4>Blocked IP addresses (dynamic feature)</h4>
366
+
367
+ <blockquote>
368
+ <!--<?php adinj_add_checkbox('block_ips') ?><?php _e("Exclude ads from these IP addresses.", 'adinj') ?><br />-->
369
+ <textarea name="blocked_ips" rows="4" cols="70"><?php echo $ops['blocked_ips']; ?></textarea>
370
+ <p>Comma separated list e.g.: <br /><code>0.0.0.1, 0.0.0.2</code></p>
371
+ <p>Or you can list one IP per line with optional comments e.g.</p>
372
+ <code style="padding:0px 0px">192.168.0.1<br />0.0.0.2<br /><?php echo $_SERVER['REMOTE_ADDR'] ?> //my ip<br />0.0.0.3</code>
373
+
374
+ <p>For reference your current IP address is <code><?php echo $_SERVER['REMOTE_ADDR'] ?></code></p>
375
+ </blockquote>
376
+ </div>
377
+
378
+ </div>
379
+
380
+ <?php adinj_postbox_end(); ?>
381
+
382
+
383
+ <?php adinj_postbox_start(__("Debugging", 'adinj'), 'debugging'); ?>
384
+
385
+ <?php adinj_add_checkbox('debug_mode') ?>Enable debug mode
386
+
387
+ <p>If you are not sure why ads aren't appearing, or why they are appearing, enable debug mode and look at the debug information (search for 'ADINJ DEBUG') in the HTML of your content pages.</p>
388
+
389
+ <?php
390
+
391
+ if (adinj_problem_with_wpminify_check()){
392
+ echo adinj_get_problem_with_wpminify_message();
393
+ }
394
+
395
+ adinj_debug_information();
396
+ ?>
397
+
398
+ <p></p>
399
+
400
+ <p>If you want to restore all settings (excluding the ad contents) to their default values use this button.</p>
401
+
402
+ <input type="submit" name="adinj_action" value="<?php _e('Reset to Default', 'adinj') ?>" />
403
+
404
+ <p>You can delete the database settings if you are going to uninstall Ad Injection (they will be automatically deleted if you uninstall via WordPress as well).</p>
405
+
406
+ <input type="submit" name="adinj_action" value="<?php _e('Delete settings from DB', 'adinj') ?>" />
407
+
408
+ <p>This button will delete all your Ad Injection widgets.</p>
409
+
410
+ <input type="submit" name="adinj_action" value="<?php _e('Delete widget settings from DB', 'adinj') ?>" />
411
+
412
+ <?php adinj_postbox_end(); ?>
413
+
414
+
415
+ <br clear="all" />
416
+
417
+ <?php
418
+
419
+ adinj_docs();
420
+ }
421
+
422
+ function adinj_side_status_box(){
423
+ ?>
424
+ <div class="postbox-container" style="width:258px;">
425
+ <div class="metabox-holder">
426
+ <div class="meta-box-sortables" style="min-height:50px;">
427
+ <div class="postbox">
428
+ <h3 class="hndle"><span><?php echo adinj_get_logo(); ?> Status</span></h3>
429
+ <div class="inside" style="margin:5px;">
430
+
431
+ <style type="text/css">
432
+ .adinjstatustable td { vertical-align: top; }
433
+ </style>
434
+
435
+ <table border="0" cellpadding="2" class="adinjstatustable">
436
+
437
+ <tr><td style="text-align:right">
438
+ <b><a href="#global">Ads enabled</a></b>
439
+ </td><td>
440
+ <?php
441
+ $info = adinj_get_status('global'); echo adinj_dot($info[0]).' '.$info[1];
442
+ if ($info[0] != 'red') { ?>
443
+ <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('exclude_home'); ?> home
444
+ <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('exclude_page'); ?> page
445
+ <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('exclude_single'); ?> single
446
+ <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('exclude_archive'); ?> archive
447
+ </td></tr>
448
+
449
+ <tr><td style="text-align:right">
450
+ <b><a href="#random">Random ads</a></b>
451
+ </td><td>
452
+ <?php
453
+ $info = adinj_get_status('random'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
454
+ $info = adinj_get_status('random_home'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
455
+ $info = adinj_get_status('random_pool'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
456
+ $info = adinj_get_status('random_alt_pool'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
457
+ ?>
458
+ </td></tr>
459
+
460
+ <tr><td style="text-align:right">
461
+ <b><a href="#topad">Top ad</a></b>
462
+ </td><td>
463
+ <?php
464
+ $info = adinj_get_status('topad'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
465
+ $info = adinj_get_status('top_pool'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
466
+ $info = adinj_get_status('top_alt_pool'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
467
+ ?>
468
+ </td></tr>
469
+
470
+ <tr><td style="text-align:right">
471
+ <b><a href="#bottomad">Bottom ad</a></b>
472
+ </td><td>
473
+ <?php
474
+ $info = adinj_get_status('bottomad'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
475
+ $info = adinj_get_status('bottom_pool'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
476
+ $info = adinj_get_status('bottom_alt_pool'); echo adinj_dot($info[0]).' '.$info[1].'<br />';
477
+ ?>
478
+ </td></tr>
479
+
480
+ <tr><td style="text-align:right; vertical-align:top">
481
+ <b><a href="#widgets">Widgets</a></b>
482
+ </td><td>
483
+ <?php $info = adinj_get_status('widgets'); echo adinj_dot($info[0]).' '.$info[1];
484
+ if ($info[0] != 'red') { ?>
485
+ <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('widget_exclude_home'); ?> home
486
+ <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('widget_exclude_page'); ?> page
487
+ <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('widget_exclude_single'); ?> single
488
+ <br />&nbsp;&nbsp;<?php echo adinj_green_or_red_dot('widget_exclude_archive'); ?> archive
489
+ <?php } ?>
490
+ </td></tr>
491
+
492
+ <tr><td style="text-align:right">
493
+ <b><a href="#restrictions">Mode</a></b>
494
+ </td><td>
495
+ <?php $info = adinj_get_status('mode'); echo adinj_dot($info[0]).' '.$info[1]; ?>
496
+ </td></tr>
497
+
498
+ <tr><td style="text-align:right">
499
+ <b><a href="#dynamic">Restrictions</a></b>
500
+ </td><td>
501
+ <?php $info = adinj_get_status('restrictions'); echo adinj_dot($info[0]).' '.$info[1]; ?>
502
+ </td></tr>
503
+
504
+ <tr><td style="text-align:right">
505
+ <b><a href="#debugging">Debug mode</a></b>
506
+ </td><td>
507
+ <?php $info = adinj_get_status('debugging'); echo adinj_dot($info[0]).' '.$info[1]; ?>
508
+ </td></tr>
509
+ <tr><td>
510
+ </td><td>
511
+ </td></tr>
512
+ <tr><td>
513
+ </td><td>
514
+ <?php } ?>
515
+ </td></tr>
516
+ </table>
517
+ </div>
518
+ </div>
519
+ </div>
520
+ </div>
521
+ </div>
522
+
523
+ <br />
524
+ <?php
525
+ }
526
+
527
+ function adinj_debug_information(){
528
+ $stored_options = adinj_options();
529
+ $default_options = adinj_default_options();
530
+ ?>
531
+ <h4>Settings dump from database (all in 'adinj_options' option)</h4>
532
+ <table border="1" style="width:610px; table-layout:fixed; word-wrap:break-word;">
533
+ <tr><td><b>Name</b></td><td><b>Stored</b></td><td><b>Default</b></td></tr>
534
+ <?php
535
+ if ($stored_options !== false){
536
+ $count = 0;
537
+ foreach ($stored_options as $key => $value){
538
+ if ($count % 2 == 0){
539
+ echo '<tr style="background-color:#cccccc"><td>';
540
+ } else {
541
+ echo '<tr><td>';
542
+ }
543
+ echo "$key";
544
+ echo "</td><td>";
545
+ $value = htmlentities($value);
546
+ echo "$value";
547
+ echo "</td><td>";
548
+ echo $default_options[$key];
549
+ echo "</td></tr>";
550
+ $count++;
551
+ }
552
+ } else {
553
+ echo "<br />No options in database!";
554
+ }
555
+ echo '</table>';
556
+
557
+ ?><h4>Widget settings dump from database (all in 'widget_adinj' option)</h4>
558
+ <table border="1" style="width:610px; word-wrap:break-word;">
559
+ <tr><td><b>Widget</b></td><td><b>Setting:Value</b></td></tr>
560
+ <?php
561
+ $widgetops = get_option('widget_adinj');
562
+ $count = 0;
563
+ if (is_array($widgetops)){
564
+ foreach($widgetops as $key=>$val){
565
+ if ($count % 2 == 0){
566
+ echo '<tr style="background-color:#cccccc"><td style="vertical-align:top">';
567
+ } else {
568
+ echo '<tr><td style="vertical-align:top">';
569
+ }
570
+ echo $key;
571
+ echo "</td>";
572
+ echo '<td style="vertical-align:top">';
573
+ if (is_array($val)){
574
+ foreach($val as $subkey=>$subval){
575
+ echo $subkey.':'.htmlentities($subval).'<br />';
576
+ }
577
+ } else {
578
+ echo htmlentities($val);
579
+ }
580
+ echo '</td></tr>';
581
+ ++$count;
582
+ }
583
+ } else {
584
+ echo '<tr><td></td><td><b>No widget settings found</b></td></tr>';
585
+ }
586
+ echo '</table>';
587
+
588
+ echo '<h4>Other settings</h4><blockquote>';
589
+
590
+ echo 'ADINJ_PATH='.ADINJ_PATH.'<br />';
591
+ echo 'ADINJ_CONFIG_FILE='.ADINJ_CONFIG_FILE.'<br />';
592
+ echo 'ADINJ_AD_PATH='.ADINJ_AD_PATH.'<br />';
593
+
594
+ echo 'Plugin version='.adinj_get_version();
595
+ echo '</blockquote>';
596
+
597
+ global $adinj_warning_msg_filewrite;
598
+ if (!empty($adinj_warning_msg_filewrite)){
599
+ echo "<h4>Errors on 'Save all settings'</h4><blockquote>$adinj_warning_msg_filewrite</blockquote";
600
+ }
601
+
602
+ global $adinj_warning_msg_chmod;
603
+ if (!empty($adinj_warning_msg_chmod)){
604
+ echo "<h4>Warnings on 'Save all settings'</h4><blockquote>$adinj_warning_msg_chmod</blockquote";
605
+ }
606
+
607
+ }
608
+
609
+ function adinj_docs(){
610
+ ?>
611
+ <hr />
612
+
613
+ <?php adinj_postbox_start(__("Quick Start", 'adinj'), "docs", '95%'); ?>
614
+
615
+ <p>1. Copy and paste your ad code into the ad code boxes.</p>
616
+
617
+ <p>2. Choose how many ads of each type you want displayed.</p>
618
+
619
+ <p>3. Configure any ad positioning (optional).</p>
620
+
621
+ <p>4. Check the ad insertion mode (in the Insertion mode and ad display restriction section).</p>
622
+
623
+ <p>5. If you are using a compatible ad insertion mode you may configure dynamic ad display restrictions. i.e. showing ads only to certain people (e.g. search engine visitors), or blocking ads from specific IPs.</p>
624
+
625
+ <p>6. Enable your ads (tick box at the very top).</p>
626
+ </div>
627
+
628
+ <h3><?php echo adinj_get_logo(); ?> Supported in-page tags</h3>
629
+ <div class="inside" style="margin:10px">
630
+
631
+ <p>These tags can be inserted into the page source to override the configured behaviour on individual pages. Because sometimes specific pages need to be treated differently.</p>
632
+
633
+ <ul>
634
+ <li><code>&lt;!--noadsense--&gt;</code> OR <code>&lt;!-no-adsense--&gt;</code> OR <code>&lt;!--NoAds--&gt;</code> OR <code>&lt;!--OffAds--&gt;</code> - disables all ads on this page. These tags are here to make this plugin compatible with the tags from Adsense Injection, Whydowork Adsense and Quick Adsense.</li>
635
+ </ul>
636
+
637
+ <p></p>
638
+
639
+ <ul>
640
+ <li><code>&lt;!--adsandwich--&gt;</code> - Inserts the top and bottom ad but no random ads. Disables all other ads.</li>
641
+ <li><code>&lt;!--adfooter--&gt;</code> - Insert a single ad at the very bottom. Disables all other ads.</li>
642
+ </ul>
643
+
644
+ <p></p>
645
+
646
+ <ol>
647
+ <li><code>&lt;!--adsensestart--&gt;</code> - Random ads will start from this point*. For compatibility with Adsense Injection.</li>
648
+ <li><code>&lt;!--adsenseend--&gt;</code> - Random ads will not be inserted after this point*. New tag but I've kept the Adsense Injection naming convention to make it fit with the above tag.</li>
649
+ <li><code>&lt;!--adstart--&gt;</code> - Random ads will start from this point*.</li>
650
+ <li><code>&lt;!--adend--&gt;</code> - Random ads will not be inserted after this point*.</li>
651
+ </ol>
652
+
653
+ <p>These four tags will not affect the top and bottom ad.</p>
654
+
655
+ <h4>Custom field for disabling adverts</h4>
656
+
657
+ <p>To disable all adverts on the page you can also set the custom <code>disable_adverts</code> field to '1' from the WordPress post editor.</p>
658
+
659
+
660
+ <?php adinj_postbox_end(); ?>
661
+
662
+
663
+ <?php adinj_postbox_start(__("Test Adverts", 'adinj'), "testads", '95%'); ?>
664
+
665
+ <p>You can copy and paste these adverts into the boxes above to test your ad setup before switching to your real ads.</p>
666
+
667
+ <h4><a name="468x60"></a>468x60 banner</h4>
668
+
669
+ <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#ff9999; width:468px; height:60px;&quot;&gt;
670
+ &lt;h5&gt;TEST ADVERT 468x60 - &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;www.reviewmylife.co.uk&lt;/a&gt;&lt;/h5&gt;
671
+ &lt;/div&gt;</textarea></p>
672
+
673
+ <div style="background-color:#99ffff; width:468px; height:60px;">
674
+ <h5>TEST ADVERT 468x60 - <a href="http://www.reviewmylife.co.uk/">www.reviewmylife.co.uk</a></h5>
675
+ </div><p></p>
676
+
677
+ <h4><a name="728x90"></a>728x90 banner</h4>
678
+
679
+ <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#ff9999; width:728px; height:90px;&quot;&gt;
680
+ &lt;h5&gt;TEST ADVERT 728x90&lt;/h5&gt;
681
+ &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;www.reviewmylife.co.uk&lt;/a&gt;&lt;br /&gt;
682
+ &lt;a href=&quot;http://www.advancedhtml.co.uk/&quot;&gt;www.advancedhtml.co.uk&lt;/a&gt;
683
+ &lt;/div&gt;</textarea></p>
684
+
685
+ <div style="background-color:#ff9999; width:728px; height:90px;">
686
+ <h5>TEST ADVERT 728x90</h5>
687
+ <a href="http://www.reviewmylife.co.uk/">www.reviewmylife.co.uk</a><br />
688
+ <a href="http://www.advancedhtml.co.uk/">www.advancedhtml.co.uk</a>
689
+ </div><p></p>
690
+
691
+ <h4>160x90 link unit</h4>
692
+
693
+ <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#ccff99; width:160px; height:90px;&quot;&gt;
694
+ &lt;h5&gt;TEST ADVERT 160x90&lt;/h5&gt;
695
+ &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;reviewmylife.co.uk&lt;/a&gt;&lt;br /&gt;
696
+ &lt;a href=&quot;http://www.advancedhtml.co.uk/&quot;&gt;advancedhtml.co.uk&lt;/a&gt;
697
+ &lt;/div&gt;</textarea></p>
698
+
699
+ <div style="background-color:#ccff99; width:160px; height:90px;">
700
+ <h5>TEST ADVERT 160x90</h5>
701
+ <a href="http://www.reviewmylife.co.uk/">reviewmylife.co.uk</a>
702
+ <a href="http://www.advancedhtml.co.uk/">advancedhtml.co.uk</a><br />
703
+ </div><p></p>
704
+
705
+ <h4><a name="468x15"></a>468x15 link unit</h4>
706
+
707
+ <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#cccc99; width:468px; height:15px;&quot;&gt;
708
+ &lt;font size=&quot;-2&quot;&gt;&lt;b&gt;TEST ADVERT 160x90&lt;/b&gt; &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;reviewmylife.co.uk&lt;/a&gt;&lt;/font&gt;
709
+ &lt;/div&gt;</textarea></p>
710
+
711
+ <div style="background-color:#cccc99; width:468px; height:15px;">
712
+ <font size="-2"><b>TEST ADVERT 160x90</b> <a href="http://www.reviewmylife.co.uk/">reviewmylife.co.uk</a></font>
713
+ </div><p></p>
714
+
715
+ <h4><a name="336x280"></a>336x280 large rectangle</h4>
716
+
717
+ <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#ccccff; width:336px; height:280px;&quot;&gt;
718
+ &lt;h5&gt;TEST ADVERT 336x280 - &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;www.reviewmylife.co.uk&lt;/a&gt;&lt;/h5&gt;
719
+ &lt;/div&gt;</textarea></p>
720
+
721
+ <div style="background-color:#ccccff; width:336px; height:280px;">
722
+ <h5>TEST ADVERT 336x280 - <a href="http://www.reviewmylife.co.uk/">www.reviewmylife.co.uk</a></h5>
723
+ </div><p></p>
724
+
725
+ <h4>468x60 banner with dynamic PHP</h4>
726
+
727
+ <p>The PHP will execute if either 1) WP Super Cache is turned on, or 2) if WP Super Cache is not installed/disabled. If you use another caching plugin the dynamic code will probably not work.</p>
728
+
729
+ <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="5">&lt;div style=&quot;background-color:#ffff99; width:468px; height:60px;&quot;&gt;
730
+ &lt;b&gt;TEST ADVERT 468x60 with date() and rand()&lt;/b&gt;&lt;br /&gt;
731
+ &lt;?php echo &quot;date=&quot;.date(&quot;Y-m-d H:i:s&quot;) .&quot; rand=&quot;.rand(); ?&gt;&lt;br /&gt;
732
+ &lt;a href=&quot;http://www.advancedhtml.co.uk/&quot;&gt;www.advancedhtml.co.uk&lt;/a&gt;
733
+ &lt;/div&gt;</textarea></p>
734
+
735
+ <div style="background-color:#ffff99; width:468px; height:60px;">
736
+ <b>TEST ADVERT 468x60 with date() and rand()</b><br />
737
+ <?php echo "date=".date("Y-m-d H:i:s") ." rand=".rand(); ?><br />
738
+ <a href="http://www.advancedhtml.co.uk/">www.advancedhtml.co.uk</a>
739
+ </div><p></p>
740
+
741
+ <?php adinj_postbox_end();
742
+
743
+ }
744
+
745
+ ?>
uninstall.php CHANGED
@@ -9,7 +9,9 @@ if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
9
 
10
  // Database cleanup
11
  delete_option('adinj_options');
12
- //delete_option('widget_adinj'); //TODO does WordPress do this automatically?
 
 
13
 
14
  // Delete the configuration file
15
  $adinj_dir = dirname(__FILE__);
9
 
10
  // Database cleanup
11
  delete_option('adinj_options');
12
+ // Seems that widget settings don't automatically get cleaned up when plugin
13
+ // uninstalled
14
+ delete_option('widget_adinj');
15
 
16
  // Delete the configuration file
17
  $adinj_dir = dirname(__FILE__);