PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/application/index.php

https://github.com/robeendey/ce
PHP | 193 lines | 134 code | 28 blank | 31 comment | 63 complexity | 9c22f055e237fa87e0709dbf49023056 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Engine_Core
  4. * @version $Id: index.php 7539 2010-10-04 04:41:38Z john $
  5. * @copyright Copyright (c) 2008 Webligo Developments
  6. * @license http://www.socialengine.net/license/
  7. */
  8. // Redirect to index if rewrite not enabled
  9. if( !defined('_ENGINE_R_REWRITE') ) {
  10. $target = null;
  11. if( empty($_GET['rewrite']) && $_SERVER['PHP_SELF'] != parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ) {
  12. $target = $_SERVER['PHP_SELF'];
  13. $params = $_GET;
  14. unset($params['rewrite']);
  15. if( !empty($params) ) {
  16. $target .= '?' . http_build_query($params);
  17. }
  18. } else if( isset($_GET['rewrite']) && $_GET['rewrite'] == 2 ) {
  19. //$target = dirname($_SERVER['PHP_SELF']);
  20. $target = preg_replace('/\/index\.php\/?/i', '/', $_SERVER['REQUEST_URI']);
  21. }
  22. if( null !== $target ) {
  23. header('Location: ' . $target);
  24. exit();
  25. }
  26. }
  27. // Config
  28. if( !defined('_ENGINE_R_CONF') || _ENGINE_R_CONF ) {
  29. // Error reporting
  30. error_reporting(E_ALL);
  31. // Constants
  32. define('_ENGINE', TRUE);
  33. define('DS', DIRECTORY_SEPARATOR);
  34. define('PS', PATH_SEPARATOR);
  35. // Define full application path, environment, and name
  36. defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(dirname(__FILE__))));
  37. defined('APPLICATION_PATH_COR') || define('APPLICATION_PATH_COR', realpath(dirname(__FILE__)));
  38. defined('APPLICATION_PATH_TMP') || define('APPLICATION_PATH_TMP', APPLICATION_PATH . DS . 'temporary');
  39. defined('APPLICATION_PATH_EXT') || define('APPLICATION_PATH_EXT', APPLICATION_PATH . DS . 'externals');
  40. defined('APPLICATION_PATH_PUB') || define('APPLICATION_PATH_PUB', APPLICATION_PATH . DS . 'public');
  41. defined('APPLICATION_PATH_SET') || define('APPLICATION_PATH_SET', APPLICATION_PATH_COR . DS . 'settings');
  42. defined('APPLICATION_NAME') || define('APPLICATION_NAME', 'Core');
  43. defined('_ENGINE_ADMIN_NEUTER') || define('_ENGINE_ADMIN_NEUTER', false);
  44. defined('_ENGINE_NO_AUTH') || define('_ENGINE_NO_AUTH', false);
  45. defined('_ENGINE_REQUEST_START') || define('_ENGINE_REQUEST_START', microtime(true));
  46. defined('_ENGINE_SSL') || define('_ENGINE_SSL', (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on'));
  47. // Setup required include paths; optimized for Zend usage. Most other includes
  48. // will use an absolute path
  49. set_include_path(
  50. APPLICATION_PATH . DS . 'application' . DS . 'libraries' . PS .
  51. APPLICATION_PATH . DS . 'application' . DS . 'libraries' . DS . 'PEAR' . PS .
  52. '.' // get_include_path()
  53. );
  54. }
  55. // get general config
  56. if( file_exists(APPLICATION_PATH_SET . DS . 'general.php') ) {
  57. $generalConfig = include APPLICATION_PATH_SET . DS . 'general.php';
  58. } else {
  59. $generalConfig = array('environment_mode' => 'development');
  60. }
  61. // maintenance mode
  62. if( !empty($generalConfig['maintenance']['enabled']) && !empty($generalConfig['maintenance']['code']) ) {
  63. $code = $generalConfig['maintenance']['code'];
  64. if( @$_GET['en4_maint_code'] == $code || @$_COOKIE['en4_maint_code'] == $code ) {
  65. if( @$_COOKIE['en4_maint_code'] !== $code ) {
  66. setcookie('en4_maint_code', $code, time() + (86400 * 7), '/');
  67. }
  68. } else {
  69. echo file_get_contents(dirname(__FILE__) . DS . 'maintenance.html');
  70. exit();
  71. }
  72. }
  73. // development mode
  74. $application_env = @$generalConfig['environment_mode'];
  75. defined('APPLICATION_ENV') || define('APPLICATION_ENV', (
  76. !empty($_SERVER['_ENGINE_ENVIRONMENT']) ? $_SERVER['_ENGINE_ENVIRONMENT'] : (
  77. $application_env ? $application_env :
  78. 'production'
  79. )));
  80. // Check for uninstalled state
  81. if( !file_exists(APPLICATION_PATH_SET . DS . 'database.php') ) {
  82. header('Location: ' . rtrim((string)constant('_ENGINE_R_BASE'), '/') . '/install/index.php');
  83. exit();
  84. }
  85. // Check tasks
  86. if( !empty($_REQUEST['notrigger']) ) {
  87. define('ENGINE_TASK_NOTRIGGER', true);
  88. }
  89. // Sub apps
  90. if( !defined('_ENGINE_R_MAIN') && !defined('_ENGINE_R_INIT') ) {
  91. if( @$_GET['m'] == 'css' ) {
  92. define('_ENGINE_R_MAIN', 'css.php');
  93. define('_ENGINE_R_INIT', false);
  94. } else if( @$_GET['m'] == 'comet' ) {
  95. define('_ENGINE_R_MAIN', 'comet.php');
  96. define('_ENGINE_R_INIT', false);
  97. } else if( @$_GET['m'] == 'lite' ) {
  98. define('_ENGINE_R_MAIN', 'lite.php');
  99. define('_ENGINE_R_INIT', false);
  100. } else if( @$_GET['m'] == 'mobile' ) {
  101. define('_ENGINE_R_MAIN', 'mobile.php');
  102. define('_ENGINE_R_INIT', true);
  103. } else {
  104. define('_ENGINE_R_MAIN', false);
  105. define('_ENGINE_R_INIT', true);
  106. }
  107. }
  108. // Boot
  109. if( _ENGINE_R_INIT ) {
  110. // Application
  111. require_once 'Engine/Loader.php';
  112. require_once 'Engine/Application.php';
  113. Engine_Loader::getInstance()
  114. // Libraries
  115. ->register('Zend', APPLICATION_PATH_COR . DS . 'libraries' . DS . 'Zend')
  116. ->register('Engine', APPLICATION_PATH_COR . DS . 'libraries' . DS . 'Engine')
  117. ->register('Facebook', APPLICATION_PATH_COR . DS . 'libraries' . DS . 'Facebook')
  118. //->register('Zym', APPLICATION_PATH_COR . DS . 'libraries' . DS . 'Zym')
  119. // Plugins
  120. ->register('Plugin', APPLICATION_PATH_COR . DS . 'plugins')
  121. // Widgets
  122. ->register('Widget', APPLICATION_PATH_COR . DS . 'widgets')
  123. ;
  124. // Create application, bootstrap, and run
  125. $application = new Engine_Application(
  126. APPLICATION_ENV,
  127. array(
  128. 'bootstrap' => array(
  129. 'path' => APPLICATION_PATH_COR . DS . 'modules' . DS . APPLICATION_NAME . DS . 'Bootstrap.php',
  130. 'class' => ucfirst(APPLICATION_NAME) . '_Bootstrap',
  131. )
  132. )
  133. );
  134. Engine_Api::getInstance()->setApplication($application);
  135. }
  136. // config mode
  137. if( defined('_ENGINE_R_CONF') && _ENGINE_R_CONF ) {
  138. return;
  139. }
  140. if( !empty($_SERVER['_ENGINE_TRACE_ALLOW']) && extension_loaded('xdebug') ) {
  141. xdebug_start_trace();
  142. }
  143. // Sub apps
  144. if( _ENGINE_R_MAIN ) {
  145. require dirname(__FILE__) . DS . _ENGINE_R_MAIN;
  146. exit();
  147. }
  148. // Main app
  149. else if( APPLICATION_ENV !== 'development' ) {
  150. try {
  151. $application->bootstrap();
  152. $application->run();
  153. } catch( Exception $e ) {
  154. echo file_get_contents(dirname(__FILE__) . DS . 'offline.html');
  155. exit();
  156. }
  157. }
  158. // Main app (dev mode)
  159. else {
  160. $application->bootstrap();
  161. $application->run();
  162. }
  163. if( !empty($_SERVER['_ENGINE_TRACE_ALLOW']) && extension_loaded('xdebug') ) {
  164. xdebug_stop_trace();
  165. }