PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 1.8.2
Wp Social Login and Register Social Counter v1.8.2
3.2.1 trunk 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.10 1.3.11 1.3.2 1.3.3 1.3.4 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.4 1.4.5 1.4.6 1.4.8 1.4.9 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.5 1.8.6 1.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.8 2.2.9 3.0.0 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0
wp-social / lib / rating / rating.php
wp-social / lib / rating Last commit date
rating.php 5 years ago
rating.php
516 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 {
50 if ($text_domain == null) {
51 return false;
52 }
53
54 self::$instance = new self();
55 self::$instance->config($text_domain, (is_null($unique_id) ? uniqid() : $unique_id));
56 return self::$instance;
57 }
58
59 /**
60 * Set Text domain
61 *
62 * @param string $text_domain
63 * @param string $unique_id
64 */
65 public function config($text_domain, $unique_id)
66 {
67 $this->text_domain = $text_domain;
68 }
69
70 /**
71 * Get vesrion of $this
72 *
73 * @return \Wpmet\Rating\Rating
74 */
75 public function get_version()
76 {
77 return $this->script_version;
78 }
79
80 /**
81 * @return $this file location for debugging 🐛 purpose
82 */
83 public function get_script_location()
84 {
85 return __FILE__;
86 }
87
88 /**
89 * @param
90 */
91 public function set_plugin($plugin_name, $plugin_url)
92 {
93 $this->plugin_name = $plugin_name;
94 $this->rating_url = $plugin_url;
95 return $this;
96 }
97
98 /**
99 * @param
100 */
101 public function set_priority($priority)
102 {
103 $this->priority = $priority;
104 return $this;
105 }
106
107 public function set_first_appear_day($days = 7)
108 {
109 $this->days = $days;
110 return $this;
111 }
112
113 public function set_rating_url($url)
114 {
115 $this->rating_url = $url;
116 return $this;
117 }
118
119 public function set_plugin_logo($logo_url)
120 {
121 $this->plugin_logo = $logo_url;
122 return $this;
123 }
124
125 public function set_allowed_screens($screen)
126 {
127
128 $this->plugin_screens[] = $screen;
129
130 return $this;
131 }
132
133 public function set_condition($result)
134 {
135 switch (gettype($result)) {
136 case 'boolean':
137 $this->condition_status = $result;
138 break;
139 case 'object':
140 $this->condition_status = $result();
141 break;
142 default:
143 $this->condition_status = false;
144 }
145
146 return $this;
147 }
148
149 public static function init()
150 {
151 add_action("wp_ajax_wpmet_rating_never_show_message", [__CLASS__, "never_show_message"]);
152 add_action("wp_ajax_wpmet_rating_ask_me_later_message", [__CLASS__, "ask_me_later_message"]);
153 }
154
155 protected function is_current_screen_allowed($current_screen_id)
156 {
157 if (in_array($current_screen_id, array_merge($this->plugin_screens, ['dashboard', 'plugins']))) {
158 return true;
159 }
160
161 return false;
162 }
163
164 /**
165 * ------------------------------------------
166 * 🚀 Rating class execution point
167 * ------------------------------------------
168 */
169 public function call()
170 {
171
172 $this->init();
173 add_action('admin_head', [$this, 'fire'], $this->priority);
174 }
175
176 /**
177 * -------------------------------------------
178 * 🔥 fire the rating functionality
179 * -------------------------------------------
180 */
181 public function fire()
182 {
183
184 if (current_user_can('update_plugins')) {
185
186 $current_screen = get_current_screen();
187
188 if (!$this->is_current_screen_allowed($current_screen->id)) {
189 return;
190 }
191
192 if ($this->condition_status === false) {
193 return;
194 }
195
196 add_action('admin_footer', [$this, 'scripts'], 9999);
197
198
199 if ($this->action_on_fire()) {
200 if (!$this->is_installation_date_exists()) {
201 $this->set_installation_date();
202 }
203
204
205 if (get_option($this->text_domain . '_never_show') == 'yes') {
206
207 return;
208 }
209
210
211 // $this->display_message_box();
212
213
214 if (get_option($this->text_domain . '_ask_me_later') == 'yes') {
215
216 $this->days = '30';
217 $this->duplication = true;
218 $this->never_show_triggered = true;
219 if($this->get_remaining_days() >= $this->days){
220 $this->duplication = false;
221 }
222 }
223
224 $this->display_message_box();
225
226
227
228 }
229 }
230 }
231
232
233
234 private function action_on_fire()
235 {
236 return true;
237 }
238
239
240 public function set_installation_date()
241 {
242 add_option($this->text_domain . '_install_date', date('Y-m-d h:i:s'));
243 }
244
245 public function is_installation_date_exists()
246 {
247 return (get_option($this->text_domain . '_install_date') == false) ? false : true;
248 }
249
250 public function get_installation_date()
251 {
252 return get_option($this->text_domain . '_install_date');
253 }
254
255 public function set_first_action_date()
256 {
257 add_option($this->text_domain . '_first_action_Date', date('Y-m-d h:i:s'));
258 add_option($this->text_domain . '_first_action', 'yes');
259 }
260
261 public function get_days($from_date, $to_date)
262 {
263 return round(($to_date->format('U') - $from_date->format('U')) / (60 * 60 * 24));
264 }
265
266 public function is_first_use($in_days)
267 {
268 $install_date = get_option($this->text_domain . '_install_date');
269 $display_date = date('Y-m-d h:i:s');
270 $datetime1 = new DateTime($install_date);
271 $datetime2 = new DateTime($display_date);
272 $diff_interval = $this->get_days($datetime1, $datetime2);
273
274 if (abs($diff_interval) >= $in_days && get_option($this->text_domain . '_first_action_Date') == "yes") {
275
276 // action implementation here
277
278 }
279 }
280
281 /**
282 * ---------------------------------------------
283 * Change the status of Rating notification
284 * not to show the message again
285 * ---------------------------------------------
286 */
287 public static function never_show_message()
288 {
289 $plugin_name = $_POST['plugin_name'];
290 add_option($plugin_name . '_never_show', 'yes');
291 }
292
293 public function get_remaining_days(){
294 $install_date = get_option($this->text_domain . '_install_date');
295 $display_date = date('Y-m-d h:i:s');
296 $datetime1 = new DateTime($install_date);
297 $datetime2 = new DateTime($display_date);
298 $diff_interval = $this->get_days($datetime1, $datetime2);
299 return abs($diff_interval);
300 }
301
302 /**
303 *----------------------------------
304 * Ask me later functionality
305 *----------------------------------
306 */
307 public function display_message_box()
308 {
309
310 if(!$this->duplication){
311 global $wpmet_libs_execution_container;
312
313 if(isset($wpmet_libs_execution_container['rating'])){
314 return;
315 }
316
317 }
318
319
320 $wpmet_libs_execution_container['rating'] = __FILE__;
321
322 $install_date = get_option($this->text_domain . '_install_date');
323 $display_date = date('Y-m-d h:i:s');
324 $datetime1 = new DateTime($install_date);
325 $datetime2 = new DateTime($display_date);
326 $diff_interval = $this->get_days($datetime1, $datetime2);
327 if (abs($diff_interval) >= $this->days) {
328
329 $not_good_enough_btn_id = ($this->never_show_triggered) ? '_btn_never_show' : '_btn_not_good';
330
331 $message = "Hello! Seems like you have used {$this->plugin_name} to build this website — Thanks a lot! <br>
332 Could you please do us a <b>big favor</b> and give it a <b>5-star</b> rating on WordPress?
333 This would boost our motivation and help other users make a comfortable decision while choosing the {$this->plugin_name}";
334
335 LibsNotice::instance($this->text_domain, '_plugin_rating_msg_used_in_day')
336 ->set_message($message)
337 ->set_logo($this->plugin_logo, "max-height: 100px !important")
338 ->set_button([
339 'url' => $this->rating_url,
340 'text' => 'Ok, you deserved it',
341 'class' => 'button-primary',
342 'id' => $this->text_domain . '_btn_deserved',
343 ])
344 ->set_button([
345 'url' => '#',
346 'text' => 'I already did',
347 'class' => 'button-default',
348 'id' => $this->text_domain. '_btn_already_did',
349 'icon' => 'dashicons-before dashicons-smiley'
350 ])
351 ->set_button([
352 'url' => 'https://help.wpmet.com/',
353 'text' => 'I need support',
354 'class' => 'button-default',
355 'id' => '#',
356 'icon' => 'dashicons-before dashicons-sos',
357 ])
358 ->set_button([
359 'url' => '#',
360 'text' => 'No, not good enough',
361 'class' => 'button-default',
362 'id' => $this->text_domain . $not_good_enough_btn_id ,
363 'icon' => 'dashicons-before dashicons-thumbs-down',
364 ])
365 ->call();
366 }
367 }
368
369
370 /**
371 *---------------------------------------------------------
372 * When user will click @notGoodEnough button
373 * Then it will fire this function to change the status
374 * for next asking time
375 *---------------------------------------------------------
376 */
377
378
379 public static function ask_me_later_message()
380 {
381 $plugin_name = $_POST['plugin_name'];
382 if (get_option($plugin_name . '_ask_me_later') == false) {
383 add_option($plugin_name . '_ask_me_later', 'yes');
384 } else {
385 add_option($plugin_name . '_never_show', 'yes');
386 }
387 }
388
389 /**
390 *--------------------------------------
391 * Get current version of the plugin
392 *--------------------------------------
393 */
394
395 public function get_current_version()
396 {
397
398 return $this->version;
399 }
400
401 /**
402 *-------------------------------------------
403 * Get previous version of the plugin
404 * that have been stored in database
405 *-------------------------------------------
406 */
407
408
409 public function get_previous_version()
410 {
411
412 return get_option($this->text_domain . '_version');
413 }
414
415 /**
416 *----------------------------------------
417 * Set current version of the plugin
418 *----------------------------------------
419 */
420
421 public function set_version($version)
422 {
423 if (!get_option($this->text_domain . '_version')) {
424 add_option($this->text_domain . '_version');
425 } else {
426 update_option($this->text_domain . '_version', $version);
427 }
428 }
429
430 /**
431 *
432 * JS Ajax script for updating
433 * rating status from users
434 *
435 */
436
437 public function scripts()
438 {
439
440 echo "
441 <script>
442 jQuery(document).ready(function ($) {
443
444 $( '#".$this->text_domain."_btn_already_did' ).on( 'click', function() {
445
446 $.ajax({
447 url: ajaxurl,
448 type: 'POST',
449 data: {
450 action : 'wpmet_rating_never_show_message',
451 plugin_name : '" . $this->text_domain . "',
452
453 },
454 success:function(response){
455 $('#" . $this->text_domain . "-_plugin_rating_msg_used_in_day').remove();
456
457 }
458 });
459
460 });
461
462 $('#".$this->text_domain."_btn_deserved').click(function(){
463 $.ajax({
464 url: ajaxurl,
465 type: 'POST',
466 data: {
467 action : 'wpmet_rating_never_show_message',
468 plugin_name : '" . $this->text_domain . "',
469
470 },
471 success:function(response){
472 $('#" . $this->text_domain . "-_plugin_rating_msg_used_in_day').remove();
473
474 }
475 });
476 });
477
478 $('#".$this->text_domain."_btn_not_good').click(function(){
479 $.ajax({
480 url: ajaxurl,
481 type: 'POST',
482 data: {
483 action : 'wpmet_rating_ask_me_later_message',
484 plugin_name : '" . $this->text_domain . "',
485
486 },
487 success:function(response){
488 $('#" . $this->text_domain . "-_plugin_rating_msg_used_in_day').remove();
489
490 }
491 });
492 });
493
494 $('#".$this->text_domain."_btn_never_show').click(function(){
495 $.ajax({
496 url: ajaxurl,
497 type: 'POST',
498 data: {
499 action : 'wpmet_rating_never_show_message',
500 plugin_name : '" . $this->text_domain . "',
501
502 },
503 success:function(response){
504 $('#" . $this->text_domain . "-_plugin_rating_msg_used_in_day').remove();
505
506 }
507 });
508 });
509
510 });
511 </script>
512 ";
513 }
514 }
515 }
516