PluginProbe ʕ •ᴥ•ʔ
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.0
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.0
4.0.2 4.0.1 4.0.0 3.10.02 3.10.01 3.9.10 3.9.9 3.9.8 3.9.7 3.9.5 3.9.6 3.9.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.1 2.3.1.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.4.0 2.5.0 2.5.1 2.5.10 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.2 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.6.0 3.6.1 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.8.1 3.8.2 3.9.0 3.9.1 3.9.2 trunk 1.2.6 1.2.7 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.0.9.1 2.0.9.2 2.0.9.3
elementskit-lite / libs / rating / rating.php
elementskit-lite / libs / rating Last commit date
rating.php 6 months ago
rating.php
498 lines
1 <?php
2
3 namespace Wpmet\Libs;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use DateTime;
8 use Oxaim\Libs\Notice as LibsNotice;
9
10 if ( ! class_exists( 'Wpmet\Libs\Rating' ) ) {
11
12 /**
13 * Asking client for rating and
14 * other stuffs
15 * Class Rating
16 * @package MetForm\Utils
17 */
18 class Rating {
19
20 private $plugin_name;
21 private $priority = 10;
22 private $days;
23 private $rating_url;
24 private $version;
25 private $condition_status = true;
26 private $text_domain;
27 private $plugin_logo;
28 private $plugin_screens;
29 private $duplication = false;
30 private $never_show_triggered = false;
31
32 /**
33 * scripts version
34 *
35 * @var string
36 */
37 protected $script_version = '2.0.0';
38
39 private static $instance;
40
41 /**
42 * Method: instance -> Return Notice module class instance
43 *
44 * @param string|null $text_domain
45 * @param string|null $unique_id
46 * @return mixed
47 */
48 public static function instance( $text_domain = null, $unique_id = null ) {
49 if ( $text_domain == null ) {
50 return false;
51 }
52
53 self::$instance = new self();
54 self::$instance->config( $text_domain, ( is_null( $unique_id ) ? uniqid() : $unique_id ) );
55 return self::$instance;
56 }
57
58 /**
59 * Set Text domain
60 *
61 * @param string $text_domain
62 * @param string $unique_id
63 */
64 public function config( $text_domain, $unique_id ) {
65 $this->text_domain = $text_domain;
66 }
67
68 /**
69 * Get vesrion of $this
70 *
71 * @return \Wpmet\Rating\Rating
72 */
73 public function get_version() {
74 return $this->script_version;
75 }
76
77 /**
78 * @return $this file location for debugging 🐛 purpose
79 */
80 public function get_script_location() {
81 return __FILE__;
82 }
83
84 /**
85 * @param
86 */
87 public function set_plugin( $plugin_name, $plugin_url ) {
88 $this->plugin_name = $plugin_name;
89 $this->rating_url = $plugin_url;
90 return $this;
91 }
92
93 /**
94 * @param
95 */
96 public function set_priority( $priority ) {
97 $this->priority = $priority;
98 return $this;
99 }
100
101 public function set_first_appear_day( $days = 7 ) {
102 $this->days = $days;
103 return $this;
104 }
105
106 public function set_rating_url( $url ) {
107 $this->rating_url = $url;
108 return $this;
109 }
110
111 public function set_plugin_logo( $logo_url ) {
112 $this->plugin_logo = $logo_url;
113 return $this;
114 }
115
116 public function set_allowed_screens( $screen ) {
117
118 $this->plugin_screens[] = $screen;
119
120 return $this;
121 }
122
123 public function set_condition( $result ) {
124 switch ( gettype( $result ) ) {
125 case 'boolean':
126 $this->condition_status = $result;
127 break;
128 case 'object':
129 $this->condition_status = $result();
130 break;
131 default:
132 $this->condition_status = false;
133 }
134
135 return $this;
136 }
137
138 public static function init() {
139 add_action( 'wp_ajax_wpmet_rating_never_show_message', array( __CLASS__, 'never_show_message' ) );
140 add_action( 'wp_ajax_wpmet_rating_ask_me_later_message', array( __CLASS__, 'ask_me_later_message' ) );
141 }
142
143 protected function is_current_screen_allowed( $current_screen_id ) {
144 if ( in_array( $current_screen_id, array_merge( $this->plugin_screens, array( 'dashboard', 'plugins' ) ) ) ) {
145 return true;
146 }
147
148 return false;
149 }
150
151 /**
152 * ------------------------------------------
153 * 🚀 Rating class execution point
154 * ------------------------------------------
155 */
156 public function call() {
157
158 $this->init();
159 add_action( 'admin_head', array( $this, 'fire' ), $this->priority );
160 }
161
162 /**
163 * -------------------------------------------
164 * 🔥 fire the rating functionality
165 * -------------------------------------------
166 */
167 public function fire() {
168
169 if ( current_user_can( 'update_plugins' ) ) {
170
171 $current_screen = get_current_screen();
172
173 if ( ! $this->is_current_screen_allowed( $current_screen->id ) ) {
174 return;
175 }
176
177 if ( $this->condition_status === false ) {
178 return;
179 }
180
181 add_action( 'admin_footer', array( $this, 'scripts' ), 9999 );
182
183 if ( $this->action_on_fire() ) {
184 if ( ! $this->is_installation_date_exists() ) {
185 $this->set_installation_date();
186 }
187
188 if ( get_option( $this->text_domain . '_never_show' ) == 'yes' ) {
189
190 return;
191 }
192
193 // $this->display_message_box();
194
195 if ( get_option( $this->text_domain . '_ask_me_later' ) == 'yes' ) {
196
197 $this->days = '30';
198 $this->duplication = true;
199 $this->never_show_triggered = true;
200 if ( $this->get_remaining_days() >= $this->days ) {
201 $this->duplication = false;
202 }
203 }
204
205 $this->display_message_box();
206
207 }
208 }
209 }
210
211
212
213 private function action_on_fire() {
214 return true;
215 }
216
217
218 public function set_installation_date() {
219 add_option( $this->text_domain . '_install_date', gmdate( 'Y-m-d h:i:s' ) );
220 }
221
222 public function is_installation_date_exists() {
223 return ( get_option( $this->text_domain . '_install_date' ) == false ) ? false : true;
224 }
225
226 public function get_installation_date() {
227 return get_option( $this->text_domain . '_install_date' );
228 }
229
230 public function set_first_action_date() {
231 add_option( $this->text_domain . '_first_action_Date', gmdate( 'Y-m-d h:i:s' ) );
232 add_option( $this->text_domain . '_first_action', 'yes' );
233 }
234
235 public function get_days( $from_date, $to_date ) {
236 return round( ( $to_date->format( 'U' ) - $from_date->format( 'U' ) ) / ( 60 * 60 * 24 ) );
237 }
238
239 public function is_first_use( $in_days ) {
240 $install_date = get_option( $this->text_domain . '_install_date' );
241 $display_date = gmdate( 'Y-m-d h:i:s' );
242 $datetime1 = new DateTime( $install_date );
243 $datetime2 = new DateTime( $display_date );
244 $diff_interval = $this->get_days( $datetime1, $datetime2 );
245
246 if ( abs( $diff_interval ) >= $in_days && get_option( $this->text_domain . '_first_action_Date' ) == 'yes' ) {
247
248 // action implementation here
249
250 }
251 }
252
253 /**
254 * ---------------------------------------------
255 * Change the status of Rating notification
256 * not to show the message again
257 * ---------------------------------------------
258 */
259 public static function never_show_message() {
260
261 if( empty( $_POST['nonce'] ) || !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'wpmet_rating' ) ){
262 return false;
263 }
264
265 $plugin_name = isset($_POST['plugin_name']) ? sanitize_key( $_POST['plugin_name'] ) : '';
266 add_option( $plugin_name . '_never_show', 'yes' );
267 }
268
269 public function get_remaining_days() {
270 $install_date = get_option( $this->text_domain . '_install_date' );
271 $display_date = gmdate( 'Y-m-d h:i:s' );
272 $datetime1 = new DateTime( $install_date );
273 $datetime2 = new DateTime( $display_date );
274 $diff_interval = $this->get_days( $datetime1, $datetime2 );
275 return abs( $diff_interval );
276 }
277
278 /**
279 *----------------------------------
280 * Ask me later functionality
281 *----------------------------------
282 */
283 public function display_message_box() {
284
285 if ( ! $this->duplication ) {
286 global $wpmet_libs_execution_container;
287
288 if ( isset( $wpmet_libs_execution_container['rating'] ) ) {
289 return;
290 }
291 }
292
293 $wpmet_libs_execution_container['rating'] = __FILE__;
294
295 $install_date = get_option( $this->text_domain . '_install_date' );
296 $display_date = gmdate( 'Y-m-d h:i:s' );
297 $datetime1 = new DateTime( $install_date );
298 $datetime2 = new DateTime( $display_date );
299 $diff_interval = $this->get_days( $datetime1, $datetime2 );
300 if ( abs( $diff_interval ) >= $this->days ) {
301
302 $not_good_enough_btn_id = ( $this->never_show_triggered ) ? '_btn_never_show' : '_btn_not_good';
303
304 $message = "Hello! Seems like you have used {$this->plugin_name} to build this website — Thanks a lot! <br>
305 Could you please do us a <b>big favor</b> and give it a <b>5-star</b> rating on WordPress?
306 This would boost our motivation and help other users make a comfortable decision while choosing the {$this->plugin_name}";
307
308 LibsNotice::instance( $this->text_domain, '_plugin_rating_msg_used_in_day' )
309 ->set_message( $message )
310 ->set_logo( $this->plugin_logo, 'max-height: 100px !important' )
311 ->set_button(
312 array(
313 'url' => $this->rating_url,
314 'text' => 'Ok, you deserved it',
315 'class' => 'button-primary',
316 'id' => $this->text_domain . '_btn_deserved',
317 )
318 )
319 ->set_button(
320 array(
321 'url' => '#',
322 'text' => 'I already did',
323 'class' => 'button-default',
324 'id' => $this->text_domain . '_btn_already_did',
325 'icon' => 'dashicons-before dashicons-smiley',
326 )
327 )
328 ->set_button(
329 array(
330 'url' => 'https://wpmet.com/support-ticket',
331 'text' => 'I need support',
332 'class' => 'button-default',
333 'id' => '#',
334 'icon' => 'dashicons-before dashicons-sos',
335 )
336 )
337 ->set_button(
338 array(
339 'url' => '#',
340 'text' => 'No, not good enough',
341 'class' => 'button-default',
342 'id' => $this->text_domain . $not_good_enough_btn_id,
343 'icon' => 'dashicons-before dashicons-thumbs-down',
344 )
345 )
346 ->call();
347 }
348 }
349
350
351 /**
352 *---------------------------------------------------------
353 * When user will click @notGoodEnough button
354 * Then it will fire this function to change the status
355 * for next asking time
356 *---------------------------------------------------------
357 */
358
359
360 public static function ask_me_later_message() {
361
362 if( empty( $_POST['nonce'] ) || !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'wpmet_rating' ) ){
363 return false;
364 }
365
366 $plugin_name = isset($_POST['plugin_name']) ? sanitize_key( $_POST['plugin_name'] ) : '';
367 if ( get_option( $plugin_name . '_ask_me_later' ) == false ) {
368 add_option( $plugin_name . '_ask_me_later', 'yes' );
369 } else {
370 add_option( $plugin_name . '_never_show', 'yes' );
371 }
372 }
373
374 /**
375 *--------------------------------------
376 * Get current version of the plugin
377 *--------------------------------------
378 */
379
380 public function get_current_version() {
381
382 return $this->version;
383 }
384
385 /**
386 *-------------------------------------------
387 * Get previous version of the plugin
388 * that have been stored in database
389 *-------------------------------------------
390 */
391
392
393 public function get_previous_version() {
394
395 return get_option( $this->text_domain . '_version' );
396 }
397
398 /**
399 *----------------------------------------
400 * Set current version of the plugin
401 *----------------------------------------
402 */
403
404 public function set_version( $version ) {
405 if ( ! get_option( $this->text_domain . '_version' ) ) {
406 add_option( $this->text_domain . '_version' );
407 } else {
408 update_option( $this->text_domain . '_version', $version );
409 }
410 }
411
412 /**
413 *
414 * JS Ajax script for updating
415 * rating status from users
416 *
417 */
418
419 public function scripts() {
420
421 echo "
422 <script>
423 jQuery(document).ready(function ($) {
424
425 $( '#" . esc_js( $this->text_domain ) . "_btn_already_did' ).on( 'click', function() {
426
427 $.ajax({
428 url: ajaxurl,
429 type: 'POST',
430 data: {
431 action : 'wpmet_rating_never_show_message',
432 plugin_name : '" . esc_js( $this->text_domain ) . "',
433 nonce : '" . esc_js( wp_create_nonce( 'wpmet_rating' ) ) . "'
434
435 },
436 success:function(response){
437 $('#" . esc_js( $this->text_domain ) . "-_plugin_rating_msg_used_in_day').remove();
438
439 }
440 });
441
442 });
443
444 $('#" . esc_js( $this->text_domain ) . "_btn_deserved').on('click', function(){
445 $.ajax({
446 url: ajaxurl,
447 type: 'POST',
448 data: {
449 action : 'wpmet_rating_never_show_message',
450 plugin_name : '" . esc_js( $this->text_domain ) . "',
451 nonce : '" . esc_js( wp_create_nonce( 'wpmet_rating' ) ) . "'
452 },
453 success:function(response){
454 $('#" . esc_js( $this->text_domain ) . "-_plugin_rating_msg_used_in_day').remove();
455
456 }
457 });
458 });
459
460 $('#" . esc_js( $this->text_domain ) . "_btn_not_good').on('click', function(){
461 $.ajax({
462 url: ajaxurl,
463 type: 'POST',
464 data: {
465 action : 'wpmet_rating_ask_me_later_message',
466 plugin_name : '" . esc_js( $this->text_domain ) . "',
467 nonce : '" . esc_js( wp_create_nonce( 'wpmet_rating' ) ) . "'
468 },
469 success:function(response){
470 $('#" . esc_js( $this->text_domain ) . "-_plugin_rating_msg_used_in_day').remove();
471
472 }
473 });
474 });
475
476 $('#" . esc_js( $this->text_domain ) . "_btn_never_show').on('click', function(){
477 $.ajax({
478 url: ajaxurl,
479 type: 'POST',
480 data: {
481 action : 'wpmet_rating_never_show_message',
482 plugin_name : '" . esc_js( $this->text_domain ) . "',
483 nonce : '" . esc_js( wp_create_nonce( 'wpmet_rating' ) ) . "'
484 },
485 success:function(response){
486 $('#" . esc_js( $this->text_domain ) . "-_plugin_rating_msg_used_in_day').remove();
487
488 }
489 });
490 });
491
492 });
493 </script>
494 ";
495 }
496 }
497 }
498