| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handles fake bot detection functionality. |
| 4 |
* |
| 5 |
* @package WP_Defender\Controller |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Controller; |
| 9 |
|
| 10 |
use WP_Defender\Controller; |
| 11 |
use WP_Defender\Component\Blacklist_Lockout; |
| 12 |
use WP_Defender\Component\Fake_Bot_Detection as Fake_Bot_Detection_Component; |
| 13 |
use WP_Defender\Traits\IP; |
| 14 |
|
| 15 |
/** |
| 16 |
* Handles operations to detect whether the current HTTP request comes from a legitimate bot. |
| 17 |
*/ |
| 18 |
class Fake_Bot_Detection extends Controller { |
| 19 |
use IP; |
| 20 |
|
| 21 |
/** |
| 22 |
* Service for handling logic. |
| 23 |
* |
| 24 |
* @var Fake_Bot_Detection_Component |
| 25 |
*/ |
| 26 |
protected $service; |
| 27 |
|
| 28 |
/** |
| 29 |
* Constructor for the Fake_Bot_Detection class. |
| 30 |
* Initializes the service and sets up necessary hooks. |
| 31 |
* |
| 32 |
* @param Fake_Bot_Detection_Component $service The service instance for fake bot functionality. |
| 33 |
*/ |
| 34 |
public function __construct( Fake_Bot_Detection_Component $service ) { |
| 35 |
$this->service = $service; |
| 36 |
|
| 37 |
$service = wd_di()->get( Blacklist_Lockout::class ); |
| 38 |
$ip = $this->get_user_ip(); |
| 39 |
|
| 40 |
if ( $this->service->is_enabled() && ! $service->are_ips_whitelisted( $ip ) ) { |
| 41 |
add_action( 'init', array( $this->service, 'load_crawlers' ) ); |
| 42 |
add_action( 'init', array( $this->service, 'validate_legit_crawler' ) ); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Delete all the data & the cache. |
| 48 |
*/ |
| 49 |
public function remove_data() { |
| 50 |
delete_site_transient( Fake_Bot_Detection_Component::CACHE_KEY ); |
| 51 |
$this->service->clear_fb_transients(); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Exports strings. |
| 56 |
* |
| 57 |
* @return array An array of strings. |
| 58 |
*/ |
| 59 |
public function export_strings(): array { |
| 60 |
return array(); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Converts the object data to an array. |
| 65 |
* |
| 66 |
* @return array An array representation of the object. |
| 67 |
*/ |
| 68 |
public function to_array(): array { |
| 69 |
return array(); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Imports data into the model. |
| 74 |
* |
| 75 |
* @param array $data Data to be imported into the model. |
| 76 |
* |
| 77 |
* @throws Exception If table is not defined. |
| 78 |
*/ |
| 79 |
public function import_data( array $data ) { |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Removes settings for all submodules. |
| 84 |
*/ |
| 85 |
public function remove_settings(): void { |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Provides data for the frontend. |
| 90 |
* |
| 91 |
* @return array An array of data for the frontend. |
| 92 |
*/ |
| 93 |
public function data_frontend(): array { |
| 94 |
return array(); |
| 95 |
} |
| 96 |
} |
| 97 |
|