PageRenderTime 780ms CodeModel.GetById 605ms app.highlight 6ms RepoModel.GetById 166ms app.codeStats 1ms

/vafpress/bootstrap.php

https://github.com/bmen/wordpress-theme-premium-umweltc
PHP | 175 lines | 4 code | 3 blank | 168 comment | 0 complexity | 6aeca92d321d4843704360ad970b99f2 MD5 | raw file
  1<?php
  2
  3//////////////////////////
  4// Include Constants    //
  5//////////////////////////
  6require_once 'constant.php';
  7
  8//////////////////////////
  9// Include Autoloader  //
 10//////////////////////////
 11require_once 'autoload.php';
 12
 13//////////////////////////
 14// Bootstrap Extensions //
 15//////////////////////////
 16foreach (glob(VP_EXT_DIR . "/*", GLOB_ONLYDIR) as $ext)
 17{
 18	$bs_file  = $ext . '/bootstrap.php';
 19	$fc_file  = $ext . '/functions.php';
 20	if(is_file($bs_file) and is_file($fc_file))
 21	{
 22		// bootstrap and get namespace
 23		$ns = require_once $bs_file;
 24
 25		// check the existence of config and views dir
 26		$views_dir  = is_dir($ext . '/views')  ? $ext . '/views'  : '';
 27		$config_dir = is_dir($ext . '/config') ? $ext . '/config' : '';
 28
 29		VP_Extension::add_extension($ns)
 30			->set_bootstrap_file($bs_file)
 31			->set_functions_file($fc_file)
 32			->set_views_dir($views_dir)
 33			->set_config_dir($config_dir);
 34	}
 35}
 36
 37
 38//////////////////////////
 39// Setup FileSystem     //
 40//////////////////////////
 41$vpfs = VP_FileSystem::instance();
 42// App Directories
 43$vpfs->add_directories('views'   , VP_APP_VIEWS_DIR);
 44$vpfs->add_directories('builder' , VP_APP_BUILDER_DIR);
 45$vpfs->add_directories('config'  , VP_APP_CONFIG_DIR);
 46$vpfs->add_directories('data'    , VP_APP_DATA_DIR);
 47$vpfs->add_directories('includes', VP_APP_INCLUDE_DIR);
 48// Core Directories
 49$vpfs->add_directories('views'   , VP_CORE_VIEWS_DIR);
 50$vpfs->add_directories('builder' , VP_CORE_BUILDER_DIR);
 51$vpfs->add_directories('config'  , VP_CORE_CONFIG_DIR);
 52$vpfs->add_directories('data'    , VP_CORE_DATA_DIR);
 53$vpfs->add_directories('includes', VP_CORE_INCLUDE_DIR);
 54
 55
 56//////////////////////////
 57// Include Data Source  //
 58//////////////////////////
 59foreach (array_merge(glob(VP_APP_DATA_DIR . "/*.php"), glob(VP_CORE_DATA_DIR . "/*.php")) as $datasource)
 60{
 61	require_once($datasource);
 62}
 63
 64////////////////////////
 65// Global Variables   //
 66////////////////////////
 67global $vp_set, $vp_config, $vp_opt;
 68$vp_opt = array();
 69
 70////////////////////////
 71// Load Theme Config  //
 72////////////////////////
 73$vp_config = VP_Util_Config::instance()->load('option');
 74
 75
 76////////////////////////
 77// Load Languages     //
 78////////////////////////
 79$lang_dir = VP_THEME_DIR . '/lang';
 80load_theme_textdomain('vp_textdomain', $lang_dir);
 81
 82/////////////////////////////
 83// Bootstrap Theme Options //
 84/////////////////////////////
 85require_once 'option.php';
 86
 87/////////////////////////
 88// Bootstrap Metaboxes //
 89/////////////////////////
 90require_once 'metabox.php';
 91
 92////////////////////////
 93// Run Extension      //
 94////////////////////////
 95foreach (VP_Extension::get_extensions() as $ext)
 96{
 97	require_once $ext->get_functions_file();
 98}
 99
100///////////////////////////////////////////////
101// Theme Activation and Deactivation actions //
102///////////////////////////////////////////////
103function vp_deactivate_theme()
104{
105	// get new theme slug
106	$new_theme = get_stylesheet();
107
108	// delete old opt
109	$stylesheet = get_option( 'theme_switched' );
110	delete_option("vpf_active_$stylesheet");
111
112	// send data if it's not vpf theme activated
113	if(!get_option("vpf_active_$new_theme"))
114	{
115		if(vp_should_track())
116		{
117			$tracker    = new VP_WP_Tracker();
118			$tracker->track($stylesheet);
119		}
120    }
121}
122
123function vp_activate_theme()
124{
125	// set activated option value
126	$theme      = get_stylesheet();
127	$option_key = 'vpf_active_' . $theme;
128	update_option( $option_key, 1 );
129
130	// setup option to db
131	vp_setup_options_to_db();
132
133	if(vp_should_track())
134	{
135		$tracker = new VP_WP_Tracker();
136		$tracker->track();
137	}
138}
139
140function vp_should_track()
141{
142	if(vp_option('enable_tracking') and !vp_is_local())
143	{
144		return true;
145	}
146	return false;
147}
148
149function vp_is_local()
150{
151	$local_hosts = array('localhost', '127.0.0.1', '::1');
152	if(isset($_SERVER['HTTP_HOST']) and !in_array($_SERVER['HTTP_HOST'], $local_hosts))
153		return false;
154	return true;
155}
156
157// schedule tracker
158if(vp_should_track())
159{
160	$tracker = new VP_WP_Tracker();
161	$tracker->schedule_track();
162}
163
164// register theme deactivation hook
165add_action('switch_theme', 'vp_deactivate_theme');
166
167// register theme activation 'hook'
168add_action('after_switch_theme', 'vp_activate_theme');
169
170// do scripts and styles dependencies for Mass Enqueuer
171VP_WP_MassEnqueuer::instance()->register();
172
173/**
174 * EOF
175 */