| 1 |
<?php |
| 2 |
/** |
| 3 |
* Responsible for gathering analytics data. |
| 4 |
* |
| 5 |
* @package WP_Defender\Helper\Analytics |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Helper\Analytics; |
| 9 |
|
| 10 |
use WP_Defender\Event; |
| 11 |
use WP_Defender\Traits\Plugin; |
| 12 |
|
| 13 |
/** |
| 14 |
* Gather analytics data. |
| 15 |
*/ |
| 16 |
class Deactivation_Survey extends Event { |
| 17 |
|
| 18 |
use Plugin; |
| 19 |
|
| 20 |
public const EVENT_DATA_OPTION = 'wp_defender_event_times'; |
| 21 |
|
| 22 |
/** |
| 23 |
* Provides data for the frontend. |
| 24 |
* |
| 25 |
* @return array An array of data for the frontend. |
| 26 |
*/ |
| 27 |
public function data_frontend(): array { |
| 28 |
return array(); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Converts the current state of the object to an array. |
| 33 |
* |
| 34 |
* @return array Returns an associative array of object properties. |
| 35 |
*/ |
| 36 |
public function to_array(): array { |
| 37 |
return array(); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Imports data into the model. |
| 42 |
* |
| 43 |
* @param array $data Data to be imported into the model. |
| 44 |
*/ |
| 45 |
public function import_data( array $data ) { |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Removes settings for all submodules. |
| 50 |
*/ |
| 51 |
public function remove_settings() { |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Delete all the data & the cache. |
| 56 |
*/ |
| 57 |
public function remove_data() { |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Exports strings. |
| 62 |
* |
| 63 |
* @return array |
| 64 |
*/ |
| 65 |
public function export_strings() { |
| 66 |
return array(); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Get a list of active features. |
| 71 |
* |
| 72 |
* @return array |
| 73 |
*/ |
| 74 |
private function get_active_features(): array { |
| 75 |
$google_recaptcha = false; |
| 76 |
$turnstile = false; |
| 77 |
$captcha = wd_di()->get( \WP_Defender\Model\Setting\Captcha::class ); |
| 78 |
if ( $captcha->enabled ) { |
| 79 |
$turnstile = 'turnstile' === $captcha->active_type; |
| 80 |
$google_recaptcha = 'turnstile' !== $captcha->active_type; |
| 81 |
} |
| 82 |
$ua_model = wd_di()->get( \WP_Defender\Model\Setting\User_Agent_Lockout::class ); |
| 83 |
|
| 84 |
$features = array( |
| 85 |
'antibot' => wd_di()->get( \WP_Defender\Model\Setting\Antibot_Global_Firewall_Setting::class )->enabled, |
| 86 |
'audit_logging' => wd_di()->get( \WP_Defender\Model\Setting\Audit_Logging::class )->enabled, |
| 87 |
'google_recaptcha' => $google_recaptcha, |
| 88 |
'cloudflare_turnstile' => $turnstile, |
| 89 |
'404_detection' => wd_di()->get( \WP_Defender\Model\Setting\Notfound_Lockout::class )->enabled, |
| 90 |
'login_protection' => wd_di()->get( \WP_Defender\Model\Setting\Login_Lockout::class )->enabled, |
| 91 |
'user_agent_banning' => $ua_model->enabled, |
| 92 |
'fake_crawler' => $ua_model->enabled ? $ua_model->fake_bots_enabled : false, |
| 93 |
'two_factor_authentication' => wd_di()->get( \WP_Defender\Model\Setting\Two_Fa::class )->enabled, |
| 94 |
'mask_login_area' => wd_di()->get( \WP_Defender\Model\Setting\Mask_Login::class )->enabled, |
| 95 |
'security_headers' => wd_di()->get( \WP_Defender\Model\Setting\Security_Headers::class )->is_any_activated(), |
| 96 |
'pwned_passwords' => wd_di()->get( \WP_Defender\Model\Setting\Password_Protection::class )->enabled, |
| 97 |
'strong_password' => wd_di()->get( \WP_Defender\Model\Setting\Strong_Password::class )->enabled, |
| 98 |
); |
| 99 |
|
| 100 |
return array_keys( |
| 101 |
array_filter( |
| 102 |
$features, |
| 103 |
function ( $value ) { |
| 104 |
return true === $value; |
| 105 |
} |
| 106 |
) |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Get Date & Time properties. |
| 112 |
* |
| 113 |
* @return array |
| 114 |
*/ |
| 115 |
private function get_date_time_properties(): array { |
| 116 |
$properties = array(); |
| 117 |
$event_times = get_site_option( self::EVENT_DATA_OPTION, array() ); |
| 118 |
$time_events = array( |
| 119 |
'Installation Date' => 'plugin_installed', |
| 120 |
'Activation Date' => 'plugin_activated', |
| 121 |
'Last Updated' => 'plugin_upgraded', |
| 122 |
); |
| 123 |
|
| 124 |
foreach ( $time_events as $event_name => $event_key ) { |
| 125 |
if ( isset( $event_times[ $event_key ] ) ) { |
| 126 |
$event_value = $event_times[ $event_key ]; |
| 127 |
if ( is_int( $event_value ) && $event_value > 0 ) { |
| 128 |
$properties[ $event_name ] = gmdate( 'c', $event_value ); |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
return $properties; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Track Deactivation survey. |
| 138 |
* |
| 139 |
* @param array $properties Array of properties. |
| 140 |
* |
| 141 |
* @return void |
| 142 |
*/ |
| 143 |
public function track_deactivation_survey( $properties ) { |
| 144 |
if ( ! defender_is_wp_cli() ) { |
| 145 |
$properties = array_merge( |
| 146 |
$properties, |
| 147 |
array( |
| 148 |
'active_plugins' => $this->get_active_plugin_names(), |
| 149 |
'active_features' => $this->get_active_features(), |
| 150 |
), |
| 151 |
$this->get_date_time_properties() |
| 152 |
); |
| 153 |
|
| 154 |
$this->forced_track( |
| 155 |
'Deactivation Survey', |
| 156 |
$properties |
| 157 |
); |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
|