<?php

/**
 * SHRK Framework
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
	
global $shrk_theme_info;
global $shrk_options;
$shrk_options = array(); // If not initiated and Redux not active, issue with PHP notice not raising when it should.

$shrk_theme_info = wp_get_theme();

define( 'SHRK_THEME_LIBRARY', get_template_directory() .'/includes' );
define( 'SHRK_THEME_LIBRARY_URI', get_template_directory_uri() .'/includes' );

define( 'SHRK_THEME_MODULES', SHRK_THEME_LIBRARY .'/modules' );
define( 'SHRK_THEME_MODULES_URI', SHRK_THEME_LIBRARY_URI .'/modules/' );

define( 'SHRK_THEME_TGM_DIR', SHRK_THEME_LIBRARY .'/TGM' );
define( 'SHRK_THEME_PLUGINS_DIR', SHRK_THEME_LIBRARY. '/plugins/' );
define( 'SHRK_THEME_PLUGINS_URI', SHRK_THEME_LIBRARY_URI . '/plugins/' );

define( 'SHRK_THEME_ADMIN_PATH', SHRK_THEME_LIBRARY . '/admin' );
define( 'SHRK_THEME_ADMIN_URI', SHRK_THEME_LIBRARY_URI . '/admin' );
define( 'SHRK_ADMIN_JS_URI', SHRK_THEME_ADMIN_URI . '/js' );
define( 'SHRK_ADMIN_CSS_URI', SHRK_THEME_ADMIN_URI . '/css' );
define( 'SHRK_ADMIN_IMG_URI', SHRK_THEME_ADMIN_URI . '/images' );

define( 'SHRK_FONTS_DIR_URL', get_template_directory_uri() . '/fonts' );

define( 'SHRK_GOOGLE_FONTS_URL', 'http://api.develoved.com/fonts/' );

require_once( SHRK_THEME_LIBRARY . '/meta-config.php' );
require_once( SHRK_THEME_LIBRARY . '/global' . '/global.php');
require_once( SHRK_THEME_LIBRARY . '/global' . '/helpers.php');
require_once( SHRK_THEME_LIBRARY . '/global' . '/ajax.php');

// Extras
require_once( SHRK_THEME_LIBRARY . '/sidebars/sidebars.php' );

/**
 * Modules
 * @var array
 */
$shrk_modules = apply_filters( 'shrk_theme_modules', array(
	'woocommerce'               => true,
	'redux'                     => true,
	'swiper'                    => true,
	'photoswipe'                => true,
	'yith-wcas'                 => true,
	'searchwp-live-ajax-search' => true,
	'revslider'                 => true,
	'wc-vendors'                => true,
	'dokan'                     => true,
	'new-product-badge'         => true,
	'wc-ajax-product-filter'    => true,
) );

foreach ( $shrk_modules as $file => $dependancy ) {
	if ( $dependancy ) {
		require( SHRK_THEME_MODULES . sprintf( '/%1$s/%1$s.php', $file ) );
	}
}

// Mega menu walker
if ( file_exists( SHRK_THEME_LIBRARY . '/menu/shrk_menu.php' ) ) {
	require_once( SHRK_THEME_LIBRARY . '/menu/shrk_menu.php' );
}

// Side menu
if ( file_exists( SHRK_THEME_LIBRARY . '/menu/side_menu.php' ) ) {
	require_once( SHRK_THEME_LIBRARY . '/menu/side_menu.php' );
}

require_once ( SHRK_THEME_TGM_DIR . '/tgm.php' );
require_once ( SHRK_THEME_ADMIN_PATH . '/admin.php' );

require_once ( SHRK_THEME_LIBRARY . '/theme_functions.php' );
require_once ( SHRK_THEME_LIBRARY . '/theme_custom_css.php' );

// Setup metaboxes for basic posttypes





function shrk_register_postpage_meta() {
    shrk_add_meta_boxes( 'page' );
    shrk_add_meta_boxes( 'post' );
}
add_action( 'admin_menu', 'shrk_register_postpage_meta' );

// Set VC as theme
function shrk_vc_SetAsTheme() {
    vc_set_as_theme();
	
	// Disable VC Frontend editor 
	vc_disable_frontend();
}
add_action( 'vc_before_init', 'shrk_vc_SetAsTheme' );

// Enable VC backend editor for theme specific post types
function shrk_vc_set_default_editor_post_types() {
	if ( !shrk_get_theme_option( 'vc_auto_enable_posttypes' ) ) {
		return false;
	}

	$pt_list = array( 'page' );

	if ( function_exists( 'shrk_register_sections' ) ) {
		$pt_list[] = 'pagesections';
	}

	if ( function_exists( 'WC' ) ) {
		$pt_list[] = 'product';
	}

	if ( function_exists( 'vc_set_default_editor_post_types' ) ) {
		vc_set_default_editor_post_types( $pt_list );
	}
}
add_action( 'vc_after_init', 'shrk_vc_set_default_editor_post_types' );

?>