index.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. date_default_timezone_set('Asia/Shanghai');
  3. define('ENVIRONMENT', (isset($_SERVER["CI_ENV"]) ? $_SERVER["CI_ENV"] : "production"));
  4. switch( ENVIRONMENT )
  5. {
  6. case 'development':
  7. error_reporting(-1);
  8. ini_set('display_errors', 1);
  9. break;
  10. case 'testing':
  11. case 'production':
  12. ini_set('display_errors', 0);
  13. if( version_compare(PHP_VERSION, '5.3', '>=') )
  14. {
  15. error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
  16. }
  17. else
  18. {
  19. error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
  20. }
  21. break;
  22. default:
  23. header('HTTP/1.1 503 Service Unavailable.', true, 503);
  24. echo 'The application environment is not set correctly.';
  25. exit( 1 );
  26. }
  27. $system_path = "apps" . DIRECTORY_SEPARATOR . "system";
  28. $application_folder = "apps" . DIRECTORY_SEPARATOR . "application";
  29. $view_folder = "template";
  30. if( defined('STDIN') )
  31. {
  32. chdir(dirname(preg_replace("@\\(.*\\(.*\$@", "", __FILE__)));
  33. }
  34. if( ($_temp = realpath($system_path)) !== false )
  35. {
  36. $system_path = $_temp . DIRECTORY_SEPARATOR;
  37. }
  38. else
  39. {
  40. $system_path = strtr(rtrim($system_path, "/\\"), "/\\", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
  41. }
  42. if( !is_dir($system_path) )
  43. {
  44. header("HTTP/1.1 503 Service Unavailable.", true, 503);
  45. echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: ' . pathinfo(preg_replace("@\\(.*\\(.*\$@", "", __FILE__), PATHINFO_BASENAME);
  46. exit( 3 );
  47. }
  48. if( !defined('SELF') )
  49. {
  50. define('SELF', pathinfo(preg_replace("@\\(.*\\(.*\$@", "", __FILE__), PATHINFO_BASENAME));
  51. }
  52. define('BASEPATH', $system_path);
  53. if( !defined('FCPATH') )
  54. {
  55. define('FCPATH', dirname(preg_replace("@\\(.*\\(.*\$@", "", __FILE__)) . DIRECTORY_SEPARATOR);
  56. }
  57. define('SYSDIR', basename(BASEPATH));
  58. if( is_dir($application_folder) )
  59. {
  60. if( ($_temp = realpath($application_folder)) !== false )
  61. {
  62. $application_folder = $_temp;
  63. }
  64. else
  65. {
  66. $application_folder = strtr(rtrim($application_folder, "/\\"), "/\\", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
  67. }
  68. }
  69. else
  70. {
  71. if( is_dir(BASEPATH . $application_folder . DIRECTORY_SEPARATOR) )
  72. {
  73. $application_folder = BASEPATH . strtr(trim($application_folder, "/\\"), "/\\", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
  74. }
  75. else
  76. {
  77. header('HTTP/1.1 503 Service Unavailable.', true, 503);
  78. echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF;
  79. exit( 3 );
  80. }
  81. }
  82. define('APPPATH', $application_folder . DIRECTORY_SEPARATOR);
  83. if( !isset($view_folder[0]) && is_dir(APPPATH . "views" . DIRECTORY_SEPARATOR) )
  84. {
  85. $view_folder = APPPATH . "views";
  86. }
  87. else
  88. {
  89. if( is_dir($view_folder) )
  90. {
  91. if( ($_temp = realpath($view_folder)) !== false )
  92. {
  93. $view_folder = $_temp;
  94. }
  95. else
  96. {
  97. $view_folder = strtr(rtrim($view_folder, "/\\"), "/\\", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
  98. }
  99. }
  100. else
  101. {
  102. if( is_dir(APPPATH . $view_folder . DIRECTORY_SEPARATOR) )
  103. {
  104. $view_folder = APPPATH . strtr(trim($view_folder, "/\\"), "/\\", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
  105. }
  106. else
  107. {
  108. header('HTTP/1.1 503 Service Unavailable.', true, 503);
  109. echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF;
  110. exit( 3 );
  111. }
  112. }
  113. }
  114. define('VIEWPATH', $view_folder . DIRECTORY_SEPARATOR);
  115. require_once(FCPATH . 'libraries/ctcms.php');
  116. require_once(BASEPATH . 'core/CodeIgniter.php');