bootstrap.inc.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. define('IN_IA', true);
  7. define('STARTTIME', microtime());
  8. define('IA_ROOT', str_replace("\\", '/', dirname(dirname(__FILE__))));
  9. define('MAGIC_QUOTES_GPC', (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) || @ini_get('magic_quotes_sybase'));
  10. define('TIMESTAMP', time());
  11. $_W = $_GPC = array();
  12. $configfile = IA_ROOT . "/data/config.php";
  13. if(!file_exists($configfile)) {
  14. if(file_exists(IA_ROOT . '/install.php')) {
  15. header('Content-Type: text/html; charset=utf-8');
  16. require IA_ROOT . '/framework/version.inc.php';
  17. echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
  18. echo "·如果你还没安装本程序,请运行<a href='".(strpos($_SERVER['SCRIPT_NAME'], 'web') === false ? './install.php' : '../install.php')."'> install.php 进入安装&gt;&gt; </a><br/><br/>";
  19. echo "&nbsp;&nbsp;<a href='http://www.w7.cc' style='font-size:12px' target='_blank'>Power by WE7 " . IMS_VERSION . " &nbsp;微擎公众平台自助开源引擎</a>";
  20. exit();
  21. } else {
  22. header('Content-Type: text/html; charset=utf-8');
  23. exit('配置文件不存在或是不可读,请检查“data/config”文件或是重新安装!');
  24. }
  25. }
  26. require $configfile;
  27. require IA_ROOT . '/framework/version.inc.php';
  28. require IA_ROOT . '/framework/const.inc.php';
  29. require IA_ROOT . '/framework/class/loader.class.php';
  30. load()->func('global');
  31. load()->func('compat');
  32. load()->func('compat.biz');
  33. load()->func('pdo');
  34. load()->classs('account');
  35. load()->model('cache');
  36. load()->model('account');
  37. load()->model('setting');
  38. load()->model('module');
  39. load()->library('agent');
  40. load()->classs('db');
  41. load()->func('communication');
  42. define('CLIENT_IP', getip());
  43. $_W['config'] = $config;
  44. $_W['config']['db']['tablepre'] = !empty($_W['config']['db']['master']['tablepre']) ? $_W['config']['db']['master']['tablepre'] : $_W['config']['db']['tablepre'];
  45. $_W['timestamp'] = TIMESTAMP;
  46. $_W['charset'] = $_W['config']['setting']['charset'];
  47. $_W['clientip'] = CLIENT_IP;
  48. unset($configfile, $config);
  49. define('ATTACHMENT_ROOT', IA_ROOT .'/attachment/');
  50. error_reporting(0);
  51. if(!in_array($_W['config']['setting']['cache'], array('mysql', 'memcache', 'redis'))) {
  52. $_W['config']['setting']['cache'] = 'mysql';
  53. }
  54. load()->func('cache');
  55. if(function_exists('date_default_timezone_set')) {
  56. date_default_timezone_set($_W['config']['setting']['timezone']);
  57. }
  58. if(!empty($_W['config']['setting']['memory_limit']) && function_exists('ini_get') && function_exists('ini_set')) {
  59. if(@ini_get('memory_limit') != $_W['config']['setting']['memory_limit']) {
  60. @ini_set('memory_limit', $_W['config']['setting']['memory_limit']);
  61. }
  62. }
  63. if (isset($_W['config']['setting']['https']) && $_W['config']['setting']['https'] == '1') {
  64. $_W['ishttps'] = $_W['config']['setting']['https'];
  65. } else {
  66. $_W['ishttps'] = $_SERVER['SERVER_PORT'] == 443 ||
  67. (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ||
  68. strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' ||
  69. strtolower($_SERVER['HTTP_X_CLIENT_SCHEME']) == 'https' ? true : false;
  70. }
  71. $_W['isajax'] = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
  72. $_W['ispost'] = $_SERVER['REQUEST_METHOD'] == 'POST';
  73. $_W['sitescheme'] = $_W['ishttps'] ? 'https://' : 'http://';
  74. $_W['script_name'] = htmlspecialchars(scriptname());
  75. $sitepath = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
  76. $_W['siteroot'] = htmlspecialchars($_W['sitescheme'] . $_SERVER['HTTP_HOST'] . $sitepath);
  77. if(substr($_W['siteroot'], -1) != '/') {
  78. $_W['siteroot'] .= '/';
  79. }
  80. $urls = parse_url($_W['siteroot']);
  81. $urls['path'] = str_replace(array('/web', '/app', '/payment/wechat', '/payment/alipay', '/payment/jueqiymf', '/api'), '', $urls['path']);
  82. $_W['siteroot'] = $urls['scheme'].'://'.$urls['host'].((!empty($urls['port']) && $urls['port']!='80') ? ':'.$urls['port'] : '').$urls['path'];
  83. if(MAGIC_QUOTES_GPC) {
  84. $_GET = istripslashes($_GET);
  85. $_POST = istripslashes($_POST);
  86. $_COOKIE = istripslashes($_COOKIE);
  87. }
  88. foreach($_GET as $key => $value) {
  89. if (is_string($value) && !is_numeric($value)) {
  90. $value = safe_gpc_string($value);
  91. }
  92. $_GET[$key] = $_GPC[$key] = $value;
  93. }
  94. $cplen = strlen($_W['config']['cookie']['pre']);
  95. foreach($_COOKIE as $key => $value) {
  96. if(substr($key, 0, $cplen) == $_W['config']['cookie']['pre']) {
  97. $_GPC[substr($key, $cplen)] = $value;
  98. }
  99. }
  100. unset($cplen, $key, $value);
  101. $_GPC = array_merge($_GPC, $_POST);
  102. $_GPC = ihtmlspecialchars($_GPC);
  103. $_W['siteurl'] = $urls['scheme'].'://'.$urls['host'].((!empty($urls['port']) && $urls['port']!='80') ? ':'.$urls['port'] : '') . $_W['script_name'] . '?' . http_build_query($_GET, '', '&');
  104. if (!$_W['isajax']) {
  105. $input = file_get_contents("php://input");
  106. if (!empty($input)) {
  107. $__input = @json_decode($input, true);
  108. if (!empty($__input)) {
  109. $_GPC['__input'] = $__input;
  110. $_W['isajax'] = true;
  111. }
  112. }
  113. unset($input, $__input);
  114. }
  115. setting_load();
  116. if (empty($_W['setting']['upload'])) {
  117. $_W['setting']['upload'] = array_merge($_W['config']['upload']);
  118. }
  119. define('DEVELOPMENT', $_W['setting']['copyright']['develop_status'] == 1 || $_W['config']['setting']['development'] == 1);
  120. if(DEVELOPMENT) {
  121. ini_set('display_errors', '1');
  122. error_reporting(E_ALL ^ E_NOTICE);
  123. }
  124. if ($_W['config']['setting']['development'] == 2) {
  125. load()->library('sentry');
  126. if (class_exists('Raven_Autoloader')) {
  127. error_reporting(E_ALL ^ E_NOTICE);
  128. Raven_Autoloader::register();
  129. $client = new Raven_Client('http://8d52c70dbbed4133b72e3b8916663ae3:0d84397f72204bf1a3f721edf9c782e1@sentry.w7.cc/6');
  130. $error_handler = new Raven_ErrorHandler($client);
  131. $error_handler->registerExceptionHandler();
  132. $error_handler->registerErrorHandler();
  133. $error_handler->registerShutdownFunction();
  134. }
  135. }
  136. $_W['os'] = Agent::deviceType();
  137. if($_W['os'] == Agent::DEVICE_MOBILE) {
  138. $_W['os'] = 'mobile';
  139. } elseif($_W['os'] == Agent::DEVICE_DESKTOP) {
  140. $_W['os'] = 'windows';
  141. } else {
  142. $_W['os'] = 'unknown';
  143. }
  144. $_W['container'] = Agent::browserType();
  145. if(Agent::isMicroMessage() == Agent::MICRO_MESSAGE_YES) {
  146. $_W['container'] = 'wechat';
  147. } elseif ($_W['container'] == Agent::BROWSER_TYPE_ANDROID) {
  148. $_W['container'] = 'android';
  149. } elseif ($_W['container'] == Agent::BROWSER_TYPE_IPAD) {
  150. $_W['container'] = 'ipad';
  151. } elseif ($_W['container'] == Agent::BROWSER_TYPE_IPHONE) {
  152. $_W['container'] = 'iphone';
  153. } elseif ($_W['container'] == Agent::BROWSER_TYPE_IPOD) {
  154. $_W['container'] = 'ipod';
  155. } elseif ($_W['container'] == Agent::BROWSER_TYPE_XZAPP) {
  156. $_W['container'] = 'baidu';
  157. } else {
  158. $_W['container'] = 'unknown';
  159. }
  160. if ($_W['container'] == 'wechat' || $_W['container'] == 'baidu') {
  161. $_W['platform'] = 'account';
  162. }
  163. $controller = $_GPC['c'];
  164. $action = $_GPC['a'];
  165. $do = $_GPC['do'];
  166. header('Content-Type: text/html; charset=' . $_W['charset']);