| 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 |
// Exit if accessed directly. |
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
if ( ! class_exists( 'ThemeIsle_SDK_Feedback_Deactivate' ) ) : |
| 16 |
/** |
| 17 |
* Deactivate feedback model for ThemeIsle SDK. |
| 18 |
*/ |
| 19 |
class ThemeIsle_SDK_Feedback_Deactivate extends ThemeIsle_SDK_Feedback { |
| 20 |
|
| 21 |
/** |
| 22 |
* @var array $options The main options list |
| 23 |
*/ |
| 24 |
private $options = array( |
| 25 |
'I only needed the plugin for a short period' => array( |
| 26 |
'id' => 1, |
| 27 |
), |
| 28 |
'The plugin broke my site' => array( |
| 29 |
'id' => 2, |
| 30 |
), |
| 31 |
'I found a better plugin' => array( |
| 32 |
'id' => 3, |
| 33 |
'type' => 'text', |
| 34 |
'placeholder' => 'What\'s the plugin\'s name?', |
| 35 |
), |
| 36 |
'The plugin suddenly stopped working' => array( |
| 37 |
'id' => 4, |
| 38 |
), |
| 39 |
'I no longer need the plugin' => array( |
| 40 |
'id' => 5, |
| 41 |
'type' => 'textarea', |
| 42 |
'placeholder' => 'If you could improve one thing about our product, what would it be?', |
| 43 |
), |
| 44 |
'It\'s a temporary deactivation. I\'m just debugging an issue.' => array( |
| 45 |
'id' => 6, |
| 46 |
), |
| 47 |
); |
| 48 |
|
| 49 |
/** |
| 50 |
* @var array $other The other option |
| 51 |
*/ |
| 52 |
private $other = array( |
| 53 |
'Other' => array( |
| 54 |
'id' => 999, |
| 55 |
'type' => 'textarea', |
| 56 |
'placeholder' => 'cmon cmon tell us', |
| 57 |
), |
| 58 |
); |
| 59 |
|
| 60 |
/** |
| 61 |
* @var string $heading The heading of the modal |
| 62 |
*/ |
| 63 |
private $heading = 'If you have a moment, please let us know why you are deactivating:'; |
| 64 |
|
| 65 |
/** |
| 66 |
* @var string $button_submit_before The text of the deactivate button before an option is chosen |
| 67 |
*/ |
| 68 |
private $button_submit_before = 'Skip & Deactivate'; |
| 69 |
|
| 70 |
/** |
| 71 |
* @var string $button_submit The text of the deactivate button |
| 72 |
*/ |
| 73 |
private $button_submit = 'Submit & Deactivate'; |
| 74 |
|
| 75 |
/** |
| 76 |
* @var string $button_cancel The text of the cancel button |
| 77 |
*/ |
| 78 |
private $button_cancel = 'Cancel'; |
| 79 |
|
| 80 |
/** |
| 81 |
* ThemeIsle_SDK_Feedback_Deactivate constructor. |
| 82 |
* |
| 83 |
* @param ThemeIsle_SDK_Product $product_object The product object. |
| 84 |
*/ |
| 85 |
public function __construct( $product_object ) { |
| 86 |
parent::__construct( $product_object ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Registers the hooks |
| 91 |
*/ |
| 92 |
public function setup_hooks_child() { |
| 93 |
global $pagenow; |
| 94 |
if ( 'plugins.php' === $pagenow ) { |
| 95 |
add_action( 'admin_head', array( $this, 'load_resources' ) ); |
| 96 |
} |
| 97 |
add_action( 'wp_ajax_' . $this->product->get_key() . __CLASS__, array( $this, 'post_deactivate' ) ); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Loads the additional resources |
| 102 |
*/ |
| 103 |
function load_resources() { |
| 104 |
add_thickbox(); |
| 105 |
|
| 106 |
$id = $this->product->get_key() . '_deactivate'; |
| 107 |
|
| 108 |
$this->add_css( $this->product->get_key() ); |
| 109 |
$this->add_js( $this->product->get_key(), '#TB_inline?' . apply_filters( $this->product->get_key() . '_feedback_deactivate_attributes', 'width=600&height=550' ) . '&inlineId=' . $id ); |
| 110 |
|
| 111 |
echo '<div id="' . $id . '" style="display:none;" class="themeisle-deactivate-box">' . $this->get_html( $this->product->get_key() ) . '</div>'; |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Loads the css |
| 116 |
* |
| 117 |
* @param string $key The product key. |
| 118 |
*/ |
| 119 |
function add_css( $key ) { |
| 120 |
?> |
| 121 |
<style type="text/css" id="<?php echo $key; ?>ti-deactivate-css"> |
| 122 |
input[name="ti-deactivate-option"] ~ div { |
| 123 |
display: none; |
| 124 |
} |
| 125 |
|
| 126 |
input[name="ti-deactivate-option"]:checked ~ div { |
| 127 |
display: block; |
| 128 |
} |
| 129 |
|
| 130 |
body.plugins-php .<?php echo $key; ?>-container #TB_window.thickbox-loading:before { |
| 131 |
background: none !important; |
| 132 |
} |
| 133 |
|
| 134 |
body.plugins-php .<?php echo $key; ?>-container #TB_title { |
| 135 |
font-size: 21px; |
| 136 |
padding: 20px 0; |
| 137 |
background-color: #f3f3f3; |
| 138 |
} |
| 139 |
|
| 140 |
body.plugins-php .<?php echo $key; ?>-container div.actions { |
| 141 |
padding: 20px 0; |
| 142 |
background-color: #f3f3f3; |
| 143 |
border-top: 1px solid #dddddd; |
| 144 |
} |
| 145 |
|
| 146 |
body.plugins-php .<?php echo $key; ?>-container input.button.button-primary { |
| 147 |
margin-right: 20px; |
| 148 |
} |
| 149 |
|
| 150 |
body.plugins-php .<?php echo $key; ?>-container input.button { |
| 151 |
margin-right: 20px; |
| 152 |
} |
| 153 |
|
| 154 |
body.plugins-php .<?php echo $key; ?>-container #TB_ajaxWindowTitle { |
| 155 |
text-align: left; |
| 156 |
margin-left: 15px; |
| 157 |
} |
| 158 |
|
| 159 |
body.plugins-php .<?php echo $key; ?>-container div.revive_network-container { |
| 160 |
background-color: #ffffff; |
| 161 |
} |
| 162 |
|
| 163 |
body.plugins-php .<?php echo $key; ?>-container ul.ti-list li { |
| 164 |
font-size: 14px; |
| 165 |
} |
| 166 |
|
| 167 |
body.plugins-php .<?php echo $key; ?>-container ul.ti-list li label { |
| 168 |
margin-left: 10px; |
| 169 |
line-height: 32px; |
| 170 |
font-size: 16px; |
| 171 |
} |
| 172 |
|
| 173 |
body.plugins-php .<?php echo $key; ?>-container #TB_ajaxContent { |
| 174 |
padding: 10px 20px; |
| 175 |
} |
| 176 |
|
| 177 |
body.plugins-php .<?php echo $key; ?>-container li div textarea { |
| 178 |
padding: 10px 15px; |
| 179 |
width: 100%; |
| 180 |
} |
| 181 |
|
| 182 |
body.plugins-php .<?php echo $key; ?>-container ul.ti-list li div { |
| 183 |
margin: 10px 30px; |
| 184 |
} |
| 185 |
|
| 186 |
.<?php echo $key; ?>-container #TB_title #TB_ajaxWindowTitle { |
| 187 |
display: block; |
| 188 |
} |
| 189 |
|
| 190 |
body.plugins-php .<?php echo $key; ?>-container .actions { |
| 191 |
|
| 192 |
width: 100%; |
| 193 |
display: block; |
| 194 |
position: absolute; |
| 195 |
left: 0px; |
| 196 |
bottom: 0px; |
| 197 |
text-align: right; |
| 198 |
} |
| 199 |
|
| 200 |
body.plugins-php .<?php echo $key; ?>-container #TB_title { |
| 201 |
|
| 202 |
height: 33px; |
| 203 |
width: 100%; |
| 204 |
text-align: center; |
| 205 |
} |
| 206 |
|
| 207 |
body.plugins-php .<?php echo $key; ?>-container { |
| 208 |
|
| 209 |
margin: auto !important; |
| 210 |
height: 550px !important; |
| 211 |
top: 0 !important; |
| 212 |
left: 0 !important; |
| 213 |
bottom: 0 !important; |
| 214 |
right: 0 !important; |
| 215 |
} |
| 216 |
</style> |
| 217 |
<?php |
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* Loads the js |
| 222 |
* |
| 223 |
* @param string $key The product key. |
| 224 |
* @param string $src The url that will hijack the deactivate button url. |
| 225 |
*/ |
| 226 |
function add_js( $key, $src ) { |
| 227 |
|
| 228 |
$heading = apply_filters( $this->product->get_key() . '_feedback_deactivate_heading', $this->heading ); |
| 229 |
?> |
| 230 |
<script type="text/javascript" id="ti-deactivate-js"> |
| 231 |
(function ($) { |
| 232 |
$(document).ready(function () { |
| 233 |
|
| 234 |
var href = $('tr[data-plugin^="<?php echo $this->product->get_slug();?>/"] span.deactivate a').attr('href'); |
| 235 |
$('#<?php echo $key;?>ti-deactivate-no').on('click', function (e) { |
| 236 |
e.preventDefault(); |
| 237 |
e.stopPropagation(); |
| 238 |
$('body').unbind('thickbox:removed'); |
| 239 |
tb_remove(); |
| 240 |
}); |
| 241 |
|
| 242 |
$('#<?php echo $key;?> ul.ti-list label, #<?php echo $key;?> ul.ti-list input[name="ti-deactivate-option"]').on('click', function (e) { |
| 243 |
$('#<?php echo $key;?>ti-deactivate-yes').val($('#<?php echo $key;?>ti-deactivate-yes').attr('data-after-text')); |
| 244 |
|
| 245 |
var radio = $(this).prop('tagName') === 'LABEL' ? $(this).parent() : $(this); |
| 246 |
if (radio.parent().find('textarea').length > 0 && radio.parent().find('textarea').val().length === 0) { |
| 247 |
$('#<?php echo $key;?>ti-deactivate-yes').attr('disabled', 'disabled'); |
| 248 |
radio.parent().find('textarea').on('keyup', function (ee) { |
| 249 |
if ($(this).val().length === 0) { |
| 250 |
$('#<?php echo $key;?>ti-deactivate-yes').attr('disabled', 'disabled'); |
| 251 |
} else { |
| 252 |
$('#<?php echo $key;?>ti-deactivate-yes').removeAttr('disabled'); |
| 253 |
} |
| 254 |
}); |
| 255 |
} else { |
| 256 |
$('#<?php echo $key;?>ti-deactivate-yes').removeAttr('disabled'); |
| 257 |
} |
| 258 |
}); |
| 259 |
|
| 260 |
$('#<?php echo $key;?>ti-deactivate-yes').attr('data-ti-action', href).on('click', function (e) { |
| 261 |
e.preventDefault(); |
| 262 |
e.stopPropagation(); |
| 263 |
$.ajax({ |
| 264 |
url: ajaxurl, |
| 265 |
method: 'post', |
| 266 |
data: { |
| 267 |
'action': '<?php echo $key . __CLASS__;?>', |
| 268 |
'nonce': '<?php echo wp_create_nonce( (string) __CLASS__ );?>', |
| 269 |
'id': $('#<?php echo $key;?> input[name="ti-deactivate-option"]:checked').parent().attr('ti-option-id'), |
| 270 |
'msg': $('#<?php echo $key;?> input[name="ti-deactivate-option"]:checked').parent().find('textarea').val() |
| 271 |
}, |
| 272 |
}); |
| 273 |
location.href = $(this).attr('data-ti-action'); |
| 274 |
}); |
| 275 |
$('tr[data-plugin^="<?php echo $this->product->get_slug();?>/"] span.deactivate a').attr('name', '<?php echo esc_html( $heading ); ?>').attr('href', '<?php echo $src;?>').addClass('thickbox'); |
| 276 |
var thicbox_timer; |
| 277 |
$('tr[data-plugin^="<?php echo $this->product->get_slug();?>/"] span.deactivate a').on('click', function () { |
| 278 |
tiBindThickbox(); |
| 279 |
}); |
| 280 |
|
| 281 |
function tiBindThickbox() { |
| 282 |
var thicbox_timer = setTimeout(function () { |
| 283 |
if ($("#<?php echo esc_html( $key ); ?>").is(":visible")) { |
| 284 |
$("body").trigger('thickbox:iframe:loaded'); |
| 285 |
$("#TB_window").addClass("<?php echo $key; ?>-container"); |
| 286 |
clearTimeout(thicbox_timer); |
| 287 |
$('body').unbind('thickbox:removed'); |
| 288 |
} else { |
| 289 |
tiBindThickbox(); |
| 290 |
} |
| 291 |
}, 100); |
| 292 |
} |
| 293 |
}); |
| 294 |
})(jQuery); |
| 295 |
</script> |
| 296 |
<?php |
| 297 |
} |
| 298 |
|
| 299 |
/** |
| 300 |
* Generates the HTML |
| 301 |
* |
| 302 |
* @param string $key The product key. |
| 303 |
*/ |
| 304 |
function get_html( $key ) { |
| 305 |
$options = $this->randomize_options( apply_filters( $this->product->get_key() . '_feedback_deactivate_options', $this->options ) ); |
| 306 |
$button_submit_before = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_submit_before', $this->button_submit_before ); |
| 307 |
$button_submit = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_submit', $this->button_submit ); |
| 308 |
$button_cancel = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_cancel', $this->button_cancel ); |
| 309 |
|
| 310 |
$options += $this->other; |
| 311 |
|
| 312 |
$list = ''; |
| 313 |
foreach ( $options as $title => $attributes ) { |
| 314 |
$id = $attributes['id']; |
| 315 |
$list .= '<li ti-option-id="' . $id . '"><input type="radio" name="ti-deactivate-option" id="' . $key . $id . '"><label for="' . $key . $id . '">' . __( $title ) . '</label>'; |
| 316 |
if ( array_key_exists( 'type', $attributes ) ) { |
| 317 |
$list .= '<div>'; |
| 318 |
$placeholder = array_key_exists( 'placeholder', $attributes ) ? __( $attributes['placeholder'] ) : ''; |
| 319 |
switch ( $attributes['type'] ) { |
| 320 |
case 'text': |
| 321 |
$list .= '<textarea style="width: 100%" rows="1" name="comments" placeholder="' . $placeholder . '"></textarea>'; |
| 322 |
break; |
| 323 |
case 'textarea': |
| 324 |
$list .= '<textarea style="width: 100%" rows="2" name="comments" placeholder="' . $placeholder . '"></textarea>'; |
| 325 |
break; |
| 326 |
} |
| 327 |
$list .= '</div>'; |
| 328 |
} |
| 329 |
$list .= '</li>'; |
| 330 |
} |
| 331 |
|
| 332 |
return '<div id="' . $this->product->get_key() . '">' |
| 333 |
. '<ul class="ti-list">' . $list . '</ul>' |
| 334 |
. '<div class="actions">' |
| 335 |
. get_submit_button( __( $button_submit_before ), 'secondary', $this->product->get_key() . 'ti-deactivate-yes', false, array( |
| 336 |
'data-after-text' => $button_submit, |
| 337 |
) ) |
| 338 |
. get_submit_button( __( $button_cancel ), 'primary', $this->product->get_key() . 'ti-deactivate-no', false ) |
| 339 |
. '</div></div>'; |
| 340 |
} |
| 341 |
|
| 342 |
/** |
| 343 |
* Called when the deactivate button is clicked |
| 344 |
*/ |
| 345 |
function post_deactivate() { |
| 346 |
check_ajax_referer( (string) __CLASS__, 'nonce' ); |
| 347 |
|
| 348 |
if ( ! empty( $_POST['id'] ) ) { |
| 349 |
$this->call_api( array( |
| 350 |
'type' => 'deactivate', |
| 351 |
'id' => $_POST['id'], |
| 352 |
'comment' => isset( $_POST['msg'] ) ? $_POST['msg'] : '', |
| 353 |
) ); |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
endif; |
| 358 |
|