wp/wp-content/plugins/portfolio/bws_menu/class-bws-settings.php
changeset 7 cf61fcea0001
child 12 d8a8807227e4
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
       
     1 <?php
       
     2 /**
       
     3  * Displays the content on the plugin settings page
       
     4  * @package BestWebSoft
       
     5  * @since 1.9.8
       
     6  */
       
     7 
       
     8 if ( ! class_exists( 'Bws_Settings_Tabs' ) ) {
       
     9 	class Bws_Settings_Tabs {
       
    10 		private $tabs;
       
    11 		private $pro_plugin_is_activated = false;
       
    12 		private $custom_code_args = array();
       
    13 
       
    14 		public $plugin_basename;
       
    15 		public $prefix;
       
    16 		public $wp_slug;
       
    17 				
       
    18 		public $options;
       
    19 		public $default_options;
       
    20 		public $is_network_options;	
       
    21 		public $plugins_info  = array();
       
    22 		public $hide_pro_tabs = false;
       
    23 		public $demo_data;
       
    24 
       
    25 		public $is_pro = false;
       
    26 		public $pro_page;
       
    27 		public $bws_license_plugin;
       
    28 		public $link_key;
       
    29 		public $link_pn;
       
    30 		public $is_trial = false;
       
    31 		public $trial_days;
       
    32 		public $bws_hide_pro_option_exist = true;	
       
    33 
       
    34 		public $forbid_view = false;
       
    35 		public $change_permission_attr = '';
       
    36 
       
    37 		public $version;
       
    38 		public $upload_dir;
       
    39 		public $all_plugins;
       
    40 		public $is_multisite;
       
    41 
       
    42 		public $doc_link;
       
    43 		public $doc_video_link;
       
    44 
       
    45 		/**
       
    46 		 * Constructor.
       
    47 		 *
       
    48 		 * The child class should call this constructor from its own constructor to override
       
    49 		 * the default $args.
       
    50 		 * @access public
       
    51 		 * 
       
    52 		 * @param array|string $args
       
    53 		 */
       
    54 		public function __construct( $args = array() ) {
       
    55 			$args = wp_parse_args( $args, array(
       
    56 				'plugin_basename' 	 => '',
       
    57 				'prefix' 			 => '',
       
    58 				'plugins_info'		=> array(),
       
    59 				'default_options' 	 => array(),
       
    60 				'options' 			 => array(),
       
    61 				'is_network_options' => false,
       
    62 				'tabs' 				 => array(),
       
    63 				'doc_link'			=> '',
       
    64 				'doc_video_link'	=> '',
       
    65 				'wp_slug'			=> '',
       
    66 				'demo_data' 		=> false,
       
    67 				/* if this is free version and pro exist */
       
    68 				'pro_page'			=> '',
       
    69 				'bws_license_plugin'=> '',
       
    70 				'link_key'			=> '',
       
    71 				'link_pn'			=> '',
       
    72 				'trial_days'		=> false
       
    73 			) );
       
    74 
       
    75 			$args['plugins_info']['Name'] = str_replace( ' by BestWebSoft', '', $args['plugins_info']['Name'] );
       
    76 			
       
    77 			$this->plugin_basename		= $args['plugin_basename'];
       
    78 			$this->prefix				= $args['prefix'];
       
    79 			$this->plugins_info			= $args['plugins_info'];			
       
    80 			$this->options				= $args['options'];
       
    81 			$this->default_options  	= $args['default_options'];
       
    82 			$this->wp_slug  			= $args['wp_slug'];
       
    83 			$this->demo_data  			= $args['demo_data'];
       
    84 
       
    85 			$this->tabs  				= $args['tabs'];
       
    86 			$this->is_network_options  	= $args['is_network_options'];
       
    87 
       
    88 			$this->doc_link  			= $args['doc_link'];
       
    89 			$this->doc_video_link  		= $args['doc_video_link'];
       
    90 
       
    91 			$this->pro_page  			= $args['pro_page'];
       
    92 			$this->bws_license_plugin  	= $args['bws_license_plugin'];
       
    93 			$this->link_key  			= $args['link_key'];
       
    94 			$this->link_pn  			= $args['link_pn'];
       
    95 			$this->trial_days  			= $args['trial_days'];
       
    96 
       
    97 			$this->hide_pro_tabs   		= bws_hide_premium_options_check( $this->options );
       
    98 			$this->version = '1.0.0';
       
    99 			$this->is_multisite = is_multisite();
       
   100 
       
   101 			if ( empty( $this->pro_page ) && array_key_exists( 'license', $this->tabs ) )
       
   102 				$this->is_pro = true;
       
   103 		}
       
   104 
       
   105 		/**
       
   106 		 * Displays the content of the "Settings" on the plugin settings page
       
   107 		 * @access public
       
   108 		 * @param  void
       
   109 		 * @return void
       
   110 		 */
       
   111 		public function display_content() {
       
   112 			global $bstwbsftwppdtplgns_options;
       
   113 			if ( array_key_exists( 'custom_code', $this->tabs ) ) {
       
   114 				/* get args for `custom code` tab */
       
   115 				$this->get_custom_code();
       
   116 			}
       
   117 
       
   118 			$save_results = $this->save_all_tabs_options();
       
   119 
       
   120 			$this->display_messages( $save_results );
       
   121 			if ( isset( $_REQUEST['bws_restore_default'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) {
       
   122 				bws_form_restore_default_confirm( $this->plugin_basename );
       
   123 			} elseif ( isset( $_POST['bws_handle_demo'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) {
       
   124 				$this->demo_data->bws_demo_confirm();
       
   125 			} else {
       
   126 				bws_show_settings_notice(); ?>
       
   127 				<form class="bws_form" method="post" action="" enctype="multipart/form-data">
       
   128 					<div id="poststuff">
       
   129 						<div id="post-body" class="metabox-holder columns-2">
       
   130 							<div id="post-body-content" style="position: relative;">
       
   131 								<?php $this->display_tabs(); ?>					
       
   132 							</div><!-- #post-body-content -->
       
   133 							<div id="postbox-container-1" class="postbox-container">
       
   134 								<div class="meta-box-sortables ui-sortable">
       
   135 									<div id="submitdiv" class="postbox">
       
   136 										<h3 class="hndle"><?php _e( 'Information', 'bestwebsoft' ); ?></h3>
       
   137 										<div class="inside">
       
   138 											<div class="submitbox" id="submitpost">
       
   139 												<div id="minor-publishing">
       
   140 													<div id="misc-publishing-actions">
       
   141 														<?php if ( $this->is_pro ) {
       
   142 															if ( ! isset( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ) || isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $this->plugin_basename ] ) ) {
       
   143 																$license_type = 'Pro';
       
   144 																$license_status = __( 'Inactive', 'bestwebsoft' ) . ' <a href="#' . $this->prefix . '_license_tab" class="bws_trigger_tab_click">' . __( 'Learn More', 'bestwebsoft' ) . '</a>';
       
   145 															} else {
       
   146 																$finish = strtotime( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] );
       
   147 																$today = strtotime( date( "m/d/Y" ) );
       
   148 																if ( isset( $bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] ) ) { 
       
   149 																	$license_type = 'Trial Pro';
       
   150 
       
   151 																	if ( $finish < $today ) {
       
   152 																		$license_status = __( 'Expired', 'bestwebsoft' );
       
   153 																	} else {
       
   154 																		$daysleft = floor( ( $finish - $today ) / ( 60*60*24 ) );
       
   155 																		$license_status = sprintf( __( '%s day(-s) left', 'bestwebsoft' ), $daysleft );
       
   156 																	}
       
   157 																	$license_status .= '. <a target="_blank" href="' . esc_url( $this->plugins_info['PluginURI'] ) . '">' . __( 'Upgrade to Pro', 'bestwebsoft' ) . '</a>';							 		
       
   158 																} else {
       
   159 																	$license_type = isset( $bstwbsftwppdtplgns_options['nonprofit'][ $this->plugin_basename ] ) ? 'Nonprofit Pro' : 'Pro';
       
   160 																	if ( $finish < $today ) {
       
   161 																		$license_status = sprintf( __( 'Expired on %s', 'bestwebsoft' ), $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ) . '. <a target="_blank" href="https://support.bestwebsoft.com/entries/53487136">' . __( 'Renew Now', 'bestwebsoft' ) . '</a>';
       
   162 																	} else {
       
   163 																		$license_status = __( 'Active', 'bestwebsoft' );
       
   164 																	}
       
   165 																}
       
   166 															} ?>
       
   167 															<div class="misc-pub-section">
       
   168 																<strong><?php _e( 'License', 'bestwebsoft' ); ?>:</strong> <?php echo $license_type; ?>
       
   169 															</div>
       
   170 															<div class="misc-pub-section">
       
   171 																<strong><?php _e( 'Status', 'bestwebsoft' ); ?>:</strong> <?php echo $license_status; ?>
       
   172 															</div><!-- .misc-pub-section -->
       
   173 														<?php } ?>
       
   174 														<div class="misc-pub-section">
       
   175 															<strong><?php _e( 'Version', 'bestwebsoft' ); ?>:</strong> <?php echo $this->plugins_info['Version']; ?>
       
   176 														</div><!-- .misc-pub-section -->
       
   177 													</div>
       
   178 													<div class="clear"></div>
       
   179 												</div>
       
   180 												<div id="major-publishing-actions">
       
   181 													<div id="publishing-action">
       
   182 														<input type="hidden" name="<?php echo $this->prefix; ?>_form_submit" value="submit" />
       
   183 														<input id="bws-submit-button" type="submit" class="button button-primary button-large" value="<?php _e( 'Save Changes', 'bestwebsoft' ); ?>" />
       
   184 														<?php wp_nonce_field( $this->plugin_basename, 'bws_nonce_name' ); ?>					
       
   185 													</div>
       
   186 													<div class="clear"></div>
       
   187 												</div>
       
   188 											</div>
       
   189 										</div>										
       
   190 									</div>
       
   191 									<?php /**
       
   192 									 * action - Display custom metabox
       
   193 									 */
       
   194 									do_action( __CLASS__ . '_display_metabox' ); ?>
       
   195 								</div>
       
   196 							</div>
       
   197 							<div id="postbox-container-2" class="postbox-container">
       
   198 								<?php /**
       
   199 								 * action - Display additional content for #postbox-container-2
       
   200 								 */
       
   201 								do_action( __CLASS__ . '_display_second_postbox' ); ?>
       
   202 								<div class="submit">
       
   203 									<input type="submit" class="button button-primary button-large" value="<?php _e( 'Save Changes', 'bestwebsoft' ); ?>" />
       
   204 								</div>								
       
   205 								<?php if ( ! empty( $this->wp_slug ) )
       
   206 									bws_plugin_reviews_block( $this->plugins_info['Name'], $this->wp_slug ); ?>
       
   207 							</div>
       
   208 						</div>
       
   209 					</form>
       
   210 				</div>
       
   211 			<?php }
       
   212 		}
       
   213 
       
   214 		/**
       
   215 		 * Displays the Tabs
       
   216 		 * @access public
       
   217 		 * @param  void
       
   218 		 * @return void
       
   219 		 */
       
   220 		public function display_tabs() { 
       
   221 			global $wp_version; ?>
       
   222 			<div id="bws_settings_tabs_wrapper"<?php if ( version_compare( $wp_version, '4.0', '<' ) ) echo ' class="edit-form-section"'; ?>>
       
   223 				<ul id="bws_settings_tabs">
       
   224 					<?php $this->display_tabs_list(); ?>
       
   225 				</ul>
       
   226 				<?php $this->display_tabs_content(); ?>
       
   227 				<div class="clear"></div>
       
   228 				<input type="hidden" name="bws_active_tab" value="<?php if ( isset( $_REQUEST['bws_active_tab'] ) ) echo esc_attr( $_REQUEST['bws_active_tab'] ); ?>" />
       
   229 			</div>
       
   230 		<?php }
       
   231 
       
   232 		/**
       
   233 		 * Displays the list of tabs
       
   234 		 * @access private
       
   235 		 * @return void
       
   236 		 */
       
   237 		private function display_tabs_list() {
       
   238 			foreach ( $this->tabs as $tab_slug => $data ) {
       
   239 				if ( ! empty( $data['is_pro'] ) && $this->hide_pro_tabs )
       
   240 					continue;
       
   241 				$tab_class = 'bws-tab-' . $tab_slug;
       
   242 				if ( ! empty( $data['is_pro'] ) )
       
   243 					$tab_class .= ' bws_pro_tab';
       
   244 				if ( ! empty( $data['class'] ) )
       
   245 					$tab_class .= ' ' . $data['class']; ?>
       
   246 				<li class="<?php echo $tab_class; ?>" data-slug="<?php echo $tab_slug; ?>">
       
   247 					<a href="#<?php echo $this->prefix; ?>_<?php echo $tab_slug; ?>_tab">
       
   248 						<span><?php echo esc_html( $data['label'] ); ?></span>
       
   249 					</a>
       
   250 				</li>
       
   251 			<?php }
       
   252 		}
       
   253 
       
   254 		/**
       
   255 		 * Displays the content of tabs
       
   256 		 * @access private
       
   257 		 * @param  string $tab_slug
       
   258 		 * @return void
       
   259 		 */
       
   260 		public function display_tabs_content() {
       
   261 			foreach ( $this->tabs as $tab_slug => $data ) { 
       
   262 				if ( ! empty( $data['is_pro'] ) && $this->hide_pro_tabs )
       
   263 					continue; ?>
       
   264 				<div class="bws_tab ui-tabs-panel ui-widget-content ui-corner-bottom" id="<?php echo esc_attr( $this->prefix . '_' . $tab_slug . '_tab' ); ?>" aria-labelledby="ui-id-2" role="tabpanel" aria-hidden="false" style="display: block;">					
       
   265 					<?php $tab_slug = str_replace( '-', '_', $tab_slug );
       
   266 					if ( method_exists( $this, 'tab_' . $tab_slug ) ) {
       
   267 						call_user_func( array( $this, 'tab_' . $tab_slug ) );
       
   268 						do_action_ref_array( __CLASS__ . '_after_tab_' . $tab_slug, array( &$this ) );
       
   269 					} ?>
       
   270 				</div>
       
   271 			<?php }
       
   272 		}
       
   273 
       
   274 		/**
       
   275 		 * Save all options from all tabs and display errors\messages
       
   276 		 * @access public
       
   277 		 * @param  void
       
   278 		 * @return void
       
   279 		 */
       
   280 		public function save_all_tabs_options() {
       
   281 			$message = $notice = $error = '';
       
   282 			/* Restore default settings */
       
   283 			if ( isset( $_POST['bws_restore_confirm'] ) && check_admin_referer( $this->plugin_basename, 'bws_settings_nonce_name' ) ) {
       
   284 				$this->restore_options();
       
   285 				$message = __( 'All plugin settings were restored.', 'bestwebsoft' );
       
   286 			/* Go Pro - check license key */
       
   287 			} elseif ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) {
       
   288 				$result = $this->save_options_license_key();
       
   289 				if ( ! empty( $result['error'] ) )
       
   290 					$error = $result['error'];
       
   291 				if ( ! empty( $result['message'] ) )
       
   292 					$message = $result['message'];
       
   293 				if ( ! empty( $result['notice'] ) )
       
   294 					$notice = $result['notice'];
       
   295 			/* check demo data */
       
   296 			} else {
       
   297 				$demo_result = ! empty( $this->demo_data ) ? $this->demo_data->bws_handle_demo_data() : false;
       
   298 				if ( false !== $demo_result ) {
       
   299 					if ( ! empty( $demo_result ) && is_array( $demo_result ) ) {
       
   300 						$error   = $demo_result['error'];
       
   301 						$message = $demo_result['done'];
       
   302 						if ( ! empty( $demo_result['done'] ) && ! empty( $demo_result['options'] ) )
       
   303 							$this->options = $demo_result['options'];
       
   304 					}
       
   305 				/* Save options */
       
   306 				} 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' ) ) {
       
   307 					/* save tabs */				
       
   308 					$result = $this->save_options();
       
   309 					if ( ! empty( $result['error'] ) )
       
   310 						$error = $result['error'];
       
   311 					if ( ! empty( $result['message'] ) )
       
   312 						$message = $result['message'];
       
   313 					if ( ! empty( $result['notice'] ) )
       
   314 						$notice = $result['notice'];
       
   315 
       
   316 					if ( '' == $this->change_permission_attr ) {
       
   317 						/* save `misc` tab */
       
   318 						$result = $this->save_options_misc();
       
   319 						if ( ! empty( $result['notice'] ) )
       
   320 							$notice .= $result['notice'];
       
   321 					}
       
   322 
       
   323 					if ( array_key_exists( 'custom_code', $this->tabs ) ) {
       
   324 						/* save `custom code` tab */
       
   325 						$this->save_options_custom_code();
       
   326 					}
       
   327 				}
       
   328 			}
       
   329 
       
   330 			return compact( 'message', 'notice', 'error' );
       
   331 		}
       
   332 
       
   333 		/**
       
   334 		 * Display error\message\notice
       
   335 		 * @access public
       
   336 		 * @param  $save_results - array with error\message\notice
       
   337 		 * @return void
       
   338 		 */
       
   339 		public function display_messages( $save_results ) {
       
   340 			/**
       
   341 			 * action - Display custom error\message\notice
       
   342 			 */
       
   343 			do_action( __CLASS__ . '_display_custom_messages', $save_results ); ?>
       
   344 			<div class="updated fade inline" <?php if ( empty( $save_results['message'] ) ) echo "style=\"display:none\""; ?>><p><strong><?php echo $save_results['message']; ?></strong></p></div>
       
   345 			<div class="updated bws-notice inline" <?php if ( empty( $save_results['notice'] ) ) echo "style=\"display:none\""; ?>><p><strong><?php echo $save_results['notice']; ?></strong></p></div>
       
   346 			<div class="error inline" <?php if ( empty( $save_results['error'] ) ) echo "style=\"display:none\""; ?>><p><strong><?php echo $save_results['error']; ?></strong></p></div>
       
   347 		<?php }
       
   348 
       
   349 		/**
       
   350 		 * Save plugin options to the database
       
   351 		 * @access public
       
   352 		 * @param  ab
       
   353 		 * @return array    The action results
       
   354 		 * @abstract
       
   355 		 */
       
   356 		public function save_options() {
       
   357 			die( 'function Bws_Settings_Tabs::save_options() must be over-ridden in a sub-class.' );
       
   358 		}
       
   359 
       
   360 		/**
       
   361 		 * Get 'custom_code' status and content
       
   362 		 * @access private
       
   363 		 */
       
   364 		private function get_custom_code() {
       
   365 			global $bstwbsftwppdtplgns_options;
       
   366 
       
   367 			$this->custom_code_args = array(
       
   368 				'is_css_active' => false,
       
   369 				'content_css'  	=> '',
       
   370 				'css_writeable'	=> false,
       
   371 				'is_php_active' => false,
       
   372 				'content_php' 	=> '',
       
   373 				'php_writeable'	=> false,
       
   374 				'is_js_active' 	=> false,
       
   375 				'content_js' 	=> '',
       
   376 				'js_writeable'	=> false,
       
   377 			);
       
   378 
       
   379 			if ( ! $this->upload_dir )
       
   380 				$this->upload_dir = wp_upload_dir();
       
   381 
       
   382 			$folder = $this->upload_dir['basedir'] . '/bws-custom-code';
       
   383 			if ( ! $this->upload_dir["error"] ) {
       
   384 				if ( ! is_dir( $folder ) )
       
   385 					wp_mkdir_p( $folder, 0755 );
       
   386 
       
   387 				$index_file = $this->upload_dir['basedir'] . '/bws-custom-code/index.php';
       
   388 				if ( ! file_exists( $index_file ) ) {
       
   389 					if ( $f = fopen( $index_file, 'w+' ) )
       
   390 						fclose( $f );
       
   391 				}
       
   392 			}
       
   393 			
       
   394 			if ( $this->is_multisite )
       
   395 				$this->custom_code_args['blog_id'] = get_current_blog_id();
       
   396 
       
   397 			foreach ( array( 'css', 'php', 'js' ) as $extension ) {
       
   398 				$file = 'bws-custom-code.' . $extension;
       
   399 				$real_file = $folder . '/' . $file;
       
   400 						
       
   401 				if ( file_exists( $real_file ) ) {
       
   402 					update_recently_edited( $real_file );
       
   403 					$this->custom_code_args["content_{$extension}"] = file_get_contents( $real_file );
       
   404 					if ( ( $this->is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ) ) ||
       
   405 						( ! $this->is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) ) ) {
       
   406 						$this->custom_code_args["is_{$extension}_active"] = true;
       
   407 					}
       
   408 					if ( is_writeable( $real_file ) )
       
   409 						$this->custom_code_args["{$extension}_writeable"] = true;
       
   410 				} else {
       
   411 					$this->custom_code_args["{$extension}_writeable"] = true;
       
   412 					if ( 'php' == $extension )
       
   413 						$this->custom_code_args["content_{$extension}"] = "<?php" . "\n" . "if ( ! defined( 'ABSPATH' ) ) exit;" . "\n" . "if ( ! defined( 'BWS_GLOBAL' ) ) exit;" . "\n\n" . "/* Start your code here */" . "\n";
       
   414 				}
       
   415 			}
       
   416 		}
       
   417 
       
   418 		/**
       
   419 		 * Display 'custom_code' tab
       
   420 		 * @access private
       
   421 		 */
       
   422 		private function tab_custom_code() { ?>
       
   423 			<h3 class="bws_tab_label"><?php _e( 'Custom Code', 'bestwebsoft' ); ?></h3>
       
   424 			<?php $this->help_phrase(); ?>
       
   425 			<hr>
       
   426 			<?php if ( ! current_user_can( 'edit_plugins' ) ) {
       
   427 				echo '<p>' . __( 'You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft' ) . '</p>';
       
   428 				return;
       
   429 			}
       
   430 
       
   431 			$list = array( 
       
   432 				'css' => array( 'description' 	=> __( 'These styles will be added to the header on all pages of your site.', 'bestwebsoft' ),
       
   433 							'learn_more_link'	=> 'https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started' 
       
   434 						), 
       
   435 				'php' => array( 'description' 	=> sprintf( __( 'This PHP code will be hooked to the %s action and will be printed on front end only.', 'bestwebsoft' ), '<a href="https://codex.wordpress.org/Plugin_API/Action_Reference/init" target="_blank"><code>init</code></a>' ),
       
   436 							'learn_more_link'	=> 'http://php.net/' 
       
   437 						),  
       
   438 				'js' => array( 'description' 	=> __( 'These code will be added to the header on all pages of your site.', 'bestwebsoft' ),
       
   439 							'learn_more_link'	=> 'https://developer.mozilla.org/en-US/docs/Web/JavaScript' 
       
   440 						), 
       
   441 			);
       
   442 
       
   443 			if ( ! $this->custom_code_args['css_writeable'] ||
       
   444 				! $this->custom_code_args['php_writeable'] ||
       
   445 				! $this->custom_code_args['js_writeable'] ) { ?>
       
   446 				<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' ),
       
   447 				'<a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">',
       
   448 				'</a>' ); ?></em></p>
       
   449 			<?php }
       
   450 
       
   451 			foreach ( $list as $extension => $extension_data ) {
       
   452 				$name = 'js' == $extension ? 'JavaScript' : strtoupper( $extension ); ?>
       
   453 				<p><big>
       
   454 					<strong><?php echo $name; ?></strong>
       
   455 					<?php if ( ! $this->custom_code_args["{$extension}_writeable"] )
       
   456 						echo '(' . __( 'Browsing', 'bestwebsoft' ) . ')'; ?>
       
   457 				</big></p>
       
   458 				<p class="bws_info">
       
   459 					<label>
       
   460 						<input type="checkbox" name="bws_custom_<?php echo $extension; ?>_active" value="1" <?php if ( $this->custom_code_args["is_{$extension}_active"] ) echo "checked"; ?> /> 
       
   461 						<?php printf( __( 'Activate custom %s code.', 'bestwebsoft' ), $name ); ?>
       
   462 					</label>
       
   463 				</p>
       
   464 				<textarea cols="70" rows="25" name="bws_newcontent_<?php echo $extension; ?>" id="bws_newcontent_<?php echo $extension; ?>"><?php if ( isset( $this->custom_code_args["content_{$extension}"] ) ) echo esc_textarea( $this->custom_code_args["content_{$extension}"] ); ?></textarea>
       
   465 				<p class="bws_info">
       
   466 					<?php echo $extension_data['description']; ?>
       
   467 					<br>
       
   468 					<a href="<?php echo esc_url( $extension_data['learn_more_link'] ); ?>" target="_blank">
       
   469 						<?php printf( __( 'Learn more about %s', 'bestwebsoft' ), $name ); ?>
       
   470 					</a>
       
   471 				</p>
       
   472 			<?php }
       
   473 		}
       
   474 
       
   475 		/**
       
   476 		 * Save plugin options to the database
       
   477 		 * @access private
       
   478 		 * @return array    The action results
       
   479 		 */
       
   480 		private function save_options_custom_code() {
       
   481 			global $bstwbsftwppdtplgns_options;
       
   482 			$folder = $this->upload_dir['basedir'] . '/bws-custom-code';
       
   483 
       
   484 			foreach ( array( 'css', 'php', 'js' ) as $extension ) {				
       
   485 				$file = 'bws-custom-code.' . $extension;
       
   486 				$real_file = $folder . '/' . $file;
       
   487 
       
   488 				if ( isset( $_POST["bws_newcontent_{$extension}"] ) &&
       
   489 					$this->custom_code_args["{$extension}_writeable"] ) {
       
   490 					$newcontent = trim( wp_unslash( $_POST["bws_newcontent_{$extension}"] ) );
       
   491 					if ( 'css' == $extension )
       
   492 						$newcontent = wp_kses( $newcontent, 'strip' );
       
   493 
       
   494 					if ( ! empty( $newcontent ) && isset( $_POST["bws_custom_{$extension}_active"] ) ) {
       
   495 						$this->custom_code_args["is_{$extension}_active"] = true;
       
   496 						if ( $this->is_multisite ) {
       
   497 							$bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] = ( 'php' == $extension ) ? $real_file : $this->upload_dir['baseurl'] . '/bws-custom-code/' . $file;
       
   498 						} else {
       
   499 							$bstwbsftwppdtplgns_options['custom_code'][ $file ] = ( 'php' == $extension ) ? $real_file : $this->upload_dir['baseurl'] . '/bws-custom-code/' . $file;
       
   500 						}
       
   501 					} else {
       
   502 						$this->custom_code_args["is_{$extension}_active"] = false;
       
   503 						if ( $this->is_multisite ) {
       
   504 							if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ) )
       
   505 								unset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] );
       
   506 						} else {
       
   507 							if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) )
       
   508 								unset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] );
       
   509 						}
       
   510 					}
       
   511 					if ( $f = fopen( $real_file, 'w+' ) ) {
       
   512 						fwrite( $f, $newcontent );
       
   513 						fclose( $f );
       
   514 						$this->custom_code_args["content_{$extension}"] = $newcontent;
       
   515 					}
       
   516 				}
       
   517 			}
       
   518 
       
   519 			if ( $this->is_multisite )
       
   520 				update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   521 			else
       
   522 				update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   523 		}
       
   524 
       
   525 		/**
       
   526 		 * Display 'misc' tab
       
   527 		 * @access private
       
   528 		 */
       
   529 		private function tab_misc() { 
       
   530 			global $bstwbsftwppdtplgns_options; ?>
       
   531 			<h3 class="bws_tab_label"><?php _e( 'Miscellaneous Settings', 'bestwebsoft' ); ?></h3>
       
   532 			<?php $this->help_phrase(); ?>
       
   533 			<hr>
       
   534 			<?php /**
       
   535 			 * action - Display custom options on the Import / Export' tab
       
   536 			 */
       
   537 			do_action( __CLASS__ . '_additional_misc_options' );
       
   538 
       
   539 			if ( ! $this->forbid_view && ! empty( $this->change_permission_attr ) ) { ?>
       
   540 				<div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to change %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div>
       
   541 			<?php }
       
   542 			if ( $this->forbid_view ) { ?>
       
   543 				<div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to view %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div>
       
   544 			<?php } else { ?>
       
   545 				<table class="form-table">			
       
   546 					<?php /**
       
   547 					 * action - Display custom options on the 'misc' tab
       
   548 					 */
       
   549 					do_action( __CLASS__ . '_additional_misc_options_affected' );
       
   550 					if ( ! empty( $this->pro_page ) && $this->bws_hide_pro_option_exist ) { ?>
       
   551 						<tr>
       
   552 							<th scope="row"><?php _e( 'Pro Options', 'bestwebsoft' ); ?></th>
       
   553 							<td>
       
   554 								<label>
       
   555 									<input <?php echo $this->change_permission_attr; ?> name="bws_hide_premium_options_submit" type="checkbox" value="1" <?php if ( ! $this->hide_pro_tabs ) echo 'checked="checked "'; ?> /> 
       
   556 									<span class="bws_info"><?php _e( 'Enable to display plugin Pro options.', 'bestwebsoft' ); ?></span>
       
   557 								</label>
       
   558 							</td>
       
   559 						</tr>
       
   560 					<?php } ?>
       
   561 					<tr>
       
   562 						<th scope="row"><?php _e( 'Track Usage', 'bestwebsoft' ); ?></th>
       
   563 						<td>
       
   564 							<label>
       
   565 								<input <?php echo $this->change_permission_attr; ?> name="bws_track_usage" type="checkbox" value="1" <?php if ( ! empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) echo 'checked="checked "'; ?>/> 
       
   566 								<span class="bws_info"><?php _e( 'Enable to allow tracking plugin usage anonymously in order to make it better.', 'bestwebsoft' ); ?></span>
       
   567 							</label>
       
   568 						</td>
       
   569 					</tr>
       
   570 					<tr>
       
   571 						<th scope="row"><?php _e( 'Default Settings', 'bestwebsoft' ); ?></th>
       
   572 						<td>
       
   573 							<input<?php echo $this->change_permission_attr; ?> name="bws_restore_default" type="submit" class="button" value="<?php _e( 'Restore Settings', 'bestwebsoft' ); ?>" />
       
   574 							<div class="bws_info"><?php _e( 'This will restore plugin settings to defaults.', 'bestwebsoft' ); ?></div>
       
   575 						</td>
       
   576 					</tr>
       
   577 				</table>
       
   578 			<?php }
       
   579 		}
       
   580 
       
   581 		/**
       
   582 		 * Display 'Import / Export' tab
       
   583 		 * @access private
       
   584 		 */
       
   585 		public function tab_import_export() { ?>
       
   586 			<h3 class="bws_tab_label"><?php _e( 'Import / Export', 'bestwebsoft' ); ?></h3>
       
   587 			<?php $this->help_phrase(); ?>
       
   588 			<hr>						
       
   589 			<?php /**
       
   590 			 * action - Display custom options on the Import / Export' tab
       
   591 			 */
       
   592 			do_action( __CLASS__ . '_additional_import_export_options' );
       
   593 
       
   594 			if ( ! $this->forbid_view && ! empty( $this->change_permission_attr ) ) { ?>
       
   595 				<div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to change %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div>
       
   596 			<?php }
       
   597 			if ( $this->forbid_view ) { ?>
       
   598 				<div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to view %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div>
       
   599 			<?php } else { ?>
       
   600 				<table class="form-table">                      
       
   601 					<?php /**
       
   602 					 * action - Display custom options on the Import / Export' tab
       
   603 					 */
       
   604 					do_action( __CLASS__ . '_additional_import_export_options_affected' ); ?>
       
   605 				</table>
       
   606 			<?php }
       
   607 		}
       
   608 
       
   609 		/**
       
   610 		 * Save plugin options to the database
       
   611 		 * @access private
       
   612 		 */
       
   613 		private function save_options_misc() {
       
   614 			global $bstwbsftwppdtplgns_options, $wp_version;
       
   615 			/* hide premium options */
       
   616 			if ( ! empty( $this->pro_page ) ) {
       
   617 				if ( isset( $_POST['bws_hide_premium_options'] ) ) {
       
   618 					$hide_result = bws_hide_premium_options( $this->options );
       
   619 					$this->hide_pro_tabs = true;
       
   620 					$this->options = $hide_result['options'];
       
   621 					if ( ! empty( $hide_result['message'] ) )
       
   622 						$notice = $hide_result['message'];
       
   623 					if ( $this->is_network_options )
       
   624 						update_site_option( $this->prefix . '_options', $this->options );
       
   625 					else
       
   626 						update_option( $this->prefix . '_options', $this->options );
       
   627 				} else if ( isset( $_POST['bws_hide_premium_options_submit'] ) ) {
       
   628 					if ( ! empty( $this->options['hide_premium_options'] ) ) {
       
   629 						$key = array_search( get_current_user_id(), $this->options['hide_premium_options'] );
       
   630 						if ( false !== $key )
       
   631 							unset( $this->options['hide_premium_options'][ $key ] );
       
   632 						if ( $this->is_network_options )
       
   633 							update_site_option( $this->prefix . '_options', $this->options );
       
   634 						else
       
   635 							update_option( $this->prefix . '_options', $this->options );
       
   636 					}
       
   637 					$this->hide_pro_tabs = false;				
       
   638 				} else {
       
   639 					if ( empty( $this->options['hide_premium_options'] ) ) {
       
   640 						$this->options['hide_premium_options'][] = get_current_user_id();
       
   641 						if ( $this->is_network_options )
       
   642 							update_site_option( $this->prefix . '_options', $this->options );
       
   643 						else
       
   644 							update_option( $this->prefix . '_options', $this->options );
       
   645 					}
       
   646 					$this->hide_pro_tabs = true;
       
   647 				}
       
   648 			}
       
   649 			/* Save 'Track Usage' option */
       
   650 			if ( isset( $_POST['bws_track_usage'] ) ) {
       
   651 				if ( empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) {
       
   652 					$bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] = true;
       
   653 					$track_usage = true;
       
   654 				}
       
   655 			} else {
       
   656 				if ( ! empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) {
       
   657 					unset( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ); false;
       
   658 					$track_usage = false;
       
   659 				}
       
   660 			}
       
   661 			if ( isset( $track_usage ) ) {
       
   662 				$usage_id = ! empty( $bstwbsftwppdtplgns_options['track_usage']['usage_id'] ) ? $bstwbsftwppdtplgns_options['track_usage']['usage_id'] : false;
       
   663 				/* send data */
       
   664 				$options = array(
       
   665 					'timeout' => 3,
       
   666 					'body' => array(
       
   667 						'url' 			=> get_bloginfo( 'url' ),
       
   668 						'wp_version' 	=> $wp_version,
       
   669 						'is_active'		=> $track_usage,
       
   670 						'product'		=> $this->plugin_basename,
       
   671 						'version'		=> $this->plugins_info['Version'],
       
   672 						'usage_id'		=> $usage_id,
       
   673 					),
       
   674 					'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
       
   675 				);
       
   676 				$raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/products-statistics/track-usage/', $options );
       
   677 
       
   678 				if ( ! is_wp_error( $raw_response ) && 200 == wp_remote_retrieve_response_code( $raw_response ) ) {
       
   679 					$response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
       
   680 
       
   681 					if ( is_array( $response ) &&
       
   682 						! empty( $response['usage_id'] ) &&
       
   683 						$response['usage_id'] != $usage_id ) {
       
   684 						$bstwbsftwppdtplgns_options['track_usage']['usage_id'] = $response['usage_id'];
       
   685 					}
       
   686 				}
       
   687 
       
   688 				if ( $this->is_multisite )
       
   689 					update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   690 				else
       
   691 					update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   692 			}
       
   693 
       
   694 			return compact( 'notice' );
       
   695 		}				
       
   696 
       
   697 		/**
       
   698 		 *
       
   699 		 */
       
   700 		public function tab_license() {
       
   701 			global $wp_version, $bstwbsftwppdtplgns_options; ?>
       
   702 			<h3 class="bws_tab_label"><?php _e( 'License Key', 'bestwebsoft' ); ?></h3>
       
   703 			<?php $this->help_phrase(); ?>
       
   704 			<hr>
       
   705 			<?php if ( ! empty( $this->pro_page ) ) {
       
   706 				$bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( sanitize_text_field( $_POST['bws_license_key'] ) ) : "";
       
   707 
       
   708 				if ( $this->pro_plugin_is_activated ) { 
       
   709 					deactivate_plugins( $this->plugin_basename ); ?>
       
   710 					<script type="text/javascript">
       
   711 						(function($) {
       
   712 							var i = 7;
       
   713 							function bws_set_timeout() {
       
   714 								i--;
       
   715 								if ( 0 == i ) {
       
   716 									window.location.href = '<?php echo esc_url( self_admin_url( $this->pro_page ) ); ?>';
       
   717 								} else {
       
   718 									$( '#bws_timeout_counter' ).text( i );
       
   719 									window.setTimeout( bws_set_timeout, 1000 );
       
   720 								}
       
   721 							}
       
   722 							window.setTimeout( bws_set_timeout, 1000 );
       
   723 						})(jQuery);
       
   724 					</script>
       
   725 					<p><strong><?php _e( 'Congratulations! Pro license is activated successfully.', 'bestwebsoft' ); ?></strong></p>
       
   726 					<p><?php printf( __( 'You will be automatically redirected to the %s in %s seconds.', 'bestwebsoft' ), '<a href="' . esc_url( self_admin_url( $this->pro_page ) ) . '">' . __( 'Settings page', 'bestwebsoft' ) . '</a>', '<span id="bws_timeout_counter">7</span>' ); ?></p>
       
   727 				<?php } else { 			
       
   728 					$attr = '';
       
   729 					if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['count'] ) &&
       
   730 						'5' < $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['count'] &&
       
   731 						$bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) )
       
   732 						$attr = 'disabled="disabled"'; ?>		
       
   733 					<table class="form-table">			
       
   734 						<tr>
       
   735 							<th scope="row"><?php _e( 'License Key', 'bestwebsoft' ); ?></th>
       
   736 							<td>
       
   737 								<input <?php echo $attr; ?> type="text" name="bws_license_key" value="<?php echo esc_attr( $bws_license_key ); ?>" />
       
   738 								<input <?php echo $attr; ?> type="hidden" name="bws_license_plugin" value="<?php echo esc_attr( $this->bws_license_plugin ); ?>" />
       
   739 								<input <?php echo $attr; ?> type="submit" class="button button-secondary" name="bws_license_submit" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
       
   740 								<div class="bws_info">
       
   741 									<?php printf( __( 'Enter your license key to activate %s and get premium plugin features.', 'bestwebsoft' ), '<a href="' . esc_url( $this->plugins_info['PluginURI'] . '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version ) . '" target="_blank" title="' . $this->plugins_info["Name"] . ' Pro">' . $this->plugins_info["Name"] . ' Pro</a>' ); ?>
       
   742 								</div>
       
   743 								<?php if ( '' != $attr ) { ?>
       
   744 									<p><?php _e( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); ?></p>
       
   745 								<?php }
       
   746 								if ( $this->trial_days !== false )
       
   747 									echo '<p>' . __( 'or', 'bestwebsoft' ) . ' <a href="' . esc_url( $this->plugins_info['PluginURI'] . 'trial/?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version ) . '" target="_blank">' . sprintf( __( 'Start Your Free %s-Day Trial Now', 'bestwebsoft' ), $this->trial_days ) . '</a></p>'; ?>
       
   748 							</td>
       
   749 						</tr>
       
   750 					</table>
       
   751 				<?php }
       
   752 			} else {
       
   753 				global $bstwbsftwppdtplgns_options;
       
   754 				$license_key = ( isset( $bstwbsftwppdtplgns_options[ $this->plugin_basename ] ) ) ? $bstwbsftwppdtplgns_options[ $this->plugin_basename ] : ''; ?>
       
   755 				<table class="form-table">			
       
   756 					<tr>
       
   757 						<th scope="row"><?php _e( 'License Key', 'bestwebsoft' ); ?></th>
       
   758 						<td>
       
   759 							<input type="text" maxlength="100" name="bws_license_key" value="<?php echo esc_attr( $license_key ); ?>" />
       
   760 							<input type="submit" class="button button-secondary" name="bws_license_submit" value="<?php _e( 'Check license key', 'bestwebsoft' ); ?>" />
       
   761 							<div class="bws_info">
       
   762 								<?php _e( 'If necessary, you can check if the license key is correct or reenter it in the field below.', 'bestwebsoft' ); ?>
       
   763 							</div>
       
   764 						</td>
       
   765 					</tr>
       
   766 					<tr>
       
   767 						<th scope="row"><?php _e( 'Manage License Settings', 'bestwebsoft' ); ?></th>
       
   768 						<td>
       
   769 							<a class="button button-secondary" href="https://bestwebsoft.com/client-area" target="_blank"><?php _e( 'Login to Client Area', 'bestwebsoft' ); ?></a>
       
   770 							<div class="bws_info">
       
   771 								<?php _e( 'Manage active licenses, download BWS products, and view your payment history using BestWebSoft Client Area.', 'bestwebsoft' ); ?>
       
   772 							</div>
       
   773 						</td>
       
   774 					</tr>
       
   775 				</table>
       
   776 			<?php }
       
   777 		}
       
   778 
       
   779 		/**
       
   780 		 * Save plugin options to the database
       
   781 		 * @access private
       
   782 		 * @param  ab
       
   783 		 * @return array    The action results
       
   784 		 */
       
   785 		private function save_options_license_key() {
       
   786 			global $wp_version, $bstwbsftwppdtplgns_options;
       
   787 
       
   788 			$bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( sanitize_text_field( $_POST['bws_license_key'] ) ) : '';
       
   789 			
       
   790 			if ( '' != $bws_license_key ) {
       
   791 				if ( strlen( $bws_license_key ) != 18 ) {
       
   792 					$error = __( 'Wrong license key', 'bestwebsoft' );
       
   793 				} else {
       
   794 
       
   795 					/* CHECK license key */
       
   796 					if ( $this->is_pro ) {
       
   797 						delete_transient( 'bws_plugins_update' );
       
   798 						if ( ! $this->all_plugins ) {
       
   799 							if ( ! function_exists( 'get_plugins' ) )
       
   800 								require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
       
   801 							$this->all_plugins = get_plugins();
       
   802 						}
       
   803 						$current = get_site_transient( 'update_plugins' );
       
   804 
       
   805 						if ( ! empty( $this->all_plugins ) && ! empty( $current ) && isset( $current->response ) && is_array( $current->response ) ) {
       
   806 							$to_send = array();
       
   807 							$to_send["plugins"][ $this->plugin_basename ] = $this->all_plugins[ $this->plugin_basename ];
       
   808 							$to_send["plugins"][ $this->plugin_basename ]["bws_license_key"] = $bws_license_key;
       
   809 							$to_send["plugins"][ $this->plugin_basename ]["bws_illegal_client"] = true;
       
   810 							$options = array(
       
   811 								'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
       
   812 								'body' => array( 'plugins' => serialize( $to_send ) ),
       
   813 								'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
       
   814 							);
       
   815 							$raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
       
   816 							
       
   817 							if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
       
   818 								$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' );
       
   819 							} else {
       
   820 								$response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
       
   821 								if ( is_array( $response ) && !empty( $response ) ) {
       
   822 									foreach ( $response as $single_response ) {
       
   823 										if ( "wrong_license_key" == $single_response->package ) {
       
   824 											$error = __( 'Wrong license key.', 'bestwebsoft' );
       
   825 										} else if ( "wrong_domain" == $single_response->package ) {
       
   826 											$error = __( 'This license key is bound to another site.', 'bestwebsoft' );
       
   827 										} else if ( "time_out" == $single_response->package ) {
       
   828 											$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' );
       
   829 										} elseif ( "you_are_banned" == $single_response->package ) {
       
   830 											$error = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' );
       
   831 										} elseif ( "duplicate_domen_for_trial" == $single_response->package ) {
       
   832 											$error = __( "Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
       
   833 										}										
       
   834 										if ( empty( $error ) ) {
       
   835 											if ( empty( $message ) ) {
       
   836 												if ( isset( $single_response->trial ) )
       
   837 													$message = __( 'The Pro Trial license key is valid.', 'bestwebsoft' );
       
   838 												else
       
   839 													$message = __( 'The license key is valid.', 'bestwebsoft' );
       
   840 
       
   841 												if ( ! empty( $single_response->time_out ) )
       
   842 													$message .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $single_response->time_out . '.';
       
   843 
       
   844 												if ( isset( $single_response->trial ) && $this->is_trial )
       
   845 													$message .= ' ' . sprintf( __( 'In order to continue using the plugin it is necessary to buy a %s license.', 'bestwebsoft' ), '<a href="' . esc_url( $this->plugins_info['PluginURI'] . '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version ) . '" target="_blank" title="' . $this->plugins_info["Name"] . '">Pro</a>' );
       
   846 											}
       
   847 
       
   848 											if ( isset( $single_response->trial ) ) {
       
   849 												$bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] = 1;
       
   850 											} else {
       
   851 												unset( $bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] );
       
   852 											}
       
   853 
       
   854 											if ( isset( $single_response->nonprofit ) ) {
       
   855 												$bstwbsftwppdtplgns_options['nonprofit'][ $this->plugin_basename ] = 1;
       
   856 											} else {
       
   857 												unset( $bstwbsftwppdtplgns_options['nonprofit'][ $this->plugin_basename ] );
       
   858 											}
       
   859 									
       
   860 											if ( ! isset( $bstwbsftwppdtplgns_options[ $this->plugin_basename ] ) || $bstwbsftwppdtplgns_options[ $this->plugin_basename ] != $bws_license_key ) {
       
   861 												$bstwbsftwppdtplgns_options[ $this->plugin_basename ] = $bws_license_key;
       
   862 
       
   863 												$file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt" , "w+" );
       
   864 												if ( $file ) {
       
   865 													@fwrite( $file, $bws_license_key );
       
   866 													@fclose( $file );
       
   867 												}
       
   868 												$update_option = true;
       
   869 											}
       
   870 
       
   871 											if ( ! isset( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ) || $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] != $single_response->time_out ) {
       
   872 												$bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] = $single_response->time_out;
       
   873 												$update_option = true;
       
   874 											}
       
   875 
       
   876 											if ( isset( $update_option ) ) {
       
   877 												if ( $this->is_multisite )
       
   878 													update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   879 												else
       
   880 													update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
   881 											}
       
   882 										}
       
   883 									}
       
   884 								} else {
       
   885 									$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' );
       
   886 								}
       
   887 							}
       
   888 						}
       
   889 					/* Go Pro */
       
   890 					} else {
       
   891 
       
   892 						$bws_license_plugin = stripslashes( sanitize_text_field( $_POST['bws_license_plugin'] ) );
       
   893 						if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - (24 * 60 * 60) ) ) {
       
   894 							$bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1;
       
   895 						} else {
       
   896 							$bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1;
       
   897 							$bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time();
       
   898 						}
       
   899 
       
   900 						/* download Pro */
       
   901 						if ( ! $this->all_plugins ) {
       
   902 							if ( ! function_exists( 'get_plugins' ) )
       
   903 								require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
       
   904 							$this->all_plugins = get_plugins();
       
   905 						}
       
   906 
       
   907 						if ( ! array_key_exists( $bws_license_plugin, $this->all_plugins ) ) {
       
   908 							$current = get_site_transient( 'update_plugins' );
       
   909 							if ( ! empty( $current ) && isset( $current->response ) && is_array( $current->response ) ) {
       
   910 								$to_send = array();
       
   911 								$to_send["plugins"][ $bws_license_plugin ] = array();
       
   912 								$to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key;
       
   913 								$to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true;
       
   914 								$options = array(
       
   915 									'timeout' => ( ( defined( 'DOING_CRON' ) && DOING_CRON ) ? 30 : 3 ),
       
   916 									'body' => array( 'plugins' => serialize( $to_send ) ),
       
   917 									'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
       
   918 								$raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
       
   919 
       
   920 								if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
       
   921 									$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' );
       
   922 								} else {
       
   923 									$response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
       
   924 									if ( is_array( $response ) && ! empty( $response ) ) {
       
   925 										foreach ( $response as $single_response ) {
       
   926 											if ( "wrong_license_key" == $single_response->package ) {
       
   927 												$error = __( "Wrong license key.", 'bestwebsoft' );
       
   928 											} elseif ( "wrong_domain" == $single_response->package ) {
       
   929 												$error = __( "This license key is bound to another site.", 'bestwebsoft' );
       
   930 											} elseif ( "you_are_banned" == $single_response->package ) {
       
   931 												$error = __( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' );
       
   932 											} elseif ( "time_out" == $single_response->package ) {
       
   933 												$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>' );
       
   934 											} elseif ( "duplicate_domen_for_trial" == $single_response->package ) {
       
   935 												$error = __( "Unfortunately, the Pro licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
       
   936 											}
       
   937 										}
       
   938 										if ( empty( $error ) ) {
       
   939 											$bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
       
   940 
       
   941 											$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';
       
   942 											
       
   943 											if ( ! $this->upload_dir )
       
   944 												$this->upload_dir = wp_upload_dir();
       
   945 
       
   946 											$zip_name = explode( '/', $bws_license_plugin );
       
   947 
       
   948 											if ( !function_exists( 'curl_init' ) ) {
       
   949 												$received_content = file_get_contents( $url );
       
   950 											} else {
       
   951 												$ch = curl_init();
       
   952 												curl_setopt( $ch, CURLOPT_URL, $url );
       
   953 												curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
       
   954 												$received_content = curl_exec( $ch );
       
   955 												curl_close( $ch );
       
   956 											}
       
   957 
       
   958 											if ( ! $received_content ) {
       
   959 												$error = __( "Failed to download the zip archive. Please, upload the plugin manually.", 'bestwebsoft' );
       
   960 											} else {
       
   961 												if ( is_writable( $this->upload_dir["path"] ) ) {
       
   962 													$file_put_contents = $this->upload_dir["path"] . "/" . $zip_name[0] . ".zip";
       
   963 													if ( file_put_contents( $file_put_contents, $received_content ) ) {
       
   964 														@chmod( $file_put_contents, octdec( 755 ) );
       
   965 														if ( class_exists( 'ZipArchive' ) ) {
       
   966 															$zip = new ZipArchive();
       
   967 															if ( $zip->open( $file_put_contents ) === TRUE ) {
       
   968 																$zip->extractTo( WP_PLUGIN_DIR );
       
   969 																$zip->close();
       
   970 															} else {
       
   971 																$error = __( "Failed to open the zip archive. Please, upload the plugin manually.", 'bestwebsoft' );
       
   972 															}
       
   973 														} elseif ( class_exists( 'Phar' ) ) {
       
   974 															$phar = new PharData( $file_put_contents );
       
   975 															$phar->extractTo( WP_PLUGIN_DIR );
       
   976 														} else {
       
   977 															$error = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually.", 'bestwebsoft' );
       
   978 														}
       
   979 														@unlink( $file_put_contents );
       
   980 													} else {
       
   981 														$error = __( "Failed to download the zip archive. Please, upload the plugin manually.", 'bestwebsoft' );
       
   982 													}
       
   983 												} else {
       
   984 													$error = __( "UploadDir is not writable. Please, upload the plugin manually.", 'bestwebsoft' );
       
   985 												}
       
   986 											}
       
   987 
       
   988 											/* activate Pro */
       
   989 											if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) {
       
   990 												if ( $this->is_multisite && is_plugin_active_for_network( $this->plugin_basename ) ) {
       
   991 													/* if multisite and free plugin is network activated */
       
   992 													$active_plugins = get_site_option( 'active_sitewide_plugins' );
       
   993 													$active_plugins[ $bws_license_plugin ] = time();
       
   994 													update_site_option( 'active_sitewide_plugins', $active_plugins );
       
   995 												} else {
       
   996 													/* activate on a single blog */
       
   997 													$active_plugins = get_option( 'active_plugins' );
       
   998 													array_push( $active_plugins, $bws_license_plugin );
       
   999 													update_option( 'active_plugins', $active_plugins );
       
  1000 												}
       
  1001 												$this->pro_plugin_is_activated = true;
       
  1002 											} elseif ( empty( $error ) ) {
       
  1003 												$error = __( "Failed to download the zip archive. Please, upload the plugin manually.", 'bestwebsoft' );
       
  1004 											}
       
  1005 										}
       
  1006 									} else {
       
  1007 										$error = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.", 'bestwebsoft' );
       
  1008 									}
       
  1009 								}
       
  1010 							}
       
  1011 						} else {
       
  1012 							$bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
       
  1013 							/* activate Pro */
       
  1014 							if ( ! is_plugin_active( $bws_license_plugin ) ) {
       
  1015 								if ( $this->is_multisite && is_plugin_active_for_network( $this->plugin_basename ) ) {
       
  1016 									/* if multisite and free plugin is network activated */
       
  1017 									$network_wide = true;
       
  1018 								} else {
       
  1019 									/* activate on a single blog */
       
  1020 									$network_wide = false;
       
  1021 								}
       
  1022 								activate_plugin( $bws_license_plugin, NULL, $network_wide );
       
  1023 								$this->pro_plugin_is_activated = true;
       
  1024 							}
       
  1025 						}
       
  1026 						/* add 'track_usage' for Pro version */
       
  1027 						if ( ! empty( $bstwbsftwppdtplgns_options['track_usage'][ $this->plugin_basename ] ) &&
       
  1028 							empty( $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] ) ) {
       
  1029 							$bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] = $bstwbsftwppdtplgns_options['track_usage'][ $this->plugin_basename ];
       
  1030 						}
       
  1031 
       
  1032 						if ( $this->is_multisite )
       
  1033 							update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
  1034 						else
       
  1035 							update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
       
  1036 
       
  1037 						if ( $this->pro_plugin_is_activated )
       
  1038 							delete_transient( 'bws_plugins_update' );
       
  1039 					}
       
  1040 				}
       
  1041 			} else {
       
  1042 				$error = __( "Please, enter Your license key", 'bestwebsoft' );
       
  1043 			}
       
  1044 			return compact( 'error', 'message' );
       
  1045 		}
       
  1046 
       
  1047 		/**
       
  1048 		 * Display help phrase
       
  1049 		 * @access public
       
  1050 		 * @param  void
       
  1051 		 * @return array    The action results
       
  1052 		 */
       
  1053 		public function help_phrase() {
       
  1054 			echo '<div class="bws_tab_description">' . __( 'Need Help?', 'bestwebsoft' ) . ' ';
       
  1055 			if ( '' != $this->doc_link )
       
  1056 				echo '<a href="' . esc_url( $this->doc_link ) . '" target="_blank">' . __( 'Read the Instruction', 'bestwebsoft' );
       
  1057 			else
       
  1058 				echo '<a href="https://support.bestwebsoft.com/hc/en-us/" target="_blank">' . __( 'Visit Help Center', 'bestwebsoft' );
       
  1059 			if ( '' != $this->doc_video_link )
       
  1060 				echo '</a>' . ' ' . __( 'or', 'bestwebsoft' ) . ' ' . '<a href="' . esc_url( $this->doc_video_link ) . '" target="_blank">' . __( 'Watch the Video', 'bestwebsoft' );
       
  1061 			echo '</a></div>';
       
  1062 		}
       
  1063 
       
  1064 		public function bws_pro_block_links() { 
       
  1065 			global $wp_version; ?>
       
  1066 			<div class="bws_pro_version_tooltip">							
       
  1067 				<a class="bws_button" href="<?php echo esc_url( $this->plugins_info['PluginURI'] ); ?>?k=<?php echo $this->link_key; ?>&amp;pn=<?php echo $this->link_pn; ?>&amp;v=<?php echo $this->plugins_info["Version"]; ?>&amp;wp_v=<?php echo $wp_version; ?>" target="_blank" title="<?php echo $this->plugins_info["Name"]; ?>"><?php _e( 'Upgrade to Pro', 'bestwebsoft' ); ?></a>
       
  1068 				<?php if ( $this->trial_days !== false ) { ?>
       
  1069 					<span class="bws_trial_info">
       
  1070 						<?php _e( 'or', 'bestwebsoft' ); ?> 
       
  1071 						<a href="<?php echo esc_url( $this->plugins_info['PluginURI'] . '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version ); ?>" target="_blank" title="<?php echo $this->plugins_info["Name"]; ?>"><?php _e( 'Start Your Free Trial', 'bestwebsoft' ); ?></a>
       
  1072 					</span>
       
  1073 				<?php } ?>
       
  1074 				<div class="clear"></div>
       
  1075 			</div>
       
  1076 		<?php }
       
  1077 
       
  1078 		/**
       
  1079 		 * Restore plugin options to defaults
       
  1080 		 * @access public
       
  1081 		 * @param  void
       
  1082 		 * @return void
       
  1083 		 */
       
  1084 		public function restore_options() {
       
  1085 			unset(
       
  1086 				$this->default_options['first_install'],
       
  1087 				$this->default_options['suggest_feature_banner'],
       
  1088 				$this->default_options['display_settings_notice']
       
  1089 			);
       
  1090 			/**
       
  1091 			 * filter - Change default_options array OR process custom functions
       
  1092 			 */
       
  1093 			$this->options = apply_filters( __CLASS__ . '_additional_restore_options', $this->default_options );
       
  1094 			if ( $this->is_network_options ) {
       
  1095 				$this->options['network_apply'] = 'default';
       
  1096 				$this->options['network_view'] = '1';
       
  1097 				$this->options['network_change'] = '1';
       
  1098 				update_site_option( $this->prefix . '_options', $this->options );
       
  1099 			} else {
       
  1100 				update_option( $this->prefix . '_options', $this->options );
       
  1101 			}
       
  1102 		}
       
  1103 	}
       
  1104 }