PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.2.0
Defender Security – Malware Scanner, Login Security & Firewall v6.2.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / helper / analytics / class-scan.php

class-scan.php in Defender Security – Malware Scanner, Login Security & Firewall 6.2.0, at src/helper/analytics/class-scan.php

148 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Responsible for gathering analytics data for the scan feature.
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\Model\Scan_Item;
12 use WP_Defender\Model\Scan as Scan_Model;
13
14 /**
15 * Gather analytics data required for scan feature.
16 */
17 class Scan extends Event {
18
19 public const EVENT_SCAN_FAILED = 'def_scan_failed_new';
20 public const EVENT_SCAN_FAILED_PROP = 'Failure reason';
21 public const EVENT_SCAN_FAILED_CANCEL = 'User Cancellation';
22 public const EVENT_SCAN_FAILED_ERROR = 'Error';
23
24 // Mandatory empty methods.
25 // Start.
26 /**
27 * Provides data for the frontend.
28 *
29 * @return array An array of data for the frontend.
30 */
31 public function data_frontend(): array {
32 return array();
33 }
34
35 /**
36 * Converts the current state of the object to an array.
37 *
38 * @return array Returns an associative array of object properties.
39 */
40 public function to_array(): array {
41 return array();
42 }
43
44 /**
45 * Imports data into the model.
46 *
47 * @param array $data Data to be imported into the model.
48 */
49 public function import_data( array $data ) {
50 }
51
52 /**
53 * Removes settings for all submodules.
54 */
55 public function remove_settings() {
56 }
57
58 /**
59 * Delete all the data & the cache.
60 */
61 public function remove_data() {
62 }
63
64 /**
65 * Exports strings.
66 *
67 * @return array An array of strings.
68 */
69 public function export_strings(): array {
70 return array();
71 }
72 // End.
73
74 /**
75 * Analytics data for scan completed event.
76 *
77 * @param Scan_Model $scan_model Scan model object.
78 *
79 * @return array{
80 * 'event' => string,
81 * 'data' => array
82 * }
83 */
84 public function scan_completed( Scan_Model $scan_model ): array {
85 $last_scan = $scan_model::get_last();
86 if ( ! $last_scan instanceof Scan_Model ) {
87 return array();
88 }
89 $scan_item_group_total = wd_di()->get( Scan_Item::class )
90 ->get_types_total( $last_scan->id, Scan_Item::STATUS_ACTIVE );
91
92 $data = array();
93
94 if ( isset( $scan_item_group_total['all'] ) ) {
95 $data['Threats Count'] = $scan_item_group_total['all'];
96 }
97
98 if ( isset( $scan_item_group_total[ Scan_Item::TYPE_INTEGRITY ] ) ) {
99 $data['WP core issue count'] = $scan_item_group_total[ Scan_Item::TYPE_INTEGRITY ];
100 }
101 if ( isset( $scan_item_group_total[ Scan_Item::TYPE_SUSPICIOUS ] ) ) {
102 $data['Suspicious Code'] = $scan_item_group_total[ Scan_Item::TYPE_SUSPICIOUS ];
103 // Additional JS file count if found.
104 $items = $last_scan->get_issues( Scan_Item::TYPE_SUSPICIOUS, Scan_Item::STATUS_ACTIVE );
105 $count_js_files = 0;
106 foreach ( $items as $item ) {
107 if (
108 isset( $item->raw_data['file'] ) && is_file( $item->raw_data['file'] ) &&
109 'js' === strtolower( pathinfo( $item->raw_data['file'], PATHINFO_EXTENSION ) )
110 ) {
111 ++$count_js_files;
112 }
113 }
114 if ( $count_js_files > 0 ) {
115 $data['JS file Detection'] = $count_js_files;
116 }
117 }
118
119 if ( isset( $scan_item_group_total[ Scan_Item::TYPE_VULNERABILITY ] ) ) {
120 $data['Vulnerability'] = $scan_item_group_total[ Scan_Item::TYPE_VULNERABILITY ];
121 }
122
123 if ( isset( $scan_item_group_total[ Scan_Item::TYPE_PLUGIN_CHECK ] ) ) {
124 $data['Plugin file modified'] = $scan_item_group_total[ Scan_Item::TYPE_PLUGIN_CHECK ];
125 }
126
127 $is_closed = false;
128 $is_outdated = false;
129 $count = 0;
130 if ( isset( $scan_item_group_total[ Scan_Item::TYPE_PLUGIN_CLOSED ] ) ) {
131 $is_closed = true;
132 $count += $scan_item_group_total[ Scan_Item::TYPE_PLUGIN_CLOSED ];
133 }
134 if ( isset( $scan_item_group_total[ Scan_Item::TYPE_PLUGIN_OUTDATED ] ) ) {
135 $is_outdated = true;
136 $count += $scan_item_group_total[ Scan_Item::TYPE_PLUGIN_OUTDATED ];
137 }
138 if ( $is_closed || $is_outdated ) {
139 $data['Outdated & Removed Plugins'] = $count;
140 }
141
142 return array(
143 'event' => 'def_scan_completed_new',
144 'data' => $data,
145 );
146 }
147 }
148