PageRenderTime 69ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/libraries/common.inc.php

https://github.com/sahilbabu/phpb2b
PHP | 195 lines | 39 code | 0 blank | 156 comment | 11 complexity | 0b41c477ada471d19cfc8271f87a7c16 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
  4. * The contents of this file are subject to the License; you may not use this file except in compliance with the License.
  5. *
  6. * @version $Revision: 2148 $
  7. */
  8. define('IN_PHPB2B', TRUE);
  9. define('PHPB2B_ROOT', substr(dirname(__FILE__), 0, -9));
  10. define('MAGIC_QUOTES_GPC', function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc());
  11. if (!defined('DIRECTORY_SEPARATOR')) {
  12. define('DIRECTORY_SEPARATOR','/');
  13. }
  14. define('DS', DIRECTORY_SEPARATOR);
  15. require(PHPB2B_ROOT. 'configs'.DS.'config.inc.php');
  16. if($app_lang == "en") $app_lang = "en-us";//for older version
  17. /**
  18. * PHPB2B Debug Level
  19. * Myabe 0-5
  20. */
  21. if(!isset($debug)) $debug = 0;
  22. require(PHPB2B_ROOT. 'libraries'.DS.'global.func.php');
  23. require(PHPB2B_ROOT. 'configs'.DS.'paths.php');
  24. list($accept_language) = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
  25. //$accept_languages = unserialize($_PB_CACHE['setting']['languages']);
  26. if(is_file(CACHE_ROOT.strtolower($accept_language).DS."lang_site.php")) $app_lang = strtolower($accept_language);
  27. if (isset($_COOKIE[$cookiepre.'lang'])) {
  28. $app_lang = $_COOKIE[$cookiepre.'lang'];
  29. }
  30. if (isset($_GET['app_lang'])) {
  31. $app_lang = $_GET['app_lang'];
  32. }
  33. define('CACHE_COMMON_PATH', PHPB2B_ROOT."data".DS."cache".DS);
  34. define('CACHE_PATH', PHPB2B_ROOT."data".DS."cache".DS.$app_lang.DS);
  35. define('CACHE_LANG_PATH', PHPB2B_ROOT."data".DS."cache".DS.$app_lang.DS);
  36. $msg = $show_ajax = null;
  37. if (!defined("LOCALE_PATH")) {
  38. define("LOCALE_PATH", PHPB2B_ROOT.'languages'.DS.$app_lang.DS);
  39. }
  40. $php_self = pb_getenv('PHP_SELF');
  41. $base_script = basename($php_self);
  42. list($basefilename) = explode('.', $base_script);
  43. define('WEBROOT_DIR', basename(dirname(dirname(__FILE__))));
  44. if(!defined('URL')) {
  45. $s = null;
  46. if (pb_getenv('HTTPS')) {
  47. $s ='s';
  48. }
  49. $hosts = 'http'.$s.'://'.pb_getenv('HTTP_HOST');
  50. $site_url = htmlspecialchars($hosts.preg_replace("/\/+(api|app)?\/*$/i", '', substr($php_self, 0, strrpos($php_self, '/'))).'/');
  51. if(WEBROOT_DIR!="www" && strpos($site_url, "/".WEBROOT_DIR)){
  52. $site_url = substr($site_url, 0, strpos($site_url, WEBROOT_DIR)+strlen(WEBROOT_DIR))."/";
  53. }else{
  54. $site_url = $hosts."/";
  55. }
  56. define('URL', $site_url);
  57. }
  58. $time_start = getmicrotime();
  59. $time_stamp = time();
  60. require(SOURCE_PATH. 'adodb'.DS.'adodb.inc.php');
  61. $pdb = ADONewConnection($database);
  62. require(LIB_PATH. 'template.class.php');
  63. $smarty = new TemplateEngines();
  64. $includes = array(
  65. LIB_PATH. 'logger.class.php',
  66. LIB_PATH. 'core/object.php',
  67. LIB_PATH. 'core/model.php',
  68. LIB_PATH. 'core/controller.php',
  69. LIB_PATH. 'core/view.php',
  70. );
  71. foreach ($includes as $inc) {
  72. if (!file_exists($inc)) {
  73. trigger_error(sprintf(L("file_not_exists", "msg", $inc)));
  74. }else{
  75. require($inc);
  76. }
  77. }
  78. $log = new Logger();
  79. $connected = $pdb->Connect($dbhost,$dbuser,$dbpasswd,$dbname);
  80. if(!$connected or empty($connected)) {
  81. $msg = L("db_conn_error", 'msg', $pdb->ErrorMsg());
  82. $msg.= "<br />".L("db_conn_error_no", 'msg', $pdb->ErrorNo());
  83. if (!file_exists(DATA_PATH. "install.lock")) {
  84. $msg.="<br /><a href='".URL."install/install.php'>".L("please_reinstall_program", "msg")."</a>";
  85. }
  86. require(LIB_PATH. "error.class.php");
  87. Errors::showError($msg, 'db');
  88. exit;
  89. }
  90. if($dbcharset && mysql_get_server_info() > '4.1') {
  91. $pdb->Execute("SET NAMES '{$dbcharset}'");
  92. }
  93. //caches check
  94. if (!file_exists(CACHE_COMMON_PATH. "cache_setting.php") || !file_exists(CACHE_LANG_PATH. "lang_site.php")) {
  95. require(LIB_PATH. "cache.class.php");
  96. $cache = new Caches();
  97. if($cache->cacheAll()){
  98. $msg.="<a href='".pb_getenv('REQUEST_URI')."'>Cached successfully, please refresh.</a>";
  99. header_sent($msg);
  100. exit;
  101. }
  102. }
  103. $cachelost = (include CACHE_COMMON_PATH. 'cache_setting.php') ? '' : 'settings';
  104. $phpb2b_auth_key = $_PB_CACHE['setting']['auth_key'];
  105. if($headercharset) {
  106. @header('Content-Type: text/html; charset='.$charset);
  107. }
  108. //STATIC_CHECK, IF DON'T NEED, YOU CAN DELETE ME.
  109. //Todo:ARCHIVER
  110. $path_parts = pathinfo($php_self);
  111. $dir_name = PHPB2B_ROOT.'archiver'.$path_parts['dirname'].DS;
  112. if (isset($cache_archiver)){
  113. if(isset($htmlize) && !empty($_PB_CACHE['setting']['main_cache'])) {
  114. $default_html_filename = $dir_name.basename(pb_getenv('PHP_SELF'), ".php").'-'.md5(pb_getenv('REQUEST_URI')).'.htm';
  115. $show_ajax = true;
  116. if ($_PB_CACHE['setting']['main_cache_lifetime']>0) {
  117. //if not the office member and adminer,make the static html page.
  118. if (! file_exists ( $default_html_filename )) {
  119. $re_create_file = true;
  120. } else {
  121. $time_sep = time () - @filemtime ( $default_html_filename );
  122. if ($time_sep < $_PB_CACHE ['setting'] ['main_cache_lifetime']) {
  123. $contents = file_get_contents ( $default_html_filename );
  124. echo $contents;
  125. exit ();
  126. }
  127. }
  128. }
  129. }
  130. }
  131. //END static check
  132. //timezone
  133. if (isset($_PB_CACHE['setting']['time_offset'])){
  134. $time_offset = trim($_PB_CACHE['setting']['time_offset']);
  135. $date_format = isset($_PB_CACHE['setting']['date_format'])?$_PB_CACHE['setting']['date_format']:"Y-m-d";
  136. $time_now = array('time' => gmdate("{$date_format} H:i", $time_stamp + 3600 * $time_offset),
  137. 'offset' => ($time_offset >= 0 ? ($time_offset == 0 ? '' : '+'.$time_offset) : $time_offset));
  138. if(PHP_VERSION > '5.1') {
  139. @date_default_timezone_set('Etc/GMT'.($time_offset > 0 ? '-' : '+').(abs($time_offset)));
  140. }else{
  141. @putenv("TZ=GMT".$time_now['offset']);
  142. }
  143. }
  144. $date_line = date("Y-m-d H:i:s", $time_stamp);
  145. $viewhelper = new PbView();
  146. $conditions = null;
  147. $pb_userinfo = pb_get_member_info();
  148. if ($pb_userinfo) {
  149. $pb_user = $pb_userinfo;
  150. $pb_user = pb_addslashes($pb_user);
  151. uaAssign($pb_userinfo);
  152. }
  153. $js_language = $app_lang;
  154. $_G = array(
  155. 'SiteUrl'=>URL,
  156. 'charset'=>$charset,
  157. 'AppLanguage'=>$app_lang,
  158. 'WebRootUrl'=>$absolute_uri,
  159. 'TemplateDir'=>'templates',
  160. 'JsLanguage'=>$js_language,
  161. 'cookiepre'=>$cookiepre,
  162. 'cookiedomain'=>$cookiedomain,
  163. 'cookiepath'=>$cookiepath
  164. );
  165. uaAssign($_G);
  166. if (!empty($_PB_CACHE['setting']['site_theme_styles'])) {
  167. $_PB_CACHE['setting']['site_theme_styles'] = unserialize($_PB_CACHE['setting']['site_theme_styles']);
  168. }
  169. //at c, use $G;v, $_G.
  170. $G = pb_lang_split_recursive($_PB_CACHE['setting']);
  171. setvar("_G", $G);
  172. uaAssign($G);
  173. if ($show_ajax) {
  174. setvar('show_ajax', 1);
  175. }
  176. if(!MAGIC_QUOTES_GPC) {
  177. $_GET = pb_addslashes($_GET);
  178. $_POST = pb_addslashes($_POST);
  179. $_COOKIE = pb_addslashes($_COOKIE);
  180. }
  181. $pre_length = strlen($cookiepre);
  182. foreach($_COOKIE as $key => $val) {
  183. if(substr($key, 0, $pre_length) == $cookiepre) {
  184. $_UCOOKIE[(substr($key, $pre_length))] = MAGIC_QUOTES_GPC ? $val : pb_addslashes($val);
  185. }
  186. }
  187. $pre_refer = empty($_SERVER['HTTP_REFERER'])?'':$_SERVER['HTTP_REFERER'];
  188. if($gzipcompress && function_exists('ob_gzhandler')) {
  189. ob_start('ob_gzhandler');
  190. } else {
  191. $gzipcompress = 0;
  192. ob_start();
  193. }
  194. ?>