<?php
/**
 * Simple class for managing theme features.
 *
 * Themer must fill out the theme features variables
 * in this class for setting up the default values for
 * the theme.
 *
 * User can change the configuration via theme options
 * and save them to the theme database entry as wordpress
 * theme_mod specifies.
 *
 * This class then will merge the database entry with the
 * default values and pass them to theme templates via
 * VTCore_Zeus_Utility class.
 *
 * Other plugin can interact with the features system by
 * using Wordpress action vtcore_zeus_alter_features
 * and use the object public methods to alter the features.
 *
 * @author jason.xie@victheme.com
 *
 */
class VTCore_Zeus_Config_Options
extends VTCore_Wordpress_Models_Config {

  protected $database = 'features';
  protected $filter = 'vtcore_zeus_features_context_alter';
  protected $loadFunction = 'get_theme_mod';
  protected $savefunction = 'set_theme_mod';
  protected $deleteFunction = 'remove_theme_mod';

  /**
   * Centralized location for registering default
   * values for all the theme features excluding
   * the default values for schema settings.
   */
  public function register(array $options) {
    $this->url = defined('VTCORE_ZEUS_THEME_URL') ? VTCORE_ZEUS_THEME_URL : get_template_directory_uri();
    $this->options = array(
      'show' => array(
        'teaser' => array(
          'title' => true,
          'image' => true,
          'byline' => true,
          'excerpt' => true,
          'readmore' => true,
        ),
        'full' => array(
          'image' => true,
          'title' => true,
          'content' => true,
          'tags' => true,
          'author' => true,
          'comments' => true,
          'comment_form' => true,
          'social' => true,
        ),
        'notfound' => array(
          'title' => true,
          'content' => true,
        ),
        'page' => array(
          'image' => true,
          'title' => true,
          'content' => true,
          'comments' => true,
          'comment_form' => true,
          'social' => true,
        ),
        'portfolio' => array(
          'title' => true,
          'tags' => true,
          'social' => true,
        ),
        'footer' => array(
          'fullfooter' => true,
          'menu' => true,
          'copyright' => true,
        ),
      ),

      'images' => array(
        'thumbnail' => array(
          'width' => 800,
          'height' => 600,
          'crop' => false
        ),
        'full' => array(
          'width' => 800,
          'height' => 600,
          'crop' => false
        ),
      ),

      'sidebars' => array(
        'teaser' => 'right',
        'full' => 'right',
        'notfound' => 'right',
        'page' => false,
        'portfolio_teaser' => false,
        'portfolio_full' => false,
      ),

      'options' => array(
        'logo' => array(
          'image' => VTCORE_ZEUS_THEME_URL . '/logo.png',
          'text' => '',
          'slogan' => '',
          'width' => '119',
          'height' => '36',
        ),
        'animsition' => array(
          'enable' => true,
          'loading_text' => __('Loading ..', BASE_THEME),
          'animation_in' => 'zoom-in',
          'in_duration' => 1000,
          'animation_out' => 'zoom-out',
          'out_duration' => 800,
        ),
        'favicon' => array(
          'image' => VTCORE_ZEUS_THEME_URL . '/favicon.ico',
        ),
        'menu' => array(
          'disable_parent' => false,
          'enable_slick' => true,
          'enable_sticky' => true,
        ),
        'page' => array(
          'maxwidth' => 'max-1170',
          'style' => 'style-normal',
          'responsive' => 'bs-responsive',
        ),
        'notfound' => array(
          'title' => __('Oops. This Page Could Not Be Found!', BASE_THEME),
          'content' => __('Oops! 404', BASE_THEME),
        ),
        'footer' => array(
          'copyrighttext' => __('Equaly Premium Theme built by VicTheme.com', BASE_THEME),
        ),
        'performance' => array(
          'aggregate' => false,
          'minify' => false,
        ),

        'customizer' => array(
          'general' => true,
          'style' => true,
          'layout' => true,
          'widgets' => true,
        ),
      ),
    );

    // Try to fill out the logo options if the default logo is false
    if (!$this->get('options.logo')) {
      $schema = new VTCore_Zeus_Schema_Factory();
      if ($schema->getActiveSchema()->getData('logo')) {
        $this->mutate('options.logo', $schema->getActiveSchema()->getData('logo'));
      }
    }

    // Merge the user supplied options
    $this->merge($options);

    // Apply the hookable filter
    $this->filter();

    // Inject from database
    $this->load();

    // Backward compatibility
    do_action('vtcore_zeus_alter_features', $this);

    // Always turn off slick nav on non responsive mode
    if ($this->options['options']['page']['responsive'] == 'bs-fixed') {
      $this->options['options']['menu']['enable_slick'] = false;
    }

    return $this;

  }

  /**
   * Simple getter for extracting the features value.
   *
   * User should use VTCore_Zeus_Utility classes method
   * for easily extracting this class features variables
   * instead of using this raw method.
   *
   * @deprecated
   *  just here to avoid template broken, don't use this
   *  for new file, just use the direct config object method.
   */
  public function getFeature($key) {
    return $this->get($key);
  }



  /**
   * Change a single feature value dynamically after
   * the class initialized.
   *
   * @deprecated
   *  just here to avoid template broken, don't use this
   *  for new file, just use the direct config object method.
   */
  public function setFeature($type, $key, $value) {
    $this->add($type . '.' . $key, $value);
    return $this;
  }



  /**
   * Changing the value in the features options only.
   *
   * @deprecated
   *  just here to avoid template broken, don't use this
   *  for new file, just use the direct config object method.
   * @return VTCore_Zeus_Features
   */
  public function setOption($type, $key, $value) {
    $this->add('options.' . $type . '.' . $key, $value);
    return $this;
  }


  /**
   * Remove a single feature
   *
   * @deprecated
   *  just here to avoid template broken, don't use this
   *  for new file, just use the direct config object method.
   */
  public function removeFeature($type, $key) {
    $this->remove($type . '.' . $key);
    return $this;
  }
}