diff -r bf1778c34b9a -r d8a8807227e4 wp/wp-content/plugins/portfolio/bws_menu/class-bws-settings.php --- a/wp/wp-content/plugins/portfolio/bws_menu/class-bws-settings.php Mon Oct 14 18:35:50 2019 +0200 +++ b/wp/wp-content/plugins/portfolio/bws_menu/class-bws-settings.php Tue Oct 15 11:56:20 2019 +0200 @@ -14,10 +14,10 @@ public $plugin_basename; public $prefix; public $wp_slug; - + public $options; public $default_options; - public $is_network_options; + public $is_network_options; public $plugins_info = array(); public $hide_pro_tabs = false; public $demo_data; @@ -28,8 +28,9 @@ public $link_key; public $link_pn; public $is_trial = false; + public $licenses; public $trial_days; - public $bws_hide_pro_option_exist = true; + public $bws_hide_pro_option_exist = true; public $forbid_view = false; public $change_permission_attr = ''; @@ -48,35 +49,36 @@ * The child class should call this constructor from its own constructor to override * the default $args. * @access public - * + * * @param array|string $args */ public function __construct( $args = array() ) { $args = wp_parse_args( $args, array( 'plugin_basename' => '', 'prefix' => '', - 'plugins_info' => array(), + 'plugins_info' => array(), 'default_options' => array(), 'options' => array(), 'is_network_options' => false, 'tabs' => array(), - 'doc_link' => '', - 'doc_video_link' => '', - 'wp_slug' => '', - 'demo_data' => false, + 'doc_link' => '', + 'doc_video_link' => '', + 'wp_slug' => '', + 'demo_data' => false, /* if this is free version and pro exist */ - 'pro_page' => '', - 'bws_license_plugin'=> '', - 'link_key' => '', - 'link_pn' => '', - 'trial_days' => false + 'pro_page' => '', + 'bws_license_plugin' => '', + '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->plugins_info = $args['plugins_info']; $this->options = $args['options']; $this->default_options = $args['default_options']; $this->wp_slug = $args['wp_slug']; @@ -93,13 +95,28 @@ $this->link_key = $args['link_key']; $this->link_pn = $args['link_pn']; $this->trial_days = $args['trial_days']; + $this->licenses = $args['licenses']; $this->hide_pro_tabs = bws_hide_premium_options_check( $this->options ); $this->version = '1.0.0'; $this->is_multisite = is_multisite(); - if ( empty( $this->pro_page ) && array_key_exists( 'license', $this->tabs ) ) + if ( empty( $this->pro_page ) && array_key_exists( 'license', $this->tabs ) ) { $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 + ); + } else { + $this->licenses[ $this->plugins_info['TextDomain'] ] = array( + 'name' => $this->plugins_info['Name'], + 'slug' => $this->plugins_info['TextDomain'], + 'pro_slug' => stristr( $this->bws_license_plugin, '/', TRUE ), + 'basename' => $this->plugin_basename, + 'pro_basename' => $this->bws_license_plugin + ); + } } /** @@ -124,20 +141,20 @@ $this->demo_data->bws_demo_confirm(); } else { bws_show_settings_notice(); ?> -
-
-
-
- display_tabs(); ?> -
-
-
-
-

-
-
-
-
+ +
+
+
+ display_tabs(); ?> +
+
+
+
+

+
+
+
+
is_pro ) { if ( ! isset( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ) || isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $this->plugin_basename ] ) ) { $license_type = 'Pro'; @@ -145,7 +162,7 @@ } else { $finish = strtotime( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ); $today = strtotime( date( "m/d/Y" ) ); - if ( isset( $bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] ) ) { + if ( isset( $bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] ) ) { $license_type = 'Trial Pro'; if ( $finish < $today ) { @@ -154,7 +171,7 @@ $daysleft = floor( ( $finish - $today ) / ( 60*60*24 ) ); $license_status = sprintf( __( '%s day(-s) left', 'bestwebsoft' ), $daysleft ); } - $license_status .= '. ' . __( 'Upgrade to Pro', 'bestwebsoft' ) . ''; + $license_status .= '. ' . __( 'Upgrade to Pro', 'bestwebsoft' ) . ''; } else { $license_type = isset( $bstwbsftwppdtplgns_options['nonprofit'][ $this->plugin_basename ] ) ? 'Nonprofit Pro' : 'Pro'; if ( $finish < $today ) { @@ -164,50 +181,50 @@ } } } ?> -
- : -
-
- : -
+
+ : +
+
+ : +
-
- : plugins_info['Version']; ?> -
-
-
-
-
-
- - - plugin_basename, 'bws_nonce_name' ); ?> -
-
-
-
-
-
+
+ : plugins_info['Version']; ?> +
+
+
+
+
+
+ + + plugin_basename, 'bws_nonce_name' ); ?> +
+
+
+
+
+
-
-
-
+
+
+
-
- -
+
+ +
wp_slug ) ) bws_plugin_reviews_block( $this->plugins_info['Name'], $this->wp_slug ); ?> -
-
- -
+
+
+ +
-
> - display_tabs_content(); ?> -
- -
+
+ + -
  • - - - -
  • +
  • + + + +
  • tabs as $tab_slug => $data ) { + foreach ( $this->tabs as $tab_slug => $data ) { if ( ! empty( $data['is_pro'] ) && $this->hide_pro_tabs ) continue; ?> -
    +
    -
    +
    plugin_basename, 'bws_settings_nonce_name' ) ) { $this->restore_options(); $message = __( 'All plugin settings were restored.', 'bestwebsoft' ); - /* Go Pro - check license key */ + /* Go Pro - check license key */ } elseif ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { $result = $this->save_options_license_key(); + if ( ! empty( $result['empty_field_error'] ) ) + $error = $result['empty_field_error']; if ( ! empty( $result['error'] ) ) $error = $result['error']; if ( ! empty( $result['message'] ) ) $message = $result['message']; if ( ! empty( $result['notice'] ) ) $notice = $result['notice']; - /* check demo data */ + /* check demo data */ } else { $demo_result = ! empty( $this->demo_data ) ? $this->demo_data->bws_handle_demo_data() : false; if ( false !== $demo_result ) { @@ -302,9 +321,9 @@ if ( ! empty( $demo_result['done'] ) && ! empty( $demo_result['options'] ) ) $this->options = $demo_result['options']; } - /* Save 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' ) ) { - /* save tabs */ + /* save tabs */ $result = $this->save_options(); if ( ! empty( $result['error'] ) ) $error = $result['error']; @@ -341,9 +360,9 @@ * action - Display custom error\message\notice */ do_action( __CLASS__ . '_display_custom_messages', $save_results ); ?> -
    >

    -
    >

    -
    >

    +
    >

    +
    >

    +
    >

    is_multisite ) $this->custom_code_args['blog_id'] = get_current_blog_id(); foreach ( array( 'css', 'php', 'js' ) as $extension ) { $file = 'bws-custom-code.' . $extension; $real_file = $folder . '/' . $file; - + if ( file_exists( $real_file ) ) { update_recently_edited( $real_file ); $this->custom_code_args["content_{$extension}"] = 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->is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) ) ) { $this->custom_code_args["is_{$extension}_active"] = true; } if ( is_writeable( $real_file ) ) @@ -420,55 +439,55 @@ * @access private */ private function tab_custom_code() { ?> -

    +

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

    '; return; } - $list = array( + $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' - ), + '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' => 'http://php.net/' - ), + 'learn_more_link' => 'http://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' - ), + 'learn_more_link' => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript' + ), ); if ( ! $this->custom_code_args['css_writeable'] || - ! $this->custom_code_args['php_writeable'] || - ! $this->custom_code_args['js_writeable'] ) { ?> -

    ', - '' ); ?>

    + ! $this->custom_code_args['php_writeable'] || + ! $this->custom_code_args['js_writeable'] ) { ?> +

    ', + '' ); ?>

    $extension_data ) { $name = 'js' == $extension ? 'JavaScript' : strtoupper( $extension ); ?> -

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

    -

    -

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

    +

    + -

    - -

    + +

    + +

    -
    - +
    +
    - -

    + +

    upload_dir['basedir'] . '/bws-custom-code'; - foreach ( array( 'css', 'php', 'js' ) as $extension ) { + 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"] ) { + $this->custom_code_args["{$extension}_writeable"] ) { $newcontent = trim( wp_unslash( $_POST["bws_newcontent_{$extension}"] ) ); if ( 'css' == $extension ) - $newcontent = wp_kses( $newcontent, 'strip' ); + $newcontent = wp_kses( $newcontent, array( '\'', '\"' ) ); if ( ! empty( $newcontent ) && isset( $_POST["bws_custom_{$extension}_active"] ) ) { $this->custom_code_args["is_{$extension}_active"] = true; @@ -526,55 +545,55 @@ * Display 'misc' tab * @access private */ - private function tab_misc() { + private function tab_misc() { global $bstwbsftwppdtplgns_options; ?> -

    +

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

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

    +

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

    forbid_view ) { ?> -

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

    +

    : 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="" /> -
    -
    + + + + + + + + + + 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"] ); ?>

    +

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

    forbid_view ) { ?> -

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

    +

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

    - +
    -
    + prefix . '_options', $this->options ); } - $this->hide_pro_tabs = false; + $this->hide_pro_tabs = false; } else { if ( empty( $this->options['hide_premium_options'] ) ) { $this->options['hide_premium_options'][] = get_current_user_id(); @@ -679,8 +698,8 @@ $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']; } } @@ -692,89 +711,102 @@ } return compact( 'notice' ); - } + } /** * */ public function tab_license() { global $wp_version, $bstwbsftwppdtplgns_options; ?> -

    +

    help_phrase(); ?> -
    - pro_page ) ) { - $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( sanitize_text_field( $_POST['bws_license_key'] ) ) : ""; +
    + 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'] ) ) { - if ( $this->pro_plugin_is_activated ) { - deactivate_plugins( $this->plugin_basename ); ?> - -

    -

    pro_page ) ) . '">' . __( 'Settings page', 'bestwebsoft' ) . '', '7' ); ?>

    - 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 ) ) ) - $attr = 'disabled="disabled"'; ?> - - - - - -
    - type="text" name="bws_license_key" value="" /> - type="hidden" name="bws_license_plugin" value="bws_license_plugin ); ?>" /> - type="submit" class="button button-secondary" name="bws_license_submit" value="" /> -
    - 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">' . $this->plugins_info["Name"] . ' Pro' ); ?> -
    - -

    - trial_days !== false ) - echo '

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

    '; ?> -
    + window.setTimeout( bws_set_timeout, 1000 ); + })(jQuery); + +

    +

    pro_page ) ) . '">' . __( 'Settings page', 'bestwebsoft' ) . '', '7' ); ?>

    + 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 ) ) ) + $attr = 'disabled="disabled"'; + + + $license_key = ''; + if( ! empty( $single_license['pro_basename'] ) ) { + $license_key = ! empty( $bstwbsftwppdtplgns_options[ $single_license['pro_basename'] ] ) ? $bstwbsftwppdtplgns_options[ $single_license['pro_basename'] ] : ''; + } + $current_plugin_link = ( ! empty( $this->link_key ) && ! empty( $this->link_pn ) ? esc_url( 'https://bestwebsoft.com/products/wordpress/plugins/' . $this->wp_slug . '/' . '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version ) : esc_url( 'https://bestwebsoft.com/products/wordpress/plugins/' . $this->wp_slug . '/' ) ); + ?> + + + + + +
    + 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="" /> +
    + ' . $pro_plugin_name . '' ); ?> +
    + +

    + trial_days !== false ) + echo '

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

    '; ?> +
    + + + + + + +
    + + +
    + +
    +
    plugin_basename ] ) ) ? $bstwbsftwppdtplgns_options[ $this->plugin_basename ] : ''; ?> - - - - - - - - - -
    - - -
    - -
    -
    - -
    - -
    -
    - + + + + + +
    + +
    + +
    +
    + is_pro ) { - 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"][ $this->plugin_basename ] = $this->all_plugins[ $this->plugin_basename ]; - $to_send["plugins"][ $this->plugin_basename ]["bws_license_key"] = $bws_license_key; - $to_send["plugins"][ $this->plugin_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( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-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' ); - - if ( ! empty( $single_response->time_out ) ) - $message .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $single_response->time_out . '.'; - - 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'][ $this->plugin_basename ] = 1; - } else { - unset( $bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] ); - } - - if ( isset( $single_response->nonprofit ) ) { - $bstwbsftwppdtplgns_options['nonprofit'][ $this->plugin_basename ] = 1; - } else { - unset( $bstwbsftwppdtplgns_options['nonprofit'][ $this->plugin_basename ] ); - } - - if ( ! isset( $bstwbsftwppdtplgns_options[ $this->plugin_basename ] ) || $bstwbsftwppdtplgns_options[ $this->plugin_basename ] != $bws_license_key ) { - $bstwbsftwppdtplgns_options[ $this->plugin_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['time_out'][ $this->plugin_basename ] ) || $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] != $single_response->time_out ) { - $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_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 ); - } - } - } - } 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 */ + /*$empty_field_error - added to avoid error when 1 field is empty while another field contains license key*/ + $empty_field_error = ''; + 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'] ] ) ) ? 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 { - $bws_license_plugin = stripslashes( sanitize_text_field( $_POST['bws_license_plugin'] ) ); - 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(); - } + /* 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' ); - /* 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 ) ) { + if ( ! empty( $this->all_plugins ) && ! 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' ) ); + $to_send["plugins"][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] = $this->all_plugins[ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ]; + $to_send["plugins"][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ]["bws_license_key"] = $bws_license_key; + $to_send["plugins"][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $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( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-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' ); + $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' ); + $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 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' ); + $error = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' ); } 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' ); + $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 ) ) { - $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; + 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' ); + } - $url = 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/downloads/?bws_first_download=' . $bws_license_plugin . '&bws_license_key=' . $bws_license_key . '&download_from=5'; - - if ( ! $this->upload_dir ) - $this->upload_dir = wp_upload_dir(); - - $zip_name = explode( '/', $bws_license_plugin ); + if ( ! empty( $single_response->time_out ) ) { + $message .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $single_response->time_out . '.'; + } - if ( !function_exists( 'curl_init' ) ) { - $received_content = file_get_contents( $url ); - } else { - $ch = curl_init(); - curl_setopt( $ch, CURLOPT_URL, $url ); - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); - $received_content = curl_exec( $ch ); - curl_close( $ch ); - } + 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 ( ! $received_content ) { - $error = __( "Failed to download the zip archive. Please, upload the plugin manually.", 'bestwebsoft' ); - } else { - if ( is_writable( $this->upload_dir["path"] ) ) { - $file_put_contents = $this->upload_dir["path"] . "/" . $zip_name[0] . ".zip"; - if ( file_put_contents( $file_put_contents, $received_content ) ) { - @chmod( $file_put_contents, octdec( 755 ) ); - if ( class_exists( 'ZipArchive' ) ) { - $zip = new ZipArchive(); - if ( $zip->open( $file_put_contents ) === TRUE ) { - $zip->extractTo( WP_PLUGIN_DIR ); - $zip->close(); - } else { - $error = __( "Failed to open the zip archive. Please, upload the plugin manually.", 'bestwebsoft' ); - } - } elseif ( class_exists( 'Phar' ) ) { - $phar = new PharData( $file_put_contents ); - $phar->extractTo( WP_PLUGIN_DIR ); - } else { - $error = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually.", 'bestwebsoft' ); - } - @unlink( $file_put_contents ); + if ( isset( $single_response->trial ) ) { + $bstwbsftwppdtplgns_options['trial'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] = 1; + } else { + unset( $bstwbsftwppdtplgns_options['trial'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] ); + } + + if ( isset( $single_response->nonprofit ) ) { + $bstwbsftwppdtplgns_options['nonprofit'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] = 1; + } else { + unset( $bstwbsftwppdtplgns_options['nonprofit'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] ); + } + + if ( ! isset( $bstwbsftwppdtplgns_options[ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] ) || $bstwbsftwppdtplgns_options[ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] != $bws_license_key ) { + $bstwbsftwppdtplgns_options[ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $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['time_out'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] ) || $bstwbsftwppdtplgns_options['time_out'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $single_license['basename'] ] != $single_response->time_out ) { + $bstwbsftwppdtplgns_options['time_out'][ ( ! empty( $single_license['pro_basename'] ) ) ? $single_license['pro_basename'] : $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 { - $error = __( "Failed to download the zip archive. Please, upload the plugin manually.", 'bestwebsoft' ); + update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); } - } else { - $error = __( "UploadDir is not writable. Please, upload the plugin manually.", 'bestwebsoft' ); } } - - /* activate Pro */ - if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) { - if ( $this->is_multisite && is_plugin_active_for_network( $this->plugin_basename ) ) { - /* if multisite and free plugin is network activated */ - $active_plugins = get_site_option( 'active_sitewide_plugins' ); - $active_plugins[ $bws_license_plugin ] = time(); - update_site_option( 'active_sitewide_plugins', $active_plugins ); - } else { - /* activate on a single blog */ - $active_plugins = get_option( 'active_plugins' ); - array_push( $active_plugins, $bws_license_plugin ); - update_option( 'active_plugins', $active_plugins ); - } - $this->pro_plugin_is_activated = true; - } elseif ( empty( $error ) ) { - $error = __( "Failed to download the zip archive. Please, upload the plugin manually.", 'bestwebsoft' ); - } } } 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( $this->plugin_basename ) ) { - /* if multisite and free plugin is network activated */ - $network_wide = true; - } else { - /* activate on a single blog */ - $network_wide = false; + + $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' ); } - 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( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-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' ); + } 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; + + $url = 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/downloads/?bws_first_download=' . $bws_license_plugin . '&bws_license_key=' . $bws_license_key . '&download_from=5'; + + if ( ! $this->upload_dir ) { + $this->upload_dir = wp_upload_dir(); + } + + $zip_name = explode( '/', $bws_license_plugin ); + + if ( ! function_exists( 'curl_init' ) ) { + $received_content = file_get_contents( $url ); + } else { + $ch = curl_init(); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + $received_content = curl_exec( $ch ); + curl_close( $ch ); + } + + if ( ! $received_content ) { + $error = __( "Failed to download the zip archive. Please, upload the plugin manually.", 'bestwebsoft' ); + } else { + if ( is_writable( $this->upload_dir["path"] ) ) { + $file_put_contents = $this->upload_dir["path"] . "/" . $zip_name[0] . ".zip"; + if ( file_put_contents( $file_put_contents, $received_content ) ) { + @chmod( $file_put_contents, octdec( 755 ) ); + if ( class_exists( 'ZipArchive' ) ) { + $zip = new ZipArchive(); + if ( $zip->open( $file_put_contents ) === true ) { + $zip->extractTo( WP_PLUGIN_DIR ); + $zip->close(); + } else { + $error = __( "Failed to open the zip archive. Please, upload the plugin manually.", 'bestwebsoft' ); + } + } elseif ( class_exists( 'Phar' ) ) { + $phar = new PharData( $file_put_contents ); + $phar->extractTo( WP_PLUGIN_DIR ); + } else { + $error = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually.", 'bestwebsoft' ); + } + @unlink( $file_put_contents ); + } else { + $error = __( "Failed to download the zip archive. Please, upload the plugin manually.", 'bestwebsoft' ); + } + } else { + $error = __( "UploadDir is not writable. Please, upload the plugin manually.", 'bestwebsoft' ); + } + } + + /* activate Pro */ + if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) { + 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 */ + $active_plugins = get_site_option( 'active_sitewide_plugins' ); + $active_plugins[ $bws_license_plugin ] = time(); + update_site_option( 'active_sitewide_plugins', $active_plugins ); + } else { + /* activate on a single blog */ + $active_plugins = get_option( 'active_plugins' ); + array_push( $active_plugins, $bws_license_plugin ); + update_option( 'active_plugins', $active_plugins ); + } + $this->pro_plugin_is_activated = true; + } elseif ( empty( $error ) ) { + $error = __( "Failed to download the zip archive. Please, upload the plugin manually.", 'bestwebsoft' ); + } + } + } 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'][ $this->plugin_basename ] ) && - empty( $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] ) ) { - $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] = $bstwbsftwppdtplgns_options['track_usage'][ $this->plugin_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 { - $error = __( "Please, enter Your license key", 'bestwebsoft' ); } - return compact( 'error', 'message' ); + return compact( 'error', 'message', 'empty_field_error' ); } /** @@ -1061,18 +1107,18 @@ echo ''; } - public function bws_pro_block_links() { + public function bws_pro_block_links() { global $wp_version; ?> -
    - &wp_v=" target="_blank" title="plugins_info["Name"]; ?>"> +
    + &wp_v=" target="_blank" title="plugins_info["Name"]; ?>"> trial_days !== false ) { ?> - - - + + + -
    -
    +
    +