<?php
/**
 * Theme Alien Core functions and definitions
 *
 * @package BigBoom
 */

/**
 * Define theme's constant
 */
if ( ! defined( 'THEME_VERSION' ) ) {
	define( 'THEME_VERSION', '1.0.4' );
}
if ( ! defined( 'THEME_DIR' ) ) {
	define( 'THEME_DIR', get_template_directory() );
}
if ( ! defined( 'THEME_URL' ) ) {
	define( 'THEME_URL', get_template_directory_uri() );
}

/**
 * Set the content width based on the theme's design and stylesheet.
 */
if ( ! isset( $content_width ) ) {
	$content_width = 640;
}

/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * @since  1.0
 *
 * @return void
 */
function bigboom_setup() {

	// Make theme available for translation.
	load_theme_textdomain( 'bigboom', get_template_directory() . '/lang' );

	// Theme supports
	add_theme_support( 'woocommerce' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
	add_theme_support( 'html5', array(
		'comment-list',
		'search-form',
		'comment-form',
		'gallery',
	) );

	// Register theme nav menu
	register_nav_menus( array(
		'primary' => __( 'Primary Menu', 'bigboom' ),
		'footer'  => __( 'Footer Menu', 'bigboom' ),
		'mobile'  => __( 'Mobile Menu', 'bigboom' ),
	) );
}
add_action( 'after_setup_theme', 'bigboom_setup' );

/**
 * Initialize additional functions/classes
 *
 * @since 1.0
 */
function bigboom_init() {
	new BigBoom_VC;
	new BigBoom_WooCommerce;

	if ( is_admin() ) {
		new Bigboom_Walker_Nav_Menu_Custom_Fields;

		new TA_Demo_Import( array(
			'home_page' => 'Home Page 1',
			'blog_page' => 'Blog',
			'base_url'  => 'http://demo.themealien.com/bigboom-2/',
			'sliders'   => true,
		) );
	} else {
		new BigBoom_Shortcodes;
	}
}
add_action( 'after_setup_theme', 'bigboom_init', 20 );

/**
 * Add image sizes.
 * Must be added to init hook to remove sizes of portfolio plugin.
 *
 * @since 1.0
 */
function bigboom_add_image_sizes() {
	add_image_size( 'blog-thumb-tiny', 113, 113, true );
	add_image_size( 'blog-small-thumb', 555, 245, true );
	add_image_size( 'blog-thumb', 870, 385, true );
	add_image_size( 'blog-large-thumb', 1170, 520, true );
	add_image_size( 'widget-thumb', 125, 135, true );
}
add_action( 'after_setup_theme', 'bigboom_add_image_sizes', 10 );

/**
 * Register widgetized area and update sidebar with default widgets.
 *
 * @since 1.0
 *
 * @return void
 */
function bigboom_register_sidebar() {
	// Register topbar sidebar
	register_sidebar( array(
		'name'          => __( 'Topbar Left', 'bigboom' ),
		'id'            => 'topbar-left',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h4 class="widget-title">',
		'after_title'   => '</h4>',
	) );

	register_sidebar( array(
		'name'          => __( 'Topbar Right', 'bigboom' ),
		'id'            => 'topbar-right',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h4 class="widget-title">',
		'after_title'   => '</h4>',
	) );

	// Register header sidebar
	register_sidebar( array(
		'name'          => __( 'Header Right', 'bigboom' ),
		'id'            => 'header-sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h4 class="widget-title">',
		'after_title'   => '</h4>',
	) );

	// Register shop sidebar
	register_sidebar( array(
		'name'          => __( 'Shop Sidebar', 'bigboom' ),
		'id'            => 'shop-sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h4 class="widget-title">',
		'after_title'   => '</h4>',
	) );

	// Register blog sidebar
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'bigboom' ),
		'id'            => 'blog-sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h4 class="widget-title">',
		'after_title'   => '</h4>',
	) );

	// Register page sidebar
	register_sidebar( array(
		'name'          => __( 'Page Sidebar', 'bigboom' ),
		'id'            => 'page-sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h4 class="widget-title">',
		'after_title'   => '</h4>',
	) );

	// Register footer sidebar
	register_sidebars( 5, array(
		'name'          => __( 'Footer', 'bigboom' ) . ' %d',
		'id'            => 'footer-sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h4 class="widget-title">',
		'after_title'   => '</h4>',
	) );
}
add_action( 'widgets_init', 'bigboom_register_sidebar' );

/**
 * Load theme
 */

// Theme Options
require THEME_DIR . '/inc/libs/theme-options/framework.php';
require THEME_DIR . '/inc/backend/theme-options.php';

// Widgets
require THEME_DIR . '/inc/widgets/widgets.php';

// Visual composer
require THEME_DIR . '/inc/backend/visual-composer.php';

// Woocommerce hooks
require THEME_DIR . '/inc/frontend/woocommerce.php';

if ( is_admin() ) {
	require THEME_DIR . '/inc/libs/class-tgm-plugin-activation.php';
	require THEME_DIR . '/inc/backend/plugins.php';
	require THEME_DIR . '/inc/backend/meta-boxes.php';
	require THEME_DIR . '/inc/backend/nav-menus.php';
	require THEME_DIR . '/inc/importer/importer.php';
} else {
	// Frontend functions and shortcodes
	require THEME_DIR . '/inc/functions/media.php';
	require THEME_DIR . '/inc/functions/nav.php';
	require THEME_DIR . '/inc/functions/mega-menu-walker.php';
	require THEME_DIR . '/inc/functions/layout.php';
	require THEME_DIR . '/inc/functions/entry.php';
	require THEME_DIR . '/inc/functions/shortcodes.php';

	// Frontend hooks
	require THEME_DIR . '/inc/frontend/layout.php';
	require THEME_DIR . '/inc/frontend/header.php';
	require THEME_DIR . '/inc/frontend/nav.php';
	require THEME_DIR . '/inc/frontend/entry.php';
	require THEME_DIR . '/inc/frontend/footer.php';
}
