bootstrap.inc.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.we7.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('pdo');
  33. load()->classs('account');
  34. load()->model('cache');
  35. load()->model('account');
  36. load()->model('setting');
  37. load()->model('module');
  38. load()->library('agent');
  39. load()->classs('db');
  40. load()->func('communication');
  41. define('CLIENT_IP', getip());
  42. $_W['config'] = $config;
  43. $_W['config']['db']['tablepre'] = !empty($_W['config']['db']['master']['tablepre']) ? $_W['config']['db']['master']['tablepre'] : $_W['config']['db']['tablepre'];
  44. $_W['timestamp'] = TIMESTAMP;
  45. $_W['charset'] = $_W['config']['setting']['charset'];
  46. $_W['clientip'] = CLIENT_IP;
  47. unset($configfile, $config);
  48. define('ATTACHMENT_ROOT', IA_ROOT .'/attachment/');
  49. define('DEVELOPMENT', $_W['config']['setting']['development'] == 1);
  50. if(DEVELOPMENT) {
  51. ini_set('display_errors', '1');
  52. error_reporting(E_ALL ^ E_NOTICE);
  53. } else {
  54. error_reporting(0);
  55. }
  56. if(!in_array($_W['config']['setting']['cache'], array('mysql', 'memcache', 'redis'))) {
  57. $_W['config']['setting']['cache'] = 'mysql';
  58. }
  59. load()->func('cache');
  60. if(function_exists('date_default_timezone_set')) {
  61. date_default_timezone_set($_W['config']['setting']['timezone']);
  62. }
  63. if(!empty($_W['config']['setting']['memory_limit']) && function_exists('ini_get') && function_exists('ini_set')) {
  64. if(@ini_get('memory_limit') != $_W['config']['setting']['memory_limit']) {
  65. @ini_set('memory_limit', $_W['config']['setting']['memory_limit']);
  66. }
  67. }
  68. if (isset($_W['config']['setting']['https']) && $_W['config']['setting']['https'] == '1') {
  69. $_W['ishttps'] = $_W['config']['setting']['https'];
  70. } else {
  71. $_W['ishttps'] = $_SERVER['SERVER_PORT'] == 443 ||
  72. (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ||
  73. strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' ||
  74. strtolower($_SERVER['HTTP_X_CLIENT_SCHEME']) == 'https' ? true : false;
  75. }
  76. $_W['isajax'] = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
  77. $_W['ispost'] = $_SERVER['REQUEST_METHOD'] == 'POST';
  78. $_W['sitescheme'] = $_W['ishttps'] ? 'https://' : 'http://';
  79. $_W['script_name'] = htmlspecialchars(scriptname());
  80. $sitepath = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
  81. $_W['siteroot'] = htmlspecialchars($_W['sitescheme'] . $_SERVER['HTTP_HOST'] . $sitepath);
  82. if(substr($_W['siteroot'], -1) != '/') {
  83. $_W['siteroot'] .= '/';
  84. }
  85. $urls = parse_url($_W['siteroot']);
  86. $urls['path'] = str_replace(array('/web', '/app', '/payment/wechat', '/payment/alipay', '/payment/jueqiymf', '/api'), '', $urls['path']);
  87. $_W['siteroot'] = $urls['scheme'].'://'.$urls['host'].((!empty($urls['port']) && $urls['port']!='80') ? ':'.$urls['port'] : '').$urls['path'];
  88. if(MAGIC_QUOTES_GPC) {
  89. $_GET = istripslashes($_GET);
  90. $_POST = istripslashes($_POST);
  91. $_COOKIE = istripslashes($_COOKIE);
  92. }
  93. foreach($_GET as $key => $value) {
  94. if (is_string($value) && !is_numeric($value)) {
  95. $value = safe_gpc_string($value);
  96. }
  97. $_GET[$key] = $_GPC[$key] = $value;
  98. }
  99. $cplen = strlen($_W['config']['cookie']['pre']);
  100. foreach($_COOKIE as $key => $value) {
  101. if(substr($key, 0, $cplen) == $_W['config']['cookie']['pre']) {
  102. $_GPC[substr($key, $cplen)] = $value;
  103. }
  104. }
  105. unset($cplen, $key, $value);
  106. $_GPC = array_merge($_GPC, $_POST);
  107. $_GPC = ihtmlspecialchars($_GPC);
  108. $_W['siteurl'] = $urls['scheme'].'://'.$urls['host'].((!empty($urls['port']) && $urls['port']!='80') ? ':'.$urls['port'] : '') . $_W['script_name'] . '?' . http_build_query($_GET, '', '&');
  109. if (!$_W['isajax']) {
  110. $input = file_get_contents("php://input");
  111. if (!empty($input)) {
  112. $__input = @json_decode($input, true);
  113. if (!empty($__input)) {
  114. $_GPC['__input'] = $__input;
  115. $_W['isajax'] = true;
  116. }
  117. }
  118. unset($input, $__input);
  119. }
  120. setting_load();
  121. if (empty($_W['setting']['upload'])) {
  122. $_W['setting']['upload'] = array_merge($_W['config']['upload']);
  123. }
  124. $_W['os'] = Agent::deviceType();
  125. if($_W['os'] == Agent::DEVICE_MOBILE) {
  126. $_W['os'] = 'mobile';
  127. } elseif($_W['os'] == Agent::DEVICE_DESKTOP) {
  128. $_W['os'] = 'windows';
  129. } else {
  130. $_W['os'] = 'unknown';
  131. }
  132. $_W['container'] = Agent::browserType();
  133. if(Agent::isMicroMessage() == Agent::MICRO_MESSAGE_YES) {
  134. $_W['container'] = 'wechat';
  135. } elseif ($_W['container'] == Agent::BROWSER_TYPE_ANDROID) {
  136. $_W['container'] = 'android';
  137. } elseif ($_W['container'] == Agent::BROWSER_TYPE_IPAD) {
  138. $_W['container'] = 'ipad';
  139. } elseif ($_W['container'] == Agent::BROWSER_TYPE_IPHONE) {
  140. $_W['container'] = 'iphone';
  141. } elseif ($_W['container'] == Agent::BROWSER_TYPE_IPOD) {
  142. $_W['container'] = 'ipod';
  143. } else {
  144. $_W['container'] = 'unknown';
  145. }
  146. $controller = $_GPC['c'];
  147. $action = $_GPC['a'];
  148. $do = $_GPC['do'];
  149. header('Content-Type: text/html; charset=' . $_W['charset']);