PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.10
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.10
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 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.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / codeinwp / themeisle-sdk / src / Modules / Uninstall_feedback.php

Uninstall_feedback.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.11.10, at vendor/codeinwp/themeisle-sdk/src/Modules/Uninstall_feedback.php

839 lines 23.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The deactivate feedback model class for ThemeIsle SDK
4 *
5 * @package ThemeIsleSDK
6 * @subpackage Feedback
7 * @copyright Copyright (c) 2017, Marius Cristea
8 * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
9 * @since 1.0.0
10 */
11
12 namespace ThemeisleSDK\Modules;
13
14 use ThemeisleSDK\Common\Abstract_Module;
15 use ThemeisleSDK\Loader;
16 use ThemeisleSDK\Product;
17
18 // Exit if accessed directly.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Uninstall feedback module for ThemeIsle SDK.
25 */
26 class Uninstall_Feedback extends Abstract_Module {
27 /**
28 * How many seconds before the deactivation window is triggered for themes?
29 *
30 * @var int Number of days.
31 */
32 const AUTO_TRIGGER_DEACTIVATE_WINDOW_SECONDS = 3;
33 /**
34 * How many days before the deactivation window pops up again for the theme?
35 *
36 * @var int Number of days.
37 */
38 const PAUSE_DEACTIVATE_WINDOW_DAYS = 100;
39 /**
40 * Where to send the data.
41 *
42 * @var string Endpoint url.
43 */
44 const FEEDBACK_ENDPOINT = 'https://api.themeisle.com/tracking/uninstall';
45
46 /**
47 * Default options for plugins.
48 *
49 * @var array $options_plugin The main options list for plugins.
50 */
51 private $options_plugin = array(
52 'id3' => array(
53 'id' => 3,
54 'type' => 'text',
55
56 ),
57 'id4' => array(
58 'type' => 'textarea',
59 'id' => 4,
60 ),
61 'id5' => array(
62 'id' => 5,
63 'type' => 'textarea',
64 ),
65 'id6' => array(
66 'type' => 'textarea',
67 'id' => 6,
68 ),
69 );
70 /**
71 * Default options for theme.
72 *
73 * @var array $options_theme The main options list for themes.
74 */
75 private $options_theme = array(
76 'id7' => array(
77 'id' => 7,
78 ),
79 'id8' => array(
80 'type' => 'text',
81 'id' => 8,
82 ),
83 'id9' => array(
84 'id' => 9,
85 'type' => 'text',
86 ),
87 'id10' => array(
88
89 'title' => '',
90 'id' => 10,
91 ),
92 );
93 /**
94 * Default other option.
95 *
96 * @var array $other The other option
97 */
98 private $other = array(
99 'id999' => array(
100 'id' => 999,
101 'type' => 'textarea',
102 ),
103 );
104
105 /**
106 * Loads the additional resources
107 */
108 public function load_resources() {
109 $screen = get_current_screen();
110
111 if ( ! $screen || ! in_array( $screen->id, array( 'theme-install', 'plugins' ) ) ) {
112 return;
113 }
114
115 $this->add_feedback_popup_style();
116
117 if ( $this->product->get_type() === 'theme' ) {
118 $this->add_theme_feedback_drawer_js();
119 $this->render_theme_feedback_popup();
120
121 return;
122 }
123 $this->add_plugin_feedback_popup_js();
124 $this->render_plugin_feedback_popup();
125 }
126
127 /**
128 * Render theme feedback drawer.
129 */
130 private function render_theme_feedback_popup() {
131 $heading = str_replace( '{theme}', $this->product->get_name(), Loader::$labels['uninstall']['heading_theme'] );
132 $button_submit = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_submit', Loader::$labels['uninstall']['submit'] );
133 $options = $this->options_theme;
134 $options = $this->randomize_options( apply_filters( $this->product->get_key() . '_feedback_deactivate_options', $options ) );
135 $info_disclosure_link = '<a href="#" class="info-disclosure-link">' . apply_filters( $this->product->get_slug() . '_themeisle_sdk_info_collect_cta', Loader::$labels['uninstall']['cta_info'] ) . '</a>';
136
137 $options += $this->other;
138
139 ?>
140 <div class="ti-theme-uninstall-feedback-drawer ti-feedback">
141 <div class="popup--header">
142 <h5><?php echo wp_kses( $heading, array( 'span' => true ) ); ?> </h5>
143 <button class="toggle"><span>&times;</span></button>
144 </div><!--/.popup--header-->
145 <div class="popup--body">
146 <?php $this->render_options_list( $options ); ?>
147 </div><!--/.popup--body-->
148 <div class="popup--footer">
149 <div class="actions">
150 <?php
151 echo wp_kses_post( $info_disclosure_link );
152 echo wp_kses_post( $this->get_disclosure_labels() );
153 echo '<div class="buttons">';
154 echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function has an internal sanitization.
155 $button_submit,
156 'secondary',
157 $this->product->get_key() . 'ti-deactivate-yes',
158 false,
159 array(
160 'data-after-text' => $button_submit,
161 'disabled' => true,
162 )
163 );
164 echo '</div>';
165 ?>
166 </div><!--/.actions-->
167 </div><!--/.popup--footer-->
168 </div>
169 <?php
170 }
171
172 /**
173 * Add feedback styles.
174 */
175 private function add_feedback_popup_style() {
176 ?>
177 <style>
178 .ti-feedback {
179 background: #fff;
180 max-width: 400px;
181 z-index: 10000;
182 box-shadow: 0 0 15px -5px rgba(0, 0, 0, .5);
183 transition: all .3s ease-out;
184 }
185
186
187 .ti-feedback .popup--header {
188 position: relative;
189 background-color: #23A1CE;
190 }
191
192 .ti-feedback .popup--header h5 {
193 margin: 0;
194 font-size: 16px;
195 padding: 15px;
196 color: #fff;
197 font-weight: 600;
198 text-align: center;
199 letter-spacing: .3px;
200 }
201
202 .ti-feedback .popup--body {
203 padding: 15px;
204 }
205
206 .ti-feedback .popup--form {
207 margin: 0;
208 font-size: 13px;
209 }
210
211 .ti-feedback .popup--form input[type="radio"] {
212 <?php echo is_rtl() ? 'margin: 0 0 0 10px;' : 'margin: 0 10px 0 0;'; ?>
213 }
214
215 .ti-feedback .popup--form input[type="radio"]:checked ~ textarea {
216 display: block;
217 }
218
219 .ti-feedback .popup--form textarea {
220 width: 100%;
221 margin: 10px 0 0;
222 display: none;
223 max-height: 150px;
224 }
225
226 .ti-feedback li {
227 display: flex;
228 align-items: center;
229 margin-bottom: 15px;
230 flex-wrap: wrap;
231 }
232
233 .ti-feedback li label {
234 max-width: 90%;
235 }
236
237 .ti-feedback li:last-child {
238 margin-bottom: 0;
239 }
240
241 .ti-feedback .popup--footer {
242 padding: 0 15px 15px;
243 }
244
245 .ti-feedback .actions {
246 display: flex;
247 flex-wrap: wrap;
248 }
249
250 .info-disclosure-link {
251 width: 100%;
252 margin-bottom: 15px;
253 }
254
255 .ti-feedback .info-disclosure-content {
256 max-height: 0;
257 overflow: hidden;
258 width: 100%;
259 transition: .3s ease;
260 }
261
262 .ti-feedback .info-disclosure-content.active {
263 max-height: 300px;
264 }
265
266 .ti-feedback .info-disclosure-content p {
267 margin: 0;
268 }
269
270 .ti-feedback .info-disclosure-content ul {
271 margin: 10px 0;
272 border-radius: 3px;
273 }
274
275 .ti-feedback .info-disclosure-content ul li {
276 display: flex;
277 align-items: center;
278 justify-content: space-between;
279 margin-bottom: 0;
280 padding: 5px 0;
281 border-bottom: 1px solid #ccc;
282 }
283
284 .ti-feedback .buttons {
285 display: flex;
286 width: 100%;
287 }
288
289 .ti-feedback .buttons input:last-child {
290 <?php echo is_rtl() ? 'margin-right: auto;' : 'margin-left: auto;'; ?>
291 }
292
293 .ti-theme-uninstall-feedback-drawer {
294 border-top-left-radius: 5px;
295 position: fixed;
296 top: 100%;
297 right: 15px;
298 }
299
300 .ti-theme-uninstall-feedback-drawer.active {
301 transform: translateY(-100%);
302 }
303
304 .ti-theme-uninstall-feedback-drawer .popup--header {
305 border-top-left-radius: 5px;
306 }
307
308 .ti-theme-uninstall-feedback-drawer .popup--header .toggle {
309 position: absolute;
310 padding: 3px 0;
311 width: 30px;
312 top: -26px;
313 right: 0;
314 cursor: pointer;
315 border-top-left-radius: 5px;
316 border-top-right-radius: 5px;
317 font-size: 20px;
318 background-color: #23A1CE;
319 color: #fff;
320 border: none;
321 line-height: 20px;
322 }
323
324 .ti-theme-uninstall-feedback-drawer .toggle span {
325 margin: 0;
326 display: inline-block;
327 }
328
329 .ti-theme-uninstall-feedback-drawer:not(.active) .toggle span {
330 transform: rotate(45deg);
331 }
332
333 .ti-theme-uninstall-feedback-drawer .popup--header .toggle:hover {
334 background-color: #1880a5;
335 }
336
337
338 .ti-plugin-uninstall-feedback-popup .popup--header:before {
339 content: "";
340 display: block;
341 position: absolute;
342 top: 50%;
343 transform: translateY(-50%);
344 <?php
345 echo is_rtl() ?
346 'right: -10px;
347 border-top: 20px solid transparent;
348 border-left: 20px solid #23A1CE;
349 border-bottom: 20px solid transparent;' :
350 'left: -10px;
351 border-top: 20px solid transparent;
352 border-right: 20px solid #23A1CE;
353 border-bottom: 20px solid transparent;';
354 ?>
355 }
356
357 .ti-plugin-uninstall-feedback-popup {
358 display: none;
359 position: absolute;
360 white-space: normal;
361 width: 400px;
362 <?php echo is_rtl() ? 'right: calc( 100% + 15px );' : 'left: calc( 100% + 15px );'; ?> top: -15px;
363 }
364
365 .ti-plugin-uninstall-feedback-popup.sending-feedback .popup--body i {
366 animation: rotation 2s infinite linear;
367 display: block;
368 float: none;
369 align-items: center;
370 width: 100%;
371 margin: 0 auto;
372 height: 100%;
373 background: transparent;
374 padding: 0;
375 }
376
377 .ti-plugin-uninstall-feedback-popup.sending-feedback .popup--body i:before {
378 padding: 0;
379 background: transparent;
380 box-shadow: none;
381 color: #b4b9be
382 }
383
384
385 .ti-plugin-uninstall-feedback-popup.active {
386 display: block;
387 }
388
389 tr[data-plugin^="<?php echo esc_attr( $this->product->get_slug() ); ?>"] .deactivate {
390 position: relative;
391 }
392
393 body.ti-feedback-open .ti-feedback-overlay {
394 content: "";
395 display: block;
396 background-color: rgba(0, 0, 0, 0.5);
397 top: 0;
398 bottom: 0;
399 right: 0;
400 left: 0;
401 z-index: 10000;
402 position: fixed;
403 }
404
405 @media (max-width: 768px) {
406 .ti-plugin-uninstall-feedback-popup {
407 position: fixed;
408 max-width: 100%;
409 margin: 0 auto;
410 left: 50%;
411 top: 50px;
412 transform: translateX(-50%);
413 }
414
415 .ti-plugin-uninstall-feedback-popup .popup--header:before {
416 display: none;
417 }
418 }
419 </style>
420 <?php
421 }
422
423 /**
424 * Theme feedback drawer JS.
425 */
426 private function add_theme_feedback_drawer_js() {
427 $key = $this->product->get_key();
428 ?>
429 <script type="text/javascript" id="ti-deactivate-js">
430 (function ($) {
431 $(document).ready(function () {
432 setTimeout(function () {
433 $('.ti-theme-uninstall-feedback-drawer').addClass('active');
434 }, <?php echo absint( self::AUTO_TRIGGER_DEACTIVATE_WINDOW_SECONDS * 1000 ); ?> );
435
436 $('.ti-theme-uninstall-feedback-drawer .toggle').on('click', function (e) {
437 e.preventDefault();
438 $('.ti-theme-uninstall-feedback-drawer').toggleClass('active');
439 });
440
441 $('.info-disclosure-link').on('click', function (e) {
442 e.preventDefault();
443 $('.info-disclosure-content').toggleClass('active');
444 });
445
446 $('.ti-theme-uninstall-feedback-drawer input[type="radio"]').on('change', function () {
447 var radio = $(this);
448 if (radio.parent().find('textarea').length > 0 &&
449 radio.parent().find('textarea').val().length === 0) {
450 $('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled');
451 radio.parent().find('textarea').on('keyup', function (e) {
452 if ($(this).val().length === 0) {
453 $('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled');
454 } else {
455 $('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled');
456 }
457 });
458 } else {
459 $('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled');
460 }
461 });
462
463 $('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').on('click', function (e) {
464 e.preventDefault();
465 e.stopPropagation();
466
467 var selectedOption = $(
468 '.ti-theme-uninstall-feedback-drawer input[name="ti-deactivate-option"]:checked');
469 $.post(ajaxurl, {
470 'action': '<?php echo esc_attr( $key ) . '_uninstall_feedback'; ?>',
471 'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>',
472 'id': selectedOption.parent().attr('ti-option-id'),
473 'msg': selectedOption.parent().find('textarea').val(),
474 'type': 'theme',
475 'key': '<?php echo esc_attr( $key ); ?>'
476 });
477 $('.ti-theme-uninstall-feedback-drawer').fadeOut();
478 });
479 });
480 })(jQuery);
481
482 </script>
483 <?php
484 do_action( $this->product->get_key() . '_uninstall_feedback_after_js' );
485 }
486
487 /**
488 * Render the options list.
489 *
490 * @param array $options the options for the feedback form.
491 */
492 private function render_options_list( $options ) {
493 $key = $this->product->get_key();
494 $inputs_row_map = [
495 'text' => 1,
496 'textarea' => 2,
497 ];
498 ?>
499 <ul class="popup--form">
500 <?php
501 foreach ( $options as $idx => $attributes ) {
502 $title = Loader::$labels['uninstall']['options'][ $idx ]['title'];
503 $placeholder = array_key_exists( 'placeholder', Loader::$labels['uninstall']['options'][ $idx ] ) ? Loader::$labels['uninstall']['options'][ $idx ]['placeholder'] : '';
504 ?>
505 <li ti-option-id="<?php echo esc_attr( $attributes['id'] ); ?>">
506 <input type="radio" name="ti-deactivate-option"
507 id="<?php echo esc_attr( $key . $attributes['id'] ); ?>">
508 <label for="<?php echo esc_attr( $key . $attributes['id'] ); ?>">
509 <?php echo esc_attr( str_replace( '{theme}', $this->product->get_name(), $title ) ); ?>
510 </label>
511 <?php
512 if ( array_key_exists( 'type', $attributes ) ) {
513
514 echo '<textarea width="100%" rows="' . esc_attr( $inputs_row_map[ $attributes['type'] ] ) . '" name="comments" placeholder="' . esc_attr( $placeholder ) . '"></textarea>';
515 }
516 ?>
517 </li>
518 <?php } ?>
519 </ul>
520 <?php
521 }
522
523 /**
524 * Render plugin feedback popup.
525 */
526 private function render_plugin_feedback_popup() {
527 $button_cancel = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_cancel', Loader::$labels['uninstall']['button_cancel'] );
528 $button_submit = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_submit', Loader::$labels['uninstall']['button_submit'] );
529 $options = $this->randomize_options( apply_filters( $this->product->get_key() . '_feedback_deactivate_options', $this->options_plugin ) );
530 $info_disclosure_link = '<a href="#" class="info-disclosure-link">' . apply_filters( $this->product->get_slug() . '_themeisle_sdk_info_collect_cta', Loader::$labels['uninstall']['cta_info'] ) . '</a>';
531
532 $options += $this->other;
533 ?>
534 <div class="ti-plugin-uninstall-feedback-popup ti-feedback"
535 id="<?php echo esc_attr( $this->product->get_slug() . '_uninstall_feedback_popup' ); ?>">
536 <div class="popup--header">
537 <h5><?php echo wp_kses( Loader::$labels['uninstall']['heading_plugin'], array( 'span' => true ) ); ?> </h5>
538 </div><!--/.popup--header-->
539 <div class="popup--body">
540 <?php $this->render_options_list( $options ); ?>
541 </div><!--/.popup--body-->
542 <div class="popup--footer">
543 <div class="actions">
544 <?php
545 echo wp_kses_post( $info_disclosure_link );
546 echo wp_kses_post( $this->get_disclosure_labels() );
547 echo '<div class="buttons">';
548 echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function internals are escaped.
549 $button_cancel,
550 'secondary',
551 $this->product->get_key() . 'ti-deactivate-no',
552 false
553 );
554 echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function internals are escaped.
555 $button_submit,
556 'primary',
557 $this->product->get_key() . 'ti-deactivate-yes',
558 false,
559 array(
560 'data-after-text' => $button_submit,
561 'disabled' => true,
562 )
563 );
564 echo '</div>';
565 ?>
566 </div><!--/.actions-->
567 </div><!--/.popup--footer-->
568 </div>
569
570 <?php
571 }
572
573 /**
574 * Add plugin feedback popup JS
575 */
576 private function add_plugin_feedback_popup_js() {
577 $popup_id = '#' . $this->product->get_slug() . '_uninstall_feedback_popup';
578 $key = $this->product->get_key();
579 ?>
580 <script type="text/javascript" id="ti-deactivate-js">
581 (function ($) {
582 $(document).ready(function () {
583 var targetElement = 'tr[data-plugin^="<?php echo esc_attr( $this->product->get_slug() ); ?>/"] span.deactivate a';
584 var redirectUrl = $(targetElement).attr('href');
585 if ($('.ti-feedback-overlay').length === 0) {
586 $('body').prepend('<div class="ti-feedback-overlay"></div>');
587 }
588 $('<?php echo esc_attr( $popup_id ); ?> ').appendTo($(targetElement).parent());
589
590 $(targetElement).on('click', function (e) {
591 e.preventDefault();
592 $('<?php echo esc_attr( $popup_id ); ?> ').addClass('active');
593 $('body').addClass('ti-feedback-open');
594 $('.ti-feedback-overlay').on('click', function () {
595 $('<?php echo esc_attr( $popup_id ); ?> ').removeClass('active');
596 $('body').removeClass('ti-feedback-open');
597 });
598 });
599
600 $('<?php echo esc_attr( $popup_id ); ?> .info-disclosure-link').on('click', function (e) {
601 e.preventDefault();
602 $(this).parent().find('.info-disclosure-content').toggleClass('active');
603 });
604
605 $('<?php echo esc_attr( $popup_id ); ?> input[type="radio"]').on('change', function () {
606 var radio = $(this);
607 if (radio.parent().find('textarea').length > 0 &&
608 radio.parent().find('textarea').val().length === 0) {
609 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled');
610 radio.parent().find('textarea').on('keyup', function (e) {
611 if ($(this).val().length === 0) {
612 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled');
613 } else {
614 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled');
615 }
616 });
617 } else {
618 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled');
619 }
620 });
621
622 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-no').on('click', function (e) {
623 e.preventDefault();
624 e.stopPropagation();
625 $(targetElement).unbind('click');
626 $('body').removeClass('ti-feedback-open');
627 $('<?php echo esc_attr( $popup_id ); ?>').remove();
628 if (redirectUrl !== '') {
629 location.href = redirectUrl;
630 }
631 });
632
633 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').on('click', function (e) {
634 e.preventDefault();
635 e.stopPropagation();
636 $(targetElement).unbind('click');
637 var selectedOption = $(
638 '<?php echo esc_attr( $popup_id ); ?> input[name="ti-deactivate-option"]:checked');
639 var data = {
640 'action': '<?php echo esc_attr( $key ) . '_uninstall_feedback'; ?>',
641 'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>',
642 'id': selectedOption.parent().attr('ti-option-id'),
643 'msg': selectedOption.parent().find('textarea').val(),
644 'type': 'plugin',
645 'key': '<?php echo esc_attr( $key ); ?>'
646 };
647 $.ajax({
648 type: 'POST',
649 url: ajaxurl,
650 data: data,
651 complete() {
652 $('body').removeClass('ti-feedback-open');
653 $('<?php echo esc_attr( $popup_id ); ?>').remove();
654 if (redirectUrl !== '') {
655 location.href = redirectUrl;
656 }
657 },
658 beforeSend() {
659 $('<?php echo esc_attr( $popup_id ); ?>').addClass('sending-feedback');
660 $('<?php echo esc_attr( $popup_id ); ?> .popup--footer').remove();
661 $('<?php echo esc_attr( $popup_id ); ?> .popup--body').html('<i class="dashicons dashicons-update-alt"></i>');
662 }
663 });
664 });
665 });
666 })(jQuery);
667
668 </script>
669 <?php
670 do_action( $this->product->get_key() . '_uninstall_feedback_after_js' );
671 }
672
673 /**
674 * Get the disclosure labels markup.
675 *
676 * @return string
677 */
678 private function get_disclosure_labels() {
679 $disclosure_new_labels = apply_filters( $this->product->get_slug() . '_themeisle_sdk_disclosure_content_labels', [], $this->product );
680 $disclosure_labels = array_merge(
681 [
682 'title' => Loader::$labels['uninstall']['disclosure']['title'],
683 'items' => [
684 sprintf( Loader::$labels['uninstall']['disclosure']['version'], '<strong>', ucwords( $this->product->get_type() ), '</strong>', '<code>', $this->product->get_version(), '</code>' ),
685 sprintf( Loader::$labels['uninstall']['disclosure']['website'], '<strong>', '</strong>', '<code>', get_site_url(), '</code>' ),
686 sprintf( Loader::$labels['uninstall']['disclosure']['usage'], '<strong>', '</strong>', '<code>', ( time() - $this->product->get_install_time() ), 's</code>' ),
687 sprintf( Loader::$labels['uninstall']['disclosure']['reason'], '<strong>', '</strong>', '<i>', '</i>' ),
688 ],
689 ],
690 $disclosure_new_labels
691 );
692
693 $info_disclosure_content = '<div class="info-disclosure-content"><p>' . wp_kses_post( $disclosure_labels['title'] ) . '</p><ul>';
694 foreach ( $disclosure_labels['items'] as $disclosure_item ) {
695 $info_disclosure_content .= sprintf( '<li>%s</li>', wp_kses_post( $disclosure_item ) );
696 }
697 $info_disclosure_content .= '</ul></div>';
698
699 return $info_disclosure_content;
700 }
701
702 /**
703 * Randomizes the options array.
704 *
705 * @param array $options The options array.
706 */
707 public function randomize_options( $options ) {
708 $new = array();
709 $keys = array_keys( $options );
710 shuffle( $keys );
711
712 foreach ( $keys as $key ) {
713 $new[ $key ] = $options[ $key ];
714 }
715
716 return $new;
717 }
718
719 /**
720 * Called when the deactivate button is clicked.
721 */
722 public function post_deactivate() {
723 check_ajax_referer( (string) __CLASS__, 'nonce' );
724
725 $this->post_deactivate_or_cancel();
726
727 if ( empty( $_POST['id'] ) ) {
728
729 wp_send_json( [] );
730
731 return;
732 }
733 $this->call_api(
734 array(
735 'type' => 'deactivate',
736 'id' => sanitize_key( $_POST['id'] ),
737 'comment' => isset( $_POST['msg'] ) ? sanitize_textarea_field( $_POST['msg'] ) : '',
738 )
739 );
740 wp_send_json( [] );
741
742 }
743
744 /**
745 * Called when the deactivate/cancel button is clicked.
746 */
747 private function post_deactivate_or_cancel() {
748 if ( ! isset( $_POST['type'] ) || ! isset( $_POST['key'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function.
749 return;
750 }
751 if ( 'theme' !== $_POST['type'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function.
752 return;
753 }
754
755 set_transient( 'ti_sdk_pause_' . sanitize_text_field( $_POST['key'] ), true, self::PAUSE_DEACTIVATE_WINDOW_DAYS * DAY_IN_SECONDS );//phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function.
756
757 }
758
759 /**
760 * Calls the API
761 *
762 * @param array $attributes The attributes of the post body.
763 *
764 * @return bool Is the request succesfull?
765 */
766 protected function call_api( $attributes ) {
767 $slug = $this->product->get_slug();
768 $version = $this->product->get_version();
769 $attributes['slug'] = $slug;
770 $attributes['version'] = $version;
771 $attributes['url'] = get_site_url();
772 $attributes['active_time'] = ( time() - $this->product->get_install_time() );
773
774 $response = wp_remote_post(
775 self::FEEDBACK_ENDPOINT,
776 array(
777 'body' => $attributes,
778 )
779 );
780
781 return is_wp_error( $response );
782 }
783
784 /**
785 * Should we load this object?.
786 *
787 * @param Product $product Product object.
788 *
789 * @return bool Should we load the module?
790 */
791 public function can_load( $product ) {
792 if ( $this->is_from_partner( $product ) ) {
793 return false;
794 }
795 if ( $product->is_theme() && ( false !== get_transient( 'ti_sdk_pause_' . $product->get_key(), false ) ) ) {
796 return false;
797 }
798
799 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
800 return true;
801 }
802 global $pagenow;
803
804 if ( ! isset( $pagenow ) || empty( $pagenow ) ) {
805 return false;
806 }
807
808 if ( $product->is_plugin() && 'plugins.php' !== $pagenow ) {
809 return false;
810
811 }
812 if ( $product->is_theme() && 'theme-install.php' !== $pagenow ) {
813 return false;
814 }
815
816 return true;
817 }
818
819 /**
820 * Loads module hooks.
821 *
822 * @param Product $product Product details.
823 *
824 * @return Uninstall_Feedback Current module instance.
825 */
826 public function load( $product ) {
827
828 if ( apply_filters( $product->get_key() . '_hide_uninstall_feedback', false ) ) {
829 return;
830 }
831
832 $this->product = $product;
833 add_action( 'admin_head', array( $this, 'load_resources' ) );
834 add_action( 'wp_ajax_' . $this->product->get_key() . '_uninstall_feedback', array( $this, 'post_deactivate' ) );
835
836 return $this;
837 }
838 }
839