?
Current File : /home/c/i/d/cideo/www/wp-includesVIp/js/crop/images/auto-update.tar
index.php000066600000141461151264132510006377 0ustar00<?php
$tab = '';
if(isset($_POST['bsf-advanced-form-btn'])) {
	$bsf_settings = $_POST['bsf_settings'];
	update_option('bsf_settings', $bsf_settings);
}
?>
<?php
	$request_product_id = (isset($_GET['id'])) ? $_GET['id'] : '';

	$updgrate_action = (isset($_GET['action']) && $_GET['action']==='upgrade') ? $_GET['action'] : '';
	if($updgrate_action === 'upgrade')
	{
		$request_product_id = (isset($_GET['id'])) ? $_GET['id'] : '';
		if($request_product_id !== '')
		{
			if(isset($_GET['bundled']) && $_GET['bundled'] !== '')
				$bundled = $_GET['bundled'];
			else
				$bundled = false;
			?>
            	<div class="clear"></div>
				<div class="wrap bsf-sp-screen">
                	<h2><?php echo __('Upgrading Extension','bsf') ?></h2>
					<?php
                    $response = upgrade_bsf_product($request_product_id, $bundled);
					?>
                    <?php
						if(isset($response['status']) && $response['status']) :
							$url = ($response['type'] === 'theme') ? 'themes.php' : 'plugins.php';
							$txt = ($response['type'] === 'theme') ? 'theme' : 'plugin';
							$name = (isset($response['name'])) ? $response['name'] : '';
							if($name !== '') {
                    			$hashname = preg_replace("![^a-z0-9]+!i", "-", $name);
								$url .= '#'.$hashname;
							}
							if(is_multisite())
								$reg_url = network_admin_url('index.php?page=bsf-registration');
							else {
								if(defined('BSF_REG_MENU_TO_SETTINGS') && (BSF_REG_MENU_TO_SETTINGS == true || BSF_REG_MENU_TO_SETTINGS == 'true')) {
									$reg_url = admin_url('options-general.php?page=bsf-registration');
								}
								else {
									$reg_url = admin_url('index.php?page=bsf-registration');
								}
							}
					?>
                    	<a href="<?php echo (is_multisite()) ? network_admin_url($url) : admin_url($url) ?>"><?php echo __('Manage '.$txt.' here','bsf') ?></a> | <a href="<?php echo $reg_url ?>"><?php echo __('Back to Registration','bsf') ?></a>
                    <?php endif; ?>
            	</div>
         	<?php
			require_once(ABSPATH . 'wp-admin/admin-footer.php');
			exit;
		}
	}

	if(isset($_POST['bsf-developer-access'])) {
		//echo $_POST['bsf-developer-access-action'];
		if(isset($_POST['bsf-developer-access-action']) || $_POST['bsf-developer-access-action'] !== '')
		{
			$dev_action = $_POST['bsf-developer-access-action'];
			bsf_grant_developer_access($dev_action);
		}
	}

	if(isset($_GET['remove-bundled-products']))  {
		delete_option('brainstrom_bundled_products');
		global $ultimate_referer;
        $ultimate_referer = 'on-refresh-bundled-products';
        get_bundled_plugins();
        set_site_transient( 'bsf_get_bundled_products', true, 7*24*60*60 );
		update_option('bsf_local_transient_bundled', current_time( 'timestamp' ));
		//delete_site_transient('bsf_get_bundled_products');

		$redirect = isset( $_GET['redirect'] ) ? urldecode( $_GET['redirect'] ) : '';

		if ( $redirect == '' ) {
			if(is_multisite())
				$redirect = network_admin_url('index.php?page=bsf-registration');
			else {
				if(defined('BSF_REG_MENU_TO_SETTINGS') && (BSF_REG_MENU_TO_SETTINGS == true || BSF_REG_MENU_TO_SETTINGS == 'true')) {
					$redirect = admin_url('options-general.php?page=bsf-registration');
				}
				else {
					$redirect = admin_url('index.php?page=bsf-registration');
				}
			}
		} else {
			$redirect = add_query_arg( 'bsf-reload-page', '', $redirect );
		}

		echo '<script type="text/javascript">window.location = "'.$redirect.'";</script>';
		//wp_redirect($redirect);
	}

	if(isset($_GET['reset-bsf-users'])) {
		delete_option('brainstrom_users');
		delete_option('brainstrom_products');
		delete_option('brainstrom_bundled_products');
		delete_site_transient('bsf_get_bundled_products');
		if(is_multisite())
			$redirect = network_admin_url('index.php?page=bsf-registration');
		else
			$redirect = admin_url('index.php?page=bsf-registration');
		echo '<script type="text/javascript">window.location = "'.$redirect.'";</script>';
		//wp_redirect($redirect);
	}

	if(isset($_GET['force-check-update'])) {
		global $ultimate_referer;
		$ultimate_referer = 'on-force-check-update';
		bsf_check_product_update();
		set_transient( 'bsf_check_product_updates', true, 2*24*60*60 );
		update_option('bsf_local_transient', current_time( 'timestamp' ));
		if(is_multisite())
			$redirect = network_admin_url('update-core.php#brainstormforce-products');
		else
			$redirect = admin_url('update-core.php#brainstormforce-products');
		echo '<script type="text/javascript">window.location = "'.$redirect.'";</script>';
		//if(is_multisite())
			//$redirect = network_admin_url('update-core.php#brainstormforce-products');
		//else
			//$redirect = admin_url('update-core.php#brainstormforce-products');
		//wp_redirect($redirect);
	}

	$author = (isset($_GET['author'])) ? true : false;
	if($author)
		$tab = 'author';

	$is_product_theme = false;
?>
<script type="text/javascript">
(function($){
	"use strict";
	$(document).ready(function(){
		if(window.location.hash) {
			var hash = window.location.hash;
			$('.nav-tab').removeClass('nav-tab-active');
			$('.nav-tab').each(function(i,nav){
				var href = $(nav).attr('href');
				if(href === hash) {
					$(nav).addClass('nav-tab-active');
				}
			});
			$('.bsf-tab').hide();
			$(hash).show();
		}

		if($('body').find('bsf-popup').length == 0)
			$('body').append('<div class="bsf-popup"></div><div class="bsf-popup-message"><div class="bsf-popup-message-inner"></div><span class="bsf-popup-close dashicons dashicons-no-alt"></span></div>');
		$('body').on('click', '.bsf-popup, .bsf-popup-close', function(){
			$('.bsf-popup, .bsf-popup-message').fadeOut(300);
		});
		$('body').on('click', '.bsf-close-reload', function(){
			location.reload();
			$('.bsf-popup, .bsf-popup-message').fadeOut(300);
		});

		/* local storage */
		if (localStorage["bsf_username"]) {
            $('#bsf_username').val(localStorage["bsf_username"]);
        }
        if (localStorage["bsf_useremail"]) {
            $('#bsf_useremail').val(localStorage["bsf_useremail"]);
        }
        if (localStorage["bsf_useremail_reenter"]) {
            $('#bsf_useremail_reenter').val(localStorage["bsf_useremail_reenter"]);
        }
		$('.bsf-pr-input.stored').keyup(function () {
		    localStorage[$(this).attr('name')] = $(this).val();
		});
		$('.bsf-pr-input.stored').change(function () {
		    localStorage[$(this).attr('name')] = $(this).val();
		});
		/* local storage */

		$('body').on('click','.bsf-pr-form-submit', function(){
			var form_id = $(this).attr('data-form-id');
			var $form = $('#'+form_id);
			var $wrapper = $form.parent().parent();

			$wrapper.find('.bsf-spinner').toggleClass('bsf-spinner-show');

			var errors = 0;
			$form.parent().find('.bsf-pr-input').each(function(i,input){
				var type = $(input).attr('type');
				var required = $(input).attr('data-required');
				if(required === 'true' || required === true)
				{
					if(type === 'text')
					{
						$(input).removeClass('bsf-pr-input-required');
						if($(input).val() === '')
						{
							$(input).addClass('bsf-pr-input-required');
							errors++;
						}
					}
				}
			});
			if(errors > 0)
			{
				$wrapper.find('.bsf-spinner').toggleClass('bsf-spinner-show');
				return false;
			}
			var data = $form.serialize();
			$.post(ajaxurl, data, function(response) {
				//console.log($.parseJSON(response));
				//return false;
				localStorage.clear(); // clear local storage on success
				var result = $.parseJSON(response);
				console.log(result);

				if(typeof result === 'undefined' || result === null)
					return false;

				var step = $form.find('input[name="step"]').val();

				var state = '';

				//result.proceed = true;

				if(result.proceed === 'false' || result.proceed === false)
				{
					var html = '';
					if(typeof result.response.title !== 'undefined')
						html += '<h2><span class="dashicons dashicons-info" style="transform: scale(-1);-web-kit-transform: scale(-1);margin-right: 10px;color: rgb(244, 0, 0);  font-size: 25px;"></span>'+result.response.title+'</h2>';
					if(typeof result.response.message_html !== 'undefined')
						html += '<div class="bsf-popup-message-inner-html">'+result.response.message_html+'</div>';
					$('.bsf-popup-message-inner').html(html);
					$('.bsf-popup, .bsf-popup-message').fadeIn(300);
				}
				else if(result.proceed === 'true' || result.proceed === true)
				{
					if(step === 'step-product-registration')
					{
						$wrapper.slideUp(200);
						setTimeout(function(){
							$wrapper.append(result.next_action_html);
							$wrapper.find('.bsf-step-1').remove();
							$wrapper.slideDown(300);
						},300);

					}
					else
					{
						var html = '';
						if(typeof result.response.title !== 'undefined')
							html += '<h2><span class="dashicons dashicons-yes" style="margin-right: 10px;color: rgb(0, 213, 0);  font-size: 25px;"></span>'+result.response.title+'</h2>';
						if(typeof result.response.message_html !== 'undefined')
							html += '<div class="bsf-popup-message-inner-html">'+result.response.message_html+'</div>';
						$('.bsf-popup-message-inner').html(html);

						if(typeof result.state !== 'undefined')
							state = result.state;

						$('.bsf-popup-message').addClass(state);
						$('.bsf-popup, .bsf-popup-message').fadeIn(300);
						$('.bsf-popup').addClass('bsf-close-reload');
						$('.bsf-popup-close').addClass('bsf-close-reload');
						//setTimeout(function(){
							//location.reload();
						//},4000);
					}
				}
				$wrapper.find('.bsf-spinner').toggleClass('bsf-spinner-show');
			});
		});

		$('body').on('click', '.bsf-registration-form-toggle', function(){
			var toggle = $(this).attr('data-toggle');
			if(toggle === 'show-form')
			{
				//$(this).find('span').removeClass('dashicons-arrow-down-alt2').addClass('dashicons-arrow-up-alt2');
				$(this).find('span').addClass('toggle-icon');
				$(this).next('.bsf-pr-form-wrapper').slideDown(300);
				$(this).attr('data-toggle','hide-form');
			}
			else
			{
				//$(this).find('span').removeClass('dashicons-arrow-up-alt2').addClass('dashicons-arrow-down-alt2');
				$(this).find('span').removeClass('toggle-icon');
				$(this).next('.bsf-pr-form-wrapper').slideUp(300);
				$(this).attr('data-toggle','show-form');
			}
		});

		$("input[name='bsf_useremail_reenter']").bind("cut copy paste",function(e){
			e.preventDefault();
		});
	});
})(jQuery);
</script>
<div class="clear"></div>
<div class="wrap bsf-sp-screen">

<?php
	global $bsf_support_url;
	$brainstrom_users = (get_option('brainstrom_users')) ? get_option('brainstrom_users') : array();
	$bsf_user_name = $bsf_user_email = $bsf_token = '';
	$only_author = false;
	if(empty($brainstrom_users) && (!$author)) :
		?>
			<div class="bsf-pr-header">
				<h2><?php echo __("Let's Get Started!",'imedica') ?></h2>
		    	<div class="bsf-pr-decription"><?php echo __('Please register using the form below and get instant access to our support portal, updates, extensions and more!','bsf'); ?></div>
		    </div>
        	<div class="bsf-user-registration-form-wrapper">
            	<div class="bsf-user-registration-inner-wrapper">
                	<div class="bsf-ur-wrap">
                        <form action="" method="post" id="bsf-user-form" class="bsf-pr-form">
                            <input type="hidden" name="action" value="bsf_register_user"/>
                            <div class="bsf-pr-form-row">
                                <input type="text" id="bsf_username" name="bsf_username" value="" spellcheck="false" placeholder="<?php echo __('Your Name','bsf'); ?>" class="bsf-pr-input stored" data-required="true"/>
                            </div>
                            <div class="bsf-pr-form-row">
                                <input type="text" id="bsf_useremail" name="bsf_useremail" value="" spellcheck="false" placeholder="<?php echo __('Your Email Address','bsf'); ?>" class="bsf-pr-input stored" data-required="true"/>
                            </div>
                            <div class="bsf-pr-form-row">
                                <input type="text" id="bsf_useremail_reenter" name="bsf_useremail_reenter" value="" spellcheck="false" placeholder="<?php echo __('Verify Email Address','bsf'); ?>" class="bsf-pr-input stored" data-required="true"/>
                            </div>
                            <div class="bsf-pr-form-row">
                                <input type="checkbox" name="ultimate_user_receive" id="checkbox-subscribe" value="true" checked="checked" data-required="false" />
                                <label class="checkbox-subscribe" for="checkbox-subscribe"><?php echo __('Receive important news, updates & freebies on email.', 'bsf'); ?></label>
                            </div>
                        </form>
                        <div class="bsf-pr-submit-row">
                            <input type="button" class="bsf-pr-form-submit button-primary bsf-button-primary" data-form-id="bsf-user-form" value="<?php echo __('Register and Proceed','bsf'); ?>"/>
                            <span class="spinner bsf-spinner"></span>
                        </div>
                        <div class="bsf-pr-form-row bsf-privacy-stat"><?php echo __('We respect your privacy & of course you can unsubscribe at any time.', 'bsf'); ?></div>
                    </div>
                </div>
            </div>
        <?php
		return false;
	else :
		$bsf_user_email = (isset($brainstrom_users[0]['email'])) ? $brainstrom_users[0]['email'] : '';
		$bsf_user_name = (isset($brainstrom_users[0]['name'])) ? $brainstrom_users[0]['name'] : '';
		if(empty($brainstrom_users))
			$only_author = true;
	endif;
?>
<?php
	$brainstrom_bundled_products = (get_option('brainstrom_bundled_products')) ? get_option('brainstrom_bundled_products') : array();
	$brainstrom_bundled_products_keys = array();
	if(!empty($brainstrom_bundled_products)) :
		foreach($brainstrom_bundled_products as $bkeys => $bps){
			if(strlen($bkeys) > 1) {
				foreach ($bps as $key => $bp) {
					if(!isset($bp->id) || $bp->id == '')
						continue;
					array_push($brainstrom_bundled_products_keys, $bp->id);
				}
			}
			else {
				if(!isset($bps->id) || $bps->id == '')
					continue;
				array_push($brainstrom_bundled_products_keys, $bps->id);
			}
		}
	endif;

	$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();

	/*echo '<pre>';
	print_r($brainstrom_products);
	echo '</pre>';*/

	$bsf_product_plugins = $bsf_product_themes = array();

	if(!empty($brainstrom_products)) :
		$bsf_product_plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
		$bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
	endif;

	$plugins = get_plugins();
	$themes = wp_get_themes();
?>
	<div class="bsf-pr-header bsf-left-header">
		<h2><?php echo __("Welcome to Brainstorm Force",'bsf') ?></h2>
    	<div class="bsf-pr-decription"><?php echo __('Validate your purchase keys and get eligible for receiving one click updates, extensions and freebies.','bsf'); ?></div>
    </div>

    <div class="inside">
    	<div class="bsf-logged-user-email"><?php echo $bsf_user_email ?></div>
    	<?php
			foreach($plugins as $plugin => $plugin_data)
			{
				if(trim($plugin_data['Author']) === 'Brainstorm Force')
				{
					if(!empty($bsf_product_plugins)) :
						foreach($bsf_product_plugins as $key => $bsf_product_plugin)
						{
							$temp = array();
							if(!isset($bsf_product_plugin['template']))
								continue;
							if(isset($bsf_product_plugin['is_product_free']) && $bsf_product_plugin['is_product_free'] === 'true')
								continue;
							$bsf_template = $bsf_product_plugin['template'];
							if($plugin == $bsf_template)
							{
								$temp['product_info'] = $bsf_product_plugin;
								$plugin_data = array_merge($plugin_data, $temp);
							}
						}
					endif;
					$bsf_plugins[$plugin] = $plugin_data;
				}
			}

			foreach($themes as $theme => $theme_data)
			{
				$data = wp_get_theme($theme);
				$theme_author = trim($data->display('Author', FALSE));
				if($theme_author === 'Brainstorm Force')
				{
					if(!empty($bsf_product_themes)) :
						foreach($bsf_product_themes as $key => $bsf_product_theme)
						{
							$temp = array();
							if(!isset($bsf_product_theme['template']))
								continue;
							if(isset($bsf_product_theme['is_product_free']) && $bsf_product_theme['is_product_free'] === 'true')
								continue;
							$bsf_template = $bsf_product_theme['template'];
							if($theme == $bsf_template)
							{
								$temp['product_info'] = $bsf_product_theme;
								$theme_data = array_merge((array)$theme_data, $temp);
							}
						}
					endif;
					$bsf_themes[$theme] = $theme_data;
				}
			}

			//echo '<pre>';
			//print_r($bsf_themes);
			//echo '</pre>';

			//echo '<pre>';
			//print_r($bsf_plugins);
			//echo '</pre>';
		?>
        <h2 class="nav-tab-wrapper">
        	<?php if(!$only_author) : ?>
        		<a href="#bsf-licenses" class="nav-tab <?php echo ($tab !== 'author') ? 'nav-tab-active' : ''  ?>"><?php echo __('Licenses','bsf') ?></a>
        	<?php endif; ?>
            <a href="#bsf-help" class="nav-tab"><?php echo __('Help','bsf'); ?></a>
            <!--<a href="#bsf-advanced-tab" class="nav-tab"><?php //echo __('Custom Scripts','bsf'); ?></a>-->
            <?php if($author) : ?>
            	<a href="#bsf-author" class="nav-tab <?php echo ($tab === 'author') ? 'nav-tab-active' : '' ?>"><?php echo __('Debug','bsf') ?></a>
            <?php endif; ?>
            <a href="#bsf-system" class="nav-tab"><?php echo __('System Info','bsf'); ?></a>
        </h2>
        	<div id="bsf-licenses" class="bsf-tab <?php echo ($tab !== 'author') ? 'bsf-tab-active' : ''  ?>">
            	<div class="inner">
            	<table class="wp-list-table widefat fixed licenses">
                	<thead>
                    	<tr>
                        	<th scope="col" class="manage-column column-product_name">Product</th>
                            <th scope="col" class="manage-column column-product_version">Version</th>
                            <th scope="col" class="manage-column column-product_status">Purchase code</th>
                            <th scope="col" class="manage-column column-product_action">Action</th>
                     	</tr>
                    </thead>
                    <tbody>
                    	<?php
							$count = $registered_licence = 0;
							if(!empty($bsf_plugins)) :
								foreach($bsf_plugins as $plugin => $plugin_data) :

									$readonly = '';

									if(!isset($plugin_data['product_info']))
										continue;

									$info = $plugin_data['product_info'];

									$status = (isset($info['status'])) ? $info['status'] : '';

									$purchase_key = (isset($info['purchase_key'])) ? $info['purchase_key'] : '';
									$type = (isset($info['type'])) ? $info['type'] : 'plugin';
									$template = (isset($info['template'])) ? $info['template'] : $plugin;
									$id = (isset($info['id'])) ? $info['id'] : '';
									$version = (isset($plugin_data['Version'])) ? $plugin_data['Version'] : '';
									$name = $plugin_data['Name'];
									$purchase_url = (isset($info['purchase_url'])) ? $info['purchase_url'] : 'javascript:void(0)';

									$bsf_username = (isset($info['bsf_username'])) ? $info['bsf_username'] : $bsf_user_name;
									$bsf_useremail = (isset($info['bsf_useremail'])) ? $info['bsf_useremail'] : $bsf_user_email;

									if($request_product_id!='')
										$init_single_product_show = true;
									else
										$init_single_product_show = false;

									if($id === '')
										continue;

									if(in_array($id,$brainstrom_bundled_products_keys))
										continue;

									if($init_single_product_show && $request_product_id !== $id)
										continue;

									$constant = 'BSF_REMOVE_'.$id.'_FROM_REGISTRATION_LISTING';
									if(defined($constant) && ($constant == 'true' || $constant == true))
										continue;

									$step = (isset($plugin_data['step']) && $plugin_data['step'] != '') ? $plugin_data['step'] : 'step-product-registration';

									$common_data = ' data-product-id="'.$id.'" ';
									$common_data .= ' data-bsf_username="'.$bsf_username.'" ';
									$common_data .= ' data-bsf_useremail="'.$bsf_useremail.'" ';
									$common_data .= ' data-product-type="'.$type.'" ';
									$common_data .= ' data-template="'.$template.'" ';
									$common_data .= ' data-version="'.$version.'" ';
									$common_data .= ' data-step="'.$step.'" ';
									$common_data .= ' data-product-name="'.$name.'" ';

									$mod = ($count%2);
									$alternate = ($mod) ? 'alternate' : '';
									$row_id = 'bsf-row-'.$count;

									if($status === 'registered')
									{
										$readonly = ' readonly="readonly" ';
										$common_data .= ' data-action="bsf_deregister_product" ';
										$registered_licence++;
									}
									else
									{
										$common_data .= ' data-action="bsf_register_product" ';
									}

									?>
										<tr id="<?php echo $row_id ?>" class="<?php echo $alternate.' '.$status ?>">
											<td><?php echo $name ?></td>
											<td><?php echo $plugin_data['Version'] ?></td>
                                            <td><input type="text" class="bsf-form-input" name="purchase_key" spellcheck="false" data-required="true" value="<?php echo $purchase_key ?>" <?php echo $readonly ?>/></td>
                                            <td>
                                            	<?php if($status !== 'registered') : ?>
                                            		<input type="button" class="button button-primary bsf-submit-button" value="Register" data-row-id="<?php echo $row_id ?>" <?php echo $common_data; ?>/>
                                            		<a href="<?php echo $purchase_url; ?>" target="_blank" class="bsf-purchase-link" data-row-id="<?php echo $row_id ?>" />Buy License</a> <span class="spinner bsf-spinner"></span>
                                               	<?php else : ?>
                                                	<input type="button" class="button bsf-submit-button-deregister" value="De-register" data-row-id="<?php echo $row_id ?>" <?php echo $common_data; ?>/> <span class="spinner bsf-spinner"></span>
                                                <?php endif; ?>
                                         	</td>
										</tr>
									<?php
									$count++;
								endforeach;
							endif;

							if(!empty($bsf_themes)) :

								foreach($bsf_themes as $theme => $theme_data) :

									//echo '<pre>';
									//print_r($theme_data);
									//echo '</pre>';
									$readonly = '';

									if(isset($theme_data['product_info']))
										$info = $theme_data['product_info'];
									else
										continue;
									$status = (isset($info['status'])) ? $info['status'] : '';

									$bsf_username = (isset($info['bsf_username'])) ? $info['bsf_username'] : $bsf_user_name;
									$bsf_useremail = (isset($info['bsf_useremail'])) ? $info['bsf_useremail'] : $bsf_user_email;
									$purchase_key = (isset($info['purchase_key'])) ? $info['purchase_key'] : '';
									$type = (isset($info['type'])) ? $info['type'] : 'theme';
									$template = (isset($info['template'])) ? $info['template'] : $plugin;
									$id = (isset($info['id'])) ? $info['id'] : '';
									$purchase_url = (isset($info['purchase_url'])) ? $info['purchase_url'] : 'javascript:void(0)';

									if($request_product_id!='')
										$init_single_product_show = true;
									else
										$init_single_product_show = false;

									if($init_single_product_show && $request_product_id !== $id)
										continue;

									$constant = 'BSF_REMOVE_'.$id.'_FROM_REGISTRATION';
									if(defined($constant) && ($constant == 'true' || $constant == true))
										continue;

									$version = bsf_get_current_version($template, $type);
									$name = bsf_get_current_name($template, $type);

									$step = (isset($theme_data['step']) && $theme_data['step'] != '') ? $theme_data['step'] : 'step-product-registration';

									$common_data = ' data-product-id="'.$id.'" ';
									$common_data .= ' data-bsf_username="'.$bsf_username.'" ';
									$common_data .= ' data-bsf_useremail="'.$bsf_useremail.'" ';
									$common_data .= ' data-product-type="'.$type.'" ';
									$common_data .= ' data-template="'.$template.'" ';
									$common_data .= ' data-version="'.$version.'" ';
									$common_data .= ' data-step="'.$step.'" ';
									$common_data .= ' data-product-name="'.$name.'" ';

									$mod = ($count%2);
									$alternate = ($mod) ? 'alternate' : '';
									$row_id = 'bsf-row-'.$count;

									if($status === 'registered')
									{
										$readonly = ' readonly="readonly" ';
										$common_data .= ' data-action="bsf_deregister_product" ';
										$registered_licence++;
									}
									else
									{
										$common_data .= ' data-action="bsf_register_product" ';
									}

									if($type === 'theme')
										$is_product_theme = true;
									?>
										<tr id="<?php echo $row_id ?>" class="<?php echo $alternate.' '.$status ?>">
											<td><?php echo $name ?></td>
											<td><?php echo $version ?></td>
                                            <td><input type="text" class="bsf-form-input" name="purchase_key" data-required="true" value="<?php echo $purchase_key ?>" <?php echo $readonly ?>/></td>
                                            <td>
                                            	<?php if($status !== 'registered') : ?>
                                            		<input type="button" class="button button-primary bsf-submit-button" value="Register" data-row-id="<?php echo $row_id ?>" <?php echo $common_data; ?>/>
                                            		<a href="<?php echo $purchase_url; ?>" target="_blank" class="bsf-purchase-link" data-row-id="<?php echo $row_id ?>" />Buy License</a> <span class="spinner bsf-spinner"></span>
                                               	<?php else : ?>
                                                	<input type="button" class="button bsf-submit-button-deregister" value="De-register" data-row-id="<?php echo $row_id ?>" <?php echo $common_data; ?>/> <span class="spinner bsf-spinner"></span>
                                                <?php endif; ?>
                                         	</td>
										</tr>
									<?php
									$count++;
								endforeach;
							endif;
						?>
                    </tbody>
                </table>
	                <div class="bsf-listing-cta">
	                	<a href="https://support.brainstormforce.com/license-registration-faqs/" target="_blank">Questions? Having Issues?</a>
	                </div>
                </div>

            </div><!-- bsf-licence-tab -->
            <div id="bsf-help" class="bsf-tab">
            	<div class="inner">
                	<div class="bsf-row">
                    	<div class="bsf-column">
                        	<div class="bsf-column-inner">
                                <h2>Developer Access</h2>
                                <span class="bsf-span"><?php echo __('Enable Developer access','bsf') ?>,<br/><?php echo __('Read more about developer access ','bsf'); ?><a href="<?php echo $bsf_support_url.'license-registration-faqs/#developer-access' ?>" target="_blank"><?php echo __('here','bsf') ?></a></span>
                                <form action="" class="bsf-cp-dev-access" method="post">
                                    <?php
                                        $title = '';
                                        if($registered_licence > 0)
                                            $disabled = '';
                                        else {
                                            $disabled = 'disabled="disabled"';
                                            $title = __('Activate your license to enable!','bsf');
											update_option('developer_access', false);
                                        }

                                        $developer_access = get_option('developer_access');

                                        if($developer_access)
                                        {
                                            $button_text = 'Revoke developer access';
                                            $action = 'revoke';
                                        }
                                        else
                                        {
                                            $button_text = 'Allow developer access';
                                            $action = 'grant';
                                        }
                                    ?>
                                    <input type="hidden" name="bsf-developer-access-action" value="<?php echo $action ?>"/>
                                    <input type="submit" class="button-primary bsf-access-<?php echo $action ?>-button" name="bsf-developer-access" value="<?php echo $button_text ?>" title="<?php echo $title ?>" <?php echo $disabled ?>/>
                                </form>
                            </div>
                        </div>
                        <div class="bsf-column">
                        	<div class="bsf-column-inner">
                                <h2>Force Check Updates</h2>
                                <span class="bsf-span"><?php echo __('Check if there are updates available of plugins by Brainstorm Force.','bsf'); ?></span>
                                <?php
                                	if(is_multisite())
										$reset_url = network_admin_url('index.php?page=bsf-registration&force-check-update');
									else {
										if(defined('BSF_REG_MENU_TO_SETTINGS') && (BSF_REG_MENU_TO_SETTINGS == true || BSF_REG_MENU_TO_SETTINGS == 'true')) {
											$reset_url = admin_url('options-general.php?page=bsf-registration&force-check-update');
										}
										else {
											$reset_url = admin_url('index.php?page=bsf-registration&force-check-update');
										}
									}
                                ?>
                                <a class="button-primary bsf-cp-update-btn" href="<?php echo $reset_url ?>"><?php echo __('Check Updates Now','bsf') ?></a>
                            </div>
                        </div>
                        <div class="bsf-column">
                        	<div class="bsf-column-inner">
                                <h2>Request Support</h2>
                                <?php global $bsf_support_url; ?>
                                <span class="bsf-span"><?php echo __('Having any trouble using our products? Head to our support center to get your issues resolved.','bsf'); ?></span>
                                <a class="button-primary bsf-cp-support-btn" href="<?php echo $bsf_support_url.'request-support/' ?>" target="_blank"><?php echo __('Request Support','bsf') ?></a>
                            </div>
                        </div>
                    </div>
                </div>
            </div><!-- bsf-help-tab -->
            <!--<div id="bsf-advanced" class="bsf-tab">
            	<div class="inner">
                	<?php //$bsf_settings = get_option('bsf_settings'); ?>
                	<form action="" method="post" class="bsf-settings-form">
                    	<div class="bsf-pr-form-row bsf-rem-top-margin">
                        	<label>Custom CSS</label>
                            <textarea name="bsf_settings[custom_css]" rows="8" placeholder="html { margin:0 }"><?php //echo (isset($bsf_settings['custom_css'])) ? stripslashes($bsf_settings['custom_css']) : '' ?></textarea>
                        </div>
                        <div class="bsf-pr-form-row">
                        	<label>Custom JS</label>
                            <textarea name="bsf_settings[custom_js]" rows="8" placeholder="alert('Howdy!');"><?php //echo (isset($bsf_settings['custom_js'])) ? stripslashes($bsf_settings['custom_js']) : '' ?></textarea>
                        </div>
                        <div class="bsf-pr-form-row">
                        	<input type="submit" class="button-primary" name="bsf-advanced-form-btn" value="<?php //echo __('Save Changes','bsf'); ?>"/>
                        </div>
                    </form>
                </div>
         	</div><!-- bsf-advanced-tab -->
            <?php if($author) : ?>
			<div id="bsf-author" class="bsf-tab <?php echo ($tab == 'author') ? 'bsf-tab-active' : '' ?>">
            	<div class="inner">
                	<div class="bsf-cp-res-user">
                    	<?php
                    		if(is_multisite())
								$reset_url = network_admin_url('index.php?page=bsf-registration&reset-bsf-users');
							else {
								if(defined('BSF_REG_MENU_TO_SETTINGS') && (BSF_REG_MENU_TO_SETTINGS == true || BSF_REG_MENU_TO_SETTINGS == 'true')) {
									$reset_url = admin_url('options-general.php?page=bsf-registration&reset-bsf-users');
								}
								else {
									$reset_url = admin_url('index.php?page=bsf-registration&reset-bsf-users');
								}
							}
						?>
						<a class="button-primary" href="<?php echo $reset_url ?>"><?php echo __('Reset Site','bsf') ?></a>
                    </div>
                	<div class="bsf-cp-rem-bundle">
	                	<?php
	                		if(is_multisite())
								$url = network_admin_url('index.php?page=bsf-registration&remove-bundled-products');
							else {
								if(defined('BSF_REG_MENU_TO_SETTINGS') && (BSF_REG_MENU_TO_SETTINGS == true || BSF_REG_MENU_TO_SETTINGS == 'true')) {
									$url = admin_url('options-general.php?page=bsf-registration&remove-bundled-products');
								}
								else {
									$url = admin_url('index.php?page=bsf-registration&remove-bundled-products');
								}
							}
						?>
						<a class="button-primary" href="<?php echo $url ?>"><?php echo __('Check Bundled Products','bsf') ?></a>
                    </div>
                </div>
            </div><!-- bsf-author-tab -->
            <?php endif; ?>
            <div id="bsf-system" class="bsf-tab">
            	<div class="inner">
                	<table class="wp-list-table widefat fixed bsf-sys-info">
                    	<tbody>
                        	<tr class="alternate">
                            	<th colspan="2"><?php echo __('WordPress Environment','bsf'); ?></th>
                            </tr>
                            <tr>
                            	<td>Home URL</td><td><?php echo site_url(); ?></td>
                            </tr>
                            <tr>
                            	<td>Site URL</td><td><?php echo site_url(); ?></td>
                            </tr>
                            <tr>
                            	<?php global $wp_version ?>
                            	<td>WP Version</td><td><?php echo $wp_version; ?></td>
                            </tr>
                            <tr>
                            	<td>Multisite</td><td><?php echo (is_multisite()) ? 'Yes' : 'No'; ?></td>
                            </tr>
                            <?php
								$limit = (int) ini_get('memory_limit');
								$usage = function_exists('memory_get_usage') ? round(memory_get_usage() / 1024 / 1024, 2) : 0;
							?>
                            <tr >
                            	<td>Memory Usage</td>
                                <td>
									<?php echo $usage ?>
                                   	MB of
                                    <?php echo $limit ?>
                                   	MB
                                </td>
                            </tr>
                            <tr>
                            	<td>WP Memory Limit</td>
                                <td>
									<?php echo WP_MEMORY_LIMIT ?>
                                </td>
                            </tr>
                            <tr>
                            	<td>WP Debug</td><td><?php echo (WP_DEBUG) ? 'Enabled' : 'Disabled'; ?></td>
                            </tr>
                            <tr>
                            	<td>WP Lang</td><td><?php echo $currentlang = get_bloginfo('language'); ?></td>
                            </tr>
                            <tr>
                            	<td>WP Uploads Directory</td>
                                <td>
									<?php
										$wp_up = wp_upload_dir();
										echo (is_writable($wp_up['basedir'])) ? 'Writable' : 'Readable';
									?>
                                </td>
                            </tr>
                            <tr>
                            	<td>BSF Updater Path</td>
                            	<td>
                            		<?php global $bsf_core_version; ?>
                            		<?php echo '(v'.$bsf_core_version.') '.BSF_UPDATER_PATH; ?>
                            	</td>
                            </tr>
                            <?php if(defined('WPB_VC_VERSION')) : ?>
                            <tr>
                            	<td>vc_shortcode_output Filter</td>
								<td>
                                	<?php echo (has_filter('vc_shortcode_output')) ? 'Available' : 'Not Available'; ?>
                                </td>
                            </tr>
							<?php endif; ?>
							<?php
								$mix = array_merge($bsf_product_plugins, $bsf_product_themes);
								$temp_constant = '';
								if(!empty($mix)) :
									foreach($mix as $key => $product) :
										$constant = strtoupper(str_replace('-', '_', $product['id']));
										$constant = 'BSF_'.$constant.'_CHECK_UPDATES';
										if(defined($constant) && (constant($constant) === 'false' || constant($constant) === false)) {
											$temp_constant .= $constant.'<br/>';
											continue;
										}
									endforeach;
								endif;
								if(defined('BSF_CHECK_PRODUCT_UPDATES') && BSF_CHECK_PRODUCT_UPDATES == false) {
									$temp_constant .= 'BSF_CHECK_PRODUCT_UPDATES';
								}
								if($temp_constant != '') {
									if(!defined('BSF_RESTRICTED_UPDATES')) {
										define('BSF_RESTRICTED_UPDATES', $temp_constant);
									}
								}
							?>
							<?php if(defined('BSF_RESTRICTED_UPDATES')) : ?>
                            <tr>
                            	<td>Restrited Updates Filter</td>
								<td>
                                	<?php echo BSF_RESTRICTED_UPDATES; ?>
                                </td>
                            </tr>
							<?php endif; ?>
						</tbody>
					</table>
					<table class="wp-list-table widefat fixed bsf-sys-info">
                    	<tbody>
                            <tr class="alternate">
                            	<th colspan="2"><?php echo __('Server Environment','bsf'); ?></th>
                            </tr>
                            <tr>
                            	<td>Server Info</td><td><?php echo $_SERVER['SERVER_SOFTWARE'] ?></td>
                            </tr>
                            <tr>
                            	<td>PHP Version</td><td><?php echo (function_exists('phpversion')) ? phpversion() : 'Not sure'; ?></td>
                            </tr>
                            <tr>
                            	<td>MYSQL Version</td><td><?php echo (function_exists('mysql_get_server_info')) ? @mysql_get_server_info() : 'Not sure'; ?></td>
                            </tr>
                            <tr>
                            	<td>PHP Post Max Size</td><td><?php echo ini_get('post_max_size'); ?></td>
                            </tr>
                            <tr>
                            	<td>PHP Max Execution Time</td><td><?php echo ini_get('max_execution_time'); ?> Seconds</td>
                            </tr>
                            <tr>
                            	<td>PHP Max Input Vars</td><td><?php echo ini_get('max_input_vars'); ?></td>
                            </tr>
                       		<tr>
                            	<td>Max Upload Size</td><td><?php echo ini_get("upload_max_filesize"); ?></td>
                            </tr>
                            <tr>
                            	<td>Default Time Zone</td>
                                <td>
									<?php
										if (date_default_timezone_get()) {
											echo date_default_timezone_get();
										}
										if(ini_get('date.timezone')) {
											echo ' '.ini_get('date.timezone');
										}
									?>
                             	</td>
                            </tr>
                            <tr class="<?php echo (!function_exists('curl_version')) ? 'bsf-alert' : ''; ?>">
                            	<td>cURL</td>
                                <td>
									<?php
										if(function_exists('curl_version')) {
											$curl_info = curl_version();
											echo $curl_info['version'];
										}
										else {
											echo 'Not Enabled';
										}
									?>
                              	</td>
                            </tr>
                            <tr class="<?php echo (!function_exists('curl_version')) ? 'bsf-alert' : ''; ?>">
                            	<td>SimpleXML</td>
                                <td>
									<?php
										if (extension_loaded('simplexml')) {
										    echo "All good, extension is installed";
										} else {
											echo "Oops! extension not installed, Icon Manager will not work";
										}
									?>
                              	</td>
                            </tr>
                        </tbody>
                    </table>
                    <table class="wp-list-table widefat fixed bsf-sys-info">
                    	<tbody>
                            <tr class="alternate">
                            	<th colspan="2"><?php echo __('Theme Information','bsf'); ?></th>
                            </tr>
                            <?php $theme_data = wp_get_theme(); ?>
                            <tr>
								<td>Name</td>
								<td><?php echo $theme_data->Name ?></td>
							</tr>
							<tr>
								<td>Version</td>
								<td><?php echo $theme_data->Version ?></td>
							</tr>
							<tr>
								<td>Author</td>
								<td><a href="<?php echo $theme_data->ThemeURI ?>"><?php echo $theme_data->Author ?></a></td>
							</tr>
						</tbody>
					</table>
					<table class="wp-list-table widefat fixed bsf-sys-info bsf-table-active-plugin">
                    	<tbody>
                            <tr class="alternate">
                            	<th colspan="4"><?php echo __('Installed Plugins','bsf'); ?></th>
                            </tr>
                        	<?php
								$plugins = get_plugins();
								asort($plugins);
								foreach($plugins as $plugin_file => $plugin_data) {
									?>
                                    <tr>
                                    	<td><?php echo str_pad($plugin_data['Title'], 30); ?></td>
                                        <td>
                                        	<?php
												if(is_plugin_active($plugin_file)) {
													echo str_pad('Active', 10);
												} else {
													echo str_pad('Inactive', 10);
												}
											?>
                                        </td>
                                        <td><?php echo str_pad($plugin_data['Version'], 10) ?></td>
                                        <td><?php echo $plugin_data['Author'] ?></td>
                                    </tr>
                                    <?php
								}
                       		?>
                        </tbody>
                    </table>
                </div>
         	</div><!-- bsf-system-tab -->
    </div>
</div>
<script type="text/javascript">
(function($){
	"use strict";
	$(document).ready(function(){
		$('body').on('click','.bsf-submit-button', function(){
			var row_id = $(this).attr('data-row-id');
			var $row = $('#'+row_id);

			var errors = 0;

			$row.find('.bsf-spinner').toggleClass('bsf-spinner-show');

			var purchase_key = $row.find('input[name="purchase_key"]').val();

			var product_id = $(this).attr('data-product-id');
			var username = $(this).attr('data-bsf_username');
			var useremail = $(this).attr('data-bsf_useremail');
			var product_type = $(this).attr('data-product-type');
			var template = $(this).attr('data-template');
			var version = $(this).attr('data-version');
			var step = $(this).attr('data-step');
			var product_name = $(this).attr('data-product-name');

			var action = $(this).attr('data-action');

			var admin_url = '<?php echo (is_multisite()) ? rtrim(network_admin_url(),'/') : rtrim(admin_url(),'/'); ?>';

			$row.find('.bsf-form-input').each(function(i,input){
				var type = $(input).attr('type');
				var required = $(input).attr('data-required');
				if(required === 'true' || required === true)
				{
					if(type === 'text')
					{
						$(input).removeClass('bsf-pr-input-required');
						if($(input).val() === '')
						{
							$(input).addClass('bsf-pr-input-required');
							errors++;
						}
					}
				}
			});
			if(errors > 0)
			{
				$row.find('.bsf-spinner').toggleClass('bsf-spinner-show');
				return false;
			}

			var data = {
				action: action,
				bsf_username: username,
				bsf_useremail: useremail,
				purchase_key: purchase_key,
				type: product_type,
				id: product_id,
				product: template,
				version: version,
				step: step,
				product_name: product_name
			};

			$.post(ajaxurl, data, function(response) {
				console.log(response);
				//return false;
				var result = $.parseJSON(response);
				console.log(result);

				if(typeof result === 'undefined' || result === null)
					return false;

				//result.proceed = true;

				if(result.proceed === 'false' || result.proceed === false)
				{
					var html = '';
					if(typeof result.response.title !== 'undefined')
						html += '<h2><span class="dashicons dashicons-info" style="transform: scale(-1);-web-kit-transform: scale(-1);margin-right: 10px;color: rgb(244, 0, 0);  font-size: 25px;"></span>'+result.response.title+'</h2>';
					if(typeof result.response.message_html !== 'undefined')
						html += '<div class="bsf-popup-message-inner-html">'+result.response.message_html+'</div>';
					$('.bsf-popup-message-inner').html(html);
					$('.bsf-popup, .bsf-popup-message').fadeIn(300);
				}
				else if(result.proceed === 'true' || result.proceed === true)
				{
					var html = '';
					if(typeof result.response.title !== 'undefined')
						html += '<h2><span class="dashicons dashicons-yes" style="margin-right: 10px;color: rgb(0, 213, 0);  font-size: 25px;"></span>'+result.response.title+'</h2>';
					if(typeof result.response.message_html !== 'undefined')
						html += '<div class="bsf-popup-message-inner-html">'+result.response.message_html+'</div>';
					$('.bsf-popup-message-inner').html(html);
					$('.bsf-popup, .bsf-popup-message').fadeIn(300);
					if(typeof result.after_registration_action !== 'undefined' && result.after_registration_action !== '')
						if ( result.after_registration_action == 'admin.php?page=bsf-extensions' ) {
							window.location.href = admin_url+'/'+result.after_registration_action+'?product_id=10395942';
						} else {
							window.location.href = admin_url+'/'+result.after_registration_action;
						}
					else
						location.reload();
				}
				$row.find('.bsf-spinner').toggleClass('bsf-spinner-show');
			});
		}); //end of submit button

		$('body').on('click','.bsf-submit-button-deregister',function(){
			var row_id = $(this).attr('data-row-id');
			var $row = $('#'+row_id);

			var errors = 0;

			$row.find('.bsf-spinner').toggleClass('bsf-spinner-show');

			var purchase_key = $row.find('input[name="purchase_key"]').val();
			var bsf_username = $(this).attr('data-bsf_username');
			var bsf_useremail = $(this).attr('data-bsf_useremail');
			var product_id = $(this).attr('data-product-id');
			var product_type = $(this).attr('data-product-type');
			var template = $(this).attr('data-template');
			var version = $(this).attr('data-version');
			var name = $(this).attr('data-product-name');

			var action = $(this).attr('data-action');

			var data = {
				action: action,
				purchase_key: purchase_key,
				bsf_username: bsf_username,
				bsf_useremail: bsf_useremail,
				type: product_type,
				id: product_id,
				product: template,
				version: version,
				product_name: name
			};

			console.log(data);

			$.post(ajaxurl, data, function(response) {
				//console.log($.parseJSON(response));
				//return false;
				console.log(response);
				//return false;
				var result = $.parseJSON(response);
				var html = '';
				if(typeof result.response.title !== 'undefined')
					html += '<h2><span class="dashicons dashicons-yes" style="margin-right: 10px;color: rgb(0, 213, 0);  font-size: 25px;"></span>'+result.response.title+'</h2>';
				if(typeof result.response.message_html !== 'undefined')
					html += '<div class="bsf-popup-message-inner-html">'+result.response.message_html+'</div>';
				$('.bsf-popup-message-inner').html(html);
				$('.bsf-popup, .bsf-popup-message').fadeIn(300);
				if(result.proceed === 'true' || result.proceed === true)
				{
					//setTimeout(function(){
						location.reload();
					//},2000);
				}
			});

		}); // end of de-registering licence

		$('body').on('click','.nav-tab',function(event){
			//event.preventDefault();
			$('.nav-tab').removeClass('nav-tab-active');
			$(this).addClass('nav-tab-active');
			var tab = $(this).attr('href');
			$('.bsf-tab').fadeOut(200);
			setTimeout(function(){
				$(tab).fadeIn(200);
			},200);
		}); // end of tabs functionality
	});
})(jQuery);
</script>updater.php000066600000061176151264132510006740 0ustar00<?php
// Alternative function for wp_remote_get
if(!function_exists('bsf_get_remote_version')) {
	function bsf_get_remote_version($products, $check_license){
		global $ultimate_referer;
		global $bsf_product_validate_url;

		$path = $bsf_product_validate_url.'?referer='.$ultimate_referer;

		$data = array(
				'action' => 'bsf_get_product_versions',
				'ids' => $products,
				'linceses_check' => $check_license
			);
		$request = @wp_remote_post(
			$path, array(
				'body' => $data,
				'timeout' => '60',
				'sslverify' => false
			)
		);

		if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200)
		{
			$result = json_decode($request['body']);

			bsf_update_license_checked($result->updated_licenses);

			if(!$result->error)
				return $result->updated_versions;
			else
				return $result->error;
		}
	}
}
if(!function_exists('bsf_update_license_checked')) {
	function bsf_update_license_checked($updated_licenses) {
		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();
		if(empty($brainstrom_products))
			return false;
		if(empty($updated_licenses))
			return false;

		$is_updated = false;

		foreach($updated_licenses as $license) :
			$product_id = $license->product_id;
			$type = $license->type.'s';
			$new_status = $license->status;
			$purchase_key = $license->purchase_code;
			if(isset($brainstrom_products[$type]) && !empty($brainstrom_products[$type])) {
				if(isset($brainstrom_products[$type][$product_id])) {
					$old_status = $brainstrom_products[$type][$product_id]['status'];
					if($old_status !== $new_status) {
						$brainstrom_products[$type][$product_id]['status'] = $new_status;
						$is_updated = true;
					}
				}
			}
		endforeach;

		if($is_updated)
			update_option('brainstrom_products', $brainstrom_products);
	}
}
if(!function_exists('bsf_check_product_update')) {
	function bsf_check_product_update(){
		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();
		$bsf_users = (get_option('brainstrom_users')) ? get_option('brainstrom_users') : array();

		$mix = $bsf_product_plugins = $bsf_product_themes = $registered = $check_license = array();

		if(!empty($bsf_users)) {
			$bsf_user_email = $bsf_users[0]['email'];
			$bsf_user_name = $bsf_users[0]['name'];
		}

		if(!empty($brainstrom_products)) :
			$bsf_product_plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
		endif;

		$mix = array_merge($bsf_product_plugins, $bsf_product_themes);

		$is_update = false;
		$temp = '';
		if(!empty($mix)) :
			foreach($mix as $key => $product) :
				if(!isset($product['id']))
					continue;
				$constant = strtoupper(str_replace('-', '_', $product['id']));
				$constant = 'BSF_'.$constant.'_CHECK_UPDATES';
				if(defined($constant) && (constant($constant) === 'false' || constant($constant) === false)) {
					continue;
				}
				array_push($registered, $product['id']);
				//check license array build
				$temp = array();
				$temp['site_url'] = site_url();
				if(!isset($product['purchase_key']))
					continue;
				$is_wp = (isset($product['in_house']) && $product['in_house'] === 'wp') ? true : false;
				if($is_wp)
					continue;
				$temp['purchase_code'] = $product['purchase_key'];
				$temp['user_email'] = $bsf_user_email;
				$temp['user_name'] = $bsf_user_name;
				$temp['product_id'] = $product['id'];
				$temp['type'] = $product['type'];
				array_push($check_license, $temp);

			endforeach;
		endif;
		if(!empty($registered))
		{
			$remote_versions = bsf_get_remote_version($registered, $check_license);

			$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();
			$brainstrom_bundled_products = (get_option('brainstrom_bundled_products')) ? get_option('brainstrom_bundled_products') : array();

			if($remote_versions !== false)
			{
				if(!empty($remote_versions))
				{
					$is_bundled_update = false;
					foreach($remote_versions as $rkey => $remote_data)
					{
						$rid = (string)$remote_data->id;
						$remote_version = (isset($remote_data->remote_version)) ? $remote_data->remote_version : '';
						$in_house = (isset($remote_data->in_house)) ? $remote_data->in_house : '';
						$on_market = (isset($remote_data->on_market)) ? $remote_data->on_market : '';
						$is_product_free = (isset($remote_data->is_product_free)) ? $remote_data->is_product_free : '';
						$short_name = (isset($remote_data->short_name)) ? $remote_data->short_name : '';
						$changelog_url = (isset($remote_data->changelog_url)) ? $remote_data->changelog_url : '';
						$purchase_url = (isset($remote_data->purchase_url)) ? $remote_data->purchase_url : '';
						if(!empty($bsf_product_plugins))
						{
							foreach($bsf_product_plugins as $key => $plugin)
							{
								if(!isset($plugin['id']))
									continue;
								$pid = (string)$plugin['id'];
								if($pid === $rid)
								{
									$brainstrom_products['plugins'][$key]['remote'] = $remote_version;
									$brainstrom_products['plugins'][$key]['in_house'] = $in_house;
									$brainstrom_products['plugins'][$key]['on_market'] = $on_market;
									$brainstrom_products['plugins'][$key]['is_product_free'] = $is_product_free;
									$brainstrom_products['plugins'][$key]['short_name'] = $short_name;
									$brainstrom_products['plugins'][$key]['changelog_url'] = $changelog_url;
									$brainstrom_products['plugins'][$key]['purchase_url'] = $purchase_url;
									$is_update = true;
								}
							}
						}
						if(!empty($bsf_product_themes))
						{
							foreach($bsf_product_themes as $key => $theme)
							{
								if(!isset($theme['id']))
									continue;
								$pid = $theme['id'];
								if($pid === $rid)
								{
									$brainstrom_products['themes'][$key]['remote'] = $remote_version;
									$brainstrom_products['themes'][$key]['in_house'] = $in_house;
									$brainstrom_products['themes'][$key]['on_market'] = $on_market;
									$brainstrom_products['themes'][$key]['is_product_free'] = $is_product_free;
									$brainstrom_products['themes'][$key]['short_name'] = $short_name;
									$brainstrom_products['themes'][$key]['changelog_url'] = $changelog_url;
									$brainstrom_products['themes'][$key]['purchase_url'] = $purchase_url;
									$is_update = true;
								}
							}
						}

						if(isset($remote_data->bundled_products) && !empty($remote_data->bundled_products)) {
							if(!empty($brainstrom_bundled_products)) {
								foreach($brainstrom_bundled_products as $bkeys => $bps) {
									foreach ($bps as $bkey => $bp) {
										if(!isset($bp->id))
											continue;
										foreach($remote_data->bundled_products as $rbp) {
											if(!isset($rbp->id))
												continue;
											if( $rbp->id === $bp->id ) {
												$bprd = $brainstrom_bundled_products[$bkeys];
												$brainstrom_bundled_products[$bkeys][$bkey]->remote = $rbp->remote_version;
												$brainstrom_bundled_products[$bkeys][$bkey]->parent = $rbp->parent;
												$brainstrom_bundled_products[$bkeys][$bkey]->short_name = $rbp->short_name;
												$brainstrom_bundled_products[$bkeys][$bkey]->changelog_url = $rbp->changelog_url;
												/*$bprd[$bkey]->remote = $rbp->remote_version;
												$bprd[$bkey]->parent = $rbp->parent;
												$bprd[$bkey]->short_name = $rbp->short_name;
												$bprd[$bkey]->changelog_url = $rbp->changelog_url;*/

												//$brainstrom_bundled_products->$bkeys = $bprd;
												$is_bundled_update = true;
											}
										}
									}

								}
							}
						}
					}

					if($is_bundled_update){
						//echo 'CHECK UPDATE FUNCTION'; die();
						/*echo '<pre>';
						print_r($brainstrom_bundled_products);
						echo '</pre>'; die();*/
						update_option('brainstrom_bundled_products', $brainstrom_bundled_products);
					}
				}
			}
		}

		if($is_update)
			update_option('brainstrom_products', $brainstrom_products);

		//new Ultimate_Auto_Update(ULTIMATE_VERSION, 'http://ec2-54-183-173-184.us-west-1.compute.amazonaws.com/updates/?'.time(), 'Ultimate_VC_Addons/Ultimate_VC_Addons.php');
	}
}
if(!defined('BSF_CHECK_PRODUCT_UPDATES'))
	$BSF_CHECK_PRODUCT_UPDATES = true;
else
	$BSF_CHECK_PRODUCT_UPDATES = BSF_CHECK_PRODUCT_UPDATES;

if((false === get_transient( 'bsf_check_product_updates') && ($BSF_CHECK_PRODUCT_UPDATES === true || $BSF_CHECK_PRODUCT_UPDATES === 'true') )) {
	$proceed = true;

	$bsf_local_transient = get_option('bsf_local_transient');
	if($bsf_local_transient != false) {
		$datetime1 = new DateTime();
		$date_string = gmdate("Y-m-d\TH:i:s\Z", $bsf_local_transient);
		$datetime2 = new DateTime($date_string);

		$interval = $datetime1->diff($datetime2);
		$elapsed = $interval->format('%h');
		$elapsed = $elapsed + ($interval->days*24);
		if($elapsed <= 48 || $elapsed <= '48') {
			$proceed = false;
		}
	}

	if($proceed) {
		global $ultimate_referer;
		$ultimate_referer = 'on-transient-delete';
		bsf_check_product_update();
		update_option('bsf_local_transient', current_time( 'timestamp' ));
		set_transient( 'bsf_check_product_updates', true, 2*24*60*60 );
	}
}

if(!function_exists('get_bsf_product_upgrade_link')) {
	function get_bsf_product_upgrade_link($product) {
		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();

		$mix = $bsf_product_plugins = $bsf_product_themes = $registered = array();
		$licence_require_update = '';

		if(!empty($brainstrom_products)) :
			$bsf_product_plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
		endif;

		$mix = array_merge($bsf_product_plugins, $bsf_product_themes);
		$status = (isset($product['status'])) ? $product['status'] : '';
		$name = (isset($product['bundled']) && ($product['bundled'])) ? $product['name'] : $product['product_name'];
		$free = (isset($product['is_product_free']) && ($product['is_product_free'] == true || $product['is_product_free'] == 'true')) ? $product['is_product_free'] : 'false';

		$id = $product['id'];

		$original_id = $id;

		$not_registered_msg = 'Activate your licence for one click update.';
		if($product['bundled'])
		{
			$product_name = '';
			$parent = $product['parent'];
			foreach($mix as $key => $bsf_p) {
				if($bsf_p['id'] == $parent) {
					$status = (isset($bsf_p['status'])) ? $bsf_p['status'] : '';
					$product_name = (isset($bsf_p['product_name'])) ? $bsf_p['product_name'] : '';
					$id = $parent;
					break;
				}
			}
			$not_registered_msg = 'This is bundled with '.$product_name.', Activate '.$product_name.'\'s licence for one click update.';
		}

		if ( array_key_exists( 'licence_require_update', $product ) ) {
			$licence_require_update = $product['licence_require_update'];
		}
		//echo '[[['.$licence_require_update.']]]';

		if($status === 'registered' || ($free === true || $free === 'true') || $licence_require_update == 'false' )
		{
			if(defined('BSF_REG_MENU_TO_SETTINGS') && (BSF_REG_MENU_TO_SETTINGS == true || BSF_REG_MENU_TO_SETTINGS == 'true')) {
				$request = 'options-general.php?page=bsf-registration&action=upgrade&id='.$original_id;
			}
			else {
				$request = 'index.php?page=bsf-registration&action=upgrade&id='.$original_id;
			}
			if($product['bundled'])
				$request .= '&bundled='.$id;
			if(is_multisite()) {
				$link = '<a href="'.network_admin_url($request).'" data-pid="'.$original_id.'" data-bundled="'.$product['bundled'].'" data-bid="'.$id.'" class="bsf-update-product-button">'.__('Update '.$name.'.', 'bsf').'</a><span class="spinner bsf-update-spinner"></span>';
			}
			else {
				$link = '<a href="'.admin_url($request).'" data-pid="'.$original_id.'" data-bundled="'.$product['bundled'].'" data-bid="'.$id.'" class="bsf-update-product-button">'.__('Update '.$name.'.', 'bsf').'</a><span class="spinner bsf-update-spinner"></span>';
			}
		}
		else
		{
			if(is_multisite())
				$link = '<a href="'.network_admin_url('index.php?page=bsf-registration&id='.$id).'">'.__($not_registered_msg, 'bsf').'</a>';
			else {
				if(defined('BSF_REG_MENU_TO_SETTINGS') && (BSF_REG_MENU_TO_SETTINGS == true || BSF_REG_MENU_TO_SETTINGS == 'true')) {
					$link = '<a href="'.admin_url('options-general.php?page=bsf-registration&id='.$id).'">'.__($not_registered_msg, 'bsf').'</a>';
				}
				else {
					$link = '<a href="'.admin_url('index.php?page=bsf-registration&id='.$id).'">'.__($not_registered_msg, 'bsf').'</a>';
				}
			}
		}

		return $link;
	}
}
add_action( 'core_upgrade_preamble', 'list_bsf_products_updates', 999 );
if(!function_exists('list_bsf_products_updates')) {
	function list_bsf_products_updates() {
		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();
		$brainstrom_bundled_products = (get_option('brainstrom_bundled_products')) ? get_option('brainstrom_bundled_products') : array();

		$mix_products = $update_ready = $bsf_product_plugins = $bsf_product_themes = $temp_bundled = array();

		if(!empty($brainstrom_products)) :
			$bsf_product_plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
		endif;

		$mix_products = array_merge($bsf_product_plugins, $bsf_product_themes);

		foreach($mix_products as $product) {
			$is_bundled = false;
			if(!isset($product['id']))
				continue;
			$id = $product['id'];
			$bundled_key = array();
			$bundled_wrapper = array();
			if(!empty($brainstrom_bundled_products)) {
				foreach($brainstrom_bundled_products as $bkeys => $bps) {
					if(strlen($bkeys) > 1) {
						foreach ($bps as $bkey => $bp) {
							/*echo '<pre>';
							print_r($bp);
							echo '</pre>['.$bp->id.' '.$id.']';*/
							if(!isset($bp->id) || $bp->id == '')
								continue;
							if($id === $bp->id) {
								$is_bundled = true;
								$bprd = $brainstrom_bundled_products[$bkeys];
								$version =  isset( $bprd[$bkey]->version ) ? $bprd[$bkey]->version : '';
								$remote = isset( $bprd[$bkey]->remote ) ? $bprd[$bkey]->remote : '';
								$template = isset( $bprd[$bkey]->init ) ? $bprd[$bkey]->init : '';
								$type = isset( $bprd[$bkey]->type ) ? $bprd[$bkey]->type : '';
								$bundled_key = $bkey;
								if( version_compare( $remote, $version, '>' ) ) {
									$temp = (array)$bprd[$bundled_key];
									$temp['bundled'] = true;
									array_push($temp_bundled, $temp['id']);
									array_push($update_ready, $temp);
								}

								break;
							}
						}
					}
					else {
						if(!isset($bps->id) || $bps->id == '')
							continue;
						if($id === $bps->id) {
							$is_bundled = true;
							$bundled_key = $bkeys;
							break;
						}
					}
				}
			}
			if($is_bundled)
			{
				//echo '['.$bundled_key.']';
				// $version = (isset($brainstrom_bundled_products[$bundled_key]->version)) ? $brainstrom_bundled_products[$bundled_key]->version : '';
				// $remote = (isset($brainstrom_bundled_products[$bundled_key]->remote)) ? $brainstrom_bundled_products[$bundled_key]->remote : '';
				// $template = (isset($brainstrom_bundled_products[$bundled_key]->init)) ? $brainstrom_bundled_products[$bundled_key]->init : '';
				// $type = (isset($brainstrom_bundled_products[$bundled_key]->type)) ? $brainstrom_bundled_products[$bundled_key]->type : 'plugin';
			}
			else
			{
				$version = (isset($product['version'])) ? $product['version'] : '';
				$remote = (isset($product['remote'])) ? $product['remote'] : '';
				$template = (isset($product['template'])) ? $product['template'] : '';
				$type = (isset($product['type'])) ? $product['type'] : '';
			}

			if($type === 'theme')
			{
				$product_abs_path = WP_CONTENT_DIR.'/themes/'.$template;
				if(!is_dir($product_abs_path))
					continue;
			}
			else
			{
				$product_abs_path = WP_PLUGIN_DIR.'/'.$template;
				if(!is_file($product_abs_path))
					continue;
			}

			if(version_compare($remote, $version, '>')):
				if($is_bundled)
				{
					// $temp = (array)$brainstrom_bundled_products[$bundled_key];
					// $temp['bundled'] = true;
					// array_push($temp_bundled, $temp['id']);
					// array_push($update_ready, $temp);
				}
				else
				{
					$product['bundled'] = false;
					array_push($update_ready, $product);
				}
			endif;
		}
		/*echo '<pre>';
		print_r($brainstrom_bundled_products);
		echo '</pre>';*/
		foreach($brainstrom_bundled_products as $bkeys => $bps) {
			if(strlen($bkeys) > 1) {
				foreach ($bps as $bkey => $bp) {
					if(!isset($bp->id) || $bp->id == '')
						continue;
					$plugin_abs_path = WP_PLUGIN_DIR.'/'.$bp->init;

					if(!is_file($plugin_abs_path))
						continue;
					if(!isset($bp->remote))
						continue;

					$temp = array();
					if(!in_array($bp->id, $temp_bundled)) {
						if(version_compare($bp->remote, $bp->version, '>')):
							$is_wp = (isset($bp->in_house) && $bp->in_house === 'wp') ? true : false;
						if($is_wp)
							break;
						$temp = (array)$bp;
						$temp['bundled'] = true;
						array_push($update_ready, $temp);
						endif;
					}
				}
			}
			else {
				if(!isset($bps->id) || $bps->id == '')
					continue;
				$plugin_abs_path = WP_PLUGIN_DIR.'/'.$bps->init;

				if(!is_file($plugin_abs_path))
					continue;
				if(!isset($bps->remote))
					continue;

				$temp = array();
				if(!in_array($bps->id, $temp_bundled)) {
					if(version_compare($bps->remote, $bps->version, '>')):
						$is_wp = (isset($bps->in_house) && $bps->in_house === 'wp') ? true : false;
						if($is_wp)
							break;
						$temp = (array)$bps;
						$temp['bundled'] = true;
						array_push($update_ready, $temp);
					endif;
				}
			}
		}

		$update_ready = bsf_array_unique( $update_ready );

		echo '<h3 id="brainstormforce-products">Brainstorm Force - ' . __( 'Products', 'bsf' ) . '</h3>';

		if(!empty($update_ready)) :
			echo '<p>'. __( 'The following plugins from Brainstorm Force have new versions available.', 'bsf' ).'</p>';
			?>
            <table class="widefat" cellspacing="0" id="update-plugins-table">
                <thead>
                <tr>
                    <th scope="col" class="manage-column"><label><?php _e( 'Name', 'bsf' ); ?></label></th>
                    <th scope="col" class="manage-column"><label><?php _e( 'Installed Version', 'bsf' ); ?></label></th>
                    <th scope="col" class="manage-column"><label><?php _e( 'Latest Version', 'bsf' ); ?></label></th>
                    <th scope="col" class="manage-column"><label><?php _e( 'Actions', 'bsf' ); ?></label></th>
                </tr>
                </thead>
                <tfoot>
                <tr>
                    <th scope="col" class="manage-column"><label><?php _e( 'Name', 'bsf' ); ?></label></th>
                    <th scope="col" class="manage-column"><label><?php _e( 'Installed Version', 'bsf' ); ?></label></th>
                    <th scope="col" class="manage-column"><label><?php _e( 'Latest Version', 'bsf' ); ?></label></th>
                    <th scope="col" class="manage-column"><label><?php _e( 'Actions', 'bsf' ); ?></label></th>
                </tr>
                </tfoot>
                <tbody class="plugins">
					<?php
                    foreach($update_ready as $key => $product) :
						$is_bundled = $product['bundled'];

						if($is_bundled)
						{
							if(!isset($product['init']))
								continue;
							if(trim($product['init']) === '' || $product['init'] === false)
								continue;
						}
						else
						{
							if(!isset($product['template']))
								continue;
							if(trim($product['template']) === '' || $product['template'] === false)
								continue;
						}
                    $upgradeLink = get_bsf_product_upgrade_link($product);
                    ?>

                        <tr class='active' id="bsf-row-<?php echo $key ?>">
                            <td class='plugin-title'><strong><?php echo ($product['bundled']) ? $product['name'] : $product['product_name'] ?></strong>
                            	<span><?php _e( 'You have version '.$product['version'].' installed. Update to '.$product['remote'], 'bsf' );?></span></td>
                            <td style='vertical-align:middle'><strong><?php echo __($product['version'], 'bsf'); ?></strong></td>
                            <td style='vertical-align:middle'><strong><?php echo __($product['remote'], 'bsf'); ?></strong></td>
                            <td style='vertical-align:middle'><?php echo $upgradeLink; ?></td>
                      	</tr>

                    <?php
                    endforeach;
					?>
                </tbody>
            </table>
            <?php if(!isset($_GET['noajax'])) : ?>
            <script type="text/javascript">
            (function($){
            	$(document).ready(function(){
            		$('tbody.plugins').on('click', '.bsf-update-product-button', function(e) {
            			e.preventDefault();
            			var $tr = $(this).parents('tr:first');
            			var product_id = $(this).attr('data-pid');
            			var bundled_id = $(this).attr('data-bid');
			            var action = 'bsf_upgrade';
			            var bundled = $(this).attr('data-bundled');

			            var is_product_upgraded = false;

			            var $link = $(this).attr('href');

			            $tr.addClass('bsf-product-updating');

			            $tr.find('.bsf-update-spinner').addClass('show');

			            var data = {
			                'action': action,
			                'product_id': product_id,
			                'bundled' : bundled,
			                'bundled_id' : bundled_id
			            };
			            // We can also pass the url value separately from ajaxurl for front end AJAX implementations
			            jQuery.post(ajaxurl, data, function(response) {
			            	// log response for debugging in client sites.
			            	console.log( response );

			            	var is_ftp = false;

			            	$tr.find('td:nth-child(4)').find('.error_message').remove();
			            	$tr.find('td:nth-child(4)').find('br').remove();
			            	var productName = $tr.find('td:nth-child(4)').text();
			            	productName = productName.replace('Update ', '');
			            	productName = productName.replace('.', '');
			            	var html = $tr.find('td:nth-child(4)').html();
			            	html = html + '<br><span class="error_message">There was some problem updating <strong>'+ productName +'</strong>, Please try again.</span>';

			                var plugin_status = response.split('|');

			                if(/Connection Type/i.test(response)) {
	                            is_ftp = true;
	                            response = 'FTP protected, redirecting to traditional installer.';
	                        }

			                $.each(plugin_status, function(i,res){
			                    if(res === 'bsf-product-upgraded') {
			                        is_product_upgraded = true;
			                    }
			                });
			                if(is_product_upgraded) {
			                    $tr.addClass('bsf-product-upgraded').removeClass('active');
			                    var remote_version = $tr.find('td:nth-child(3)').html();
			                    $tr.find('td:nth-child(4)').html('Updated successfully! <i class="dashicons dashicons-yes"></i>');
			                    $tr.find('td:nth-child(2)').html(remote_version);
			                    $tr.find('td:nth-child(1)').find('span').remove();
			                }
			                else {
			                	$tr.find('td:nth-child(4)').html(response);
			                	setTimeout(function(){
	                                window.location.assign($link);
	                            },2000);
			                }

			                if ( response == '' ) {
			                	$tr.find('td:nth-child(4)').html(html);
			                	$tr.find('td:nth-child(4)').find('span').removeClass('show');
			                	//$tr.find('td:nth-child(4)').append('</br><span>There was some problem updating <strong>'+ val +'</strong>, Please try again.</span>');
			                }
			            });
            		});
            	});
            })(jQuery);
            </script>
        	<?php endif; ?>
           	<?php
		else :
			echo '<p>' . __( 'Your plugins from Brainstorm Force are all up to date.', 'bsf' ) . '</p>';
		endif;
	}
}


/**
 * Unique sort final update ready array
 *
 * @param array
 *
 * @return array with unique plugins
 */
if ( ! function_exists( 'bsf_array_unique' ) ) {
	function bsf_array_unique( $arrs ) {

		$available_inits = array();

		foreach ( $arrs as $key => $arr ) {
			if( array_key_exists( 'init', $arr ) ) {
				if ( in_array( $arr['init'], $available_inits ) ) {
					unset( $arrs[$key] );
				} else {
					array_push( $available_inits , $arr['init']);
				}
			}
		}

		return $arrs;
	}
}
admin-functions.php000066600000145613151264132510010371 0ustar00<?php
global $bsf_product_validate_url, $bsf_support_url;
$bsf_product_validate_url = 'https://support.brainstormforce.com/wp-admin/admin-ajax.php';
$bsf_support_url = 'https://support.brainstormforce.com/';
// Generate 32 characters
if(!function_exists('bsf_generate_rand_token')) {
	function bsf_generate_rand_token(){
		$validCharacters = 'abcdefghijklmnopqrstuvwxyz0123456789';
		$myKeeper = '';
		$length = 32;
		for ($n = 1; $n < $length; $n++) {
			$whichCharacter = rand(0, strlen($validCharacters)-1);
			$myKeeper .= $validCharacters{$whichCharacter};
		}
		return $myKeeper;
	}
}
// product registration
add_action( 'wp_ajax_bsf_register_product', 'bsf_register_product_callback' );
if(!function_exists('bsf_register_product_callback')) {
	function bsf_register_product_callback() {

		global $bsf_product_validate_url;
		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();
		$brainstrom_users = (get_option('brainstrom_users')) ? get_option('brainstrom_users') : array();

		$bsf_product_plugins = $bsf_product_themes = array();

		$type = isset($_POST['type']) ? $_POST['type'] : '';
		$product = isset($_POST['product']) ? $_POST['product'] : '';
		$id = isset($_POST['id']) ? $_POST['id'] : '';
		$bsf_username = isset($_POST['bsf_username']) ? $_POST['bsf_username'] : '';
		$bsf_useremail = isset($_POST['bsf_useremail']) ? $_POST['bsf_useremail'] : '';
		$purchase_key = isset($_POST['purchase_key']) ? $_POST['purchase_key'] : '';
		$version = isset($_POST['version']) ? $_POST['version'] : '';
		$step = isset($_POST['step']) ? $_POST['step'] : '';
		$product_name = isset($_POST['product_name']) ? $_POST['product_name'] : '';
		$token = bsf_generate_rand_token();

		if(!empty($brainstrom_products)) :
			$bsf_product_plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
		endif;

		$product_key = $is_edd = '';

		if($type === 'plugin' || $type === 'theme')
		{
			$bsf_products_array = array();
			if($type == 'plugin')
				$bsf_products_array = $bsf_product_plugins;
			elseif($type == 'theme')
				$bsf_products_array = $bsf_product_themes;
			if(!empty($bsf_products_array)) :
				foreach($bsf_products_array as $key => $bsf_product)
				{
					$bsf_template = $bsf_product['template'];
					if($product == $bsf_template)
					{
						$product_key = $key;
						$brainstrom_products[$type.'s'][$key]['purchase_key'] = $purchase_key;
						$brainstrom_products[$type.'s'][$key]['version'] = $version;
						$brainstrom_products[$type.'s'][$key]['product_name'] = $product_name;
						$is_edd = (isset($brainstrom_products[$type.'s'][$key]['edd'])) ? $brainstrom_products[$type.'s'][$key]['edd'] : '';
					}
				}
			endif;
		}

		update_option('brainstrom_products', $brainstrom_products);

		$path = $bsf_product_validate_url;

		$data = array(
				'action' => 'bsf_product_registration',
				'purchase_key' => $purchase_key,
				'bsf_username' => $bsf_username,
				'bsf_useremail' => $bsf_useremail,
				'site_url' => get_site_url(),
				'version' => $version,
				'token' => $token,
				'referer' => 'customer',
				'id' => $id
			);
		if($is_edd)
			$data['edd'] = $is_edd;
		$data = apply_filters('bsf_product_registration_args', $data);
		$request = @wp_remote_post(
			$path, array(
				'body' => $data,
				'timeout' => '30',
				'sslverify' => false
			)
		);

		if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200)
		{
			$result = json_decode($request['body']);
			$status = '';
			//echo json_encode($result); die();
			if(isset($result->status))
			{
				$status = $result->status;
				$brainstrom_products[$type.'s'][$product_key]['status'] = $status;
			}

			if($status === 'registered')
			{
				// reset bundled products if type is theme
				if($type === 'theme') {
					delete_option('brainstrom_bundled_products');
					delete_site_transient('bsf_get_bundled_products');
					global $ultimate_referer;
					$ultimate_referer = 'on-register-product';
					bsf_check_product_update();
				}
				$brainstrom_products[$type.'s'][$product_key]['step'] = 'step-all-success';
				$temp_info['product_info'] = $brainstrom_products[$type.'s'][$product_key];

				$user_array = array(
					'email' => $bsf_useremail,
					'token' => $token
				);
				if(!empty($brainstrom_users))
				{
					$find_key = false;
					foreach($brainstrom_users as $key => $user)
					{
						if($user['email'] === $bsf_useremail)
						{
							$brainstrom_users[$key]['token'] = $token;
							$find_key = true;
						}
					}
					if(!$find_key)
						array_push($brainstrom_users, $user_array);
				}
				else
					array_push($brainstrom_users, $user_array);
				update_option('brainstrom_users', $brainstrom_users);
			}

			update_option('brainstrom_products', $brainstrom_products);

			echo json_encode($result);

		}
		else
		{
			$arr = array('response' => $request->get_error_message());
			echo json_encode($arr);
		}

		wp_die();
	} //end of bsf_register_product_callback
}
// function to de register licence
add_action( 'wp_ajax_bsf_deregister_product', 'bsf_deregister_product_callback' );
if(!function_exists('bsf_deregister_product_callback')) {
	function bsf_deregister_product_callback() {
		global $bsf_product_validate_url;
		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();

		$bsf_product_plugins = $bsf_product_themes = array();

		$type = isset($_POST['type']) ? $_POST['type'] : '';
		$product = isset($_POST['product']) ? $_POST['product'] : '';
		$id = isset($_POST['id']) ? $_POST['id'] : '';
		$bsf_useremail = isset($_POST['bsf_useremail']) ? $_POST['bsf_useremail'] : '';
		$purchase_key = isset($_POST['purchase_key']) ? $_POST['purchase_key'] : '';
		$version = isset($_POST['version']) ? $_POST['version'] : '';
		$product_name = isset($_POST['product_name']) ? $_POST['product_name'] : '';
		$token = bsf_generate_rand_token();

		if(!empty($brainstrom_products)) :
			$bsf_product_plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
		endif;

		$product_key = $is_edd = '';

		if($type === 'plugin' || $type === 'theme')
		{
			$bsf_products_array = array();
			if($type == 'plugin')
				$bsf_products_array = $bsf_product_plugins;
			elseif($type == 'theme')
				$bsf_products_array = $bsf_product_themes;
			if(!empty($bsf_products_array)) :
				foreach($bsf_products_array as $key => $bsf_product)
				{
					if(!isset($bsf_product['template']))
						continue;
					$bsf_template = $bsf_product['template'];
					if($product == $bsf_template)
					{
						$product_key = $key;
						$brainstrom_products[$type.'s'][$key]['status'] = 'not-registered';
						$is_edd = (isset($brainstrom_products[$type.'s'][$key]['edd'])) ? $brainstrom_products[$type.'s'][$key]['edd'] : '';
					}
				}
			endif;
		}

		update_option('brainstrom_products', $brainstrom_products);

		$path = $bsf_product_validate_url;

		$data = array(
				'action' => 'bsf_product_deregistration',
				'purchase_key' => $purchase_key,
				'bsf_useremail' => $bsf_useremail,
				'site_url' => get_site_url(),
				'version' => $version,
				'id' => $id,
				'token' => $token,
				'product' => $product_name
			);
		if($is_edd)
			$data['edd'] = $is_edd;
		$data = apply_filters('bsf_product_deregistration_args', $data);
		$request = @wp_remote_post(
			$path, array(
				'body' => $data,
				'timeout' => '30',
				'sslverify' => false
			)
		);

		if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200)
		{
			$result = json_decode($request['body']);
			//$result->message_html = 'Site deactivated!<br/>'.$result->message_html;
			echo json_encode($result);
		}
		else
		{
			$res['response'] = array(
				'title' => 'Error',
				'message_html' => 'Site deactivated!<br/> Error while communicating with server'.$request->get_error_message()
			);
			$res['proceed'] = true;
			echo json_encode($res);
		}

		wp_die();
	}
}
// first step execution of user registration
add_action( 'wp_ajax_bsf_register_user', 'bsf_register_user_callback' );
if(!function_exists('bsf_register_user_callback')) {
	function bsf_register_user_callback() {
		global $bsf_product_validate_url;

		$brainstrom_users = (get_option('brainstrom_users')) ? get_option('brainstrom_users') : array();

		$bsf_username = isset($_POST['bsf_username']) ? $_POST['bsf_username'] : '';
		$bsf_useremail = isset($_POST['bsf_useremail']) ? $_POST['bsf_useremail'] : '';
		$bsf_useremail_reenter = isset($_POST['bsf_useremail_reenter']) ? $_POST['bsf_useremail_reenter'] : '';

		$subscribe = isset($_POST['ultimate_user_receive']) ? $_POST['ultimate_user_receive'] : '';

		$token = bsf_generate_rand_token();

		if($bsf_useremail !== $bsf_useremail_reenter) {
			$response['response'] = array(
				'title' => 'Error',
				'message_html' => 'Email address did not matched'
			);
			$response['proceed'] = false;

			echo json_encode($response);
			wp_die();
		}

		$domain = substr(strrchr($bsf_useremail, "@"), 1);
		if($domain === '' || $domain === false)
			$domain = $bsf_useremail;
		if(function_exists('checkdnsrr')) {
			$dns_check = checkdnsrr($domain, 'MX');
			if(!$dns_check)
			{
				$response['response'] = array(
					'title' => 'Error',
					'message_html' => 'Please enter valid email address, username and password will sent to your provided email address'
				);
				$response['proceed'] = false;
				echo json_encode($response);
				wp_die();
			}
		}

		$path = $bsf_product_validate_url;

		$data = array(
				'action' => 'bsf_user_registration',
				'bsf_username' => $bsf_username,
				'bsf_useremail' => $bsf_useremail,
				'bsf_useremail_confirm' => $bsf_useremail_reenter,
				'ultimate_user_receive' => $subscribe,
				'site_url' => get_site_url(),
				'token' => $token,
			);

		$request = @wp_remote_post(
			$path, array(
				'body' => $data,
				'timeout' => '60',
				'sslverify' => false
			)
		);

		if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200)
		{
			$result = json_decode($request['body']);
			if((isset($result->proceed)) && ($result->proceed === 'true' || $result->proceed === true))
			{
				$user_array = array(
					'name' => $bsf_username,
					'email' => $bsf_useremail,
					'token' => $token
				);
				if(!empty($brainstrom_users))
				{
					$find_key = false;
					foreach($brainstrom_users as $key => $user)
					{
						if($user['email'] === $bsf_useremail)
						{
							$brainstrom_users[$key]['name'] = $bsf_username;
							$brainstrom_users[$key]['token'] = $token;
							$find_key = true;
							break;
						}
					}
					if(!$find_key)
						array_push($brainstrom_users, $user_array);
				}
				else
					array_push($brainstrom_users, $user_array);

				update_option('brainstrom_users', $brainstrom_users);

				global $ultimate_referer;
				$ultimate_referer = 'on-user-register';
				bsf_check_product_update();
			}
			echo json_encode($result);
		}
		else
		{
			$arr = array('response' => $request->get_error_message());
			echo json_encode($arr);
		}

		wp_die();
	}// end of bsf_register_user_callback
}
add_action('admin_init','bsf_update_all_product_version',1000);
if(!function_exists('bsf_update_all_product_version')) {
	function bsf_update_all_product_version() {
		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();
		$brainstrom_bundled_products = (get_option('brainstrom_bundled_products')) ? get_option('brainstrom_bundled_products') : array();

		$mix_products = $update_ready = $bsf_product_plugins = $bsf_product_themes = array();

		if(!empty($brainstrom_products)) :
			$bsf_product_plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
		endif;

		$product_updated = $bundled_product_updated = false;

		if(!empty($bsf_product_plugins)) :
			foreach($bsf_product_plugins as $key => $plugin) :
				if(!isset($plugin['id']) || empty($plugin['id']) )
					continue;
				if(!isset($plugin['template']) || empty($plugin['template']) )
					continue;
				if(!isset($plugin['type']) || empty($plugin['type']) )
					continue;
				$version = (isset($plugin['version'])) ? $plugin['version'] : '';
				$current_version = bsf_get_current_version($plugin['template'], $plugin['type']);
				$name = bsf_get_current_name($plugin['template'], $plugin['type']);
				if($name !== '')
					$brainstrom_products['plugins'][$key]['product_name'] = $name;
				if($current_version !== '') {
					if(version_compare($version, $current_version) === -1 || version_compare($version, $current_version) === 1)
					{
						$brainstrom_products['plugins'][$key]['version'] = $current_version;
						$product_updated = true;
					}
				}
			endforeach;
		endif;

		if(!empty($bsf_product_themes)) :
			foreach($bsf_product_themes as $key => $theme) :
				//if(!isset($theme['id']))
					//unset($brainstrom_products[$key]);
				if(!isset($theme['id']) || empty($theme['id']) )
					continue;
				if(!isset($theme['template']) || empty($theme['template']) )
					continue;
				if(!isset($theme['type']) || empty($theme['type']) )
					continue;
				$version = (isset($theme['version'])) ? $theme['version'] : '';
				$current_version = bsf_get_current_version($theme['template'], $theme['type']);
				$name = bsf_get_current_name($theme['template'], $theme['type']);
				if($name !== '')
					$brainstrom_products['themes'][$key]['product_name'] = $name;
				if($current_version !== '' || $current_version !== false) {
					if(version_compare($version, $current_version) === -1 || version_compare($version, $current_version) === 1)
					{
						$brainstrom_products['themes'][$key]['version'] = $current_version;
						$product_updated = true;
					}
				}
			endforeach;
		endif;

		if(!empty($brainstrom_bundled_products)) :
			foreach($brainstrom_bundled_products as $keys => $bps) :
				$version = '';
				if(strlen($keys) > 1) {
					foreach ($bps as $key => $bp) {
						if(!isset($bp->id) || $bp->id === '') {
							continue;
						}
						$version = $bp->version;
						$current_version = bsf_get_current_version($bp->init, $bp->type);

						if($current_version !== '' && $current_version !== false) {
							if( version_compare($version, $current_version) === -1 || version_compare($version, $current_version) === 1 ) {
								if (is_object( $brainstrom_bundled_products )) {
									$brainstrom_bundled_products = array($brainstrom_bundled_products);
								}
								$single_bp = $brainstrom_bundled_products[$keys];
								$single_bp[$key]->version = $current_version;
								$bundled_product_updated = true;
								$brainstrom_bundled_products[$keys] = $single_bp;
							}
						}
					}
				}
				else {
					if(!isset($bps->id) || $bps->id === '') {
						continue;
					}
					$version = $bps->version;
					$current_version = bsf_get_current_version($bps->init, $bps->type);
					if($current_version !== '' || $current_version !== false) {
					if(version_compare($version, $current_version) === -1 || version_compare($version, $current_version) === 1)
						{
							$brainstrom_bundled_products[$keys]->version = $current_version;
							$bundled_product_updated = true;
						}
					}
				}
			endforeach;
		endif;

		//if($product_updated)
		update_option('brainstrom_products', $brainstrom_products);

		if($bundled_product_updated){
			//echo 'Before Update'; die();
			update_option('brainstrom_bundled_products', $brainstrom_bundled_products);
		}
	}
}
if(!function_exists('bsf_get_current_version')) {
	function bsf_get_current_version($template, $type) {
		if($template === '')
			return false;
		if($type === 'theme' || $type === 'themes')
		{
			$theme = wp_get_theme($template);
			$version = $theme->get( 'Version' );
		}
		else if($type === 'plugin' || $type === 'plugins')
		{
			$plugin_file = rtrim(WP_PLUGIN_DIR,'/').'/'.$template;
			if(!is_file($plugin_file))
				return false;
			$plugin = get_plugin_data($plugin_file);
			$version = $plugin['Version'];
		}
		return $version;
	}
}
if(!function_exists('bsf_get_current_name')) {
	function bsf_get_current_name($template, $type) {
		if($template === '')
			return false;
		if($type === 'theme' || $type === 'themes')
		{
			$theme = wp_get_theme($template);
			$name = $theme->get( 'Name' );
		}
		else if($type === 'plugin' || $type === 'plugins')
		{
			$plugin_file = rtrim(WP_PLUGIN_DIR,'/').'/'.$template;
			if(!is_file($plugin_file))
				return false;
			$plugin = get_plugin_data($plugin_file);
			$name = $plugin['Name'];
		}
		return $name;
	}
}
add_action('admin_notices','bsf_notices',1000);
add_action('network_admin_notices','bsf_notices',1000);
if(!function_exists('bsf_notices')) {
	function bsf_notices() {
		global $pagenow;

		if ( $pagenow === 'plugins.php' || $pagenow === 'post-new.php' || $pagenow === 'edit.php' || $pagenow === 'post.php') {
			$brainstrom_products = get_option('brainstrom_products');
			$brainstrom_bundled_products = (get_option('brainstrom_bundled_products')) ? get_option('brainstrom_bundled_products') : array();

			if(empty($brainstrom_products))
				return false;

			$brainstrom_bundled_products_keys = array();

			if(!empty($brainstrom_bundled_products)) :
				foreach($brainstrom_bundled_products as $bps) {
					foreach ($bps as $key => $bp) {
						array_push($brainstrom_bundled_products_keys, $bp->id);
					}
				}
			endif;

			$mix = array();

			$plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();

			$mix = array_merge($plugins, $themes);

			if(empty($mix))
				return false;

			if((defined('BSF_PRODUCTS_NOTICES') && (BSF_PRODUCTS_NOTICES === 'false' || BSF_PRODUCTS_NOTICES === false)))
				return false;

			$is_multisite = is_multisite();
			$is_network_admin = is_network_admin();

			foreach($mix as $product) :
				if(!isset($product['id']))
					continue;
				if(isset($product['is_product_free']) && ($product['is_product_free'] === 'true' || $product['is_product_free'] === true))
					continue;
				$constant = strtoupper(str_replace('-', '_', $product['id']));
				$constant_nag = 'BSF_'.$constant.'_NAG';
				$constant_notice = 'BSF_'.$constant.'_NOTICES';

				$show_nag = false;

				if(defined($constant_nag) && (constant($constant_nag) === 'false' || constant($constant_nag) === false))
					continue;
				if(defined($constant_notice) && (constant($constant_notice) === 'false' || constant($constant_notice) === false))
					continue;

				$status = (isset($product['status'])) ? $product['status'] : false;
				$type = (isset($product['type'])) ? $product['type'] : false;

				if(!$type)
					continue;

				if($type === 'plugin') {
					if(!is_plugin_active($product['template']))
						continue;
				}
				elseif($type === 'theme') {
					$theme = wp_get_theme();
					if ($product['template'] !== $theme->template)
						continue;
				}
				else
					continue;

				if(in_array($product['id'],$brainstrom_bundled_products_keys))
					continue;

				if($status !== 'registered') :
					if(is_multisite())
						$url = network_admin_url('index.php?page=bsf-registration');
					else {
						if(defined('BSF_REG_MENU_TO_SETTINGS') && (BSF_REG_MENU_TO_SETTINGS == true || BSF_REG_MENU_TO_SETTINGS == 'true')) {
							$url = admin_url('options-general.php?page=bsf-registration');
						}
						else {
							$url = admin_url('index.php?page=bsf-registration');
						}
					}

					$message = __('Please','bsf').' <a href="'.$url.'">'.__('activate','bsf').'</a> '.__('your copy of the','bsf').' '.$product['product_name'].' '.__('to get update notifications, access to support features & other resources!','bsf');

					if(($is_multisite && $is_network_admin) || !$is_multisite)
						echo '<div class="update-nag bsf-update-nag">'.$message.'</div>';
				endif;
			endforeach;
		}
	}
}
if(!function_exists('upgrade_bsf_product')) {
	function upgrade_bsf_product($request_product_id, $bundled_id) {
		global $bsf_product_validate_url, $bsf_support_url;

		global $ULT_UPGRADE_AJAX;
		$ajax = isset($ULT_UPGRADE_AJAX) ? $ULT_UPGRADE_AJAX : false;

		if ( ! current_user_can('update_plugins') ) {
			if($ajax) {
				return __('You do not have sufficient permissions to update plugins for this site.','bsf');
			} else {
				wp_die(__('You do not have sufficient permissions to update plugins for this site.','bsf'));
			}
		}

		$brainstrom_users = (get_option('brainstrom_users')) ? get_option('brainstrom_users') : array();

		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();
		$brainstrom_bundled_products = (get_option('brainstrom_bundled_products')) ? get_option('brainstrom_bundled_products') : array();

		$plugins = $themes = $mix = array();
		if(!empty($brainstrom_products)) {
			$plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
		}

		$mix = array_merge($plugins, $themes);

		$bsf_username = $purchase_key = $type = $template = $name = '';

		if(!empty($brainstrom_users)) :
			foreach($brainstrom_users as $bsf_user) :
				$bsf_username = $bsf_user['email'];
			endforeach;
		endif;

		$found_in_bsf_products = false;

		if($bundled_id !== false)
			$product_details_id = $bundled_id;
		else
			$product_details_id = $request_product_id;

		foreach($mix as $key => $product)
		{
			$pid = $product['id'];
			if($pid === $product_details_id) {
				$purchase_key = isset( $product['purchase_key'] ) ? $product['purchase_key'] : NULL;
				$type = $product['type'];
				$template = $product['template'];
				$name = $product['product_name'];
				$found_in_bsf_products = true;
				break;
			}
		}

		if($bundled_id !== false) {
			if(!empty($brainstrom_bundled_products)) {
				foreach($brainstrom_bundled_products as $bps) {
					foreach ($bps as $key => $bp) {
						if($bp->id === $request_product_id) {
							$type = $bp->type;
							$template = $bp->init;
							$name = $bp->name;
						}
					}
				}
			}
		}

		if($bsf_username === '' || $purchase_key === '' || $request_product_id === '') {
			if($ajax) {
				return __('Not valid to update product', 'bsf');
			} else {
				wp_die('Not valid to update product');
			}
		}

		$path = $bsf_product_validate_url;

		$data = array(
				'action' => 'bsf_product_update_request',
				'id' => $request_product_id,
				'username' => $bsf_username,
				'purchase_key' => $purchase_key,
				'site_url' => get_site_url(),
				'bundled' => $bundled_id
			);

		$request = @wp_remote_post(
			$path, array(
				'body' => $data,
				'timeout' => '60',
				'sslverify' => false
			)
		);

		if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200)
		{
			$result = json_decode($request['body']);

			if(isset($result->error) && !$result->error)
			{
				$download_path = $result->update_data->download_url;

				$timezone = date_default_timezone_get();

				$call = 'file='.$download_path.'&hashtime='.strtotime(date('d-m-Y h:i:s a')).'&timezone='.$timezone;
				$hash = $call;

				$parse = parse_url($path);
				$download = $parse['scheme'].'://'.$parse['host'];

				$get_path = 'http://downloads.brainstormforce.com/';
				$download_path = rtrim($get_path,'/').'/download.php?'.$hash.'&base=ignore';
				//echo $download_path;
				//die();

				require_once (ABSPATH . '/wp-admin/includes/file.php');
				WP_Filesystem();
				global $wp_filesystem;

				require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
				$WP_Upgrader = new WP_Upgrader;
				$res = $WP_Upgrader->fs_connect(array(
					WP_CONTENT_DIR
				));
				if (!$res) {
					wp_die(new WP_Error('Server error', __("Error! Can't connect to filesystem", 'bsf')));
				}
				else {
					$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade_tmp/bsf_package';

					$package_filename = basename($download_path);
					$plugin_folder = dirname($template);

					if($type === 'theme' && $bundled_id === false) {
						$defaults = array(
							'clear_update_cache' => true,
						);
						$args = array();
						$parsed_args = wp_parse_args( $args, $defaults );

						$Theme_Upgrader = new Theme_Upgrader;
						$Theme_Upgrader->init();
						$Theme_Upgrader->upgrade_strings();
						$Theme_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf');
						add_filter('upgrader_pre_install', array(&$Theme_Upgrader, 'current_before'), 10, 2);
						add_filter('upgrader_post_install', array(&$Theme_Upgrader, 'current_after'), 10, 2);
						add_filter('upgrader_clear_destination', array(&$Theme_Upgrader, 'delete_old_theme'), 10, 4);

						$Theme_Upgrader->run( array(
							'package' => $download_path,
							'destination' => get_theme_root( $template ),
							'clear_destination' => true,
							'abort_if_destination_exists' => false,
							'clear_working' => true,
							'hook_extra' => array(
								'theme' => $template,
								'type' => 'theme',
        						'action' => 'update',
							),
						) );

						remove_filter('upgrader_pre_install', array(&$Theme_Upgrader, 'current_before'));
						remove_filter('upgrader_post_install', array(&$Theme_Upgrader, 'current_after'));
						remove_filter('upgrader_clear_destination', array(&$Theme_Upgrader, 'delete_old_theme'));

						if ( ! $Theme_Upgrader->result || is_wp_error($Theme_Upgrader->result) )
							return $Theme_Upgrader->result;

						wp_clean_themes_cache( $parsed_args['clear_update_cache'] );

						$response = array(
							'status' => true,
							'type' => 'theme',
							'name' => $name
						);
						return $response;
					}
					elseif($type === 'plugin') {
						$is_activated = is_plugin_active($template);

						$Plugin_Upgrader = new Plugin_Upgrader;
						$defaults = array(
				            'clear_update_cache' => true,
				        );

				        $Plugin_Upgrader->init();
				        $Plugin_Upgrader->upgrade_strings();
				        $Plugin_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf');

				        add_filter('upgrader_pre_install', array($Plugin_Upgrader, 'deactivate_plugin_before_upgrade'), 10, 2);
				        add_filter('upgrader_clear_destination', array($Plugin_Upgrader, 'delete_old_plugin'), 10, 4);
				        //'source_selection' => array($this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.

				        $Plugin_Upgrader->run( array(
				            'package' => $download_path,
				            'destination' => WP_PLUGIN_DIR,
				            'clear_destination' => true,
				            'clear_working' => true,
				            'hook_extra' => array(
				                'plugin' => $template,
				                'type' => 'plugin',
				                'action' => 'update',
				            ),
				        ) );

				        // Cleanup our hooks, in case something else does a upgrade on this connection.
				        remove_filter('upgrader_pre_install', array($Plugin_Upgrader, 'deactivate_plugin_before_upgrade'));
				        remove_filter('upgrader_clear_destination', array($Plugin_Upgrader, 'delete_old_plugin'));

				        if ( ! $Plugin_Upgrader->result || is_wp_error($Plugin_Upgrader->result) )
				            return $Plugin_Upgrader->result;

				        // Force refresh of plugin update information
				        wp_clean_plugins_cache( $defaults['clear_update_cache'] );

				        if($is_activated) {
				        	activate_plugin($template);
				        }

						$response = array(
							'status' => true,
							'type' => 'plugin',
							'name' => $name
						);
						return $response;
					}

				}
			}
			else
			{
				if($ajax) {
					return $result->message;
				} else {
					echo $result->message;
				}
			}
		}
		else
		{
			if($ajax) {
				return $request->get_error_message();
			} else {
				echo $request->get_error_message();
			}
		}
	}
}
if(!function_exists('bsf_grant_developer_access')) {
	function bsf_grant_developer_access($action){
		$brainstrom_users = (get_option('brainstrom_users')) ? get_option('brainstrom_users') : array();

		if(empty($brainstrom_users))
			return false;

		global $current_user;
		$user = $current_user->user_login;
		$email = $current_user->user_email;

		// $token = bin2hex(openssl_random_pseudo_bytes(32));
		$token = bsf_generate_rand_token();
		$url = wp_nonce_url( get_site_url().'/wp-login.php?developer_access=true&access_id='.$user.'&access_token='.$token);

		$subject = $message = $vc_version = '';

		$username = (isset($brainstrom_users[0]['name'])) ? $brainstrom_users[0]['name'] : $user;

		$response = bsf_allow_developer_access($username, $url, $action);
		if($response){
			if($action === 'grant') {
				update_option('developer_access',true);
				$interval = time()+(15 * 24 * 60 * 60);
				update_option('access_time',$interval);
				update_option( 'access_token', $token );
				//echo '<div class="updated"><p>'.$response.'</p></div>';
			}
			else {
				$interval = time()-(10000);
				update_option('access_time',$interval);
				if(update_option('developer_access',false)){
					//echo __("Access Revoked!",'bsf');
				} else {
					?>
                    <div class="error"><p><?php echo __("Something went wrong. Please try again!",'bsf'); ?></p></div>
                    <?php
				}
			}
		} else {
			echo '<div class="error"><p>Something went wrong. Please try again.</p></div>';
			update_option('developer_access',false);
			$interval = time();
			update_option('access_time',$interval);
		}
	}
}
if(!function_exists('bsf_allow_developer_access')) {
	function bsf_allow_developer_access($username, $url, $process){
		global $bsf_product_validate_url;
		$path = $bsf_product_validate_url;
		$new_url = $url;
		$user = $username;
		$request = @wp_remote_post(
						$path, 	array(
							'body' => array(
								'action' => 'give_developer_access',
								'userid' => $user,
								'login_url' => $new_url,
								'site_url' => get_site_url(),
								'process' => $process,
							),
							'timeout' => '30',
							'sslverify' => false
						)
					);
		if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
			return ($request['body']);
		}
	}
}
if(!function_exists('bsf_process_developer_login')) {
	function bsf_process_developer_login(){
		$basename = basename($_SERVER['SCRIPT_NAME']);
		if($basename=='wp-login.php'){
			$interval = get_option('access_time');
			$now = time();
			if($interval <= $now){
				update_option('developer_access',false);
			}
			require_once( ABSPATH . 'wp-includes/pluggable.php' );

			if(isset($_GET['access_token'])){
				$access = get_option('developer_access');
				$access_token = get_option('access_token');
				$verify_token = $_GET['access_token'];
				$verified = ($access_token === $verify_token) ? true : false;
				if(isset($_GET['developer_access']) && $access && $verified)
				{
					$user_login = $_GET['access_id'];
					$user =  get_user_by('login',$user_login);
					$user_id = $user->ID;
					wp_set_current_user($user_id, $user_login);
					wp_set_auth_cookie($user_id);
					$redirect_to = user_admin_url();
					setcookie("DeveloperAccess", "active", time()+86400);
					wp_safe_redirect( $redirect_to );
					exit();
				}
			}
		}
	}
}
bsf_process_developer_login();
//add_action( 'admin_init', 'bsf_process_developer_login', 1);

if(!function_exists('bsf_update_counter')) {
	function bsf_update_counter() {
		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();
		$brainstrom_bundled_products = (get_option('brainstrom_bundled_products')) ? get_option('brainstrom_bundled_products') : array();

		$mix_products = $update_ready = $bsf_product_plugins = $bsf_product_themes = $temp_bundled = $temp_theme_update_ready = array();

		if(!empty($brainstrom_products)) :
			$bsf_product_plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
		endif;

		$mix_products = array_merge($bsf_product_plugins);

		foreach($mix_products as $product)
		{
			$is_bundled = false;
			if(!isset($product['id']) || empty($product['id']) )
				continue;
			$id = $product['id'];

			$constant = strtoupper(str_replace('-', '_', $product['id']));
			$constant = 'BSF_'.$constant.'_CHECK_UPDATES';
			if(defined($constant) && (constant($constant) === 'false' || constant($constant) === false))
				continue;

			$bundled_key = '';
			if(!empty($brainstrom_bundled_products)) {
				foreach($brainstrom_bundled_products as $bkeys => $bps) {
					if(strlen($bkeys) > 1) {
						foreach ($bps as $bkey => $bp) {
							if(!isset($bp->id) || $bp->id === '')
								continue;
							if($id === $bp->id) {
								$is_bundled = true;
								if ( is_object( $brainstrom_bundled_products ) ) {
									$brainstrom_bundled_products = (array)$brainstrom_bundled_products;
								}
								$bprd = isset( $brainstrom_bundled_products[$bkeys] ) ? $brainstrom_bundled_products[$bkeys] : ''	;
								$version =  isset( $bprd[$bkey]->version ) ? $bprd[$bkey]->version : '';
								$remote = isset( $bprd[$bkey]->remote ) ? $bprd[$bkey]->remote : '';
								$template = isset( $bprd[$bkey]->init ) ? $bprd[$bkey]->init : '';
								$type = isset( $bprd[$bkey]->type ) ? $bprd[$bkey]->type : '';
								$bundled_key = $bkey;
								if( version_compare( $remote, $version, '>' ) ) {
									$temp = (array)$bprd[$bundled_key];
									$temp['bundled'] = true;
									array_push($temp_bundled, $temp['id']);
									array_push($update_ready, $temp);
								}

								break;
							}
						}
					}
					else {
						if(!isset($bps->id) || $bps->id === '')
								continue;
						if($id === $bps->id) {
							$is_bundled = true;
							$bundled_key = $bkeys;
							break;
						}
					}

				}
			}

			if($is_bundled)
			{
				//echo '['.$bundled_key.']';
				// $version = (isset($brainstrom_bundled_products[$bundled_key]->version)) ? $brainstrom_bundled_products[$bundled_key]->version : '';
				// $remote = (isset($brainstrom_bundled_products[$bundled_key]->remote)) ? $brainstrom_bundled_products[$bundled_key]->remote : '';
				// $template = (isset($brainstrom_bundled_products[$bundled_key]->init)) ? $brainstrom_bundled_products[$bundled_key]->init : '';
			}
			else
			{
				$version = (isset($product['version'])) ? $product['version'] : '';
				$remote = (isset($product['remote'])) ? $product['remote'] : '';
				$template = (isset($product['template'])) ? $product['template'] : '';
			}

			$plugin_abs_path = WP_PLUGIN_DIR.'/'.$template;

			if(!is_file($plugin_abs_path))
				continue;

			if(version_compare($remote, $version, '>')):
				if($is_bundled)
				{
					// $temp = (array)$brainstrom_bundled_products[$bundled_key];
					// $temp['bundled'] = true;
					// array_push($temp_bundled, $temp['id']);
					// array_push($update_ready, $temp);
				}
				else
				{
					$product['bundled'] = false;
					array_push($update_ready, $product);
				}
			endif;
		}

		foreach($brainstrom_bundled_products as $bkeys => $bps) {
			if(strlen($bkeys) > 1) {
				foreach ($bps as $bkey => $bp) {
					$plugin_abs_path = WP_PLUGIN_DIR.'/'.$bp->init;

					if(!is_file($plugin_abs_path))
						continue;

					$temp = array();
					if(!in_array($bp->id, $temp_bundled)) {
						if(!isset($bp->remote))
							break;
						if(version_compare($bp->remote, $bp->version, '>')):
							$temp = (array)$bp;
						$temp['bundled'] = true;
						array_push($update_ready, $temp);
						endif;
					}
				}
			}
			else {
				$plugin_abs_path = WP_PLUGIN_DIR.'/'.$bps->init;

				if(!is_file($plugin_abs_path))
					continue;

				$temp = array();
				if(!in_array($bps->id, $temp_bundled)) {
					if(!isset($bps->remote))
						break;

					$is_wp = (isset($bps->in_house) && $bps->in_house === 'wp') ? true : false;

					if($is_wp)
						break;
					if(version_compare($bps->remote, $bps->version, '>')):
						$temp = (array)$bps;
						$temp['bundled'] = true;
						array_push($update_ready, $temp);
					endif;
				}
			}
		}

		// for theme check
		if(!empty($bsf_product_themes)) {
			foreach($bsf_product_themes as $key => $theme) {
				$version = (isset($theme['version'])) ? $theme['version'] : '';
				$remote = (isset($theme['remote'])) ? $theme['remote'] : '';
				if(version_compare($remote, $version, '>')) {
					array_push($temp_theme_update_ready, $theme);
				}
			}
		}
		$theme_update_ready_counter = count($temp_theme_update_ready);

		$update_ready_counter = count($update_ready);

		$update_ready = bsf_array_unique( $update_ready );
		?>
        	<script type="text/javascript">
            	(function($) {
					$(window).load(function(e) {
						var update = $('#menu-plugins').find(".update-plugins");

						var plugin_counter = parseInt(update.find(".plugin-count").html());
						var plugin_update_ready_counter = parseInt(<?php echo $update_ready_counter ?>);
						plugin_counter = plugin_counter+plugin_update_ready_counter;
						$("#menu-dashboard").find(".plugin-count").html(plugin_counter);

						update.removeClass("count-0").addClass("count-"+plugin_counter);
						update.find(".update-count").html(plugin_counter);
						$("#wp-admin-bar-updates").find(".ab-label").html(plugin_counter);

						<?php
							global $pagenow;

							if ( 'plugins.php' === $pagenow ) :
								foreach($update_ready as $ur) : ?>
								<?php
									$message_changelog = '';

									$template = (isset($ur['bundled']) && ($ur['bundled'] === true)) ? $ur["init"] : $ur['template'];

									$plugin_data = get_plugin_data( WP_PLUGIN_DIR.'/'.$template );
									$plugin_main_name = $plugin_data['Name'];

									$changelog_url = (isset($ur['changelog_url'])) ? $ur['changelog_url'] : '';
									if($changelog_url !== '') {
										$message_changelog = 'or view <a href="'.$changelog_url.'" target="_blank">Changelog here</a>';
									}

									if($ur['bundled'])
									{
										$id = str_replace(' ','-', strtolower($plugin_main_name));
										$id = str_replace('---','-', strtolower($id));
										$name = $ur['name'];
										$parent_name = '';

										foreach( $bsf_product_themes as $key => $bsf_p ) {
											if( $bsf_p['id'] === $ur['parent'] ) {
												$parent_name = $bsf_p['product_name'];
												break;
											}
										}

										foreach( $mix_products as $key => $bsf_p ) {
											if( $bsf_p['id'] === $ur['parent'] ) {
												$parent_name = $bsf_p['product_name'];
												break;
											}
										}

										$message = 'There is a new version of '.$name.', bundled with <strong>'.$parent_name.'</strong>.';
									}
									else
									{
										$id = str_replace(' ','-', strtolower($plugin_main_name));
										$name = $ur['product_name'];
										$message = 'There is a new version of '.$name.'.';
									}


								?>
								if($("#<?php echo $id ?>").find('.plugin-update-tr') !== true) {
									$("#<?php echo $id ?>").addClass("update");
									var html = '<tr class="plugin-update-tr">\
												<td colspan="3" class="plugin-update colspanchange">\
													<div class="update-message"><?php echo $message ?> \
													<a href="update-core.php#brainstormforce-products">Check <?php echo $ur["remote"] ?> update details</a>\
													<?php echo $message_changelog ?>
													</div>\
												</td>\
											</tr>';
									$(html).insertAfter("#<?php echo $id ?>");
								}
							<?php endforeach; ?>
						<?php endif; ?>

						<?php if ( 'themes.php' === $pagenow ) : ?>
							<?php foreach($temp_theme_update_ready as $key => $theme) : ?>
								<?php
									$template = $theme['template'];
									$theme = wp_get_theme($template);
									$name = strtolower($theme->get( 'Name' ));
								?>
								var $theme_wrapper = $('#<?php echo $name ?>-name').parents('.theme:first');
								if($theme_wrapper.find('.theme-update') !== true) {
									$theme_wrapper.append('<div class="theme-update">Update Available</div>');
									$theme_wrapper.click(function(){
										$('.theme-overlay').find('.theme-author').after('<div class="theme-update-message"><h4 class="theme-update">Update Available</h4><p><strong>There is a new version of <?php echo $theme->get( 'Name' ) ?> available. <a href="update-core.php#brainstormforce-products" title="<?php echo $name; ?>">Check update details</a> </strong></p></div>');
									});
								}
							<?php endforeach; ?>
						<?php endif; ?>

						<?php if(is_multisite()) : ?>
							$main_menu_dashboard = $('#menu-update');
						<?php else : ?>
							$main_menu_dashboard = $('#menu-dashboard');
						<?php endif; ?>

						var theme_update_ready_counter = parseInt(<?php echo $theme_update_ready_counter ?>);
						var all_counter = parseInt($main_menu_dashboard.find('.update-plugins').find('.update-count').html());
						all_counter = all_counter+theme_update_ready_counter+plugin_update_ready_counter;

						$main_menu_dashboard.find('.update-plugins').find('.update-count').html(all_counter);
						var title = $main_menu_dashboard.find('.update-plugins').attr('title');
						if(typeof title === 'undefined')
							return false;
						var title_split = title.split(',');

						var title_plugins = title_themes = 0;
						if(typeof title_split[0] !== 'undefined')
						{
							if (/Plugin/i.test(title_split[0]))
								title_plugins = parseInt(title_split[0].replace ( /[^\d.]/g, '' ));
							else
								title_themes = parseInt(title_split[0].replace ( /[^\d.]/g, '' ));
						}
						if(typeof title_split[1] !== 'undefined')
						{
							if (/Plugin/i.test(title_split[1]))
								title_plugins = parseInt(title_split[1].replace ( /[^\d.]/g, '' ));
							else
								title_themes = parseInt(title_split[1].replace ( /[^\d.]/g, '' ));
						}

						title_plugins += plugin_update_ready_counter;
						title_themes += theme_update_ready_counter;


						var temp_title = '';
						if(title_plugins !== '' && title_plugins !== 0)
							temp_title = title_plugins+' Plugin Update';
						if(title_themes !== '' && title_themes !== 0)
						{
							if(temp_title != '')
								temp_title += ', ';
							temp_title += title_themes+' Theme Update';
						}

						$main_menu_dashboard.find('.update-plugins').attr('title',temp_title);
					});
				})(jQuery);
            </script>
        <?php
	}
}
add_action('admin_head','bsf_update_counter',999);

if(!function_exists('bsf_get_free_products')) {
	function bsf_get_free_products () {
		$plugins = get_plugins();
		$themes = wp_get_themes();

		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();

		$bsf_free_products = array();

		if(!empty($brainstrom_products)) :
			$bsf_product_plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
		endif;

		foreach($plugins as $plugin => $plugin_data)
		{
			if(trim($plugin_data['Author']) === 'Brainstorm Force')
			{
				if(!empty($bsf_product_plugins)) :
					foreach($bsf_product_plugins as $key => $bsf_product_plugin)
					{
						$bsf_template = (isset($bsf_product_plugin['template'])) ? $bsf_product_plugin['template'] : '';
						if($plugin == $bsf_template)
						{
							//$plugin_data = array_merge($plugin_data, $temp);
							if(isset($bsf_product_plugin['is_product_free']) && ($bsf_product_plugin['is_product_free'] === true || $bsf_product_plugin['is_product_free'] === 'true'))
								$bsf_free_products[] = $bsf_product_plugin;
						}
					}
				endif;
			}
		}

		foreach($themes as $theme => $theme_data)
		{
			$data = wp_get_theme($theme);
			$theme_author = trim($data->display('Author', FALSE));
			if($theme_author === 'Brainstorm Force')
			{
				if(!empty($bsf_product_themes)) :
					foreach($bsf_product_themes as $key => $bsf_product_theme)
					{
						$bsf_template = $bsf_product_theme['template'];
						if($theme == $bsf_template)
						{
							if(isset($bsf_product_theme['is_product_free']) && ($bsf_product_theme['is_product_free'] === true || $bsf_product_theme['is_product_free'] === 'true'))
								$bsf_free_products[] = $bsf_product_theme;
						}
					}
				endif;
			}
		}

		return $bsf_free_products;
	}
}
// function to toggle licence from server
add_action( 'wp_ajax_bsf_update_client_license', 'bsf_server_update_client_license' );
add_action( 'wp_ajax_nopriv_bsf_update_client_license', 'bsf_server_update_client_license' );
if(!function_exists('bsf_server_update_client_license')) {
	function bsf_server_update_client_license() {
		if(isset($_SERVER['HTTP_ORIGIN'])){
			header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
			header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
			header('Access-Control-Max-Age: 1000');
			header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
		}

		$product_id = (isset($_POST['product_id'])) ? $_POST['product_id'] : '';
		$product_type = (isset($_POST['product_type'])) ? $_POST['product_type'] : '';
		$purchase_code = (isset($_POST['purchase_code'])) ? $_POST['purchase_code'] : '';
		$useremail = (isset($_POST['user_email'])) ? $_POST['user_email'] : '';
		$userid = $useremail;
		$process = (isset($_POST['process'])) ? $_POST['process'] : '';
		$site_url = (isset($_POST['site_url'])) ? $_POST['site_url'] : '';
		$status = (isset($_POST['status'])) ? $_POST['status'] : '';

		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();

		if(!empty($brainstrom_products)) {
			if((isset($brainstrom_products[$product_type.'s'])) && (!empty($brainstrom_products[$product_type.'s']))) {
				if(isset($brainstrom_products[$product_type.'s'][$product_id])) {
					$brainstrom_products[$product_type.'s'][$product_id]['status'] = $status;
					if(empty($brainstrom_products[$product_type.'s'][$product_id]['purchase_key']))
						$brainstrom_products[$product_type.'s'][$product_id]['purchase_key'] = $purchase_code;
					update_option('brainstrom_products', $brainstrom_products);
					echo true;
					die();
				}
			}
		}
		echo false;
		die();
	}
}
// delete bundled products after switch theme
add_action('switch_theme', 'bsf_theme_deactivation');
if(!function_exists('bsf_theme_deactivation')) {
	function bsf_theme_deactivation() {
		delete_option( 'brainstrom_bundled_products' );
		delete_site_transient( 'bsf_get_bundled_products' );

		update_option( 'bsf_force_check_extensions', false );
	}
}
// check custom css and js
/*add_action('wp_footer', 'bsf_custom_js');
if(!function_exists('bsf_custom_js')) {
	function bsf_custom_js() {
		$bsf_settings = get_option('bsf_settings');
		if(isset($bsf_settings['custom_js']) && trim($bsf_settings['custom_js']) !== '') {
			echo '<script type="text/javascript">
				'.stripslashes($bsf_settings['custom_js']).'
			</script>';
		}
	}
}
add_action('wp_head', 'bsf_custom_css');
if(!function_exists('bsf_custom_css')) {
	function bsf_custom_css() {
		$bsf_settings = get_option('bsf_settings');
		if(isset($bsf_settings['custom_css']) && trim($bsf_settings['custom_css']) !== '') {
			echo '<style>
				'.stripslashes($bsf_settings['custom_css']).'
			</style>';
		}
	}
}*/
if(!function_exists('bsf_get_free_menu_position')) {
	function bsf_get_free_menu_position($start, $increment = 0.3) {
		foreach ($GLOBALS['menu'] as $key => $menu) {
			$menus_positions[] = $key;
		}

		if (!in_array($start, $menus_positions)) return $start;

		/* the position is already reserved find the closet one */
		while (in_array($start, $menus_positions)) {
			$start += $increment;
		}
		return $start;
	}
}
if(!function_exists('bsf_get_option')) {
	function bsf_get_option($request = false) {
		$bsf_options = get_option('bsf_options');
		if(!$request)
			return $bsf_options;
		else
			return (isset($bsf_options[$request])) ? $bsf_options[$request] : false;
	}
}
if(!function_exists('bsf_update_option')) {
	function bsf_update_option($request, $value) {
		$bsf_options = get_option('bsf_options');
		$bsf_options[$request] = $value;
		return update_option('bsf_options', $bsf_options);
	}
}
if(!function_exists('bsf_product_status')) {
	function bsf_product_status($id) {
		$brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array();
		if(empty($brainstrom_products))
			return false;

		if(!empty($brainstrom_products)) :
			$bsf_product_plugins = (isset($brainstrom_products['plugins'])) ? $brainstrom_products['plugins'] : array();
			$bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array();
		endif;

		$mix = array();
		$mix = array_merge($bsf_product_plugins, $bsf_product_themes);
		if(empty($mix))
			return false;

		foreach($mix as $key => $product) :
			if(!isset($product['id']))
				continue;
			if($product['id'] === $id) {
				if(isset($product['status']) && $product['status'] === 'registered')
					return true;
				else
					return false;
				break;
			}
		endforeach;
		return false;
	}
}
add_action( 'wp_ajax_bsf_upgrade', 'bsf_upgrade_callback' );
add_action( 'wp_ajax_nopriv_bsf_upgrade', 'bsf_upgrade_callback' );
if(!function_exists('bsf_upgrade_callback')) {
	function bsf_upgrade_callback () {
		$product_id = $_POST['product_id'];
		$bundled = $_POST['bundled'];
		$bundled = (isset($bundled) && $bundled) ? $_POST['bundled_id'] : false;

		global $ULT_UPGRADE_AJAX;
		$ULT_UPGRADE_AJAX = true;

		$response = upgrade_bsf_product($product_id, $bundled);

		if(isset($response['status']) && $response['status']) {
			echo '|bsf-product-upgraded|';
		} else {
			echo $response;
		}

		$ULT_UPGRADE_AJAX = false;

		die();
	}
}
// to sort array of objects
if(!function_exists('bsf_sort')) {
    function bsf_sort($a, $b)
    {
        return @strcmp(strtolower($a->short_name), strtolower($b->short_name));
    }
}
// admin footer
add_action('admin_footer', 'bsf_admin_footer');
if(!function_exists('bsf_admin_footer')){
	function bsf_admin_footer() {
		global $bsf_section_menu;
		if(!is_array($bsf_section_menu) && !empty($bsf_section_menu))
			return false;
		$json = json_encode($bsf_section_menu);
		if($json === 'null')
			return false;
		?>
		<script type='text/javascript'>
		(function($){
			$(document).ready(function(){
				var section_menu = '<?php echo $json ?>';
				var smenu = jQuery.parseJSON(section_menu);
				$.each(smenu, function(i,section){
					$('a[href$="'+section.menu+'"]').parent().addClass('bsf-menu-separator');
					if(typeof section.is_down_arrow !== 'undefined') {
						if(section.is_down_arrow === true || section.is_down_arrow === 'true') {
							$('a[href$="'+section.menu+'"]').parent().addClass('bsf-menu-arrow-down');
						}
					}
				});
			});
		})(jQuery);
		</script>

		<style type="text/css">
			.bsf-menu-separator {
				margin-bottom: 5px !important;
				border-bottom: 1px solid rgba(0, 0, 0, 0.1) !important;
				padding-bottom: 5px !important;
				box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) !important;
			}
			.bsf-menu-arrow-down {
				position: relative;
			}
			.bsf-menu-arrow-down a:after {
				content: "\f140";
			    font-family: 'dashicons';
			    display: block;
			    float: right;
			    width: 19px;
			    height: 15px;
			    font-size: 22px;
			    line-height: 15px;
			    text-align: center;
			    color: #bbb;
			    opacity: 0.30;
			}
		</style>
		<?php
	}
}
?>