css
4 years ago
fonts
4 years ago
icons
4 years ago
images
4 years ago
js
4 years ago
languages
4 years ago
bws_functions.php
4 years ago
bws_include.php
4 years ago
bws_menu.php
4 years ago
class-bws-settings.php
4 years ago
deactivation-form.php
4 years ago
deprecated.php
4 years ago
product_list.php
4 years ago
class-bws-settings.php
1329 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Displays the content on the plugin settings page |
| 4 | * @package BestWebSoft |
| 5 | * @since 1.9.8 |
| 6 | */ |
| 7 | |
| 8 | if ( ! class_exists( 'Bws_Settings_Tabs' ) ) { |
| 9 | class Bws_Settings_Tabs { |
| 10 | private $tabs; |
| 11 | private $pro_plugin_is_activated = false; |
| 12 | private $custom_code_args = array(); |
| 13 | private $bws_plugin_link = ''; |
| 14 | |
| 15 | public $plugin_basename; |
| 16 | public $prefix; |
| 17 | public $wp_slug; |
| 18 | |
| 19 | public $options; |
| 20 | public $default_options; |
| 21 | public $is_network_options; |
| 22 | public $plugins_info = array(); |
| 23 | public $hide_pro_tabs = false; |
| 24 | public $demo_data; |
| 25 | |
| 26 | public $is_pro = false; |
| 27 | public $pro_page; |
| 28 | public $bws_license_plugin; |
| 29 | public $link_key; |
| 30 | public $link_pn; |
| 31 | public $is_trial = false; |
| 32 | public $licenses; |
| 33 | public $trial_days; |
| 34 | public $bws_hide_pro_option_exist = true; |
| 35 | |
| 36 | public $forbid_view = false; |
| 37 | public $change_permission_attr = ''; |
| 38 | |
| 39 | public $version; |
| 40 | public $upload_dir; |
| 41 | public $all_plugins; |
| 42 | public $is_multisite; |
| 43 | |
| 44 | public $doc_link; |
| 45 | public $doc_video_link; |
| 46 | |
| 47 | /** |
| 48 | * Constructor. |
| 49 | * |
| 50 | * The child class should call this constructor from its own constructor to override |
| 51 | * the default $args. |
| 52 | * @access public |
| 53 | * |
| 54 | * @param array|string $args |
| 55 | */ |
| 56 | public function __construct( $args = array() ) { |
| 57 | global $wp_version; |
| 58 | |
| 59 | $args = wp_parse_args( $args, array( |
| 60 | 'plugin_basename' => '', |
| 61 | 'prefix' => '', |
| 62 | 'plugins_info' => array(), |
| 63 | 'default_options' => array(), |
| 64 | 'options' => array(), |
| 65 | 'is_network_options' => false, |
| 66 | 'tabs' => array(), |
| 67 | 'doc_link' => '', |
| 68 | 'doc_video_link' => '', |
| 69 | 'wp_slug' => '', |
| 70 | 'demo_data' => false, |
| 71 | /* if this is free version and pro exist */ |
| 72 | 'link_key' => '', |
| 73 | 'link_pn' => '', |
| 74 | 'trial_days' => false, |
| 75 | 'licenses' => array() |
| 76 | ) ); |
| 77 | |
| 78 | $args['plugins_info']['Name'] = str_replace( ' by BestWebSoft', '', $args['plugins_info']['Name'] ); |
| 79 | |
| 80 | $this->plugin_basename = $args['plugin_basename']; |
| 81 | $this->prefix = $args['prefix']; |
| 82 | $this->plugins_info = $args['plugins_info']; |
| 83 | $this->options = $args['options']; |
| 84 | $this->default_options = $args['default_options']; |
| 85 | $this->wp_slug = $args['wp_slug']; |
| 86 | $this->demo_data = $args['demo_data']; |
| 87 | |
| 88 | $this->tabs = $args['tabs']; |
| 89 | $this->is_network_options = $args['is_network_options']; |
| 90 | |
| 91 | $this->doc_link = $args['doc_link']; |
| 92 | $this->doc_video_link = $args['doc_video_link']; |
| 93 | |
| 94 | $this->link_key = $args['link_key']; |
| 95 | $this->link_pn = $args['link_pn']; |
| 96 | $this->trial_days = $args['trial_days']; |
| 97 | $this->licenses = $args['licenses']; |
| 98 | |
| 99 | $this->pro_page = $this->bws_license_plugin = ''; |
| 100 | /* get $bws_plugins */ |
| 101 | require( dirname( __FILE__ ) . '/product_list.php' ); |
| 102 | if ( isset( $bws_plugins[ $this->plugin_basename ] ) ) { |
| 103 | if ( isset( $bws_plugins[ $this->plugin_basename ]['pro_settings'] ) ) { |
| 104 | $this->pro_page = $bws_plugins[ $this->plugin_basename ]['pro_settings']; |
| 105 | $this->bws_license_plugin = $bws_plugins[ $this->plugin_basename ]['pro_version']; |
| 106 | } |
| 107 | |
| 108 | $this->bws_plugin_link = substr( $bws_plugins[ $this->plugin_basename ]['link'],0 , strpos( $bws_plugins[ $this->plugin_basename ]['link'], '?' ) ); |
| 109 | |
| 110 | if ( ! empty( $this->link_key ) && ! empty( $this->link_pn ) ) |
| 111 | $this->bws_plugin_link .= '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version; |
| 112 | } |
| 113 | |
| 114 | $this->hide_pro_tabs = bws_hide_premium_options_check( $this->options ); |
| 115 | $this->version = '1.0.0'; |
| 116 | $this->is_multisite = is_multisite(); |
| 117 | |
| 118 | if ( empty( $this->pro_page ) && array_key_exists( 'license', $this->tabs ) ) { |
| 119 | $this->is_pro = true; |
| 120 | $this->licenses[ $this->plugins_info['TextDomain'] ] = array( |
| 121 | 'name' => $this->plugins_info['Name'], |
| 122 | 'slug' => $this->plugins_info['TextDomain'], |
| 123 | 'basename' => $this->plugin_basename |
| 124 | ); |
| 125 | } else { |
| 126 | $this->licenses[ $this->plugins_info['TextDomain'] ] = array( |
| 127 | 'name' => $this->plugins_info['Name'], |
| 128 | 'slug' => $this->plugins_info['TextDomain'], |
| 129 | 'pro_slug' => substr( $this->bws_license_plugin, 0, stripos( $this->bws_license_plugin, '/' ) ), |
| 130 | 'basename' => $this->plugin_basename, |
| 131 | 'pro_basename' => $this->bws_license_plugin |
| 132 | ); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Displays the content of the "Settings" on the plugin settings page |
| 138 | * @access public |
| 139 | * @param void |
| 140 | * @return void |
| 141 | */ |
| 142 | public function display_content() { |
| 143 | global $bstwbsftwppdtplgns_options; |
| 144 | if ( array_key_exists( 'custom_code', $this->tabs ) ) { |
| 145 | /* get args for `custom code` tab */ |
| 146 | $this->get_custom_code(); |
| 147 | } |
| 148 | |
| 149 | $save_results = $this->save_all_tabs_options(); |
| 150 | |
| 151 | $this->display_messages( $save_results ); |
| 152 | if ( isset( $_REQUEST['bws_restore_default'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { |
| 153 | bws_form_restore_default_confirm( $this->plugin_basename ); |
| 154 | } elseif ( isset( $_POST['bws_handle_demo'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { |
| 155 | $this->demo_data->bws_demo_confirm(); |
| 156 | } else { |
| 157 | bws_show_settings_notice(); ?> |
| 158 | <form class="bws_form" method="post" action="" enctype="multipart/form-data"> |
| 159 | <div id="poststuff"> |
| 160 | <div id="post-body" class="metabox-holder columns-2"> |
| 161 | <div id="post-body-content" style="position: relative;"> |
| 162 | <?php $this->display_tabs(); ?> |
| 163 | </div><!-- #post-body-content --> |
| 164 | <div id="postbox-container-1" class="postbox-container"> |
| 165 | <div class="meta-box-sortables ui-sortable"> |
| 166 | <div id="submitdiv" class="postbox"> |
| 167 | <h3 class="hndle"><?php _e( 'Information', 'bestwebsoft' ); ?></h3> |
| 168 | <div class="inside"> |
| 169 | <div class="submitbox" id="submitpost"> |
| 170 | <div id="minor-publishing"> |
| 171 | <div id="misc-publishing-actions"> |
| 172 | <?php /** |
| 173 | * action - Display additional content for #misc-publishing-actions |
| 174 | */ |
| 175 | do_action( __CLASS__ . '_information_postbox_top' ); ?> |
| 176 | <?php if ( $this->is_pro ) { |
| 177 | if ( isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $this->plugin_basename ] ) || empty( $bstwbsftwppdtplgns_options['time_out'] ) || ! array_key_exists( $this->plugin_basename, $bstwbsftwppdtplgns_options['time_out'] ) ) { |
| 178 | $license_type = 'Pro'; |
| 179 | $license_status = __( 'Inactive', 'bestwebsoft' ) . ' <a href="#' . $this->prefix . '_license_tab" class="bws_trigger_tab_click">' . __( 'Learn More', 'bestwebsoft' ) . '</a>'; |
| 180 | } else { |
| 181 | $finish = strtotime( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ); |
| 182 | $today = strtotime( date( "m/d/Y" ) ); |
| 183 | if ( isset( $bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] ) ) { |
| 184 | $license_type = 'Trial Pro'; |
| 185 | |
| 186 | if ( $finish < $today ) { |
| 187 | $license_status = __( 'Expired', 'bestwebsoft' ); |
| 188 | } else { |
| 189 | $daysleft = floor( ( $finish - $today ) / ( 60*60*24 ) ); |
| 190 | $license_status = sprintf( __( '%s day(-s) left', 'bestwebsoft' ), $daysleft ); |
| 191 | } |
| 192 | $license_status .= '. <a target="_blank" href="' . esc_url( $this->plugins_info['PluginURI'] ) . '">' . __( 'Upgrade to Pro', 'bestwebsoft' ) . '</a>'; |
| 193 | } else { |
| 194 | $license_type = isset( $bstwbsftwppdtplgns_options['nonprofit'][ $this->plugin_basename ] ) ? 'Nonprofit Pro' : 'Pro'; |
| 195 | if ( ! empty( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ) && $finish < $today ) { |
| 196 | $license_status = sprintf( __( 'Expired on %s', 'bestwebsoft' ), $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ) . '. <a target="_blank" href="https://support.bestwebsoft.com/entries/53487136">' . __( 'Renew Now', 'bestwebsoft' ) . '</a>'; |
| 197 | } else { |
| 198 | $license_status = __( 'Active', 'bestwebsoft' ); |
| 199 | } |
| 200 | } |
| 201 | } ?> |
| 202 | <div class="misc-pub-section"> |
| 203 | <strong><?php _e( 'License', 'bestwebsoft' ); ?>:</strong> <?php echo $license_type; ?> |
| 204 | </div> |
| 205 | <div class="misc-pub-section"> |
| 206 | <strong><?php _e( 'Status', 'bestwebsoft' ); ?>:</strong> <?php echo $license_status; ?> |
| 207 | </div><!-- .misc-pub-section --> |
| 208 | <?php } ?> |
| 209 | <div class="misc-pub-section"> |
| 210 | <strong><?php _e( 'Version', 'bestwebsoft' ); ?>:</strong> <?php echo $this->plugins_info['Version']; ?> |
| 211 | </div><!-- .misc-pub-section --> |
| 212 | <?php /** |
| 213 | * action - Display additional content for #misc-publishing-actions |
| 214 | */ |
| 215 | do_action( __CLASS__ . '_information_postbox_bottom' ); ?> |
| 216 | </div> |
| 217 | <div class="clear"></div> |
| 218 | </div> |
| 219 | <div id="major-publishing-actions"> |
| 220 | <div id="publishing-action"> |
| 221 | <input type="hidden" name="<?php echo $this->prefix; ?>_form_submit" value="submit" /> |
| 222 | <input id="bws-submit-button" type="submit" class="button button-primary button-large" value="<?php _e( 'Save Changes', 'bestwebsoft' ); ?>" /> |
| 223 | <?php wp_nonce_field( $this->plugin_basename, 'bws_nonce_name' ); ?> |
| 224 | </div> |
| 225 | <div class="clear"></div> |
| 226 | </div> |
| 227 | </div> |
| 228 | </div> |
| 229 | </div> |
| 230 | <?php /** |
| 231 | * action - Display custom metabox |
| 232 | */ |
| 233 | do_action( __CLASS__ . '_display_metabox' ); |
| 234 | |
| 235 | if ( function_exists( 'bws_affiliate_postbox' ) ) |
| 236 | bws_affiliate_postbox(); ?> |
| 237 | </div> |
| 238 | </div> |
| 239 | <div id="postbox-container-2" class="postbox-container"> |
| 240 | <?php /** |
| 241 | * action - Display additional content for #postbox-container-2 |
| 242 | */ |
| 243 | do_action( __CLASS__ . '_display_second_postbox' ); ?> |
| 244 | <div class="submit"> |
| 245 | <input type="submit" class="button button-primary button-large" value="<?php _e( 'Save Changes', 'bestwebsoft' ); ?>" /> |
| 246 | </div> |
| 247 | <?php if ( ! empty( $this->wp_slug ) ) |
| 248 | bws_plugin_reviews_block( $this->plugins_info['Name'], $this->wp_slug ); ?> |
| 249 | </div> |
| 250 | </div> |
| 251 | </form> |
| 252 | </div> |
| 253 | <?php } |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Displays the Tabs |
| 258 | * @access public |
| 259 | * @param void |
| 260 | * @return void |
| 261 | */ |
| 262 | public function display_tabs() { ?> |
| 263 | <div id="bws_settings_tabs_wrapper"> |
| 264 | <ul id="bws_settings_tabs"> |
| 265 | <?php $this->display_tabs_list(); ?> |
| 266 | </ul> |
| 267 | <?php $this->display_tabs_content(); ?> |
| 268 | <div class="clear"></div> |
| 269 | <input type="hidden" name="bws_active_tab" value="<?php if ( isset( $_REQUEST['bws_active_tab'] ) ) echo esc_attr( $_REQUEST['bws_active_tab'] ); ?>" /> |
| 270 | </div> |
| 271 | <?php } |
| 272 | |
| 273 | /** |
| 274 | * Displays the list of tabs |
| 275 | * @access private |
| 276 | * @return void |
| 277 | */ |
| 278 | private function display_tabs_list() { |
| 279 | foreach ( $this->tabs as $tab_slug => $data ) { |
| 280 | if ( ! empty( $data['is_pro'] ) && $this->hide_pro_tabs ) |
| 281 | continue; |
| 282 | $tab_class = 'bws-tab-' . $tab_slug; |
| 283 | if ( ! empty( $data['is_pro'] ) ) |
| 284 | $tab_class .= ' bws_pro_tab'; |
| 285 | if ( ! empty( $data['class'] ) ) |
| 286 | $tab_class .= ' ' . $data['class']; ?> |
| 287 | <li class="<?php echo $tab_class; ?>" data-slug="<?php echo $tab_slug; ?>"> |
| 288 | <a href="#<?php echo $this->prefix; ?>_<?php echo $tab_slug; ?>_tab"> |
| 289 | <span><?php echo esc_html( $data['label'] ); ?></span> |
| 290 | </a> |
| 291 | </li> |
| 292 | <?php } |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Displays the content of tabs |
| 297 | * @access private |
| 298 | * @param string $tab_slug |
| 299 | * @return void |
| 300 | */ |
| 301 | public function display_tabs_content() { |
| 302 | foreach ( $this->tabs as $tab_slug => $data ) { |
| 303 | if ( ! empty( $data['is_pro'] ) && $this->hide_pro_tabs ) |
| 304 | continue; ?> |
| 305 | <div class="bws_tab ui-tabs-panel ui-widget-content ui-corner-bottom" id="<?php echo esc_attr( $this->prefix . '_' . $tab_slug . '_tab' ); ?>" aria-labelledby="ui-id-2" role="tabpanel" aria-hidden="false" style="display: block;"> |
| 306 | <?php $tab_slug = str_replace( '-', '_', $tab_slug ); |
| 307 | if ( method_exists( $this, 'tab_' . $tab_slug ) ) { |
| 308 | call_user_func( array( $this, 'tab_' . $tab_slug ) ); |
| 309 | do_action_ref_array( __CLASS__ . '_after_tab_' . $tab_slug, array( &$this ) ); |
| 310 | } ?> |
| 311 | </div> |
| 312 | <?php } |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Save all options from all tabs and display errors\messages |
| 317 | * @access public |
| 318 | * @param void |
| 319 | * @return void |
| 320 | */ |
| 321 | public function save_all_tabs_options() { |
| 322 | $message = $notice = $error = ''; |
| 323 | /* Restore default settings */ |
| 324 | if ( isset( $_POST['bws_restore_confirm'] ) && check_admin_referer( $this->plugin_basename, 'bws_settings_nonce_name' ) ) { |
| 325 | $this->restore_options(); |
| 326 | $message = __( 'All plugin settings were restored.', 'bestwebsoft' ); |
| 327 | /* Go Pro - check license key */ |
| 328 | } elseif ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { |
| 329 | $result = $this->save_options_license_key(); |
| 330 | if ( ! empty( $result['empty_field_error'] ) ) |
| 331 | $error = $result['empty_field_error']; |
| 332 | if ( ! empty( $result['error'] ) ) |
| 333 | $error = $result['error']; |
| 334 | if ( ! empty( $result['message'] ) ) |
| 335 | $message = $result['message']; |
| 336 | if ( ! empty( $result['notice'] ) ) |
| 337 | $notice = $result['notice']; |
| 338 | /* check demo data */ |
| 339 | } else { |
| 340 | $demo_result = ! empty( $this->demo_data ) ? $this->demo_data->bws_handle_demo_data() : false; |
| 341 | if ( false !== $demo_result ) { |
| 342 | if ( ! empty( $demo_result ) && is_array( $demo_result ) ) { |
| 343 | $error = $demo_result['error']; |
| 344 | $message = $demo_result['done']; |
| 345 | if ( ! empty( $demo_result['done'] ) && ! empty( $demo_result['options'] ) ) |
| 346 | $this->options = $demo_result['options']; |
| 347 | } |
| 348 | /* Save options */ |
| 349 | } elseif ( ! isset( $_REQUEST['bws_restore_default'] ) && ! isset( $_POST['bws_handle_demo'] ) && isset( $_REQUEST[ $this->prefix . '_form_submit'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { |
| 350 | /* save tabs */ |
| 351 | $result = $this->save_options(); |
| 352 | if ( ! empty( $result['error'] ) ) |
| 353 | $error = $result['error']; |
| 354 | if ( ! empty( $result['message'] ) ) |
| 355 | $message = $result['message']; |
| 356 | if ( ! empty( $result['notice'] ) ) |
| 357 | $notice = $result['notice']; |
| 358 | |
| 359 | if ( '' == $this->change_permission_attr ) { |
| 360 | /* save `misc` tab */ |
| 361 | $result = $this->save_options_misc(); |
| 362 | if ( ! empty( $result['notice'] ) ) |
| 363 | $notice .= $result['notice']; |
| 364 | } |
| 365 | |
| 366 | if ( array_key_exists( 'custom_code', $this->tabs ) ) { |
| 367 | /* save `custom code` tab */ |
| 368 | $this->save_options_custom_code(); |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | return compact( 'message', 'notice', 'error' ); |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Display error\message\notice |
| 378 | * @access public |
| 379 | * @param $save_results - array with error\message\notice |
| 380 | * @return void |
| 381 | */ |
| 382 | public function display_messages( $save_results ) { |
| 383 | /** |
| 384 | * action - Display custom error\message\notice |
| 385 | */ |
| 386 | do_action( __CLASS__ . '_display_custom_messages', $save_results ); ?> |
| 387 | <div class="updated fade inline" <?php if ( empty( $save_results['message'] ) ) echo "style=\"display:none\""; ?>><p><strong><?php echo $save_results['message']; ?></strong></p></div> |
| 388 | <div class="updated bws-notice inline" <?php if ( empty( $save_results['notice'] ) ) echo "style=\"display:none\""; ?>><p><strong><?php echo $save_results['notice']; ?></strong></p></div> |
| 389 | <div class="error inline" <?php if ( empty( $save_results['error'] ) ) echo "style=\"display:none\""; ?>><p><strong><?php echo $save_results['error']; ?></strong></p></div> |
| 390 | <?php } |
| 391 | |
| 392 | /** |
| 393 | * Save plugin options to the database |
| 394 | * @access public |
| 395 | * @param ab |
| 396 | * @return array The action results |
| 397 | * @abstract |
| 398 | */ |
| 399 | public function save_options() { |
| 400 | die( 'function Bws_Settings_Tabs::save_options() must be over-ridden in a sub-class.' ); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Get 'custom_code' status and content |
| 405 | * @access private |
| 406 | */ |
| 407 | private function get_custom_code() { |
| 408 | global $bstwbsftwppdtplgns_options; |
| 409 | |
| 410 | $this->custom_code_args = array( |
| 411 | 'is_css_active' => false, |
| 412 | 'content_css' => '', |
| 413 | 'css_writeable' => false, |
| 414 | 'is_php_active' => false, |
| 415 | 'content_php' => '', |
| 416 | 'php_writeable' => false, |
| 417 | 'is_js_active' => false, |
| 418 | 'content_js' => '', |
| 419 | 'js_writeable' => false, |
| 420 | ); |
| 421 | |
| 422 | if ( ! $this->upload_dir ) |
| 423 | $this->upload_dir = wp_upload_dir(); |
| 424 | |
| 425 | $folder = $this->upload_dir['basedir'] . '/bws-custom-code'; |
| 426 | if ( ! $this->upload_dir["error"] ) { |
| 427 | if ( ! is_dir( $folder ) ) |
| 428 | wp_mkdir_p( $folder, 0755 ); |
| 429 | |
| 430 | $index_file = $this->upload_dir['basedir'] . '/bws-custom-code/index.php'; |
| 431 | if ( ! file_exists( $index_file ) ) { |
| 432 | if ( $f = fopen( $index_file, 'w+' ) ) |
| 433 | fclose( $f ); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | if ( $this->is_multisite ) |
| 438 | $this->custom_code_args['blog_id'] = get_current_blog_id(); |
| 439 | |
| 440 | foreach ( array( 'css', 'php', 'js' ) as $extension ) { |
| 441 | $file = 'bws-custom-code.' . $extension; |
| 442 | $real_file = $folder . '/' . $file; |
| 443 | |
| 444 | if ( file_exists( $real_file ) ) { |
| 445 | update_recently_edited( $real_file ); |
| 446 | $this->custom_code_args["content_{$extension}"] = file_get_contents( $real_file ); |
| 447 | if ( ( $this->is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ) ) || |
| 448 | ( ! $this->is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) ) ) { |
| 449 | $this->custom_code_args["is_{$extension}_active"] = true; |
| 450 | } |
| 451 | if ( is_writeable( $real_file ) ) |
| 452 | $this->custom_code_args["{$extension}_writeable"] = true; |
| 453 | } else { |
| 454 | $this->custom_code_args["{$extension}_writeable"] = true; |
| 455 | if ( 'php' == $extension ) |
| 456 | $this->custom_code_args["content_{$extension}"] = "<?php" . "\n" . "if ( ! defined( 'ABSPATH' ) ) exit;" . "\n" . "if ( ! defined( 'BWS_GLOBAL' ) ) exit;" . "\n\n" . "/* Start your code here */" . "\n"; |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * Display 'custom_code' tab |
| 463 | * @access private |
| 464 | */ |
| 465 | private function tab_custom_code() { ?> |
| 466 | <h3 class="bws_tab_label"><?php _e( 'Custom Code', 'bestwebsoft' ); ?></h3> |
| 467 | <?php $this->help_phrase(); ?> |
| 468 | <hr> |
| 469 | <?php if ( ! current_user_can( 'edit_plugins' ) ) { |
| 470 | echo '<p>' . __( 'You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft' ) . '</p>'; |
| 471 | return; |
| 472 | } |
| 473 | |
| 474 | $list = array( |
| 475 | 'css' => array( 'description' => __( 'These styles will be added to the header on all pages of your site.', 'bestwebsoft' ), |
| 476 | 'learn_more_link' => 'https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started' |
| 477 | ), |
| 478 | 'php' => array( 'description' => sprintf( __( 'This PHP code will be hooked to the %s action and will be printed on front end only.', 'bestwebsoft' ), '<a href="https://codex.wordpress.org/Plugin_API/Action_Reference/init" target="_blank"><code>init</code></a>' ), |
| 479 | 'learn_more_link' => 'https://php.net/' |
| 480 | ), |
| 481 | 'js' => array( 'description' => __( 'These code will be added to the header on all pages of your site.', 'bestwebsoft' ), |
| 482 | 'learn_more_link' => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript' |
| 483 | ), |
| 484 | ); |
| 485 | |
| 486 | if ( ! $this->custom_code_args['css_writeable'] || |
| 487 | ! $this->custom_code_args['php_writeable'] || |
| 488 | ! $this->custom_code_args['js_writeable'] ) { ?> |
| 489 | <p><em><?php printf( __( 'You need to make this files writable before you can save your changes. See %s the Codex %s for more information.', 'bestwebsoft' ), |
| 490 | '<a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">', |
| 491 | '</a>' ); ?></em></p> |
| 492 | <?php } |
| 493 | |
| 494 | foreach ( $list as $extension => $extension_data ) { |
| 495 | $name = 'js' == $extension ? 'JavaScript' : strtoupper( $extension ); ?> |
| 496 | <p><big> |
| 497 | <strong><?php echo $name; ?></strong> |
| 498 | <?php if ( ! $this->custom_code_args["{$extension}_writeable"] ) |
| 499 | echo '(' . __( 'Browsing', 'bestwebsoft' ) . ')'; ?> |
| 500 | </big></p> |
| 501 | <p class="bws_info"> |
| 502 | <label> |
| 503 | <input type="checkbox" name="bws_custom_<?php echo $extension; ?>_active" value="1" <?php if ( $this->custom_code_args["is_{$extension}_active"] ) echo "checked"; ?> /> |
| 504 | <?php printf( __( 'Activate custom %s code.', 'bestwebsoft' ), $name ); ?> |
| 505 | </label> |
| 506 | </p> |
| 507 | <textarea cols="70" rows="25" name="bws_newcontent_<?php echo $extension; ?>" id="bws_newcontent_<?php echo $extension; ?>"><?php if ( isset( $this->custom_code_args["content_{$extension}"] ) ) echo esc_textarea( $this->custom_code_args["content_{$extension}"] ); ?></textarea> |
| 508 | <p class="bws_info"> |
| 509 | <?php echo $extension_data['description']; ?> |
| 510 | <br> |
| 511 | <a href="<?php echo esc_url( $extension_data['learn_more_link'] ); ?>" target="_blank"> |
| 512 | <?php printf( __( 'Learn more about %s', 'bestwebsoft' ), $name ); ?> |
| 513 | </a> |
| 514 | </p> |
| 515 | <?php } |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * Save plugin options to the database |
| 520 | * @access private |
| 521 | * @return array The action results |
| 522 | */ |
| 523 | private function save_options_custom_code() { |
| 524 | global $bstwbsftwppdtplgns_options; |
| 525 | $folder = $this->upload_dir['basedir'] . '/bws-custom-code'; |
| 526 | |
| 527 | foreach ( array( 'css', 'php', 'js' ) as $extension ) { |
| 528 | $file = 'bws-custom-code.' . $extension; |
| 529 | $real_file = $folder . '/' . $file; |
| 530 | |
| 531 | if ( isset( $_POST["bws_newcontent_{$extension}"] ) && |
| 532 | $this->custom_code_args["{$extension}_writeable"] ) { |
| 533 | $newcontent = trim( wp_unslash( $_POST["bws_newcontent_{$extension}"] ) ); |
| 534 | if ( 'css' == $extension ) |
| 535 | $newcontent = wp_kses( $newcontent, array( '\'', '\"' ) ); |
| 536 | |
| 537 | if ( ! empty( $newcontent ) && isset( $_POST["bws_custom_{$extension}_active"] ) ) { |
| 538 | $this->custom_code_args["is_{$extension}_active"] = true; |
| 539 | if ( $this->is_multisite ) { |
| 540 | $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] = ( 'php' == $extension ) ? $real_file : $this->upload_dir['baseurl'] . '/bws-custom-code/' . $file; |
| 541 | } else { |
| 542 | $bstwbsftwppdtplgns_options['custom_code'][ $file ] = ( 'php' == $extension ) ? $real_file : $this->upload_dir['baseurl'] . '/bws-custom-code/' . $file; |
| 543 | } |
| 544 | } else { |
| 545 | $this->custom_code_args["is_{$extension}_active"] = false; |
| 546 | if ( $this->is_multisite ) { |
| 547 | if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ) ) |
| 548 | unset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ); |
| 549 | } else { |
| 550 | if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) ) |
| 551 | unset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ); |
| 552 | } |
| 553 | } |
| 554 | if ( $f = fopen( $real_file, 'w+' ) ) { |
| 555 | fwrite( $f, $newcontent ); |
| 556 | fclose( $f ); |
| 557 | $this->custom_code_args["content_{$extension}"] = $newcontent; |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | if ( $this->is_multisite ) |
| 563 | update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
| 564 | else |
| 565 | update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * Display 'misc' tab |
| 570 | * @access private |
| 571 | */ |
| 572 | private function tab_misc() { |
| 573 | global $bstwbsftwppdtplgns_options; ?> |
| 574 | <h3 class="bws_tab_label"><?php _e( 'Miscellaneous Settings', 'bestwebsoft' ); ?></h3> |
| 575 | <?php $this->help_phrase(); ?> |
| 576 | <hr> |
| 577 | <?php /** |
| 578 | * action - Display custom options on the Import / Export' tab |
| 579 | */ |
| 580 | do_action( __CLASS__ . '_additional_misc_options' ); |
| 581 | |
| 582 | if ( ! $this->forbid_view && ! empty( $this->change_permission_attr ) ) { ?> |
| 583 | <div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to change %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div> |
| 584 | <?php } |
| 585 | if ( $this->forbid_view ) { ?> |
| 586 | <div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to view %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div> |
| 587 | <?php } else { ?> |
| 588 | <table class="form-table"> |
| 589 | <?php /** |
| 590 | * action - Display custom options on the 'misc' tab |
| 591 | */ |
| 592 | do_action( __CLASS__ . '_additional_misc_options_affected' ); |
| 593 | if ( ! empty( $this->pro_page ) && $this->bws_hide_pro_option_exist ) { ?> |
| 594 | <tr> |
| 595 | <th scope="row"><?php _e( 'Pro Options', 'bestwebsoft' ); ?></th> |
| 596 | <td> |
| 597 | <label> |
| 598 | <input <?php echo $this->change_permission_attr; ?> name="bws_hide_premium_options_submit" type="checkbox" value="1" <?php if ( ! $this->hide_pro_tabs ) echo 'checked="checked "'; ?> /> |
| 599 | <span class="bws_info"><?php _e( 'Enable to display plugin Pro options.', 'bestwebsoft' ); ?></span> |
| 600 | </label> |
| 601 | </td> |
| 602 | </tr> |
| 603 | <?php } ?> |
| 604 | <tr> |
| 605 | <th scope="row"><?php _e( 'Track Usage', 'bestwebsoft' ); ?></th> |
| 606 | <td> |
| 607 | <label> |
| 608 | <input <?php echo $this->change_permission_attr; ?> name="bws_track_usage" type="checkbox" value="1" <?php if ( ! empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) echo 'checked="checked "'; ?>/> |
| 609 | <span class="bws_info"><?php _e( 'Enable to allow tracking plugin usage anonymously in order to make it better.', 'bestwebsoft' ); ?></span> |
| 610 | </label> |
| 611 | </td> |
| 612 | </tr> |
| 613 | <tr> |
| 614 | <th scope="row"><?php _e( 'Default Settings', 'bestwebsoft' ); ?></th> |
| 615 | <td> |
| 616 | <input<?php echo $this->change_permission_attr; ?> name="bws_restore_default" type="submit" class="button" value="<?php _e( 'Restore Settings', 'bestwebsoft' ); ?>" /> |
| 617 | <div class="bws_info"><?php _e( 'This will restore plugin settings to defaults.', 'bestwebsoft' ); ?></div> |
| 618 | </td> |
| 619 | </tr> |
| 620 | </table> |
| 621 | <?php } |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * Display 'Import / Export' tab |
| 626 | * @access private |
| 627 | */ |
| 628 | public function tab_import_export() { ?> |
| 629 | <h3 class="bws_tab_label"><?php _e( 'Import / Export', 'bestwebsoft' ); ?></h3> |
| 630 | <?php $this->help_phrase(); ?> |
| 631 | <hr> |
| 632 | <?php /** |
| 633 | * action - Display custom options on the Import / Export' tab |
| 634 | */ |
| 635 | do_action( __CLASS__ . '_additional_import_export_options' ); |
| 636 | |
| 637 | if ( ! $this->forbid_view && ! empty( $this->change_permission_attr ) ) { ?> |
| 638 | <div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to change %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div> |
| 639 | <?php } |
| 640 | if ( $this->forbid_view ) { ?> |
| 641 | <div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to view %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div> |
| 642 | <?php } else { ?> |
| 643 | <table class="form-table"> |
| 644 | <?php /** |
| 645 | * action - Display custom options on the Import / Export' tab |
| 646 | */ |
| 647 | do_action( __CLASS__ . '_additional_import_export_options_affected' ); ?> |
| 648 | </table> |
| 649 | <?php } |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Save plugin options to the database |
| 654 | * @access private |
| 655 | */ |
| 656 | private function save_options_misc() { |
| 657 | global $bstwbsftwppdtplgns_options, $wp_version; |
| 658 | $notice = ''; |
| 659 | |
| 660 | /* hide premium options */ |
| 661 | if ( ! empty( $this->pro_page ) ) { |
| 662 | if ( isset( $_POST['bws_hide_premium_options'] ) ) { |
| 663 | $hide_result = bws_hide_premium_options( $this->options ); |
| 664 | $this->hide_pro_tabs = true; |
| 665 | $this->options = $hide_result['options']; |
| 666 | if ( ! empty( $hide_result['message'] ) ) |
| 667 | $notice = $hide_result['message']; |
| 668 | if ( $this->is_network_options ) |
| 669 | update_site_option( $this->prefix . '_options', $this->options ); |
| 670 | else |
| 671 | update_option( $this->prefix . '_options', $this->options ); |
| 672 | } else if ( isset( $_POST['bws_hide_premium_options_submit'] ) ) { |
| 673 | if ( ! empty( $this->options['hide_premium_options'] ) ) { |
| 674 | $key = array_search( get_current_user_id(), $this->options['hide_premium_options'] ); |
| 675 | if ( false !== $key ) |
| 676 | unset( $this->options['hide_premium_options'][ $key ] ); |
| 677 | if ( $this->is_network_options ) |
| 678 | update_site_option( $this->prefix . '_options', $this->options ); |
| 679 | else |
| 680 | update_option( $this->prefix . '_options', $this->options ); |
| 681 | } |
| 682 | $this->hide_pro_tabs = false; |
| 683 | } else { |
| 684 | if ( empty( $this->options['hide_premium_options'] ) ) { |
| 685 | $this->options['hide_premium_options'][] = get_current_user_id(); |
| 686 | if ( $this->is_network_options ) |
| 687 | update_site_option( $this->prefix . '_options', $this->options ); |
| 688 | else |
| 689 | update_option( $this->prefix . '_options', $this->options ); |
| 690 | } |
| 691 | $this->hide_pro_tabs = true; |
| 692 | } |
| 693 | } |
| 694 | /* Save 'Track Usage' option */ |
| 695 | if ( isset( $_POST['bws_track_usage'] ) ) { |
| 696 | if ( empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) { |
| 697 | $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] = true; |
| 698 | $track_usage = true; |
| 699 | } |
| 700 | } else { |
| 701 | if ( ! empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) { |
| 702 | unset( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ); false; |
| 703 | $track_usage = false; |
| 704 | } |
| 705 | } |
| 706 | if ( isset( $track_usage ) ) { |
| 707 | $usage_id = ! empty( $bstwbsftwppdtplgns_options['track_usage']['usage_id'] ) ? $bstwbsftwppdtplgns_options['track_usage']['usage_id'] : false; |
| 708 | /* send data */ |
| 709 | $options = array( |
| 710 | 'timeout' => 3, |
| 711 | 'body' => array( |
| 712 | 'url' => get_bloginfo( 'url' ), |
| 713 | 'wp_version' => $wp_version, |
| 714 | 'is_active' => $track_usage, |
| 715 | 'product' => $this->plugin_basename, |
| 716 | 'version' => $this->plugins_info['Version'], |
| 717 | 'usage_id' => $usage_id, |
| 718 | ), |
| 719 | 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) |
| 720 | ); |
| 721 | $raw_response = wp_remote_post( 'https://bestwebsoft.com/wp-content/plugins/products-statistics/track-usage/', $options ); |
| 722 | |
| 723 | if ( ! is_wp_error( $raw_response ) && 200 == wp_remote_retrieve_response_code( $raw_response ) ) { |
| 724 | $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); |
| 725 | |
| 726 | if ( is_array( $response ) && |
| 727 | ! empty( $response['usage_id'] ) && |
| 728 | $response['usage_id'] != $usage_id ) { |
| 729 | $bstwbsftwppdtplgns_options['track_usage']['usage_id'] = $response['usage_id']; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | if ( $this->is_multisite ) |
| 734 | update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
| 735 | else |
| 736 | update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
| 737 | } |
| 738 | |
| 739 | return compact( 'notice' ); |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * |
| 744 | */ |
| 745 | public function tab_license() { |
| 746 | global $wp_version, $bstwbsftwppdtplgns_options; ?> |
| 747 | <h3 class="bws_tab_label"><?php _e( 'License Key', 'bestwebsoft' ); ?></h3> |
| 748 | <?php $this->help_phrase(); ?> |
| 749 | <hr> |
| 750 | <?php |
| 751 | foreach ( $this->licenses as $single_license ) { |
| 752 | $pro_plugin_name = ( strpos( $single_license['name'], 'Pro' ) ) ? $single_license['name'] : $single_license['name'] . ' ' . 'Pro'; |
| 753 | if ( ! empty( $this->pro_page ) || ! empty( $single_license['pro_basename'] ) ) { |
| 754 | |
| 755 | if ( $this->pro_plugin_is_activated && ( empty( $single_license['pro_basename'] ) || isset( $this->bws_license_plugin ) ) ) { |
| 756 | $url = 'https://bestwebsoft.com/wp-content/plugins/paid-products/plugins/downloads/?bws_first_download=' . $this->bws_license_plugin . '&bws_license_key=' . $bstwbsftwppdtplgns_options[ $this->bws_license_plugin ] . '&download_from=5'; ?> |
| 757 | <table class="form-table"> |
| 758 | <tr> |
| 759 | <th scope="row"><?php echo $pro_plugin_name . ' License'; ?></th> |
| 760 | <td> |
| 761 | <p> |
| 762 | <strong><?php _e( 'Your Pro plugin is ready', 'bestwebsoft' ); ?></strong> |
| 763 | <br> |
| 764 | <?php _e( 'Your plugin has been zipped, and now is ready to download.', 'bestwebsoft' ); ?> |
| 765 | </p> |
| 766 | <p> |
| 767 | <a class="button button-secondary" target="_parent" href="<?php echo esc_url( $url ); ?>"><?php _e( 'Download Now', 'bestwebsoft' ); ?></a> |
| 768 | </p> |
| 769 | <br> |
| 770 | <p> |
| 771 | <strong><?php _e( 'Need help installing the plugin?', 'bestwebsoft' ); ?></strong> |
| 772 | <br> |
| 773 | <a target="_blank" href="https://bestwebsoft.com/documentation/how-to-install-a-wordpress-product/how-to-install-a-wordpress-plugin/"><?php _e( 'How to install WordPress plugin from your admin Dashboard (ZIP archive)', 'bestwebsoft' ); ?></a> |
| 774 | </p> |
| 775 | <br> |
| 776 | <p> |
| 777 | <strong><?php _e( 'Get Started', 'bestwebsoft' ); ?></strong> |
| 778 | <br> |
| 779 | <a target="_blank" href="https://bestwebsoft.com/documentation/"><?php _e( 'Documentation', 'bestwebsoft' ); ?></a> |
| 780 | <br> |
| 781 | <a target="_blank" href="https://www.youtube.com/user/bestwebsoft"><?php _e( 'Video Instructions', 'bestwebsoft' ); ?></a> |
| 782 | <br> |
| 783 | <a target="_blank" href="https://support.bestwebsoft.com"><?php _e( 'Knowledge Base', 'bestwebsoft' ); ?></a> |
| 784 | </p> |
| 785 | </td> |
| 786 | </tr> |
| 787 | </table> |
| 788 | <?php } else { |
| 789 | $attr = $license_key = ''; |
| 790 | if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['count'] ) && |
| 791 | '5' < $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['count'] && |
| 792 | $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) |
| 793 | $attr = 'disabled="disabled"'; |
| 794 | |
| 795 | if ( ! empty( $single_license['pro_basename'] ) ) { |
| 796 | $license_key = ! empty( $bstwbsftwppdtplgns_options[ $single_license['pro_basename'] ] ) ? $bstwbsftwppdtplgns_options[ $single_license['pro_basename'] ] : ''; |
| 797 | } ?> |
| 798 | <table class="form-table"> |
| 799 | <tr> |
| 800 | <th scope="row"><?php echo $pro_plugin_name . ' License'; ?></th> |
| 801 | <td> |
| 802 | <input <?php echo $attr; ?> type="text" name="bws_license_key_<?php echo ( ! empty( $single_license['pro_slug'] ) ) ? $single_license['pro_slug'] : $single_license['slug']; ?>" value="<?php echo esc_attr( $license_key ); ?>" /> |
| 803 | <input <?php echo $attr; ?> type="hidden" name="bws_license_plugin_<?php echo ( ! empty( $single_license['pro_slug'] ) ) ? $single_license['pro_slug'] : $single_license['slug']; ?>" value="<?php echo esc_attr( ( ! empty( $single_license['pro_slug'] ) ) ? $single_license['pro_slug'] : $single_license['slug'] ); ?>" /> |
| 804 | <input <?php echo $attr; ?> type="submit" class="button button-secondary" name="bws_license_submit" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" /> |
| 805 | <div class="bws_info"> |
| 806 | <?php printf( __( 'Enter your license key to activate %s and get premium plugin features.', 'bestwebsoft' ), '<a href="' . $this->bws_plugin_link . '" target="_blank" title="' . $pro_plugin_name . '">' . $pro_plugin_name . '</a>' ); ?> |
| 807 | </div> |
| 808 | <?php if ( '' != $attr ) { ?> |
| 809 | <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); ?></p> |
| 810 | <?php } |
| 811 | if ( $this->trial_days !== false ) |
| 812 | echo '<p>' . __( 'or', 'bestwebsoft' ) . ' <a href="' . esc_url( $this->plugins_info['PluginURI'] . 'trial/?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version ) . '" target="_blank">' . sprintf( __( 'Start Your Free %s-Day Trial Now', 'bestwebsoft' ), $this->trial_days ) . '</a></p>'; ?> |
| 813 | </td> |
| 814 | </tr> |
| 815 | </table> |
| 816 | <?php } |
| 817 | } else { |
| 818 | global $bstwbsftwppdtplgns_options; |
| 819 | $license_key = ( isset( $bstwbsftwppdtplgns_options[ $single_license['basename'] ] ) ) ? $bstwbsftwppdtplgns_options[ $single_license['basename'] ] : ''; ?> |
| 820 | <table class="form-table"> |
| 821 | <tr> |
| 822 | <th scope="row"><?php echo $pro_plugin_name . ' License'; ?></th> |
| 823 | <td> |
| 824 | <input type="text" maxlength="100" name="bws_license_key_<?php echo $single_license['slug']; ?>" value="<?php echo esc_attr( $license_key ); ?>" /> |
| 825 | <input type="submit" class="button button-secondary" name="bws_license_submit" value="<?php _e( 'Check license key', 'bestwebsoft' ); ?>" /> |
| 826 | <div class="bws_info"> |
| 827 | <?php _e( 'If necessary, you can check if the license key is correct or reenter it in the field below.', 'bestwebsoft' ); ?> |
| 828 | </div> |
| 829 | </td> |
| 830 | </tr> |
| 831 | </table> |
| 832 | <?php } |
| 833 | } ?> |
| 834 | <table class="form-table"> |
| 835 | <tr> |
| 836 | <th scope="row"><?php _e( 'Manage License Settings', 'bestwebsoft' ); ?></th> |
| 837 | <td> |
| 838 | <a class="button button-secondary" href="https://bestwebsoft.com/client-area" target="_blank"><?php _e( 'Login to Client Area', 'bestwebsoft' ); ?></a> |
| 839 | <div class="bws_info"> |
| 840 | <?php _e( 'Manage active licenses, download BWS products, and view your payment history using BestWebSoft Client Area.', 'bestwebsoft' ); ?> |
| 841 | </div> |
| 842 | </td> |
| 843 | </tr> |
| 844 | </table> |
| 845 | <?php } |
| 846 | |
| 847 | /** |
| 848 | * Save plugin options to the database |
| 849 | * @access private |
| 850 | * @param ab |
| 851 | * @return array The action results |
| 852 | */ |
| 853 | private function save_options_license_key() { |
| 854 | global $wp_version, $bstwbsftwppdtplgns_options; |
| 855 | /*$empty_field_error - added to avoid error when 1 field is empty while another field contains license key*/ |
| 856 | |
| 857 | $error = $message = $empty_field_error = ''; |
| 858 | |
| 859 | foreach ( $this->licenses as $single_license) { |
| 860 | $bws_license_key = ( isset( $_POST[ ( ! empty( $single_license['pro_slug'] ) ) ? 'bws_license_key_' . $single_license['pro_slug'] : 'bws_license_key_' . $single_license['slug'] ] ) ) ? stripslashes( sanitize_text_field( $_POST[ ( ! empty( $single_license['pro_slug'] ) ) ? 'bws_license_key_' . $single_license['pro_slug'] : 'bws_license_key_' . $single_license['slug'] ] ) ) : ''; |
| 861 | if ( '' != $bws_license_key ) { |
| 862 | if ( strlen( $bws_license_key ) != 18 ) { |
| 863 | $error = __( 'Wrong license key', 'bestwebsoft' ); |
| 864 | } else { |
| 865 | |
| 866 | /* CHECK license key */ |
| 867 | if ( $this->is_pro && empty( $single_license['pro_basename'] ) ) { |
| 868 | delete_transient( 'bws_plugins_update' ); |
| 869 | if ( ! $this->all_plugins ) { |
| 870 | if ( ! function_exists( 'get_plugins' ) ) { |
| 871 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 872 | } |
| 873 | $this->all_plugins = get_plugins(); |
| 874 | } |
| 875 | $current = get_site_transient( 'update_plugins' ); |
| 876 | |
| 877 | if ( ! empty( $this->all_plugins ) && ! empty( $current ) && isset( $current->response ) && is_array( $current->response ) ) { |
| 878 | $to_send = array(); |
| 879 | $to_send["plugins"][ $single_license['basename'] ] = $this->all_plugins[ $single_license['basename'] ]; |
| 880 | $to_send["plugins"][ $single_license['basename'] ]["bws_license_key"] = $bws_license_key; |
| 881 | $to_send["plugins"][ $single_license['basename'] ]["bws_illegal_client"] = true; |
| 882 | $options = array( |
| 883 | 'timeout' => ( ( defined( 'DOING_CRON' ) && DOING_CRON ) ? 30 : 3 ), |
| 884 | 'body' => array( 'plugins' => serialize( $to_send ) ), |
| 885 | 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) |
| 886 | ); |
| 887 | $raw_response = wp_remote_post( 'https://bestwebsoft.com/wp-content/plugins/paid-products/plugins/pro-license-check/1.0/', $options ); |
| 888 | |
| 889 | if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { |
| 890 | $error = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ': <a href=https://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); |
| 891 | } else { |
| 892 | $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); |
| 893 | if ( is_array( $response ) && ! empty( $response ) ) { |
| 894 | foreach ( $response as $single_response ) { |
| 895 | if ( "wrong_license_key" == $single_response->package ) { |
| 896 | $error = __( 'Wrong license key.', 'bestwebsoft' ); |
| 897 | } else if ( "wrong_domain" == $single_response->package ) { |
| 898 | $error = __( 'This license key is bound to another site.', 'bestwebsoft' ); |
| 899 | } else if ( "time_out" == $single_response->package ) { |
| 900 | $message = __( 'This license key is valid, but Your license has expired. If you want to update our plugin in future, you should extend the license.', 'bestwebsoft' ); |
| 901 | } elseif ( "you_are_banned" == $single_response->package ) { |
| 902 | $error = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' ); |
| 903 | } elseif ( "duplicate_domen_for_trial" == $single_response->package ) { |
| 904 | $error = __( "Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' ); |
| 905 | } |
| 906 | if ( empty( $error ) ) { |
| 907 | if ( empty( $message ) ) { |
| 908 | if ( isset( $single_response->trial ) ) { |
| 909 | $message = __( 'The Pro Trial license key is valid.', 'bestwebsoft' ); |
| 910 | } else { |
| 911 | $message = __( 'The license key is valid.', 'bestwebsoft' ); |
| 912 | } |
| 913 | |
| 914 | if ( ! empty( $single_response->time_out ) ) { |
| 915 | $message .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $single_response->time_out . '.'; |
| 916 | } else { |
| 917 | /* lifetime */ |
| 918 | $single_response->time_out = NULL; |
| 919 | } |
| 920 | |
| 921 | if ( isset( $single_response->trial ) && $this->is_trial ) { |
| 922 | $message .= ' ' . sprintf( __( 'In order to continue using the plugin it is necessary to buy a %s license.', 'bestwebsoft' ), '<a href="' . esc_url( $this->plugins_info['PluginURI'] . '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version ) . '" target="_blank" title="' . $this->plugins_info["Name"] . '">Pro</a>' ); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | if ( isset( $single_response->trial ) ) { |
| 927 | $bstwbsftwppdtplgns_options['trial'][ $single_license['basename'] ] = 1; |
| 928 | } else { |
| 929 | unset( $bstwbsftwppdtplgns_options['trial'][ $single_license['basename'] ] ); |
| 930 | } |
| 931 | |
| 932 | if ( isset( $single_response->nonprofit ) ) { |
| 933 | $bstwbsftwppdtplgns_options['nonprofit'][ $single_license['basename'] ] = 1; |
| 934 | } else { |
| 935 | unset( $bstwbsftwppdtplgns_options['nonprofit'][ $single_license['basename'] ] ); |
| 936 | } |
| 937 | |
| 938 | if ( ! isset( $bstwbsftwppdtplgns_options[ $single_license['basename'] ] ) || $bstwbsftwppdtplgns_options[ $single_license['basename'] ] != $bws_license_key ) { |
| 939 | $bstwbsftwppdtplgns_options[ $single_license['basename'] ] = $bws_license_key; |
| 940 | |
| 941 | $file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt", "w+" ); |
| 942 | if ( $file ) { |
| 943 | @fwrite( $file, $bws_license_key ); |
| 944 | @fclose( $file ); |
| 945 | } |
| 946 | $update_option = true; |
| 947 | } |
| 948 | |
| 949 | if ( isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $single_license['basename'] ] ) ) { |
| 950 | unset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $single_license['basename'] ] ); |
| 951 | $update_option = true; |
| 952 | } |
| 953 | |
| 954 | if ( ! isset( $bstwbsftwppdtplgns_options['time_out'][ $single_license['basename'] ] ) || $bstwbsftwppdtplgns_options['time_out'][ $single_license['basename'] ] != $single_response->time_out ) { |
| 955 | $bstwbsftwppdtplgns_options['time_out'][ $single_license['basename'] ] = $single_response->time_out; |
| 956 | $update_option = true; |
| 957 | } |
| 958 | |
| 959 | if ( isset( $update_option ) ) { |
| 960 | if ( $this->is_multisite ) { |
| 961 | update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
| 962 | } else { |
| 963 | update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
| 964 | } |
| 965 | } |
| 966 | } |
| 967 | } |
| 968 | } else { |
| 969 | $error = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ' <a href=https://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | /* Go Pro */ |
| 974 | } else { |
| 975 | |
| 976 | $bws_license_plugin = stripslashes( sanitize_text_field( $_POST[ ( ! empty( $single_license['pro_slug'] ) ) ? 'bws_license_plugin_' . $single_license['pro_slug'] : 'bws_license_plugin_' . $single_license['slug'] ] ) ); |
| 977 | if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { |
| 978 | $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1; |
| 979 | } else { |
| 980 | $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1; |
| 981 | $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time(); |
| 982 | } |
| 983 | |
| 984 | /* download Pro */ |
| 985 | if ( ! $this->all_plugins ) { |
| 986 | if ( ! function_exists( 'get_plugins' ) ) { |
| 987 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 988 | } |
| 989 | $this->all_plugins = get_plugins(); |
| 990 | } |
| 991 | |
| 992 | if ( ! array_key_exists( $bws_license_plugin, $this->all_plugins ) ) { |
| 993 | $current = get_site_transient( 'update_plugins' ); |
| 994 | if ( ! empty( $current ) && isset( $current->response ) && is_array( $current->response ) ) { |
| 995 | $to_send = array(); |
| 996 | $to_send["plugins"][ $bws_license_plugin ] = array(); |
| 997 | $to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key; |
| 998 | $to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true; |
| 999 | $options = array( |
| 1000 | 'timeout' => ( ( defined( 'DOING_CRON' ) && DOING_CRON ) ? 30 : 3 ), |
| 1001 | 'body' => array( 'plugins' => serialize( $to_send ) ), |
| 1002 | 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) |
| 1003 | ); |
| 1004 | $raw_response = wp_remote_post( 'https://bestwebsoft.com/wp-content/plugins/paid-products/plugins/pro-license-check/1.0/', $options ); |
| 1005 | |
| 1006 | if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { |
| 1007 | $error = __( "Something went wrong. Please try again later. If the error appears again, please contact us", 'bestwebsoft' ) . ': <a href="https://support.bestwebsoft.com">BestWebSoft</a>. ' . __( "We are sorry for inconvenience.", 'bestwebsoft' ); |
| 1008 | } else { |
| 1009 | $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); |
| 1010 | if ( is_array( $response ) && ! empty( $response ) ) { |
| 1011 | foreach ( $response as $single_response ) { |
| 1012 | if ( "wrong_license_key" == $single_response->package ) { |
| 1013 | $error = __( "Wrong license key.", 'bestwebsoft' ); |
| 1014 | } elseif ( "wrong_domain" == $single_response->package ) { |
| 1015 | $error = __( "This license key is bound to another site.", 'bestwebsoft' ); |
| 1016 | } elseif ( "you_are_banned" == $single_response->package ) { |
| 1017 | $error = __( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); |
| 1018 | } elseif ( "time_out" == $single_response->package ) { |
| 1019 | $error = sprintf( __( "Unfortunately, Your license has expired. To continue getting top-priority support and plugin updates, you should extend it in your %s.", 'bestwebsoft' ), ' <a href="https://bestwebsoft.com/client-area">Client Area</a>' ); |
| 1020 | } elseif ( "duplicate_domen_for_trial" == $single_response->package ) { |
| 1021 | $error = __( "Unfortunately, the Pro licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' ); |
| 1022 | } |
| 1023 | } |
| 1024 | if ( empty( $error ) ) { |
| 1025 | $bws_license_plugin = ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename']; |
| 1026 | |
| 1027 | $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; |
| 1028 | $this->pro_plugin_is_activated = true; |
| 1029 | } |
| 1030 | } else { |
| 1031 | $error = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.", 'bestwebsoft' ); |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | } else { |
| 1036 | $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; |
| 1037 | /* activate Pro */ |
| 1038 | if ( ! is_plugin_active( $bws_license_plugin ) ) { |
| 1039 | if ( $this->is_multisite && is_plugin_active_for_network( ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ) ) { |
| 1040 | /* if multisite and free plugin is network activated */ |
| 1041 | $network_wide = true; |
| 1042 | } else { |
| 1043 | /* activate on a single blog */ |
| 1044 | $network_wide = false; |
| 1045 | } |
| 1046 | activate_plugin( $bws_license_plugin, null, $network_wide ); |
| 1047 | $this->pro_plugin_is_activated = true; |
| 1048 | } |
| 1049 | } |
| 1050 | /* add 'track_usage' for Pro version */ |
| 1051 | if ( ! empty( $bstwbsftwppdtplgns_options['track_usage'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] ) && |
| 1052 | empty( $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] ) ) { |
| 1053 | $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] = $bstwbsftwppdtplgns_options['track_usage'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ]; |
| 1054 | } |
| 1055 | |
| 1056 | if ( $this->is_multisite ) { |
| 1057 | update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
| 1058 | } else { |
| 1059 | update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
| 1060 | } |
| 1061 | |
| 1062 | if ( $this->pro_plugin_is_activated ) { |
| 1063 | delete_transient( 'bws_plugins_update' ); |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | } else { |
| 1068 | $empty_field_error = __( "Please, enter Your license key", 'bestwebsoft' ); |
| 1069 | } |
| 1070 | } |
| 1071 | return compact( 'error', 'message', 'empty_field_error' ); |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * Display help phrase |
| 1076 | * @access public |
| 1077 | * @param void |
| 1078 | * @return array The action results |
| 1079 | */ |
| 1080 | public function help_phrase() { |
| 1081 | echo '<div class="bws_tab_description">' . __( 'Need Help?', 'bestwebsoft' ) . ' '; |
| 1082 | if ( '' != $this->doc_link ) |
| 1083 | echo '<a href="' . esc_url( $this->doc_link ) . '" target="_blank">' . __( 'Read the Instruction', 'bestwebsoft' ); |
| 1084 | else |
| 1085 | echo '<a href="https://support.bestwebsoft.com/hc/en-us/" target="_blank">' . __( 'Visit Help Center', 'bestwebsoft' ); |
| 1086 | if ( '' != $this->doc_video_link ) |
| 1087 | echo '</a>' . ' ' . __( 'or', 'bestwebsoft' ) . ' ' . '<a href="' . esc_url( $this->doc_video_link ) . '" target="_blank">' . __( 'Watch the Video', 'bestwebsoft' ); |
| 1088 | echo '</a></div>'; |
| 1089 | } |
| 1090 | |
| 1091 | public function bws_pro_block_links() { |
| 1092 | global $wp_version; ?> |
| 1093 | <div class="bws_pro_version_tooltip"> |
| 1094 | <a class="bws_button" href="<?php echo esc_url( $this->plugins_info['PluginURI'] ); ?>?k=<?php echo $this->link_key; ?>&pn=<?php echo $this->link_pn; ?>&v=<?php echo $this->plugins_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="<?php echo $this->plugins_info["Name"]; ?>"><?php _e( 'Upgrade to Pro', 'bestwebsoft' ); ?></a> |
| 1095 | <?php if ( $this->trial_days !== false ) { ?> |
| 1096 | <span class="bws_trial_info"> |
| 1097 | <?php _e( 'or', 'bestwebsoft' ); ?> |
| 1098 | <a href="<?php echo esc_url( $this->plugins_info['PluginURI'] . '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version ); ?>" target="_blank" title="<?php echo $this->plugins_info["Name"]; ?>"><?php _e( 'Start Your Free Trial', 'bestwebsoft' ); ?></a> |
| 1099 | </span> |
| 1100 | <?php } ?> |
| 1101 | <div class="clear"></div> |
| 1102 | </div> |
| 1103 | <?php } |
| 1104 | |
| 1105 | /** |
| 1106 | * Restore plugin options to defaults |
| 1107 | * @access public |
| 1108 | * @param void |
| 1109 | * @return void |
| 1110 | */ |
| 1111 | public function restore_options() { |
| 1112 | unset( |
| 1113 | $this->default_options['first_install'], |
| 1114 | $this->default_options['suggest_feature_banner'], |
| 1115 | $this->default_options['display_settings_notice'] |
| 1116 | ); |
| 1117 | /** |
| 1118 | * filter - Change default_options array OR process custom functions |
| 1119 | */ |
| 1120 | $this->options = apply_filters( __CLASS__ . '_additional_restore_options', $this->default_options ); |
| 1121 | if ( $this->is_network_options ) { |
| 1122 | $this->options['network_apply'] = 'default'; |
| 1123 | $this->options['network_view'] = '1'; |
| 1124 | $this->options['network_change'] = '1'; |
| 1125 | update_site_option( $this->prefix . '_options', $this->options ); |
| 1126 | } else { |
| 1127 | update_option( $this->prefix . '_options', $this->options ); |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | public function add_request_feature() { ?> |
| 1132 | <div id="bws_request_feature" class="widget-access-link"> |
| 1133 | <button type="button" class="button" ><?php _e( 'Request a Feature', 'bestwebsoft' ); ?></button> |
| 1134 | </div> |
| 1135 | <?php $modal_html = '<div class="bws-modal bws-modal-deactivation-feedback bws-modal-request-feature"> |
| 1136 | <div class="bws-modal-dialog"> |
| 1137 | <div class="bws-modal-body"> |
| 1138 | <h2>' . sprintf( __( 'How can we improve %s?', 'bestwebsoft' ), $this->plugins_info['Name'] ) . '</h2> |
| 1139 | <div class="bws-modal-panel active"> |
| 1140 | <p>' . __( 'We look forward to hear your ideas.', 'bestwebsoft' ) . '</p> |
| 1141 | <p> |
| 1142 | <textarea placeholder="' . __( 'Describe your idea', 'bestwebsoft' ) . '..."></textarea> |
| 1143 | </p> |
| 1144 | <label class="bws-modal-anonymous-label"> |
| 1145 | <input type="checkbox" /> ' . __( 'Send website data and allow to contact me back', 'bestwebsoft' ) . ' |
| 1146 | </label> |
| 1147 | </div> |
| 1148 | </div> |
| 1149 | <div class="bws-modal-footer"> |
| 1150 | <a href="#" class="button disabled bws-modal-button button-primary">' . __( 'Submit', 'bestwebsoft' ) . '</a> |
| 1151 | <span class="bws-modal-processing hidden">' . __( 'Processing', 'bestwebsoft' ) . '...</span> |
| 1152 | <span class="bws-modal-thank-you hidden">' . __( 'Thank you!', 'bestwebsoft' ) . '</span> |
| 1153 | <div class="clear"></div> |
| 1154 | </div> |
| 1155 | </div> |
| 1156 | </div>'; |
| 1157 | |
| 1158 | $script = "(function($) { |
| 1159 | var modalHtml = " . json_encode( $modal_html ) . ", |
| 1160 | \$modal = $( modalHtml ); |
| 1161 | |
| 1162 | \$modal.appendTo( $( 'body' ) ); |
| 1163 | |
| 1164 | $( '#bws_request_feature .button' ).on( 'click', function() { |
| 1165 | /* Display the dialog box.*/ |
| 1166 | \$modal.addClass( 'active' ); |
| 1167 | $( 'body' ).addClass( 'has-bws-modal' ); |
| 1168 | }); |
| 1169 | |
| 1170 | \$modal.on( 'keypress', 'textarea', function( evt ) { |
| 1171 | BwsModalEnableButton(); |
| 1172 | }); |
| 1173 | |
| 1174 | \$modal.on( 'click', '.bws-modal-footer .button', function( evt ) { |
| 1175 | evt.preventDefault(); |
| 1176 | |
| 1177 | if ( $( this ).hasClass( 'disabled' ) ) { |
| 1178 | return; |
| 1179 | } |
| 1180 | var info = \$modal.find( 'textarea' ).val(); |
| 1181 | |
| 1182 | if ( info.length == 0 ) { |
| 1183 | return; |
| 1184 | } |
| 1185 | |
| 1186 | var _parent = $( this ).parents( '.bws-modal:first' ), |
| 1187 | _this = $( this ); |
| 1188 | |
| 1189 | var is_anonymous = ( \$modal.find( '.bws-modal-anonymous-label' ).find( 'input' ).is( ':checked' ) ) ? 0 : 1; |
| 1190 | |
| 1191 | $.ajax({ |
| 1192 | url : ajaxurl, |
| 1193 | method : 'POST', |
| 1194 | data : { |
| 1195 | 'action' : 'bws_submit_request_feature_action', |
| 1196 | 'plugin' : '" . $this->plugin_basename . "', |
| 1197 | 'info' : info, |
| 1198 | 'is_anonymous' : is_anonymous, |
| 1199 | 'bws_ajax_nonce' : '" . wp_create_nonce( 'bws_ajax_nonce' ) . "' |
| 1200 | }, |
| 1201 | beforeSend: function() { |
| 1202 | _parent.find( '.bws-modal-footer .bws-modal-button' ).hide(); |
| 1203 | _parent.find( '.bws-modal-footer .bws-modal-processing' ).show(); |
| 1204 | _parent.find( 'textarea, input' ).attr( 'disabled', 'disabled' ); |
| 1205 | }, |
| 1206 | complete : function( message ) { |
| 1207 | _parent.find( '.bws-modal-footer .bws-modal-processing' ).hide(); |
| 1208 | _parent.find( '.bws-modal-footer .bws-modal-thank-you' ).show(); |
| 1209 | } |
| 1210 | }); |
| 1211 | }); |
| 1212 | |
| 1213 | /* If the user has clicked outside the window, cancel it. */ |
| 1214 | \$modal.on( 'click', function( evt ) { |
| 1215 | var \$target = $( evt.target ); |
| 1216 | |
| 1217 | /* If the user has clicked anywhere in the modal dialog, just return. */ |
| 1218 | if ( \$target.hasClass( 'bws-modal-body' ) || \$target.hasClass( 'bws-modal-footer' ) ) { |
| 1219 | return; |
| 1220 | } |
| 1221 | |
| 1222 | /* If the user has not clicked the close button and the clicked element is inside the modal dialog, just return. */ |
| 1223 | if ( ! \$target.hasClass( 'bws-modal-button-close' ) && ( \$target.parents( '.bws-modal-body' ).length > 0 || \$target.parents( '.bws-modal-footer' ).length > 0 ) ) { |
| 1224 | return; |
| 1225 | } |
| 1226 | |
| 1227 | /* Close the modal dialog */ |
| 1228 | \$modal.removeClass( 'active' ); |
| 1229 | $( 'body' ).removeClass( 'has-bws-modal' ); |
| 1230 | |
| 1231 | return false; |
| 1232 | }); |
| 1233 | |
| 1234 | function BwsModalEnableButton() { |
| 1235 | \$modal.find( '.bws-modal-button' ).removeClass( 'disabled' ).show(); |
| 1236 | \$modal.find( '.bws-modal-processing' ).hide(); |
| 1237 | } |
| 1238 | |
| 1239 | function BwsModalDisableButton() { |
| 1240 | \$modal.find( '.bws-modal-button' ).addClass( 'disabled' ); |
| 1241 | } |
| 1242 | |
| 1243 | function BwsModalShowPanel() { |
| 1244 | \$modal.find( '.bws-modal-panel' ).addClass( 'active' ); |
| 1245 | } |
| 1246 | })(jQuery);"; |
| 1247 | |
| 1248 | /* add script in FOOTER */ |
| 1249 | wp_register_script( 'bws-request-feature-dialog', '', array( 'jquery' ), false, true ); |
| 1250 | wp_enqueue_script( 'bws-request-feature-dialog' ); |
| 1251 | wp_add_inline_script( 'bws-request-feature-dialog', sprintf( $script ) ); |
| 1252 | } |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | /** |
| 1258 | * Called after the user has submitted his reason for deactivating the plugin. |
| 1259 | * |
| 1260 | * @since 2.1.3 |
| 1261 | */ |
| 1262 | if ( ! function_exists( 'bws_submit_request_feature_action' ) ) { |
| 1263 | function bws_submit_request_feature_action() { |
| 1264 | global $bstwbsftwppdtplgns_options, $wp_version, $bstwbsftwppdtplgns_active_plugins, $current_user; |
| 1265 | |
| 1266 | wp_verify_nonce( $_REQUEST['bws_ajax_nonce'], 'bws_ajax_nonce' ); |
| 1267 | |
| 1268 | $basename = isset( $_REQUEST['plugin'] ) ? stripcslashes( sanitize_text_field( $_REQUEST['plugin'] ) ) : ''; |
| 1269 | $info = stripcslashes( sanitize_text_field( $_REQUEST['info'] ) ); |
| 1270 | |
| 1271 | if ( empty( $info ) || empty( $basename ) ) { |
| 1272 | exit; |
| 1273 | } |
| 1274 | |
| 1275 | $info = substr( $info, 0, 255 ); |
| 1276 | $is_anonymous = isset( $_REQUEST['is_anonymous'] ) && 1 == $_REQUEST['is_anonymous']; |
| 1277 | |
| 1278 | $options = array( |
| 1279 | 'product' => $basename, |
| 1280 | 'info' => $info, |
| 1281 | ); |
| 1282 | |
| 1283 | if ( ! $is_anonymous ) { |
| 1284 | if ( ! isset( $bstwbsftwppdtplgns_options ) ) |
| 1285 | $bstwbsftwppdtplgns_options = ( is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' ); |
| 1286 | |
| 1287 | if ( ! empty( $bstwbsftwppdtplgns_options['track_usage']['usage_id'] ) ) { |
| 1288 | $options['usage_id'] = $bstwbsftwppdtplgns_options['track_usage']['usage_id']; |
| 1289 | } else { |
| 1290 | $options['usage_id'] = false; |
| 1291 | $options['url'] = get_bloginfo( 'url' ); |
| 1292 | $options['wp_version'] = $wp_version; |
| 1293 | $options['is_active'] = false; |
| 1294 | $options['version'] = $bstwbsftwppdtplgns_active_plugins[ $basename ]['Version']; |
| 1295 | } |
| 1296 | |
| 1297 | $options['email'] = $current_user->data->user_email; |
| 1298 | } |
| 1299 | |
| 1300 | /* send data */ |
| 1301 | $raw_response = wp_remote_post( 'https://bestwebsoft.com/wp-content/plugins/products-statistics/request-feature/', array( |
| 1302 | 'method' => 'POST', |
| 1303 | 'body' => $options, |
| 1304 | 'timeout' => 15, |
| 1305 | ) ); |
| 1306 | |
| 1307 | if ( ! is_wp_error( $raw_response ) && 200 == wp_remote_retrieve_response_code( $raw_response ) ) { |
| 1308 | if ( ! $is_anonymous ) { |
| 1309 | $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); |
| 1310 | |
| 1311 | if ( is_array( $response ) && ! empty( $response['usage_id'] ) && $response['usage_id'] != $options['usage_id'] ) { |
| 1312 | $bstwbsftwppdtplgns_options['track_usage']['usage_id'] = $response['usage_id']; |
| 1313 | |
| 1314 | if ( is_multisite() ) |
| 1315 | update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
| 1316 | else |
| 1317 | update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | echo 'done'; |
| 1322 | } else { |
| 1323 | echo $response->get_error_code() . ': ' . $response->get_error_message(); |
| 1324 | } |
| 1325 | exit; |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | add_action( 'wp_ajax_bws_submit_request_feature_action', 'bws_submit_request_feature_action' ); |