<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php 

class Beruco_Admin_Class {
	
	private static $_instance = null;

	public function __construct() {
		add_action( 'admin_menu', array( $this, 'beruco_admin_menu' ) );		
		add_action( 'admin_menu', array( $this, 'change_admin_menu_name' ), 99 );
		add_action( 'admin_enqueue_scripts', array( $this, 'beruco_framework_admin_scripts' ), 10 );
		
		//Call plugin page
		$this->beruco_plugin_menu_connect();
	}
	
	public static function beruco_framework_admin_scripts(){
		if( isset( $_GET['page'] ) && ( $_GET['page'] == 'beruco-welcome' || $_GET['page'] == 'beruco-options' || $_GET['page'] == 'beruco-sidebars' || $_GET['page'] == 'beruco-fonts' || $_GET['page'] == 'beruco-plugins' || $_GET['page'] == 'beruco-importer' || $_GET['page'] == 'beruco-verification' ) ){
			wp_enqueue_style( 'beruco-admin', get_template_directory_uri() . '/admin/assets/css/beruco-admin-page.css', array(), '1.0', 'all' );
		}
		if( isset( $_GET['page'] ) && $_GET['page'] == 'beruco-welcome' ) {
			wp_enqueue_style( 'owl-carousel', get_template_directory_uri() . '/assets/css/owl-carousel.min.css', array(), '2.3.4', 'all' );
			wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/assets/js/owl.carousel.min.js', array( 'jquery' ), '2.3.4', true );
		}
		wp_enqueue_style( 'beruco-admin-common', get_template_directory_uri() . '/admin/assets/css/beruco-admin-common.css', array(), '1.0', 'all' );	
		wp_enqueue_script( 'beruco-admin-js', esc_url( get_template_directory_uri() . '/admin/assets/js/beruco-admin-script.js' ), array( 'jquery' ), '1.0' );
		
		if( isset( $_GET['page'] ) && $_GET['page'] == 'beruco-plugins' ){
			require_once BERUCO_DIR . '/admin/theme-plugins/tgm-init.php';			
			$plugins = TGM_Plugin_Activation::$instance->plugins;
			$args = array( 'tgm_plugins' => $plugins );
			$admin_local_args = apply_filters( 'beruco_admin_local_js_args', $args );
			wp_localize_script('beruco-admin-js', 'beruco_admin_ajax_var', $admin_local_args );
		}
		
		if( isset( $_GET['page'] ) && $_GET['page'] == 'beruco-verification' ){
			$html = '<p><strong>This purchase code already registered with another domain</strong></p><p>Please go to your previous working environment and deactivate the purchase code to use it again ( WP dashboard -> Beruco -> Token Verification -> click on the button "Deactivate" ).</p>';
			$args = array( 'already_used' => $html );
			$admin_local_args = apply_filters( 'beruco_admin_local_js_args', $args );
			wp_localize_script('beruco-admin-js', 'beruco_admin_ajax_var', $admin_local_args );
		}
	}
	
	public static function beruco_admin_menu(){
		add_menu_page( 
			esc_html__( 'Beruco', 'beruco' ),
			esc_html__( 'Beruco', 'beruco' ),
			'manage_options',
			'beruco-welcome', 
			array( 'Beruco_Admin_Class', 'beruco_admin_page' ),
			get_template_directory_uri() . '/assets/images/brand-icon.png',
			6
		);
		add_submenu_page( 
			'beruco-welcome', 
			esc_html__( 'Token Verification', 'beruco' ),
			esc_html__( 'Token Verification', 'beruco' ), 
			'manage_options', 
			'beruco-verification', 
			array( 'Beruco_Admin_Class', 'beruco_verification_admin_page' )
		);
	}
	
	public static function change_admin_menu_name(){
		global $submenu;
		if(isset($submenu['beruco-welcome'])){
			$submenu['beruco-welcome'][0][0] = esc_html__( 'Welcome', 'beruco' );
		}
	}
	
	public static function beruco_admin_page(){
	
		$beruco_theme = wp_get_theme();
		
		?>
		<div class="beruco-settings-wrap">
			<div class="beruco-header-bar">
				<div class="beruco-header-left">
					<div class="beruco-admin-logo-inline">
						<img src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/brand-logo.png' ); ?>" alt="beruco-logo">
					</div><!-- .beruco-admin-logo-inline -->
					<h2 class="title"><?php esc_html_e( 'Beruco', 'beruco' ); ?><span class="beruco-version"><?php echo esc_html( $beruco_theme->get( 'Version' ) ); ?></span></h2>
				</div><!-- .beruco-header-left -->
				<div class="beruco-header-right">
					<a href="<?php echo esc_url( admin_url( 'admin.php?page=beruco-verification' ) ) ?>" class="button beruco-btn"><?php esc_html_e( 'Verify Token', 'beruco' ); ?></a>
				</div><!-- .beruco-header-right -->
			</div><!-- .beruco-header-bar -->
			
			<div class="beruco-settings-tabs">
				<div id="beruco-general" class="beruco-settings-tab beruco-elements-list active">
					<div class="container">
						<div class="row">
							<div class="col-8">
								<div class="row">
									<div class="col-6 mb-4">
										<div class="banner-img-wrap">
											<img class="beruco-preview-img img-fluid" src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/banner.png' ); ?>" alt="essential-addons-for-elementor-featured">
										</div>
									</div><!-- .col -->
									<div class="col-6 mb-4">
										<div class="media admin-box">
											<div class="admin-box-icon mr-3">
												<span class="dashicons dashicons-admin-generic"></span>								
											</div>
											<div class="media-body admin-box-info">
												<h3 class="admin-box-title"><?php esc_html_e( 'Requirements', 'beruco' ); ?></h3>
												<div class="admin-box-content">
												<?php
													$php_version = phpversion();
													$php_version_class = version_compare( $php_version, '8.0', '>=') ? ' success' : ' warning';
													$wp_version = get_bloginfo('version');
													$wp_version_class = version_compare( $wp_version, '6.0', '>=') ? ' success' : ' warning';
													
													ob_start();
													phpinfo(INFO_MODULES);
													$info = ob_get_contents();
													ob_end_clean();
													$info = stristr($info, 'Client API version');
													preg_match('/[1-9].[0-9].[1-9][0-9]/', $info, $match);
													$mysql_version = $match[0]; 
													$mysql_version_class = version_compare( $mysql_version, '8', '>=') ? ' success' : ' warning';
													
													$post_max_size = ini_get('post_max_size');
													$post_max = str_replace("M","",$post_max_size);
													$post_max_class = $post_max >= 10 ? ' success' : ' warning';
													
													$max_execution_time = ini_get('max_execution_time');
													$max_exe_class = $max_execution_time >= 300 ? ' success' : ' warning';
													
													$max_input_vars = ini_get('max_input_vars');
													$max_input_class = $max_input_vars >= 2000 ? ' success' : ' warning';
													
												?>
													<table class="beruco-admin-table no-spacing-table">
														<thead>
															<tr>
																<td><?php esc_html_e( 'Core', 'beruco' ); ?></td>
																<td><?php esc_html_e( 'Required', 'beruco' ); ?></td>
																<td><?php esc_html_e( 'Current', 'beruco' ); ?></td>
																<td><?php esc_html_e( 'Status', 'beruco' ); ?></td>
															</tr>
														</thead>
														<tbody>
															<tr>
																<td><?php esc_html_e( 'PHP', 'beruco' ); ?></td>
																<td>8.0</td>
																<td><?php echo esc_html( $php_version ); ?></td>
																<td class="text-center"><span class="requirement-icon <?php echo esc_attr( $php_version_class ); ?>"></span></td>
															</tr>
															<tr>
																<td><?php esc_html_e( 'MySQL', 'beruco' ); ?></td>
																<td>8.0</td>
																<td><?php echo esc_html( $mysql_version ); ?></td>
																<td class="text-center"><span class="requirement-icon <?php echo esc_attr( $mysql_version_class ); ?>"></span></td>
															</tr>
															<tr>
																<td><?php esc_html_e( 'WordPress', 'beruco' ); ?></td>
																<td>6.0</td>
																<td><?php echo esc_html( $wp_version ); ?></td>
																<td class="text-center"><span class="requirement-icon <?php echo esc_attr( $wp_version_class ); ?>"></span></td>
															</tr>															
															<tr>
																<td><?php esc_html_e( 'post_max_size', 'beruco' ); ?></td>
																<td>10M</td>
																<td><?php echo esc_html( $post_max_size ); ?></td>
																<td class="text-center"><span class="requirement-icon <?php echo esc_attr( $post_max_class ); ?>"></span></td>
															</tr>
															<tr>
																<td><?php esc_html_e( 'max_input_vars', 'beruco' ); ?></td>
																<td>2000</td>
																<td><?php echo esc_html( $max_input_vars ); ?></td>
																<td class="text-center"><span class="requirement-icon <?php echo esc_attr( $max_input_class ); ?>"></span></td>
															</tr>
															<tr>
																<td><?php esc_html_e( 'max_execution_time', 'beruco' ); ?></td>
																<td>300</td>
																<td><?php echo esc_html( $max_execution_time ); ?></td>
																<td class="text-center"><span class="requirement-icon <?php echo esc_attr( $max_exe_class ); ?>"></span></td>
															</tr>
														</tbody>
													</table>
												</div>
											</div>
										</div>
									</div><!-- .col -->
									<div class="col-6 mb-4">
										<div class="media admin-box">
											<div class="admin-box-icon mr-3">
												<span class="dashicons dashicons-media-document"></span>								
											</div>
											<div class="media-body admin-box-info">
												<h3 class="admin-box-title"><?php esc_html_e( 'Documention', 'beruco' ); ?></h3>
												<div class="admin-box-content">
													<?php esc_html_e( 'Get started by spending some time with the documentation to get familiar with Berucos. Build awesome websites for you or your clients with ease.', 'beruco' ); ?>
												</div>
												<a href="<?php echo esc_url( __( 'https://docs.zozothemes.com/beruco/', 'beruco' ) );?> " class="beruco-btn btn-default" target="__blank"><?php esc_html_e( 'Go Here', 'beruco' ); ?></a>
											</div>
										</div>
									</div><!-- .col -->
									<div class="col-6">
										<div class="media admin-box">
											<div class="admin-box-icon mr-3">
												<span class="dashicons dashicons-admin-users"></span>								
											</div>
											<div class="media-body admin-box-info">
												<h3 class="admin-box-title"><?php esc_html_e( 'Need Help?', 'beruco' ); ?></h3>
												<div class="admin-box-content">
													<?php esc_html_e( 'Stuck with something? Get help from the community on WordPress.org Forum initiate a live chat at Berucos website and get support.', 'beruco' ); ?>
												</div>
												<a href="<?php echo esc_url( __( 'https://zozothemes.ticksy.com/', 'beruco' ) );?>" class="beruco-btn btn-default" target="__blank"><?php esc_html_e( 'Get Support', 'beruco' ); ?></a>
											</div>
										</div>
									</div><!-- .col -->
									<div class="col-6 mb-4">
									    <div class="media admin-box">
									        <div class="admin-box-icon mr-3">
									            <span class="dashicons dashicons-video-alt3"></span>
									        </div>
									        <div class="media-body admin-box-info">
									            <h3 class="admin-box-title"><?php esc_html_e('Video Tutorials?', 'beruco'); ?></h3>
									            <div class="admin-box-content">
									                <?php esc_html_e('Get started by spending some time with the Video tutorials to get familiar with Beruco. Here is a full video tutorial to how to setup a theme.', 'beruco'); ?>
									            </div>
									            <a href="<?php echo esc_url( __('https://www.youtube.com/watch?v=Snlj8-ASlyk', 'beruco' ));?>" class="beruco-btn btn-default" target="__blank"><?php esc_html_e('Click Here', 'beruco'); ?></a>
									        </div>
									    </div>
									</div>

									<div class="col-12">								
										<div class="admin-box-slide-wrap text-center">	
											<?php										
												//Banner
											?>
										</div>
									</div><!-- .col -->
								</div><!-- .row -->
							</div><!-- .col -->
							<div class="col-4">
							<?php
								if( !class_exists( 'Zozothemes_API' ) ){
									require_once BERUCO_DIR . '/admin/class.zozo-api.php';
								}
								$zozo_api = new Zozothemes_API;
								$response = $zozo_api->get_response();
							?>
								<div class="admin-box">
									<div class="admin-box-info">
										<h3 class="admin-box-title"><?php esc_html_e( 'Live Updates', 'beruco' ); ?></h3>
										<div class="admin-box-pro text-center">
											
										</div>									
											<div class="full-logo-wrap"><img src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/brand.png' ); ?>" alt="beruco-logo"></div>
										
										<h3 class="admin-box-title my-4"><?php esc_html_e( 'Featured Themes', 'beruco' ); ?></h3>
										<div class="admin-box-slide-wrap">
										<?php	
										if( !is_wp_error( $response ) ){										
											if( !empty( $response ) && isset( $response['products'] ) ) {
												echo '<div class="owl-carousel">';
												foreach( $response['products'] as $key => $product ){
													echo '<a href="'. esc_url( $product['link'] ) .'" target="_blank"><img src="'. esc_url( $product['img'] ) .'" alt="'. esc_url( $product['alt'] ) .'"></a>';
												}
												echo '</div>';
											}
										}else{ ?>
											<p><?php esc_html_e( 'Featured products will show here..', 'beruco' ); ?></p>
										<?php
										}
										?>
										</div>
									</div>
								</div>
							</div>
						</div><!-- .row -->
					</div><!-- .container -->
				</div><!-- .beruco-settings-tab -->
			</div><!-- .beruco-settings-tabs -->
			
		</div><!-- .beruco-settings-wrap -->
		<?php
	}

	public static function beruco_verification_admin_page(){		
	
		$beruco_theme = wp_get_theme();		
	?>
		<div class="beruco-settings-wrap">
		
			<div class="beruco-header-bar">
				<div class="beruco-header-left">
					<div class="beruco-admin-logo-inline">
						<img src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/brand-logo.png' ); ?>" alt="beruco-logo">
					</div><!-- .beruco-admin-logo-inline -->
					<h2 class="title"><?php esc_html_e( 'Purchase Code Verification', 'beruco' ); ?><span class="beruco-version"><?php echo esc_html( $beruco_theme->get( 'Version' ) ); ?></span></h2>
				</div><!-- .beruco-header-left -->
				<div class="beruco-header-right">
					<a href="<?php echo esc_url( 'https://help.market.envato.com/hc/en-us/articles/202822600-Where-Is-My-Purchase-Code-' ); ?>" class="button beruco-btn"><?php esc_html_e( 'Get Purchase Code', 'beruco' ); ?></a>
				</div><!-- .beruco-header-right -->
			</div><!-- .beruco-header-bar -->
			
			<div class="beruco-inner-wrap">
				<div class="beruco-settings-tabs">
					<div id="beruco-general" class="beruco-settings-tab beruco-elements-list active">
						<div class="container">
							<?php 
								$verfied_stat = get_option('verified_purchase_status');
							?>
							<div class="zozo-envato-registration-form-wrap">
								<?php if( !$verfied_stat ): ?>
								<h2 class="text-center"><?php esc_html_e( "Activate your Licence", "beruco" ); ?></h2>
								<p class="text-center"><?php esc_html_e( "Welcome and thank you for Choosing Beruco Theme!
The Beruco theme needs to be activated to enable demo import installation and customer support service.", "beruco" ); ?></p>	
								<a href="<?php echo esc_url( 'https://help.market.envato.com/hc/en-us/articles/202822600-Where-Is-My-Purchase-Code-' ); ?>" target="_blank"><?php esc_html_e( "How to find purchase code?", "beruco" ); ?></a>
								<form id="zozo-envato-registration-form" class="zozo-envato-registration-form" method="post">
									<?php wp_nonce_field( 'beruco_theme_verify^%&^%', 'zozo_verify_nonce' ); ?>
									<div class="form-fields">
										<div class="zozo-input-group">
											<input type="text" name="zozo_registration_email" value="" placeholder="<?php esc_attr_e( 'Enter E-mail address', 'beruco' ); ?>">
											<input type="text" name="zozo_purchase_code" value="" placeholder="<?php esc_attr_e( 'Enter your theme purchase code', 'beruco' ); ?>">
										</div>
										<div class="submit-group">
											<input type="submit" name="submit" id="submit" class="button beruco-btn" value="<?php esc_attr_e( 'Activate', 'beruco' ); ?>" />
											<span class="process-loader"><img src="<?php echo esc_url( BERUCO_URI . '/admin/assets/images/loader.gif' ); ?>" alt="<?php esc_attr_e( 'Loader', 'beruco' ) ?>" /></span>
										</div>
									</div>	

									<div class="verfication-alert text-center"><span class="verfication-txt"></span></div>
									
								</form>
								<?php else: ?>
								<div class="theme-activated-wrap text-center">
									<h2><?php esc_html_e( 'Thank you!', 'beruco' ) ?></h2>
									<p><strong><?php esc_html_e( 'Your theme\'s license is activated successfully.', 'beruco' ) ?></strong></p>
								</div>
								<form id="zozo-envato-deactivation-form" class="zozo-envato-deactivation-form text-center" method="post">
									<?php wp_nonce_field( 'beruco_theme_deactivate^%&^%', 'zozo_deactivate_nonce' ); ?>
									<div class="submit-group">
										<input type="submit" name="submit" class="button beruco-btn" value="<?php esc_attr_e( 'Deactivate', 'beruco' ); ?>" />
										<span class="process-loader"><img src="<?php echo esc_url( BERUCO_URI . '/admin/assets/images/loader.gif' ); ?>" alt="<?php esc_attr_e( 'Loader', 'beruco' ) ?>" /></span>
									</div>
								</form>
								<?php endif; ?>
								
								<div class="registration-token-instruction">
									<p class="text-center"><strong><?php esc_html_e( '1 license = 1 domain = 1 website', 'beruco' ); ?></strong></p>
									<p class="text-center"><?php printf( '%1$s <a href="%2$s" target="_blank">%3$s</a>',
										esc_html__( 'You can always buy more licences for this product:', 'beruco' ),
										esc_url( 'https://themeforest.net/user/zozothemes/portfolio' ),
										esc_html__( 'ThemeForest ZOZOTHEMES', 'beruco' )
										); ?>
									</p>
									<p class="text-left notice-wrap"><span class="info-notice"><?php esc_html_e( 'Notice', 'beruco' ); ?></span><?php esc_html_e( 'If you are developing a website in the staging site means, While moving to the production site, please deactivate the license in staging and activate it in the Production site.', 'beruco' ); ?></p>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	<?php
	}
	
	public static function beruco_plugin_menu_connect(){
		require_once BERUCO_DIR . '/admin/class.token-verification.php';
		$verfied_stat = Zozo_Purchase_Code_Verification::check_theme_activated();
		if( !empty( $verfied_stat ) && !is_array( $verfied_stat ) ) {
			require_once BERUCO_DIR . '/admin/class.plugin-settings.php';	
		}
	}
	
	public static function beruco_theme_verification(){
		
		$nonce = isset( $_POST['zozo_verify_nonce'] ) ? sanitize_text_field( $_POST['zozo_verify_nonce'] ) : '';	  
		if ( ! wp_verify_nonce( $nonce, 'beruco_theme_verify^%&^%' ) )
			wp_die ( esc_html__( 'Busted', 'beruco' ) );
		
		if( isset( $_POST['zozo_registration_email'] ) && !empty( $_POST['zozo_purchase_code'] ) ){
			require_once BERUCO_DIR . '/admin/class.token-verification.php';
			$verfy_obj = new Zozo_Purchase_Code_Verification;
			$status = $verfy_obj->verify_token();
			wp_send_json($status);
		}
		
		wp_die('finished');
	}
	
	public static function beruco_theme_deactivate(){
			
		$nonce = isset( $_POST['zozo_deactivate_nonce'] ) ? sanitize_text_field( $_POST['zozo_deactivate_nonce'] ) : '';	  
		if ( ! wp_verify_nonce( $nonce, 'beruco_theme_deactivate^%&^%' ) )
			wp_die ( esc_html__( 'Busted', 'beruco' ) );
				
		require_once BERUCO_DIR . '/admin/class.token-verification.php';
		$verfy_obj = new Zozo_Purchase_Code_Verification;
		$status = $verfy_obj->deactivate_api_call();
		wp_send_json($status);
		
		wp_die('finished');
	}
	
	public static function get_instance() {
		if ( is_null( self::$_instance ) ) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}

} Beruco_Admin_Class::get_instance();

//Theme verification ajax functions
add_action( 'wp_ajax_beruco_theme_verify', array( 'Beruco_Admin_Class', 'beruco_theme_verification' ) );
add_action( 'wp_ajax_nopriv_beruco_theme_verify', array( 'Beruco_Admin_Class', 'beruco_theme_verification' )  );

//Theme deactivate
add_action( 'wp_ajax_beruco_theme_deactivate', array( 'Beruco_Admin_Class', 'beruco_theme_deactivate' ) );
add_action( 'wp_ajax_nopriv_beruco_theme_deactivate', array( 'Beruco_Admin_Class', 'beruco_theme_deactivate' )  );