thickbox.php
281 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments - Libraries |
| 4 | * @subpackage html.feedback |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | $deactivate_url_js = !empty($displayData['url']) ? $displayData['url'] : '#'; |
| 15 | $is_pro = isset($displayData['pro']) ? $displayData['pro'] : false; |
| 16 | |
| 17 | $plain_deactivation_url = JUri::getInstance(); |
| 18 | $plain_deactivation_url->setVar('feedback', 0); |
| 19 | |
| 20 | $doc_url = 'https://vikwp.com/support/documentation/vik-appointments/'; |
| 21 | |
| 22 | $options = array(); |
| 23 | |
| 24 | $options[] = array( |
| 25 | 'value' => '0', |
| 26 | 'text' => __('No, thanks', 'vikappointments'), |
| 27 | 'checked' => true, |
| 28 | ); |
| 29 | |
| 30 | $wp = new JVersion(); |
| 31 | |
| 32 | if (version_compare($wp->getShortVersion(), '5.5', '>=')) |
| 33 | { |
| 34 | $options[] = array( |
| 35 | 'value' => 'The plugin is facing strange behaviors on WP 5.5', |
| 36 | 'text' => __('The plugin is facing strange behaviors on WP 5.5', 'vikappointments'), |
| 37 | 'help' => __('Have you tried to install <b>Enable jQuery Migrate Helper</b> plugin by WordPress Team? WordPress 5.5 update might have brought a few javascript issues, which should be solved by installing the mentioned plugin.', 'vikappointments'), |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | $options[] = array( |
| 42 | 'value' => 'The plugin is not working', |
| 43 | 'text' => __('The plugin is not working', 'vikappointments'), |
| 44 | 'notes' => true, |
| 45 | ); |
| 46 | |
| 47 | $options[] = array( |
| 48 | 'value' => 'The plugin didn\'t work as expected', |
| 49 | 'text' => __('The plugin didn\'t work as expected', 'vikappointments'), |
| 50 | 'notes' => true, |
| 51 | ); |
| 52 | |
| 53 | if (!$is_pro) |
| 54 | { |
| 55 | $options[] = array( |
| 56 | 'value' => 'The FREE version is too limited', |
| 57 | 'text' => __('The FREE version is too limited', 'vikappointments'), |
| 58 | 'notes' => array( |
| 59 | 'required' => false, |
| 60 | 'placeholder' => __('What feature would you like to use?', 'vikappointments'), |
| 61 | ), |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | $options[] = array( |
| 66 | 'value' => 'The plugin suddenly stopped working', |
| 67 | 'text' => __('The plugin suddenly stopped working', 'vikappointments'), |
| 68 | 'notes' => true, |
| 69 | ); |
| 70 | |
| 71 | $options[] = array( |
| 72 | 'value' => 'The plugin broke my site', |
| 73 | 'text' => __('The plugin broke my site', 'vikappointments'), |
| 74 | 'notes' => array( |
| 75 | 'placeholder' => __('Please, could you explain what happened?', 'vikappointments'), |
| 76 | ), |
| 77 | ); |
| 78 | |
| 79 | $options[] = array( |
| 80 | 'value' => 'I couldn\'t understand how to get it work', |
| 81 | 'text' => __('I couldn\'t understand how to get it work', 'vikappointments'), |
| 82 | 'help' => sprintf(__('Did you read the plugin documentation? You can find it <a href="%s" target="_blank">here</a>.', 'vikappointments'), $doc_url), |
| 83 | ); |
| 84 | |
| 85 | $options[] = array( |
| 86 | 'value' => 'I no longer need the plugin', |
| 87 | 'text' => __('I no longer need the plugin', 'vikappointments'), |
| 88 | ); |
| 89 | |
| 90 | $options[] = array( |
| 91 | 'value' => 'I\'m just debugging an issue', |
| 92 | 'text' => __('I\'m just debugging an issue', 'vikappointments'), |
| 93 | ); |
| 94 | |
| 95 | $options[] = array( |
| 96 | 'value' => 'I\'m not able to deactivate this plugin!', |
| 97 | 'text' => __('I\'m not able to deactivate this plugin!', 'vikappointments'), |
| 98 | 'help' => sprintf(__('In case you are experiencing some issues with the deactivation of this plugin, try to relaunch the page by appending <code>&feedback=0</code> to the URL. Otherwise just click <a href="%s">HERE</a>.', 'vikappointments'), (string) $plain_deactivation_url), |
| 99 | ); |
| 100 | |
| 101 | $options[] = array( |
| 102 | 'value' => 'Other', |
| 103 | 'text' => __('Other', 'vikappointments'), |
| 104 | 'notes' => array( |
| 105 | 'required' => true, |
| 106 | 'placeholder' => __('Please, provide us some information', 'vikappointments'), |
| 107 | ), |
| 108 | ); |
| 109 | |
| 110 | ?> |
| 111 | |
| 112 | <style> |
| 113 | .thickbox-loading { |
| 114 | height: auto !important; |
| 115 | } |
| 116 | #TB_ajaxContent { |
| 117 | width: calc(100% - 30px) !important; |
| 118 | height: calc(100% - 45px) !important; |
| 119 | } |
| 120 | .th-box-body { |
| 121 | height: calc(100% - 45px); |
| 122 | } |
| 123 | .th-box-footer { |
| 124 | text-align: right; |
| 125 | } |
| 126 | |
| 127 | .th-box-body div.form-field { |
| 128 | margin: 5px 0; |
| 129 | } |
| 130 | |
| 131 | .th-box-body blockquote { |
| 132 | color: #7f8fa4; |
| 133 | font-size: inherit; |
| 134 | padding: 8px 24px; |
| 135 | border-left: 4px solid #eaeaea; |
| 136 | background: #fff; |
| 137 | } |
| 138 | |
| 139 | textarea.invalid { |
| 140 | border: 1px solid #900; |
| 141 | } |
| 142 | </style> |
| 143 | |
| 144 | <div id="vikappointments-feedback" style="display: none;"> |
| 145 | |
| 146 | <div class="th-box-body"> |
| 147 | <h2><?php echo __('Feedback', 'vikappointments'); ?></h2> |
| 148 | <h3><?php echo __('If you have a moment, please let us know why you are deactivating.', 'vikappointments'); ?></h3> |
| 149 | |
| 150 | <form id="vap-feedback-form"> |
| 151 | |
| 152 | <?php |
| 153 | foreach ($options as $i => $opt) |
| 154 | { |
| 155 | ?> |
| 156 | <div class="form-field"> |
| 157 | <input |
| 158 | type="radio" |
| 159 | id="vap-feed-opt-<?php echo $i; ?>" |
| 160 | name="feedback_type" |
| 161 | value="<?php echo esc_attr($opt['value']); ?>" |
| 162 | <?php echo !empty($opt['checked']) ? 'checked="checked"' : ''; ?> |
| 163 | /> |
| 164 | <label for="vap-feed-opt-<?php echo $i; ?>"><?php echo $opt['text']; ?></label> |
| 165 | |
| 166 | <?php |
| 167 | if (!empty($opt['help'])) |
| 168 | { |
| 169 | ?> |
| 170 | <blockquote |
| 171 | class="feedback-help" |
| 172 | style="<?php echo !empty($opt['checked']) ? '' : 'display:none;'; ?>" |
| 173 | > |
| 174 | <?php echo $opt['help']; ?> |
| 175 | </blockquote> |
| 176 | <?php |
| 177 | } |
| 178 | |
| 179 | if (!empty($opt['notes'])) |
| 180 | { |
| 181 | $opt['notes'] = (array) $opt['notes']; |
| 182 | |
| 183 | $placeholder = !empty($opt['notes']['placeholder']) |
| 184 | ? $opt['notes']['placeholder'] |
| 185 | : __('Please, could you write some extra notes?', 'vikappointments'); |
| 186 | |
| 187 | ?> |
| 188 | <textarea |
| 189 | class="feedback-notes<?php echo !empty($opt['notes']['required']) ? ' required' : ''; ?>" |
| 190 | placeholder="<?php echo $placeholder; ?>" |
| 191 | style="<?php echo !empty($opt['checked']) ? '' : 'display:none;'; ?>" |
| 192 | ></textarea> |
| 193 | <?php |
| 194 | } |
| 195 | ?> |
| 196 | |
| 197 | </div> |
| 198 | <?php |
| 199 | } |
| 200 | ?> |
| 201 | |
| 202 | <p> |
| 203 | <small> |
| 204 | <span class="dashicons dashicons-editor-help"></span> |
| 205 | <?php echo __('In addition to the specified information, the feedback will contain your IP address (for security reasons), your PHP version, your WordPress version and the plugin version.', 'vikappointments'); ?> |
| 206 | </small> |
| 207 | </p> |
| 208 | |
| 209 | </form> |
| 210 | </div> |
| 211 | |
| 212 | <div class="th-box-footer"> |
| 213 | <a href="javascript: void(0);" id="vikappointments-deactivate" class="button button-primary"> |
| 214 | <?php echo __('Deactivate'); ?> |
| 215 | </a> |
| 216 | </div> |
| 217 | |
| 218 | </div> |
| 219 | |
| 220 | <script> |
| 221 | jQuery(function() { |
| 222 | |
| 223 | jQuery('.form-field input[name="feedback_type"]').on('change', function() { |
| 224 | var radio = jQuery('input[name="feedback_type"]:checked'); |
| 225 | |
| 226 | jQuery('.feedback-help,.feedback-notes').hide(); |
| 227 | radio.siblings('.feedback-help,.feedback-notes').show().focus(); |
| 228 | }); |
| 229 | |
| 230 | jQuery('#vikappointments-deactivate').on('click', function() { |
| 231 | var radio = jQuery('input[name="feedback_type"]:checked'); |
| 232 | |
| 233 | // get selected feedback type |
| 234 | var type = radio.val(); |
| 235 | |
| 236 | if (type == '0') { |
| 237 | // deactivate automatically |
| 238 | document.location.href = '<?php echo $deactivate_url_js; ?>'; |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | // get textarea |
| 243 | var textarea = radio.siblings('.feedback-notes'); |
| 244 | var comment = textarea.length ? textarea.val() : null; |
| 245 | |
| 246 | if (textarea.length && !textarea.val().length && textarea.hasClass('required')) { |
| 247 | textarea.addClass('invalid'); |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | // disable button |
| 252 | jQuery(this).attr('disabled', true); |
| 253 | |
| 254 | textarea.removeClass('invalid'); |
| 255 | |
| 256 | // do ajax and redirect on success/failure |
| 257 | jQuery.ajax({ |
| 258 | url: 'admin-ajax.php?action=vikappointments&task=feedback.submit', |
| 259 | type: 'post', |
| 260 | data: { |
| 261 | type: type, |
| 262 | notes: comment, |
| 263 | }, |
| 264 | }).done(function(resp) { |
| 265 | // keep a cookie for 7 days in order to stop showing the feedback |
| 266 | // modal again and again |
| 267 | var date = new Date(); |
| 268 | date.setDate(date.getDate() + 7); |
| 269 | document.cookie = 'vikappointments_feedback=1; expires=' + date.toUTCString() + '; path=/'; |
| 270 | // complete deactivation |
| 271 | document.location.href = '<?php echo $deactivate_url_js; ?>'; |
| 272 | }).fail(function(err) { |
| 273 | console.log(err); |
| 274 | // complete deactivation |
| 275 | document.location.href = '<?php echo $deactivate_url_js; ?>'; |
| 276 | }); |
| 277 | }); |
| 278 | |
| 279 | }); |
| 280 | </script> |
| 281 |