diff -r be944660c56a -r 3d72ae0968f4 wp/wp-content/plugins/portfolio/bws_menu/class-bws-settings.php --- a/wp/wp-content/plugins/portfolio/bws_menu/class-bws-settings.php Wed Sep 21 18:19:35 2022 +0200 +++ b/wp/wp-content/plugins/portfolio/bws_menu/class-bws-settings.php Tue Sep 27 16:37:53 2022 +0200 @@ -1,6 +1,7 @@ '', - 'prefix' => '', - 'plugins_info' => array(), - 'default_options' => array(), - 'options' => array(), - 'is_network_options' => false, - 'tabs' => array(), - 'doc_link' => '', - 'doc_video_link' => '', - 'wp_slug' => '', - 'demo_data' => false, - /* if this is free version and pro exist */ - 'link_key' => '', - 'link_pn' => '', - 'trial_days' => false, - 'licenses' => array() - ) ); + $args = wp_parse_args( + $args, + array( + 'plugin_basename' => '', + 'prefix' => '', + 'plugins_info' => array(), + 'default_options' => array(), + 'options' => array(), + 'is_network_options' => false, + 'tabs' => array(), + 'doc_link' => '', + 'doc_video_link' => '', + 'wp_slug' => '', + 'demo_data' => false, + /* if this is free version and pro exist */ + 'link_key' => '', + 'link_pn' => '', + 'trial_days' => false, + 'licenses' => array(), + ) + ); $args['plugins_info']['Name'] = str_replace( ' by BestWebSoft', '', $args['plugins_info']['Name'] ); - $this->plugin_basename = $args['plugin_basename']; - $this->prefix = $args['prefix']; - $this->plugins_info = $args['plugins_info']; - $this->options = $args['options']; - $this->default_options = $args['default_options']; - $this->wp_slug = $args['wp_slug']; - $this->demo_data = $args['demo_data']; + $this->plugin_basename = $args['plugin_basename']; + $this->prefix = $args['prefix']; + $this->plugins_info = $args['plugins_info']; + $this->options = $args['options']; + $this->default_options = $args['default_options']; + $this->wp_slug = $args['wp_slug']; + $this->demo_data = $args['demo_data']; - $this->tabs = $args['tabs']; - $this->is_network_options = $args['is_network_options']; + $this->tabs = $args['tabs']; + $this->is_network_options = $args['is_network_options']; - $this->doc_link = $args['doc_link']; - $this->doc_video_link = $args['doc_video_link']; + $this->doc_link = $args['doc_link']; + $this->doc_video_link = $args['doc_video_link']; - $this->link_key = $args['link_key']; - $this->link_pn = $args['link_pn']; - $this->trial_days = $args['trial_days']; - $this->licenses = $args['licenses']; + $this->link_key = $args['link_key']; + $this->link_pn = $args['link_pn']; + $this->trial_days = $args['trial_days']; + $this->licenses = $args['licenses']; $this->pro_page = $this->bws_license_plugin = ''; /* get $bws_plugins */ - require( dirname( __FILE__ ) . '/product_list.php' ); + require dirname( __FILE__ ) . '/product_list.php'; if ( isset( $bws_plugins[ $this->plugin_basename ] ) ) { if ( isset( $bws_plugins[ $this->plugin_basename ]['pro_settings'] ) ) { - $this->pro_page = $bws_plugins[ $this->plugin_basename ]['pro_settings']; - $this->bws_license_plugin = $bws_plugins[ $this->plugin_basename ]['pro_version']; - } + $this->pro_page = $bws_plugins[ $this->plugin_basename ]['pro_settings']; + $this->bws_license_plugin = $bws_plugins[ $this->plugin_basename ]['pro_version']; + } - $this->bws_plugin_link = substr( $bws_plugins[ $this->plugin_basename ]['link'],0 , strpos( $bws_plugins[ $this->plugin_basename ]['link'], '?' ) ); + $this->bws_plugin_link = substr( $bws_plugins[ $this->plugin_basename ]['link'], 0, strpos( $bws_plugins[ $this->plugin_basename ]['link'], '?' ) ); - if ( ! empty( $this->link_key ) && ! empty( $this->link_pn ) ) - $this->bws_plugin_link .= '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version; + if ( ! empty( $this->link_key ) && ! empty( $this->link_pn ) ) { + $this->bws_plugin_link .= '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info['Version'] . '&wp_v=' . $wp_version; + } } $this->hide_pro_tabs = bws_hide_premium_options_check( $this->options ); - $this->version = '1.0.0'; - $this->is_multisite = is_multisite(); + $this->version = '1.0.0'; + $this->is_multisite = is_multisite(); if ( empty( $this->pro_page ) && array_key_exists( 'license', $this->tabs ) ) { - $this->is_pro = true; + $this->is_pro = true; $this->licenses[ $this->plugins_info['TextDomain'] ] = array( 'name' => $this->plugins_info['Name'], 'slug' => $this->plugins_info['TextDomain'], - 'basename' => $this->plugin_basename + 'basename' => $this->plugin_basename, ); } else { $this->licenses[ $this->plugins_info['TextDomain'] ] = array( - 'name' => $this->plugins_info['Name'], - 'slug' => $this->plugins_info['TextDomain'], - 'pro_slug' => substr( $this->bws_license_plugin, 0, stripos( $this->bws_license_plugin, '/' ) ), - 'basename' => $this->plugin_basename, - 'pro_basename' => $this->bws_license_plugin + 'name' => $this->plugins_info['Name'], + 'slug' => $this->plugins_info['TextDomain'], + 'pro_slug' => substr( $this->bws_license_plugin, 0, stripos( $this->bws_license_plugin, '/' ) ), + 'basename' => $this->plugin_basename, + 'pro_basename' => $this->bws_license_plugin, ); } } /** * Displays the content of the "Settings" on the plugin settings page + * * @access public * @param void * @return void @@ -155,34 +162,41 @@ $this->demo_data->bws_demo_confirm(); } else { bws_show_settings_notice(); ?> -
-
-
-
+ +
+
+
display_tabs(); ?> -
-
-
-
-

-
-
-
-
- is_pro ) { +
+
+
+
+

+
+
+
+
+ + is_pro ) { 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'] ) ) { - $license_type = 'Pro'; + $license_type = 'Pro'; $license_status = __( 'Inactive', 'bestwebsoft' ) . ' ' . __( 'Learn More', 'bestwebsoft' ) . ''; } else { $finish = strtotime( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ); - $today = strtotime( date( "m/d/Y" ) ); + $today = strtotime( gmdate( 'm/d/Y' ) ); if ( isset( $bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] ) ) { $license_type = 'Trial Pro'; if ( $finish < $today ) { $license_status = __( 'Expired', 'bestwebsoft' ); } else { - $daysleft = floor( ( $finish - $today ) / ( 60*60*24 ) ); + $daysleft = floor( ( $finish - $today ) / ( 60 * 60 * 24 ) ); $license_status = sprintf( __( '%s day(-s) left', 'bestwebsoft' ), $daysleft ); } $license_status .= '. ' . __( 'Upgrade to Pro', 'bestwebsoft' ) . ''; @@ -194,118 +208,157 @@ $license_status = __( 'Active', 'bestwebsoft' ); } } - } ?> -
- : -
-
- : -
+ } + ?> +
+ : +
+
+ : +
-
- : plugins_info['Version']; ?> -
-
-
-
-
-
- - +
+ : plugins_info['Version'] ); ?> +
+ +
+
+
+
+
+ + plugin_basename, 'bws_nonce_name' ); ?> -
-
-
-
-
-
- +
+
+
+
+
+ -
-
-
- +
+
+
+ -
- -
- wp_slug ) ) - bws_plugin_reviews_block( $this->plugins_info['Name'], $this->wp_slug ); ?> -
-
- -
- +
+ + plugin_basename, 'bws_nonce_name' ); ?> +
+ wp_slug ) ) { + bws_plugin_reviews_block( $this->plugins_info['Name'], $this->wp_slug );} + ?> +
+
+ +
+ -
-
    + public function display_tabs() { + ?> +
    +
      display_tabs_list(); ?> -
    +
display_tabs_content(); ?> -
- -
-
+ + + tabs as $tab_slug => $data ) { - if ( ! empty( $data['is_pro'] ) && $this->hide_pro_tabs ) + if ( ! empty( $data['is_pro'] ) && $this->hide_pro_tabs ) { continue; + } $tab_class = 'bws-tab-' . $tab_slug; - if ( ! empty( $data['is_pro'] ) ) + if ( ! empty( $data['is_pro'] ) ) { $tab_class .= ' bws_pro_tab'; - if ( ! empty( $data['class'] ) ) - $tab_class .= ' ' . $data['class']; ?> -
  • - - - -
  • - +
  • + + + +
  • + tabs as $tab_slug => $data ) { - if ( ! empty( $data['is_pro'] ) && $this->hide_pro_tabs ) - continue; ?> -
    - hide_pro_tabs ) { + continue; + } + ?> +
    + -
    - +
    + plugin_basename, 'bws_nonce_name' ) ) { $result = $this->save_options_license_key(); - if ( ! empty( $result['empty_field_error'] ) ) + if ( ! empty( $result['empty_field_error'] ) ) { $error = $result['empty_field_error']; - if ( ! empty( $result['error'] ) ) + } + if ( ! empty( $result['error'] ) ) { $error = $result['error']; - if ( ! empty( $result['message'] ) ) + } + if ( ! empty( $result['message'] ) ) { $message = $result['message']; - if ( ! empty( $result['notice'] ) ) + } + if ( ! empty( $result['notice'] ) ) { $notice = $result['notice']; + } /* check demo data */ } else { $demo_result = ! empty( $this->demo_data ) ? $this->demo_data->bws_handle_demo_data() : false; @@ -331,30 +388,30 @@ if ( ! empty( $demo_result ) && is_array( $demo_result ) ) { $error = $demo_result['error']; $message = $demo_result['done']; - if ( ! empty( $demo_result['done'] ) && ! empty( $demo_result['options'] ) ) + if ( ! empty( $demo_result['done'] ) && ! empty( $demo_result['options'] ) ) { $this->options = $demo_result['options']; + } } /* Save options */ - } 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' ) ) { + } 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' ) ) { /* save tabs */ $result = $this->save_options(); - if ( ! empty( $result['error'] ) ) + if ( ! empty( $result['error'] ) ) { $error = $result['error']; - if ( ! empty( $result['message'] ) ) + } + if ( ! empty( $result['message'] ) ) { $message = $result['message']; - if ( ! empty( $result['notice'] ) ) + } + if ( ! empty( $result['notice'] ) ) { $notice = $result['notice']; + } - if ( '' == $this->change_permission_attr ) { + if ( '' === $this->change_permission_attr ) { /* save `misc` tab */ $result = $this->save_options_misc(); - if ( ! empty( $result['notice'] ) ) + if ( ! empty( $result['notice'] ) ) { $notice .= $result['notice']; - } - - if ( array_key_exists( 'custom_code', $this->tabs ) ) { - /* save `custom code` tab */ - $this->save_options_custom_code(); + } } } } @@ -364,25 +421,44 @@ /** * Display error\message\notice + * * @access public * @param $save_results - array with error\message\notice * @return void */ public function display_messages( $save_results ) { /** - * action - Display custom error\message\notice + * Action - Display custom error\message\notice */ - do_action( __CLASS__ . '_display_custom_messages', $save_results ); ?> -
    >

    -
    >

    -
    >

    - +
    + >

    +
    + >

    +
    + >

    + custom_code_args = array( 'is_css_active' => false, - 'content_css' => '', - 'css_writeable' => false, + 'content_css' => '', + 'css_writeable' => false, 'is_php_active' => false, - 'content_php' => '', - 'php_writeable' => false, - 'is_js_active' => false, - 'content_js' => '', - 'js_writeable' => false, + 'content_php' => '', + 'php_writeable' => false, + 'is_js_active' => false, + 'content_js' => '', + 'js_writeable' => false, ); - if ( ! $this->upload_dir ) + if ( ! $this->upload_dir ) { $this->upload_dir = wp_upload_dir(); + } $folder = $this->upload_dir['basedir'] . '/bws-custom-code'; - if ( ! $this->upload_dir["error"] ) { - if ( ! is_dir( $folder ) ) - wp_mkdir_p( $folder, 0755 ); - $index_file = $this->upload_dir['basedir'] . '/bws-custom-code/index.php'; - if ( ! file_exists( $index_file ) ) { - if ( $f = fopen( $index_file, 'w+' ) ) - fclose( $f ); - } + if ( $this->is_multisite ) { + $this->custom_code_args['blog_id'] = get_current_blog_id(); } - if ( $this->is_multisite ) - $this->custom_code_args['blog_id'] = get_current_blog_id(); + WP_Filesystem(); foreach ( array( 'css', 'php', 'js' ) as $extension ) { - $file = 'bws-custom-code.' . $extension; + $file = 'bws-custom-code.' . $extension; $real_file = $folder . '/' . $file; - - if ( file_exists( $real_file ) ) { + + if ( $wp_filesystem->exists( $real_file ) ) { update_recently_edited( $real_file ); - $this->custom_code_args["content_{$extension}"] = file_get_contents( $real_file ); + $this->custom_code_args[ "content_{$extension}" ] = $wp_filesystem->get_contents( $real_file );//file_get_contents( $real_file ); if ( ( $this->is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ) ) || - ( ! $this->is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) ) ) { - $this->custom_code_args["is_{$extension}_active"] = true; + ( ! $this->is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) ) ) { + $this->custom_code_args[ "is_{$extension}_active" ] = true; + } + if ( is_writeable( $real_file ) ) { + $this->custom_code_args[ "{$extension}_writeable" ] = true; } - if ( is_writeable( $real_file ) ) - $this->custom_code_args["{$extension}_writeable"] = true; } else { - $this->custom_code_args["{$extension}_writeable"] = true; - if ( 'php' == $extension ) - $this->custom_code_args["content_{$extension}"] = "custom_code_args[ "{$extension}_writeable" ] = true; + if ( 'php' === $extension ) { + $this->custom_code_args[ "content_{$extension}" ] = ' +

    + help_phrase(); + $bws_hide_premium = bws_hide_premium_options_check( $bstwbsftwppdtplgns_options ); + ?> +
    +

    ()

    + +
    +
    + +
    +
    + ' . esc_html__( 'You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft' ) . '

    '; + return; + } + + $list = array( + 'css' => array( + 'description' => __( 'These styles will be added to the header on all pages of your site.', 'bestwebsoft' ), + 'learn_more_link' => 'https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started', + ), + 'php' => array( + 'description' => sprintf( __( 'This PHP code will be hooked to the %s Action and will be printed on front end only.', 'bestwebsoft' ), 'init' ), + 'learn_more_link' => 'https://php.net/', + ), + 'js' => array( + 'description' => __( 'These code will be added to the header on all pages of your site.', 'bestwebsoft' ), + 'learn_more_link' => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript', + ), + ); + + foreach ( $list as $extension => $extension_data ) { + $name = 'js' === $extension ? 'JavaScript' : strtoupper( $extension ); + ?> +

    + + custom_code_args[ "{$extension}_writeable" ] ) { + echo '(' . esc_html__( 'Browsing', 'bestwebsoft' ) . ')';} + ?> + +

    +

    + +

    + +

    + +
    + + + +

    + +
    +
    +
    + ">Upgrade to Pro +
    +
    +
    + +
    + ">Upgrade to Pro +
    +
    + -

    + private function tab_misc() { + global $bstwbsftwppdtplgns_options; + ?> +

    help_phrase(); ?> -
    - ' . __( 'You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft' ) . '

    '; - return; - } - - $list = array( - 'css' => array( 'description' => __( 'These styles will be added to the header on all pages of your site.', 'bestwebsoft' ), - 'learn_more_link' => 'https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started' - ), - 'php' => array( 'description' => sprintf( __( 'This PHP code will be hooked to the %s action and will be printed on front end only.', 'bestwebsoft' ), 'init' ), - 'learn_more_link' => 'https://php.net/' - ), - 'js' => array( 'description' => __( 'These code will be added to the header on all pages of your site.', 'bestwebsoft' ), - 'learn_more_link' => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript' - ), - ); +
    + custom_code_args['css_writeable'] || - ! $this->custom_code_args['php_writeable'] || - ! $this->custom_code_args['js_writeable'] ) { ?> -

    ', - '' ); ?>

    - forbid_view && ! empty( $this->change_permission_attr ) ) { + ?> +

    : plugins_info['Name'] ), esc_html( $this->plugins_info['Name'] ) ); ?>

    + forbid_view ) { + ?> +

    : plugins_info['Name'] ), esc_html( $this->plugins_info['Name'] ) ); ?>

    + + + pro_page ) && $this->bws_hide_pro_option_exist ) { + ?> + + + + + + + + + + + + + +
    + +
    + +
    + change_permission_attr ) ); ?> name="bws_restore_default" type="submit" class="button" value="" /> +
    +
    + $extension_data ) { - $name = 'js' == $extension ? 'JavaScript' : strtoupper( $extension ); ?> -

    - - custom_code_args["{$extension}_writeable"] ) - echo '(' . __( 'Browsing', 'bestwebsoft' ) . ')'; ?> -

    -

    - -

    - -

    - -
    - - - -

    - +

    + help_phrase(); ?> +
    + forbid_view && ! empty( $this->change_permission_attr ) ) { + ?> +

    : plugins_info['Name'] ), esc_html( $this->plugins_info['Name'] ) ); ?>

    + forbid_view ) { + ?> +

    : plugins_info['Name'] ), esc_html( $this->plugins_info['Name'] ) ); ?>

    + + + +
    + upload_dir['basedir'] . '/bws-custom-code'; - - foreach ( array( 'css', 'php', 'js' ) as $extension ) { - $file = 'bws-custom-code.' . $extension; - $real_file = $folder . '/' . $file; - - if ( isset( $_POST["bws_newcontent_{$extension}"] ) && - $this->custom_code_args["{$extension}_writeable"] ) { - $newcontent = trim( wp_unslash( $_POST["bws_newcontent_{$extension}"] ) ); - if ( 'css' == $extension ) - $newcontent = wp_kses( $newcontent, array( '\'', '\"' ) ); - - if ( ! empty( $newcontent ) && isset( $_POST["bws_custom_{$extension}_active"] ) ) { - $this->custom_code_args["is_{$extension}_active"] = true; - if ( $this->is_multisite ) { - $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] = ( 'php' == $extension ) ? $real_file : $this->upload_dir['baseurl'] . '/bws-custom-code/' . $file; - } else { - $bstwbsftwppdtplgns_options['custom_code'][ $file ] = ( 'php' == $extension ) ? $real_file : $this->upload_dir['baseurl'] . '/bws-custom-code/' . $file; - } - } else { - $this->custom_code_args["is_{$extension}_active"] = false; - if ( $this->is_multisite ) { - if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ) ) - unset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ); - } else { - if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) ) - unset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ); - } - } - if ( $f = fopen( $real_file, 'w+' ) ) { - fwrite( $f, $newcontent ); - fclose( $f ); - $this->custom_code_args["content_{$extension}"] = $newcontent; - } - } - } - - if ( $this->is_multisite ) - update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); - else - update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); - } - - /** - * Display 'misc' tab - * @access private - */ - private function tab_misc() { - global $bstwbsftwppdtplgns_options; ?> -

    - help_phrase(); ?> -
    - forbid_view && ! empty( $this->change_permission_attr ) ) { ?> -

    : plugins_info["Name"], $this->plugins_info["Name"] ); ?>

    - forbid_view ) { ?> -

    : plugins_info["Name"], $this->plugins_info["Name"] ); ?>

    - - - pro_page ) && $this->bws_hide_pro_option_exist ) { ?> - - - - - - - - - - - - - -
    - -
    - -
    - change_permission_attr; ?> name="bws_restore_default" type="submit" class="button" value="" /> -
    -
    - -

    - help_phrase(); ?> -
    - forbid_view && ! empty( $this->change_permission_attr ) ) { ?> -

    : plugins_info["Name"], $this->plugins_info["Name"] ); ?>

    - forbid_view ) { ?> -

    : plugins_info["Name"], $this->plugins_info["Name"] ); ?>

    - - - -
    - pro_page ) ) { - if ( isset( $_POST['bws_hide_premium_options'] ) ) { - $hide_result = bws_hide_premium_options( $this->options ); + if ( isset( $_POST['bws_hide_premium_options'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { + $hide_result = bws_hide_premium_options( $this->options ); $this->hide_pro_tabs = true; - $this->options = $hide_result['options']; - if ( ! empty( $hide_result['message'] ) ) + $this->options = $hide_result['options']; + if ( ! empty( $hide_result['message'] ) ) { $notice = $hide_result['message']; - if ( $this->is_network_options ) + } + if ( $this->is_network_options ) { update_site_option( $this->prefix . '_options', $this->options ); - else + } else { update_option( $this->prefix . '_options', $this->options ); - } else if ( isset( $_POST['bws_hide_premium_options_submit'] ) ) { + } + } elseif ( isset( $_POST['bws_hide_premium_options_submit'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { if ( ! empty( $this->options['hide_premium_options'] ) ) { $key = array_search( get_current_user_id(), $this->options['hide_premium_options'] ); - if ( false !== $key ) + if ( false !== $key ) { unset( $this->options['hide_premium_options'][ $key ] ); - if ( $this->is_network_options ) + } + if ( $this->is_network_options ) { update_site_option( $this->prefix . '_options', $this->options ); - else + } else { update_option( $this->prefix . '_options', $this->options ); + } } $this->hide_pro_tabs = false; } else { if ( empty( $this->options['hide_premium_options'] ) ) { $this->options['hide_premium_options'][] = get_current_user_id(); - if ( $this->is_network_options ) + if ( $this->is_network_options ) { update_site_option( $this->prefix . '_options', $this->options ); - else + } else { update_option( $this->prefix . '_options', $this->options ); + } } $this->hide_pro_tabs = true; } } /* Save 'Track Usage' option */ - if ( isset( $_POST['bws_track_usage'] ) ) { + if ( isset( $_POST['bws_track_usage'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { if ( empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) { $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] = true; $track_usage = true; } } else { if ( ! empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) { - unset( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ); false; + unset( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ); + false; $track_usage = false; } } if ( isset( $track_usage ) ) { $usage_id = ! empty( $bstwbsftwppdtplgns_options['track_usage']['usage_id'] ) ? $bstwbsftwppdtplgns_options['track_usage']['usage_id'] : false; /* send data */ - $options = array( - 'timeout' => 3, - 'body' => array( - 'url' => get_bloginfo( 'url' ), - 'wp_version' => $wp_version, - 'is_active' => $track_usage, - 'product' => $this->plugin_basename, - 'version' => $this->plugins_info['Version'], - 'usage_id' => $usage_id, + $options = array( + 'timeout' => 3, + 'body' => array( + 'url' => get_bloginfo( 'url' ), + 'wp_version' => $wp_version, + 'is_active' => $track_usage, + 'product' => $this->plugin_basename, + 'version' => $this->plugins_info['Version'], + 'usage_id' => $usage_id, ), - 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) + 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ), ); $raw_response = wp_remote_post( 'https://bestwebsoft.com/wp-content/plugins/products-statistics/track-usage/', $options ); - if ( ! is_wp_error( $raw_response ) && 200 == wp_remote_retrieve_response_code( $raw_response ) ) { + if ( ! is_wp_error( $raw_response ) && 200 === intval( wp_remote_retrieve_response_code( $raw_response ) ) ) { $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); if ( is_array( $response ) && - ! empty( $response['usage_id'] ) && - $response['usage_id'] != $usage_id ) { + ! empty( $response['usage_id'] ) && + $response['usage_id'] !== $usage_id ) { $bstwbsftwppdtplgns_options['track_usage']['usage_id'] = $response['usage_id']; } } - if ( $this->is_multisite ) + if ( $this->is_multisite ) { update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); - else + } else { update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); + } } return compact( 'notice' ); @@ -732,329 +832,346 @@ * */ public function tab_license() { - global $wp_version, $bstwbsftwppdtplgns_options; ?> -

    + global $wp_version, $bstwbsftwppdtplgns_options; + ?> +

    help_phrase(); ?> -
    +
    licenses as $single_license ) { - $pro_plugin_name = ( strpos( $single_license['name'], 'Pro' ) ) ? $single_license['name'] : $single_license['name'] . ' ' . 'Pro'; - if ( ! empty( $this->pro_page ) || ! empty( $single_license['pro_basename'] ) ) { + $pro_plugin_name = ( strpos( $single_license['name'], 'Pro' ) ) ? $single_license['name'] : $single_license['name'] . ' Pro'; + if ( ! empty( $this->pro_page ) || ! empty( $single_license['pro_basename'] ) ) { if ( $this->pro_plugin_is_activated && ( empty( $single_license['pro_basename'] ) || isset( $this->bws_license_plugin ) ) ) { - $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'; ?> + $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'; + ?> - - - + + - -
    -

    - +

    +

    +
    - +

    - +


    - +
    - +


    - +
    - +
    - +
    - +

    -
    - + + + bws_license_plugin ]['count'] ) && - '5' < $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['count'] && - $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) + '5' < $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['count'] && + $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { $attr = 'disabled="disabled"'; + } if ( ! empty( $single_license['pro_basename'] ) ) { $license_key = ! empty( $bstwbsftwppdtplgns_options[ $single_license['pro_basename'] ] ) ? $bstwbsftwppdtplgns_options[ $single_license['pro_basename'] ] : ''; - } ?> - - - - - -
    - type="text" name="bws_license_key_" value="" /> - type="hidden" name="bws_license_plugin_" value="" /> - type="submit" class="button button-secondary" name="bws_license_submit" value="" /> -
    - bws_plugin_link . '" target="_blank" title="' . $pro_plugin_name . '">' . $pro_plugin_name . '' ); ?> -
    - -

    - trial_days !== false ) - echo '

    ' . __( 'or', 'bestwebsoft' ) . ' ' . sprintf( __( 'Start Your Free %s-Day Trial Now', 'bestwebsoft' ), $this->trial_days ) . '

    '; ?> -
    - + + + + + +
    + type="text" name="bws_license_key_" value="" /> + type="hidden" name="bws_license_plugin_" value="" /> + type="submit" class="button button-secondary" name="bws_license_submit" value="" /> + +
    + bws_plugin_link ) . '" target="_blank" title="' . esc_html( $pro_plugin_name ) . '">' . esc_html( $pro_plugin_name ) . '' ); ?> +
    + +

    + trial_days ) { + echo '

    ' . esc_html__( 'or', 'bestwebsoft' ) . ' ' . sprintf( esc_html__( 'Start Your Free %s-Day Trial Now', 'bestwebsoft' ), esc_attr( $this->trial_days ) ) . '

    '; + } + ?> +
    + - - - - - -
    - - -
    - -
    -
    - - - - - - -
    - -
    - -
    -
    - + + + + + +
    + + +
    + +
    +
    + + + + + + +
    + +
    + +
    +
    + licenses as $single_license) { - $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'] ] ) ) : ''; - if ( '' != $bws_license_key ) { - if ( strlen( $bws_license_key ) != 18 ) { - $error = __( 'Wrong license key', 'bestwebsoft' ); - } else { - - /* CHECK license key */ - if ( $this->is_pro && empty( $single_license['pro_basename'] ) ) { - delete_transient( 'bws_plugins_update' ); - if ( ! $this->all_plugins ) { - if ( ! function_exists( 'get_plugins' ) ) { - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); - } - $this->all_plugins = get_plugins(); - } - $current = get_site_transient( 'update_plugins' ); - - if ( ! empty( $this->all_plugins ) && ! empty( $current ) && isset( $current->response ) && is_array( $current->response ) ) { - $to_send = array(); - $to_send["plugins"][ $single_license['basename'] ] = $this->all_plugins[ $single_license['basename'] ]; - $to_send["plugins"][ $single_license['basename'] ]["bws_license_key"] = $bws_license_key; - $to_send["plugins"][ $single_license['basename'] ]["bws_illegal_client"] = true; - $options = array( - 'timeout' => ( ( defined( 'DOING_CRON' ) && DOING_CRON ) ? 30 : 3 ), - 'body' => array( 'plugins' => serialize( $to_send ) ), - 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) - ); - $raw_response = wp_remote_post( 'https://bestwebsoft.com/wp-content/plugins/paid-products/plugins/pro-license-check/1.0/', $options ); - if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { - $error = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ': BestWebSoft. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); - } else { - $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); - if ( is_array( $response ) && ! empty( $response ) ) { - foreach ( $response as $single_response ) { - if ( "wrong_license_key" == $single_response->package ) { - $error = __( 'Wrong license key.', 'bestwebsoft' ); - } else if ( "wrong_domain" == $single_response->package ) { - $error = __( 'This license key is bound to another site.', 'bestwebsoft' ); - } else if ( "time_out" == $single_response->package ) { - $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' ); - } elseif ( "you_are_banned" == $single_response->package ) { - $error = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' ); - } elseif ( "duplicate_domen_for_trial" == $single_response->package ) { - $error = __( "Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' ); - } - if ( empty( $error ) ) { - if ( empty( $message ) ) { - if ( isset( $single_response->trial ) ) { - $message = __( 'The Pro Trial license key is valid.', 'bestwebsoft' ); - } else { - $message = __( 'The license key is valid.', 'bestwebsoft' ); - } + $error = $message = $empty_field_error = ''; - if ( ! empty( $single_response->time_out ) ) { - $message .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $single_response->time_out . '.'; - } else { - /* lifetime */ - $single_response->time_out = NULL; - } - - if ( isset( $single_response->trial ) && $this->is_trial ) { - $message .= ' ' . sprintf( __( 'In order to continue using the plugin it is necessary to buy a %s license.', 'bestwebsoft' ), 'Pro' ); - } - } + if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'bws_license_key_nonce' ) ) { + die( __( 'Security check', 'bestwebsoft' ) ); + } else { - if ( isset( $single_response->trial ) ) { - $bstwbsftwppdtplgns_options['trial'][ $single_license['basename'] ] = 1; - } else { - unset( $bstwbsftwppdtplgns_options['trial'][ $single_license['basename'] ] ); - } - - if ( isset( $single_response->nonprofit ) ) { - $bstwbsftwppdtplgns_options['nonprofit'][ $single_license['basename'] ] = 1; - } else { - unset( $bstwbsftwppdtplgns_options['nonprofit'][ $single_license['basename'] ] ); - } - - if ( ! isset( $bstwbsftwppdtplgns_options[ $single_license['basename'] ] ) || $bstwbsftwppdtplgns_options[ $single_license['basename'] ] != $bws_license_key ) { - $bstwbsftwppdtplgns_options[ $single_license['basename'] ] = $bws_license_key; - - $file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt", "w+" ); - if ( $file ) { - @fwrite( $file, $bws_license_key ); - @fclose( $file ); - } - $update_option = true; - } - - if ( isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $single_license['basename'] ] ) ) { - unset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $single_license['basename'] ] ); - $update_option = true; - } - - if ( ! isset( $bstwbsftwppdtplgns_options['time_out'][ $single_license['basename'] ] ) || $bstwbsftwppdtplgns_options['time_out'][ $single_license['basename'] ] != $single_response->time_out ) { - $bstwbsftwppdtplgns_options['time_out'][ $single_license['basename'] ] = $single_response->time_out; - $update_option = true; - } + foreach ( $this->licenses as $single_license ) { + $bws_license_key = ( isset( $_POST[ ( ! empty( $single_license['pro_slug'] ) ) ? 'bws_license_key_' . $single_license['pro_slug'] : 'bws_license_key_' . $single_license['slug'] ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ ( ! empty( $single_license['pro_slug'] ) ) ? 'bws_license_key_' . $single_license['pro_slug'] : 'bws_license_key_' . $single_license['slug'] ] ) ) : ''; + if ( '' !== $bws_license_key ) { + if ( strlen( $bws_license_key ) !== 18 ) { + $error = __( 'Wrong license key', 'bestwebsoft' ); + } else { + /* CHECK license key */ + if ( $this->is_pro && empty( $single_license['pro_basename'] ) ) { + delete_transient( 'bws_plugins_update' ); + if ( ! $this->all_plugins ) { + if ( ! function_exists( 'get_plugins' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + $this->all_plugins = get_plugins(); + } + $current = get_site_transient( 'update_plugins' ); - if ( isset( $update_option ) ) { - if ( $this->is_multisite ) { - update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); - } else { - update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); - } - } - } - } - } else { - $error = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ' BestWebSoft. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); - } - } - } - /* Go Pro */ - } else { - - $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'] ] ) ); - if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { - $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1; - } else { - $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1; - $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time(); - } - - /* download Pro */ - if ( ! $this->all_plugins ) { - if ( ! function_exists( 'get_plugins' ) ) { - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); - } - $this->all_plugins = get_plugins(); - } - - if ( ! array_key_exists( $bws_license_plugin, $this->all_plugins ) ) { - $current = get_site_transient( 'update_plugins' ); - if ( ! empty( $current ) && isset( $current->response ) && is_array( $current->response ) ) { - $to_send = array(); - $to_send["plugins"][ $bws_license_plugin ] = array(); - $to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key; - $to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true; - $options = array( + if ( ! empty( $this->all_plugins ) && ! empty( $current ) && isset( $current->response ) && is_array( $current->response ) ) { + $to_send = array(); + $to_send['plugins'][ $single_license['basename'] ] = $this->all_plugins[ $single_license['basename'] ]; + $to_send['plugins'][ $single_license['basename'] ]['bws_license_key'] = $bws_license_key; + $to_send['plugins'][ $single_license['basename'] ]['bws_illegal_client'] = true; + $options = array( 'timeout' => ( ( defined( 'DOING_CRON' ) && DOING_CRON ) ? 30 : 3 ), 'body' => array( 'plugins' => serialize( $to_send ) ), - 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) + 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ), ); $raw_response = wp_remote_post( 'https://bestwebsoft.com/wp-content/plugins/paid-products/plugins/pro-license-check/1.0/', $options ); - if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { - $error = __( "Something went wrong. Please try again later. If the error appears again, please contact us", 'bestwebsoft' ) . ': BestWebSoft. ' . __( "We are sorry for inconvenience.", 'bestwebsoft' ); + if ( is_wp_error( $raw_response ) || 200 !== intval( wp_remote_retrieve_response_code( $raw_response ) ) ) { + $error = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ': BestWebSoft. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); } else { $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); if ( is_array( $response ) && ! empty( $response ) ) { foreach ( $response as $single_response ) { - if ( "wrong_license_key" == $single_response->package ) { - $error = __( "Wrong license key.", 'bestwebsoft' ); - } elseif ( "wrong_domain" == $single_response->package ) { - $error = __( "This license key is bound to another site.", 'bestwebsoft' ); - } elseif ( "you_are_banned" == $single_response->package ) { - $error = __( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); - } elseif ( "time_out" == $single_response->package ) { - $error = sprintf( __( "Unfortunately, Your license has expired. To continue getting top-priority support and plugin updates, you should extend it in your %s.", 'bestwebsoft' ), ' Client Area' ); - } elseif ( "duplicate_domen_for_trial" == $single_response->package ) { - $error = __( "Unfortunately, the Pro licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' ); + if ( 'wrong_license_key' === $single_response->package ) { + $error = __( 'Wrong license key.', 'bestwebsoft' ); + } elseif ( 'wrong_domain' === $single_response->package ) { + $error = __( 'This license key is bound to another site.', 'bestwebsoft' ); + } elseif ( 'time_out' === $single_response->package ) { + $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' ); + } elseif ( 'you_are_banned' === $single_response->package ) { + $error = __( 'Unfortunately, you have exceeded the number of available tries.', 'bestwebsoft' ); + } elseif ( 'duplicate_domen_for_trial' === $single_response->package ) { + $error = __( 'Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.', 'bestwebsoft' ); + } + if ( empty( $error ) ) { + if ( empty( $message ) ) { + if ( isset( $single_response->trial ) ) { + $message = __( 'The Pro Trial license key is valid.', 'bestwebsoft' ); + } else { + $message = __( 'The license key is valid.', 'bestwebsoft' ); + } + + if ( ! empty( $single_response->time_out ) ) { + $message .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $single_response->time_out . '.'; + } else { + /* lifetime */ + $single_response->time_out = null; + } + + if ( isset( $single_response->trial ) && $this->is_trial ) { + $message .= ' ' . sprintf( __( 'In order to continue using the plugin it is necessary to buy a %s license.', 'bestwebsoft' ), 'Pro' ); + } + } + + if ( isset( $single_response->trial ) ) { + $bstwbsftwppdtplgns_options['trial'][ $single_license['basename'] ] = 1; + } else { + unset( $bstwbsftwppdtplgns_options['trial'][ $single_license['basename'] ] ); + } + + if ( isset( $single_response->nonprofit ) ) { + $bstwbsftwppdtplgns_options['nonprofit'][ $single_license['basename'] ] = 1; + } else { + unset( $bstwbsftwppdtplgns_options['nonprofit'][ $single_license['basename'] ] ); + } + + if ( ! isset( $bstwbsftwppdtplgns_options[ $single_license['basename'] ] ) || $bstwbsftwppdtplgns_options[ $single_license['basename'] ] !== $bws_license_key ) { + $bstwbsftwppdtplgns_options[ $single_license['basename'] ] = $bws_license_key; + + WP_Filesystem(); + if ( $wp_filesystem->put_contents( dirname( dirname( __FILE__ ) ) . '/license_key.txt', $bws_license_key, 0755 ) ) { + $update_option = true; + } + } + + if ( isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $single_license['basename'] ] ) ) { + unset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $single_license['basename'] ] ); + $update_option = true; + } + + if ( ! isset( $bstwbsftwppdtplgns_options['time_out'][ $single_license['basename'] ] ) || $bstwbsftwppdtplgns_options['time_out'][ $single_license['basename'] ] !== $single_response->time_out ) { + $bstwbsftwppdtplgns_options['time_out'][ $single_license['basename'] ] = $single_response->time_out; + $update_option = true; + } + + if ( isset( $update_option ) ) { + if ( $this->is_multisite ) { + update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); + } else { + update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); + } + } } } - if ( empty( $error ) ) { - $bws_license_plugin = ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename']; - - $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; - $this->pro_plugin_is_activated = true; - } } else { - $error = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.", 'bestwebsoft' ); + $error = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ' BestWebSoft. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); } } } + /* Go Pro */ } else { - $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; - /* activate Pro */ - if ( ! is_plugin_active( $bws_license_plugin ) ) { - if ( $this->is_multisite && is_plugin_active_for_network( ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ) ) { - /* if multisite and free plugin is network activated */ - $network_wide = true; - } else { - /* activate on a single blog */ - $network_wide = false; + $slug = ! empty( $single_license['pro_slug'] ) ? 'bws_license_plugin_' . $single_license['pro_slug'] : 'bws_license_plugin_' . $single_license['slug']; + $bws_license_plugin = isset( $_POST[ $slug ] ) ? sanitize_text_field( wp_unslash( $_POST[ $slug ] ) ) : ''; + if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { + $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1; + } else { + $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1; + $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time(); + } + + /* download Pro */ + if ( ! $this->all_plugins ) { + if ( ! function_exists( 'get_plugins' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; } - activate_plugin( $bws_license_plugin, null, $network_wide ); - $this->pro_plugin_is_activated = true; + $this->all_plugins = get_plugins(); + } + + if ( ! array_key_exists( $bws_license_plugin, $this->all_plugins ) ) { + $current = get_site_transient( 'update_plugins' ); + if ( ! empty( $current ) && isset( $current->response ) && is_array( $current->response ) ) { + $to_send = array(); + $to_send['plugins'][ $bws_license_plugin ] = array(); + $to_send['plugins'][ $bws_license_plugin ]['bws_license_key'] = $bws_license_key; + $to_send['plugins'][ $bws_license_plugin ]['bws_illegal_client'] = true; + $options = array( + 'timeout' => ( ( defined( 'DOING_CRON' ) && DOING_CRON ) ? 30 : 3 ), + 'body' => array( 'plugins' => serialize( $to_send ) ), + 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ), + ); + $raw_response = wp_remote_post( 'https://bestwebsoft.com/wp-content/plugins/paid-products/plugins/pro-license-check/1.0/', $options ); + + if ( is_wp_error( $raw_response ) || 200 !== intval( wp_remote_retrieve_response_code( $raw_response ) ) ) { + $error = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ': BestWebSoft. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); + } else { + $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); + if ( is_array( $response ) && ! empty( $response ) ) { + foreach ( $response as $single_response ) { + if ( 'wrong_license_key' === $single_response->package ) { + $error = __( 'Wrong license key.', 'bestwebsoft' ); + } elseif ( 'wrong_domain' === $single_response->package ) { + $error = __( 'This license key is bound to another site.', 'bestwebsoft' ); + } elseif ( 'you_are_banned' === $single_response->package ) { + $error = __( 'Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.', 'bestwebsoft' ); + } elseif ( 'time_out' === $single_response->package ) { + $error = sprintf( __( 'Unfortunately, Your license has expired. To continue getting top-priority support and plugin updates, you should extend it in your %s.', 'bestwebsoft' ), ' Client Area' ); + } elseif ( 'duplicate_domen_for_trial' === $single_response->package ) { + $error = __( 'Unfortunately, the Pro licence was already installed to this domain. The Pro Trial license can be installed only once.', 'bestwebsoft' ); + } + } + if ( empty( $error ) ) { + $bws_license_plugin = ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename']; + + $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; + $this->pro_plugin_is_activated = true; + } + } else { + $error = __( 'Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.', 'bestwebsoft' ); + } + } + } + } else { + $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; + /* activate Pro */ + if ( ! is_plugin_active( $bws_license_plugin ) ) { + if ( $this->is_multisite && is_plugin_active_for_network( ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ) ) { + /* if multisite and free plugin is network activated */ + $network_wide = true; + } else { + /* activate on a single blog */ + $network_wide = false; + } + activate_plugin( $bws_license_plugin, null, $network_wide ); + $this->pro_plugin_is_activated = true; + } + } + /* add 'track_usage' for Pro version */ + if ( ! empty( $bstwbsftwppdtplgns_options['track_usage'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] ) && + empty( $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] ) ) { + $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] = $bstwbsftwppdtplgns_options['track_usage'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ]; + } + + if ( $this->is_multisite ) { + update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); + } else { + update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); + } + + if ( $this->pro_plugin_is_activated ) { + delete_transient( 'bws_plugins_update' ); } } - /* add 'track_usage' for Pro version */ - if ( ! empty( $bstwbsftwppdtplgns_options['track_usage'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] ) && - empty( $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] ) ) { - $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] = $bstwbsftwppdtplgns_options['track_usage'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ]; - } - - if ( $this->is_multisite ) { - update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); - } else { - update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); - } - - if ( $this->pro_plugin_is_activated ) { - delete_transient( 'bws_plugins_update' ); - } } + } else { + $empty_field_error = __( 'Please, enter Your license key', 'bestwebsoft' ); } - } else { - $empty_field_error = __( "Please, enter Your license key", 'bestwebsoft' ); } } return compact( 'error', 'message', 'empty_field_error' ); @@ -1062,37 +1179,45 @@ /** * Display help phrase + * * @access public * @param void - * @return array The action results + * @return html The Action results */ public function help_phrase() { - echo '
    ' . __( 'Need Help?', 'bestwebsoft' ) . ' '; - if ( '' != $this->doc_link ) - echo '' . __( 'Read the Instruction', 'bestwebsoft' ); - else - echo '' . __( 'Visit Help Center', 'bestwebsoft' ); - if ( '' != $this->doc_video_link ) - echo '' . ' ' . __( 'or', 'bestwebsoft' ) . ' ' . '' . __( 'Watch the Video', 'bestwebsoft' ); + /*pls */ + echo '
    ' . esc_html__( 'Need Help?', 'bestwebsoft' ) . ' '; + if ( '' !== $this->doc_link ) { + echo '' . esc_html__( 'Read the Instruction', 'bestwebsoft' ); + } else { + echo '' . esc_html__( 'Visit Help Center', 'bestwebsoft' ); + } + if ( '' !== $this->doc_video_link ) { + echo ' ' . esc_html__( 'or', 'bestwebsoft' ) . ' ' . esc_html__( 'Watch the Video', 'bestwebsoft' ); + } echo '
    '; + /* pls*/ } public function bws_pro_block_links() { - global $wp_version; ?> -
    - &wp_v=" target="_blank" title="plugins_info["Name"]; ?>"> - trial_days !== false ) { ?> - - - + global $wp_version; + ?> +
    + + trial_days ) { ?> + + + -
    -
    -
    +
    + options = apply_filters( __CLASS__ . '_additional_restore_options', $this->default_options ); if ( $this->is_network_options ) { - $this->options['network_apply'] = 'default'; - $this->options['network_view'] = '1'; + $this->options['network_apply'] = 'default'; + $this->options['network_view'] = '1'; $this->options['network_change'] = '1'; update_site_option( $this->prefix . '_options', $this->options ); } else { update_option( $this->prefix . '_options', $this->options ); } } + + public function add_request_feature() { + ?> + + +
    +
    +

    ' . sprintf( esc_html__( 'How can we improve %s?', 'bestwebsoft' ), $this->plugins_info['Name'] ) . '

    +
    +

    ' . esc_html__( 'We look forward to hear your ideas.', 'bestwebsoft' ) . '

    +

    + +

    + +
    +
    + +
    + '; + + $script = '(function($) { + var modalHtml = ' . wp_json_encode( $modal_html ) . ", + \$modal = $( modalHtml ); + + \$modal.appendTo( $( 'body' ) ); + + $( '#bws_request_feature .button' ).on( 'click', function() { + /* Display the dialog box.*/ + \$modal.addClass( 'active' ); + $( 'body' ).addClass( 'has-bws-modal' ); + }); + + \$modal.on( 'keypress', 'textarea', function( evt ) { + BwsModalEnableButton(); + }); + + \$modal.on( 'click', '.bws-modal-footer .button', function( evt ) { + evt.preventDefault(); + + if ( $( this ).hasClass( 'disabled' ) ) { + return; + } + var info = \$modal.find( 'textarea' ).val(); + + if ( info.length == 0 ) { + return; + } + + var _parent = $( this ).parents( '.bws-modal:first' ), + _this = $( this ); + + var is_anonymous = ( \$modal.find( '.bws-modal-anonymous-label' ).find( 'input' ).is( ':checked' ) ) ? 0 : 1; + + $.ajax({ + url : ajaxurl, + method : 'POST', + data : { + 'Action' : 'bws_submit_request_feature_action', + 'plugin' : '" . $this->plugin_basename . "', + 'info' : info, + 'is_anonymous' : is_anonymous, + 'bws_ajax_nonce' : '" . wp_create_nonce( 'bws_ajax_nonce' ) . "' + }, + beforeSend: function() { + _parent.find( '.bws-modal-footer .bws-modal-button' ).hide(); + _parent.find( '.bws-modal-footer .bws-modal-processing' ).show(); + _parent.find( 'textarea, input' ).attr( 'disabled', 'disabled' ); + }, + complete : function( message ) { + _parent.find( '.bws-modal-footer .bws-modal-processing' ).hide(); + _parent.find( '.bws-modal-footer .bws-modal-thank-you' ).show(); + } + }); + }); + + /* If the user has clicked outside the window, cancel it. */ + \$modal.on( 'click', function( evt ) { + var \$target = $( evt.target ); + + /* If the user has clicked anywhere in the modal dialog, just return. */ + if ( \$target.hasClass( 'bws-modal-body' ) || \$target.hasClass( 'bws-modal-footer' ) ) { + return; + } + + /* If the user has not clicked the close button and the clicked element is inside the modal dialog, just return. */ + if ( ! \$target.hasClass( 'bws-modal-button-close' ) && ( \$target.parents( '.bws-modal-body' ).length > 0 || \$target.parents( '.bws-modal-footer' ).length > 0 ) ) { + return; + } + + /* Close the modal dialog */ + \$modal.removeClass( 'active' ); + $( 'body' ).removeClass( 'has-bws-modal' ); + + return false; + }); + + function BwsModalEnableButton() { + \$modal.find( '.bws-modal-button' ).removeClass( 'disabled' ).show(); + \$modal.find( '.bws-modal-processing' ).hide(); + } + + function BwsModalDisableButton() { + \$modal.find( '.bws-modal-button' ).addClass( 'disabled' ); + } + + function BwsModalShowPanel() { + \$modal.find( '.bws-modal-panel' ).addClass( 'active' ); + } + })(jQuery);"; + + /* add script in FOOTER */ + wp_register_script( 'bws-request-feature-dialog', '', array( 'jquery' ), '2.4.2', true ); + wp_enqueue_script( 'bws-request-feature-dialog' ); + wp_add_inline_script( 'bws-request-feature-dialog', sprintf( $script ) ); + } } } + +/** + * Called after the user has submitted his reason for deactivating the plugin. + * + * @since 2.1.3 + */ +if ( ! function_exists( 'bws_submit_request_feature_action' ) ) { + function bws_submit_request_feature_action() { + global $bstwbsftwppdtplgns_options, $wp_version, $bstwbsftwppdtplgns_active_plugins, $current_user; + + if ( isset( $_REQUEST['bws_ajax_nonce'] ) ) { + + wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['bws_ajax_nonce'] ) ), 'bws_ajax_nonce' ); + + $basename = isset( $_REQUEST['plugin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['plugin'] ) ) : ''; + $info = isset( $_REQUEST['info'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['info'] ) ) : ''; + + if ( empty( $info ) || empty( $basename ) ) { + exit; + } + + $info = substr( $info, 0, 255 ); + $is_anonymous = isset( $_REQUEST['is_anonymous'] ) && 1 === intval( $_REQUEST['is_anonymous'] ); + + $options = array( + 'product' => $basename, + 'info' => $info, + ); + + if ( ! $is_anonymous ) { + if ( ! isset( $bstwbsftwppdtplgns_options ) ) { + $bstwbsftwppdtplgns_options = ( is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' ); + } + + if ( ! empty( $bstwbsftwppdtplgns_options['track_usage']['usage_id'] ) ) { + $options['usage_id'] = $bstwbsftwppdtplgns_options['track_usage']['usage_id']; + } else { + $options['usage_id'] = false; + $options['url'] = get_bloginfo( 'url' ); + $options['wp_version'] = $wp_version; + $options['is_active'] = false; + $options['version'] = $bstwbsftwppdtplgns_active_plugins[ $basename ]['Version']; + } + + $options['email'] = $current_user->data->user_email; + } + + /* send data */ + $raw_response = wp_remote_post( + 'https://bestwebsoft.com/wp-content/plugins/products-statistics/request-feature/', + array( + 'method' => 'POST', + 'body' => $options, + 'timeout' => 15, + ) + ); + + if ( ! is_wp_error( $raw_response ) && 200 === intval( wp_remote_retrieve_response_code( $raw_response ) ) ) { + if ( ! $is_anonymous ) { + $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); + + if ( is_array( $response ) && ! empty( $response['usage_id'] ) && $response['usage_id'] !== $options['usage_id'] ) { + $bstwbsftwppdtplgns_options['track_usage']['usage_id'] = $response['usage_id']; + + if ( is_multisite() ) { + update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); + } else { + update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); + } + } + } + + echo 'done'; + } else { + echo wp_kses_data( $response->get_error_code() ) . ': ' . wp_kses_data( $response->get_error_message() ); + } + } + exit; + } +} + +add_action( 'wp_ajax_bws_submit_request_feature_action', 'bws_submit_request_feature_action' );