wp/wp-content/plugins/portfolio/bws_menu/deprecated.php
changeset 16 a86126ab1dd4
parent 7 cf61fcea0001
child 19 3d72ae0968f4
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     1 <?php
     1 <?php
     2 /*
     2 /*
     3 * Deprecated functions for BestWebSoft plugins
     3 * Deprecated functions for BestWebSoft plugins
     4 */
     4 */
     5 
     5 
     6 /**
       
     7 * Function check if plugin is compatible with current WP version - for old plugin version
       
     8 * @deprecated 1.7.4
       
     9 * @todo Remove function after 01.01.2018
       
    10 */
       
    11 if ( ! function_exists( 'bws_wp_version_check' ) ) {
       
    12 	function bws_wp_version_check( $plugin_basename, $plugin_info, $require_wp ) {
       
    13 		global $bstwbsftwppdtplgns_options;
       
    14 		if ( ! isset( $bstwbsftwppdtplgns_options ) )
       
    15 			$bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
       
    16 		if ( ! isset( $bstwbsftwppdtplgns_options['deprecated_function']['bws_wp_version_check'] ) ) {
       
    17 			$bstwbsftwppdtplgns_options['deprecated_function']['bws_wp_version_check'] = array(
       
    18 				'product-name' => $plugin_info['Name']
       
    19 			);
       
    20 			if ( is_multisite() )
       
    21 				update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
    22 			else
       
    23 				update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
    24 		}
       
    25 	}
       
    26 }
       
    27 /**
       
    28 * Function add BWS Plugins page - for old plugin version
       
    29 * @deprecated 1.7.9
       
    30 * @todo Remove function after 01.01.2018
       
    31 */
       
    32 if ( ! function_exists( 'bws_add_general_menu' ) ) {
       
    33 	function bws_add_general_menu() {
       
    34 		global $bstwbsftwppdtplgns_options;
       
    35 		if ( ! isset( $bstwbsftwppdtplgns_options ) )
       
    36 			$bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
       
    37 		if ( ! isset( $bstwbsftwppdtplgns_options['deprecated_function']['bws_add_general_menu'] ) ) {
       
    38 			$get_debug_backtrace = debug_backtrace();
       
    39 			$file = ( ! empty( $get_debug_backtrace[0]['file'] ) ) ? $get_debug_backtrace[0]['file'] : '';
       
    40 			$bstwbsftwppdtplgns_options['deprecated_function']['bws_add_general_menu'] = array(
       
    41 				'file' => $file
       
    42 			);
       
    43 			if ( is_multisite() )
       
    44 				update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
    45 			else
       
    46 				update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
    47 		}
       
    48 	}
       
    49 }
       
    50 /**
       
    51 * Function display GO PRO tab - for old plugin version
       
    52 * @deprecated 1.7.6
       
    53 * @todo Remove function after 01.01.2018
       
    54 */
       
    55 if ( ! function_exists( 'bws_go_pro_tab' ) ) {
       
    56 	function bws_go_pro_tab( $plugin_info, $plugin_basename, $page, $pro_page, $bws_license_plugin, $link_slug, $link_key, $link_pn, $pro_plugin_is_activated = false, $trial_days_number = false ) {
       
    57 		global $bstwbsftwppdtplgns_options;
       
    58 		if ( ! isset( $bstwbsftwppdtplgns_options ) )
       
    59 			$bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
       
    60 		if ( ! isset( $bstwbsftwppdtplgns_options['deprecated_function']['bws_go_pro_tab'] ) ) {
       
    61 			$bstwbsftwppdtplgns_options['deprecated_function']['bws_go_pro_tab'] = array(
       
    62 				'product-name' => $plugin_info['Name']
       
    63 			);
       
    64 			if ( is_multisite() )
       
    65 				update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
    66 			else
       
    67 				update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
    68 		}
       
    69 	}
       
    70 }
       
    71 /**
     6 /**
    72 * Function add BWS Plugins page
     7 * Function add BWS Plugins page
    73 * @deprecated 1.9.8 (15.12.2016)
     8 * @deprecated 1.9.8 (15.12.2016)
    74 * @return void
     9 * @return void
    75 */
    10 */
    94 
    29 
    95 			$bws_general_menu_exist = true;
    30 			$bws_general_menu_exist = true;
    96 		}
    31 		}
    97 	}
    32 	}
    98 }
    33 }
       
    34 
       
    35 /**
       
    36 * Function process submit on the `Go Pro` tab
       
    37 * @deprecated 1.9.8 (15.12.2016)
       
    38 * @todo Remove function after 01.01.2021
       
    39 */
       
    40 if ( ! function_exists( 'bws_go_pro_tab_check' ) ) {
       
    41 	function bws_go_pro_tab_check( $plugin_basename, $plugin_options_name = false, $is_network_option = false ) {
       
    42 		global $bstwbsftwppdtplgns_options;
       
    43 		if ( ! isset( $bstwbsftwppdtplgns_options ) )
       
    44 			$bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
       
    45 		if ( ! isset( $bstwbsftwppdtplgns_options['deprecated_function']['bws_go_pro_tab_check'] ) ) {
       
    46 			$get_debug_backtrace = debug_backtrace();
       
    47 			$file = ( ! empty( $get_debug_backtrace[0]['file'] ) ) ? $get_debug_backtrace[0]['file'] : '';
       
    48 			$bstwbsftwppdtplgns_options['deprecated_function']['bws_go_pro_tab_check'] = array(
       
    49 				'file' => $file
       
    50 			);
       
    51 			if ( is_multisite() )
       
    52 				update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
    53 			else
       
    54 				update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
    55 		}
       
    56 	}
       
    57 }
       
    58 
       
    59 /**
       
    60 * Function display 'Custom code' tab
       
    61 *
       
    62 * @deprecated 1.9.8 (15.12.2016)
       
    63 * @todo Remove function after 01.01.2021
       
    64 */
       
    65 if ( ! function_exists( 'bws_custom_code_tab' ) ) {
       
    66 	function bws_custom_code_tab() {
       
    67 		global $bstwbsftwppdtplgns_options;
       
    68 		if ( ! isset( $bstwbsftwppdtplgns_options ) )
       
    69 			$bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
       
    70 		if ( ! isset( $bstwbsftwppdtplgns_options['deprecated_function']['bws_custom_code_tab'] ) ) {
       
    71 			$get_debug_backtrace = debug_backtrace();
       
    72 			$file = ( ! empty( $get_debug_backtrace[0]['file'] ) ) ? $get_debug_backtrace[0]['file'] : '';
       
    73 			$bstwbsftwppdtplgns_options['deprecated_function']['bws_custom_code_tab'] = array(
       
    74 				'file' => $file
       
    75 			);
       
    76 			if ( is_multisite() )
       
    77 				update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
    78 			else
       
    79 				update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
    80 		}
       
    81 	}
       
    82 }
       
    83 
    99 /**
    84 /**
   100 * Function check license key for Pro plugins version
    85 * Function check license key for Pro plugins version
   101 * @deprecated 1.9.8 (15.12.2016)
    86 * @deprecated 1.9.8 (15.12.2016)
   102 * @todo add notice and remove functional after 01.01.2018. Remove function after 01.01.2019
    87 * @todo Remove function after 01.01.2021
   103 */
    88 */
   104 if ( ! function_exists( 'bws_check_pro_license' ) ) {
    89 if ( ! function_exists( 'bws_check_pro_license' ) ) {
   105 	function bws_check_pro_license( $plugin_basename, $trial_plugin = false ) {
    90 	function bws_check_pro_license( $plugin_basename, $trial_plugin = false ) {
   106 		global $wp_version, $bstwbsftwppdtplgns_options;
    91 		global $bstwbsftwppdtplgns_options;
   107 		$result = array();
    92 		if ( ! isset( $bstwbsftwppdtplgns_options ) )
   108 
    93 			$bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
   109 		if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
    94 		if ( ! isset( $bstwbsftwppdtplgns_options['deprecated_function']['bws_custom_code_tab'] ) ) {
   110 			$license_key = isset( $_POST['bws_license_key'] ) ? sanitize_text_field( $_POST['bws_license_key'] ) : '';
    95 			$get_debug_backtrace = debug_backtrace();
   111 
    96 			$file = ( ! empty( $get_debug_backtrace[0]['file'] ) ) ? $get_debug_backtrace[0]['file'] : '';
   112 			if ( '' != $license_key ) {
    97 			$bstwbsftwppdtplgns_options['deprecated_function']['bws_custom_code_tab'] = array(
   113 
    98 				'file' => $file
   114 				delete_transient( 'bws_plugins_update' );
    99 			);
   115 
   100 			if ( is_multisite() )
   116 				if ( ! function_exists( 'get_plugins' ) )
   101 				update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
   117 					require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
   102 			else
   118 				$plugins_all = get_plugins();
   103 				update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
   119 				$current = get_site_transient( 'update_plugins' );
   104 		}
   120 
   105 	}
   121 				if ( is_array( $plugins_all ) && !empty( $plugins_all ) && isset( $current ) && is_array( $current->response ) ) {
   106 }
   122 					$to_send = array();
       
   123 					$to_send["plugins"][ $plugin_basename ] = $plugins_all[ $plugin_basename ];
       
   124 					$to_send["plugins"][ $plugin_basename ]["bws_license_key"] = $license_key;
       
   125 					$to_send["plugins"][ $plugin_basename ]["bws_illegal_client"] = true;
       
   126 					$options = array(
       
   127 							'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
       
   128 							'body' => array( 'plugins' => serialize( $to_send ) ),
       
   129 							'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
       
   130 						);
       
   131 					$raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
       
   132 					if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
       
   133 						$result['error'] = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ' <a href=https://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' );
       
   134 					} else {
       
   135 						$response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
       
   136 						if ( is_array( $response ) && !empty( $response ) ) {
       
   137 							foreach ( $response as $key => $value ) {
       
   138 								if ( "wrong_license_key" == $value->package ) {
       
   139 									$result['error'] = __( 'Wrong license key.', 'bestwebsoft' );
       
   140 								} else if ( "wrong_domain" == $value->package ) {
       
   141 									$result['error'] = __( 'This license key is bound to another site.', 'bestwebsoft' );
       
   142 								} else if ( "time_out" == $value->package ) {
       
   143 									$result['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' );
       
   144 								} elseif ( "you_are_banned" == $value->package ) {
       
   145 									$result['error'] = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' );
       
   146 								} elseif ( "duplicate_domen_for_trial" == $value->package ) {
       
   147 									$result['error'] = __( "Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
       
   148 								}
       
   149 								if ( empty( $result['message'] ) && empty( $result['error'] ) ) {
       
   150 									if ( isset( $value->trial ) )
       
   151 										$result['message'] = __( 'The Pro Trial license key is valid.', 'bestwebsoft' );
       
   152 									else
       
   153 										$result['message'] = __( 'The license key is valid.', 'bestwebsoft' );
       
   154 
       
   155 									if ( ! empty( $value->time_out ) )
       
   156 										$result['message'] .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $value->time_out . '.';
       
   157 
       
   158 									if ( isset( $value->trial ) && $trial_plugin != false )
       
   159 										$result['message'] .= ' ' . sprintf( __( 'In order to continue using the plugin it is necessary to buy a %s license.', 'bestwebsoft' ), '<a href="https://bestwebsoft.com/products/wordpress/plugins/' . $trial_plugin['link_slug'] . '/?k=' . $trial_plugin['link_key'] . '&pn=' . $trial_plugin['link_pn'] . '&v=' . $trial_plugin['plugin_info']['Version'] . '&wp_v=' . $wp_version . '" target="_blank" title="' . $trial_plugin['plugin_info']['Name'] . '">Pro</a>' );
       
   160 
       
   161 									if ( isset( $value->trial ) ) {
       
   162 										$bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] = 1;
       
   163 									} else {
       
   164 										unset( $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] );
       
   165 									}
       
   166 								}
       
   167 								if ( empty( $result['error'] ) ) {
       
   168 									if ( isset( $value->nonprofit ) ) {
       
   169 										$bstwbsftwppdtplgns_options['nonprofit'][ $plugin_basename ] = 1;
       
   170 									} else {
       
   171 										unset( $bstwbsftwppdtplgns_options['nonprofit'][ $plugin_basename ] );
       
   172 									}
       
   173 									
       
   174 									if ( $bstwbsftwppdtplgns_options[ $plugin_basename ] != $license_key ) {
       
   175 										$bstwbsftwppdtplgns_options[ $plugin_basename ] = $license_key;
       
   176 
       
   177 										$file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt" , "w+" );
       
   178 										if ( $file ) {
       
   179 											@fwrite( $file, $license_key );
       
   180 											@fclose( $file );
       
   181 										}
       
   182 										$update_option = true;
       
   183 									}
       
   184 
       
   185 									if ( ! isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_basename ] ) || $bstwbsftwppdtplgns_options['time_out'][ $plugin_basename ] != $value->time_out ) {
       
   186 										$bstwbsftwppdtplgns_options['time_out'][ $plugin_basename ] = $value->time_out;
       
   187 										$update_option = true;
       
   188 									}
       
   189 
       
   190 									if ( isset( $update_option ) ) {
       
   191 										if ( is_multisite() )
       
   192 											update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   193 										else
       
   194 											update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   195 									}
       
   196 								}
       
   197 							}
       
   198 						} else {
       
   199 							$result['error'] = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ' <a href=https://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' );
       
   200 						}
       
   201 					}
       
   202 				}
       
   203 			} else {
       
   204 				$result['error'] = __( 'Please, enter your license key', 'bestwebsoft' );
       
   205 			}
       
   206 		}
       
   207 		return $result;
       
   208 	}
       
   209 }
       
   210 
       
   211 
   107 
   212 /**
   108 /**
   213 * Function display block for checking license key for Pro plugins version
   109 * Function display block for checking license key for Pro plugins version
   214 * @deprecated 1.9.8 (15.12.2016)
   110 * @deprecated 1.9.8 (15.12.2016)
   215 * @todo add notice and remove functional after 01.01.2018. Remove function after 01.01.2019
   111 * @todo add notice and remove functional after 01.01.2018. Remove function after 01.01.2019
   269 					</p>
   165 					</p>
   270 				<?php } ?>
   166 				<?php } ?>
   271 			</form>
   167 			</form>
   272 		<?php } else { 
   168 		<?php } else { 
   273 			$page_url = esc_url( self_admin_url( 'admin.php?page=' . $page ) ); ?>
   169 			$page_url = esc_url( self_admin_url( 'admin.php?page=' . $page ) ); ?>
   274 			<script type="text/javascript">
       
   275 				window.setTimeout( function() {
       
   276 					window.location.href = '<?php echo $page_url; ?>';
       
   277 				}, 5000 );
       
   278 			</script>
       
   279 			<p><?php _e( "Congratulations! The Pro license of the plugin is activated successfully.", 'bestwebsoft' ); ?></p>
   170 			<p><?php _e( "Congratulations! The Pro license of the plugin is activated successfully.", 'bestwebsoft' ); ?></p>
   280 			<p>
   171 			<p>
   281 				<?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="<?php echo $page_url; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
   172 				<?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="<?php echo $page_url; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
   282 				(<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>)
       
   283 			</p>
   173 			</p>
   284 		<?php }
   174 		<?php }
   285 	}
   175 	}
   286 }
   176 }
   287 
   177 
   288 /**
       
   289 * Function process submit on the `Go Pro` tab
       
   290 * @deprecated 1.9.8 (15.12.2016)
       
   291 * @todo add notice and remove functional after 01.01.2018. Remove function after 01.01.2019
       
   292 */
       
   293 if ( ! function_exists( 'bws_go_pro_tab_check' ) ) {
       
   294 	function bws_go_pro_tab_check( $plugin_basename, $plugin_options_name = false, $is_network_option = false ) {
       
   295 		global $wp_version, $bstwbsftwppdtplgns_options;
       
   296 		$result = array();
       
   297 
       
   298 		$bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? sanitize_text_field( $_POST['bws_license_key'] ) : "";
       
   299 
       
   300 		if ( ! empty( $plugin_options_name ) && isset( $_POST['bws_hide_premium_options_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
       
   301 
       
   302 			$plugin_options = ( $is_network_option ) ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name );
       
   303 
       
   304 			if ( !empty( $plugin_options['hide_premium_options'] ) ) {
       
   305 
       
   306 				$key = array_search( get_current_user_id(), $plugin_options['hide_premium_options'] );
       
   307 				if ( false !== $key ) {
       
   308 					unset( $plugin_options['hide_premium_options'][ $key ] );
       
   309 				}
       
   310 
       
   311 				if ( $is_network_option )
       
   312 					update_site_option( $plugin_options_name, $plugin_options );
       
   313 				else
       
   314 					update_option( $plugin_options_name, $plugin_options );
       
   315 
       
   316 				$result['message'] = __( 'Check premium options on the plugin settings page!', 'bestwebsoft' );
       
   317 			}
       
   318 		}
       
   319 
       
   320 		if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
       
   321 			if ( '' != $bws_license_key ) {
       
   322 				if ( strlen( $bws_license_key ) != 18 ) {
       
   323 					$result['error'] = __( "Wrong license key", 'bestwebsoft' );
       
   324 				} else {
       
   325 					$bws_license_plugin = sanitize_text_field( $_POST['bws_license_plugin'] );
       
   326 					if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - (24 * 60 * 60) ) ) {
       
   327 						$bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1;
       
   328 					} else {
       
   329 						$bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1;
       
   330 						$bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time();
       
   331 					}
       
   332 
       
   333 					/* download Pro */
       
   334 					if ( ! function_exists( 'get_plugins' ) )
       
   335 						require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
       
   336 
       
   337 					$all_plugins = get_plugins();
       
   338 
       
   339 					if ( ! array_key_exists( $bws_license_plugin, $all_plugins ) ) {
       
   340 						$current = get_site_transient( 'update_plugins' );
       
   341 						if ( is_array( $all_plugins ) && !empty( $all_plugins ) && isset( $current ) && is_array( $current->response ) ) {
       
   342 							$to_send = array();
       
   343 							$to_send["plugins"][ $bws_license_plugin ] = array();
       
   344 							$to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key;
       
   345 							$to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true;
       
   346 							$options = array(
       
   347 								'timeout' => ( ( defined( 'DOING_CRON' ) && DOING_CRON ) ? 30 : 3 ),
       
   348 								'body' => array( 'plugins' => serialize( $to_send ) ),
       
   349 								'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
       
   350 							$raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
       
   351 
       
   352 							if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
       
   353 								$result['error'] = __( "Something went wrong. Please try again later. If the error appears again, please contact us", 'bestwebsoft' ) . ' <a href="https://support.bestwebsoft.com">BestWebSoft</a>. ' . __( "We are sorry for inconvenience.", 'bestwebsoft' );
       
   354 							} else {
       
   355 								$response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
       
   356 								if ( is_array( $response ) && !empty( $response ) ) {
       
   357 									foreach ( $response as $key => $value ) {
       
   358 										if ( "wrong_license_key" == $value->package ) {
       
   359 											$result['error'] = __( "Wrong license key.", 'bestwebsoft' );
       
   360 										} elseif ( "wrong_domain" == $value->package ) {
       
   361 											$result['error'] = __( "This license key is bound to another site.", 'bestwebsoft' );
       
   362 										} elseif ( "you_are_banned" == $value->package ) {
       
   363 											$result['error'] = __( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' );
       
   364 										} elseif ( "time_out" == $value->package ) {
       
   365 											$result['error'] = sprintf( __( "Unfortunately, Your license has expired. To continue getting top-priority support and plugin updates, you should extend it in your %s", 'bestwebsoft' ), ' <a href="https://bestwebsoft.com/client-area">Client Area</a>' );
       
   366 										} elseif ( "duplicate_domen_for_trial" == $value->package ) {
       
   367 											$result['error'] = __( "Unfortunately, the Pro licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
       
   368 										}
       
   369 									}
       
   370 									if ( empty( $result['error'] ) ) {
       
   371 										$bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
       
   372 
       
   373 										$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';
       
   374 										$uploadDir = wp_upload_dir();
       
   375 										$zip_name = explode( '/', $bws_license_plugin );
       
   376 
       
   377 										if ( !function_exists( 'curl_init' ) ) {
       
   378 											$received_content = file_get_contents( $url );
       
   379 										} else {
       
   380 											$ch = curl_init();
       
   381 											curl_setopt( $ch, CURLOPT_URL, $url );
       
   382 											curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
       
   383 											$received_content = curl_exec( $ch );
       
   384 											curl_close( $ch );
       
   385 										}
       
   386 
       
   387 										if ( ! $received_content ) {
       
   388 											$result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
       
   389 										} else {
       
   390 											if ( is_writable( $uploadDir["path"] ) ) {
       
   391 												$file_put_contents = $uploadDir["path"] . "/" . $zip_name[0] . ".zip";
       
   392 												if ( file_put_contents( $file_put_contents, $received_content ) ) {
       
   393 													@chmod( $file_put_contents, octdec( 755 ) );
       
   394 													if ( class_exists( 'ZipArchive' ) ) {
       
   395 														$zip = new ZipArchive();
       
   396 														if ( $zip->open( $file_put_contents ) === TRUE ) {
       
   397 															$zip->extractTo( WP_PLUGIN_DIR );
       
   398 															$zip->close();
       
   399 														} else {
       
   400 															$result['error'] = __( "Failed to open the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
       
   401 														}
       
   402 													} elseif ( class_exists( 'Phar' ) ) {
       
   403 														$phar = new PharData( $file_put_contents );
       
   404 														$phar->extractTo( WP_PLUGIN_DIR );
       
   405 													} else {
       
   406 														$result['error'] = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually", 'bestwebsoft' );
       
   407 													}
       
   408 													@unlink( $file_put_contents );
       
   409 												} else {
       
   410 													$result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
       
   411 												}
       
   412 											} else {
       
   413 												$result['error'] = __( "UploadDir is not writable. Please, upload the plugin manually", 'bestwebsoft' );
       
   414 											}
       
   415 										}
       
   416 
       
   417 										/* activate Pro */
       
   418 										if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) {
       
   419 											if ( is_multisite() && is_plugin_active_for_network( $plugin_basename ) ) {
       
   420 												/* if multisite and free plugin is network activated */
       
   421 												$active_plugins = get_site_option( 'active_sitewide_plugins' );
       
   422 												$active_plugins[ $bws_license_plugin ] = time();
       
   423 												update_site_option( 'active_sitewide_plugins', $active_plugins );
       
   424 											} else {
       
   425 												/* activate on a single blog */
       
   426 												$active_plugins = get_option( 'active_plugins' );
       
   427 												array_push( $active_plugins, $bws_license_plugin );
       
   428 												update_option( 'active_plugins', $active_plugins );
       
   429 											}
       
   430 											$result['pro_plugin_is_activated'] = true;
       
   431 										} elseif ( empty( $result['error'] ) ) {
       
   432 											$result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
       
   433 										}
       
   434 									}
       
   435 								} else {
       
   436 									$result['error'] = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.", 'bestwebsoft' );
       
   437 								}
       
   438 							}
       
   439 						}
       
   440 					} else {
       
   441 						$bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
       
   442 						/* activate Pro */
       
   443 						if ( ! is_plugin_active( $bws_license_plugin ) ) {
       
   444 							if ( is_multisite() && is_plugin_active_for_network( $plugin_basename ) ) {
       
   445 								/* if multisite and free plugin is network activated */
       
   446 								$network_wide = true;
       
   447 							} else {
       
   448 								/* activate on a single blog */
       
   449 								$network_wide = false;
       
   450 							}
       
   451 							activate_plugin( $bws_license_plugin, NULL, $network_wide );
       
   452 							$result['pro_plugin_is_activated'] = true;
       
   453 						}
       
   454 					}
       
   455 					if ( is_multisite() )
       
   456 						update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   457 					else
       
   458 						update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   459 
       
   460 					if ( ! empty( $result['pro_plugin_is_activated'] ) )
       
   461 						delete_transient( 'bws_plugins_update' );
       
   462 				}
       
   463 			} else {
       
   464 				$result['error'] = __( "Please, enter Your license key", 'bestwebsoft' );
       
   465 			}
       
   466 		}
       
   467 		return $result;
       
   468 	}
       
   469 }
       
   470 
   178 
   471 /**
   179 /**
   472 * Function display block for restoring default product settings
   180 * Function display block for restoring default product settings
   473 * @deprecated 1.9.8 (15.12.2016)
   181 * @deprecated 1.9.8 (15.12.2016)
   474 * @todo add notice and remove functional after 01.01.2018. Remove function after 01.01.2019
   182 * @todo add notice and remove functional after 01.01.2018. Remove function after 01.01.2019
   480 			<p>
   188 			<p>
   481 				<input <?php echo $change_permission_attr; ?> type="submit" class="button" value="<?php _e( 'Restore settings', 'bestwebsoft' ); ?>" />
   189 				<input <?php echo $change_permission_attr; ?> type="submit" class="button" value="<?php _e( 'Restore settings', 'bestwebsoft' ); ?>" />
   482 			</p>
   190 			</p>
   483 			<input type="hidden" name="bws_restore_default" value="submit" />
   191 			<input type="hidden" name="bws_restore_default" value="submit" />
   484 			<?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
   192 			<?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
   485 		</form>
       
   486 	<?php }
       
   487 }
       
   488 
       
   489 /**
       
   490 * Function display 'Custom code' tab
       
   491 *
       
   492 * @deprecated 1.9.8 (15.12.2016)
       
   493 * @todo add notice and remove functional after 01.01.2018. Remove function after 01.01.2019
       
   494 */
       
   495 if ( ! function_exists( 'bws_custom_code_tab' ) ) {
       
   496 	function bws_custom_code_tab() {
       
   497 		if ( ! current_user_can( 'edit_plugins' ) )
       
   498 			wp_die( __( 'You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft' ) );
       
   499 
       
   500 		global $bstwbsftwppdtplgns_options;
       
   501 
       
   502 		$message = $content = '';
       
   503 		$is_css_active = $is_php_active = false;
       
   504 
       
   505 		$upload_dir = wp_upload_dir();
       
   506 		$folder = $upload_dir['basedir'] . '/bws-custom-code';
       
   507 		if ( ! $upload_dir["error"] ) {
       
   508 			if ( ! is_dir( $folder ) )
       
   509 				wp_mkdir_p( $folder, 0755 );
       
   510 
       
   511 			$index_file = $upload_dir['basedir'] . '/bws-custom-code/index.php';
       
   512 			if ( ! file_exists( $index_file ) ) {
       
   513 				if ( $f = fopen( $index_file, 'w+' ) )
       
   514 					fclose( $f );
       
   515 			}
       
   516 		}
       
   517 
       
   518 		$css_file = 'bws-custom-code.css';
       
   519 		$real_css_file = $folder . '/' . $css_file;
       
   520 
       
   521 		$php_file = 'bws-custom-code.php';
       
   522 		$real_php_file = $folder . '/' . $php_file;
       
   523 
       
   524 		$is_multisite = is_multisite();
       
   525 		if ( $is_multisite )
       
   526 			$blog_id = get_current_blog_id();
       
   527 
       
   528 		if ( isset( $_REQUEST['bws_update_custom_code'] ) && check_admin_referer( 'bws_update_' . $css_file ) ) {
       
   529 
       
   530 			/* CSS */
       
   531 			$newcontent_css = wp_kses( trim( wp_unslash( $_POST['bws_newcontent_css'] ) ), 'strip' );
       
   532 
       
   533 			if ( ! empty( $newcontent_css ) && isset( $_REQUEST['bws_custom_css_active'] ) ) {
       
   534 				if ( $is_multisite )
       
   535 					$bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] = $upload_dir['baseurl'] . '/bws-custom-code/' . $css_file;
       
   536 				else
       
   537 					$bstwbsftwppdtplgns_options['custom_code'][ $css_file ] = $upload_dir['baseurl'] . '/bws-custom-code/' . $css_file;
       
   538 			} else {
       
   539 				if ( $is_multisite ) {
       
   540 					if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] ) )
       
   541 						unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] );
       
   542 				} else {
       
   543 					if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] ) )
       
   544 						unset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] );
       
   545 				}
       
   546 			}
       
   547 			if ( $f = fopen( $real_css_file, 'w+' ) ) {
       
   548 				fwrite( $f, $newcontent_css );
       
   549 				fclose( $f );
       
   550 				$message .= sprintf( __( 'File %s edited successfully.', 'bestwebsoft' ), '<i>' . $css_file . '</i>' ) . ' ';
       
   551 			} else {
       
   552 				$error .= __( 'Not enough permissions to create or update the file', 'bestwebsoft' ) . ' ' . $real_css_file . '. ';
       
   553 			}
       
   554 
       
   555 			/* PHP */
       
   556 			$newcontent_php = trim( wp_unslash( $_POST['bws_newcontent_php'] ) );
       
   557 			if ( file_exists( $index_file ) ) {
       
   558 				if ( ! empty( $newcontent_php ) && isset( $_REQUEST['bws_custom_php_active'] ) ) {
       
   559 					if ( $is_multisite )
       
   560 						$bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] = $real_php_file;
       
   561 					else
       
   562 						$bstwbsftwppdtplgns_options['custom_code'][ $php_file ] = $real_php_file;
       
   563 				} else {
       
   564 					if ( $is_multisite ) {
       
   565 						if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] ) )
       
   566 							unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] );
       
   567 					} else {
       
   568 						if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] ) )
       
   569 							unset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] );
       
   570 					}
       
   571 				}
       
   572 
       
   573 				if ( $f = fopen( $real_php_file, 'w+' ) ) {
       
   574 					$newcontent_php = $newcontent_php;
       
   575 					fwrite( $f, $newcontent_php );
       
   576 					fclose( $f );
       
   577 					$message .= sprintf( __( 'File %s edited successfully.', 'bestwebsoft' ), '<i>' . $php_file . '</i>' );
       
   578 				} else {
       
   579 					$error .= __( 'Not enough permissions to create or update the file', 'bestwebsoft' ) . ' ' . $real_php_file . '. ';
       
   580 				}
       
   581 			} else {
       
   582 				$error .= __( 'Not enough permissions to create the file', 'bestwebsoft' ) . ' ' . $index_file . '. ';
       
   583 			}
       
   584 
       
   585 			if ( ! empty( $error ) )
       
   586 				$error .= ' <a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">' . __( 'Learn more', 'bestwebsoft' ) . '</a>';
       
   587 
       
   588 			if ( $is_multisite )
       
   589 				update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   590 			else
       
   591 				update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   592 		}
       
   593 
       
   594 		if ( file_exists( $real_css_file ) ) {
       
   595 			update_recently_edited( $real_css_file );
       
   596 			$content_css = file_get_contents( $real_css_file );
       
   597 			if ( ( $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] ) ) ||
       
   598 				( ! $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] ) ) ) {
       
   599 				$is_css_active = true;
       
   600 			}
       
   601 		}
       
   602 		if ( file_exists( $real_php_file ) ) {
       
   603 			update_recently_edited( $real_php_file );
       
   604 			$content_php = file_get_contents( $real_php_file );
       
   605 			if ( ( $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] ) ) ||
       
   606 				( ! $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] ) ) ) {
       
   607 				$is_php_active = true;
       
   608 			}
       
   609 		} else {
       
   610 			$content_php = "<?php" . "\n" . "if ( ! defined( 'ABSPATH' ) ) exit;" . "\n" . "if ( ! defined( 'BWS_GLOBAL' ) ) exit;" . "\n\n" . "/* Start your code here */" . "\n";
       
   611 		}
       
   612 
       
   613 		if ( ! empty( $message ) ) { ?>
       
   614 			<div id="message" class="below-h2 updated notice is-dismissible"><p><?php echo $message; ?></p></div>
       
   615 		<?php } ?>
       
   616 		<form action="" method="post">
       
   617 			<?php foreach ( array( 'css', 'php' ) as $extension ) { ?>
       
   618 				<p>
       
   619 					<?php if ( 'css' == $extension )
       
   620 						_e( 'These styles will be added to the header on all pages of your site.', 'bestwebsoft' );
       
   621 					else
       
   622 						printf( __( 'This PHP code will be hooked to the %s action and will be printed on front end only.', 'bestwebsoft' ), '<a href="https://codex.wordpress.org/Plugin_API/Action_Reference/init" target="_blank"><code>init</code></a>' ); ?>
       
   623 				</p>
       
   624 				<p><big>
       
   625 					<?php if ( ! file_exists( ${"real_{$extension}_file"} ) || ( is_writeable( ${"real_{$extension}_file"} ) ) ) {
       
   626 						echo __( 'Editing', 'bestwebsoft' ) . ' <strong>' . ${"{$extension}_file"} . '</strong>';
       
   627 					} else {
       
   628 						echo __( 'Browsing', 'bestwebsoft' ) . ' <strong>' . ${"{$extension}_file"} . '</strong>';
       
   629 					} ?>
       
   630 				</big></p>
       
   631 				<p><label><input type="checkbox" name="bws_custom_<?php echo $extension; ?>_active" value="1" <?php if ( ${"is_{$extension}_active"} ) echo "checked"; ?> />	<?php _e( 'Activate', 'bestwebsoft' ); ?></label></p>
       
   632 				<textarea cols="70" rows="25" name="bws_newcontent_<?php echo $extension; ?>" id="bws_newcontent_<?php echo $extension; ?>"><?php if ( isset( ${"content_{$extension}"} ) ) echo esc_textarea( ${"content_{$extension}"} ); ?></textarea>
       
   633 				<p class="description">
       
   634 					<a href="<?php echo ( 'css' == $extension ) ? 'https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started' : 'http://php.net/' ?>" target="_blank">
       
   635 						<?php printf( __( 'Learn more about %s', 'bestwebsoft' ), strtoupper( $extension ) ); ?>
       
   636 					</a>
       
   637 				</p>
       
   638 			<?php }
       
   639 			if ( ( ! file_exists( $real_css_file ) || is_writeable( $real_css_file ) ) && ( ! file_exists( $real_php_file ) || is_writeable( $real_php_file ) ) ) { ?>
       
   640 				<p class="submit">
       
   641 					<input type="hidden" name="bws_update_custom_code" value="submit" />
       
   642 					<?php submit_button( __( 'Save Changes', 'bestwebsoft' ), 'primary', 'submit', false );
       
   643 					wp_nonce_field( 'bws_update_' . $css_file ); ?>
       
   644 				</p>
       
   645 			<?php } else { ?>
       
   646 				<p><em><?php printf( __( 'You need to make this files writable before you can save your changes. See %s the Codex %s for more information.', 'bestwebsoft' ),
       
   647 				'<a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">',
       
   648 				'</a>' ); ?></em></p>
       
   649 			<?php }	?>
       
   650 		</form>
   193 		</form>
   651 	<?php }
   194 	<?php }
   652 }
   195 }
   653 
   196 
   654 /**
   197 /**
   660 	function bws_go_pro_tab_show( $bws_hide_premium_options_check, $plugin_info, $plugin_basename, $page, $pro_page, $bws_license_plugin, $link_slug, $link_key, $link_pn, $pro_plugin_is_activated = false, $trial_days_number = false ) {
   203 	function bws_go_pro_tab_show( $bws_hide_premium_options_check, $plugin_info, $plugin_basename, $page, $pro_page, $bws_license_plugin, $link_slug, $link_key, $link_pn, $pro_plugin_is_activated = false, $trial_days_number = false ) {
   661 		global $wp_version, $bstwbsftwppdtplgns_options;
   204 		global $wp_version, $bstwbsftwppdtplgns_options;
   662 		$bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? sanitize_text_field( $_POST['bws_license_key'] ) : "";
   205 		$bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? sanitize_text_field( $_POST['bws_license_key'] ) : "";
   663 		if ( $pro_plugin_is_activated ) { 
   206 		if ( $pro_plugin_is_activated ) { 
   664 			$page_url = esc_url( self_admin_url( 'admin.php?page=' . $pro_page ) ); ?>
   207 			$page_url = esc_url( self_admin_url( 'admin.php?page=' . $pro_page ) ); ?>
   665 			<script type="text/javascript">
       
   666 				window.setTimeout( function() {
       
   667 					window.location.href = '<?php echo $page_url; ?>';
       
   668 				}, 5000 );
       
   669 			</script>
       
   670 			<p><?php _e( "Congratulations! Pro version of the plugin is  installed and activated successfully.", 'bestwebsoft' ); ?></p>
   208 			<p><?php _e( "Congratulations! Pro version of the plugin is  installed and activated successfully.", 'bestwebsoft' ); ?></p>
   671 			<p>
   209 			<p>
   672 				<?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="<?php echo $page_url; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
   210 				<?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="<?php echo $page_url; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
   673 				(<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>)
       
   674 			</p>
   211 			</p>
   675 		<?php } else {
   212 		<?php } else {
   676 			if ( $bws_hide_premium_options_check ) { ?>
   213 			if ( $bws_hide_premium_options_check ) { ?>
   677 				<form method="post" action="">
   214 				<form method="post" action="">
   678 					<p>
   215 					<p>
   717 				<?php } ?>
   254 				<?php } ?>
   718 			</form>
   255 			</form>
   719 		<?php }
   256 		<?php }
   720 	}
   257 	}
   721 }
   258 }
       
   259 
       
   260 /**
       
   261 * Function display GO PRO Banner (inline in 'admin_notices' action )
       
   262 * @deprecated 2.2.5 (29.11.2019)
       
   263 * @todo Remove notice after 01.12.2021
       
   264 */
       
   265 if ( ! function_exists( 'bws_plugin_banner' ) ) {
       
   266 	function bws_plugin_banner( $plugin_info, $this_banner_prefix, $link_slug, $link_key, $link_pn, $banner_url_or_slug ) {
       
   267 		/* the function is not longer use, but we need to store it */
       
   268 	}
       
   269 }
       
   270 
       
   271 /**
       
   272 * Function display timeout PRO Banner (inline in 'admin_notices' action )
       
   273 * @deprecated 2.2.5 (29.11.2019)
       
   274 * @todo Remove notice after 01.12.2021
       
   275 */
       
   276 if ( ! function_exists ( 'bws_plugin_banner_timeout' ) ) {
       
   277 	function bws_plugin_banner_timeout( $plugin_key, $plugin_prefix, $plugin_name, $banner_url_or_slug = false ) {
       
   278 		/* the function is not longer use, but we need to store it */
       
   279 	}
       
   280 }