templates-patterns-collection
/
vendor
/
codeinwp
/
themeisle-sdk
/
src
/
Modules
/
Uninstall_feedback.php
About_us.php
3 weeks ago
Abstract_Migration.php
2 months ago
Announcements.php
2 months ago
Compatibilities.php
2 years ago
Dashboard_widget.php
3 weeks ago
Featured_plugins.php
1 month ago
Float_widget.php
1 year ago
Licenser.php
2 months ago
Logger.php
10 months ago
Migrator.php
2 months ago
Notification.php
3 years ago
Promotions.php
3 weeks ago
Recommendation.php
3 years ago
Review.php
1 year ago
Rollback.php
1 year ago
Script_loader.php
1 year ago
Translate.php
5 years ago
Translations.php
1 year ago
Uninstall_feedback.php
2 days ago
Welcome.php
2 years ago
Uninstall_feedback.php
855 lines
| 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 | <?php $this->do_popup_header_after_heading_action( 'theme' ); ?> |
| 144 | <button class="toggle"><span>×</span></button> |
| 145 | </div><!--/.popup--header--> |
| 146 | <div class="popup--body"> |
| 147 | <?php $this->render_options_list( $options ); ?> |
| 148 | </div><!--/.popup--body--> |
| 149 | <div class="popup--footer"> |
| 150 | <div class="actions"> |
| 151 | <?php |
| 152 | echo wp_kses_post( $info_disclosure_link ); |
| 153 | echo wp_kses_post( $this->get_disclosure_labels() ); |
| 154 | echo '<div class="buttons">'; |
| 155 | echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function has an internal sanitization. |
| 156 | $button_submit, |
| 157 | 'secondary', |
| 158 | $this->product->get_key() . 'ti-deactivate-yes', |
| 159 | false, |
| 160 | array( |
| 161 | 'data-after-text' => $button_submit, |
| 162 | 'disabled' => true, |
| 163 | ) |
| 164 | ); |
| 165 | echo '</div>'; |
| 166 | ?> |
| 167 | </div><!--/.actions--> |
| 168 | </div><!--/.popup--footer--> |
| 169 | </div> |
| 170 | <?php |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Add feedback styles. |
| 175 | */ |
| 176 | private function add_feedback_popup_style() { |
| 177 | ?> |
| 178 | <style> |
| 179 | .ti-feedback { |
| 180 | background: #fff; |
| 181 | max-width: 400px; |
| 182 | z-index: 10000; |
| 183 | box-shadow: 0 0 15px -5px rgba(0, 0, 0, .5); |
| 184 | transition: all .3s ease-out; |
| 185 | } |
| 186 | |
| 187 | |
| 188 | .ti-feedback .popup--header { |
| 189 | position: relative; |
| 190 | background-color: #23A1CE; |
| 191 | } |
| 192 | |
| 193 | .ti-feedback .popup--header h5 { |
| 194 | margin: 0; |
| 195 | font-size: 16px; |
| 196 | padding: 15px; |
| 197 | color: #fff; |
| 198 | font-weight: 600; |
| 199 | text-align: center; |
| 200 | letter-spacing: .3px; |
| 201 | } |
| 202 | |
| 203 | .ti-feedback .popup--body { |
| 204 | padding: 15px; |
| 205 | } |
| 206 | |
| 207 | .ti-feedback .popup--form { |
| 208 | margin: 0; |
| 209 | font-size: 13px; |
| 210 | } |
| 211 | |
| 212 | .ti-feedback .popup--form input[type="radio"] { |
| 213 | <?php echo is_rtl() ? 'margin: 0 0 0 10px;' : 'margin: 0 10px 0 0;'; ?> |
| 214 | } |
| 215 | |
| 216 | .ti-feedback .popup--form input[type="radio"]:checked ~ textarea { |
| 217 | display: block; |
| 218 | } |
| 219 | |
| 220 | .ti-feedback .popup--form textarea { |
| 221 | width: 100%; |
| 222 | margin: 10px 0 0; |
| 223 | display: none; |
| 224 | max-height: 150px; |
| 225 | } |
| 226 | |
| 227 | .ti-feedback li { |
| 228 | display: flex; |
| 229 | align-items: center; |
| 230 | margin-bottom: 15px; |
| 231 | flex-wrap: wrap; |
| 232 | } |
| 233 | |
| 234 | .ti-feedback li label { |
| 235 | max-width: 90%; |
| 236 | } |
| 237 | |
| 238 | .ti-feedback li:last-child { |
| 239 | margin-bottom: 0; |
| 240 | } |
| 241 | |
| 242 | .ti-feedback .popup--footer { |
| 243 | padding: 0 15px 15px; |
| 244 | } |
| 245 | |
| 246 | .ti-feedback .actions { |
| 247 | display: flex; |
| 248 | flex-wrap: wrap; |
| 249 | } |
| 250 | |
| 251 | .info-disclosure-link { |
| 252 | width: 100%; |
| 253 | margin-bottom: 15px; |
| 254 | } |
| 255 | |
| 256 | .ti-feedback .info-disclosure-content { |
| 257 | max-height: 0; |
| 258 | overflow: hidden; |
| 259 | width: 100%; |
| 260 | transition: .3s ease; |
| 261 | } |
| 262 | |
| 263 | .ti-feedback .info-disclosure-content.active { |
| 264 | max-height: 300px; |
| 265 | } |
| 266 | |
| 267 | .ti-feedback .info-disclosure-content p { |
| 268 | margin: 0; |
| 269 | } |
| 270 | |
| 271 | .ti-feedback .info-disclosure-content ul { |
| 272 | margin: 10px 0; |
| 273 | border-radius: 3px; |
| 274 | } |
| 275 | |
| 276 | .ti-feedback .info-disclosure-content ul li { |
| 277 | display: flex; |
| 278 | align-items: center; |
| 279 | justify-content: space-between; |
| 280 | margin-bottom: 0; |
| 281 | padding: 5px 0; |
| 282 | border-bottom: 1px solid #ccc; |
| 283 | } |
| 284 | |
| 285 | .ti-feedback .buttons { |
| 286 | display: flex; |
| 287 | width: 100%; |
| 288 | } |
| 289 | |
| 290 | .ti-feedback .buttons input:last-child { |
| 291 | <?php echo is_rtl() ? 'margin-right: auto;' : 'margin-left: auto;'; ?> |
| 292 | } |
| 293 | |
| 294 | .ti-theme-uninstall-feedback-drawer { |
| 295 | border-top-left-radius: 5px; |
| 296 | position: fixed; |
| 297 | top: 100%; |
| 298 | right: 15px; |
| 299 | } |
| 300 | |
| 301 | .ti-theme-uninstall-feedback-drawer.active { |
| 302 | transform: translateY(-100%); |
| 303 | } |
| 304 | |
| 305 | .ti-theme-uninstall-feedback-drawer .popup--header { |
| 306 | border-top-left-radius: 5px; |
| 307 | } |
| 308 | |
| 309 | .ti-theme-uninstall-feedback-drawer .popup--header .toggle { |
| 310 | position: absolute; |
| 311 | padding: 3px 0; |
| 312 | width: 30px; |
| 313 | top: -26px; |
| 314 | right: 0; |
| 315 | cursor: pointer; |
| 316 | border-top-left-radius: 5px; |
| 317 | border-top-right-radius: 5px; |
| 318 | font-size: 20px; |
| 319 | background-color: #23A1CE; |
| 320 | color: #fff; |
| 321 | border: none; |
| 322 | line-height: 20px; |
| 323 | } |
| 324 | |
| 325 | .ti-theme-uninstall-feedback-drawer .toggle span { |
| 326 | margin: 0; |
| 327 | display: inline-block; |
| 328 | } |
| 329 | |
| 330 | .ti-theme-uninstall-feedback-drawer:not(.active) .toggle span { |
| 331 | transform: rotate(45deg); |
| 332 | } |
| 333 | |
| 334 | .ti-theme-uninstall-feedback-drawer .popup--header .toggle:hover { |
| 335 | background-color: #1880a5; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | .ti-plugin-uninstall-feedback-popup .popup--header:before { |
| 340 | content: ""; |
| 341 | display: block; |
| 342 | position: absolute; |
| 343 | top: 50%; |
| 344 | transform: translateY(-50%); |
| 345 | <?php |
| 346 | echo is_rtl() ? |
| 347 | 'right: -10px; |
| 348 | border-top: 20px solid transparent; |
| 349 | border-left: 20px solid #23A1CE; |
| 350 | border-bottom: 20px solid transparent;' : |
| 351 | 'left: -10px; |
| 352 | border-top: 20px solid transparent; |
| 353 | border-right: 20px solid #23A1CE; |
| 354 | border-bottom: 20px solid transparent;'; |
| 355 | ?> |
| 356 | } |
| 357 | |
| 358 | .ti-plugin-uninstall-feedback-popup { |
| 359 | display: none; |
| 360 | position: absolute; |
| 361 | white-space: normal; |
| 362 | width: 400px; |
| 363 | <?php echo is_rtl() ? 'right: calc( 100% + 15px );' : 'left: calc( 100% + 15px );'; ?> top: -15px; |
| 364 | } |
| 365 | |
| 366 | .ti-plugin-uninstall-feedback-popup.sending-feedback .popup--body i { |
| 367 | animation: rotation 2s infinite linear; |
| 368 | display: block; |
| 369 | float: none; |
| 370 | align-items: center; |
| 371 | width: 100%; |
| 372 | margin: 0 auto; |
| 373 | height: 100%; |
| 374 | background: transparent; |
| 375 | padding: 0; |
| 376 | } |
| 377 | |
| 378 | .ti-plugin-uninstall-feedback-popup.sending-feedback .popup--body i:before { |
| 379 | padding: 0; |
| 380 | background: transparent; |
| 381 | box-shadow: none; |
| 382 | color: #b4b9be |
| 383 | } |
| 384 | |
| 385 | |
| 386 | .ti-plugin-uninstall-feedback-popup.active { |
| 387 | display: block; |
| 388 | } |
| 389 | |
| 390 | tr[data-plugin^="<?php echo esc_attr( $this->product->get_slug() ); ?>"] .deactivate { |
| 391 | position: relative; |
| 392 | } |
| 393 | |
| 394 | body.ti-feedback-open .ti-feedback-overlay { |
| 395 | content: ""; |
| 396 | display: block; |
| 397 | background-color: rgba(0, 0, 0, 0.5); |
| 398 | top: 0; |
| 399 | bottom: 0; |
| 400 | right: 0; |
| 401 | left: 0; |
| 402 | z-index: 10000; |
| 403 | position: fixed; |
| 404 | } |
| 405 | |
| 406 | @media (max-width: 768px) { |
| 407 | .ti-plugin-uninstall-feedback-popup { |
| 408 | position: fixed; |
| 409 | max-width: 100%; |
| 410 | margin: 0 auto; |
| 411 | left: 50%; |
| 412 | top: 50px; |
| 413 | transform: translateX(-50%); |
| 414 | } |
| 415 | |
| 416 | .ti-plugin-uninstall-feedback-popup .popup--header:before { |
| 417 | display: none; |
| 418 | } |
| 419 | } |
| 420 | </style> |
| 421 | <?php |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Theme feedback drawer JS. |
| 426 | */ |
| 427 | private function add_theme_feedback_drawer_js() { |
| 428 | $key = $this->product->get_key(); |
| 429 | ?> |
| 430 | <script type="text/javascript" id="ti-deactivate-js"> |
| 431 | (function ($) { |
| 432 | $(document).ready(function () { |
| 433 | setTimeout(function () { |
| 434 | $('.ti-theme-uninstall-feedback-drawer').addClass('active'); |
| 435 | }, <?php echo absint( self::AUTO_TRIGGER_DEACTIVATE_WINDOW_SECONDS * 1000 ); ?> ); |
| 436 | |
| 437 | $('.ti-theme-uninstall-feedback-drawer .toggle').on('click', function (e) { |
| 438 | e.preventDefault(); |
| 439 | $('.ti-theme-uninstall-feedback-drawer').toggleClass('active'); |
| 440 | }); |
| 441 | |
| 442 | $('.info-disclosure-link').on('click', function (e) { |
| 443 | e.preventDefault(); |
| 444 | $('.info-disclosure-content').toggleClass('active'); |
| 445 | }); |
| 446 | |
| 447 | $('.ti-theme-uninstall-feedback-drawer input[type="radio"]').on('change', function () { |
| 448 | var radio = $(this); |
| 449 | if (radio.parent().find('textarea').length > 0 && |
| 450 | radio.parent().find('textarea').val().length === 0) { |
| 451 | $('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled'); |
| 452 | radio.parent().find('textarea').on('keyup', function (e) { |
| 453 | if ($(this).val().length === 0) { |
| 454 | $('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled'); |
| 455 | } else { |
| 456 | $('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled'); |
| 457 | } |
| 458 | }); |
| 459 | } else { |
| 460 | $('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled'); |
| 461 | } |
| 462 | }); |
| 463 | |
| 464 | $('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').on('click', function (e) { |
| 465 | e.preventDefault(); |
| 466 | e.stopPropagation(); |
| 467 | |
| 468 | var selectedOption = $( |
| 469 | '.ti-theme-uninstall-feedback-drawer input[name="ti-deactivate-option"]:checked'); |
| 470 | $.post(ajaxurl, { |
| 471 | 'action': '<?php echo esc_attr( $key ) . '_uninstall_feedback'; ?>', |
| 472 | 'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>', |
| 473 | 'id': selectedOption.parent().attr('ti-option-id'), |
| 474 | 'msg': selectedOption.parent().find('textarea').val(), |
| 475 | 'type': 'theme', |
| 476 | 'key': '<?php echo esc_attr( $key ); ?>' |
| 477 | }); |
| 478 | $('.ti-theme-uninstall-feedback-drawer').fadeOut(); |
| 479 | }); |
| 480 | }); |
| 481 | })(jQuery); |
| 482 | |
| 483 | </script> |
| 484 | <?php |
| 485 | do_action( $this->product->get_key() . '_uninstall_feedback_after_js' ); |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * Fires after the popup header heading, allowing products to output extra markup. |
| 490 | * |
| 491 | * @param string $context Popup context. Either `theme` or `plugin`. |
| 492 | */ |
| 493 | private function do_popup_header_after_heading_action( $context ) { |
| 494 | do_action( |
| 495 | $this->product->get_key() . '_uninstall_feedback_popup_header_after_heading', |
| 496 | $this->product, |
| 497 | $context |
| 498 | ); |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Render the options list. |
| 503 | * |
| 504 | * @param array $options the options for the feedback form. |
| 505 | */ |
| 506 | private function render_options_list( $options ) { |
| 507 | $key = $this->product->get_key(); |
| 508 | $inputs_row_map = [ |
| 509 | 'text' => 1, |
| 510 | 'textarea' => 2, |
| 511 | ]; |
| 512 | ?> |
| 513 | <ul class="popup--form"> |
| 514 | <?php |
| 515 | foreach ( $options as $idx => $attributes ) { |
| 516 | $title = Loader::$labels['uninstall']['options'][ $idx ]['title']; |
| 517 | $placeholder = array_key_exists( 'placeholder', Loader::$labels['uninstall']['options'][ $idx ] ) ? Loader::$labels['uninstall']['options'][ $idx ]['placeholder'] : ''; |
| 518 | ?> |
| 519 | <li ti-option-id="<?php echo esc_attr( $attributes['id'] ); ?>"> |
| 520 | <input type="radio" name="ti-deactivate-option" |
| 521 | id="<?php echo esc_attr( $key . $attributes['id'] ); ?>"> |
| 522 | <label for="<?php echo esc_attr( $key . $attributes['id'] ); ?>"> |
| 523 | <?php echo esc_attr( str_replace( '{theme}', $this->product->get_name(), $title ) ); ?> |
| 524 | </label> |
| 525 | <?php |
| 526 | if ( array_key_exists( 'type', $attributes ) ) { |
| 527 | |
| 528 | echo '<textarea width="100%" rows="' . esc_attr( $inputs_row_map[ $attributes['type'] ] ) . '" name="comments" placeholder="' . esc_attr( $placeholder ) . '"></textarea>'; |
| 529 | } |
| 530 | ?> |
| 531 | </li> |
| 532 | <?php } ?> |
| 533 | </ul> |
| 534 | <?php |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * Render plugin feedback popup. |
| 539 | */ |
| 540 | private function render_plugin_feedback_popup() { |
| 541 | $button_cancel = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_cancel', Loader::$labels['uninstall']['button_cancel'] ); |
| 542 | $button_submit = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_submit', Loader::$labels['uninstall']['button_submit'] ); |
| 543 | $options = $this->randomize_options( apply_filters( $this->product->get_key() . '_feedback_deactivate_options', $this->options_plugin ) ); |
| 544 | $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>'; |
| 545 | |
| 546 | $options += $this->other; |
| 547 | ?> |
| 548 | <div class="ti-plugin-uninstall-feedback-popup ti-feedback" |
| 549 | id="<?php echo esc_attr( $this->product->get_slug() . '_uninstall_feedback_popup' ); ?>"> |
| 550 | <div class="popup--header"> |
| 551 | <h5><?php echo wp_kses( Loader::$labels['uninstall']['heading_plugin'], array( 'span' => true ) ); ?> </h5> |
| 552 | <?php $this->do_popup_header_after_heading_action( 'plugin' ); ?> |
| 553 | </div><!--/.popup--header--> |
| 554 | <div class="popup--body"> |
| 555 | <?php $this->render_options_list( $options ); ?> |
| 556 | </div><!--/.popup--body--> |
| 557 | <div class="popup--footer"> |
| 558 | <div class="actions"> |
| 559 | <?php |
| 560 | echo wp_kses_post( $info_disclosure_link ); |
| 561 | echo wp_kses_post( $this->get_disclosure_labels() ); |
| 562 | echo '<div class="buttons">'; |
| 563 | echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function internals are escaped. |
| 564 | $button_cancel, |
| 565 | 'secondary', |
| 566 | $this->product->get_key() . 'ti-deactivate-no', |
| 567 | false |
| 568 | ); |
| 569 | echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function internals are escaped. |
| 570 | $button_submit, |
| 571 | 'primary', |
| 572 | $this->product->get_key() . 'ti-deactivate-yes', |
| 573 | false, |
| 574 | array( |
| 575 | 'data-after-text' => $button_submit, |
| 576 | 'disabled' => true, |
| 577 | ) |
| 578 | ); |
| 579 | echo '</div>'; |
| 580 | ?> |
| 581 | </div><!--/.actions--> |
| 582 | </div><!--/.popup--footer--> |
| 583 | </div> |
| 584 | |
| 585 | <?php |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Add plugin feedback popup JS |
| 590 | */ |
| 591 | private function add_plugin_feedback_popup_js() { |
| 592 | $popup_id = '#' . $this->product->get_slug() . '_uninstall_feedback_popup'; |
| 593 | $key = $this->product->get_key(); |
| 594 | ?> |
| 595 | <script type="text/javascript" id="ti-deactivate-js"> |
| 596 | (function ($) { |
| 597 | $(document).ready(function () { |
| 598 | var targetElement = 'tr[data-plugin^="<?php echo esc_attr( $this->product->get_slug() ); ?>/"] span.deactivate a'; |
| 599 | var $deactivateLink = $(targetElement); |
| 600 | var redirectUrl = $deactivateLink.attr('href'); |
| 601 | if ($('.ti-feedback-overlay').length === 0) { |
| 602 | $('body').prepend('<div class="ti-feedback-overlay"></div>'); |
| 603 | } |
| 604 | $('<?php echo esc_attr( $popup_id ); ?> ').appendTo($deactivateLink.parent()); |
| 605 | |
| 606 | $deactivateLink.on('click', function (e) { |
| 607 | e.preventDefault(); |
| 608 | $('<?php echo esc_attr( $popup_id ); ?> ').addClass('active'); |
| 609 | $('body').addClass('ti-feedback-open'); |
| 610 | $('.ti-feedback-overlay').on('click', function () { |
| 611 | $('<?php echo esc_attr( $popup_id ); ?> ').removeClass('active'); |
| 612 | $('body').removeClass('ti-feedback-open'); |
| 613 | }); |
| 614 | }); |
| 615 | |
| 616 | $('<?php echo esc_attr( $popup_id ); ?> .info-disclosure-link').on('click', function (e) { |
| 617 | e.preventDefault(); |
| 618 | $(this).parent().find('.info-disclosure-content').toggleClass('active'); |
| 619 | }); |
| 620 | |
| 621 | $('<?php echo esc_attr( $popup_id ); ?> input[type="radio"]').on('change', function () { |
| 622 | var radio = $(this); |
| 623 | if (radio.parent().find('textarea').length > 0 && |
| 624 | radio.parent().find('textarea').val().length === 0) { |
| 625 | $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled'); |
| 626 | radio.parent().find('textarea').on('keyup', function (e) { |
| 627 | if ($(this).val().length === 0) { |
| 628 | $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled'); |
| 629 | } else { |
| 630 | $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled'); |
| 631 | } |
| 632 | }); |
| 633 | } else { |
| 634 | $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled'); |
| 635 | } |
| 636 | }); |
| 637 | |
| 638 | $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-no').on('click', function (e) { |
| 639 | e.preventDefault(); |
| 640 | e.stopPropagation(); |
| 641 | $deactivateLink.unbind('click'); |
| 642 | $('body').removeClass('ti-feedback-open'); |
| 643 | $('<?php echo esc_attr( $popup_id ); ?>').remove(); |
| 644 | if (redirectUrl !== '') { |
| 645 | location.href = redirectUrl; |
| 646 | } |
| 647 | }); |
| 648 | |
| 649 | $('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').on('click', function (e) { |
| 650 | e.preventDefault(); |
| 651 | e.stopPropagation(); |
| 652 | $deactivateLink.unbind('click'); |
| 653 | var selectedOption = $( |
| 654 | '<?php echo esc_attr( $popup_id ); ?> input[name="ti-deactivate-option"]:checked'); |
| 655 | var data = { |
| 656 | 'action': '<?php echo esc_attr( $key ) . '_uninstall_feedback'; ?>', |
| 657 | 'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>', |
| 658 | 'id': selectedOption.parent().attr('ti-option-id'), |
| 659 | 'msg': selectedOption.parent().find('textarea').val(), |
| 660 | 'type': 'plugin', |
| 661 | 'key': '<?php echo esc_attr( $key ); ?>' |
| 662 | }; |
| 663 | $.ajax({ |
| 664 | type: 'POST', |
| 665 | url: ajaxurl, |
| 666 | data: data, |
| 667 | complete() { |
| 668 | $('body').removeClass('ti-feedback-open'); |
| 669 | $('<?php echo esc_attr( $popup_id ); ?>').remove(); |
| 670 | if (redirectUrl !== '') { |
| 671 | location.href = redirectUrl; |
| 672 | } |
| 673 | }, |
| 674 | beforeSend() { |
| 675 | $('<?php echo esc_attr( $popup_id ); ?>').addClass('sending-feedback'); |
| 676 | $('<?php echo esc_attr( $popup_id ); ?> .popup--footer').remove(); |
| 677 | $('<?php echo esc_attr( $popup_id ); ?> .popup--body').html('<i class="dashicons dashicons-update-alt"></i>'); |
| 678 | } |
| 679 | }); |
| 680 | }); |
| 681 | }); |
| 682 | })(jQuery); |
| 683 | |
| 684 | </script> |
| 685 | <?php |
| 686 | do_action( $this->product->get_key() . '_uninstall_feedback_after_js' ); |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * Get the disclosure labels markup. |
| 691 | * |
| 692 | * @return string |
| 693 | */ |
| 694 | private function get_disclosure_labels() { |
| 695 | $disclosure_new_labels = apply_filters( $this->product->get_slug() . '_themeisle_sdk_disclosure_content_labels', [], $this->product ); |
| 696 | $disclosure_labels = array_merge( |
| 697 | [ |
| 698 | 'title' => Loader::$labels['uninstall']['disclosure']['title'], |
| 699 | 'items' => [ |
| 700 | sprintf( Loader::$labels['uninstall']['disclosure']['version'], '<strong>', ucwords( $this->product->get_type() ), '</strong>', '<code>', $this->product->get_version(), '</code>' ), |
| 701 | sprintf( Loader::$labels['uninstall']['disclosure']['website'], '<strong>', '</strong>', '<code>', get_site_url(), '</code>' ), |
| 702 | sprintf( Loader::$labels['uninstall']['disclosure']['usage'], '<strong>', '</strong>', '<code>', ( time() - $this->product->get_install_time() ), 's</code>' ), |
| 703 | sprintf( Loader::$labels['uninstall']['disclosure']['reason'], '<strong>', '</strong>', '<i>', '</i>' ), |
| 704 | ], |
| 705 | ], |
| 706 | $disclosure_new_labels |
| 707 | ); |
| 708 | |
| 709 | $info_disclosure_content = '<div class="info-disclosure-content"><p>' . wp_kses_post( $disclosure_labels['title'] ) . '</p><ul>'; |
| 710 | foreach ( $disclosure_labels['items'] as $disclosure_item ) { |
| 711 | $info_disclosure_content .= sprintf( '<li>%s</li>', wp_kses_post( $disclosure_item ) ); |
| 712 | } |
| 713 | $info_disclosure_content .= '</ul></div>'; |
| 714 | |
| 715 | return $info_disclosure_content; |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * Randomizes the options array. |
| 720 | * |
| 721 | * @param array $options The options array. |
| 722 | */ |
| 723 | public function randomize_options( $options ) { |
| 724 | $new = array(); |
| 725 | $keys = array_keys( $options ); |
| 726 | shuffle( $keys ); |
| 727 | |
| 728 | foreach ( $keys as $key ) { |
| 729 | $new[ $key ] = $options[ $key ]; |
| 730 | } |
| 731 | |
| 732 | return $new; |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Called when the deactivate button is clicked. |
| 737 | */ |
| 738 | public function post_deactivate() { |
| 739 | check_ajax_referer( (string) __CLASS__, 'nonce' ); |
| 740 | |
| 741 | $this->post_deactivate_or_cancel(); |
| 742 | |
| 743 | if ( empty( $_POST['id'] ) ) { |
| 744 | |
| 745 | wp_send_json( [] ); |
| 746 | |
| 747 | return; |
| 748 | } |
| 749 | $this->call_api( |
| 750 | array( |
| 751 | 'type' => 'deactivate', |
| 752 | 'id' => sanitize_key( $_POST['id'] ), |
| 753 | 'comment' => isset( $_POST['msg'] ) ? sanitize_textarea_field( $_POST['msg'] ) : '', |
| 754 | ) |
| 755 | ); |
| 756 | wp_send_json( [] ); |
| 757 | |
| 758 | } |
| 759 | |
| 760 | /** |
| 761 | * Called when the deactivate/cancel button is clicked. |
| 762 | */ |
| 763 | private function post_deactivate_or_cancel() { |
| 764 | if ( ! isset( $_POST['type'] ) || ! isset( $_POST['key'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function. |
| 765 | return; |
| 766 | } |
| 767 | if ( 'theme' !== $_POST['type'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function. |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | 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. |
| 772 | |
| 773 | } |
| 774 | |
| 775 | /** |
| 776 | * Calls the API |
| 777 | * |
| 778 | * @param array $attributes The attributes of the post body. |
| 779 | * |
| 780 | * @return bool Is the request succesfull? |
| 781 | */ |
| 782 | protected function call_api( $attributes ) { |
| 783 | $slug = $this->product->get_slug(); |
| 784 | $version = $this->product->get_version(); |
| 785 | $attributes['slug'] = $slug; |
| 786 | $attributes['version'] = $version; |
| 787 | $attributes['url'] = get_site_url(); |
| 788 | $attributes['active_time'] = ( time() - $this->product->get_install_time() ); |
| 789 | |
| 790 | $response = wp_remote_post( |
| 791 | self::FEEDBACK_ENDPOINT, |
| 792 | array( |
| 793 | 'body' => $attributes, |
| 794 | ) |
| 795 | ); |
| 796 | |
| 797 | return is_wp_error( $response ); |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * Should we load this object?. |
| 802 | * |
| 803 | * @param Product $product Product object. |
| 804 | * |
| 805 | * @return bool Should we load the module? |
| 806 | */ |
| 807 | public function can_load( $product ) { |
| 808 | if ( $this->is_from_partner( $product ) ) { |
| 809 | return false; |
| 810 | } |
| 811 | if ( $product->is_theme() && ( false !== get_transient( 'ti_sdk_pause_' . $product->get_key(), false ) ) ) { |
| 812 | return false; |
| 813 | } |
| 814 | |
| 815 | if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 816 | return true; |
| 817 | } |
| 818 | global $pagenow; |
| 819 | |
| 820 | if ( ! isset( $pagenow ) || empty( $pagenow ) ) { |
| 821 | return false; |
| 822 | } |
| 823 | |
| 824 | if ( $product->is_plugin() && 'plugins.php' !== $pagenow ) { |
| 825 | return false; |
| 826 | |
| 827 | } |
| 828 | if ( $product->is_theme() && 'theme-install.php' !== $pagenow ) { |
| 829 | return false; |
| 830 | } |
| 831 | |
| 832 | return true; |
| 833 | } |
| 834 | |
| 835 | /** |
| 836 | * Loads module hooks. |
| 837 | * |
| 838 | * @param Product $product Product details. |
| 839 | * |
| 840 | * @return Uninstall_Feedback Current module instance. |
| 841 | */ |
| 842 | public function load( $product ) { |
| 843 | |
| 844 | if ( apply_filters( $product->get_key() . '_hide_uninstall_feedback', false ) ) { |
| 845 | return; |
| 846 | } |
| 847 | |
| 848 | $this->product = $product; |
| 849 | add_action( 'admin_head', array( $this, 'load_resources' ) ); |
| 850 | add_action( 'wp_ajax_' . $this->product->get_key() . '_uninstall_feedback', array( $this, 'post_deactivate' ) ); |
| 851 | |
| 852 | return $this; |
| 853 | } |
| 854 | } |
| 855 |