PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / trunk
Defender Security – Malware Scanner, Login Security & Firewall vtrunk
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 3.1.1 All 140 releases
defender-security / src / controller / class-rate.php

class-rate.php in Defender Security – Malware Scanner, Login Security & Firewall trunk, at src/controller/class-rate.php

164 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle rating functionality.
4 *
5 * @package WP_Defender\Controller
6 */
7
8 namespace WP_Defender\Controller;
9
10 use WP_Defender\Event;
11 use Calotes\Component\Response;
12 use Calotes\Component\Request;
13 use WP_Defender\Component\Rate as Rate_Component;
14 use WP_Defender\Helper\Analytics\Rate as Rate_Analytics;
15
16 /**
17 * Handle rating functionality.
18 *
19 * @since 5.6.0
20 */
21 class Rate extends Event {
22
23 /**
24 * Initialize the class by setting button labels and registering actions.
25 */
26 public function __construct() {
27 $this->register_routes();
28 }
29
30 /**
31 * Handle notice.
32 *
33 * @param Request $request Request object.
34 *
35 * @return Response Response object.
36 * @defender_route
37 */
38 public function handle_notice( Request $request ): Response {
39 Rate_Component::reset_counters();
40 update_site_option( Rate_Component::SLUG_FOR_BUTTON_RATE, true );
41 // Track.
42 $data = $request->get_data(
43 array(
44 'prompt' => array( 'type' => 'string' ),
45 'location' => array( 'type' => 'string' ),
46 )
47 );
48 wd_di()->get( Rate_Analytics::class )->track_rating( $data['prompt'], 'rate', $data['location'] );
49
50 return new Response( true, array() );
51 }
52
53 /**
54 * Handle postponed notice.
55 * Reset counters and set new date to display a postponed notice.
56 *
57 * @param Request $request Request object.
58 *
59 * @return Response Response object.
60 * @defender_route
61 */
62 public function postpone_notice( Request $request ): Response {
63 Rate_Component::reset_counters();
64 update_site_option( Rate_Component::SLUG_POSTPONED_NOTICE_DATE, time() );
65 // Track.
66 $data = $request->get_data(
67 array(
68 'prompt' => array( 'type' => 'string' ),
69 'location' => array( 'type' => 'string' ),
70 )
71 );
72 wd_di()->get( Rate_Analytics::class )->track_rating( $data['prompt'], 'remind_later', $data['location'] );
73
74 return new Response( true, array() );
75 }
76
77 /**
78 * Handle refuse notice.
79 *
80 * @param Request $request Request object.
81 *
82 * @return Response Response object.
83 * @defender_route
84 */
85 public function refuse_notice( Request $request ): Response {
86 Rate_Component::reset_counters();
87 update_site_option( Rate_Component::SLUG_FOR_BUTTON_THANKS, true );
88 // Track.
89 $data = $request->get_data(
90 array(
91 'prompt' => array( 'type' => 'string' ),
92 'location' => array( 'type' => 'string' ),
93 )
94 );
95 wd_di()->get( Rate_Analytics::class )->track_rating( $data['prompt'], 'dismiss', $data['location'] );
96
97 return new Response( true, array() );
98 }
99
100 /**
101 * All the variables that we will show on frontend.
102 *
103 * @return array
104 */
105 public function data_frontend() {
106 return array_merge(
107 array(
108 'repo_link' => Rate_Component::URL_PLUGIN_NEW_REVIEW_VCS,
109 'rate_button' => Rate_Component::get_rate_button_title(),
110 'dismiss_button' => Rate_Component::get_dismiss_button_title(),
111 'postpone_button' => Rate_Component::get_postpone_button_title(),
112 'location' => Rate_Component::get_current_page_label(),
113 ),
114 $this->dump_routes_and_nonces()
115 );
116 }
117
118 /**
119 * Delete all the data.
120 */
121 public function remove_data() {
122 delete_site_option( Rate_Component::SLUG_COMPLETED_SCANS );
123 delete_site_option( Rate_Component::SLUG_FIXED_SCAN_ISSUES );
124 delete_site_option( Rate_Component::SLUG_FREE_INSTALL_DATE );
125 delete_site_option( Rate_Component::SLUG_FOR_BUTTON_RATE );
126 delete_site_option( Rate_Component::SLUG_FOR_BUTTON_THANKS );
127 delete_site_option( Rate_Component::SLUG_POSTPONED_NOTICE_DATE );
128 delete_site_option( Rate_Component::SLUG_UA_LOCKOUTS );
129 delete_site_option( Rate_Component::SLUG_IP_LOCKOUTS );
130 }
131
132 /**
133 * Export strings.
134 *
135 * @return array An array of strings.
136 */
137 public function export_strings(): array {
138 return array();
139 }
140
141 /**
142 * Convert the object data to an array.
143 *
144 * @return array An array representation of the object.
145 */
146 public function to_array(): array {
147 return array();
148 }
149
150 /**
151 * Import data into the model.
152 *
153 * @param array $data Data to be imported into the model.
154 */
155 public function import_data( array $data ) {
156 }
157
158 /**
159 * Remove settings for all submodules.
160 */
161 public function remove_settings(): void {
162 }
163 }
164