<?php


if (isset($_GET['activated']) && is_admin()) {
	set_transient( '_welcome_screen_activation_redirect', true, 30 );
}

add_action( 'admin_init', 'welcome_screen_do_activation_redirect' );
function welcome_screen_do_activation_redirect() {
  // Bail if no activation redirect
    if ( ! get_transient( '_welcome_screen_activation_redirect' ) ) {
    return;
  }

  // Delete the redirect transient
  delete_transient( '_welcome_screen_activation_redirect' );

  // Bail if activating from network, or bulk
  if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
    return;
  }

  // Redirect to bbPress about page
  wp_safe_redirect( add_query_arg( array( 'page' => 'welcome-screen-about' ), admin_url( 'themes.php' ) ) );

}

add_action('admin_menu', 'welcome_screen_pages');

function welcome_screen_pages() {
	add_theme_page(
		'Welcome To Welcome i-one',
		'About i-one',
		'read',
		'welcome-screen-about',
		'welcome_screen_content',
		'dashicons-awards', 
		6 		
	);
}

function welcome_screen_content() {
	
	include get_template_directory() . '/inc/theme-welcome/tw-content.php';
	include get_template_directory() . '/inc/theme-welcome/tw-functions.php';	
	
	$logo_url = get_template_directory_uri() . '/inc/theme-welcome/ideal-page-settings.png';
	$img_url = get_template_directory_uri() . '/inc/theme-welcome/images/';
	$active_tab = 'ione_about';
	
	/* Urls */
	$reviewURL = esc_url('//wordpress.org/support/theme/i-one/reviews/?filter=5');
	$goPremiumURL = esc_url('//templatesnext.org/ispirit/landing/');
	$videoguide = esc_url('//www.templatesnext.in/i-one-documentation/');
	$supportforum = esc_url('//templatesnext.in/forum/'); 
	$toolkit = esc_url('//www.templatesnext.org/icreate/templatesnext-toolkit/');
	$fb_page = esc_url('//www.facebook.com/templatesnext/');
	$pb_tutorial = esc_url('https://siteorigin.com/page-builder/documentation/');


	$ocdi_buttont = "";
	if ( class_exists('OCDI_Plugin') ) {
		$ocdi_buttont = "button-enabled";
	} else
	{
		$ocdi_buttont = "button-disabled";
	} 	
	$details_theme = wp_get_theme();
	$name_version = $details_theme->get( 'Name' ) . " - " . $details_theme->get( 'Version' );
  	?>
  	<div class="wrapp">
        <div class="nx-info-wrap-2 welcome-panel">
        	
        	<div class="nx-info-wrap">
            	
                <div class="nx-welcome"><?php _e( 'Welcome To ', 'i-one' ); echo $name_version; ?></div>
                <div class="tx-wspace-24"></div>
                <div class="txo-info-desc">
                    <p>
						<span class="welcome-msg"><?php esc_html_e( 'Congratulations! You are about to use one of the most flexible WordPress theme. You can use it as :', 'i-one' ); ?></span>
                        <ul class="ione-usage">
                        	<li><?php esc_html_e( 'Blog : Multiple blog layouts.', 'i-one' ); ?></li>
                        	<li><?php esc_html_e( 'WooCommerce : Supports WooCommerce with product search and main nav live cart.', 'i-one' ); ?></li> 
                        	<li><?php esc_html_e( 'Personal or Business : Custom page options to suit any layout, any page builder. Supports Elementor, Brizy, SiteOrigin Page Builder, Divi, Visual Composer, etc.', 'i-one' ); ?></li>                                                        
                        </ul>
                    </p>
                    <div class="tx-wspace-24"></div>
                    
                    <a class="button button-primary button-hero" href="<?php echo $reviewURL; ?>">
                    <?php esc_html_e( 'Post Your Review', 'i-one' ); ?>
                    </a>  
                    <a class="button button-primary button-hero" href="<?php echo $goPremiumURL; ?>">
                    	<?php esc_html_e( 'Go Premium', 'i-one' ); ?>
                    </a>  
                </div>
                <div class="tx-wspace-12">
                </div>
                <div class="nx-admin-row">
                	<div class="tw-info-wrap" style="display: block; float: left; width: 82%;">
                        <h3 style="margin-bottom: 12px;">Ideal Page Settings For Page Builder Layouts</h3>
                        <div>
                            <img src="<?php echo $logo_url; ?>" height="" width="100%" alt="Ideal Page Settings For Page Builders">
                        </div>                    
                    </div>
                	<div style="display: block; float: right; width: 16%;">
                	<div class="one-one-col">
                    	<a href="<?php echo $videoguide; ?>" target="_blank">
                            <div class="nx-dash"><span class="dashicons dashicons-video-alt2"></span></div>
                            <h3 class="tx-admin-link"><?php _e( 'Documentation', 'i-one' ); ?></h3>
                        </a>
                    </div>
                	<div class="one-one-col">
                    	<a href="<?php echo $supportforum; ?>" target="_blank">
                            <div class="nx-dash"><span class="dashicons dashicons-format-chat"></span></div>
                            <h3 class="tx-admin-link"><?php _e( 'Support Forum', 'i-one' ); ?></h3>
                        </a>
                    </div>
                	<div class="one-one-col">
                    	<a href="<?php echo $fb_page; ?>" target="_blank">
                            <div class="nx-dash"><span class="dashicons dashicons-facebook-alt"></span></div>
                            <h3 class="tx-admin-link"><?php _e( 'Community', 'i-one' ); ?></h3>
                        </a>
                    </div>                                                            
                </div>
                <div class="tx-wspace-24"></div>
                <?php
					if( isset( $_GET[ 'tab' ] ) ) {
						$active_tab = $_GET[ 'tab' ];
					}
				?>
                <h2 class="nav-tab-wrapper">
                    <a href="?page=welcome-screen-about&tab=ione_about" class="nav-tab <?php echo $active_tab == 'ione_about' ? 'nav-tab-active' : ''; ?>">
                   		<?php _e( 'Setting Up i-one', 'i-one' ); ?>
                    </a>
                    <!--
                    <a href="?page=welcome-screen-about&tab=ione_plugins" class="nav-tab <?php echo $active_tab == 'ione_plugins' ? 'nav-tab-active' : ''; ?> nx-kick">
                    	<?php _e( 'Plugins', 'i-one' ); ?>
                    </a>
                    <a href="?page=welcome-screen-about&tab=ione_faq" class="nav-tab <?php echo $active_tab == 'ione_faq' ? 'nav-tab-active' : ''; ?> nx-plug">
                    	<?php _e( 'FAQs/Support', 'i-one' ); ?>
                    </a>
                    -->
                </h2>
                
                <?php
					if( $active_tab == 'ione_about' )
					{
				?> 
                	<div class="nx-tab-content">
                		<p>&nbsp;</p>
                        <ul class="nx-welcome">
  							<?php
									echo '<li>';
									echo '<h3>';
									printf( esc_html__( 'Upload Logos', 'i-one' ));
									echo '</h3>';
									printf( esc_html__( 'Start with uploading your logos', 'i-one' ) );
									echo '<div class="nx-customizer-link">';
									printf( __( '<a href="%scustomize.php?autofocus[section]=title_tagline" target="_blank">Customizer Option</a>', 'i-one' ), admin_url() );
									echo '</div>';								
									echo '</li>';

									echo '<li>';
									echo '<h3>';
									printf( esc_html__( 'Set Theme Color', 'i-one' ));
									echo '</h3>';
									printf( esc_html__( 'Change theme color', 'i-one' ) );
									echo '<div class="nx-customizer-link">';
									printf( __( '<a href="%scustomize.php?autofocus[section]=colors" target="_blank">Customizer Option</a>', 'i-one' ), admin_url() );
									echo '</div>';								
									echo '</li>';

									echo '<li>';
									echo '<h3>';
									printf( esc_html__( 'Email And Phone', 'i-one' ));
									echo '</h3>';
									printf( esc_html__( 'Add your phone and email or empty the fields to remove them', 'i-one' ) );
									echo '<div class="nx-customizer-link">';
									printf( __( '<a href="%scustomize.php?autofocus[section]=nxphoneandmail" target="_blank">Customizer Option</a>', 'i-one' ), admin_url() );
									echo '</div>';								
									echo '</li>';

									echo '<li>';
									echo '<h3>';
									printf( esc_html__( 'Add Social Media Links', 'i-one' ));
									echo '</h3>';
									printf( esc_html__( 'Add social media links or empty the fields to remove the icons', 'i-one' ) );
									echo '<div class="nx-customizer-link">';
									printf( __( '<a href="%scustomize.php?autofocus[section]=nxsocial" target="_blank">Customizer Option</a>', 'i-one' ), admin_url() );
									echo '</div>';								
									echo '</li>';

									echo '<li>';
									echo '<h3>';
									printf( esc_html__( 'Turn ON/OFF Preloader', 'i-one' ));
									echo '</h3>';
									printf( esc_html__( 'Turn on or off page preloader, by default it is on', 'i-one' ) );
									echo '<div class="nx-customizer-link">';
									printf( __( '<a href="%scustomize.php?autofocus[section]=layout" target="_blank">Customizer Option</a>', 'i-one' ), admin_url() );
									echo '</div>';								
									echo '</li>';
									
									echo '<li>';
									echo '<h3>';
									printf( esc_html__( 'Header Customization', 'i-one' ));
									echo '</h3>';
									printf( esc_html__( 'Customize header background, fonts, etc', 'i-one' ) );
									echo '<div class="nx-customizer-link">';
									printf( __( '<a href="%scustomize.php?autofocus[section]=customheader" target="_blank">Customizer Option</a>', 'i-one' ), admin_url() );
									echo '</div>';								
									echo '</li>';									

									echo '<li>';
									echo '<h3>';
									printf( esc_html__( 'Default Home Page Custumization', 'i-one' ));
									echo '</h3>';
									printf( esc_html__( 'Customize your default home page including home header and slider appearance.', 'i-one' ) );
									echo '<div class="nx-customizer-link">';
									printf( __( '<a href="%scustomize.php?autofocus[section]=static_front_page" target="_blank">Customizer Option</a>', 'i-one' ), admin_url() );
									echo '</div>';								
									echo '</li>';
									
									// delete
									echo '<li>';
									echo '<h3>';
									printf( esc_html__( 'Default Home Image/Video Header Options', 'i-one' ));
									echo '</h3>';
									printf( esc_html__( 'Edit the defult home page Video/Image header.', 'i-one' ) );
									echo '<div class="nx-customizer-link">';
									printf( __( '<a href="%scustomize.php?autofocus[section]=header_image" target="_blank">Customizer Option</a>', 'i-one' ), admin_url() );
									echo '</div>';								
									echo '</li>';

									echo '<li>';
									echo '<h3>';
									printf( esc_html__( 'Set Fonts', 'i-one' ));
									echo '</h3>';
									printf( esc_html__( 'Choose your fonts', 'i-one' ) );
									echo '<div class="nx-customizer-link">';
									printf( __( '<a href="%scustomize.php?autofocus[section]=fonts" target="_blank">Customizer Option</a>', 'i-one' ), admin_url() );
									echo '</div>';								
									echo '</li>';
									
									echo '<li>';
									echo '<h3>';
									printf( esc_html__( 'Turn ON/OFF Maintenance/Coming soon mode', 'i-one' ));
									echo '</h3>';
									printf( esc_html__( 'I-ONE comes with inbuilt maintenance/cooming soon mode. ', 'i-one' ) );
									echo '<div class="nx-customizer-link">';
									printf( __( '<a href="%scustomize.php?autofocus[section]=mmode" target="_blank">Customizer Option</a>', 'i-one' ), admin_url() );
									echo '</div>';								
									echo '</li>';									
                            ?>
                        </ul>                                                                        
        			</div>
				<?php		
					} elseif ( $active_tab == 'ione_plugins' )
					{
				?>     
                	<div class="nx-tab-content"> 
                		<p>&nbsp;</p>
                        <ol>
							<?php
			
								foreach ($tx_plugins as $plugin) {
									
									$pluginLocation = rawurlencode($plugin['slug'].'/'.$plugin['pluginfile']);
									$pluginLink = ione_plugin_activation( $pluginLocation, $plugin['slug'], $plugin['pluginfile'] );
									$nonce_install = ione_plugin_install($plugin['slug']);
															
									
									echo '<li><b>'.$plugin['name'].'</b><br />';
									echo $plugin['desc'].'<br />';
									echo _e( 'Plugin URL : ', 'i-one' ).'<a href="'.$plugin['pluginurl'].'" target="_blank">'.$plugin['pluginurl'].'</a><br />';
									if(!empty($plugin['tutorial']))
									{
										echo _e( 'Tutorial : ', 'i-one' ).'<a href="'.$plugin['tutorial'].'" target="_blank">'.$plugin['tutorial'].'</a><br />';   
									}
									
									$pluginTitle = $plugin['title'];
									if ( is_plugin_active( $plugin['slug'].'/'.$plugin['pluginfile'] ) ) {
										echo '<a href="#" class="button disabled">' . __( 'Plugin installed and active', 'i-one' ) . '</a>';  
									} elseif( ione_is_plugin_installed($pluginTitle) == false )
									{
										echo '<a data-slug="' . $plugin['slug'] . '" data-active-lebel="' . __( 'Installing...', 'i-one' ) . '" class="install-now button" href="' . esc_url( $nonce_install ) . '" data-name="' . $plugin['slug'] . '" aria-label="Install ' . $plugin['slug'] . '">' . __( 'Install and activate', 'i-one' ) . '</a>';
									} else
									{
										echo '<a class="button activate-now button-primary" data-active-lebel="' . __( 'Activating...', 'i-one' ) . '" data-slug="' . $plugin['slug'] . '" href="' . esc_url( $pluginLink ) . '" aria-label="Activate ' . $plugin['slug'] . '">Activate</a>';
									}
									
									echo '</li>';
									
								}
                            ?>                    
                        </ol>
        			</div>       
                        
				<?php	
					} elseif ( $active_tab == 'ione_faq' )
					{
				?>     
                	<div class="nx-tab-content"> 
                		<p>&nbsp;</p>
                        <?php
							foreach ($tx_faqs as $faq) {
								echo '<b>'._e( 'Q. ', 'i-one' ).$faq['question'].'</b><br />';
								echo _e( 'A. ', 'i-one' ).$faq['answeer'].'<br /><br />';									   
							}
                        ?>                    
                        
        			</div>      
                        
				<?php	
					}
				?>
  
                <div class="tx-wspace-24"></div><div class="tx-wspace-24"></div>    
 	
            </div>

                <div id="dashboard_right_now" class="postbox" style="display: block; float: none; width: 100%; max-width: 320px; margin: 16px;">
                    <h2 class="hndle nxw-title" style="padding: 12px 24px;"><span><?php echo $review_pop['title']; ?></span></h2>
                    <div class="inside">
                        <div class="main" style="padding: 24px;">
							<?php echo $review_pop['desc']; ?>
                    		<a class="button button-primary button-hero" target="_blank" href="<?php echo $reviewURL; ?>">
                            	<?php echo $review_pop['link']; ?>
                            </a> 
                            <?php echo $review_pop['conclusion']; ?>
                        </div>
                    </div>
                </div>   

            <div class="tx-wspace"></div>
        
            
            
        </div>
        
  	</div>
  
  	<?php
}

add_action( 'admin_head', 'welcome_screen_remove_menus' );
function welcome_screen_remove_menus() {
    remove_submenu_page( 'index.php', 'welcome-screen-about' );
}


// Add Stylesheet
add_action( 'admin_enqueue_scripts', 'ione_welcome_scripts' );
function ione_welcome_scripts() {
	wp_enqueue_style( 'nx-welcome-style', get_template_directory_uri() . '/inc/theme-welcome/css/nx-welcome.css', array(), '1.01' );
	wp_enqueue_script( 'nx-welcome-script', get_template_directory_uri() . '/inc/theme-welcome/js/nx-welcome.js' );
}
