Ad Injection - Version 1.2.0.0

Version Description

  • Set the position of the top and bottom advert by paragraph or character.
  • Position the random ads to start or stop in the middle of the post.
  • Stop the random ads 2/3 of the way down a post, or at a paragraph/character position from the beginning/end of the post.
  • Fade unused Home/Archive options instead of making them dissapear.
  • Add page age settings to status.
  • Improve debug messages.
Download this release

Release Info

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

Code changes from version 1.1.0.6 to 1.2.0.0

ad-injection-admin.php CHANGED
@@ -149,7 +149,7 @@ function adinj_config_block_ips() { return $block_ips; }
149
  function adinj_config_blocked_ips() { return array($ip_list); }
150
 
151
  function adinj_config_block_keywords() { return $block_keywords; }
152
- function adinj_config_blocked_keywords() { return array($blocked_keywords); }
153
 
154
  function adinj_config_debug_mode() { return $debug_mode; }
155
 
@@ -335,7 +335,7 @@ function adinj_top_message_box(){
335
 
336
  } else if (!isset($_GET['tab'])){
337
  echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
338
- echo "5th September 2011: New block ads by referrer feature - an example use would be to treat people who arrive at your site after searching for your site by name as direct visitors and block them from seeing ads. Load tags in batches to reduce memory usage for blogs with lots of tags. Plus other minor fixes. <font color='red'>Beta testers for 1.2.0.0 release</font> - If you are interested in testing the new 1.2.0.0 release a few days early contact me via the link at the end of this paragraph and I'll send you a zip when it is ready for testing. Thanks! Please contact me ASAP if you spot any bugs, or odd behaviour via the ".'<a href="'.adinj_feedback_url().'" target="_new">quick feedback form</a>.';
339
  echo '</strong></p></div>';
340
  }
341
  }
@@ -431,7 +431,8 @@ function adinj_add_checkbox($name, $class=NULL, $all=NULL){
431
  if ($all != NULL && adinj_ticked($name)){
432
  ?>
433
  <script type="text/javascript">
434
- document.write('<style type="text/css" media="screen">.<?php echo $class; ?> { display: none; }</style>');
 
435
  </script>
436
  <?php
437
  }
@@ -447,7 +448,7 @@ function adinj_admin_tabs( $current = 0 ) {
447
  $current = 'main';
448
  }
449
  }
450
- $tabs = array( 'main' => __( 'Main', 'ad-injection' ), 'adrotation' => __( 'Ad codes / rotation / misc', 'ad-injection' ), 'debug' => __( 'Debug' ) );
451
  $links = array();
452
  foreach( $tabs as $tab => $name ) {
453
  if ( $current == $tab ) {
@@ -467,6 +468,7 @@ function adinj_postbox_start($title, $anchor, $width='650px'){
467
  $ops = adinj_options();
468
  ?>
469
  <div class='postbox-container' style='width:<?php echo $width; ?>;float:left; clear:left;'>
 
470
  <div class="metabox-holder">
471
  <div class="postbox">
472
  <input type="submit" style="float:right" class="button-primary" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
@@ -501,7 +503,7 @@ echo <<<HTML
501
  HTML;
502
  ?>
503
 
504
- <h3><?php $info = adinj_get_status($anchor); echo adinj_dot($info[0]); ?> <a name="<?php echo $anchor; ?>"></a><?php echo adinj_get_logo() . ' ' . $title; ?></h3>
505
  <?php if($hide == 'true'){ ?>
506
  <div id="<?php echo $anchor; ?>-box" class="hiddenbox">
507
  <?php } else { ?>
@@ -557,9 +559,20 @@ function adinj_get_status($name){
557
  if ($ops['sevisitors_only'] == 'on'){
558
  $status[1] .= 'referrer';
559
  }
 
 
 
560
  if ($ops['block_ips'] == 'on' && !empty($ops['blocked_ips'])){
561
  $status[1] .= ' ip';
562
  }
 
 
 
 
 
 
 
 
563
  } else if ($name == 'adsettings'){
564
  $status[0] = 'green';
565
  } else if ($name == 'adverts'){
@@ -568,6 +581,8 @@ function adinj_get_status($name){
568
  } else {
569
  $status[0] = 'red';
570
  }
 
 
571
  } else if ($name == 'debugging'){
572
  $val = $ops['debug_mode'];
573
  if ($val == 'on'){
@@ -661,7 +676,6 @@ function adinj_selection_box($name, $values, $type="", $selected_value=NULL){
661
  }
662
  echo "<option value=\"$option_value\" ";
663
  if("$selected_value" == "$option_value" ||
664
- "$selected_value" == ADINJ_ALWAYS_SHOW && "$option_value" == 'a' || //todo remove?
665
  "$selected_value" == ADINJ_DISABLED && "$option_value" == 'd' || //todo remove?
666
  "$selected_value" == ADINJ_NA && "$option_value" == 'd' ||
667
  "$selected_value" == ADINJ_RULE_DISABLED && "$option_value" == 'd' || //todo remove?
@@ -670,7 +684,7 @@ function adinj_selection_box($name, $values, $type="", $selected_value=NULL){
670
  echo 'selected="selected"';
671
  }
672
  $typetxt = $type;
673
- if (adinj_not_set($option_value) || adinj_alwaysshow($display_value)) $typetxt = "";
674
  if ("$option_value" === 'a') { $display_value = ADINJ_NA; } //TODO remove?
675
  if ("$option_value" === 'd') { $display_value = ADINJ_NA; }
676
  if ("$option_value" === 'o') { $display_value = ADINJ_ONLY_SHOW_IN; }
@@ -693,9 +707,15 @@ function adinj_javascript_addtext(){
693
  }
694
  function adinj_toggle_tick_boxes(name, hide){
695
  if (hide){
696
- jQuery('.'+name).hide();
 
 
 
697
  } else {
698
- jQuery('.'+name).show();
 
 
 
699
  }
700
  }
701
  </script>
@@ -777,7 +797,7 @@ function adinj_condition_table($name, $description, $type, $ops, $dropdown_field
777
  if ($type == 'category') {
778
  $categories = get_categories();
779
  $cat = NULL;
780
- foreach ($categories as &$cat) {
781
  $nicename = rawurldecode($cat->category_nicename);
782
  echo '<option value="'.$nicename.'">'.$nicename.' ('.$cat->category_count.')</option>';
783
  }
@@ -798,7 +818,7 @@ function adinj_condition_table($name, $description, $type, $ops, $dropdown_field
798
  } else if ($type == 'author') {
799
  $authors = adinj_get_authors();
800
  $author = NULL;
801
- foreach ($authors as &$author) {
802
  $login = $author->user_login;
803
  $displayname = $author->display_name;
804
  echo '<option value="'.$login.'">'.$login.' ('.$displayname.')</option>';
@@ -825,7 +845,7 @@ function adinj_print_tags($quantity, $offset){
825
  $tags = get_tags(array('number' => $quantity, 'offset' => $offset));
826
  if (count($tags) == 0) return false;
827
  $tag = NULL;
828
- foreach ($tags as &$tag) {
829
  $slug = rawurldecode($tag->slug);
830
  echo '<option value="'.$slug.'">'.$slug.' ('.$tag->count.')</option>';
831
  }
@@ -843,6 +863,31 @@ function adinj_get_authors(){
843
  return $authors;
844
  }
845
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
846
  function adinj_add_alignment_options($prefix){
847
  adinj_add_alignment_clear_options($prefix);
848
  echo "<br />";
@@ -1285,6 +1330,17 @@ function adinj_upgrade_db(){
1285
  $new_options['widgets_on_page_older_than'] = $stored_options['ads_on_page_older_than'];
1286
  }
1287
 
 
 
 
 
 
 
 
 
 
 
 
1288
  // 3. Bump up db version number.
1289
  $new_options['db_version'] = $new_dbversion;
1290
 
@@ -1305,74 +1361,23 @@ function adinj_default_options(){
1305
  'ads_enabled' => 'off',
1306
  'ads_on_page_older_than' => '0',
1307
  'widgets_on_page_older_than' => '0',
1308
- 'exclude_front' => '',
1309
- 'exclude_home' => '',
1310
- 'exclude_page' => '',
1311
- 'exclude_single' => '',
1312
- 'exclude_archive' => '',
1313
- 'exclude_search' => 'on',
1314
- 'exclude_404' => 'on',
1315
- 'global_category_condition_mode' => 'o',
1316
- 'global_category_condition_entries' => '',
1317
- 'global_tag_condition_mode' => 'o',
1318
- 'global_tag_condition_entries' => '',
1319
- 'global_author_condition_mode' => 'o',
1320
- 'global_author_condition_entries' => '',
1321
- 'global_id_condition_mode' => 'o',
1322
- 'global_id_condition_entries' => '',
1323
  'content_length_unit' => 'words',
1324
- // Random ads
1325
- 'ad_code_random_1' => '',
1326
- 'ad_code_random_2' => '',
1327
- 'ad_code_random_3' => '',
1328
- 'ad_code_random_4' => '',
1329
- 'ad_code_random_5' => '',
1330
- 'ad_code_random_6' => '',
1331
- 'ad_code_random_7' => '',
1332
- 'ad_code_random_8' => '',
1333
- 'ad_code_random_9' => '',
1334
- 'ad_code_random_10' => '',
1335
- 'ad_code_random_1_split' => '100',
1336
- 'ad_code_random_2_split' => '100',
1337
- 'ad_code_random_3_split' => '100',
1338
- 'ad_code_random_4_split' => '100',
1339
- 'ad_code_random_5_split' => '100',
1340
- 'ad_code_random_6_split' => '100',
1341
- 'ad_code_random_7_split' => '100',
1342
- 'ad_code_random_8_split' => '100',
1343
- 'ad_code_random_9_split' => '100',
1344
- 'ad_code_random_10_split' => '100',
1345
- 'ad_code_random_alt_1' => '',
1346
- 'ad_code_random_alt_2' => '',
1347
- 'ad_code_random_alt_1_split' => '100',
1348
- 'ad_code_random_alt_2_split' => '100',
1349
- 'rnd_align' => 'd',
1350
- 'rnd_clear' => 'd',
1351
- 'rnd_margin_top' => 'd',
1352
- 'rnd_margin_bottom' => 'd',
1353
- 'rnd_padding_top' => 'd',
1354
- 'rnd_padding_bottom' => 'd',
1355
- 'start_from_paragraph' => 'd',
1356
- 'random_ads_after_mode' => 'at',
1357
- 'random_ads_after_unit' => 'paragraph',
1358
  'rnd_allow_ads_on_last_paragraph' => '',
1359
  'rnd_reselect_ad_per_position_in_post' => '',
1360
  'multiple_ads_at_same_position' => '',
1361
- 'random_category_condition_mode' => 'o',
1362
- 'random_category_condition_entries' => '',
1363
- 'random_tag_condition_mode' => 'o',
1364
- 'random_tag_condition_entries' => '',
1365
- 'random_author_condition_mode' => 'o',
1366
- 'random_author_condition_entries' => '',
1367
- 'random_id_condition_mode' => 'o',
1368
- 'random_id_condition_entries' => '',
1369
- 'random_exclude_front' => '',
1370
- 'random_exclude_home' => '',
1371
- 'random_exclude_page' => '',
1372
- 'random_exclude_single' => '',
1373
- 'random_exclude_archive' => '',
1374
- 'random_exclude_search' => '',
1375
- 'random_exclude_404' => '',
1376
  // single posts and pages
1377
  'top_ad_if_longer_than' => 'd',
1378
  'max_num_of_ads' => '2', // random ads
@@ -1428,27 +1433,31 @@ function adinj_default_options(){
1428
  'ad_code_top_alt_2' => '',
1429
  'ad_code_top_alt_1_split' => '100',
1430
  'ad_code_top_alt_2_split' => '100',
1431
- 'top_align' => 'd',
1432
- 'top_clear' => 'd',
1433
- 'top_margin_top' => 'd',
1434
- 'top_margin_bottom' => 'd',
1435
- 'top_padding_top' => 'd',
1436
- 'top_padding_bottom' => 'd',
1437
- 'top_category_condition_mode' => 'o',
1438
- 'top_category_condition_entries' => '',
1439
- 'top_tag_condition_mode' => 'o',
1440
- 'top_tag_condition_entries' => '',
1441
- 'top_author_condition_mode' => 'o',
1442
- 'top_author_condition_entries' => '',
1443
- 'top_id_condition_mode' => 'o',
1444
- 'top_id_condition_entries' => '',
1445
- 'top_exclude_front' => '',
1446
- 'top_exclude_home' => '',
1447
- 'top_exclude_page' => '',
1448
- 'top_exclude_single' => '',
1449
- 'top_exclude_archive' => '',
1450
- 'top_exclude_search' => '',
1451
- 'top_exclude_404' => '',
 
 
 
 
1452
  // Bottom ads
1453
  'ad_code_bottom_1' => '',
1454
  'ad_code_bottom_2' => '',
@@ -1474,27 +1483,6 @@ function adinj_default_options(){
1474
  'ad_code_bottom_alt_2' => '',
1475
  'ad_code_bottom_alt_1_split' => '100',
1476
  'ad_code_bottom_alt_2_split' => '100',
1477
- 'bottom_align' => 'd',
1478
- 'bottom_clear' => 'd',
1479
- 'bottom_margin_top' => 'd',
1480
- 'bottom_margin_bottom' => 'd',
1481
- 'bottom_padding_top' => 'd',
1482
- 'bottom_padding_bottom' => 'd',
1483
- 'bottom_category_condition_mode' => 'o',
1484
- 'bottom_category_condition_entries' => '',
1485
- 'bottom_tag_condition_mode' => 'o',
1486
- 'bottom_tag_condition_entries' => '',
1487
- 'bottom_author_condition_mode' => 'o',
1488
- 'bottom_author_condition_entries' => '',
1489
- 'bottom_id_condition_mode' => 'o',
1490
- 'bottom_id_condition_entries' => '',
1491
- 'bottom_exclude_front' => '',
1492
- 'bottom_exclude_home' => '',
1493
- 'bottom_exclude_page' => '',
1494
- 'bottom_exclude_single' => '',
1495
- 'bottom_exclude_archive' => '',
1496
- 'bottom_exclude_search' => '',
1497
- 'bottom_exclude_404' => '',
1498
  // Footer ads
1499
  'ad_code_footer_1' => '',
1500
  'ad_code_footer_2' => '',
@@ -1520,12 +1508,73 @@ function adinj_default_options(){
1520
  'ad_code_footer_alt_2' => '',
1521
  'ad_code_footer_alt_1_split' => '100',
1522
  'ad_code_footer_alt_2_split' => '100',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1523
  'footer_align' => 'center',
1524
  'footer_clear' => 'd',
1525
  'footer_margin_top' => 'd',
1526
  'footer_margin_bottom' => 'd',
1527
  'footer_padding_top' => 'd',
1528
  'footer_padding_bottom' => '3',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1529
  'footer_category_condition_mode' => 'o',
1530
  'footer_category_condition_entries' => '',
1531
  'footer_tag_condition_mode' => 'o',
@@ -1534,6 +1583,35 @@ function adinj_default_options(){
1534
  'footer_author_condition_entries' => '',
1535
  'footer_id_condition_mode' => 'o',
1536
  'footer_id_condition_entries' => '',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1537
  'footer_exclude_front' => '',
1538
  'footer_exclude_home' => '',
1539
  'footer_exclude_page' => '',
@@ -1541,7 +1619,6 @@ function adinj_default_options(){
1541
  'footer_exclude_archive' => '',
1542
  'footer_exclude_search' => '',
1543
  'footer_exclude_404' => '',
1544
- // widgets
1545
  'widget_exclude_front' => '',
1546
  'widget_exclude_home' => '',
1547
  'widget_exclude_page' => '',
@@ -1549,7 +1626,6 @@ function adinj_default_options(){
1549
  'widget_exclude_archive' => '',
1550
  'widget_exclude_search' => '',
1551
  'widget_exclude_404' => '',
1552
- // template ads
1553
  'template_exclude_front' => '',
1554
  'template_exclude_home' => '',
1555
  'template_exclude_page' => '',
@@ -1557,15 +1633,6 @@ function adinj_default_options(){
1557
  'template_exclude_archive' => '',
1558
  'template_exclude_search' => '',
1559
  'template_exclude_404' => '',
1560
- // dynamic features
1561
- 'ad_insertion_mode' => 'mfunc',
1562
- 'sevisitors_only' => 'off',
1563
- 'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search.',
1564
- 'block_keywords' => 'off',
1565
- 'blocked_keywords' => '',
1566
- 'block_ads_for_hours' => '24',
1567
- 'block_ips' => 'off',
1568
- 'blocked_ips' => '',
1569
  // ui main tab
1570
  'ui_global_hide' => 'false',
1571
  'ui_adsettings_hide' => 'false',
149
  function adinj_config_blocked_ips() { return array($ip_list); }
150
 
151
  function adinj_config_block_keywords() { return $block_keywords; }
152
+ function adinj_config_blocked_keywords() { return array($keyword_list); }
153
 
154
  function adinj_config_debug_mode() { return $debug_mode; }
155
 
335
 
336
  } else if (!isset($_GET['tab'])){
337
  echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
338
+ echo "14th September 2011: This is a big update with many new positioning options for top/random/bottom ads and completely re-written ad insertion code. More details of some of the new features are on <a href='http://www.advancedhtml.co.uk/ad-injection-1-2-0-0-preview-wordpress-ad-management-plugin/' target='_new'>Advanced HTML</a>. I've tested this as much as I can, but some bugs may have slipped through. I'm waiting to fix them as soon as I hear about them! Please contact me ASAP if you spot any bugs, or odd behaviour via the ".'<a href="'.adinj_feedback_url().'" target="_new">quick feedback form</a>.';
339
  echo '</strong></p></div>';
340
  }
341
  }
431
  if ($all != NULL && adinj_ticked($name)){
432
  ?>
433
  <script type="text/javascript">
434
+ //document.write('<style type="text/css" media="screen">.<?php echo $class; ?> { display: none; }</style>');
435
+ document.write('<style type="text/css" media="screen">.<?php echo $class; ?> { opacity:0.3; filter:alpha(opacity=30)" }</style>');
436
  </script>
437
  <?php
438
  }
448
  $current = 'main';
449
  }
450
  }
451
+ $tabs = array( 'main' => __( 'Main', 'ad-injection' ), 'adrotation' => __( 'Ad codes / Ad rotation', 'ad-injection' ), 'debug' => __( 'Debug' ) );
452
  $links = array();
453
  foreach( $tabs as $tab => $name ) {
454
  if ( $current == $tab ) {
468
  $ops = adinj_options();
469
  ?>
470
  <div class='postbox-container' style='width:<?php echo $width; ?>;float:left; clear:left;'>
471
+ <a name="<?php echo $anchor; ?>"></a>
472
  <div class="metabox-holder">
473
  <div class="postbox">
474
  <input type="submit" style="float:right" class="button-primary" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
503
  HTML;
504
  ?>
505
 
506
+ <h3><?php $info = adinj_get_status($anchor); echo adinj_dot($info[0]); ?> <?php echo adinj_get_logo() . ' ' . $title; ?></h3>
507
  <?php if($hide == 'true'){ ?>
508
  <div id="<?php echo $anchor; ?>-box" class="hiddenbox">
509
  <?php } else { ?>
559
  if ($ops['sevisitors_only'] == 'on'){
560
  $status[1] .= 'referrer';
561
  }
562
+ if ($ops['sevisitors_only'] == 'on'){
563
+ $status[1] .= ' keywords';
564
+ }
565
  if ($ops['block_ips'] == 'on' && !empty($ops['blocked_ips'])){
566
  $status[1] .= ' ip';
567
  }
568
+ } else if ($name == 'older_than_normal'){
569
+ $status[0] = 'green';
570
+ $days = $ops['ads_on_page_older_than'];
571
+ $status[1] = "> $days days";
572
+ } else if ($name == 'older_than_widgets'){
573
+ $status[0] = 'green';
574
+ $days = $ops['widgets_on_page_older_than'];
575
+ $status[1] = "> $days days";
576
  } else if ($name == 'adsettings'){
577
  $status[0] = 'green';
578
  } else if ($name == 'adverts'){
581
  } else {
582
  $status[0] = 'red';
583
  }
584
+ } else if ($name == 'filters'){
585
+ $status[0] = 'green';
586
  } else if ($name == 'debugging'){
587
  $val = $ops['debug_mode'];
588
  if ($val == 'on'){
676
  }
677
  echo "<option value=\"$option_value\" ";
678
  if("$selected_value" == "$option_value" ||
 
679
  "$selected_value" == ADINJ_DISABLED && "$option_value" == 'd' || //todo remove?
680
  "$selected_value" == ADINJ_NA && "$option_value" == 'd' ||
681
  "$selected_value" == ADINJ_RULE_DISABLED && "$option_value" == 'd' || //todo remove?
684
  echo 'selected="selected"';
685
  }
686
  $typetxt = $type;
687
+ if (adinj_not_set($option_value)) $typetxt = "";
688
  if ("$option_value" === 'a') { $display_value = ADINJ_NA; } //TODO remove?
689
  if ("$option_value" === 'd') { $display_value = ADINJ_NA; }
690
  if ("$option_value" === 'o') { $display_value = ADINJ_ONLY_SHOW_IN; }
707
  }
708
  function adinj_toggle_tick_boxes(name, hide){
709
  if (hide){
710
+ //jQuery('.'+name).hide();
711
+ jQuery('.'+name).css({ opacity: 0.3 });
712
+ //jQuery('.'+name+' :input').attr('disabled', true);
713
+ //jQuery('.'+name+' :input').attr('readonly', true)
714
  } else {
715
+ //jQuery('.'+name).show();
716
+ jQuery('.'+name).css({ opacity: 1.0 });
717
+ //jQuery('.'+name+' :input').removeAttr('disabled');
718
+ //jQuery('.'+name+' :input').removeAttr('readonly');
719
  }
720
  }
721
  </script>
797
  if ($type == 'category') {
798
  $categories = get_categories();
799
  $cat = NULL;
800
+ foreach ($categories as $cat) {
801
  $nicename = rawurldecode($cat->category_nicename);
802
  echo '<option value="'.$nicename.'">'.$nicename.' ('.$cat->category_count.')</option>';
803
  }
818
  } else if ($type == 'author') {
819
  $authors = adinj_get_authors();
820
  $author = NULL;
821
+ foreach ($authors as $author) {
822
  $login = $author->user_login;
823
  $displayname = $author->display_name;
824
  echo '<option value="'.$login.'">'.$login.' ('.$displayname.')</option>';
845
  $tags = get_tags(array('number' => $quantity, 'offset' => $offset));
846
  if (count($tags) == 0) return false;
847
  $tag = NULL;
848
+ foreach ($tags as $tag) {
849
  $slug = rawurldecode($tag->slug);
850
  echo '<option value="'.$slug.'">'.$slug.' ('.$tag->count.')</option>';
851
  }
863
  return $authors;
864
  }
865
 
866
+ function adinj_table_width($table){
867
+ global $wp_db_version;
868
+ if ($table == 'ad'){
869
+ if ($wp_db_version < 18226){
870
+ echo '60';
871
+ } else { //WP3.2+
872
+ echo '70';
873
+ }
874
+ } else if ($table == 'rotation'){
875
+ if ($wp_db_version < 18226){
876
+ echo '65';
877
+ } else { //WP3.2+
878
+ echo '75';
879
+ }
880
+ } else if ($table == 'dynamic'){
881
+ if ($wp_db_version < 18226){
882
+ echo '70';
883
+ } else { //WP3.2+
884
+ echo '80';
885
+ }
886
+ } else {
887
+ echo '61';
888
+ }
889
+ }
890
+
891
  function adinj_add_alignment_options($prefix){
892
  adinj_add_alignment_clear_options($prefix);
893
  echo "<br />";
1330
  $new_options['widgets_on_page_older_than'] = $stored_options['ads_on_page_older_than'];
1331
  }
1332
 
1333
+ if ($stored_dbversion < 18){
1334
+ // todo test
1335
+ $new_options['random_ads_start_mode'] = $stored_options['random_ads_after_mode'];
1336
+ $new_options['random_ads_start_unit'] = $stored_options['random_ads_after_unit'];
1337
+ $new_options['random_ads_start_at'] = $stored_options['start_from_paragraph'];
1338
+ if ($new_options['random_ads_start_at'] == 'd'){
1339
+ $new_options['random_ads_start_mode'] = 'anywhere';
1340
+ $new_options['random_ads_start_at'] = '1';
1341
+ }
1342
+ }
1343
+
1344
  // 3. Bump up db version number.
1345
  $new_options['db_version'] = $new_dbversion;
1346
 
1361
  'ads_enabled' => 'off',
1362
  'ads_on_page_older_than' => '0',
1363
  'widgets_on_page_older_than' => '0',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1364
  'content_length_unit' => 'words',
1365
+ // random ad start/end position
1366
+ 'random_ads_start_mode' => 'anywhere',
1367
+ 'random_ads_start_unit' => 'paragraph',
1368
+ 'random_ads_start_at' => '1',
1369
+ 'random_ads_end_mode' => 'anywhere',
1370
+ 'random_ads_end_unit' => 'paragraph',
1371
+ 'random_ads_end_at' => '20',
1372
+ 'random_ads_end_direction' => 'fromstart',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1373
  'rnd_allow_ads_on_last_paragraph' => '',
1374
  'rnd_reselect_ad_per_position_in_post' => '',
1375
  'multiple_ads_at_same_position' => '',
1376
+ // top/bottom ad position
1377
+ 'top_ad_position' => '0',
1378
+ 'top_ad_position_unit' => 'paragraph',
1379
+ 'bottom_ad_position' => '0',
1380
+ 'bottom_ad_position_unit' => 'paragraph',
 
 
 
 
 
 
 
 
 
 
1381
  // single posts and pages
1382
  'top_ad_if_longer_than' => 'd',
1383
  'max_num_of_ads' => '2', // random ads
1433
  'ad_code_top_alt_2' => '',
1434
  'ad_code_top_alt_1_split' => '100',
1435
  'ad_code_top_alt_2_split' => '100',
1436
+ // Random ads
1437
+ 'ad_code_random_1' => '',
1438
+ 'ad_code_random_2' => '',
1439
+ 'ad_code_random_3' => '',
1440
+ 'ad_code_random_4' => '',
1441
+ 'ad_code_random_5' => '',
1442
+ 'ad_code_random_6' => '',
1443
+ 'ad_code_random_7' => '',
1444
+ 'ad_code_random_8' => '',
1445
+ 'ad_code_random_9' => '',
1446
+ 'ad_code_random_10' => '',
1447
+ 'ad_code_random_1_split' => '100',
1448
+ 'ad_code_random_2_split' => '100',
1449
+ 'ad_code_random_3_split' => '100',
1450
+ 'ad_code_random_4_split' => '100',
1451
+ 'ad_code_random_5_split' => '100',
1452
+ 'ad_code_random_6_split' => '100',
1453
+ 'ad_code_random_7_split' => '100',
1454
+ 'ad_code_random_8_split' => '100',
1455
+ 'ad_code_random_9_split' => '100',
1456
+ 'ad_code_random_10_split' => '100',
1457
+ 'ad_code_random_alt_1' => '',
1458
+ 'ad_code_random_alt_2' => '',
1459
+ 'ad_code_random_alt_1_split' => '100',
1460
+ 'ad_code_random_alt_2_split' => '100',
1461
  // Bottom ads
1462
  'ad_code_bottom_1' => '',
1463
  'ad_code_bottom_2' => '',
1483
  'ad_code_bottom_alt_2' => '',
1484
  'ad_code_bottom_alt_1_split' => '100',
1485
  'ad_code_bottom_alt_2_split' => '100',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1486
  // Footer ads
1487
  'ad_code_footer_1' => '',
1488
  'ad_code_footer_2' => '',
1508
  'ad_code_footer_alt_2' => '',
1509
  'ad_code_footer_alt_1_split' => '100',
1510
  'ad_code_footer_alt_2_split' => '100',
1511
+ // dynamic features
1512
+ 'ad_insertion_mode' => 'mfunc',
1513
+ 'sevisitors_only' => 'off',
1514
+ 'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search.',
1515
+ 'block_keywords' => 'off',
1516
+ 'blocked_keywords' => '',
1517
+ 'block_ads_for_hours' => '24',
1518
+ 'block_ips' => 'off',
1519
+ 'blocked_ips' => '',
1520
+ // ad display (layout) settings
1521
+ 'top_align' => 'd',
1522
+ 'top_clear' => 'd',
1523
+ 'top_margin_top' => 'd',
1524
+ 'top_margin_bottom' => 'd',
1525
+ 'top_padding_top' => 'd',
1526
+ 'top_padding_bottom' => 'd',
1527
+ 'rnd_align' => 'd',
1528
+ 'rnd_clear' => 'd',
1529
+ 'rnd_margin_top' => 'd',
1530
+ 'rnd_margin_bottom' => 'd',
1531
+ 'rnd_padding_top' => 'd',
1532
+ 'rnd_padding_bottom' => 'd',
1533
+ 'bottom_align' => 'd',
1534
+ 'bottom_clear' => 'd',
1535
+ 'bottom_margin_top' => 'd',
1536
+ 'bottom_margin_bottom' => 'd',
1537
+ 'bottom_padding_top' => 'd',
1538
+ 'bottom_padding_bottom' => 'd',
1539
  'footer_align' => 'center',
1540
  'footer_clear' => 'd',
1541
  'footer_margin_top' => 'd',
1542
  'footer_margin_bottom' => 'd',
1543
  'footer_padding_top' => 'd',
1544
  'footer_padding_bottom' => '3',
1545
+ // category, tag, author, id filters
1546
+ 'global_category_condition_mode' => 'o',
1547
+ 'global_category_condition_entries' => '',
1548
+ 'global_tag_condition_mode' => 'o',
1549
+ 'global_tag_condition_entries' => '',
1550
+ 'global_author_condition_mode' => 'o',
1551
+ 'global_author_condition_entries' => '',
1552
+ 'global_id_condition_mode' => 'o',
1553
+ 'global_id_condition_entries' => '',
1554
+ 'top_category_condition_mode' => 'o',
1555
+ 'top_category_condition_entries' => '',
1556
+ 'top_tag_condition_mode' => 'o',
1557
+ 'top_tag_condition_entries' => '',
1558
+ 'top_author_condition_mode' => 'o',
1559
+ 'top_author_condition_entries' => '',
1560
+ 'top_id_condition_mode' => 'o',
1561
+ 'top_id_condition_entries' => '',
1562
+ 'random_category_condition_mode' => 'o',
1563
+ 'random_category_condition_entries' => '',
1564
+ 'random_tag_condition_mode' => 'o',
1565
+ 'random_tag_condition_entries' => '',
1566
+ 'random_author_condition_mode' => 'o',
1567
+ 'random_author_condition_entries' => '',
1568
+ 'random_id_condition_mode' => 'o',
1569
+ 'random_id_condition_entries' => '',
1570
+ 'bottom_category_condition_mode' => 'o',
1571
+ 'bottom_category_condition_entries' => '',
1572
+ 'bottom_tag_condition_mode' => 'o',
1573
+ 'bottom_tag_condition_entries' => '',
1574
+ 'bottom_author_condition_mode' => 'o',
1575
+ 'bottom_author_condition_entries' => '',
1576
+ 'bottom_id_condition_mode' => 'o',
1577
+ 'bottom_id_condition_entries' => '',
1578
  'footer_category_condition_mode' => 'o',
1579
  'footer_category_condition_entries' => '',
1580
  'footer_tag_condition_mode' => 'o',
1583
  'footer_author_condition_entries' => '',
1584
  'footer_id_condition_mode' => 'o',
1585
  'footer_id_condition_entries' => '',
1586
+ // exclusion tick boxes
1587
+ 'exclude_front' => '',
1588
+ 'exclude_home' => '',
1589
+ 'exclude_page' => '',
1590
+ 'exclude_single' => '',
1591
+ 'exclude_archive' => '',
1592
+ 'exclude_search' => 'on',
1593
+ 'exclude_404' => 'on',
1594
+ 'top_exclude_front' => '',
1595
+ 'top_exclude_home' => '',
1596
+ 'top_exclude_page' => '',
1597
+ 'top_exclude_single' => '',
1598
+ 'top_exclude_archive' => '',
1599
+ 'top_exclude_search' => '',
1600
+ 'top_exclude_404' => '',
1601
+ 'random_exclude_front' => '',
1602
+ 'random_exclude_home' => '',
1603
+ 'random_exclude_page' => '',
1604
+ 'random_exclude_single' => '',
1605
+ 'random_exclude_archive' => '',
1606
+ 'random_exclude_search' => '',
1607
+ 'random_exclude_404' => '',
1608
+ 'bottom_exclude_front' => '',
1609
+ 'bottom_exclude_home' => '',
1610
+ 'bottom_exclude_page' => '',
1611
+ 'bottom_exclude_single' => '',
1612
+ 'bottom_exclude_archive' => '',
1613
+ 'bottom_exclude_search' => '',
1614
+ 'bottom_exclude_404' => '',
1615
  'footer_exclude_front' => '',
1616
  'footer_exclude_home' => '',
1617
  'footer_exclude_page' => '',
1619
  'footer_exclude_archive' => '',
1620
  'footer_exclude_search' => '',
1621
  'footer_exclude_404' => '',
 
1622
  'widget_exclude_front' => '',
1623
  'widget_exclude_home' => '',
1624
  'widget_exclude_page' => '',
1626
  'widget_exclude_archive' => '',
1627
  'widget_exclude_search' => '',
1628
  'widget_exclude_404' => '',
 
1629
  'template_exclude_front' => '',
1630
  'template_exclude_home' => '',
1631
  'template_exclude_page' => '',
1633
  'template_exclude_archive' => '',
1634
  'template_exclude_search' => '',
1635
  'template_exclude_404' => '',
 
 
 
 
 
 
 
 
 
1636
  // ui main tab
1637
  'ui_global_hide' => 'false',
1638
  'ui_adsettings_hide' => 'false',
ad-injection-widget.php CHANGED
@@ -1,378 +1,378 @@
1
- <?php
2
- /*
3
- Part of the Ad Injection plugin for WordPress
4
- http://www.reviewmylife.co.uk/
5
- */
6
-
7
- // 1 = original
8
- // 2 = split testing / alt content
9
- // 3 = increase db rotation slots to 10 - no UI support yet
10
- // 4 = added ui show fields for ads 4-10. Category/tag/author conditions.
11
- // 5 = ad/alt pool show fields
12
- // 6 = page type restrictions
13
- // 7 = align and clear
14
- // 8 = post/page id restrictions
15
- define('ADINJ_WIDGET_DB_VERSION', 8);
16
-
17
- class Ad_Injection_Widget extends WP_Widget {
18
- function Ad_Injection_Widget() {
19
- $widget_ops = array( 'classname' => 'adinjwidget', 'description' => 'Insert Ad Injection adverts into your sidebars/widget areas.' );
20
- $control_ops = array( 'width' => 500, 'height' => 300, 'id_base' => 'adinj' );
21
- $this->WP_Widget( 'adinj', 'Ad Injection', $widget_ops, $control_ops );
22
- }
23
-
24
- function widget( $args, $instance ) {
25
- if (adinj_ads_completely_disabled_from_page('widget')) return;
26
-
27
- if ((is_front_page() && adinj_ticked('widget_exclude_front')) ||
28
- (is_home() && adinj_ticked('widget_exclude_home')) ||
29
- (is_page() && adinj_ticked('widget_exclude_page')) ||
30
- (is_single() && adinj_ticked('widget_exclude_single')) ||
31
- (is_archive() && adinj_ticked('widget_exclude_archive')) ||
32
- (is_search() && adinj_ticked('widget_exclude_search')) ||
33
- (is_404() && adinj_ticked('widget_exclude_404'))){
34
- return;
35
- }
36
-
37
- if ((is_front_page() && adinj_ticked('exclude_front', $instance)) ||
38
- (is_home() && adinj_ticked('exclude_home', $instance)) ||
39
- (is_page() && adinj_ticked('exclude_page', $instance)) ||
40
- (is_single() && adinj_ticked('exclude_single', $instance)) ||
41
- (is_archive() && adinj_ticked('exclude_archive', $instance)) ||
42
- (is_search() && adinj_ticked('exclude_search', $instance)) ||
43
- (is_404() && adinj_ticked('exclude_404', $instance))){
44
- return;
45
- }
46
-
47
- if (!adinj_allowed_in_category('widget', $instance)) return;
48
- if (!adinj_allowed_in_tag('widget', $instance)) return;
49
- if (!adinj_allowed_in_author('widget', $instance)) return;
50
- if (!adinj_allowed_in_id('widget', $instance)) return;
51
-
52
- extract( $args );
53
-
54
- $ops = adinj_options();
55
-
56
- $include = "";
57
- if (adinj_mfunc_mode()){
58
- $include = adinj_ad_code_include();
59
- }
60
-
61
- $title = apply_filters('widget_title', $instance['title'] );
62
-
63
- // The old 'non upgraded' db will be passed here if the widget hasn't
64
- // been resaved. We can't upgrade as doing so would mean we'd have to
65
- // re-save the widget files - which we can't do as we can't re-write
66
- // the settings back to the db (at least not without a bit more work)
67
- $adcode = adinj_get_ad_code('widget_'.$this->get_id(), $instance);
68
-
69
- echo $before_widget;
70
- if ( $title ) {
71
- echo $before_title . $title . $after_title;
72
- }
73
-
74
- if ( !empty($adcode) ){
75
- echo $include;
76
- echo $adcode;
77
- }
78
-
79
- echo $after_widget;
80
- }
81
-
82
- function update( $new_instance, $old_instance ){
83
- $updated = $this->adinj_upgrade_widget_db($new_instance, $old_instance);
84
-
85
- // Only strip tags when potential for updated title
86
- $updated['title'] = strip_tags( $new_instance['title'] );
87
-
88
- // After first save mark it as saved
89
- $updated['saved'] = 1;
90
-
91
- for ($i=1; $i<=10; ++$i){
92
- write_ad_to_file($updated['advert_'.$i], $this->get_ad_file_path($i));
93
- }
94
- for ($i=1; $i<=3; ++$i){
95
- write_ad_to_file($updated['advert_alt_'.$i], $this->get_alt_file_path($i));
96
- }
97
-
98
- return $updated;
99
- }
100
-
101
- function default_options(){
102
- /* Set up some default widget settings. */
103
- return array(
104
- 'title' => '',
105
- //adverts
106
- 'advert_1' => '',
107
- 'advert_1_split' => '100',
108
- 'advert_2' => '',
109
- 'advert_2_split' => '100',
110
- 'advert_3' => '',
111
- 'advert_3_split' => '100',
112
- 'advert_4' => '',
113
- 'advert_4_split' => '100',
114
- 'advert_5' => '',
115
- 'advert_5_split' => '100',
116
- 'advert_6' => '',
117
- 'advert_6_split' => '100',
118
- 'advert_7' => '',
119
- 'advert_7_split' => '100',
120
- 'advert_8' => '',
121
- 'advert_8_split' => '100',
122
- 'advert_9' => '',
123
- 'advert_9_split' => '100',
124
- 'advert_10' => '',
125
- 'advert_10_split' => '100',
126
- 'advert_alt_1' => '',
127
- 'advert_alt_1_split' => '100',
128
- 'advert_alt_2' => '',
129
- 'advert_alt_2_split' => '100',
130
- 'advert_alt_3' => '',
131
- 'advert_alt_3_split' => '100',
132
- //settings
133
- 'margin_top' => 'd',
134
- 'margin_bottom' => 'd',
135
- 'padding_top' => 'd',
136
- 'padding_bottom' => 'd',
137
- 'align' => 'd',
138
- 'clear' => 'd',
139
- 'widget_category_condition_mode' => 'o',
140
- 'widget_category_condition_entries' => '',
141
- 'widget_tag_condition_mode' => 'o',
142
- 'widget_tag_condition_entries' => '',
143
- 'widget_author_condition_mode' => 'o',
144
- 'widget_author_condition_entries' => '',
145
- 'widget_id_condition_mode' => 'o',
146
- 'widget_id_condition_entries' => '',
147
- 'exclude_front' => '',
148
- 'exclude_home' => '',
149
- 'exclude_page' => '',
150
- 'exclude_single' => '',
151
- 'exclude_archive' => '',
152
- 'exclude_search' => '',
153
- 'exclude_404' => '',
154
- //ui
155
- 'ui_ad_1_show' => 'true',
156
- 'ui_pagetypes_show' => 'false',
157
- 'ui_conditions_show' => 'false',
158
- 'ui_spacing_show' => 'false',
159
- 'ui_ad_pool_show' => 'false',
160
- 'ui_ad_2_show' => 'false',
161
- 'ui_ad_3_show' => 'false',
162
- 'ui_ad_4_show' => 'false',
163
- 'ui_ad_5_show' => 'false',
164
- 'ui_ad_6_show' => 'false',
165
- 'ui_ad_7_show' => 'false',
166
- 'ui_ad_8_show' => 'false',
167
- 'ui_ad_9_show' => 'false',
168
- 'ui_ad_10_show' => 'false',
169
- 'ui_alt_pool_show' => 'false',
170
- 'ui_alt_1_show' => 'false',
171
- 'ui_alt_2_show' => 'false',
172
- 'ui_alt_3_show' => 'false',
173
- 'saved' => 0,
174
- //
175
- 'db_version' => ADINJ_WIDGET_DB_VERSION
176
- );
177
- }
178
-
179
- function adinj_upgrade_widget_db($new_instance, $old_instance){
180
- // Copy old values across to default
181
- $updated = $this->default_options();
182
- foreach ($updated as $key => $value){
183
- if (array_key_exists($key, $new_instance)){
184
- $updated[$key] = $new_instance[$key];
185
- }
186
- }
187
-
188
- // Upgrade any options as necessary
189
- $old_dbversion = adinj_db_version($old_instance);
190
- if ($old_dbversion == 1){
191
- $updated['advert_1'] = $old_instance['advert'];
192
- }
193
-
194
- $updated['db_version'] = ADINJ_WIDGET_DB_VERSION;
195
-
196
- return $updated;
197
- }
198
-
199
- function form( $instance ) {
200
- $instance = $this->adinj_upgrade_widget_db($instance, $instance);
201
-
202
- $savedfieldname = $this->get_field_name('saved');
203
- $savedfieldvalue = $instance['saved'];
204
- ?>
205
-
206
- <input type='hidden' <?php $this->add_name('db_version'); ?> value='<?php echo $defaults['db_version']; ?>' />
207
- <input type='hidden' name="$savedfieldname" value='$savedfieldvalue' />
208
-
209
- <p>
210
- <b>Title:</b><br />
211
- <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" style="width:490px;" />
212
- <br />
213
- <span style="font-size:10px;">Make sure any title 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>
214
- </p>
215
-
216
- <style type="text/css">
217
- .adinjtable td { vertical-align: top; }
218
- </style>
219
-
220
- <table border="0" width="490px" class="adinjtable">
221
- <?php
222
- $total_ad_split = adinj_total_split('advert_', $instance);
223
- $this->add_row('advert_', 1, 'Ad code 1', 'ui_ad_1_show', $total_ad_split, $instance);
224
- ?>
225
- </table>
226
-
227
- <?php
228
- if ($savedfieldvalue != 1){
229
- echo '<b>The widget needs to be saved for first time to activate the other options.</b>';
230
- return;
231
- }
232
- ?>
233
-
234
- <br />
235
- <b> Exclude this widget from page types</b>
236
- <?php $this->add_show_hide_section('ad_pagetypes_'.uniqid(''), 'ui_pagetypes_show', $instance); ?>
237
- <?php
238
- $count_pages = wp_count_posts('page', 'readable');
239
- $count_posts = wp_count_posts('post', 'readable');
240
- ?>
241
- <?php $this->add_checkbox('exclude_front', $instance) ?>front - <?php echo get_bloginfo('url'); ?><br />
242
- <?php $this->add_checkbox('exclude_home', $instance) ?>home page (latest posts page - may or may not be same as front)<br />
243
- <?php $this->add_checkbox('exclude_page', $instance) ?>page - <?php echo $count_pages->publish; ?> single page(s)<br />
244
- <?php $this->add_checkbox('exclude_single', $instance) ?>single - <?php echo $count_posts->publish; ?> single post(s)<br />
245
- <?php $this->add_checkbox('exclude_archive', $instance) ?>archive - categories, tags, authors, dates<br />
246
- <?php $this->add_checkbox('exclude_search', $instance) ?>search<br />
247
- <?php $this->add_checkbox('exclude_404', $instance) ?>404<br />
248
- <span style="font-size:10px;"><b>Notes:</b> Your home page is the page displaying your latest posts. It may be different to your front page if you have configured your front page to be a static page.</span><br />
249
- <span style="font-size:10px;">If you have <a href='options-reading.php'>set your front page</a> to be a static 'page' rather than your latest posts, the 'page' tick box will also apply to the front page.</span>
250
- </div>
251
-
252
- <br />
253
- <b> Category, tag, author and id conditions</b>
254
- <?php
255
- $this->add_show_hide_section('ad_restrictions_'.uniqid(''), 'ui_conditions_show', $instance);
256
- adinj_condition_table('widget_category', 'category slugs. e.g: cat1, cat2, cat3', 'category', $instance, $this->get_field_name('widget_category_condition_mode'), $this->get_field_name('widget_category_condition_entries'));
257
- adinj_condition_table('widget_tag', 'tag slugs. e.g: tag1, tag2, tag3', 'tag', $instance, $this->get_field_name('widget_tag_condition_mode'), $this->get_field_name('widget_tag_condition_entries'));
258
- adinj_condition_table('widget_author', 'author nicknames. e.g: john, paul', 'author', $instance, $this->get_field_name('widget_author_condition_mode'), $this->get_field_name('widget_author_condition_entries'));
259
- adinj_condition_table('widget_id', 'post/page ids. e.g: 7, 23, 276', 'id', $instance, $this->get_field_name('widget_id_condition_mode'), $this->get_field_name('widget_id_condition_entries'));
260
- echo '</div>'
261
- ?>
262
-
263
- <br />
264
- <b> Spacing and alignment options</b>
265
- <?php $this->add_show_hide_section('ad_spacing_'.uniqid(''), 'ui_spacing_show', $instance); ?>
266
- <table border="0" width="490px" class="adinjtable">
267
- <tr><td>
268
- <?php adinj_add_alignment_clear_options('widget_', $instance, $this->get_field_name('align'), $this->get_field_name('clear') ); ?>
269
- </td><td>
270
- <?php adinj_add_margin_top_bottom_options('widget_', $instance, $this->get_field_name('margin_top'), $this->get_field_name('margin_bottom') ); ?>
271
- </td><td>
272
- <?php adinj_add_padding_top_bottom_options('widget_', $instance, $this->get_field_name('padding_top'), $this->get_field_name('padding_bottom') ); ?>
273
- </td></tr>
274
- </table>
275
- </div>
276
-
277
- <br />
278
- <b> Ad rotation pool</b>
279
- <?php $this->add_show_hide_section('ad_pool_'.uniqid(''), 'ui_ad_pool_show', $instance); ?>
280
- <table border="0" width="490px" class="adinjtable">
281
- <?php
282
- for ($i=2; $i<=10; ++$i){
283
- $this->add_row('advert_', $i, 'Ad code '.$i, 'ui_ad_'.$i.'_show', $total_ad_split, $instance);
284
- }
285
- ?>
286
- </table></div>
287
-
288
- <br />
289
- <b> Alt content pool</b>
290
- <?php $this->add_show_hide_section('alt_pool_'.uniqid(''), 'ui_alt_pool_show', $instance); ?>
291
- <table border="0" cellspacing="5" width="490px" class="adinjtable">
292
- <?php
293
- $total_alt_split = adinj_total_split('advert_alt_', $instance);
294
- for ($i=1; $i<=3; ++$i){
295
- $this->add_row('advert_alt_', $i, 'Alt content '.$i, 'ui_alt_'.$i.'_show', $total_alt_split, $instance);
296
- }
297
- ?>
298
- </table></div>
299
-
300
- <br />
301
-
302
- <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>. You can also set a global <a href='options-general.php?page=ad-injection.php#global'>page type</a> restriction for the widgets.</p>
303
-
304
- <?php
305
- }
306
-
307
- function add_checkbox($name, $instance){
308
- ?>
309
- <input type="hidden" <?php $this->add_name($name); ?> value="off" />
310
- <input type="checkbox" <?php $this->add_name($name); ?> <?php echo adinj_ticked($name, $instance); ?> />
311
- <?php
312
- }
313
-
314
- function add_row($op_stem, $num, $label, $show_op, $total_split, $ops){
315
- $op = $op_stem.$num;
316
- $op_split = $op.'_split';
317
- $anchorid = $op.'_'.uniqid('');
318
-
319
- $percentage_split = adinj_percentage_split($op_stem, $num, $ops, $total_split);
320
- ?>
321
- <tr><td colspan='2'>
322
- <input style="float:right; padding:0; margin:0;" <?php $this->add_name($op_split); ?> size="7" value="<?php echo $ops[$op_split]; ?>" />
323
-
324
- <?php
325
- echo <<<HTML
326
- <b> $label</b> <label style='float:right'>(Rotation: $percentage_split)</label>
327
-
328
- HTML;
329
- $this->add_show_hide_section($anchorid, $show_op, $ops);
330
-
331
- if ($op_stem == 'advert_' && $num == 2){
332
- 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 />';
333
- }
334
- if ($op_stem == 'advert_alt_' && $num == 1){
335
- 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 />';
336
- }
337
-
338
- ?>
339
-
340
- <textarea class="widefat" rows="8" cols="50" width="100%" <?php $this->add_name($op); ?>><?php echo $ops[$op]; ?></textarea>
341
- </div><!--add_show_hide_section-->
342
- </td></tr>
343
- <?php
344
- }
345
-
346
- function add_show_hide_section($anchor, $show_op, $ops){
347
- $show_field_name = $this->get_field_name($show_op);
348
- adinj_add_show_hide_section($anchor, $show_op, $show_field_name, $ops);
349
- }
350
-
351
- function add_name($op){
352
- echo 'id="'.$this->get_field_id($op).'" name="'.$this->get_field_name($op).'"';
353
- }
354
-
355
- function get_ad_file_path($num){
356
- return ADINJ_AD_PATH.'/'.$this->get_ad_file_name($num);
357
- }
358
-
359
- function get_alt_file_path($num){
360
- return ADINJ_AD_PATH.'/'.$this->get_alt_file_name($num);
361
- }
362
-
363
- function get_ad_file_name($num){
364
- return 'ad_widget_'.$this->get_id().'_'.$num.'.txt';
365
- }
366
-
367
- function get_alt_file_name($num){
368
- return 'ad_widget_'.$this->get_id().'_alt_'.$num.'.txt';
369
- }
370
-
371
- function get_id(){
372
- $field = $this->get_field_id('advert_1');
373
- preg_match('/-(\d+)-/', $field, $matches);
374
- return $matches[1];
375
- }
376
- }
377
-
378
  ?>
1
+ <?php
2
+ /*
3
+ Part of the Ad Injection plugin for WordPress
4
+ http://www.reviewmylife.co.uk/
5
+ */
6
+
7
+ // 1 = original
8
+ // 2 = split testing / alt content
9
+ // 3 = increase db rotation slots to 10 - no UI support yet
10
+ // 4 = added ui show fields for ads 4-10. Category/tag/author conditions.
11
+ // 5 = ad/alt pool show fields
12
+ // 6 = page type restrictions
13
+ // 7 = align and clear
14
+ // 8 = post/page id restrictions
15
+ define('ADINJ_WIDGET_DB_VERSION', 8);
16
+
17
+ class Ad_Injection_Widget extends WP_Widget {
18
+ function Ad_Injection_Widget() {
19
+ $widget_ops = array( 'classname' => 'adinjwidget', 'description' => 'Insert Ad Injection adverts into your sidebars/widget areas.' );
20
+ $control_ops = array( 'width' => 500, 'height' => 300, 'id_base' => 'adinj' );
21
+ $this->WP_Widget( 'adinj', 'Ad Injection', $widget_ops, $control_ops );
22
+ }
23
+
24
+ function widget( $args, $instance ) {
25
+ if (adinj_ads_completely_disabled_from_page('widget')) return;
26
+
27
+ if ((is_front_page() && adinj_ticked('widget_exclude_front')) ||
28
+ (is_home() && adinj_ticked('widget_exclude_home')) ||
29
+ (is_page() && adinj_ticked('widget_exclude_page')) ||
30
+ (is_single() && adinj_ticked('widget_exclude_single')) ||
31
+ (is_archive() && adinj_ticked('widget_exclude_archive')) ||
32
+ (is_search() && adinj_ticked('widget_exclude_search')) ||
33
+ (is_404() && adinj_ticked('widget_exclude_404'))){
34
+ return;
35
+ }
36
+
37
+ if ((is_front_page() && adinj_ticked('exclude_front', $instance)) ||
38
+ (is_home() && adinj_ticked('exclude_home', $instance)) ||
39
+ (is_page() && adinj_ticked('exclude_page', $instance)) ||
40
+ (is_single() && adinj_ticked('exclude_single', $instance)) ||
41
+ (is_archive() && adinj_ticked('exclude_archive', $instance)) ||
42
+ (is_search() && adinj_ticked('exclude_search', $instance)) ||
43
+ (is_404() && adinj_ticked('exclude_404', $instance))){
44
+ return;
45
+ }
46
+
47
+ if (!adinj_allowed_in_category('widget', $instance)) return;
48
+ if (!adinj_allowed_in_tag('widget', $instance)) return;
49
+ if (!adinj_allowed_in_author('widget', $instance)) return;
50
+ if (!adinj_allowed_in_id('widget', $instance)) return;
51
+
52
+ extract( $args );
53
+
54
+ $ops = adinj_options();
55
+
56
+ $include = "";
57
+ if (adinj_mfunc_mode()){
58
+ $include = adinj_ad_code_include();
59
+ }
60
+
61
+ $title = apply_filters('widget_title', $instance['title'] );
62
+
63
+ // The old 'non upgraded' db will be passed here if the widget hasn't
64
+ // been resaved. We can't upgrade as doing so would mean we'd have to
65
+ // re-save the widget files - which we can't do as we can't re-write
66
+ // the settings back to the db (at least not without a bit more work)
67
+ $adcode = adinj_get_ad_code('widget_'.$this->get_id(), $instance);
68
+
69
+ echo $before_widget;
70
+ if ( $title ) {
71
+ echo $before_title . $title . $after_title;
72
+ }
73
+
74
+ if ( !empty($adcode) ){
75
+ echo $include;
76
+ echo $adcode;
77
+ }
78
+
79
+ echo $after_widget;
80
+ }
81
+
82
+ function update( $new_instance, $old_instance ){
83
+ $updated = $this->adinj_upgrade_widget_db($new_instance, $old_instance);
84
+
85
+ // Only strip tags when potential for updated title
86
+ $updated['title'] = strip_tags( $new_instance['title'] );
87
+
88
+ // After first save mark it as saved
89
+ $updated['saved'] = 1;
90
+
91
+ for ($i=1; $i<=10; ++$i){
92
+ write_ad_to_file($updated['advert_'.$i], $this->get_ad_file_path($i));
93
+ }
94
+ for ($i=1; $i<=3; ++$i){
95
+ write_ad_to_file($updated['advert_alt_'.$i], $this->get_alt_file_path($i));
96
+ }
97
+
98
+ return $updated;
99
+ }
100
+
101
+ function default_options(){
102
+ /* Set up some default widget settings. */
103
+ return array(
104
+ 'title' => '',
105
+ //adverts
106
+ 'advert_1' => '',
107
+ 'advert_1_split' => '100',
108
+ 'advert_2' => '',
109
+ 'advert_2_split' => '100',
110
+ 'advert_3' => '',
111
+ 'advert_3_split' => '100',
112
+ 'advert_4' => '',
113
+ 'advert_4_split' => '100',
114
+ 'advert_5' => '',
115
+ 'advert_5_split' => '100',
116
+ 'advert_6' => '',
117
+ 'advert_6_split' => '100',
118
+ 'advert_7' => '',
119
+ 'advert_7_split' => '100',
120
+ 'advert_8' => '',
121
+ 'advert_8_split' => '100',
122
+ 'advert_9' => '',
123
+ 'advert_9_split' => '100',
124
+ 'advert_10' => '',
125
+ 'advert_10_split' => '100',
126
+ 'advert_alt_1' => '',
127
+ 'advert_alt_1_split' => '100',
128
+ 'advert_alt_2' => '',
129
+ 'advert_alt_2_split' => '100',
130
+ 'advert_alt_3' => '',
131
+ 'advert_alt_3_split' => '100',
132
+ //settings
133
+ 'margin_top' => 'd',
134
+ 'margin_bottom' => 'd',
135
+ 'padding_top' => 'd',
136
+ 'padding_bottom' => 'd',
137
+ 'align' => 'd',
138
+ 'clear' => 'd',
139
+ 'widget_category_condition_mode' => 'o',
140
+ 'widget_category_condition_entries' => '',
141
+ 'widget_tag_condition_mode' => 'o',
142
+ 'widget_tag_condition_entries' => '',
143
+ 'widget_author_condition_mode' => 'o',
144
+ 'widget_author_condition_entries' => '',
145
+ 'widget_id_condition_mode' => 'o',
146
+ 'widget_id_condition_entries' => '',
147
+ 'exclude_front' => '',
148
+ 'exclude_home' => '',
149
+ 'exclude_page' => '',
150
+ 'exclude_single' => '',
151
+ 'exclude_archive' => '',
152
+ 'exclude_search' => '',
153
+ 'exclude_404' => '',
154
+ //ui
155
+ 'ui_ad_1_show' => 'true',
156
+ 'ui_pagetypes_show' => 'false',
157
+ 'ui_conditions_show' => 'false',
158
+ 'ui_spacing_show' => 'false',
159
+ 'ui_ad_pool_show' => 'false',
160
+ 'ui_ad_2_show' => 'false',
161
+ 'ui_ad_3_show' => 'false',
162
+ 'ui_ad_4_show' => 'false',
163
+ 'ui_ad_5_show' => 'false',
164
+ 'ui_ad_6_show' => 'false',
165
+ 'ui_ad_7_show' => 'false',
166
+ 'ui_ad_8_show' => 'false',
167
+ 'ui_ad_9_show' => 'false',
168
+ 'ui_ad_10_show' => 'false',
169
+ 'ui_alt_pool_show' => 'false',
170
+ 'ui_alt_1_show' => 'false',
171
+ 'ui_alt_2_show' => 'false',
172
+ 'ui_alt_3_show' => 'false',
173
+ 'saved' => 0,
174
+ //
175
+ 'db_version' => ADINJ_WIDGET_DB_VERSION
176
+ );
177
+ }
178
+
179
+ function adinj_upgrade_widget_db($new_instance, $old_instance){
180
+ // Copy old values across to default
181
+ $updated = $this->default_options();
182
+ foreach ($updated as $key => $value){
183
+ if (array_key_exists($key, $new_instance)){
184
+ $updated[$key] = $new_instance[$key];
185
+ }
186
+ }
187
+
188
+ // Upgrade any options as necessary
189
+ $old_dbversion = adinj_db_version($old_instance);
190
+ if ($old_dbversion == 1){
191
+ $updated['advert_1'] = $old_instance['advert'];
192
+ }
193
+
194
+ $updated['db_version'] = ADINJ_WIDGET_DB_VERSION;
195
+
196
+ return $updated;
197
+ }
198
+
199
+ function form( $instance ) {
200
+ $instance = $this->adinj_upgrade_widget_db($instance, $instance);
201
+
202
+ $savedfieldname = $this->get_field_name('saved');
203
+ $savedfieldvalue = $instance['saved'];
204
+ ?>
205
+
206
+ <input type='hidden' <?php $this->add_name('db_version'); ?> value='<?php echo $defaults['db_version']; ?>' />
207
+ <input type='hidden' name="$savedfieldname" value='$savedfieldvalue' />
208
+
209
+ <p>
210
+ <b>Title:</b><br />
211
+ <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" style="width:490px;" />
212
+ <br />
213
+ <span style="font-size:10px;">Make sure any title 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>
214
+ </p>
215
+
216
+ <style type="text/css">
217
+ .adinjtable td { vertical-align: top; }
218
+ </style>
219
+
220
+ <table border="0" width="490px" class="adinjtable">
221
+ <?php
222
+ $total_ad_split = adinj_total_split('advert_', $instance);
223
+ $this->add_row('advert_', 1, 'Ad code 1', 'ui_ad_1_show', $total_ad_split, $instance);
224
+ ?>
225
+ </table>
226
+
227
+ <?php
228
+ if ($savedfieldvalue != 1){
229
+ echo '<b>The widget needs to be saved for first time to activate the other options.</b>';
230
+ return;
231
+ }
232
+ ?>
233
+
234
+ <br />
235
+ <b> Exclude this widget from page types</b>
236
+ <?php $this->add_show_hide_section('ad_pagetypes_'.uniqid(''), 'ui_pagetypes_show', $instance); ?>
237
+ <?php
238
+ $count_pages = wp_count_posts('page', 'readable');
239
+ $count_posts = wp_count_posts('post', 'readable');
240
+ ?>
241
+ <?php $this->add_checkbox('exclude_front', $instance) ?>front - <?php echo get_bloginfo('url'); ?><br />
242
+ <?php $this->add_checkbox('exclude_home', $instance) ?>home page (latest posts page - may or may not be same as front)<br />
243
+ <?php $this->add_checkbox('exclude_page', $instance) ?>page - <?php echo $count_pages->publish; ?> single page(s)<br />
244
+ <?php $this->add_checkbox('exclude_single', $instance) ?>single - <?php echo $count_posts->publish; ?> single post(s)<br />
245
+ <?php $this->add_checkbox('exclude_archive', $instance) ?>archive - categories, tags, authors, dates<br />
246
+ <?php $this->add_checkbox('exclude_search', $instance) ?>search<br />
247
+ <?php $this->add_checkbox('exclude_404', $instance) ?>404<br />
248
+ <span style="font-size:10px;"><b>Notes:</b> Your home page is the page displaying your latest posts. It may be different to your front page if you have configured your front page to be a static page.</span><br />
249
+ <span style="font-size:10px;">If you have <a href='options-reading.php'>set your front page</a> to be a static 'page' rather than your latest posts, the 'page' tick box will also apply to the front page.</span>
250
+ </div>
251
+
252
+ <br />
253
+ <b> Category, tag, author and id conditions</b>
254
+ <?php
255
+ $this->add_show_hide_section('ad_restrictions_'.uniqid(''), 'ui_conditions_show', $instance);
256
+ adinj_condition_table('widget_category', 'category slugs. e.g: cat1, cat2, cat3', 'category', $instance, $this->get_field_name('widget_category_condition_mode'), $this->get_field_name('widget_category_condition_entries'));
257
+ adinj_condition_table('widget_tag', 'tag slugs. e.g: tag1, tag2, tag3', 'tag', $instance, $this->get_field_name('widget_tag_condition_mode'), $this->get_field_name('widget_tag_condition_entries'));
258
+ adinj_condition_table('widget_author', 'author nicknames. e.g: john, paul', 'author', $instance, $this->get_field_name('widget_author_condition_mode'), $this->get_field_name('widget_author_condition_entries'));
259
+ adinj_condition_table('widget_id', 'post/page ids. e.g: 7, 23, 276', 'id', $instance, $this->get_field_name('widget_id_condition_mode'), $this->get_field_name('widget_id_condition_entries'));
260
+ echo '</div>'
261
+ ?>
262
+
263
+ <br />
264
+ <b> Spacing and alignment options</b>
265
+ <?php $this->add_show_hide_section('ad_spacing_'.uniqid(''), 'ui_spacing_show', $instance); ?>
266
+ <table border="0" width="490px" class="adinjtable">
267
+ <tr><td>
268
+ <?php adinj_add_alignment_clear_options('widget_', $instance, $this->get_field_name('align'), $this->get_field_name('clear') ); ?>
269
+ </td><td>
270
+ <?php adinj_add_margin_top_bottom_options('widget_', $instance, $this->get_field_name('margin_top'), $this->get_field_name('margin_bottom') ); ?>
271
+ </td><td>
272
+ <?php adinj_add_padding_top_bottom_options('widget_', $instance, $this->get_field_name('padding_top'), $this->get_field_name('padding_bottom') ); ?>
273
+ </td></tr>
274
+ </table>
275
+ </div>
276
+
277
+ <br />
278
+ <b> Ad rotation pool</b>
279
+ <?php $this->add_show_hide_section('ad_pool_'.uniqid(''), 'ui_ad_pool_show', $instance); ?>
280
+ <table border="0" width="490px" class="adinjtable">
281
+ <?php
282
+ for ($i=2; $i<=10; ++$i){
283
+ $this->add_row('advert_', $i, 'Ad code '.$i, 'ui_ad_'.$i.'_show', $total_ad_split, $instance);
284
+ }
285
+ ?>
286
+ </table></div>
287
+
288
+ <br />
289
+ <b> Alt content pool</b>
290
+ <?php $this->add_show_hide_section('alt_pool_'.uniqid(''), 'ui_alt_pool_show', $instance); ?>
291
+ <table border="0" cellspacing="5" width="490px" class="adinjtable">
292
+ <?php
293
+ $total_alt_split = adinj_total_split('advert_alt_', $instance);
294
+ for ($i=1; $i<=3; ++$i){
295
+ $this->add_row('advert_alt_', $i, 'Alt content '.$i, 'ui_alt_'.$i.'_show', $total_alt_split, $instance);
296
+ }
297
+ ?>
298
+ </table></div>
299
+
300
+ <br />
301
+
302
+ <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>. You can also set a global <a href='options-general.php?page=ad-injection.php#global'>page type</a> restriction for the widgets.</p>
303
+
304
+ <?php
305
+ }
306
+
307
+ function add_checkbox($name, $instance){
308
+ ?>
309
+ <input type="hidden" <?php $this->add_name($name); ?> value="off" />
310
+ <input type="checkbox" <?php $this->add_name($name); ?> <?php echo adinj_ticked($name, $instance); ?> />
311
+ <?php
312
+ }
313
+
314
+ function add_row($op_stem, $num, $label, $show_op, $total_split, $ops){
315
+ $op = $op_stem.$num;
316
+ $op_split = $op.'_split';
317
+ $anchorid = $op.'_'.uniqid('');
318
+
319
+ $percentage_split = adinj_percentage_split($op_stem, $num, $ops, $total_split);
320
+ ?>
321
+ <tr><td colspan='2'>
322
+ <input style="float:right; padding:0; margin:0;" <?php $this->add_name($op_split); ?> size="7" value="<?php echo $ops[$op_split]; ?>" />
323
+
324
+ <?php
325
+ echo <<<HTML
326
+ <b> $label</b> <label style='float:right'>(Rotation: $percentage_split)</label>
327
+
328
+ HTML;
329
+ $this->add_show_hide_section($anchorid, $show_op, $ops);
330
+
331
+ if ($op_stem == 'advert_' && $num == 2){
332
+ 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 />';
333
+ }
334
+ if ($op_stem == 'advert_alt_' && $num == 1){
335
+ 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 />';
336
+ }
337
+
338
+ ?>
339
+
340
+ <textarea class="widefat" rows="8" cols="50" width="100%" <?php $this->add_name($op); ?>><?php echo $ops[$op]; ?></textarea>
341
+ </div><!--add_show_hide_section-->
342
+ </td></tr>
343
+ <?php
344
+ }
345
+
346
+ function add_show_hide_section($anchor, $show_op, $ops){
347
+ $show_field_name = $this->get_field_name($show_op);
348
+ adinj_add_show_hide_section($anchor, $show_op, $show_field_name, $ops);
349
+ }
350
+
351
+ function add_name($op){
352
+ echo 'id="'.$this->get_field_id($op).'" name="'.$this->get_field_name($op).'"';
353
+ }
354
+
355
+ function get_ad_file_path($num){
356
+ return ADINJ_AD_PATH.'/'.$this->get_ad_file_name($num);
357
+ }
358
+
359
+ function get_alt_file_path($num){
360
+ return ADINJ_AD_PATH.'/'.$this->get_alt_file_name($num);
361
+ }
362
+
363
+ function get_ad_file_name($num){
364
+ return 'ad_widget_'.$this->get_id().'_'.$num.'.txt';
365
+ }
366
+
367
+ function get_alt_file_name($num){
368
+ return 'ad_widget_'.$this->get_id().'_alt_'.$num.'.txt';
369
+ }
370
+
371
+ function get_id(){
372
+ $field = $this->get_field_id('advert_1');
373
+ preg_match('/-(\d+)-/', $field, $matches);
374
+ return $matches[1];
375
+ }
376
+ }
377
+
378
  ?>
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: 1.1.0.6
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
@@ -33,7 +33,8 @@ define('ADINJ_NO_CONFIG_FILE', 1);
33
  // 15 = remove duplicate 'Disabled' option from top/bottom ad section
34
  // 16 = after paragraph options, older option for widget
35
  // 17 = block ads for days
36
- define('ADINJ_DB_VERSION', 17);
 
37
 
38
  // Files
39
  // TODO will these paths work on windows?
@@ -44,17 +45,17 @@ define('ADINJ_AD_PATH', WP_PLUGIN_DIR.'/ad-injection-data');
44
  // Constants
45
  define('ADINJ_DISABLED', 'Disabled'); // todo deprecated?
46
  define('ADINJ_RULE_DISABLED', 'Rule Disabled'); // todo depreacated?
47
- define('ADINJ_ALWAYS_SHOW', 'Always show'); // todo deprecated?
48
  //
49
  define('ADINJ_ONLY_SHOW_IN', 'Only show in');
50
  define('ADINJ_NEVER_SHOW_IN', 'Never show in');
51
  define('ADINJ_NA', 'n/a');
 
 
52
 
53
  // Global variables
54
  $adinj_total_top_ads_used = 0;
55
  $adinj_total_random_ads_used = 0;
56
  $adinj_total_bottom_ads_used = 0;
57
- $adinj_total_all_ads_used = 0;
58
  $adinj_data = array();
59
 
60
  require_once(ADINJ_PATH . '/adshow.php');
@@ -205,24 +206,15 @@ function adinj_ad_code_random(){
205
  }
206
 
207
  function adinj_ad_code_top(){
208
- $ad = adinj_get_ad_code('top', adinj_options());
209
- global $adinj_total_all_ads_used;
210
- ++$adinj_total_all_ads_used;
211
- return $ad;
212
  }
213
 
214
  function adinj_ad_code_bottom(){
215
- $ad = adinj_get_ad_code('bottom', adinj_options());
216
- global $adinj_total_all_ads_used;
217
- ++$adinj_total_all_ads_used;
218
- return $ad;
219
  }
220
 
221
  function adinj_ad_code_footer(){
222
- $ad = adinj_get_ad_code('footer', adinj_options());
223
- global $adinj_total_all_ads_used;
224
- ++$adinj_total_all_ads_used;
225
- return $ad;
226
  }
227
 
228
  /**
@@ -345,6 +337,7 @@ function adinj_ad_code_include(){
345
  // files from within ABSPATH. To remove this limitation we do the include
346
  // using mfunc instead.
347
  return adinj_ad_code_eval("\n
 
348
  <!--mfunc include_once('$plugin_dir/adshow.php') -->
349
  <?php include_once('$plugin_dir/adshow.php'); ?>
350
  <!--/mfunc-->
@@ -396,12 +389,19 @@ function adinj_adverts_disabled_flag(){
396
 
397
  function adinj($content, $message){
398
  if (!adinj_ticked('debug_mode')) return $content;
399
- global $adinj_total_top_ads_used, $adinj_total_random_ads_used, $adinj_total_bottom_ads_used, $adinj_total_all_ads_used;
400
  $ops = adinj_options();
401
- $para = adinj_paragraph_to_start_ads();
402
- $random_mode = $ops['random_ads_after_mode'];
403
- if ($random_mode == 'after') $random_mode = 'at or after';
404
- $random_unit = $ops['random_ads_after_unit'];
 
 
 
 
 
 
 
405
  $mode = $ops['ad_insertion_mode'];
406
 
407
  $posttype = get_post_type() . ' (';
@@ -427,9 +427,8 @@ $message
427
  \$adinj_total_top_ads_used=$adinj_total_top_ads_used
428
  \$adinj_total_random_ads_used=$adinj_total_random_ads_used
429
  \$adinj_total_bottom_ads_used=$adinj_total_bottom_ads_used
430
- \$adinj_total_all_ads_used=$adinj_total_all_ads_used
431
- paragraphtostartads=$para (fyi: -1 is disabled)
432
- random ads start $random_mode $random_unit $para (fyi: -1 is disabled)
433
  posttype=$posttype
434
  currentdate=$currentdate ($currentday)
435
  postdate=$postdate ($postday)
@@ -437,6 +436,7 @@ injection mode=$mode
437
  -->\n";
438
  }
439
 
 
440
  function adinj_excluded_by_tick_box($prefix){
441
  if (is_front_page() && adinj_ticked($prefix.'exclude_front') ||
442
  is_home() && adinj_ticked($prefix.'exclude_home') ||
@@ -529,6 +529,7 @@ function adinj_allowed_in_category($scope, $ops){
529
 
530
  $mode = $ops[$scope.'_category_condition_mode'];
531
 
 
532
  if (!in_the_loop() && adinj_mode_only_show_in($mode) && !(is_single() || is_category())){
533
  return false;
534
  }
@@ -644,23 +645,29 @@ function adinj_footer_hook(){
644
  echo adinj_ad_code_footer();
645
  }
646
 
 
 
 
 
 
647
  function adinj_content_hook($content){
648
  if (is_feed()) return $content; // TODO feed specific ads
649
- if (!in_the_loop()) return $content; // Don't insert ads into meta description tags TODOTODO
650
  $ops = adinj_options();
651
  if(empty($ops)){
652
  return $content;
653
  }
 
654
  $debug_on = $ops['debug_mode'];
655
- if ($debug_on) echo "<!--adinj-->"; //TODO remove?
 
656
 
657
  adinj_upgrade_db_if_necessary();
658
-
659
- global $adinj_total_all_ads_used, $adinj_total_random_ads_used, $adinj_total_top_ads_used, $adinj_total_bottom_ads_used;
660
  if(!is_archive() && (is_page() || is_single())){
661
  // On single page the_content may be called more than once - e.g. for
662
  // description meta tag and for content.
663
- $adinj_total_all_ads_used = 0;
664
  $adinj_total_top_ads_used = 0;
665
  $adinj_total_random_ads_used = 0;
666
  $adinj_total_bottom_ads_used = 0;
@@ -671,9 +678,6 @@ function adinj_content_hook($content){
671
  return adinj($content, $reason);
672
  }
673
 
674
- $debug_on = $ops['debug_mode'];
675
- $debug = "";
676
-
677
  if ($debug_on && adinj_direct_mode()){
678
  $showads = adshow_show_adverts();
679
  if ($showads !== true){
@@ -688,223 +692,356 @@ function adinj_content_hook($content){
688
 
689
  # Ad sandwich mode
690
  if(is_page() || is_single()){
691
- if(stripos($content, "<!--adsandwich-->") !== false) return adinj($ad_include.adinj_ad_code_top().$content.adinj_ad_code_bottom(), "Ads=adsandwich" . $debug);
692
- if(stripos($content, "<!--adfooter-->") !== false) return adinj($content.$ad_include.adinj_ad_code_bottom(), "Ads=adfooter" . $debug);
693
  }
694
 
 
 
695
  $length = 0;
696
  if ($ops['content_length_unit'] == 'all'){
697
- $length = strlen($content);
698
- if ($debug_on) $debug .= "\nnum chars: $length (including HTML chars)";
699
  } else if ($ops['content_length_unit'] == 'viewable'){
700
  $length = strlen(strip_tags($content));
701
- if ($debug_on) $debug .= "\nnum chars: $length (viewable chars only)";
702
  } else {
703
  $length = str_word_count_utf8(strip_tags($content));
704
- if ($debug_on) $debug .= "\nnum words: $length";
705
  }
706
- # Insert top and bottom ads if necesary
707
- if(stripos($content, "<!--topad-->") == false){
708
- if (adinj_num_top_ads_to_insert($length) > 0){
709
- $content = $ad_include.adinj_ad_code_top().$content;
710
- $ad_include = "";
711
- ++$adinj_total_top_ads_used;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
712
  }
713
- } else {
714
- if ($debug_on) $debug .= "\ntop ad position(s) fixed by 'topad' tag";
715
- $content = str_replace('<!--topad-->', adinj_ad_code_top(), $content);
716
- $content = $ad_include.$content;
717
- $ad_include = "";
718
- ++$adinj_total_top_ads_used;
719
  }
 
720
 
721
- if(stripos($content, "<!--bottomad-->") == false){
722
- if (adinj_num_bottom_ads_to_insert($length) > 0){
723
- $content = $content.adinj_ad_code_bottom();
724
- ++$adinj_total_bottom_ads_used;
725
- }
726
- } else {
727
- if ($debug_on) $debug .= "\nbottom ad position(s) fixed by 'bottomad' tag";
728
- $content = str_replace('<!--bottomad-->', adinj_ad_code_bottom(), $content);
729
- ++$adinj_total_bottom_ads_used;
730
  }
731
-
732
- if ($ad_include !== "") $content = $ad_include.$content;
733
 
734
- if(stripos($content, "<!--randomad-->") !== false){
735
- if ($debug_on) $debug .= "\nrandom ad position(s) fixed by 'randomad' tag";
736
- $content = str_replace('<!--randomad-->', adinj_ad_code_random(), $content);
737
- return adinj($content, "Fixed random ads" . $debug);
 
 
 
738
  }
739
 
740
- $num_rand_ads_to_insert = adinj_num_rand_ads_to_insert($length);
741
- if ($num_rand_ads_to_insert <= 0) return adinj($content, "no random ads on this post" . $debug);
742
- $ad = adinj_ad_code_random();
743
- if (empty($ad)) return adinj($content, "no random ad defined" . $debug);
744
-
745
- if (!$debug_on) $debugtags=false;
746
-
747
- $adstart_override = false;
748
- $content_adfree_header = "";
749
- $content_adfree_footer = "";
750
-
751
- // TODO add docs explaining the significance of leaving blank lines
752
- // before or after these tags
753
- # 'Adsense Injection' tag compatibility
754
- $split = adinj_split_by_tag($content, "<!--adsensestart-->", $debugtags);
755
- if (count($split) == 2){
756
- $content_adfree_header = $split[0];
757
- $content = $split[1];
758
- $adstart_override = true;
 
 
 
 
 
759
  }
760
-
761
- # Use the same naming convention for the end tag
762
- $split = adinj_split_by_tag($content, "<!--adsenseend-->", $debugtags);
763
- if (count($split) == 2){
764
- $content = $split[0];
765
- $content_adfree_footer = $split[1];
766
  }
767
-
768
- $split = adinj_split_by_tag($content, "<!--adstart-->", $debugtags);
769
- if (count($split) == 2){
770
- $content_adfree_header = $split[0];
771
- $content = $split[1];
772
- $adstart_override = true;
773
  }
774
 
775
- $split = adinj_split_by_tag($content, "<!--adend-->", $debugtags);
776
- if (count($split) == 2){
777
- $content = $split[0];
778
- $content_adfree_footer = $split[1];
 
 
 
 
779
  }
780
-
781
- if ($debug_on) $debug .= "\nContent length=". strlen($content);
782
 
783
- $startposition = adinj_paragraph_to_start_ads();
784
 
785
- if (!$adstart_override){
786
- if ($ops['random_ads_after_unit'] == 'character' && $startposition > 0){
787
- $split = adinj_split_by_index($content, $startposition);
788
- if (count($split) == 2){
789
- $content_adfree_header = $split[0];
790
- $content = $split[1];
791
- if ($ops['random_ads_after_mode'] == 'at'){
792
- // Start ads at next paragraph
793
- $startposition = 1;
794
- } else {
795
- $startposition = -1;
796
- }
797
- } else {
798
- return adinj($content, "No random ads: content too short for 'start first ad at/after character $startposition' setting");
799
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
800
  }
801
  }
802
 
803
- // TODO add note explaining that start tags are processed before the 'first
804
- // paragraph ad
805
-
806
- // Move onto random ad insertions
807
- $paragraphmarker = "</p>";
808
- if(stripos($content, $paragraphmarker) === false) return adinj($content, "no &lt;/p&gt; tags");
809
 
810
- if ($debug_on) $debug .= "\nTags=". htmlentities($debugtags);
811
 
812
- // Generate a list of all potential injection points
813
- if ($debug_on) $debug .= "\nInitial potential positions: ";
814
- $potential_inj_positions = array();
815
- $prevpos = -1;
816
- while(($prevpos = stripos($content, $paragraphmarker, $prevpos+1)) !== false){
817
- $potentialposition = $prevpos + strlen($paragraphmarker);
818
- $potential_inj_positions[] = $potentialposition;
819
- if ($debug_on) $debug .= "$potentialposition, ";
820
  }
821
-
822
- if ($debug_on) $debug .= "\npotential_inj_positions:".sizeof($potential_inj_positions);
823
 
824
- if (sizeof($potential_inj_positions) == 0){
825
- return adinj($content, "No random ads: no potential inj positions found in content");
 
 
 
 
826
  }
 
827
 
828
- if (!adinj_ticked('rnd_allow_ads_on_last_paragraph')){
829
- array_pop($potential_inj_positions);
830
- if (sizeof($potential_inj_positions) == 0){
831
- return adinj($content, "No random ads: no potential inj positions after removing last paragraph position");
832
- }
833
  }
834
 
835
- $inj_positions = array();
836
-
837
- if ($startposition > 0){
838
- $pos = NULL;
839
- if ($ops['random_ads_after_mode'] == 'at'){
840
- for ($i=0; $i<$startposition; ++$i){
841
- // discard positions until we get to the starting paragraph
842
- $pos = array_shift($potential_inj_positions);
843
- }
844
- if ($pos != NULL && $ops['random_ads_after_mode'] == 'at'){
845
- $inj_positions[] = $pos;
846
- --$num_rand_ads_to_insert;
847
- }
848
- } else { // mode == at or after
849
- for ($i=0; $i<$startposition-1; ++$i){
850
- // discard positions before the starting paragraph
851
- array_shift($potential_inj_positions);
852
- }
853
- }
854
- if (sizeof($potential_inj_positions) == 0){
855
- return adinj($content, "No random ads: no potential inj positions left after applying 'start ads at/after paragraph' $startposition setting");
856
- }
857
- }
858
-
859
- // Pick the correct number of random injection points
860
- if (sizeof($potential_inj_positions) > 0 && $num_rand_ads_to_insert > 0){
861
  if (!adinj_ticked('multiple_ads_at_same_position')){
862
  // Each ad is inserted into a unique position
863
- if (sizeof($potential_inj_positions) < $num_rand_ads_to_insert){
864
- $debug .= "\nnum_rand_ads_to_insert requested=$num_rand_ads_to_insert. But restricted to ". sizeof($potential_inj_positions) . " due to limited injection points.";
865
- $num_rand_ads_to_insert = sizeof($potential_inj_positions);
866
  }
867
- $rand_positions = array_rand(array_flip($potential_inj_positions), $num_rand_ads_to_insert);
868
  if ($num_rand_ads_to_insert == 1){
869
- // Convert it back into an array
870
- $inj_positions[] = $rand_positions;
871
  } else {
872
- $inj_positions = array_merge($inj_positions, $rand_positions);
 
873
  }
874
  } else {
875
  // Multiple ads may be inserted at the same position
876
  $injections = 0;
877
  while($injections++ < $num_rand_ads_to_insert){
878
- $rnd = array_rand($potential_inj_positions);
879
- if ($debug_on) $debug = $potential_inj_positions[$rnd] . ", " . $debug;
880
- $inj_positions[] = $potential_inj_positions[$rnd];
881
  }
882
  }
883
  }
 
 
 
884
 
885
- if (sizeof($inj_positions) == 0){
886
- return adinj($content_adfree_header.$content.$content_adfree_footer, "Error: No random ad injection positions: " . $debug);
887
- }
888
- foreach($inj_positions as $pos){
889
- if ($debug_on) $debug = "$pos, $debug";
 
890
  }
891
 
892
- // Sort positions
893
- sort($inj_positions);
894
-
895
- // Insert ads in reverse order
896
- global $adinj_total_random_ads_used, $adinj_total_all_ads_used;
897
- for ($adnum=sizeof($inj_positions)-1; $adnum>=0; $adnum--){
898
- $content = substr_replace($content, $ad, $inj_positions[$adnum], 0);
899
- ++$adinj_total_random_ads_used;
900
- ++$adinj_total_all_ads_used;
901
 
902
- if (adinj_ticked('rnd_reselect_ad_per_position_in_post')){
903
- $ad = adinj_ad_code_random();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
904
  }
905
  }
 
 
906
 
907
- return adinj($content_adfree_header.$content.$content_adfree_footer, "Ads injected: " . $debug);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
908
  }
909
 
910
  //http://php.net/manual/en/function.str-word-count.php
@@ -917,39 +1054,25 @@ function str_word_count_utf8($str){
917
  }
918
  }
919
 
920
- function adinj_paragraph_to_start_ads(){
921
  $ops = adinj_options();
922
- if (adinj_db_version($ops) == 1){
923
- if (adinj_ticked('first_paragraph_ad')) return 1;
924
- return -1;
925
  }
926
- if (adinj_rule_disabled('start_from_paragraph')){
927
- return -1;
928
- } else {
929
- return $ops['start_from_paragraph'];
930
  }
931
- }
932
-
933
- function adinj_split_by_tag($content, $tag, &$debugtags){
934
- $ret = array();
935
- if (strpos($content, $tag) !== false){
936
- if ($debugtags !== false) $debugtags .= "$tag, ";
937
- $content_split = explode($tag, $content, 2);
938
- $ret[] = $content_split[0];
939
- if (count($content_split) == 2){
940
- $ret[] = $content_split[1];
941
- }
942
  }
943
- return $ret;
944
- }
945
-
946
- function adinj_split_by_index($content, $index){
947
- $ret = array();
948
- if (strlen($content) > $index+4){ // +4 as there is no point splitting unless there is room for a </p> at end
949
- $ret[0] = substr($content, 0, $index);
950
- $ret[1] = substr($content, $index+1);
951
  }
952
- return $ret;
953
  }
954
 
955
  function adinj_get_current_page_type_prefix(){
@@ -958,7 +1081,7 @@ function adinj_get_current_page_type_prefix(){
958
  return '';
959
  }
960
 
961
- function adinj_num_top_ads_to_insert($content_length){
962
  if (adinj_excluded_by_tick_box('top_')) return 0;
963
  $ops = adinj_options();
964
  $prefix = adinj_get_current_page_type_prefix();
@@ -971,19 +1094,17 @@ function adinj_num_top_ads_to_insert($content_length){
971
  }
972
  if ($max_num_ads_to_insert <= 0) return 0;
973
 
974
- if (!adinj_allowed_in_category('top', $ops)) return 0;
975
- if (!adinj_allowed_in_tag('top', $ops)) return 0;
976
- if (!adinj_allowed_in_author('top', $ops)) return 0;
977
- if (!adinj_allowed_in_id('top', $ops)) return 0;
978
 
979
  $val = $ops[$prefix.'top_ad_if_longer_than'];
980
  if (adinj_not_set($val) || adinj_true_if($content_length, '>', $val)){
981
  return 1;
982
  }
 
983
  return 0;
984
  }
985
 
986
- function adinj_num_bottom_ads_to_insert($content_length){
987
  if (adinj_excluded_by_tick_box('bottom_')) return 0;
988
  $ops = adinj_options();
989
  $prefix = adinj_get_current_page_type_prefix();
@@ -996,19 +1117,17 @@ function adinj_num_bottom_ads_to_insert($content_length){
996
  }
997
  if ($max_num_ads_to_insert <= 0) return 0;
998
 
999
- if (!adinj_allowed_in_category('bottom', $ops)) return 0;
1000
- if (!adinj_allowed_in_tag('bottom', $ops)) return 0;
1001
- if (!adinj_allowed_in_author('bottom', $ops)) return 0;
1002
- if (!adinj_allowed_in_id('bottom', $ops)) return 0;
1003
 
1004
  $val = $ops[$prefix.'bottom_ad_if_longer_than'];
1005
  if (adinj_not_set($val) || adinj_true_if($content_length, '>', $val)){
1006
  return 1;
1007
  }
 
1008
  return 0;
1009
  }
1010
 
1011
- function adinj_num_rand_ads_to_insert($content_length){
1012
  if (adinj_excluded_by_tick_box('random_')) return 0;
1013
  global $adinj_total_random_ads_used; // a page can be more than one post
1014
  $ops = adinj_options();
@@ -1021,30 +1140,38 @@ function adinj_num_rand_ads_to_insert($content_length){
1021
  $max_num_rand_ads_to_insert = $ops[$prefix.'max_num_random_ads_per_page'] - $adinj_total_random_ads_used;
1022
  $max_ads_in_post = $ops[$prefix.'max_num_random_ads_per_post'];
1023
  } else {
 
1024
  return 0;
1025
  }
1026
 
1027
  $max_num_rand_ads_to_insert = min($max_num_rand_ads_to_insert, $max_ads_in_post);
1028
 
1029
  if ($max_num_rand_ads_to_insert <= 0) {
 
1030
  return 0;
1031
  }
1032
 
1033
- if (!adinj_allowed_in_category('random', $ops)) return 0;
1034
- if (!adinj_allowed_in_tag('random', $ops)) return 0;
1035
- if (!adinj_allowed_in_author('random', $ops)) return 0;
1036
- if (!adinj_allowed_in_id('random', $ops)) return 0;
1037
  $length = $content_length;
1038
- if (adinj_true_if($length, '<', $ops[$prefix.'no_random_ads_if_shorter_than'])){
 
 
1039
  return 0;
1040
  }
1041
- if (adinj_true_if($length, '<', $ops[$prefix.'one_ad_if_shorter_than'])){
 
 
1042
  return 1;
1043
  }
1044
- if (adinj_true_if($length, '<', $ops[$prefix.'two_ads_if_shorter_than'])){
 
 
1045
  return min(2, $max_num_rand_ads_to_insert);
1046
  }
1047
- if (adinj_true_if($length, '<', $ops[$prefix.'three_ads_if_shorter_than'])){
 
 
1048
  return min(3, $max_num_rand_ads_to_insert);
1049
  }
1050
  return $max_num_rand_ads_to_insert;
@@ -1057,15 +1184,11 @@ function adinj_num_footer_ads_to_insert(){
1057
  return 0;
1058
  }
1059
  $ops = adinj_options();
1060
- if (!adinj_allowed_in_category('footer', $ops)) return 0;
1061
- if (!adinj_allowed_in_tag('footer', $ops)) return 0;
1062
- if (!adinj_allowed_in_author('footer', $ops)) return 0;
1063
- if (!adinj_allowed_in_id('footer', $ops)) return 0;
1064
  return 1;
1065
  }
1066
 
1067
  function adinj_true_if($rule_value, $condition, $content_length){
1068
- if (adinj_alwaysshow($rule_value)) return true; // todo deprecated
1069
  if ($condition == '>'){
1070
  return ($rule_value >= $content_length);
1071
  } else if ($condition == '<'){
@@ -1085,10 +1208,6 @@ function adinj_mfunc_mode(){
1085
  return ($ops['ad_insertion_mode'] == 'mfunc');
1086
  }
1087
 
1088
- function adinj_alwaysshow($value){ // todo deprecated?
1089
- return "$value" == ADINJ_ALWAYS_SHOW || "$value" == 'a';
1090
- }
1091
-
1092
  function adinj_rule_disabled($value){
1093
  return "$value" == ADINJ_RULE_DISABLED || "$value" == ADINJ_DISABLED || "$value" == 'd' || "$value" == '';
1094
  }
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: 1.2.0.0
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
33
  // 15 = remove duplicate 'Disabled' option from top/bottom ad section
34
  // 16 = after paragraph options, older option for widget
35
  // 17 = block ads for days
36
+ // 18 = 1.2.0.0 New ad insertion engine and new top/random/bottom positioning options
37
+ define('ADINJ_DB_VERSION', 18);
38
 
39
  // Files
40
  // TODO will these paths work on windows?
45
  // Constants
46
  define('ADINJ_DISABLED', 'Disabled'); // todo deprecated?
47
  define('ADINJ_RULE_DISABLED', 'Rule Disabled'); // todo depreacated?
 
48
  //
49
  define('ADINJ_ONLY_SHOW_IN', 'Only show in');
50
  define('ADINJ_NEVER_SHOW_IN', 'Never show in');
51
  define('ADINJ_NA', 'n/a');
52
+ //
53
+ define('ADINJ_PARA', '</p>');
54
 
55
  // Global variables
56
  $adinj_total_top_ads_used = 0;
57
  $adinj_total_random_ads_used = 0;
58
  $adinj_total_bottom_ads_used = 0;
 
59
  $adinj_data = array();
60
 
61
  require_once(ADINJ_PATH . '/adshow.php');
206
  }
207
 
208
  function adinj_ad_code_top(){
209
+ return adinj_get_ad_code('top', adinj_options());
 
 
 
210
  }
211
 
212
  function adinj_ad_code_bottom(){
213
+ return adinj_get_ad_code('bottom', adinj_options());
 
 
 
214
  }
215
 
216
  function adinj_ad_code_footer(){
217
+ return adinj_get_ad_code('footer', adinj_options());
 
 
 
218
  }
219
 
220
  /**
337
  // files from within ABSPATH. To remove this limitation we do the include
338
  // using mfunc instead.
339
  return adinj_ad_code_eval("\n
340
+ <!--Ad Injection mfunc mode ad include code-->
341
  <!--mfunc include_once('$plugin_dir/adshow.php') -->
342
  <?php include_once('$plugin_dir/adshow.php'); ?>
343
  <!--/mfunc-->
389
 
390
  function adinj($content, $message){
391
  if (!adinj_ticked('debug_mode')) return $content;
392
+ global $adinj_total_top_ads_used, $adinj_total_random_ads_used, $adinj_total_bottom_ads_used;
393
  $ops = adinj_options();
394
+
395
+ $rnd_start_at = $ops['random_ads_start_at'];
396
+ $rnd_start_mode = $ops['random_ads_start_mode'];
397
+ if ($rnd_start_mode == 'after') $rnd_start_mode = 'at or after';
398
+ $rnd_start_unit = $ops['random_ads_start_unit'];
399
+
400
+ $rnd_end_at = $ops['random_ads_end_at'];
401
+ $rnd_end_mode = $ops['random_ads_end_mode'];
402
+ $rnd_end_unit = $ops['random_ads_end_unit'];
403
+ $rnd_end_unit_dir = $ops['random_ads_end_direction'];
404
+
405
  $mode = $ops['ad_insertion_mode'];
406
 
407
  $posttype = get_post_type() . ' (';
427
  \$adinj_total_top_ads_used=$adinj_total_top_ads_used
428
  \$adinj_total_random_ads_used=$adinj_total_random_ads_used
429
  \$adinj_total_bottom_ads_used=$adinj_total_bottom_ads_used
430
+ random ads start=$rnd_start_mode - $rnd_start_unit - $rnd_start_at
431
+ random ads end=$rnd_end_mode - $rnd_end_unit - $rnd_end_at $rnd_end_unit_dir
 
432
  posttype=$posttype
433
  currentdate=$currentdate ($currentday)
434
  postdate=$postdate ($postday)
436
  -->\n";
437
  }
438
 
439
+ // todo check exclude options for hardcoded ads
440
  function adinj_excluded_by_tick_box($prefix){
441
  if (is_front_page() && adinj_ticked($prefix.'exclude_front') ||
442
  is_home() && adinj_ticked($prefix.'exclude_home') ||
529
 
530
  $mode = $ops[$scope.'_category_condition_mode'];
531
 
532
+ // widget ads and footer ad
533
  if (!in_the_loop() && adinj_mode_only_show_in($mode) && !(is_single() || is_category())){
534
  return false;
535
  }
645
  echo adinj_ad_code_footer();
646
  }
647
 
648
+ function adinj_debug_on(){
649
+ $ops = adinj_options();
650
+ return $ops['debug_mode'];
651
+ }
652
+
653
  function adinj_content_hook($content){
654
  if (is_feed()) return $content; // TODO feed specific ads
655
+ if (!in_the_loop()) return $content; // Don't insert ads into meta description tags
656
  $ops = adinj_options();
657
  if(empty($ops)){
658
  return $content;
659
  }
660
+
661
  $debug_on = $ops['debug_mode'];
662
+ $debug = "";
663
+ if ($debug_on) echo "<!--adinj Ad Injection debug mode on-->";
664
 
665
  adinj_upgrade_db_if_necessary();
666
+
667
+ global $adinj_total_random_ads_used, $adinj_total_top_ads_used, $adinj_total_bottom_ads_used;
668
  if(!is_archive() && (is_page() || is_single())){
669
  // On single page the_content may be called more than once - e.g. for
670
  // description meta tag and for content.
 
671
  $adinj_total_top_ads_used = 0;
672
  $adinj_total_random_ads_used = 0;
673
  $adinj_total_bottom_ads_used = 0;
678
  return adinj($content, $reason);
679
  }
680
 
 
 
 
681
  if ($debug_on && adinj_direct_mode()){
682
  $showads = adshow_show_adverts();
683
  if ($showads !== true){
692
 
693
  # Ad sandwich mode
694
  if(is_page() || is_single()){
695
+ if(stripos($content, "<!--adsandwich-->") !== false) return adinj($ad_include.adinj_ad_code_top().$content.adinj_ad_code_bottom(), "Ads=sandwich" . $debug);
696
+ if(stripos($content, "<!--adfooter-->") !== false) return adinj($content.$ad_include.adinj_ad_code_bottom(), "Ads=footer" . $debug);
697
  }
698
 
699
+ # Get content length for ad placement settings
700
+ $rawlength = strlen($content);
701
  $length = 0;
702
  if ($ops['content_length_unit'] == 'all'){
703
+ $length = $rawlength;
 
704
  } else if ($ops['content_length_unit'] == 'viewable'){
705
  $length = strlen(strip_tags($content));
 
706
  } else {
707
  $length = str_word_count_utf8(strip_tags($content));
 
708
  }
709
+
710
+ # Record original paragraph positions
711
+ $original_paragraph_positions = array();
712
+ $prevpos = -1;
713
+ while(($prevpos = stripos($content, ADINJ_PARA, $prevpos+1)) !== false){
714
+ $original_paragraph_positions[] = $prevpos + strlen(ADINJ_PARA);
715
+ }
716
+ $paracount = count($original_paragraph_positions);
717
+ if ($debug_on) $debug .= "\nContent length=$length (".$ops['content_length_unit'].") Raw character length=$rawlength Paragraph count=$paracount";
718
+ if($paracount == 0) if ($debug_on) $debug .= "\nNo &lt;/p&gt; tags found";
719
+
720
+ $topad = adinj_ad_code_top();
721
+ if (empty($topad)) { if ($debug_on) $debug .= "\nNo top ad defined in any of the ad code boxes"; }
722
+ $randomad = adinj_ad_code_random();
723
+ if (empty($randomad)) { if ($debug_on) $debug .= "\nNo random ad defined in any of the ad code boxes"; }
724
+ $bottomad = adinj_ad_code_bottom();
725
+ if (empty($bottomad)) { if ($debug_on) $debug .= "\nNo bottom ad defined in any of the ad code boxes"; }
726
+
727
+ # Positions to insert ads
728
+ $top_ad_paragraph = -1;
729
+ $random_ad_paragraphs = array();
730
+ $bottom_ad_paragraph = -1;
731
+
732
+ $fixed_top = stripos($content, "<!--topad-->");
733
+ $fixed_random = stripos($content, "<!--randomad-->");
734
+ $fixed_bottom = stripos($content, "<!--bottomad-->");
735
+
736
+ # Find top ad position
737
+ if ($fixed_top === false){
738
+ if (adinj_num_top_ads_to_insert($length, $debug) > 0){
739
+ $top_ad_paragraph = adinj_get_paragraph('top', $content, $original_paragraph_positions, $debug);
740
  }
 
 
 
 
 
 
741
  }
742
+ if ($debug_on) $debug .= "\nTop ad paragraph: $top_ad_paragraph";
743
 
744
+ # Find bottom ad position
745
+ if ($fixed_bottom === false){
746
+ if (adinj_num_bottom_ads_to_insert($length, $debug) > 0){
747
+ $bottom_ad_paragraph = adinj_get_paragraph('bottom', $content, $original_paragraph_positions, $debug);
748
+ }
749
+ if ($bottom_ad_paragraph !== -1){
750
+ $bottom_ad_paragraph = $paracount - $bottom_ad_paragraph;
751
+ }
 
752
  }
753
+ if ($debug_on) $debug .= "\nBottom ad paragraph: $bottom_ad_paragraph";
 
754
 
755
+ # Find random ad positions
756
+ if ($fixed_random === false){
757
+ $random_ad_paragraphs = adinj_get_random_paragraphs($content, $length, $original_paragraph_positions, $debug);
758
+ $random_ads_to_insert_count = sizeof($random_ad_paragraphs);
759
+ if ($random_ads_to_insert_count == 0){
760
+ if ($debug_on) $debug .= "\nWarning: No random ad injection positions";
761
+ }
762
  }
763
 
764
+ # Insert the adverts into the content. Scan through the paragraph list in reverse order.
765
+ $adpos = count($random_ad_paragraphs);
766
+ for ($i=$paracount; $i>0; --$i){
767
+ if ($i === $bottom_ad_paragraph){
768
+ $content = substr_replace($content, $bottomad, $original_paragraph_positions[$i-1], 0);
769
+ ++$adinj_total_bottom_ads_used;
770
+ }
771
+ for ($j=$adpos-1; $j>=0; --$j){
772
+ $rnd = $random_ad_paragraphs[$j];
773
+ if ($i==$rnd){
774
+ if (adinj_ticked('rnd_reselect_ad_per_position_in_post')){
775
+ $randomad = adinj_ad_code_random();
776
+ }
777
+ $content = substr_replace($content, $randomad, $original_paragraph_positions[$rnd-1], 0);
778
+ ++$adinj_total_random_ads_used;
779
+ --$adpos;
780
+ } else {
781
+ break;
782
+ }
783
+ }
784
+ if ($i === $top_ad_paragraph){
785
+ $content = substr_replace($content, $topad, $original_paragraph_positions[$i-1], 0);
786
+ ++$adinj_total_top_ads_used;
787
+ }
788
  }
789
+ if ($top_ad_paragraph === 0){ // default is special case
790
+ $content = $topad.$content;
791
+ ++$adinj_total_top_ads_used;
 
 
 
792
  }
793
+ if ($bottom_ad_paragraph !== -1 && $adinj_total_bottom_ads_used == 0){
794
+ $content = $content.$bottomad;
795
+ ++$adinj_total_bottom_ads_used;
 
 
 
796
  }
797
 
798
+ if($fixed_top) {
799
+ adinj_insert_fixed_ad($content, $topad, 'top', $adinj_total_top_ads_used, $debug);
800
+ }
801
+ if($fixed_random) {
802
+ adinj_insert_fixed_ad($content, $randomad, 'random', $adinj_total_random_ads_used, $debug);
803
+ }
804
+ if($fixed_bottom) {
805
+ adinj_insert_fixed_ad($content, $bottomad, 'bottom', $adinj_total_bottom_ads_used, $debug);
806
  }
 
 
807
 
808
+ $content = $ad_include.$content;
809
 
810
+ return adinj($content, "Ad Injection in-content injections complete!" . $debug);
811
+ }
812
+
813
+ function adinj_insert_fixed_ad(&$content, $ad, $adname, &$counter, &$debug){
814
+ if (!adinj_excluded_by_tick_box($adname.'_')){
815
+ $tagname = $adname.'ad';
816
+ if (adinj_debug_on()) $debug .= "\n$adname ad position(s) fixed by '$tagname' tag";
817
+ $counter += substr_count($content, "<!--$tagname-->");
818
+ $content = str_replace("<!--$tagname-->", $ad, $content);
819
+ } else {
820
+ if (adinj_debug_on()) $debug .= "\nFixed $adname ad excluded by tick box";
821
+ }
822
+ }
823
+
824
+ // length here can be raw characters, displayable, or number of words
825
+ // returns array of paragraph positions to insert rnd ads into
826
+ function adinj_get_random_paragraphs($content, $length, $original_paragraph_positions, &$debug){
827
+ $ops = adinj_options();
828
+ $debug_on = adinj_debug_on();
829
+ $random_ad_paragraphs = array();
830
+ $random_start_paragraph = 0;
831
+ $random_end_paragraph = 0;
832
+ adinj_get_random_ad_start_end_paragraph($content, $original_paragraph_positions, $random_start_paragraph, $random_end_paragraph, $debug);
833
+ if ($debug_on) $debug .= "\n1st Injected random ads range starts at: $random_start_paragraph, and ends at: $random_end_paragraph";
834
+
835
+ $paracount = count($original_paragraph_positions);
836
+ $random_end_paragraph = min($random_end_paragraph, $paracount);
837
+ if (!adinj_ticked('rnd_allow_ads_on_last_paragraph')){
838
+ if ($random_end_paragraph == $paracount) --$random_end_paragraph;
839
+ if ($random_end_paragraph == 0){
840
+ if ($debug_on) $debug .= "\nNo random ads: no potential inj positions after removing last paragraph position";
841
+ return;
842
  }
843
  }
844
 
845
+ if ($random_start_paragraph <= 0 || $random_end_paragraph <= 0 ||
846
+ $random_end_paragraph - $random_start_paragraph < 0){
847
+ if ($debug_on) $debug .= "\nWarning: No paragraphs: random_start_paragraph:$random_start_paragraph random_end_paragraph:$random_end_paragraph";
848
+ return array();
849
+ }
 
850
 
851
+ if ($debug_on) $debug .= "\n2nd Injected random ads range starts at: $random_start_paragraph, and ends at: $random_end_paragraph";
852
 
853
+ $potential_random_ad_paragraphs = range($random_start_paragraph, $random_end_paragraph);
854
+ if ($debug_on) $debug .= "\npotential_random_ad_paragraphs:".sizeof($potential_random_ad_paragraphs);
855
+ if (sizeof($potential_random_ad_paragraphs) == 0){
856
+ if ($debug_on) $debug .= "\nNo random ads: no potential inj positions found in content";
857
+ return array();
 
 
 
858
  }
 
 
859
 
860
+ # Checks to see if we can inject random ads
861
+ $requested_num_rand_ads_to_insert = adinj_num_rand_ads_to_insert($length, $debug);
862
+ if ($debug_on) $debug .= "\nrequested_num_rand_ads_to_insert:$requested_num_rand_ads_to_insert";
863
+ if ($requested_num_rand_ads_to_insert <= 0) {
864
+ if ($debug_on) $debug .= "\nNo random ads enabled on this post";
865
+ return array();
866
  }
867
+ $num_rand_ads_to_insert = $requested_num_rand_ads_to_insert;
868
 
869
+ # We have to put the first ad at the first position we already selected unless the first ad can start 'anywhere'
870
+ if ($ops['random_ads_start_mode'] != 'anywhere' && $ops['random_ads_start_mode'] != 'after'){
871
+ $random_ad_paragraphs[] = array_shift($potential_random_ad_paragraphs);
872
+ --$num_rand_ads_to_insert;
 
873
  }
874
 
875
+ # Pick the correct number of random injection points
876
+ if (sizeof($potential_random_ad_paragraphs) > 0 && $num_rand_ads_to_insert > 0){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
877
  if (!adinj_ticked('multiple_ads_at_same_position')){
878
  // Each ad is inserted into a unique position
879
+ if (sizeof($potential_random_ad_paragraphs) < $num_rand_ads_to_insert){
880
+ $debug .= "\nNum random ads requested=$requested_num_rand_ads_to_insert. But restricted to ". (sizeof($potential_random_ad_paragraphs) + sizeof($random_ad_paragraphs)) . " due to limited injection points.";
881
+ $num_rand_ads_to_insert = sizeof($potential_random_ad_paragraphs);
882
  }
883
+ $rand_positions = array_rand(array_flip($potential_random_ad_paragraphs), $num_rand_ads_to_insert);
884
  if ($num_rand_ads_to_insert == 1){
885
+ // Add the single value to the array
886
+ $random_ad_paragraphs[] = $rand_positions;
887
  } else {
888
+ // Merge the values with the array
889
+ $random_ad_paragraphs = array_merge($random_ad_paragraphs, $rand_positions);
890
  }
891
  } else {
892
  // Multiple ads may be inserted at the same position
893
  $injections = 0;
894
  while($injections++ < $num_rand_ads_to_insert){
895
+ $rnd = array_rand($potential_random_ad_paragraphs);
896
+ $random_ad_paragraphs[] = $potential_random_ad_paragraphs[$rnd];
 
897
  }
898
  }
899
  }
900
+
901
+ # Sort positions
902
+ sort($random_ad_paragraphs);
903
 
904
+ if ($debug_on){
905
+ $injected_list = '';
906
+ foreach($random_ad_paragraphs as $pos){
907
+ $injected_list .= "$pos ";
908
+ }
909
+ $debug .= "\nInjected ads at: $injected_list";
910
  }
911
 
912
+ return $random_ad_paragraphs;
913
+ }
 
 
 
 
 
 
 
914
 
915
+ // for top/bottom ad
916
+ // returns valid paragraph or -1
917
+ // will return 0 if the position is 0
918
+ function adinj_get_paragraph($op, $content, $original_paragraph_positions, &$debug){ // op is top or bottom
919
+ $ops = adinj_options();
920
+ $position = $ops[$op.'_ad_position'];
921
+ $paracount = count($original_paragraph_positions);
922
+ $rawlength = strlen($content);
923
+ $ad_paragraph = 0;
924
+ if ($position != 0){
925
+ if ($ops[$op.'_ad_position_unit'] == 'paragraph'){
926
+ if ($paracount < $position){
927
+ $ad_paragraph = -1;
928
+ if (adinj_debug_on()) $debug .= "\nPost too short for $op ad paracount($paracount) < para-position($position)";
929
+ } else {
930
+ $ad_paragraph = $position;
931
+ }
932
+ } else { //unit==character
933
+ if ($rawlength < $position){
934
+ $ad_paragraph = -1;
935
+ if (adinj_debug_on()) $debug .= "\nPost too short for $op ad rawlength($rawlength) < char-position($position)";
936
+ } else {
937
+ $ad_paragraph = adinj_get_paragraph_from_position($content, $position, $original_paragraph_positions, 1);
938
+ }
939
  }
940
  }
941
+ return (int)$ad_paragraph;
942
+ }
943
 
944
+ // Return a valid paragraph or -1
945
+ function adinj_get_paragraph_from_position($content, $offset, $original_paragraph_positions, $adjust=0, $mode='fromstart'){
946
+ $paracount = count($original_paragraph_positions);
947
+ if ($paracount == 0) return -1;
948
+ $contentlength = strlen($content);
949
+ if ($offset > $contentlength) return -1;
950
+ if ($mode == 'fromend') $offset = $contentlength - $offset;
951
+ $position = stripos($content, ADINJ_PARA, $offset);
952
+ if ($position === false) return -1;
953
+ $position += strlen(ADINJ_PARA);
954
+ for ($i=0; $i<$paracount; ++$i){
955
+ if ($position == $original_paragraph_positions[$i]) {
956
+ $paragraph = $i+$adjust;
957
+ return min($paragraph, $paracount);
958
+ }
959
+ }
960
+ return -1;
961
+ }
962
+
963
+ // Can return 0 as the end paragraph - meaning no random ads TODO check
964
+ function adinj_get_random_ad_start_end_paragraph($content, $original_paragraph_positions, &$start, &$end, &$debug){
965
+ $ops = adinj_options();
966
+ $debug_on = adinj_debug_on();
967
+
968
+ $paracount = count($original_paragraph_positions);
969
+ if ($paracount == 0){
970
+ $start = -1;
971
+ $end = -1;
972
+ return;
973
+ }
974
+
975
+ // initialise to 'anywhere' max range
976
+ $start = 1;
977
+ $end = $paracount;
978
+
979
+ // todo docs: should include these tags on same line as paragraph or can affect paragraph count
980
+ $tagposition = stripos($content, '<!--adstart-->');
981
+ if ($tagposition === false) $tagposition = stripos($content, '<!--adsensestart-->');
982
+ if ($tagposition === false){
983
+ $start = adinj_get_random_ad_paragraph($content, $original_paragraph_positions, 'start', $start, $debug);
984
+ } else {
985
+ $start = adinj_get_paragraph_from_position($content, $tagposition, $original_paragraph_positions, 1);
986
+ if ($debug_on) $debug .= "\nFound hardcoded start tag. Starting ads at paragraph $start";
987
+ }
988
+
989
+ $tagposition = stripos($content, '<!--adend-->');
990
+ if ($tagposition === false) $tagposition = stripos($content, '<!--adsenseend-->');
991
+ if ($tagposition === false){
992
+ $end = adinj_get_random_ad_paragraph($content, $original_paragraph_positions, 'end', $end, $debug);
993
+ } else {
994
+ $end = adinj_get_paragraph_from_position($content, $tagposition, $original_paragraph_positions, 0);
995
+ if ($debug_on) $debug .= "\nFound hardcoded end tag. Ending ads at paragraph $end";
996
+ }
997
+ }
998
+
999
+ // Returns -1 if paragraph can't be located
1000
+ function adinj_get_random_ad_paragraph($content, $original_paragraph_positions, $opname, $default, &$debug){
1001
+ $ops = adinj_options();
1002
+ $mode = $ops['random_ads_'.$opname.'_mode'];
1003
+ $paracount = count($original_paragraph_positions);
1004
+ $rawlength = strlen($content);
1005
+ $paragraph = -1;
1006
+
1007
+ if ($mode == 'anywhere'){
1008
+ $paragraph = $default;
1009
+ } else if ($mode == 'at' || $mode == 'after'){
1010
+ $position = $ops['random_ads_'.$opname.'_at'];
1011
+ $unit = $ops['random_ads_'.$opname.'_unit'];
1012
+ $direction = $ops['random_ads_'.$opname.'_direction'];
1013
+ if ($unit == 'character'){
1014
+ $adjust = ($direction == 'fromend') ? 0 : 1;
1015
+ $paragraph = adinj_get_paragraph_from_position($content, $position, $original_paragraph_positions, $adjust, $direction);
1016
+ if ($opname == 'end' && $direction == 'fromstart' && $paragraph == -1){
1017
+ $paragraph = $paracount;
1018
+ }
1019
+ } else {
1020
+ // paragraph is same as value in UI
1021
+ $paragraph = $position;
1022
+ if ($direction == 'fromend'){
1023
+ $paragraph = $paracount - $paragraph;
1024
+ }
1025
+ }
1026
+ } else if ($mode == 'middleback'){
1027
+ $pos = round(($rawlength / 2), 0);
1028
+ $paragraph = adinj_get_paragraph_from_position($content, $pos, $original_paragraph_positions, 0);
1029
+ } else if ($mode == 'middleforward'){
1030
+ $pos = round(($rawlength / 2), 0);
1031
+ $paragraph = adinj_get_paragraph_from_position($content, $pos, $original_paragraph_positions, 1);
1032
+ } else if ($mode == 'middleparaback'){
1033
+ $val = ($paracount % 2 == 0) ? 0 : 0.5;
1034
+ $paragraph = intval(round((($paracount-$val) / 2), 0)); // todo test with 0 and 1 paragraphs
1035
+ } else if ($mode == 'middleparaforward'){
1036
+ $paragraph = intval(round(($paracount / 2), 0));
1037
+ } else if ($mode == 'twothirds'){
1038
+ $pos = round(($rawlength * 0.66), 0);
1039
+ $paragraph = adinj_get_paragraph_from_position($content, $pos, $original_paragraph_positions, 1);
1040
+ }
1041
+ if ($paragraph == -1){
1042
+ if ($debug_on) $debug .= "\nParagraph not found - mode:$randomaftermode op:$opname";
1043
+ }
1044
+ return $paragraph;
1045
  }
1046
 
1047
  //http://php.net/manual/en/function.str-word-count.php
1054
  }
1055
  }
1056
 
1057
+ function adinj_ads_filtered_out($adname, &$debug){
1058
  $ops = adinj_options();
1059
+ if (!adinj_allowed_in_category($adname, $ops)){
1060
+ $debug .= "\n$adname ad filtered out by categories";
1061
+ return true;
1062
  }
1063
+ if (!adinj_allowed_in_tag($adname, $ops)){
1064
+ $debug .= "\n$adname ad filtered out by tags";
1065
+ return true;
 
1066
  }
1067
+ if (!adinj_allowed_in_author($adname, $ops)){
1068
+ $debug .= "\n$adname ad filtered out by authors";
1069
+ return true;
 
 
 
 
 
 
 
 
1070
  }
1071
+ if (!adinj_allowed_in_id($adname, $ops)){
1072
+ $debug .= "\n$adname ad filtered out by ids";
1073
+ return true;
 
 
 
 
 
1074
  }
1075
+ return false;
1076
  }
1077
 
1078
  function adinj_get_current_page_type_prefix(){
1081
  return '';
1082
  }
1083
 
1084
+ function adinj_num_top_ads_to_insert($content_length, &$debug){
1085
  if (adinj_excluded_by_tick_box('top_')) return 0;
1086
  $ops = adinj_options();
1087
  $prefix = adinj_get_current_page_type_prefix();
1094
  }
1095
  if ($max_num_ads_to_insert <= 0) return 0;
1096
 
1097
+ if (adinj_ads_filtered_out('top', $debug)) return 0;
 
 
 
1098
 
1099
  $val = $ops[$prefix.'top_ad_if_longer_than'];
1100
  if (adinj_not_set($val) || adinj_true_if($content_length, '>', $val)){
1101
  return 1;
1102
  }
1103
+ $debug .= "\nNo top ad because post length < $val";
1104
  return 0;
1105
  }
1106
 
1107
+ function adinj_num_bottom_ads_to_insert($content_length, &$debug){
1108
  if (adinj_excluded_by_tick_box('bottom_')) return 0;
1109
  $ops = adinj_options();
1110
  $prefix = adinj_get_current_page_type_prefix();
1117
  }
1118
  if ($max_num_ads_to_insert <= 0) return 0;
1119
 
1120
+ if (adinj_ads_filtered_out('bottom', $debug)) return 0;
 
 
 
1121
 
1122
  $val = $ops[$prefix.'bottom_ad_if_longer_than'];
1123
  if (adinj_not_set($val) || adinj_true_if($content_length, '>', $val)){
1124
  return 1;
1125
  }
1126
+ $debug .= "\nNo bottom ad because post length < $val";
1127
  return 0;
1128
  }
1129
 
1130
+ function adinj_num_rand_ads_to_insert($content_length, &$debug){
1131
  if (adinj_excluded_by_tick_box('random_')) return 0;
1132
  global $adinj_total_random_ads_used; // a page can be more than one post
1133
  $ops = adinj_options();
1140
  $max_num_rand_ads_to_insert = $ops[$prefix.'max_num_random_ads_per_page'] - $adinj_total_random_ads_used;
1141
  $max_ads_in_post = $ops[$prefix.'max_num_random_ads_per_post'];
1142
  } else {
1143
+ $debug .= "\nNo random ads because not correct page type";
1144
  return 0;
1145
  }
1146
 
1147
  $max_num_rand_ads_to_insert = min($max_num_rand_ads_to_insert, $max_ads_in_post);
1148
 
1149
  if ($max_num_rand_ads_to_insert <= 0) {
1150
+ $debug .= "\nNo random ads to insert in this post";
1151
  return 0;
1152
  }
1153
 
1154
+ if (adinj_ads_filtered_out('random', $debug)) return 0;
1155
+
 
 
1156
  $length = $content_length;
1157
+ $conditionlength = $ops[$prefix.'no_random_ads_if_shorter_than'];
1158
+ if (adinj_true_if($length, '<', $conditionlength)){
1159
+ $debug .= "\nNo random ads because post length < $conditionlength";
1160
  return 0;
1161
  }
1162
+ $conditionlength = $ops[$prefix.'one_ad_if_shorter_than'];
1163
+ if (adinj_true_if($length, '<', $conditionlength)){
1164
+ $debug .= "\nOnly 1 random ad because post length < $conditionlength";
1165
  return 1;
1166
  }
1167
+ $conditionlength = $ops[$prefix.'two_ads_if_shorter_than'];
1168
+ if (adinj_true_if($length, '<', $conditionlength)){
1169
+ $debug .= "\nLimit on random ads because post length < $conditionlength";
1170
  return min(2, $max_num_rand_ads_to_insert);
1171
  }
1172
+ $conditionlength = $ops[$prefix.'three_ads_if_shorter_than'];
1173
+ if (adinj_true_if($length, '<', $conditionlength)){
1174
+ $debug .= "\nLimit on random ads because post length < $conditionlength";
1175
  return min(3, $max_num_rand_ads_to_insert);
1176
  }
1177
  return $max_num_rand_ads_to_insert;
1184
  return 0;
1185
  }
1186
  $ops = adinj_options();
1187
+ if (adinj_ads_filtered_out('footer', $debug)) return 0;
 
 
 
1188
  return 1;
1189
  }
1190
 
1191
  function adinj_true_if($rule_value, $condition, $content_length){
 
1192
  if ($condition == '>'){
1193
  return ($rule_value >= $content_length);
1194
  } else if ($condition == '<'){
1208
  return ($ops['ad_insertion_mode'] == 'mfunc');
1209
  }
1210
 
 
 
 
 
1211
  function adinj_rule_disabled($value){
1212
  return "$value" == ADINJ_RULE_DISABLED || "$value" == ADINJ_DISABLED || "$value" == 'd' || "$value" == '';
1213
  }
adinj-sev.js CHANGED
@@ -39,6 +39,9 @@ function adinj_allowed_referrers_setting(){
39
  }
40
 
41
  function adinj_blocked(){
 
 
 
42
  if (adinj_blockedCookieSet()){
43
  return true;
44
  }
39
  }
40
 
41
  function adinj_blocked(){
42
+ if (adinj_searchEngineCookieSet()){
43
+ return false;
44
+ }
45
  if (adinj_blockedCookieSet()){
46
  return true;
47
  }
adshow.php CHANGED
@@ -20,6 +20,8 @@ if (file_exists($adinj_dir.'/ad-injection-config.php')){
20
  if (!function_exists('adshow_functions_exist')){
21
  // Used to downgrade fatal errors to printed errors to make debugging easier
22
  // and so that a problem doesn't disable the whole website.
 
 
23
  function adshow_functions_exist(){
24
  if (!defined('ADINJ_NO_CONFIG_FILE')){
25
  if (!adshow_functions_exist_impl('adinj_config_sevisitors_only')){ return false; }
@@ -226,12 +228,20 @@ function adshow_add_formatting($ad, $ops = array()){
226
  //////////////////////////////////////////////////////////////////////////////
227
 
228
  if (!function_exists('adshow_fromasearchengine')){
229
- function adshow_fromasearchengine(){
230
  if (!adshow_functions_exist()){ return false; }
231
 
 
 
 
 
 
232
  // return true if the visitor has recently come from a search engine
233
  // and has the adinj cookie set.
234
- if ($_COOKIE["adinj"]==1) return true;
 
 
 
235
 
236
  $referrer = $_SERVER['HTTP_REFERER'];
237
  $searchengines = adinj_config_search_engine_referrers();
@@ -248,13 +258,24 @@ if (!function_exists('adshow_blocked_referrer')){
248
  function adshow_blocked_referrer(){
249
  if (!adshow_functions_exist()){ return false; }
250
 
 
 
 
 
 
251
  // true if blocked cookie is set
252
- if ($_COOKIE["adinjblocked"]==1) return true;
 
 
 
253
 
254
  $referrer = $_SERVER['HTTP_REFERER'];
 
 
255
  $blocked = adinj_config_blocked_keywords();
256
  foreach ($blocked as $bl) {
257
  if (stripos($referrer, $bl) !== false) {
 
258
  return true;
259
  }
260
  }
20
  if (!function_exists('adshow_functions_exist')){
21
  // Used to downgrade fatal errors to printed errors to make debugging easier
22
  // and so that a problem doesn't disable the whole website.
23
+ // TODO can't just add new checks to here as Ad Injection might now get run before config
24
+ // file is regenerated - e.g. if cached versions of pages are served
25
  function adshow_functions_exist(){
26
  if (!defined('ADINJ_NO_CONFIG_FILE')){
27
  if (!adshow_functions_exist_impl('adinj_config_sevisitors_only')){ return false; }
228
  //////////////////////////////////////////////////////////////////////////////
229
 
230
  if (!function_exists('adshow_fromasearchengine')){
231
+ function adshow_fromasearchengine(){ //todo rename to allowed_referrer
232
  if (!adshow_functions_exist()){ return false; }
233
 
234
+ if ($_COOKIE["adinjblocked"]==1) {
235
+ if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: allowed referrer check ignored because adinjblocked cookie set-->\n"; }
236
+ return false;
237
+ }
238
+
239
  // return true if the visitor has recently come from a search engine
240
  // and has the adinj cookie set.
241
+ if ($_COOKIE["adinj"]==1) {
242
+ if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: adinj cookie set-->\n"; }
243
+ return true;
244
+ }
245
 
246
  $referrer = $_SERVER['HTTP_REFERER'];
247
  $searchengines = adinj_config_search_engine_referrers();
258
  function adshow_blocked_referrer(){
259
  if (!adshow_functions_exist()){ return false; }
260
 
261
+ if ($_COOKIE["adinj"]==1) {
262
+ if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: blocked check ignored because adinj cookie set-->\n"; }
263
+ return false;
264
+ }
265
+
266
  // true if blocked cookie is set
267
+ if ($_COOKIE["adinjblocked"]==1) {
268
+ if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: adinjblocked cookie set-->\n"; }
269
+ return true;
270
+ }
271
 
272
  $referrer = $_SERVER['HTTP_REFERER'];
273
+ if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: referrer=$referrer-->\n"; }
274
+
275
  $blocked = adinj_config_blocked_keywords();
276
  foreach ($blocked as $bl) {
277
  if (stripos($referrer, $bl) !== false) {
278
+ if (adinj_config_debug_mode()){ echo "<!--ADINJ DEBUG: ads blocked - referrer contains $bl -->\n"; }
279
  return true;
280
  }
281
  }
licence.txt ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-w
4
  Tags: ad injection, adsense, advert injection, advert, ad, injection, advertising, affiliate, inject, injection, insert, widget, widgets, sidebar, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, Adsense Injection, free, blog, ad rotation, A:B testing, split testing, WP Super Cache, W3 Total Cache, WP Cache
5
  Requires at least: 2.8.6
6
  Tested up to: 3.2.1
7
- Stable tag: 1.1.0.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
 
@@ -12,6 +12,15 @@ Injects any adverts (e.g. AdSense) into the WordPress posts or widget area. Rest
12
 
13
  Ad Injection from [reviewmylife](http://www.reviewmylife.co.uk/ "reviewmylife") injects any kind of advert or other content (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, W3 Total Cache and WP Cache.
14
 
 
 
 
 
 
 
 
 
 
15
  **New Features 1.1.x.x**
16
 
17
  * Template ads - you can now include ads anywhere in your theme template with some simple tags. You can load the top/random/bottom/footer ads, or you can load an ad from a text file on disk. Template ads inherit the same dynamic and global restrictions as for ads configured via the UI.
@@ -56,7 +65,7 @@ You can specify that ads should only be shown to search engine visitors, or to v
56
 
57
  = Block by referrer =
58
 
59
- Block ads to people coming from certain referring URLs. e.g. you may wish to treat people who arrive at your site after searching for your site name as direct visitors and disable the ads for them.
60
 
61
  = Ads on old posts only =
62
 
@@ -274,7 +283,7 @@ The top, random, bottom and footer ads can be placed into the category pages. Ca
274
 
275
  On the main settings page for Ad Injection just enter the number of adverts you want on these page types using the Archives column in the 'Ad placement settings' section.
276
 
277
- Ads will only appear on archives/category pages if you are showing the full post contents on these pages. They won't work if you are showing excerpts.
278
 
279
  = My adverts are overlapping with other page elements (e.g. images) =
280
 
@@ -286,6 +295,10 @@ If you always have a floated image at the top of the page you can set which para
286
 
287
  Check your style sheet to see if either the text or headings have the 'clear' attribute set. This may be preventing your text / headings from flowing around the advert.
288
 
 
 
 
 
289
  = I have configured four Google AdSense ad units but only three are showing. Why? =
290
 
291
  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.
@@ -316,6 +329,52 @@ You can do the same for tags using has_tag. See http://codex.wordpress.org/Funct
316
 
317
  Note - this will only work in direct insertion mode.
318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  = How can I show different ads for different post authors? =
320
 
321
  This is something I hope to build into the UI at some point. But in the mean time you can use PHP in the ad code boxes to do this: e.g.
@@ -349,9 +408,9 @@ You can download the Country Filter plugin from http://wordpress.org/extend/plug
349
 
350
  = If I restrict a widget to both a category and a tag it doesn't appear in the relevant category/tag archives. Why? =
351
 
352
- If you set an with a tag restriction of 'tag1' and a category restriction of 'cat1', then it will only appear on pages that have BOTH the tag1 and cat1 property.
353
 
354
- A post in this category with that tag will work as you spotted.
355
 
356
  But if will not show in the 'tag1' archive or 'cat1' category. This is because the 'tag1' archive is not part of the 'cat1' category. A tag archive can't be part of a category, and a category archive can't be part of a tag.
357
 
@@ -512,12 +571,22 @@ If you do get any errors please use the 'Report a bug or give feedback' link on
512
 
513
  == Screenshots ==
514
 
515
- 1. Easy to use interface which allows you to copy and paste your ad code directly from your ad provider. Options are provided to control when and where your ads appear.
516
- 2. The ads are automatically injected into the pages of your blog.
517
- 3. Can choose to show the ads only to search engine visitors, or define IP addresses that ads aren't shown to.
 
 
518
 
519
  == Changelog ==
520
 
 
 
 
 
 
 
 
 
521
  = 1.1.0.6 =
522
  * New block ads by referring keyword/URL feature.
523
  * Load tags in batches to reduce memory used when displaying main settings screen. Will help people with lots of tags.
@@ -714,6 +783,9 @@ Fix 'Something badly wrong in num_rand_ads_to_insert' message that occurs on pag
714
 
715
  == Upgrade Notice ==
716
 
 
 
 
717
  = 1.1.0.6 =
718
  * New block ads by referrer feature. Reduce UI memory usage for people with lots of tags. Fix randomad override tag.
719
 
4
  Tags: ad injection, adsense, advert injection, advert, ad, injection, advertising, affiliate, inject, injection, insert, widget, widgets, sidebar, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, Adsense Injection, free, blog, ad rotation, A:B testing, split testing, WP Super Cache, W3 Total Cache, WP Cache
5
  Requires at least: 2.8.6
6
  Tested up to: 3.2.1
7
+ Stable tag: 1.2.0.0
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
 
12
 
13
  Ad Injection from [reviewmylife](http://www.reviewmylife.co.uk/ "reviewmylife") injects any kind of advert or other content (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, W3 Total Cache and WP Cache.
14
 
15
+ **New Features 1.2.x.x**
16
+
17
+ * Set the position of the top and bottom advert by paragraph or character.
18
+ * Position the random ads to start or stop in the middle of the post.
19
+ * Stop the random ads 2/3 of the way down a post, or at a paragraph/character position from the beginning/end of the post.
20
+ * Fade unused Home/Archive options instead of making them dissapear.
21
+ * Add page age settings to status.
22
+ * Improve debug messages.
23
+
24
  **New Features 1.1.x.x**
25
 
26
  * Template ads - you can now include ads anywhere in your theme template with some simple tags. You can load the top/random/bottom/footer ads, or you can load an ad from a text file on disk. Template ads inherit the same dynamic and global restrictions as for ads configured via the UI.
65
 
66
  = Block by referrer =
67
 
68
+ Block ads to people coming from certain referring URLs. e.g. you may wish to treat people who arrive at your site after searching for your name as direct visitors and disable the ads for them.
69
 
70
  = Ads on old posts only =
71
 
283
 
284
  On the main settings page for Ad Injection just enter the number of adverts you want on these page types using the Archives column in the 'Ad placement settings' section.
285
 
286
+ These ads will only appear on archives/category pages if you are showing the full post contents on these pages. They won't work if you are showing excerpts. These restrictions don't apply to widget ads.
287
 
288
  = My adverts are overlapping with other page elements (e.g. images) =
289
 
295
 
296
  Check your style sheet to see if either the text or headings have the 'clear' attribute set. This may be preventing your text / headings from flowing around the advert.
297
 
298
+ = After adding the ads my sidebar has dropped down the screen. Why? =
299
+
300
+ This is because you have inserted adverts that are too wide for your site's layout. The browser can no longer fit all the parts of your layout side-by-side. Try using ads that are less wide.
301
+
302
  = I have configured four Google AdSense ad units but only three are showing. Why? =
303
 
304
  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.
329
 
330
  Note - this will only work in direct insertion mode.
331
 
332
+ == I want a different advert for each category. How can I do this? ==
333
+
334
+ 1. In your plugins directory create a sub-directory called 'ad-injection-ads'. e.g. /wordpress/wp-content/plugins/ad-injection-ads/
335
+
336
+ 2. Create a text files in this folder for each of the categories that you want an ad for. The text files should be named [category nicename].txt The 'nicename' of the category is the category name with spaces and dots converted to '-' and apostrophes removed. e.g.
337
+
338
+ Liverpool = liverpool.txt
339
+ Manchester United = manchester-united.txt
340
+ A.F.C Aldermaston = a-f-c-aldermaston.txt
341
+ Bishop's Stortford = bishops-stortford.txt
342
+
343
+ 3. Then put this code (from the starting `<?php` to the closing `?>`) into the ad box. It will load the text file ad matching the category name when the post is displayed.
344
+
345
+ `<?php
346
+ $plugin_dir = dirname(__FILE__);
347
+ $ad_dir = dirname($plugin_dir).'/ad-injection-ads/';
348
+ if (file_exists($ad_dir)){
349
+ global $post;
350
+ $categories = get_the_category($post->ID);
351
+ foreach ($categories as $cat){
352
+ // nicename: spaces and dots are converted to '-' and apostrophes are removed
353
+ $full_ad_path = $ad_dir.$cat->category_nicename.'.txt';
354
+ if (file_exists($full_ad_path)){
355
+ $ad = file_get_contents($full_ad_path);
356
+ if ($ad === false) echo "<!--ADINJ CATCODE: could not read ad from file: $full_ad_path-->\n";
357
+ echo $ad;
358
+ break; // only show first category ad that matches
359
+ } else {
360
+ echo "<!--ADINJ CATCODE: could not find ad at: $full_ad_path-->\n";
361
+ }
362
+ }
363
+ } else {
364
+ echo "<!--ADINJ CATCODE: could not find ad directory: $ad_dir-->\n";
365
+ }
366
+ ?>`
367
+
368
+ Some extra information:
369
+ * This code will load one text file ad per post. If for example you had a post with the categories 'Liverpool' and 'Manchester United' it would load which ever ad it found first.
370
+ * If will ignore categories that have no text file in the directory. If you have a post with the categories 'Liverpool' and 'Latest News' then it will always load the liverpool.txt as long as you don't create a 'latest-news.txt'.
371
+ * This code will only work in 'direct' ad insertion mode. It won't work in 'mfunc' mode.
372
+
373
+ Expansion ideas:
374
+ * Show a default advert if no text file exists.
375
+ * Create multiple text files for each category and then randomly select one.
376
+ * Use different code for top, random or bottom ads. e.g. you could have liverpool_top.txt and liverpool_random.txt
377
+
378
  = How can I show different ads for different post authors? =
379
 
380
  This is something I hope to build into the UI at some point. But in the mean time you can use PHP in the ad code boxes to do this: e.g.
408
 
409
  = If I restrict a widget to both a category and a tag it doesn't appear in the relevant category/tag archives. Why? =
410
 
411
+ If you set an ad with a tag restriction of 'tag1' and a category restriction of 'cat1', then it will only appear on pages that have BOTH the tag1 and cat1 property.
412
 
413
+ A post in this category with that tag will have the ad.
414
 
415
  But if will not show in the 'tag1' archive or 'cat1' category. This is because the 'tag1' archive is not part of the 'cat1' category. A tag archive can't be part of a category, and a category archive can't be part of a tag.
416
 
571
 
572
  == Screenshots ==
573
 
574
+ 1. Easy to use interface which allows you to select on what types of pages the ads appear.
575
+ 2. You can copy and paste your ad code directly from your ad provider.
576
+ 3. The ads are automatically injected into the pages of your blog.
577
+ 4. There are options to define how many ads appear on the post, and where they appear. The quantity of ads can be varied depending on post length.
578
+ 5. Can choose to show the ads only to search engine visitors, or define IP addresses that ads aren't shown to.
579
 
580
  == Changelog ==
581
 
582
+ = 1.2.0.0 =
583
+ * Set the position of the top and bottom advert by paragraph or character.
584
+ * Position the random ads to start or stop in the middle of the post.
585
+ * Stop the random ads 2/3 of the way down a post, or at a paragraph/character position from the beginning/end of the post.
586
+ * Fade unused Home/Archive options instead of making them dissapear.
587
+ * Add page age settings to status.
588
+ * Improve debug messages.
589
+
590
  = 1.1.0.6 =
591
  * New block ads by referring keyword/URL feature.
592
  * Load tags in batches to reduce memory used when displaying main settings screen. Will help people with lots of tags.
783
 
784
  == Upgrade Notice ==
785
 
786
+ = 1.2.0.0 =
787
+ * New top, random and bottom positioning options. UI updates. Debug message improvements.
788
+
789
  = 1.1.0.6 =
790
  * New block ads by referrer feature. Reduce UI memory usage for people with lots of tags. Fix randomad override tag.
791
 
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
screenshot-3.png CHANGED
Binary file
screenshot-4.png ADDED
Binary file
screenshot-5.png ADDED
Binary file
ui-tab-adrotation.php CHANGED
@@ -10,7 +10,7 @@ function adinj_tab_adrotation(){
10
  $ops = adinj_options();
11
 
12
  echo <<<DOCS
13
- <p><a href="#multiple_top">Top adverts</a> | <a href="#multiple_random">Random adverts</a> | <a href="#multiple_bottom">Bottom adverts</a> | <a href="#multiple_footer">Footer adverts</a> | <a href="#misc">Misc settings</a> | <a href="#docs_tags">Tag docs</a> | <a href="#testads">Test ads</a></p>
14
  DOCS;
15
 
16
  $total_rand_split = adinj_total_split('ad_code_random_', $ops);
@@ -84,38 +84,9 @@ DOCS;
84
  echo '</table>';
85
  adinj_postbox_end();
86
 
87
-
88
- adinj_postbox_start(__("Misc options", 'adinj'), 'misc'); ?>
89
- <table>
90
- <tr>
91
- <td>Content length counting method:</td>
92
- <td>
93
- <?php
94
- adinj_selection_box("content_length_unit",
95
- array('viewable' => 'viewable chars', 'all' => 'all chars', 'words' => 'words'));
96
- ?>
97
- </td></tr>
98
- <tr><td colspan="2"><p><span style="font-size:10px;">When defining conditions that refer to the length of the content; do you want to count viewable characters, all characters (which includes HTML tags), or number of words?</span></p></td></tr>
99
- <tr><td>
100
- <?php _e("Allow multiple random ads to be injected at the same positions.", 'adinj') ?></td><td><?php adinj_add_checkbox('multiple_ads_at_same_position') ?> (default is to inject ads at unique positions)
101
- </td></tr>
102
-
103
- <tr><td>
104
- <?php _e("Allow random ad on last paragraph");
105
- echo '</td><td>';
106
- adinj_add_checkbox('rnd_allow_ads_on_last_paragraph'); ?>
107
-
108
- <td></tr>
109
- <tr><td>
110
- <?php _e("Re-select an ad for each position on post");
111
- echo '</td><td>';
112
- adinj_add_checkbox('rnd_reselect_ad_per_position_in_post'); ?>
113
- </td></tr>
114
-
115
- </table>
116
- <?php adinj_postbox_end();
117
 
118
  adinj_docs_tags();
 
119
 
120
  adinj_testads();
121
 
@@ -131,7 +102,11 @@ echo <<<EOT
131
  <tr><td>
132
  <a name="$name"></a>
133
  <span style="font-size:10px;"><b>$title $num</b></span><br />
134
- <textarea name="$name" rows="8" cols="60">$ops[$name]</textarea>
 
 
 
 
135
  </td><td>
136
  <input name="$namesplit" size="7" value="$ops[$namesplit]" />
137
  <br />
@@ -147,6 +122,21 @@ function adinj_docs_tags(){
147
 
148
  <p>These tags can be inserted into the page source to override the configured behaviour on single posts and pages. Because sometimes specific pages need to be treated differently.</p>
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  <ul>
151
  <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>
152
  </ul>
@@ -154,20 +144,15 @@ function adinj_docs_tags(){
154
  <p></p>
155
 
156
  <ul>
157
- <li><code>&lt;!--adsandwich--&gt;</code> - Inserts the top and bottom ad but no random ads. Disables all other ads.</li>
158
- <li><code>&lt;!--adfooter--&gt;</code> - Insert a single ad at the very bottom. Disables all other ads.</li>
159
  </ul>
160
 
161
  <p></p>
162
 
163
- <ol>
164
- <li><code>&lt;!--adsensestart--&gt;</code> - Random ads will start from this point*. For compatibility with Adsense Injection.</li>
165
- <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>
166
- <li><code>&lt;!--adstart--&gt;</code> - Random ads will start from this point*.</li>
167
- <li><code>&lt;!--adend--&gt;</code> - Random ads will not be inserted after this point*.</li>
168
- </ol>
169
-
170
- <p>These four tags will not affect the top and bottom ad.</p>
171
 
172
  <h4>Custom field for disabling adverts</h4>
173
 
10
  $ops = adinj_options();
11
 
12
  echo <<<DOCS
13
+ <p><a href="#multiple_top">Top adverts</a> | <a href="#multiple_random">Random adverts</a> | <a href="#multiple_bottom">Bottom adverts</a> | <a href="#multiple_footer">Footer adverts</a> | <a href="#docs_tags">Tag docs</a> | <a href="#testads">Test ads</a></p>
14
  DOCS;
15
 
16
  $total_rand_split = adinj_total_split('ad_code_random_', $ops);
84
  echo '</table>';
85
  adinj_postbox_end();
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  adinj_docs_tags();
89
+
90
 
91
  adinj_testads();
92
 
102
  <tr><td>
103
  <a name="$name"></a>
104
  <span style="font-size:10px;"><b>$title $num</b></span><br />
105
+ <textarea name="$name" rows="8" cols="
106
+ EOT;
107
+ adinj_table_width('rotation');
108
+ echo <<<EOT
109
+ ">$ops[$name]</textarea>
110
  </td><td>
111
  <input name="$namesplit" size="7" value="$ops[$namesplit]" />
112
  <br />
122
 
123
  <p>These tags can be inserted into the page source to override the configured behaviour on single posts and pages. Because sometimes specific pages need to be treated differently.</p>
124
 
125
+ <h3>Fully supported tags</h3><br />
126
+
127
+ <ul>
128
+ <li><code>&lt;!--topad--&gt;</code> OR <code>&lt;!--randomad--&gt;</code> OR <code>&lt;!--bottomad--&gt;</code> - These tags allow precise positioning of the adverts instead of using the computer calculated positions.</li>
129
+ </ul>
130
+
131
+ <ul>
132
+ <li><code>&lt;!--adstart--&gt;</code> - Random ads will start from this point.</li>
133
+ <li><code>&lt;!--adend--&gt;</code> - Random ads will not be inserted after this point.</li>
134
+ </ul>
135
+
136
+ <p>The above adstart/adend tags and below adsensestart tag will not affect the top and bottom ad.</p>
137
+
138
+ <h3>Other tags</h3><br />
139
+
140
  <ul>
141
  <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>
142
  </ul>
144
  <p></p>
145
 
146
  <ul>
147
+ <li><code>&lt;!--adsensestart--&gt;</code> - Random ads will start from this point. For compatibility with Adsense Injection.</li>
 
148
  </ul>
149
 
150
  <p></p>
151
 
152
+ <ul>
153
+ <li><code>&lt;!--adsandwich--&gt;</code> - Inserts the top and bottom ad but no random ads. Disables all other ads.</li>
154
+ <li><code>&lt;!--adfooter--&gt;</code> - Insert a single ad at the very bottom. Disables all other ads.</li>
155
+ </ul>
 
 
 
 
156
 
157
  <h4>Custom field for disabling adverts</h4>
158
 
ui-tab-main.php CHANGED
@@ -4,6 +4,8 @@ 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(){
@@ -14,12 +16,36 @@ function adinj_tab_main(){
14
 
15
  <?php adinj_global_settings_box($ops); ?>
16
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- <?php adinj_postbox_start(__("Ad placement settings", 'adinj'), 'adsettings'); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  <p></p>
21
 
22
- <table border="0" class="adinjtable" width="95%">
23
  <tr><td></td><td width="20%"><b>Single/Page</b></td><td width="20%"><b>Home</b></td><td width="20%"><b>Archive</b></td></tr>
24
  <tr><td colspan="4"><h3><a name="topadplacement"></a>Top ad [<a href="#topadcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
25
 
@@ -35,7 +61,7 @@ function adinj_tab_main(){
35
  ?>
36
  </div></td></tr>
37
 
38
- <tr><td><b>|_</b> Max num of ads on whole page:</td><td>1</td><td><div class="adinj_home">
39
  <?php
40
  $num_ads_array = array(0,1,2,3,4,5,6,7,8,9,10);
41
  adinj_selection_box("home_max_num_top_ads_per_page", $num_ads_array);
@@ -44,8 +70,30 @@ function adinj_tab_main(){
44
  ?>
45
  </div></td></tr>
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- <tr><td colspan="4"><h3><a name="randomadplacement"></a>Random ads [<a href="#randomadcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
49
  <tr><td>Max num of ads on whole page:</td><td>
50
  n/a
51
  </td><td><div class="adinj_home">
@@ -55,7 +103,7 @@ function adinj_tab_main(){
55
  adinj_selection_box("archive_max_num_random_ads_per_page", $num_ads_array);
56
  ?>
57
  </div></td></tr>
58
- <tr><td><b>|_ </b>Max num of random ads per post:</td><td>
59
  <?php
60
  adinj_selection_box("max_num_of_ads", $num_ads_array);
61
  echo '</td><td><div class="adinj_home">';
@@ -68,45 +116,131 @@ function adinj_tab_main(){
68
  adinj_random_ad_limit_table();
69
  ?>
70
  <tr><td colspan="4">
 
 
71
  <table class="adinjtable">
72
  <tr><td>
73
  <?php
74
- _e("Always start the first ad ", 'adinj');
75
  ?>
76
- </td><td>
77
- <input type="radio" name="random_ads_after_mode" value="at" <?php if ($ops['random_ads_after_mode']=='at') echo 'checked="checked"'; ?> /> <b>at</b><br />
78
- <input type="radio" name="random_ads_after_mode" value="after" <?php if ($ops['random_ads_after_mode']=='after') echo 'checked="checked"'; ?> /> <b>at or after</b><br />
79
- </td><td>
80
- <input type="radio" name="random_ads_after_unit" value="paragraph" <?php if ($ops['random_ads_after_unit']=='paragraph') echo 'checked="checked"'; ?> /> <b>paragraph:</b><br />
81
- <input type="radio" name="random_ads_after_unit" value="character" <?php if ($ops['random_ads_after_unit']=='character' || $ops['ads_enabled']=='') echo 'checked="checked"'; ?> /> <b>character:</b><br />
 
 
82
  </td>
83
  <td>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  <?php
85
- adinj_selection_box("start_from_paragraph", array('d',1,2,3,4,5,100,200,300,500,750,1000,1500,2000,3000,4000,5000,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20), " ");
86
  ?>
 
 
 
87
  </td></tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  </table>
89
 
90
  <script type="text/javascript">
91
  jQuery(document).ready(function(){
92
- jQuery('input[name=random_ads_after_unit]:radio').change(function() {
93
- if (jQuery('input[name=random_ads_after_unit]:checked').val() == "character"){
94
- jQuery('#random_ads_after_warning').slideDown(300);
95
  } else {
96
- jQuery('#random_ads_after_warning').slideUp(300);
97
  }
98
  return true;
99
  });
100
  });
101
- if ('<?php echo $ops['random_ads_after_unit'] ?>' == 'paragraph') {
102
- document.write('<style type="text/css">#random_ads_after_warning { display: none; }</style>');
103
  }
104
- </script>
105
- <div id="random_ads_after_warning"><span style="font-size:10px;color:red;">Note: If starting 'at character x', the start point will be the next paragraph.</span><br /></div>
106
 
107
  </td></tr>
108
 
109
- <tr><td colspan="4"><h3><a name="bottomadplacement"></a>Bottom ad [<a href="#bottomadcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
110
 
111
  <tr><td>Only show on posts longer than:</td><td>
112
  <?php
@@ -118,7 +252,7 @@ function adinj_tab_main(){
118
  ?>
119
  </div></td></tr>
120
 
121
- <tr><td><b>|_ </b>Max num of ads on whole page:</td><td>1</td><td><div class="adinj_home">
122
  <?php
123
  adinj_selection_box("home_max_num_bottom_ads_per_page", $num_ads_array);
124
  echo '</div></td><td><div class="adinj_archive">';
@@ -126,19 +260,49 @@ function adinj_tab_main(){
126
  ?>
127
  </div></td></tr>
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
-
 
 
 
 
 
 
 
 
 
 
 
131
  </table>
132
 
133
- <?php adinj_postbox_end(); ?>
134
-
135
 
 
 
136
 
137
-
138
- <?php adinj_postbox_start(__("Adverts", 'adinj'), 'adverts'); ?>
139
 
140
  <h3><a name="topadcode"></a>Top ad (below post title - this is not a 'header' ad) [<a href="#topadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_top'>pool</a>]--></h3>
141
- <table border="0" class="adinjtable" width="95%">
142
  <tr><td>
143
  <textarea name="ad_code_top_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_top_1']; ?></textarea>
144
  <br />
@@ -153,7 +317,7 @@ function adinj_tab_main(){
153
  <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>
154
 
155
  <h3><a name="randomadcode"></a>Random ad (inserted randomly between paragraphs) [<a href="#randomadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_random'>pool</a>]--></h3>
156
- <table border="0" class="adinjtable" width="95%">
157
  <tr><td>
158
  <textarea name="ad_code_random_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_random_1']; ?></textarea>
159
  <br />
@@ -167,7 +331,7 @@ function adinj_tab_main(){
167
  </table>
168
 
169
  <h3><a name="bottomadcode"></a>Bottom ad (below the post content) [<a href="#bottomadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_bottom'>pool</a>]--></h3>
170
- <table border="0" class="adinjtable" width="95%">
171
  <tr><td>
172
  <textarea name="ad_code_bottom_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_bottom_1']; ?></textarea>
173
  <br />
@@ -182,7 +346,7 @@ function adinj_tab_main(){
182
 
183
 
184
  <h3><a name="footeradcode"></a>Footer ad (put into 'the_footer' hook - not supported by all themes) [<a href="#footeradplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_footer'>pool</a>]--></h3>
185
- <table border="0" class="adinjtable" width="95%">
186
  <tr><td>
187
  <textarea name="ad_code_footer_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_footer_1']; ?></textarea>
188
  <br />
@@ -202,46 +366,7 @@ function adinj_tab_main(){
202
  </td></tr>
203
  </table>
204
 
205
-
206
- <?php adinj_postbox_end(); ?>
207
-
208
- <?php adinj_filters_box($ops); ?>
209
-
210
- <?php adinj_insertion_mode_box($ops); ?>
211
-
212
- <br clear="all" />
213
-
214
- <?php
215
-
216
- adinj_docs();
217
-
218
- adinj_testads();
219
-
220
- global $adinj_warning_msg_chmod;
221
- if (!empty($adinj_warning_msg_chmod)){
222
- echo '<a name="warning_msg_chmod"></a>';
223
- echo '<br clear="all" />';
224
- echo $adinj_warning_msg_chmod;
225
- }
226
- }
227
-
228
- function adinj_table_width($table){
229
- global $wp_db_version;
230
- if ($table == 'ad'){
231
- if ($wp_db_version < 18226){
232
- echo '60';
233
- } else { //WP3.2+
234
- echo '70';
235
- }
236
- } else if ($table == 'dynamic'){
237
- if ($wp_db_version < 18226){
238
- echo '70';
239
- } else { //WP3.2+
240
- echo '80';
241
- }
242
- } else {
243
- echo '61';
244
- }
245
  }
246
 
247
  function adinj_global_settings_box($ops){
@@ -280,9 +405,9 @@ function adinj_global_settings_box($ops){
280
  <td><b><font color="red">Tick to disable ads:</font></b></td>
281
  <td><b>Single(<?php echo $count_posts->publish; ?>)</b></td>
282
  <td><b>Page(<?php echo $count_pages->publish; ?>)</b></td>
283
- <td><b>Home</b></td>
 
284
  <td><b>Archive</b></td>
285
- <td><b><a href="<?php echo get_bloginfo('url'); ?>" target="_new">Front</a></b></td>
286
  <td><b>404</b></td>
287
  <td><b>Search</b></td>
288
  </tr>
@@ -291,7 +416,7 @@ function adinj_global_settings_box($ops){
291
  adinj_add_exclude_row('|_&nbsp;&nbsp;<a href="#topadplacement">Top</a>', 'top_');
292
  adinj_add_exclude_row('|_&nbsp;&nbsp;<a href="#randomadplacement">Random</a>', 'random_');
293
  adinj_add_exclude_row('|_&nbsp;&nbsp;<a href="#bottomadplacement">Bottom</a>', 'bottom_');
294
- adinj_add_exclude_row('|_&nbsp;&nbsp;<a href="#footeradplacement">Footer</a>', 'footer_');
295
  adinj_add_exclude_row('|_&nbsp;&nbsp;Widget', 'widget_');
296
  adinj_add_exclude_row('|_&nbsp;&nbsp;Template', 'template_');
297
  ?>
@@ -353,11 +478,11 @@ function adinj_filters_box($ops){
353
  <h4>Top ad filters</h4>
354
  <?php adinj_condition_tables('top_', 'ui_top_conditions_show'); ?>
355
  <h4>Random ad filters</h4>
356
- <?php adinj_condition_tables('random_', 'ui_top_conditions_show'); ?>
357
  <h4>Bottom ad filters</h4>
358
- <?php adinj_condition_tables('bottom_', 'ui_top_conditions_show'); ?>
359
  <h4>Footer ad filters</h4>
360
- <?php adinj_condition_tables('footer_', 'ui_top_conditions_show'); ?>
361
  <?php
362
  adinj_postbox_end();
363
  }
@@ -367,9 +492,6 @@ function adinj_insertion_mode_box($ops){
367
  <h4>Ad insertion mode</h4>
368
  <blockquote>
369
  <input type="radio" name="ad_insertion_mode" value="mfunc" <?php if (adinj_mfunc_mode()) echo 'checked="checked"'; ?> /> <b>mfunc: Insert ads using cache compatible mfunc tags</b> - Dynamic features will work with WP Super Cache, W3 Total Cache and WP Cache. Only select this mode if you are using one of those caching plugins and want to use dynamic features (IP / referrer restriction, alt content and ad roatation). If you aren't using dynamic features select direct mode.
370
- <?php if (!is_supported_caching_plugin_active()) {
371
- echo '<p><b><span style="font-size:10px;color:red;">Note: A supported caching plugin does not appear to be active. If you are not using WP Super Cache / W3 Total Cache / WP Cache you should use one of the direct insertion modes below.</span></b></p>';
372
- } ?>
373
 
374
  <?php if (!adinj_mfunc_mode()) { ?>
375
  <script type="text/javascript">
@@ -379,6 +501,9 @@ function adinj_insertion_mode_box($ops){
379
  <br />
380
 
381
  <div id="caching_plugin_msg" class="caching_plugin_msg">
 
 
 
382
  <?php
383
  if (is_plugin_active('wp-super-cache/wp-cache.php')){
384
  adinj_wp_super_cache_msg();
@@ -426,7 +551,7 @@ function adinj_insertion_mode_box($ops){
426
  <blockquote>
427
  <?php adinj_add_checkbox('block_keywords') ?><?php _e("Don't show ads to visitors from external sites if the referrer contains one of these keywords or substrings.", 'adinj') ?> If a blocked string is found block ads for: <?php adinj_selection_box("block_ads_for_hours", array('1'=>'1 hour', '2'=>'2 hours', '3'=>'3 hours', '6'=>'6 hours', '24'=>'1 day', '48'=>'2 days', '72'=>'3 days', '168'=>'1 week', '720'=>'30 days', '8760'=>'1 year')); ?><br />
428
  <textarea name="blocked_keywords" rows="2" cols="<?php adinj_table_width('dynamic'); ?>"><?php echo $ops['blocked_keywords']; ?></textarea>
429
- <p>Comma separated list e.g.: <br /><code>myblogname.com, .ru, .in, james+bond</code></p>
430
  </blockquote>
431
 
432
 
@@ -457,8 +582,8 @@ function adinj_add_exclude_row($name, $prefix=''){
457
  <td><?php adinj_add_checkbox($prefix.'exclude_single', 'adinj_single', $all) ?></td>
458
  <td><?php adinj_add_checkbox($prefix.'exclude_page', 'adinj_page', $all) ?></td>
459
  <td><?php adinj_add_checkbox($prefix.'exclude_home', 'adinj_home', $all) ?></td>
460
- <td><?php adinj_add_checkbox($prefix.'exclude_archive', 'adinj_archive', $all) ?></td>
461
  <td><?php adinj_add_checkbox($prefix.'exclude_front', 'adinj_front', $all) ?></td>
 
462
  <td><?php adinj_add_checkbox($prefix.'exclude_404', 'adinj_404', $all) ?></td>
463
  <td><?php adinj_add_checkbox($prefix.'exclude_search', 'adinj_search', $all) ?></td>
464
  </tr>
@@ -467,7 +592,7 @@ function adinj_add_exclude_row($name, $prefix=''){
467
 
468
  function adinj_random_ad_limit_table(){
469
  ?>
470
- <tr><td>&nbsp;<b>|_</b> No ads if post shorter than:</td>
471
  <?php
472
  $prefixes = array("", "home", "archive");
473
  $unit = adinj_counting_unit_description();
@@ -480,7 +605,7 @@ function adinj_random_ad_limit_table(){
480
  echo '</div></td>';
481
  } ?>
482
  </tr>
483
- <tr><td>&nbsp;<b>|_</b> Only 1 ad if post shorter than:</td>
484
  <?php
485
  foreach ($prefixes as $prefix){
486
  echo '<td><div class="adinj_'.$prefix.'">';
@@ -489,7 +614,7 @@ function adinj_random_ad_limit_table(){
489
  echo '</div></td>';
490
  } ?>
491
  </tr>
492
- <tr><td>&nbsp;<b>|_</b> Only 2 ads if post shorter than:</td>
493
  <?php
494
  foreach ($prefixes as $prefix){
495
  echo '<td><div class="adinj_'.$prefix.'">';
@@ -499,7 +624,7 @@ function adinj_random_ad_limit_table(){
499
  }
500
  ?>
501
  </tr>
502
- <tr><td>&nbsp;<b>|_</b> Only 3 ads if post shorter than:</td>
503
  <?php
504
  foreach ($prefixes as $prefix){
505
  echo '<td><div class="adinj_'.$prefix.'">';
@@ -589,6 +714,18 @@ function adinj_side_status_box(){
589
  if ($info[0] != 'red') { ?>
590
  </td></tr>
591
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  <tr><td style="text-align:right">
593
  <b><a href="#restrictions">Mode</a></b>
594
  </td><td>
@@ -596,7 +733,7 @@ function adinj_side_status_box(){
596
  </td></tr>
597
 
598
  <tr><td style="text-align:right">
599
- <b><a href="#dynamic">Restrictions</a></b>
600
  </td><td>
601
  <?php $info = adinj_get_status('restrictions'); echo adinj_dot($info[0]).' '.$info[1]; ?>
602
  </td></tr>
@@ -708,17 +845,15 @@ function adinj_docs(){
708
 
709
  <?php adinj_postbox_start(__("Quick Start", 'adinj'), "docsquickstart", '95%'); ?>
710
 
711
- <p>1. Copy and paste your ad code into the ad code boxes.</p>
712
-
713
- <p>2. Choose how many ads of each type you want displayed.</p>
714
 
715
- <p>3. Configure any ad positioning (optional).</p>
716
 
717
- <p>4. Check the ad insertion mode (in the Insertion mode and ad display restriction section).</p>
718
 
719
- <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>
720
 
721
- <p>6. Enable your ads (tick box at the very top).</p>
722
 
723
  <?php adinj_postbox_end();
724
 
4
  http://www.reviewmylife.co.uk/
5
  */
6
 
7
+ //TODO widths changed from 95-98% check on 3.1
8
+
9
  if (!is_admin()) return;
10
 
11
  function adinj_tab_main(){
16
 
17
  <?php adinj_global_settings_box($ops); ?>
18
 
19
+ <?php adinj_placement_settings_box($ops); ?>
20
+
21
+ <?php adinj_adverts_box($ops); ?>
22
+
23
+ <?php adinj_insertion_mode_box($ops); ?>
24
+
25
+ <?php adinj_filters_box($ops); ?>
26
+
27
+ <br clear="all" />
28
+
29
+ <?php
30
 
31
+ adinj_docs();
32
+
33
+ adinj_testads();
34
+
35
+ global $adinj_warning_msg_chmod;
36
+ if (!empty($adinj_warning_msg_chmod)){
37
+ echo '<a name="warning_msg_chmod"></a>';
38
+ echo '<br clear="all" />';
39
+ echo $adinj_warning_msg_chmod;
40
+ }
41
+ }
42
+
43
+ function adinj_placement_settings_box($ops){
44
+ adinj_postbox_start(__("Ad placement settings", 'adinj'), 'adsettings'); ?>
45
 
46
  <p></p>
47
 
48
+ <table border="0" class="adinjtable" width="98%">
49
  <tr><td></td><td width="20%"><b>Single/Page</b></td><td width="20%"><b>Home</b></td><td width="20%"><b>Archive</b></td></tr>
50
  <tr><td colspan="4"><h3><a name="topadplacement"></a>Top ad [<a href="#topadcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
51
 
61
  ?>
62
  </div></td></tr>
63
 
64
+ <tr><td>|_ Max num of ads on whole page:</td><td>1</td><td><div class="adinj_home">
65
  <?php
66
  $num_ads_array = array(0,1,2,3,4,5,6,7,8,9,10);
67
  adinj_selection_box("home_max_num_top_ads_per_page", $num_ads_array);
70
  ?>
71
  </div></td></tr>
72
 
73
+ <tr><td colspan="4">
74
+ <table class="adinjtable">
75
+ <tr><td>
76
+ <?php
77
+ _e("Put the top ad at", 'adinj');
78
+ ?>
79
+ </td>
80
+ <td>
81
+ <input type="radio" name="top_ad_position_unit" value="paragraph" <?php if ($ops['top_ad_position_unit']=='paragraph') echo 'checked="checked"'; ?> /> paragraph:<br />
82
+ <input type="radio" name="top_ad_position_unit" value="character" <?php if ($ops['top_ad_position_unit']=='character') echo 'checked="checked"'; ?> /> character:<br />
83
+ </td>
84
+ <td>
85
+ <?php
86
+ adinj_selection_box("top_ad_position", array(0,1,2,3,4,5,100,200,300,500,750,1000,1500,2000,3000), " ");
87
+ ?>
88
+ </td></tr>
89
+ </table>
90
+ </td></tr>
91
+
92
+ <tr><td colspan="4">
93
+ <p></p>
94
+ </td></tr>
95
 
96
+ <tr><td colspan="4"><input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" /><h3><a name="randomadplacement"></a>Random ads [<a href="#randomadcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
97
  <tr><td>Max num of ads on whole page:</td><td>
98
  n/a
99
  </td><td><div class="adinj_home">
103
  adinj_selection_box("archive_max_num_random_ads_per_page", $num_ads_array);
104
  ?>
105
  </div></td></tr>
106
+ <tr><td>|_ Max num of random ads per post:</td><td>
107
  <?php
108
  adinj_selection_box("max_num_of_ads", $num_ads_array);
109
  echo '</td><td><div class="adinj_home">';
116
  adinj_random_ad_limit_table();
117
  ?>
118
  <tr><td colspan="4">
119
+
120
+
121
  <table class="adinjtable">
122
  <tr><td>
123
  <?php
124
+ _e("Start the random ad(s) ", 'adinj');
125
  ?>
126
+ </td>
127
+ <td colspan="3">
128
+ <input type="radio" name="random_ads_start_mode" value="anywhere" <?php if ($ops['random_ads_start_mode']=='anywhere') echo 'checked="checked"'; ?> /> anywhere<br />
129
+ <br />
130
+ </td>
131
+ </tr>
132
+ <tr>
133
+ <td>
134
  </td>
135
  <td>
136
+ <input type="radio" name="random_ads_start_mode" value="at" <?php if ($ops['random_ads_start_mode']=='at') echo 'checked="checked"'; ?> /> at<br />
137
+ <input type="radio" name="random_ads_start_mode" value="after" <?php if ($ops['random_ads_start_mode']=='after') echo 'checked="checked"'; ?> /> at or after<br />
138
+ </td><td colspan="2">
139
+ <table class="adinjtable">
140
+ <tr><td>
141
+ <input type="radio" name="random_ads_start_unit" value="paragraph" <?php if ($ops['random_ads_start_unit']=='paragraph') echo 'checked="checked"'; ?> /> paragraph:<br />
142
+ <input type="radio" name="random_ads_start_unit" value="character" <?php if ($ops['random_ads_start_unit']=='character') echo 'checked="checked"'; ?> /> character:<br />
143
+ </td><td>
144
+ <?php
145
+ adinj_selection_box("random_ads_start_at", array(1,2,3,4,5,100,200,300,500,750,1000,1500,2000,3000,4000,5000,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20), " ");
146
+ ?>
147
+ </td>
148
+ </tr>
149
+ </table>
150
+ </td>
151
+ </tr>
152
+
153
+ <tr><td></td>
154
+ <td colspan="3">
155
+ <div id="random_ads_start_warning"><span style="font-size:10px;color:red;">Note: If starting 'at character x', the start point will be the next paragraph.</span><br /></div>
156
+ <br />
157
+ </td>
158
+ </tr>
159
+
160
+ <tr><td></td>
161
+ <td colspan="3">
162
+ <input type="radio" name="random_ads_start_mode" value="middleback" <?php if ($ops['random_ads_start_mode']=='middleback') echo 'checked="checked"'; ?> /> in the middle of the post (uses raw char count - then back)<br />
163
+ <input type="radio" name="random_ads_start_mode" value="middleforward" <?php if ($ops['random_ads_start_mode']=='middleforward') echo 'checked="checked"'; ?> /> in the middle of the post (uses raw char count - then forward)<br />
164
+ <input type="radio" name="random_ads_start_mode" value="middleparaback" <?php if ($ops['random_ads_start_mode']=='middleparaback') echo 'checked="checked"'; ?> /> at the middle paragraph (if 4 paragraphs pos=2, if 7 pos=3)<br />
165
+ <input type="radio" name="random_ads_start_mode" value="middleparaforward" <?php if ($ops['random_ads_start_mode']=='middleparaforward') echo 'checked="checked"'; ?> /> at the middle paragraph (if 4 paragraphs pos=2, if 7 pos=4)<br />
166
+ <br />
167
+ </td>
168
+ </tr>
169
+
170
+ <tr><td>
171
  <?php
172
+ _e("Stop the random ad(s) ", 'adinj');
173
  ?>
174
+ </td><td>
175
+ <input type="radio" name="random_ads_end_mode" value="anywhere" <?php if ($ops['random_ads_end_mode']=='anywhere') echo 'checked="checked"'; ?> /> anywhere<br />
176
+ <br />
177
  </td></tr>
178
+ <tr><td></td>
179
+ <td>
180
+ <input type="radio" name="random_ads_end_mode" value="at" <?php if ($ops['random_ads_end_mode']=='at') echo 'checked="checked"'; ?> /> at<br />
181
+ </td><td>
182
+ <table class="adinjtable">
183
+ <tr><td>
184
+ <input type="radio" name="random_ads_end_unit" value="paragraph" <?php if ($ops['random_ads_end_unit']=='paragraph') echo 'checked="checked"'; ?> /> paragraph:<br />
185
+ <input type="radio" name="random_ads_end_unit" value="character" <?php if ($ops['random_ads_end_unit']=='character') echo 'checked="checked"'; ?> /> character:<br />
186
+ </td><td>
187
+ <?php
188
+ adinj_selection_box("random_ads_end_at", array(1,2,3,4,5,100,200,300,500,750,1000,1500,2000,3000,4000,5000,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20), " ");
189
+ ?>
190
+ </td>
191
+ <td>
192
+ <?php
193
+ adinj_selection_box("random_ads_end_direction", array('fromstart'=>'from the start', 'fromend'=>'from the end'), " ");
194
+ ?>
195
+ </td>
196
+ </table>
197
+ <br />
198
+ </td>
199
+ </tr>
200
+ <tr><td></td>
201
+ <td colspan="3">
202
+ <input type="radio" name="random_ads_end_mode" value="middleforward" <?php if ($ops['random_ads_end_mode']=='middleforward') echo 'checked="checked"'; ?> /> in the middle of the post (uses raw character count)<br />
203
+ <input type="radio" name="random_ads_end_mode" value="twothirds" <?php if ($ops['random_ads_end_mode']=='twothirds') echo 'checked="checked"'; ?> /> two thirds of the way down the post (uses raw character count)<br />
204
+ <br />
205
+ </td>
206
+ </tr>
207
+
208
+ <tr><td colspan="3">
209
+ <?php _e("Allow random ad on last paragraph");
210
+ echo '</td><td colspan="1">';
211
+ adinj_add_checkbox('rnd_allow_ads_on_last_paragraph'); ?>
212
+ <td></tr>
213
+ <tr><td colspan="3">
214
+ <?php _e("Allow multiple random ads to be injected at the same position", 'adinj') ?></td>
215
+ <td colspan="1"><?php adinj_add_checkbox('multiple_ads_at_same_position') ?>
216
+ </td></tr>
217
+ <tr><td colspan="3">
218
+ <?php _e("Re-select an ad for each position on post");
219
+ echo '</td><td colspan="1">';
220
+ adinj_add_checkbox('rnd_reselect_ad_per_position_in_post'); ?>
221
+ </td></tr>
222
+
223
  </table>
224
 
225
  <script type="text/javascript">
226
  jQuery(document).ready(function(){
227
+ jQuery('input[name=random_ads_start_unit]:radio').change(function() {
228
+ if (jQuery('input[name=random_ads_start_unit]:checked').val() == "character"){
229
+ jQuery('#random_ads_start_warning').slideDown(300);
230
  } else {
231
+ jQuery('#random_ads_start_warning').slideUp(300);
232
  }
233
  return true;
234
  });
235
  });
236
+ if ('<?php echo $ops['random_ads_start_unit'] ?>' == 'paragraph') {
237
+ document.write('<style type="text/css">#random_ads_start_warning { display: none; }</style>');
238
  }
239
+ </script>
 
240
 
241
  </td></tr>
242
 
243
+ <tr><td colspan="4"><input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" /><h3><a name="bottomadplacement"></a>Bottom ad [<a href="#bottomadcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
244
 
245
  <tr><td>Only show on posts longer than:</td><td>
246
  <?php
252
  ?>
253
  </div></td></tr>
254
 
255
+ <tr><td>|_ Max num of ads on whole page:</td><td>1</td><td><div class="adinj_home">
256
  <?php
257
  adinj_selection_box("home_max_num_bottom_ads_per_page", $num_ads_array);
258
  echo '</div></td><td><div class="adinj_archive">';
260
  ?>
261
  </div></td></tr>
262
 
263
+ <tr><td colspan="4">
264
+ <table class="adinjtable">
265
+ <tr><td>
266
+ <?php
267
+ _e("Put the bottom ad ", 'adinj');
268
+ ?>
269
+ </td>
270
+ <td>
271
+ <?php
272
+ adinj_selection_box("bottom_ad_position", array(0,1,2,3,4,5,100,200,300,500,750,1000,1500,2000,3000), " ");
273
+ ?>
274
+ </td>
275
+ <td>
276
+ <input type="radio" name="bottom_ad_position_unit" value="paragraph" <?php if ($ops['bottom_ad_position_unit']=='paragraph') echo 'checked="checked"'; ?> /> paragraph(s) before end of post<br />
277
+ <input type="radio" name="bottom_ad_position_unit" value="character" <?php if ($ops['bottom_ad_position_unit']=='character') echo 'checked="checked"'; ?> /> character(s) before end of post<br />
278
+ </td>
279
+ </tr>
280
+ </table>
281
+ </td></tr>
282
 
283
+ <tr><td colspan="4"><input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" /><h3>Other ad placement settings</h3></td></tr>
284
+
285
+ <tr>
286
+ <td>Content length counting method:</td>
287
+ <td colspan="3">
288
+ <?php
289
+ adinj_selection_box("content_length_unit",
290
+ array('viewable' => 'viewable chars', 'all' => 'all chars', 'words' => 'words'));
291
+ ?>
292
+ </td></tr>
293
+ <tr><td colspan="4"><p><span style="font-size:10px;">When defining 'post longer than' / 'post shorter than' conditions; do you want to count viewable characters, all characters (which includes HTML tags), or number of words?<br />This setting does not apply to the settings for positioning the ads near a character position - these use the raw character count.</span></p></td></tr>
294
+
295
  </table>
296
 
 
 
297
 
298
+ <?php adinj_postbox_end();
299
+ }
300
 
301
+ function adinj_adverts_box($ops){
302
+ adinj_postbox_start(__("Adverts", 'adinj'), 'adverts'); ?>
303
 
304
  <h3><a name="topadcode"></a>Top ad (below post title - this is not a 'header' ad) [<a href="#topadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_top'>pool</a>]--></h3>
305
+ <table border="0" class="adinjtable" width="98%">
306
  <tr><td>
307
  <textarea name="ad_code_top_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_top_1']; ?></textarea>
308
  <br />
317
  <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>
318
 
319
  <h3><a name="randomadcode"></a>Random ad (inserted randomly between paragraphs) [<a href="#randomadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_random'>pool</a>]--></h3>
320
+ <table border="0" class="adinjtable" width="98%">
321
  <tr><td>
322
  <textarea name="ad_code_random_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_random_1']; ?></textarea>
323
  <br />
331
  </table>
332
 
333
  <h3><a name="bottomadcode"></a>Bottom ad (below the post content) [<a href="#bottomadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_bottom'>pool</a>]--></h3>
334
+ <table border="0" class="adinjtable" width="98%">
335
  <tr><td>
336
  <textarea name="ad_code_bottom_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_bottom_1']; ?></textarea>
337
  <br />
346
 
347
 
348
  <h3><a name="footeradcode"></a>Footer ad (put into 'the_footer' hook - not supported by all themes) [<a href="#footeradplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_footer'>pool</a>]--></h3>
349
+ <table border="0" class="adinjtable" width="98%">
350
  <tr><td>
351
  <textarea name="ad_code_footer_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_footer_1']; ?></textarea>
352
  <br />
366
  </td></tr>
367
  </table>
368
 
369
+ <?php adinj_postbox_end();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  }
371
 
372
  function adinj_global_settings_box($ops){
405
  <td><b><font color="red">Tick to disable ads:</font></b></td>
406
  <td><b>Single(<?php echo $count_posts->publish; ?>)</b></td>
407
  <td><b>Page(<?php echo $count_pages->publish; ?>)</b></td>
408
+ <td><b>[ Home</b></td>
409
+ <td><b><a href="<?php echo get_bloginfo('url'); ?>" target="_new">Front</a> ]</b></td>
410
  <td><b>Archive</b></td>
 
411
  <td><b>404</b></td>
412
  <td><b>Search</b></td>
413
  </tr>
416
  adinj_add_exclude_row('|_&nbsp;&nbsp;<a href="#topadplacement">Top</a>', 'top_');
417
  adinj_add_exclude_row('|_&nbsp;&nbsp;<a href="#randomadplacement">Random</a>', 'random_');
418
  adinj_add_exclude_row('|_&nbsp;&nbsp;<a href="#bottomadplacement">Bottom</a>', 'bottom_');
419
+ adinj_add_exclude_row('|_&nbsp;&nbsp;Footer', 'footer_');
420
  adinj_add_exclude_row('|_&nbsp;&nbsp;Widget', 'widget_');
421
  adinj_add_exclude_row('|_&nbsp;&nbsp;Template', 'template_');
422
  ?>
478
  <h4>Top ad filters</h4>
479
  <?php adinj_condition_tables('top_', 'ui_top_conditions_show'); ?>
480
  <h4>Random ad filters</h4>
481
+ <?php adinj_condition_tables('random_', 'ui_random_conditions_show'); ?>
482
  <h4>Bottom ad filters</h4>
483
+ <?php adinj_condition_tables('bottom_', 'ui_bottom_conditions_show'); ?>
484
  <h4>Footer ad filters</h4>
485
+ <?php adinj_condition_tables('footer_', 'ui_footer_conditions_show'); ?>
486
  <?php
487
  adinj_postbox_end();
488
  }
492
  <h4>Ad insertion mode</h4>
493
  <blockquote>
494
  <input type="radio" name="ad_insertion_mode" value="mfunc" <?php if (adinj_mfunc_mode()) echo 'checked="checked"'; ?> /> <b>mfunc: Insert ads using cache compatible mfunc tags</b> - Dynamic features will work with WP Super Cache, W3 Total Cache and WP Cache. Only select this mode if you are using one of those caching plugins and want to use dynamic features (IP / referrer restriction, alt content and ad roatation). If you aren't using dynamic features select direct mode.
 
 
 
495
 
496
  <?php if (!adinj_mfunc_mode()) { ?>
497
  <script type="text/javascript">
501
  <br />
502
 
503
  <div id="caching_plugin_msg" class="caching_plugin_msg">
504
+ <?php if (!is_supported_caching_plugin_active()) {
505
+ echo '<p><b><span style="font-size:10px;color:red;">Note: A supported caching plugin does not appear to be active. If you are not using WP Super Cache / W3 Total Cache / WP Cache you should use one of the direct insertion modes below.</span></b></p>';
506
+ } ?>
507
  <?php
508
  if (is_plugin_active('wp-super-cache/wp-cache.php')){
509
  adinj_wp_super_cache_msg();
551
  <blockquote>
552
  <?php adinj_add_checkbox('block_keywords') ?><?php _e("Don't show ads to visitors from external sites if the referrer contains one of these keywords or substrings.", 'adinj') ?> If a blocked string is found block ads for: <?php adinj_selection_box("block_ads_for_hours", array('1'=>'1 hour', '2'=>'2 hours', '3'=>'3 hours', '6'=>'6 hours', '24'=>'1 day', '48'=>'2 days', '72'=>'3 days', '168'=>'1 week', '720'=>'30 days', '8760'=>'1 year')); ?><br />
553
  <textarea name="blocked_keywords" rows="2" cols="<?php adinj_table_width('dynamic'); ?>"><?php echo $ops['blocked_keywords']; ?></textarea>
554
+ <p>Comma separated list e.g.: <br /><code>facebook.com, .org, james+bond</code></p>
555
  </blockquote>
556
 
557
 
582
  <td><?php adinj_add_checkbox($prefix.'exclude_single', 'adinj_single', $all) ?></td>
583
  <td><?php adinj_add_checkbox($prefix.'exclude_page', 'adinj_page', $all) ?></td>
584
  <td><?php adinj_add_checkbox($prefix.'exclude_home', 'adinj_home', $all) ?></td>
 
585
  <td><?php adinj_add_checkbox($prefix.'exclude_front', 'adinj_front', $all) ?></td>
586
+ <td><?php adinj_add_checkbox($prefix.'exclude_archive', 'adinj_archive', $all) ?></td>
587
  <td><?php adinj_add_checkbox($prefix.'exclude_404', 'adinj_404', $all) ?></td>
588
  <td><?php adinj_add_checkbox($prefix.'exclude_search', 'adinj_search', $all) ?></td>
589
  </tr>
592
 
593
  function adinj_random_ad_limit_table(){
594
  ?>
595
+ <tr><td>&nbsp;|_ No ads if post shorter than:</td>
596
  <?php
597
  $prefixes = array("", "home", "archive");
598
  $unit = adinj_counting_unit_description();
605
  echo '</div></td>';
606
  } ?>
607
  </tr>
608
+ <tr><td>&nbsp;|_ Max 1 ad if post shorter than:</td>
609
  <?php
610
  foreach ($prefixes as $prefix){
611
  echo '<td><div class="adinj_'.$prefix.'">';
614
  echo '</div></td>';
615
  } ?>
616
  </tr>
617
+ <tr><td>&nbsp;|_ Max 2 ads if post shorter than:</td>
618
  <?php
619
  foreach ($prefixes as $prefix){
620
  echo '<td><div class="adinj_'.$prefix.'">';
624
  }
625
  ?>
626
  </tr>
627
+ <tr><td>&nbsp;|_ Max 3 ads if post shorter than:</td>
628
  <?php
629
  foreach ($prefixes as $prefix){
630
  echo '<td><div class="adinj_'.$prefix.'">';
714
  if ($info[0] != 'red') { ?>
715
  </td></tr>
716
 
717
+ <tr><td style="text-align:right">
718
+ <b><a href='#global'>Ads on posts</a></b>
719
+ </td><td>
720
+ <?php $info = adinj_get_status('older_than_normal'); echo adinj_dot($info[0]).' '.$info[1]; ?>
721
+ </td></tr>
722
+
723
+ <tr><td style="text-align:right">
724
+ <b><a href='#global'>Widgets on posts</a></b>
725
+ </td><td>
726
+ <?php $info = adinj_get_status('older_than_widgets'); echo adinj_dot($info[0]).' '.$info[1]; ?>
727
+ </td></tr>
728
+
729
  <tr><td style="text-align:right">
730
  <b><a href="#restrictions">Mode</a></b>
731
  </td><td>
733
  </td></tr>
734
 
735
  <tr><td style="text-align:right">
736
+ <b><a href="#restrictions">Restrictions</a></b>
737
  </td><td>
738
  <?php $info = adinj_get_status('restrictions'); echo adinj_dot($info[0]).' '.$info[1]; ?>
739
  </td></tr>
845
 
846
  <?php adinj_postbox_start(__("Quick Start", 'adinj'), "docsquickstart", '95%'); ?>
847
 
848
+ <p>1. Copy and paste your ad code into the ad code boxes. [<a href="#adverts">Goto adverts</a>]</p>
 
 
849
 
850
+ <p>2. Choose how many ads of each type you want displayed. [<a href="#adsettings">Goto ad placement settings</a>]</p>
851
 
852
+ <p>3. Make sure ads are enabled for the page types you want them to be enabled for. [<a href="#global">Goto global settings</a>]</p>
853
 
854
+ <p>4. Check the ad insertion mode. You will probably want 'direct' mode unless you are 1) using a caching plugin AND 2) are using the dynamic features (dynamic restrictions or ad rotation). [<a href="#restrictions">Goto 'Ad insertion mode and dynamic ad display restriction'</a>]</p>
855
 
856
+ <p>5. Enable your ads by selecting the 'on' option at the top. [<a href="#global">Goto global settings</a>]</p>
857
 
858
  <?php adinj_postbox_end();
859