/**
  * Rebuild every demo file
  */
 public function rebuild(ctImport $xmlImporter, ctNHP_Options $options)
 {
     //echo ctImport::getThemeOptionsPath();exit;
     //theme options
     if (file_put_contents(ctImport::getThemeOptionsPath(), $options->export()) === false) {
         throw new Exception("Cannot save file to: " . ctImport::getThemeOptionsPath());
     }
     $this->export(self::EXPORT_FILE);
     error_reporting(E_ERROR);
     require_once ABSPATH . 'wp-admin/includes/export.php';
     flush();
     ob_start();
     export_wp(array('content' => 'all'));
     $xml = ob_get_contents();
     ob_end_clean();
     file_put_contents(ctImport::getXmlPath(), $xml);
 }
 /**
  * Adds option
  * @return mixed
  */
 public static function addOptions($sections)
 {
     if (!file_exists(CT_THEME_SETTINGS_MAIN_DIR . '/demo')) {
         return $sections;
     }
     $rebuild = isset($_GET['ct_dev']);
     $html = '<div style="font-style: normal" class="import">';
     $html .= '<p>' . __('You can setup your Wordpre ss with just a single click!', 'ct_theme') . '</p>';
     $html .= apply_filters('ct_import_demo.recommends', '');
     $html .= '<div class="importDescription">';
     $html .= '<p style="color:red"><strong>' . __('Warning! Import content only on new Wordpress installation. Otherwise your current pages and posts may be lost!', 'ct_theme') . '</strong></p>';
     if (file_exists(CT_THEME_SETTINGS_MAIN_DIR . '/demo/wordpress.xml')) {
         if ($rebuild) {
             $html .= '<a href="#" data-action="ct-demo-rebuild" data-dir="" class="ct-demo-import button button-primary">' . __('REBUILD demo content', 'ct_theme') . '</a>&nbsp;&nbsp;';
         } else {
             $html .= '<a href="#" data-action="ct-demo-import" data-dir="" class="ct-demo-import button button-primary">' . __('import demo content', 'ct_theme') . '</a>&nbsp;&nbsp;';
         }
     }
     //check whether there is additional flavour
     $dirs = glob(CT_THEME_SETTINGS_MAIN_DIR . '/demo/*', GLOB_ONLYDIR);
     if (is_array($dirs)) {
         foreach ($dirs as $dir) {
             $dName = basename($dir);
             if ($rebuild) {
                 $html .= '<a href="#" data-action="ct-demo-rebuild" data-dir="' . $dName . '" class="ct-demo-import button button-primary">' . __('REBUILD demo content', 'ct_theme') . ': ' . $dName . '</a>&nbsp;&nbsp;';
             } else {
                 $html .= '<a href="#" data-action="ct-demo-import" data-dir="' . $dName . '" class="ct-demo-import button button-primary">' . __('import demo content', 'ct_theme') . ': ' . $dName . '</a>&nbsp;&nbsp;';
             }
         }
     }
     $html .= '</div>';
     $html .= '<div class="importLoader" style="display:none">';
     $html .= '<span style="position:relative;top:-28px;padding-right:20px"><strong>' . __('Importing ...', 'ct_theme') . '</strong></span><img src="' . CT_THEME_ADMIN_ASSETS_URI . '/images/import_loader.gif" alt="loading"/>';
     $html .= '</div>';
     $html .= '</div>';
     $section = array('icon' => NHP_OPTIONS_URL . 'img/glyphicons/glyphicons_181_download_alt.png', 'title' => __('1-Click Demo Import', 'ct_theme'), 'group' => __("General", 'ct_theme'), 'desc' => $html);
     $sections = ctNHP_Options::insertSectionAtIndex($sections, $section, 2);
     return $sections;
 }
 /**
  * Inits Option tree
  */
 public function initThemeOptions()
 {
     if (!class_exists('ctNHP_Options')) {
         self::getFilesLoader()->requireOnce(CT_THEME_LIB_DIR . '/createit/ctNHP_Options.class.php');
     }
     //load our theme options
     $dir = CT_THEME_SETTINGS_MAIN_DIR . '/options';
     //these variables are for being filled in theme
     $sections = array();
     //section structure
     $tabs = array();
     //additional, custom tabs
     $args = array();
     //options configuration
     //include because we use injected variables. Otherwise we could use ctFilesLoader::includeOnce
     include self::getFilesLoader()->getFilePath($dir . '/init.php');
     /** @var $order array */
     foreach ($order as $e) {
         include self::getFilesLoader()->getFilePath($dir . '/_' . $e . '.php');
     }
     //add options
     if ($s = apply_filters('ct_theme_loader.options.load', $sections)) {
         $sections = $s;
     }
     //lets initialize options
     global $NHP_Options;
     $NHP_Options = new ctNHP_Options($sections, $args, $tabs);
     if ($this->isUpgradeRequired()) {
         $NHP_Options->refresh();
     }
     $theme_data = wp_get_theme();
     //add current version
     update_option($this->projectName . '_theme_version', (double) $theme_data->get('Version'));
     add_action('nhp-opts-load-page-' . $NHP_Options->getOptionsPageName(), array($this, 'themeOptionsCustomAssets'));
     $this->callInitialized();
 }