bootstrap.inc.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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='" . (false === strpos($_SERVER['SCRIPT_NAME'], 'web') ? './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 ($_W['config']['setting']['memory_limit'] != @ini_get('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'] = isset($_SERVER['SERVER_PORT']) && 443 == $_SERVER['SERVER_PORT'] ||
  67. (isset($_SERVER['HTTPS']) && 'off' != strtolower($_SERVER['HTTPS'])) ||
  68. isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) ||
  69. isset($_SERVER['HTTP_X_CLIENT_SCHEME']) && 'https' == strtolower($_SERVER['HTTP_X_CLIENT_SCHEME']) ? true : false;
  70. }
  71. $_W['isajax'] = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH']);
  72. $_W['ispost'] = isset($_SERVER['REQUEST_METHOD']) && 'POST' == $_SERVER['REQUEST_METHOD'];
  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'] . (isset($_SERVER['HTTP_HOST']) ? $_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. $urls['scheme'] = !empty($urls['scheme']) ? $urls['scheme'] : 'http';
  83. $urls['host'] = !empty($urls['host']) ? $urls['host'] : '';
  84. $_W['siteroot'] = $urls['scheme'] . '://' . $urls['host'] . ((!empty($urls['port']) && '80' != $urls['port']) ? ':' . $urls['port'] : '') . $urls['path'];
  85. if (MAGIC_QUOTES_GPC) {
  86. $_GET = istripslashes($_GET);
  87. $_POST = istripslashes($_POST);
  88. $_COOKIE = istripslashes($_COOKIE);
  89. }
  90. foreach ($_GET as $key => $value) {
  91. if (is_string($value) && !is_numeric($value)) {
  92. $value = safe_gpc_string($value);
  93. }
  94. $_GET[$key] = $_GPC[$key] = $value;
  95. }
  96. $cplen = strlen($_W['config']['cookie']['pre']);
  97. foreach ($_COOKIE as $key => $value) {
  98. if ($_W['config']['cookie']['pre'] == substr($key, 0, $cplen)) {
  99. $_GPC[substr($key, $cplen)] = $value;
  100. }
  101. }
  102. unset($cplen, $key, $value);
  103. $_GPC = array_merge($_GPC, $_POST);
  104. $_GPC = ihtmlspecialchars($_GPC);
  105. $_W['siteurl'] = $urls['scheme'] . '://' . $urls['host'] . ((!empty($urls['port']) && '80' != $urls['port']) ? ':' . $urls['port'] : '') . $_W['script_name'] . '?' . http_build_query($_GET, '', '&');
  106. if (!$_W['isajax']) {
  107. $input = file_get_contents('php://input');
  108. if (!empty($input)) {
  109. $__input = @json_decode($input, true);
  110. if (!empty($__input)) {
  111. $_GPC['__input'] = $__input;
  112. $_W['isajax'] = true;
  113. }
  114. }
  115. unset($input, $__input);
  116. }
  117. $_W['uniacid'] = $_W['uid'] = 0;
  118. define('DEVELOPMENT', $_W['config']['setting']['development'] == 1 || $_W['setting']['copyright']['develop_status'] ==1);
  119. if (DEVELOPMENT) {
  120. ini_set('display_errors', '1');
  121. error_reporting(E_ALL ^ E_NOTICE);
  122. }
  123. if ($_W['config']['setting']['development'] == 2) {
  124. load()->library('sentry');
  125. if (class_exists('Raven_Autoloader')) {
  126. error_reporting(E_ALL ^ E_NOTICE);
  127. Raven_Autoloader::register();
  128. $client = new Raven_Client('http://8d52c70dbbed4133b72e3b8916663ae3:0d84397f72204bf1a3f721edf9c782e1@sentry.w7.cc/6');
  129. $error_handler = new Raven_ErrorHandler($client);
  130. $error_handler->registerExceptionHandler();
  131. $error_handler->registerErrorHandler();
  132. $error_handler->registerShutdownFunction();
  133. }
  134. }
  135. setting_load();
  136. if (empty($_W['setting']['upload'])) {
  137. $_W['setting']['upload'] = array_merge($_W['config']['upload']);
  138. }
  139. $_W['os'] = Agent::deviceType();
  140. if (Agent::DEVICE_MOBILE == $_W['os']) {
  141. $_W['os'] = 'mobile';
  142. } elseif (Agent::DEVICE_DESKTOP == $_W['os']) {
  143. $_W['os'] = 'windows';
  144. } else {
  145. $_W['os'] = 'unknown';
  146. }
  147. $_W['container'] = Agent::browserType();
  148. if (Agent::MICRO_MESSAGE_YES == Agent::isMicroMessage()) {
  149. $_W['container'] = 'wechat';
  150. } elseif (Agent::BROWSER_TYPE_ANDROID == $_W['container']) {
  151. $_W['container'] = 'android';
  152. } elseif (Agent::BROWSER_TYPE_IPAD == $_W['container']) {
  153. $_W['container'] = 'ipad';
  154. } elseif (Agent::BROWSER_TYPE_IPHONE == $_W['container']) {
  155. $_W['container'] = 'iphone';
  156. } elseif (Agent::BROWSER_TYPE_IPOD == $_W['container']) {
  157. $_W['container'] = 'ipod';
  158. } elseif (Agent::BROWSER_TYPE_XZAPP == $_W['container']) {
  159. $_W['container'] = 'baidu';
  160. } else {
  161. $_W['container'] = 'unknown';
  162. }
  163. if ('wechat' == $_W['container'] || 'baidu' == $_W['container']) {
  164. $_W['platform'] = 'account';
  165. }
  166. $controller = !empty($_GPC['c']) ? $_GPC['c'] : '';
  167. $action = !empty($_GPC['a']) ? $_GPC['a'] : '';
  168. $do = !empty($_GPC['do']) ? $_GPC['do'] : '';
  169. header('Content-Type: text/html; charset=' . $_W['charset']);