Spider Blocker - Version 1.0.17

Version Description

Download this release

Release Info

Developer niteoweb
Plugin Icon 128x128 Spider Blocker
Version 1.0.17
Comparing to
See all releases

Code changes from version 1.0.16 to 1.0.17

Files changed (1) hide show
  1. index.php +35 -5
index.php CHANGED
@@ -3,7 +3,7 @@ namespace Niteoweb\SpiderBlocker;
3
  /**
4
  * Plugin Name: Spider Blocker
5
  * Description: Spider Blocker will block most common bots that consume bandwidth and slow down your server.
6
- * Version: 1.0.16
7
  * Runtime: 5.3+
8
  * Author: Easy Blog Networks
9
  * Author URI: www.easyblognetworks.com
@@ -202,6 +202,12 @@ class SpiderBlocker
202
  'desc' => 'http://www.majestic12.co.uk/projects/dsearch/mj12bot.php',
203
  'state' => true,
204
  ),
 
 
 
 
 
 
205
  array(
206
  'name' => 'Blekko Bot',
207
  're' => 'BlekkoBot',
@@ -279,6 +285,9 @@ class SpiderBlocker
279
  add_action('wp_ajax_NSB-set_list', array(&$this, 'saveList'));
280
  add_action('wp_ajax_NSB-reset_list', array(&$this, 'resetList'));
281
  }
 
 
 
282
  add_action('generate_rewrite_rules', array(&$this, "generateRewriteRules"));
283
 
284
  }
@@ -456,7 +465,7 @@ class SpiderBlocker
456
  private function getBots()
457
  {
458
  $data = get_option(self::OptionName);
459
- if($data && count($data) > 0){
460
  return maybe_unserialize($data);
461
  }
462
  return $this->default_bots;
@@ -474,6 +483,7 @@ class SpiderBlocker
474
  check_ajax_referer(self::nonce, 'nonce');
475
  delete_option(self::OptionName);
476
  $this->generateBlockRules();
 
477
  wp_send_json_success($this->getBots());
478
  }
479
 
@@ -495,7 +505,7 @@ class SpiderBlocker
495
  {
496
 
497
  check_ajax_referer(self::nonce, 'nonce');
498
- $data = json_decode(stripcslashes($_POST['data']));
499
 
500
  if (json_last_error()) {
501
  if (function_exists('json_last_error_msg')) {
@@ -512,10 +522,30 @@ class SpiderBlocker
512
  }
513
 
514
  $this->generateBlockRules();
 
515
  wp_send_json_success($this->getBots());
516
 
517
  }
518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
519
  /**
520
  * @codeCoverageIgnore
521
  */
@@ -773,13 +803,13 @@ class SpiderBlocker
773
  <?php
774
  }
775
 
776
-
777
  }
778
 
779
  // Inside WordPress
780
  if (defined('ABSPATH')) {
781
  $NiteowebSpiderBlocker_ins = new SpiderBlocker;
 
782
  add_action( "upgrader_process_complete", array(&$NiteowebSpiderBlocker_ins, 'onPluginUpgrade'), 10, 2);
783
  register_activation_hook(__FILE__, array(&$NiteowebSpiderBlocker_ins, 'activatePlugin'));
784
  register_deactivation_hook(__FILE__, array(&$NiteowebSpiderBlocker_ins, 'removeBlockRules'));
785
- }
3
  /**
4
  * Plugin Name: Spider Blocker
5
  * Description: Spider Blocker will block most common bots that consume bandwidth and slow down your server.
6
+ * Version: 1.0.17
7
  * Runtime: 5.3+
8
  * Author: Easy Blog Networks
9
  * Author URI: www.easyblognetworks.com
202
  'desc' => 'http://www.majestic12.co.uk/projects/dsearch/mj12bot.php',
203
  'state' => true,
204
  ),
205
+ array(
206
+ 'name' => 'MJ12',
207
+ 're' => 'MJ12',
208
+ 'desc' => 'http://www.majestic12.co.uk/projects/dsearch/mj12bot.php',
209
+ 'state' => true,
210
+ ),
211
  array(
212
  'name' => 'Blekko Bot',
213
  're' => 'BlekkoBot',
285
  add_action('wp_ajax_NSB-set_list', array(&$this, 'saveList'));
286
  add_action('wp_ajax_NSB-reset_list', array(&$this, 'resetList'));
287
  }
288
+
289
+ // Filter (for robots.txt)
290
+ add_filter( 'robots_txt', array (&$this, 'robotsFile' ), ~PHP_INT_MAX, 2 );
291
  add_action('generate_rewrite_rules', array(&$this, "generateRewriteRules"));
292
 
293
  }
465
  private function getBots()
466
  {
467
  $data = get_option(self::OptionName);
468
+ if($data){
469
  return maybe_unserialize($data);
470
  }
471
  return $this->default_bots;
483
  check_ajax_referer(self::nonce, 'nonce');
484
  delete_option(self::OptionName);
485
  $this->generateBlockRules();
486
+ add_filter( 'robots_txt', array (&$this, 'robotsFile' ), ~PHP_INT_MAX, 2 );
487
  wp_send_json_success($this->getBots());
488
  }
489
 
505
  {
506
 
507
  check_ajax_referer(self::nonce, 'nonce');
508
+ $data = json_decode(stripcslashes($_POST['data']), true);
509
 
510
  if (json_last_error()) {
511
  if (function_exists('json_last_error_msg')) {
522
  }
523
 
524
  $this->generateBlockRules();
525
+ add_filter( 'robots_txt', array (&$this, 'robotsFile' ), ~PHP_INT_MAX, 2 );
526
  wp_send_json_success($this->getBots());
527
 
528
  }
529
 
530
+ function robotsFile( $output, $public ) {
531
+
532
+ // Get bots list
533
+ $data = $this->getBots();
534
+
535
+ if ( $data ) {
536
+ foreach ( $data as $entry ) {
537
+ if ( ! empty( $entry['state'] ) ) {
538
+ $output .= sprintf( "User-agent: %s\n", $entry['re'] );
539
+ $output .= "Disallow: /\n";
540
+ $output .= "\n";
541
+ }
542
+ }
543
+ }
544
+
545
+ return $output;
546
+
547
+ }
548
+
549
  /**
550
  * @codeCoverageIgnore
551
  */
803
  <?php
804
  }
805
 
 
806
  }
807
 
808
  // Inside WordPress
809
  if (defined('ABSPATH')) {
810
  $NiteowebSpiderBlocker_ins = new SpiderBlocker;
811
+
812
  add_action( "upgrader_process_complete", array(&$NiteowebSpiderBlocker_ins, 'onPluginUpgrade'), 10, 2);
813
  register_activation_hook(__FILE__, array(&$NiteowebSpiderBlocker_ins, 'activatePlugin'));
814
  register_deactivation_hook(__FILE__, array(&$NiteowebSpiderBlocker_ins, 'removeBlockRules'));
815
+ }