PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

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