<?php
/**
 * SeoHub Framework
 *
 * @package seohub
 * @since seohub 1.0
 */

// Disable direct call
if ( ! defined( 'ABSPATH' ) ) { exit; }

// Framework directory path from theme root
if ( ! defined( 'SEOHUB_FW_DIR' ) )		define( 'SEOHUB_FW_DIR', '/fw/' );

// Theme timing
if ( ! defined( 'SEOHUB_START_TIME' ) )	define( 'SEOHUB_START_TIME', microtime());			// Framework start time
if ( ! defined( 'SEOHUB_START_MEMORY' ) )	define( 'SEOHUB_START_MEMORY', memory_get_usage());	// Memory usage before core loading

// Global variables storage

$SEOHUB_GLOBALS = array(
	'theme_slug'	=> 'seohub',	// Theme slug (used as prefix for theme's functions, text domain, global variables, etc.)
	'page_template'	=> '',			// Storage for current page template name (used in the inheritance system)
    'allowed_tags'	=> array(		// Allowed tags list (with attributes) in translations
    	'b' => array(),
    	'strong' => array(),
    	'i' => array(),
    	'em' => array(),
    	'u' => array(),
    	'a' => array(
			'href' => array(),
			'title' => array(),
			'target' => array(),
			'id' => array(),
			'class' => array()
		),
    	'span' => array(
			'id' => array(),
			'class' => array()
		)
    )	
);

/* Theme setup section
-------------------------------------------------------------------- */
if ( !function_exists( 'seohub_loader_theme_setup' ) ) {
	add_action( 'after_setup_theme', 'seohub_loader_theme_setup', 20 );
	function seohub_loader_theme_setup() {
		
		// Init admin url and nonce
		global $SEOHUB_GLOBALS;
		$SEOHUB_GLOBALS['admin_url']	= get_admin_url();
		$SEOHUB_GLOBALS['admin_nonce']= wp_create_nonce($SEOHUB_GLOBALS['admin_url']);
		$SEOHUB_GLOBALS['ajax_url']	= admin_url('admin-ajax.php');
		$SEOHUB_GLOBALS['ajax_nonce']	= wp_create_nonce($SEOHUB_GLOBALS['ajax_url']);

		// Before init theme
		do_action('seohub_action_before_init_theme');

		// Load current values for main theme options
		seohub_load_main_options();

		// Theme core init - only for admin side. In frontend it called from header.php
		if ( is_admin() ) {
			seohub_core_init_theme();
		}
	}
}


/* Include core parts
------------------------------------------------------------------------ */

// Manual load important libraries before load all rest files
// core.strings must be first - we use seohub_str...() in the seohub_get_file_dir()
require_once (file_exists(get_stylesheet_directory().(SEOHUB_FW_DIR).'core/core.strings.php') ? get_stylesheet_directory() : get_template_directory()).(SEOHUB_FW_DIR).'core/core.strings.php';
// core.files must be first - we use seohub_get_file_dir() to include all rest parts
require_once (file_exists(get_stylesheet_directory().(SEOHUB_FW_DIR).'core/core.files.php') ? get_stylesheet_directory() : get_template_directory()).(SEOHUB_FW_DIR).'core/core.files.php';

// Include theme variables storage
require_once seohub_get_file_dir('core/core.storage.php');

// Include custom theme files
seohub_autoload_folder( 'includes' );

// Include core files
seohub_autoload_folder( 'core' );

// Include theme-specific plugins and post types
seohub_autoload_folder( 'plugins' );

// Include theme templates
seohub_autoload_folder( 'templates' );

// Include theme widgets
seohub_autoload_folder( 'widgets' );
?>