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