<?php
/*
Plugin Name: Netbase Framework
Plugin URI: http://netbaseteam.com/
Description: Portfolio Plugin for NBCORE theme.
Version: 1.0.0
Author: NBTeam
Author URI: http://themeforest.net/user/netbaseteam?ref=pencidesign
*/

define('NB_FW_PATH', plugin_dir_path(__FILE__));
define('NB_FW_NAME', plugin_basename(__FILE__));

require_once(NB_FW_PATH . 'metaboxes/metaboxes.php');
require_once(NB_FW_PATH . 'widgets/widget.php');
require_once(NB_FW_PATH . 'inc/custom-template-tags.php');
NBT_Widget::init();
class NBT_Panel
{

    protected static $initialized = false;

    public static function init()
    {
        if (self::$initialized) {
            return;
        }
		
		add_filter( 'pt-ocdi/import_files', array(__CLASS__, 'ocdi_import_files') );
        add_action( 'pt-ocdi/after_import', array(__CLASS__, 'after_import') );
    }

    public static function enqueue_scripts()
    {
        global $pagenow;

        if ($pagenow == 'admin.php') {
            wp_enqueue_style('nb-admin-panel', NB_FW_PATH_uri() . '/assets/netbase/css/admin/admin-panel.min.css');
        }
    }

    public static function register_menus()
    {
        add_menu_page(
            esc_html__('NB BeautyCare', 'core-wp'),
            esc_html__('NB BeautyCare', 'core-wp'),
            'manage_options', 'beautycare-panel',
            array(__CLASS__, 'welcome_page'),
            'dashicons-welcome-widgets-menus',
            2
        );

        add_submenu_page(
            'beautycare-panel',
            '',
            'Sample Data',
            'manage_options',
            'themes.php?page=pt-one-click-demo-import'
        );

        add_submenu_page(
            'beautycare-panel',
            '',
            'Theme options',
            'manage_options',
            'customize.php'
        );
    }

    public static function welcome_page()
    {
        $plugins = NBT_Core::$plugins;
        ?>
        <div class="nb-panel">
            <div class="wrap nb-wrap">
                <?php require_once(NB_FW_PATH . 'pages/intro.php'); ?>
                <div class="welcome-panel">
                    <p class="intro-text"><?php esc_html_e('First you need to install some of our theme\'s plugin. Some plugins will be required and some will not, but we recommend you to install all of our plugins to make NB BeautyCare theme run smoothly', 'core-wp') ?></p>
                    <a href="<?php admin_url('themes.php?page=tgmpa-install-plugins'); ?>"
                       class="button button-primary button-hero">
                        <?php esc_html_e('Install Plugins', 'core-wp'); ?>
                    </a>
                </div>

                <div id="nb-plugins" class="tab-pane" role="tabpanel">
                    <?php foreach ($plugins as $plugin): ?>
                        <?php $plugin['thumb']; ?>
                        <div class="item-wrap">
                            <div class="item">
                                <div class="plugin-screenshot">
                                    <img src="<?php echo esc_attr($plugin['thumb']) ?>" alt="">
                                </div>
                                <div class="plugin-meta">
                                    <h3 class="plugin-name"><?php echo esc_html($plugin['name']) ?></h3>
                                    <span class="plugin-version"><?php echo esc_html($plugin['version']) ?></span>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php
    }

    public static function beautycare_panel_support()
    {
        ?>
        <div class="nb-panel">
            <div class="wrap nb-wrap">
                <?php require_once(NB_FW_PATH . '/netbase-core/panel/pages/intro.php'); ?>
                <?php require_once(NB_FW_PATH . '/netbase-core/panel/pages/support.php'); ?>
            </div>
        </div>
        <?php
    }

    public static function beautycare_panel_plugins()
    {
        $plugins = NBT_Core::$plugins;
        ?>
        <div class="nb-panel">
            <div class="wrap nb-wrap">
                <?php require_once(NB_FW_PATH . '/netbase-core/panel/pages/intro.php'); ?>
                <div id="nb-plugins" class="tab-pane" role="tabpanel">
                    <?php foreach ($plugins as $plugin): ?>
                        <?php $plugin['thumb']; ?>
                        <div class="item">
                            <div class="plugin-screenshot">
                                <img src="<?php echo esc_attr($plugin['thumb']) ?>" alt="">
                            </div>
                            <div class="plugin-meta">
                                <h3><?php echo esc_html($plugin['name']) ?></h3>
                                <a class="plugin-action button button-primary">install</a>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php
    }

    public static function ocdi_import_files() {
        return array(
            array(
                'import_file_name'           => 'Demo 1',
                'local_import_file'            => NB_FW_PATH . 'ocdi/demo1/content.xml',
                'local_import_widget_file'     => NB_FW_PATH . 'ocdi/demo1/widgets.wie',
                'local_import_customizer_file' => NB_FW_PATH . 'ocdi/demo1/customizer.dat',
                'import_preview_image_url'     => plugins_url() . '/nb-fw/ocdi/demo1/screenshot.png',
            ),
            array(
                'import_file_name'           => 'Demo 2',
                'local_import_file'            => NB_FW_PATH . 'ocdi/demo2/content.xml',
                'local_import_widget_file'     => NB_FW_PATH . 'ocdi/demo2/widgets.wie',
                'local_import_customizer_file' => NB_FW_PATH . 'ocdi/demo2/customizer.dat',
                'import_preview_image_url'     => plugins_url() . '/nb-fw/ocdi/demo2/screenshot.png',
            ),
            array(
                'import_file_name'           => 'Demo 3',
                'local_import_file'            => NB_FW_PATH . 'ocdi/demo3/content.xml',
                'local_import_widget_file'     => NB_FW_PATH . 'ocdi/demo3/widgets.wie',
                'local_import_customizer_file' => NB_FW_PATH . 'ocdi/demo3/customizer.dat',
                'import_preview_image_url'     => plugins_url() . '/nb-fw/ocdi/demo3/screenshot.png',
            ),
        );
    }

    public static function after_import( $selected_import ) {

        if ( 'Demo 1' === $selected_import['import_file_name'] ) {
            $page = get_page_by_title( 'Home');
            if ( isset( $page->ID ) ) {
                update_option( 'page_on_front', $page->ID );
                update_option( 'show_on_front', 'page' );
            }
            $primary_menu = get_term_by('name', 'Main Menu', 'nav_menu');
            set_theme_mod( 'nav_menu_locations', array(
                    'primary' => $primary_menu->term_id,
                )
            );

            if ( class_exists( 'RevSlider' ) ) {
                $slider_array = array(
                    NB_FW_PATH .'ocdi/demo1/handmade1.zip'
                );

                $slider = new RevSlider();

                foreach($slider_array as $filepath){
                    $slider->importSliderFromPost(true,true,$filepath);
                }

                echo 'Slider processed';
            }
        } elseif ( 'Demo 2' === $selected_import['import_file_name'] ) {
            $page = get_page_by_title( 'Home 2');
            if ( isset( $page->ID ) ) {
                update_option( 'page_on_front', $page->ID );
                update_option( 'show_on_front', 'page' );
            }
            $primary_menu = get_term_by('name', 'Main Menu', 'nav_menu');
            set_theme_mod( 'nav_menu_locations', array(
                    'primary' => $primary_menu->term_id,
                )
            );

            if ( class_exists( 'RevSlider' ) ) {
                $slider_array = array(
                    NB_FW_PATH .'ocdi/demo2/handmade2.zip'
                );

                $slider = new RevSlider();

                foreach($slider_array as $filepath){
                    $slider->importSliderFromPost(true,true,$filepath);
                }

                echo 'Slider processed';
            }
        } elseif ( 'Demo 3' === $selected_import['import_file_name'] ) {
            $page = get_page_by_title( 'Home 3');
            if ( isset( $page->ID ) ) {
                update_option( 'page_on_front', $page->ID );
                update_option( 'show_on_front', 'page' );
            }
            $primary_menu = get_term_by('name', 'Main Menu', 'nav_menu');
            set_theme_mod( 'nav_menu_locations', array(
                    'primary' => $primary_menu->term_id,
                )
            );

            if ( class_exists( 'RevSlider' ) ) {
                $slider_array = array(
                    NB_FW_PATH .'ocdi/demo3/handmade3.zip'
                );

                $slider = new RevSlider();

                foreach($slider_array as $filepath){
                    $slider->importSliderFromPost(true,true,$filepath);
                }

                echo 'Slider processed';
            }
        }
    }
}
NBT_Panel::init();
