国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

304 satır
9.5KB

  1. <?php
  2. /**
  3. * 系统核心函数存放文件
  4. * @version $Id: common.func.php 4 16:39 2010年7月6日Z tianya $
  5. * @package DedeBIZ.Libraries
  6. * @copyright Copyright (c) 2020, DedeBIZ.COM
  7. * @license https://www.dedebiz.com/license
  8. * @link https://www.dedebiz.com
  9. */
  10. if (!defined('DEDEINC')) exit('dedebiz');
  11. if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
  12. if (!function_exists('mysql_connect') and function_exists('mysqli_connect')) {
  13. function mysql_connect($server, $username, $password)
  14. {
  15. return mysqli_connect($server, $username, $password);
  16. }
  17. }
  18. if (!function_exists('mysql_query') and function_exists('mysqli_query')) {
  19. function mysql_query($query, $link)
  20. {
  21. return mysqli_query($link, $query);
  22. }
  23. }
  24. if (!function_exists('mysql_select_db') and function_exists('mysqli_select_db')) {
  25. function mysql_select_db($database_name, $link)
  26. {
  27. return mysqli_select_db($link, $database_name);
  28. }
  29. }
  30. if (!function_exists('mysql_fetch_array') and function_exists('mysqli_fetch_array')) {
  31. function mysql_fetch_array($result)
  32. {
  33. return mysqli_fetch_array($result);
  34. }
  35. }
  36. if (!function_exists('mysql_close') and function_exists('mysqli_close')) {
  37. function mysql_close($link)
  38. {
  39. return mysqli_close($link);
  40. }
  41. }
  42. if (!function_exists('split')) {
  43. function split($pattern, $string)
  44. {
  45. return explode($pattern, $string);
  46. }
  47. }
  48. }
  49. function make_hash()
  50. {
  51. $rand = dede_random_bytes(16);
  52. $_SESSION['token'] = ($rand === FALSE)
  53. ? md5(uniqid(mt_rand(), TRUE))
  54. : bin2hex($rand);
  55. return $_SESSION['token'];
  56. }
  57. function dede_random_bytes($length)
  58. {
  59. if (empty($length) or !ctype_digit((string) $length)) {
  60. return FALSE;
  61. }
  62. if (function_exists('openssl_random_pseudo_bytes')) {
  63. return openssl_random_pseudo_bytes($length);
  64. }
  65. if (function_exists('random_bytes')) {
  66. try {
  67. return random_bytes((int) $length);
  68. } catch (Exception $e) {
  69. return FALSE;
  70. }
  71. }
  72. if (defined('MCRYPT_DEV_URANDOM') && ($output = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)) !== FALSE) {
  73. return $output;
  74. }
  75. if (is_readable('/dev/urandom') && ($fp = fopen('/dev/urandom', 'rb')) !== FALSE) {
  76. version_compare(PHP_VERSION, '5.4.0', '>=') && stream_set_chunk_size($fp, $length);
  77. $output = fread($fp, $length);
  78. fclose($fp);
  79. if ($output !== FALSE) {
  80. return $output;
  81. }
  82. }
  83. return FALSE;
  84. }
  85. /**
  86. * 载入小助手,系统默认载入小助手
  87. * 在/data/helper.inc.php中进行默认小助手初始化的设置
  88. * 使用示例:
  89. * 在开发中,首先需要创建一个小助手函数,目录在\include\helpers中
  90. * 例如,我们创建一个示例为test.helper.php,文件基本内容如下:
  91. * <code>
  92. * if ( ! function_exists('HelloDede'))
  93. * {
  94. * function HelloDede()
  95. * {
  96. * echo "Hello! Dede...";
  97. * }
  98. * }
  99. * </code>
  100. * 则我们在开发中使用这个小助手的时候直接使用函数helper('test');初始化它
  101. * 然后在文件中就可以直接使用:HelloDede();来进行调用.
  102. *
  103. * @access public
  104. * @param mix $helpers 小助手名称,可以是数组,可以是单个字符串
  105. * @return void
  106. */
  107. $_helpers = array();
  108. function helper($helpers)
  109. {
  110. //如果是数组,则进行递归操作
  111. if (is_array($helpers)) {
  112. foreach ($helpers as $dede) {
  113. helper($dede);
  114. }
  115. return;
  116. }
  117. if (isset($_helpers[$helpers])) {
  118. return;
  119. }
  120. if (file_exists(DEDEINC . '/helpers/' . $helpers . '.helper.php')) {
  121. include_once(DEDEINC . '/helpers/' . $helpers . '.helper.php');
  122. $_helpers[$helpers] = TRUE;
  123. }
  124. // 无法载入小助手
  125. if (!isset($_helpers[$helpers])) {
  126. exit('Unable to load the requested file: helpers/' . $helpers . '.helper.php');
  127. }
  128. }
  129. function dede_htmlspecialchars($str)
  130. {
  131. global $cfg_soft_lang;
  132. if (version_compare(PHP_VERSION, '5.4.0', '<')) return htmlspecialchars($str);
  133. if ($cfg_soft_lang == 'gb2312') return htmlspecialchars($str, ENT_COMPAT, 'ISO-8859-1');
  134. else return htmlspecialchars($str);
  135. }
  136. /**
  137. * 载入小助手,这里用户可能载入用helps载入多个小助手
  138. *
  139. * @access public
  140. * @param string
  141. * @return string
  142. */
  143. function helpers($helpers)
  144. {
  145. helper($helpers);
  146. }
  147. //兼容php4的file_put_contents
  148. if (!function_exists('file_put_contents')) {
  149. function file_put_contents($n, $d)
  150. {
  151. $f = @fopen($n, "w");
  152. if (!$f) {
  153. return FALSE;
  154. } else {
  155. fwrite($f, $d);
  156. fclose($f);
  157. return TRUE;
  158. }
  159. }
  160. }
  161. /**
  162. * 显示更新信息
  163. *
  164. * @return void
  165. */
  166. function UpdateStat()
  167. {
  168. include_once(DEDEINC . "/inc/inc_stat.php");
  169. return SpUpdateStat();
  170. }
  171. $arrs1 = array(0x63, 0x66, 0x67, 0x5f, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x62, 0x79);
  172. $arrs2 = array(
  173. 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f,
  174. 0x77, 0x77, 0x77, 0x2e, 0x64, 0x65, 0x64, 0x65, 0x63, 0x6d, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x20, 0x74, 0x61, 0x72,
  175. 0x67, 0x65, 0x74, 0x3d, 0x27, 0x5f, 0x62, 0x6c, 0x61, 0x6e, 0x6b, 0x27, 0x3e, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x20,
  176. 0x62, 0x79, 0x20, 0x44, 0x65, 0x64, 0x65, 0x43, 0x6d, 0x73, 0x3c, 0x2f, 0x61, 0x3e
  177. );
  178. /**
  179. * 短消息函数,可以在某个动作处理后友好的提示信息
  180. *
  181. * @param string $msg 消息提示信息
  182. * @param string $gourl 跳转地址
  183. * @param int $onlymsg 仅显示信息
  184. * @param int $limittime 限制时间
  185. * @return void
  186. */
  187. function ShowMsg($msg, $gourl, $onlymsg = 0, $limittime = 0)
  188. {
  189. global $cfg_soft_lang, $cfg_cmsurl;
  190. if (empty($GLOBALS['cfg_plus_dir'])) $GLOBALS['cfg_plus_dir'] = '..';
  191. $htmlhead = "<html>\r\n<head>\r\n<title>DedeBIZ提示信息</title>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset={$cfg_soft_lang}\" />\r\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">";
  192. $htmlhead .= "<link rel=\"stylesheet\" href=\"{$cfg_cmsurl}/static/css/bootstrap.min.css\"><style>.modal {position: static;}</style><link href=\"{$cfg_cmsurl}/static/font-awesome/css/font-awesome.min.css\" rel=\"stylesheet\">";
  193. $htmlhead .= "<base target='_self'/></head>\r\n<body leftmargin='0' topmargin='0' bgcolor='#FFFFFF'>" . (isset($GLOBALS['ucsynlogin']) ? $GLOBALS['ucsynlogin'] : '') . "\r\n<center>\r\n<script>\r\n";
  194. $htmlfoot = "</script>\r\n</center>\r\n</body>\r\n</html>\r\n";
  195. $litime = ($limittime == 0 ? 1000 : $limittime);
  196. $func = '';
  197. if ($gourl == '-1') {
  198. if ($limittime == 0) $litime = 5000;
  199. $gourl = "javascript:history.go(-1);";
  200. }
  201. if ($gourl == '' || $onlymsg == 1) {
  202. $msg = "<script>alert(\"" . str_replace("\"", "“", $msg) . "\");</script>";
  203. } else {
  204. //当网址为:close::objname 时, 关闭父框架的id=objname元素
  205. if (preg_match('/close::/', $gourl)) {
  206. $tgobj = trim(preg_replace('/close::/', '', $gourl));
  207. $gourl = 'javascript:;';
  208. $func .= "window.parent.document.getElementById('{$tgobj}').style.display='none';\r\n";
  209. }
  210. $func .= " var pgo=0;
  211. function JumpUrl(){
  212. if(pgo==0){ location='$gourl'; pgo=1; }
  213. }\r\n";
  214. $rmsg = $func;
  215. $rmsg .= "document.write(\"<main class='container'><div class='modal' tabindex='-1' role='dialog' style='display:block'><div class='modal-dialog'><div class='modal-content'><div class='modal-header'><h6 class='modal-title'>";
  216. $rmsg .= "DedeBIZ 提示信息!</h6></div><div class='modal-body'>\");\r\n";
  217. $rmsg .= "document.write(\"" . str_replace("\"", "“", $msg) . "\");\r\n";
  218. $rmsg .= "document.write(\"";
  219. if ($onlymsg == 0) {
  220. if ($gourl != 'javascript:;' && $gourl != '') {
  221. $rmsg .= "<br /><a href='{$gourl}'>如果你的浏览器没反应,请点击这里...</a>";
  222. $rmsg .= "</div></div></div></div></main>\");\r\n";
  223. $rmsg .= "setTimeout('JumpUrl()',$litime);";
  224. } else {
  225. $rmsg .= "</div></div></div></div></main>\");\r\n";
  226. }
  227. } else {
  228. $rmsg .= "</div></div></div></div></main>\");\r\n";
  229. }
  230. $msg = $htmlhead . $rmsg . $htmlfoot;
  231. }
  232. echo $msg;
  233. }
  234. /**
  235. * 获取验证码的session值
  236. *
  237. * @return string
  238. */
  239. function GetCkVdValue()
  240. {
  241. @session_id($_COOKIE['PHPSESSID']);
  242. @session_start();
  243. return isset($_SESSION['securimage_code_value']) ? $_SESSION['securimage_code_value'] : '';
  244. }
  245. /**
  246. * PHP某些版本有Bug,不能在同一作用域中同时读session并改注销它,因此调用后需执行本函数
  247. *
  248. * @return void
  249. */
  250. function ResetVdValue()
  251. {
  252. @session_start();
  253. $_SESSION['securimage_code_value'] = '';
  254. }
  255. function IndexSub($idx, $num)
  256. {
  257. return intval($idx) - intval($num) == 0 ? '0 ' : intval($idx) - intval($num);
  258. }
  259. // 用来返回index的active
  260. function IndexActive($idx)
  261. {
  262. if ($idx == 1) {
  263. return ' active';
  264. } else {
  265. return '';
  266. }
  267. }
  268. // 自定义函数接口
  269. // 这里主要兼容早期的用户扩展,v5.7之后我们建议使用小助手helper进行扩展
  270. if (file_exists(DEDEINC . '/extend.func.php')) {
  271. require_once(DEDEINC . '/extend.func.php');
  272. }