PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.58
Timetics – Appointment Booking Calendar & Scheduling v1.0.58
1.0.64 1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 All 65 releases
timetics / vendor / themewinter / uninstaller_form / src / Api / FeedbackController.php

FeedbackController.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.58, at vendor/themewinter/uninstaller_form/src/Api/FeedbackController.php

209 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UninstallerForm\Api;
3
4 use WP_REST_Request;
5
6 /**
7 * Feedback controller for the uninstaller form.
8 *
9 * @since 1.0.0
10 *
11 * @package UNINSTALLER_FORM
12 */
13 class FeedbackController {
14 protected $plugin_file;
15 protected $plugin_text_domain;
16 protected $plugin_name;
17 protected $plugin_slug;
18
19 /**
20 * Store namespace
21 *
22 * @since 1.0.0
23 *
24 * @var string
25 */
26 protected $namespace;
27
28 /**
29 * Store rest base
30 *
31 * @since 1.0.0
32 *
33 * @var string
34 */
35 protected $rest_base = 'feedback';
36
37 /**
38 * Store webhook
39 *
40 * @since 1.0.0
41 *
42 * @var string
43 */
44 protected $webhook;
45
46 /**
47 * FeedbackController Constructor.
48 *
49 * @param string $plugin_file The path to the plugin file.
50 * @param string $plugin_text_domain The text domain of the plugin.
51 * @param string $plugin_name The name of the plugin.
52 * @param string $plugin_slug The slug of the plugin.
53 *
54 * @since 1.0.0
55 */
56 public function __construct($plugin_file, $plugin_text_domain, $plugin_name, $plugin_slug,$webhook='') {
57 $this->plugin_file = $plugin_file;
58 $this->plugin_text_domain = $plugin_text_domain;
59 $this->plugin_name = $plugin_name;
60 $this->plugin_slug = $plugin_slug;
61 $this->namespace = $plugin_slug . '/v1';
62 $this->webhook = $webhook;
63 $this->register_routes();
64 }
65
66 /**
67 * Register REST routes for the feedback controller.
68 *
69 * @since 1.0.0
70 *
71 * @return void
72 */
73 protected function register_routes() {
74 register_rest_route($this->namespace, $this->rest_base, [
75 'methods' => 'POST',
76 'callback' => [$this, 'handle_feedback'],
77 'permission_callback' => function () {
78 return current_user_can('manage_options');
79 },
80 ]);
81 }
82
83 /**
84 * Handle feedback submission.
85 *
86 * @since 1.0.0
87 *
88 * @param WP_REST_Request $request The request object.
89 * @return WP_REST_Response The response object.
90 */
91 public function handle_feedback(WP_REST_Request $request) {
92 $nonce = $request->get_header('X-WP-Nonce');
93 if (! wp_verify_nonce($nonce, 'wp_rest')) {
94 return rest_ensure_response([
95 'status_code' => 403,
96 'success' => 0,
97 'message' => 'Invalid nonce. Unauthorized request.',
98 ]);
99 }
100
101 $data = $request->get_json_params();
102 $feedback = ! empty($data['feedback']) ? sanitize_text_field($data['feedback']) : 'No feedback';
103 $reasons = ! empty($data['reasons']) ? sanitize_text_field($data['reasons']) : 'No reasons';
104 $theme_name = ! empty($data['theme_name']) ? sanitize_text_field($data['theme_name']) : '';
105 $is_agree = isset( $data['is_agree'] ) && filter_var( $data['is_agree'], FILTER_VALIDATE_BOOLEAN );
106
107 $current_user = wp_get_current_user();
108 $user_name = $current_user->exists() ? $current_user->display_name : 'Guest';
109 $user_email = $current_user->exists() ? $current_user->user_email : '';
110
111 $customer_name = ! empty($data['customer_name']) ? sanitize_text_field($data['customer_name']) : $user_name;
112 $customer_email = ! empty($data['customer_email']) ? sanitize_text_field($data['customer_email']) : 'Not Given';
113
114 // if (! $this->verify_email_status($customer_email)) {
115 // $customer_email = '';
116 // }
117
118 // Get current user info
119
120
121 try {
122 // $config = include plugin_dir_path($this->plugin_file) . 'vendor/themewinter/uninstaller_form/config/google-sheet.php';
123 // $spreadsheetId = $config['spreadsheet_id'] ?? '';
124
125 // $credentialsPath = plugin_dir_path($this->plugin_file) . 'vendor/themewinter/uninstaller_form/config/google-credentials.json';
126
127 $sheetName = str_replace(' ', '_', $this->plugin_name);
128
129 if (! empty($customer_email) && ! empty($reasons)) {
130
131 $feedback_response = wp_remote_post('https://products.arraytics.com/feedback/wp-json/afp/v1/feedback', [
132 'method' => 'POST',
133 'headers' => [
134 'Content-Type' => 'application/json',
135 ],
136 'body' => json_encode([
137 'customer_name' => $customer_name,
138 'feedback' => $feedback,
139 'customer_email' => $customer_email,
140 'plugin_name' => $this->plugin_name,
141 'theme' => $theme_name,
142 'reason' => explode(',',$reasons),
143 'is_agree' => $is_agree
144 ]),
145 ]);
146
147
148 //Storing data to excell sheet
149 // $sheetClient = new \UninstallerForm\Support\GoogleSheetClient($credentialsPath, $spreadsheetId, $sheetName);
150 // $sheetClient->appendRow([
151 // $customer_name, // Customer name
152 // $customer_email, // Customer email
153 // $this->plugin_name, // Plugin Slug
154 // $reasons, // Reason
155 // $feedback, // Feedback message,
156 // $theme_name, // Theme name
157 // current_time('mysql'), // Timestamp
158 // ]);
159
160 //Send data through webhook
161
162 if(empty($this->webhook)){
163 $this->webhook = "https://themewinter.com/?fluentcrm=1&route=contact&hash=50d358fa-e039-4459-a3d0-ef73b3c7d451";
164 }
165 $body = [
166 'customer_name' => $customer_name,
167 'email' => $customer_email,
168 'plugin_name' => $this->plugin_name,
169 'reason' => $reasons,
170 'feedback' => $feedback,
171 'theme_name' => $theme_name,
172 ];
173 $webhook_response = wp_remote_post($this->webhook, ['body' => $body]);
174 }
175 } catch (\Exception $e) {
176 return rest_ensure_response([
177 'status_code' => 500,
178 'success' => 0,
179 'message' => 'Unable to store feedback.',
180 ]);
181 }
182
183 return rest_ensure_response([
184 'status_code' => 200,
185 'success' => 1,
186 'message' => 'Feedback saved successfully.',
187 ]);
188 }
189
190 public function verify_email_status(string $email = "") {
191 $api_key = '700tpaQtc06FcqN93Ljkoibz6oo76KWk'; // Replace with your actual API key
192 $url = 'https://emailverifier.reoon.com/api/v1/verify';
193
194 $response = wp_remote_get(add_query_arg([
195 'email' => $email,
196 'key' => $api_key,
197 'mode' => 'quick',
198 ], $url));
199
200 if (is_wp_error($response)) {
201 return 'error';
202 }
203
204 $body = wp_remote_retrieve_body($response);
205 $data = json_decode($body, true);
206
207 return isset($data['status']) && $data['status'] === "valid";
208 }
209 }