国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

296 lines
11KB

  1. <?php
  2. /**
  3. * @version $id:common.inc.php 2025 tianya $
  4. * @package DedeBIZ.Libraries
  5. * @copyright Copyright (c) 2022 DedeBIZ.COM
  6. * @license GNU GPL v2 (https://www.dedebiz.com/license)
  7. * @link https://www.dedebiz.com
  8. */
  9. //系统默认运行模式为安全模式,模板管理、标签管理、数据库管理、模块管理等功能已暂停,如果您需要这些功能,DEDEBIZ_SAFE_MODE后面值`TRUE`改为`FALSE`恢复使用
  10. define('DEDEBIZ_SAFE_MODE', TRUE);
  11. //生产环境使用`production`,如果采用`dev`模式,会有一些php的报错信息提示,用于开发调试
  12. if (!defined('DEDE_ENVIRONMENT')) {
  13. define('DEDE_ENVIRONMENT', 'production');
  14. }
  15. if (!defined('DEBUG_LEVEL')) {
  16. if (DEDE_ENVIRONMENT == 'production') {
  17. define('DEBUG_LEVEL', FALSE);
  18. } else {
  19. define('DEBUG_LEVEL', TRUE);
  20. }
  21. }
  22. if (DEDE_ENVIRONMENT == 'production') {
  23. ini_set('display_errors', 0);
  24. if (version_compare(PHP_VERSION, '5.3', '>=')) {
  25. error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
  26. } else {
  27. error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
  28. }
  29. } else {
  30. error_reporting(-1);
  31. ini_set('display_errors', 1);
  32. }
  33. define('DEDEINC', str_replace("\\", '/', dirname(__FILE__)));
  34. define('DEDEROOT', str_replace("\\", '/', substr(DEDEINC, 0, -6))); //站点根目录
  35. define('DEDEDATA', substr(DEDEINC, 0, -6).'data');
  36. define('DEDESTATIC', DEDEROOT.'/static');
  37. define('DEDEMEMBER', DEDEROOT.'/user');
  38. define('DEDETEMPLATE', DEDEROOT.'/theme');
  39. define('DEDEBIZURL', "https://www.dedebiz.com");//DedeBiz商业支持
  40. define('DEDEBIZCDN', "https://cdn.dedebiz.com");//DedeBizCDN镜像
  41. define('DEDEVER', 6);//当前系统大版本
  42. define('DEDEPUB', '
  43. -----BEGIN PUBLIC KEY-----
  44. MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvupO2Lixns34bBqwTzK0
  45. 9wA9sfGBdgc03zh1sUacieJBikx08e7xmkJbMF81jb/YfNGW/+iJ3qHULdc9Dtd3
  46. +FsnHG+tUDnzjkPnVVmnrjucQqfHRRVKKAgXOWxtuRKUVF3NDjiJtDAf5Y2BMAhw
  47. oqzeepye5I4mWyO4A8/V2ougO+xDK426MIf1dq+W59NVZj8k+zeZrbPh7+fPFw4u
  48. PwAMpkTJJ9nwNOO6saH2eMGaQ3oxZIQ+SmminDB8miI/+hwIn2hNmaHFuur0OGlB
  49. NQabUzX9JoYtXqPcpZRT7ymHrppU0KFdUSEJiW0utTWJo0HrDOBIT5qWlM0MP9p/
  50. PwIDAQAB
  51. -----END PUBLIC KEY-----
  52. ');//DedeBIZ系统公钥
  53. define('DEDECDNURL', 'https://cdn.dedebiz.com');//默认静态资源地址
  54. define('DEDEBIZSEARCH', FALSE);//是否启用DedeBIZ全文检索服务
  55. define('DEDEBIZSEARCHHOST', 'http://127.0.0.1:8818');//搜索服务地址
  56. define('DEDEBIZSEARCHKEY', '设置DedeSearch密钥');//用于进行加密验签
  57. if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
  58. if (!function_exists('session_register')) {
  59. function session_register()
  60. {
  61. $args = func_get_args();
  62. foreach ($args as $key) {
  63. $_SESSION[$key] = $GLOBALS[$key];
  64. }
  65. }
  66. function session_is_registered($key)
  67. {
  68. return isset($_SESSION[$key]);
  69. }
  70. function session_unregister($key)
  71. {
  72. unset($_SESSION[$key]);
  73. }
  74. }
  75. }
  76. //是否启用mb_substr替换cn_substr来提高效率
  77. $cfg_is_mb = $cfg_is_iconv = FALSE;
  78. if (function_exists('mb_substr')) $cfg_is_mb = TRUE;
  79. if (function_exists('iconv_substr')) $cfg_is_iconv = TRUE;
  80. function _RunMagicQuotes(&$svar)
  81. {
  82. if (is_array($svar)) {
  83. foreach ($svar as $_k => $_v) {
  84. if ($_k == 'nvarname') continue;
  85. _RunMagicQuotes($_k);
  86. $svar[$_k] = _RunMagicQuotes($_v);
  87. }
  88. } else {
  89. if (strlen($svar) > 0 && preg_match('#^(cfg_|GLOBALS|_GET|_REQUEST|_POST|_COOKIE|_SESSION)#', $svar)) {
  90. exit('The requested operation is forbidden');
  91. }
  92. $svar = addslashes($svar);
  93. }
  94. return $svar;
  95. }
  96. foreach (array('_GET', '_POST', '_COOKIE') as $_req) {
  97. foreach ($$_req as $_k => $_v) {
  98. if (preg_match('#^(cfg_|GLOBALS|_GET|_REQUEST|_POST|_COOKIE|_SESSION)#', $_k)) {
  99. exit('The requested operation is forbidden');
  100. }
  101. if ($_k == 'nvarname') ${$_k} = $_v;
  102. else ${$_k} = _RunMagicQuotes($_v);
  103. }
  104. }
  105. //系统相关变量检测
  106. if (!isset($needFilter)) {
  107. $needFilter = FALSE;
  108. }
  109. $registerGlobals = @ini_get("register_globals");
  110. $isUrlOpen = @ini_get("allow_url_fopen");
  111. //系统配置参数
  112. if (!file_exists(DEDEDATA."/config.cache.inc.php") && !defined('DEDE_CLITOOLS')) {
  113. die('DedeBIZ初始化失败,确保系统正确被安装');
  114. }
  115. if (file_exists(DEDEDATA."/config.cache.inc.php")) {
  116. require_once(DEDEDATA."/config.cache.inc.php");
  117. }
  118. //Session保存路径
  119. $sessSaveHandler = @ini_get("session.save_handler");
  120. if ($sessSaveHandler !== "files") {
  121. @ini_set("session.save_handler", "files");
  122. }
  123. $enkey = substr(md5(substr($cfg_cookie_encode, 0, 5)), 0, 10);
  124. $sessSavePath = DEDEDATA."/sessions_{$enkey}";
  125. if (!is_dir($sessSavePath)) mkdir($sessSavePath);
  126. if (is_writeable($sessSavePath) && is_readable($sessSavePath)) {
  127. @session_save_path($sessSavePath);
  128. }
  129. require_once DEDEINC.'/dedealert.func.php';
  130. //转换上传的文件相关的变量及安全处理,并引用前台通用的上传函数
  131. if ($_FILES) {
  132. require_once(DEDEINC.'/uploadsafe.inc.php');
  133. }
  134. //数据库配置文件
  135. if (file_exists(DEDEDATA.'/common.inc.php')) {
  136. require_once(DEDEDATA.'/common.inc.php');
  137. } else {
  138. $cfg_dbtype = $cfg_dbhost = $cfg_dbname= $cfg_dbuser = $cfg_dbpwd = $cfg_dbprefix = $cfg_db_language ='';//数据库类型
  139. }
  140. if (!isset($cfg_dbtype)) {
  141. $cfg_dbtype = 'mysql';
  142. }
  143. //Session跨域设置
  144. if (!empty($cfg_domain_cookie)) {
  145. @session_set_cookie_params(0, '/', $cfg_domain_cookie);
  146. }
  147. //php5.1版本以上时区设置,由于这个函数对于是php5.1以下版本并无意义,因此实际上的时间调用,应该用MyDate函数调用
  148. if (PHP_VERSION > '5.1') {
  149. $time51 = $cfg_cli_time * -1;
  150. @date_default_timezone_set('Etc/GMT'.$time51);
  151. }
  152. $cfg_isUrlOpen = @ini_get("allow_url_fopen");
  153. //会员浏览默认网址
  154. if (PHP_SAPI === 'cli') {
  155. $cfg_clihost = 'https://www.dedebiz.com';
  156. } else {
  157. $cfg_clihost = 'http://'.$_SERVER['HTTP_HOST'];
  158. }
  159. if (isset($cfg_cmspath)) {
  160. $cfg_cmspath = $cfg_cmspath;
  161. } else {
  162. $cfg_cmspath = '';
  163. }
  164. //站点根目录
  165. $cfg_basedir = preg_replace('#'.$cfg_cmspath.'\/system$#i', '', DEDEINC);
  166. if ($cfg_multi_site == 'Y') {
  167. $cfg_mainsite = $cfg_basehost;
  168. } else {
  169. $cfg_mainsite = '';
  170. }
  171. //模板存放目录
  172. $cfg_templets_dir = $cfg_cmspath.'/theme';
  173. $cfg_templeturl = $cfg_mainsite.$cfg_templets_dir;
  174. $cfg_templets_skin = empty($cfg_df_style) ? $cfg_mainsite.$cfg_templets_dir."/templets" : $cfg_mainsite.$cfg_templets_dir."/$cfg_df_style";
  175. //安装目录网址
  176. $cfg_cmsurl = $cfg_mainsite.$cfg_cmspath;
  177. //模块插件目录
  178. $cfg_plus_dir = $cfg_cmspath.'/apps';
  179. $cfg_phpurl = $cfg_mainsite.$cfg_plus_dir;
  180. //一些缓存配置数据存放目录
  181. $cfg_data_dir = $cfg_cmspath.'/data';
  182. $cfg_dataurl = $cfg_mainsite.$cfg_data_dir;
  183. //专题存放目录
  184. $cfg_special = $cfg_cmspath.'/a/special';
  185. $cfg_specialurl = $cfg_mainsite.$cfg_special;
  186. //会员会员目录
  187. $cfg_member_dir = $cfg_cmspath.'/user';
  188. $cfg_memberurl = $cfg_mainsite.$cfg_member_dir;
  189. //静态文件存放目录
  190. $cfg_static_dir = $cfg_cmspath.'/static';
  191. $cfg_staticurl = $cfg_mainsite.$cfg_static_dir;
  192. //上传图片存放目录,建议按默认
  193. $cfg_image_dir = $cfg_medias_dir.'/allimg';
  194. //会员投稿图片存放目录
  195. $cfg_user_dir = $cfg_medias_dir.'/userup';
  196. //上传软件存放目录
  197. $cfg_soft_dir = $cfg_medias_dir.'/soft';
  198. //上传多媒体文件存放目录
  199. $cfg_other_medias = $cfg_medias_dir.'/media';
  200. //附件目录
  201. $cfg_medias_dir = $cfg_cmspath.$cfg_medias_dir;
  202. $cfg_mediasurl = $cfg_mainsite.$cfg_medias_dir;
  203. //程序信息摘要,请不要删除则系统无法接收升级信息
  204. $cfg_version = 'V6';
  205. $cfg_version_detail = '6.5.2';//详细版本号
  206. $cfg_soft_lang = 'utf-8';
  207. $cfg_soft_public = 'base';
  208. $cfg_softname = '得德系统';
  209. $cfg_soft_enname = 'DedeV6';
  210. $cfg_soft_devteam = 'DedeBIZ';
  211. //文档的默认命名规则
  212. $art_shortname = $cfg_df_ext = '.html';
  213. $cfg_df_namerule = '{typedir}/{aid}'.$cfg_df_ext;
  214. //新建目录的权限,如果您使用别的属性,本程不保证程序能顺利在Linux或Unix系统运行
  215. $cfg_dir_purview = 0755;
  216. //Cookie设置
  217. $cfg_cookie_samesite = 'Lax'; //samesite属性(Lax, Strict or None)
  218. $cfg_cookie_secure = FALSE; //仅当存在安全的HTTPS连接时才会设置Cookie
  219. $cfg_cookie_httponly = FALSE; //只能通过HTTP(S)访问(无法通过JavaScript访问)
  220. //特殊全局变量
  221. $_sys_globals['curfile'] = '';
  222. $_sys_globals['typeid'] = 0;
  223. $_sys_globals['typename'] = '';
  224. $_sys_globals['aid'] = 0;
  225. if (empty($cfg_addon_savetype)) {
  226. $cfg_addon_savetype = 'Ymd';
  227. }
  228. if ($cfg_sendmail_bysmtp == 'Y' && !empty($cfg_smtp_usermail)) {
  229. $cfg_adminemail = $cfg_smtp_usermail;
  230. }
  231. //DedeBIZ商业化组件
  232. require_once(DEDEINC.'/libraries/dedebiz.class.php');
  233. //第三方SDKs
  234. require_once(DEDEINC.'/sdks/include.php');
  235. //对全局分页传递参数进行过滤
  236. if (isset($GLOBALS['PageNo'])) {
  237. $GLOBALS['PageNo'] = intval($GLOBALS['PageNo']);
  238. }
  239. if (isset($GLOBALS['TotalResult'])) {
  240. $GLOBALS['TotalResult'] = intval($GLOBALS['TotalResult']);
  241. }
  242. if (!isset($cfg_NotPrintHead)) {
  243. if (PHP_SAPI != 'cli') {
  244. if (defined('IS_DEDEAPI')) {
  245. header("Content-Type:text/json; charset={$cfg_soft_lang}");
  246. } else {
  247. header("Content-Type:text/html; charset={$cfg_soft_lang}");
  248. }
  249. }
  250. }
  251. //自动加载类库处理
  252. if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
  253. require_once(DEDEINC.'/autoload7.inc.php');
  254. } else {
  255. require_once(DEDEINC.'/autoload.inc.php');
  256. }
  257. $cfg_biz_helpUrl = DEDEBIZURL."/help";
  258. $cfg_biz_gitUrl = DEDEBIZURL."/git";
  259. $cfg_biz_dedebizUrl = DEDEBIZURL;
  260. //引入数据库类
  261. if (!defined('MYSQL_BOTH')) {
  262. define('MYSQL_BOTH', MYSQLI_BOTH);
  263. }
  264. if (!defined('MYSQL_ASSOC')) {
  265. define('MYSQL_ASSOC', MYSQLI_ASSOC);
  266. }
  267. if (!defined('MYSQL_NUM')) {
  268. define('MYSQL_NUM', MYSQLI_NUM);
  269. }
  270. //全局常用函数
  271. require_once(DEDEINC.'/common.func.php');
  272. if ($GLOBALS['cfg_dbtype'] == 'mysql' || $GLOBALS['cfg_dbtype'] == 'mysqli') {
  273. require_once(DEDEINC.'/database/dedesqli.class.php');
  274. } else {
  275. require_once(DEDEINC.'/database/dedesqlite.class.php');
  276. }
  277. //载入助手配置,并对其进行默认初始化
  278. $cfg_helper_autoload = array(
  279. 'charset', /* 编码助手 */
  280. 'channelunit',/* 模型单元助手 */
  281. 'string', /* 字符串助手 */
  282. 'time', /* 日期助手 */
  283. 'file', /* 文件助手 */
  284. 'util', /* 单元助手 */
  285. 'validate', /* 数据验证助手 */
  286. 'filter', /* 过滤器助手 */
  287. 'cookie', /* cookies助手 */
  288. 'debug', /* 调试助手 */
  289. 'archive', /* 文档助手 */
  290. 'upload', /* 上传助手 */
  291. 'extend', /* 扩展助手 */
  292. 'code', /* 代码助手 */
  293. );
  294. //初始化助手
  295. helper($cfg_helper_autoload);
  296. ?>