| 1 |
<?php |
| 2 |
/** |
| 3 |
* Notification component stub for free version. |
| 4 |
* |
| 5 |
* @package WP_Defender\Component |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Component; |
| 9 |
|
| 10 |
use WP_Defender\Behavior\WPMUDEV; |
| 11 |
use WP_Defender\Model\Notification\Audit_Report; |
| 12 |
use WP_Defender\Model\Notification\Malware_Report; |
| 13 |
use WP_Defender\Model\Notification\Tweak_Reminder; |
| 14 |
use WP_Defender\Model\Notification\Firewall_Report; |
| 15 |
use WP_Defender\Model\Notification\Malware_Notification; |
| 16 |
use WP_Defender\Model\Notification\Firewall_Notification; |
| 17 |
|
| 18 |
/** |
| 19 |
* Notification component. |
| 20 |
*/ |
| 21 |
class Notification extends Notification_Base { |
| 22 |
|
| 23 |
/** |
| 24 |
* Constructs the Notification component. |
| 25 |
*/ |
| 26 |
public function __construct() { |
| 27 |
$this->attach_behavior( WPMUDEV::class, WPMUDEV::class ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Get all non-pro modules as array of arrays. |
| 32 |
* |
| 33 |
* @return array |
| 34 |
*/ |
| 35 |
public function get_modules(): array { |
| 36 |
return array( |
| 37 |
Malware_Notification::SLUG => wd_di()->get( Malware_Notification::class )->export(), |
| 38 |
Firewall_Notification::SLUG => wd_di()->get( Firewall_Notification::class )->export(), |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Get all non-pro modules as array of objects. |
| 44 |
* |
| 45 |
* @return array |
| 46 |
*/ |
| 47 |
public function get_modules_as_objects(): array { |
| 48 |
return array( |
| 49 |
wd_di()->get( Malware_Notification::class ), |
| 50 |
wd_di()->get( Firewall_Notification::class ), |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Build a slug-to-model index for all notification modules. |
| 56 |
* |
| 57 |
* @return array<string, \WP_Defender\Model\Notification> |
| 58 |
*/ |
| 59 |
public function get_module_map(): array { |
| 60 |
$map = array(); |
| 61 |
foreach ( $this->get_modules_as_objects() as $model ) { |
| 62 |
$map[ $model->slug ] = $model; |
| 63 |
} |
| 64 |
|
| 65 |
return $map; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Return the time that the next report will be triggered. For free always return 'Never'. |
| 70 |
* |
| 71 |
* @return string |
| 72 |
*/ |
| 73 |
public function get_next_run() { |
| 74 |
return esc_html__( 'Never', 'defender-security' ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Get inactive modules. For free it's always empty. |
| 79 |
* |
| 80 |
* @return array |
| 81 |
*/ |
| 82 |
public function get_inactive_modules(): array { |
| 83 |
return array(); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Get the alert model (firewall notification). |
| 88 |
* |
| 89 |
* @return array |
| 90 |
*/ |
| 91 |
public function get_alert_model(): array { |
| 92 |
return array( Firewall_Notification::SLUG => wd_di()->get( Firewall_Notification::class )->export() ); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Get all report models keyed by slug. Only for the view. |
| 97 |
* |
| 98 |
* @return array |
| 99 |
*/ |
| 100 |
public function get_reports_model(): array { |
| 101 |
$malware_report = wd_di()->get( Malware_Report::class )->export(); |
| 102 |
$malware_report['ui_title'] = esc_html__( 'Issues', 'defender-security' ); |
| 103 |
|
| 104 |
$tweak_reminder = wd_di()->get( Tweak_Reminder::class )->export(); |
| 105 |
$tweak_reminder['ui_title'] = esc_html__( 'Hardening', 'defender-security' ); |
| 106 |
|
| 107 |
$firewall_report = wd_di()->get( Firewall_Report::class )->export(); |
| 108 |
$firewall_report['ui_title'] = esc_html__( 'Firewall', 'defender-security' ); |
| 109 |
|
| 110 |
$audit_report = wd_di()->get( Audit_Report::class )->export(); |
| 111 |
$audit_report['ui_title'] = esc_html__( 'Audit log', 'defender-security' ); |
| 112 |
|
| 113 |
return array( |
| 114 |
Malware_Report::SLUG => $malware_report, |
| 115 |
Tweak_Reminder::SLUG => $tweak_reminder, |
| 116 |
Firewall_Report::SLUG => $firewall_report, |
| 117 |
Audit_Report::SLUG => $audit_report, |
| 118 |
); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Get active pro report modules as arrays. For free it's always empty. |
| 123 |
* |
| 124 |
* @return array |
| 125 |
*/ |
| 126 |
public function get_active_pro_reports(): array { |
| 127 |
return array(); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Get active pro report modules as objects. For free it's always empty. |
| 132 |
* |
| 133 |
* @return array |
| 134 |
*/ |
| 135 |
public function get_active_pro_reports_as_objects(): array { |
| 136 |
return array(); |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Dispatches reports. |
| 141 |
*/ |
| 142 |
public function maybe_dispatch_report() { |
| 143 |
// No Pro reports. |
| 144 |
} |
| 145 |
} |
| 146 |
|