<?php
/**
 * Class for initializing Zeus Framework and
 * acts as the bridge between VTCore and Zeus
 * framework
 *
 * @author jason.xie@victheme.com
 *
 */
class VTCore_Zeus_Init {

  private $autoloader;
  private static $layout;
  private static $schemas;
  private static $features;
  private static $templateSystem;
  private static $theme;
  private static $visualComposer;


  private $actions = array(
    'widgets_init',
    'wp_before_admin_bar_render',
    'wp_enqueue_scripts',
    'admin_init',
    'admin_menu',
    'customize_register',
    'customize_preview_init',
    'customize_save',
    'pre_get_posts',
    'vtcore_zeus_alter_features',
    'vtcore_zeus_alter_regions',
    'vtcore_zeus_alter_schema',
    'wp_ajax_color_customizer',
    'vc_after_mapping',
    'vc_before_init',
    'vtcore_portfolio_alter_metabox_form',
  );


  private $filters = array(
    'excerpt_more',
    'the_excerpt',
    'get_archives_link',
    'wp_list_categories',
    'wp_list_pages',
    'wp_nav_menu',
    'post_gallery',
    'attribute_escape',
    'cancel_comment_reply_link',
    'comment_reply_link',
    'vtcore_portfolio_config_context_alter',
    'vtcore_headline_configuration_context_alter',
    'vtcore_headline_context_alter',
  );



  /**
   * Constructing the main class and adding action to init.
   */
  public function __construct() {

    self::$theme = wp_get_theme();

    // Load autoloader
    $this->autoloader = new VTCore_Autoloader('VTCore_Zeus', dirname(__FILE__));
    $this->autoloader->setRemovePath('vtcore' . DIRECTORY_SEPARATOR . 'zeus' . DIRECTORY_SEPARATOR);
    $this->autoloader->register();

    // Registering theme supports
    add_theme_support('post-thumbnails');
    add_theme_support('automatic-feed-links').
    add_theme_support('html5', array('search-form', 'comment-form', 'comment-list'));
    add_theme_support('title-tag');
    add_theme_support('vtcore_custom_template');

    global $revSliderAsTheme;
    $revSliderAsTheme = true;

    // Registering default menu location
    register_nav_menu('primary', __( 'Navigation Menu', BASE_THEME));

    // Registering actions
    VTCore_Wordpress_Init::getFactory('actions')
      ->addPrefix('VTCore_Zeus_Actions_')
      ->addHooks($this->actions)
      ->register();


    // Registering filters
    VTCore_Wordpress_Init::getFactory('filters')
      ->addPrefix('VTCore_Zeus_Filters_')
      ->addHooks($this->filters)
      ->register();

    // Registering regions
    VTCore_Zeus_Init::setStaticSystem('layout', new VTCore_Zeus_Layout_Factory());

    // Registering schemas
    self::setStaticSystem('schemas', new VTCore_Zeus_Schema_Factory());

    // Registering config
    self::setStaticSystem('features', new VTCore_Zeus_Config_Options());

    // Setup the VTCore asset factory
    VTCore_Wordpress_Init::getFactory('assets')
      ->add('aggregate', VTCore_Zeus_Init::getFeatures()->get('options.performance.aggregate'))
      ->add('minify', VTCore_Zeus_Init::getFeatures()->get('options.performance.minify'))
      ->get('library')
      ->detect(VTCORE_ZEUS_THEME_PATH . DIRECTORY_SEPARATOR . 'assets', get_template_directory_uri() . '/assets');

    VTCore_Wordpress_Init::getFactory('template')
      // uncomment if wploop template supported
      //->register(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'wploop', 'templates' . DIRECTORY_SEPARATOR . 'wploop')
      ->register(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'custom', 'templates' . DIRECTORY_SEPARATOR . 'custom');

    // Booting visualComposer integration system
    if (function_exists('vc_set_as_theme')) {
      self::setStaticSystem('visualComposer', new VTCore_Zeus_VisualComposer_Init());
    }

    // Loading text domain
    load_theme_textdomain(BASE_THEME, VTCORE_ZEUS_THEME_PATH . DIRECTORY_SEPARATOR . 'languages');



  }

  /**
   * Allow other class to get the layout factory object
   * @return VTCore_Zeus_Layout_Factory
   */
  public static function getLayout() {
    return self::getStaticSystem('layout');
  }



  /**
   * Allow other class to get the schema factory object
   * @return VTCore_Zeus_Schema_Factory
   */
  public static function getSchema() {
    return self::getStaticSystem('schemas');
  }



  /**
   * Allow other class to get the features system object
   * @return VTCore_Zeus_Features
   */
  public static function getFeatures() {
    return self::getStaticSystem('features');
  }



  /**
   * Allow other class to get templating system object
   * @return VTCore_Zeus_Templates_Factory
   */
  public static function getTemplatingSystem() {
    return self::getStaticSystem('templateSystem');
  }


  /**
   * Retrieving theme information
   */
  public static function getThemeInfo($key) {
    return self::$theme->get($key);
  }


  /**
   * Populate the static system with content (or object)
   */
  public static function setStaticSystem($system, $content) {
    self::${$system} = $content;
  }


  /**
   * Retrieve the static systems.
   */
  public static function getStaticSystem($system) {
    return self::${$system};
  }

}