国内流行的内容管理系统(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.

267 lines
9.1KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 系统核心函数存放文件
  5. * @version $Id: common.func.php 4 16:39 2010年7月6日Z tianya $
  6. * @package DedeBIZ.Libraries
  7. * @copyright Copyright (c) 2022, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  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();
  172. $arrs2 = array();
  173. /**
  174. * 短消息函数,可以在某个动作处理后友好的提示信息
  175. *
  176. * @param string $msg 消息提示信息
  177. * @param string $gourl 跳转地址
  178. * @param int $onlymsg 仅显示信息
  179. * @param int $limittime 限制时间
  180. * @return void
  181. */
  182. function ShowMsg($msg, $gourl, $onlymsg = 0, $limittime = 0)
  183. {
  184. global $cfg_soft_lang, $cfg_cmsurl;
  185. if(empty($GLOBALS['cfg_plus_dir'])) $GLOBALS['cfg_plus_dir'] = '..';
  186. $htmlhead = "<html><head><meta charset='utf-8'><title>提示信息</title><meta name='viewport' content='width=device-width,initial-scale=1'><base target='_self'></head>";
  187. $htmlhead .= "<body>".(isset($GLOBALS['ucsynlogin']) ? $GLOBALS['ucsynlogin'] : '')."<center><script>";
  188. $htmlfoot = "</script></center></body></html>";
  189. $litime = ($limittime == 0 ? 1000 : $limittime);
  190. $func = '';
  191. if ($gourl == '-1') {
  192. if ($limittime == 0) $litime = 5000;
  193. $gourl = "javascript:history.go(-1);";
  194. }
  195. if ($gourl == '' || $onlymsg == 1) {
  196. $msg = "<script>alert(\"".str_replace("\"", "“", $msg)."\");</script>";
  197. } else {
  198. //当网址为:close::objname 时, 关闭父框架的id=objname元素
  199. if (preg_match('/close::/', $gourl)) {
  200. $tgobj = trim(preg_replace('/close::/', '', $gourl));
  201. $gourl = 'javascript:;';
  202. $func .= "window.parent.document.getElementById('{$tgobj}').style.display='none';\r\n";
  203. }
  204. $func .= "var pgo=0;function JumpUrl(){if (pgo==0){location='$gourl'; pgo=1;}}";
  205. $rmsg = $func;
  206. $rmsg .= "document.write(\"<style>body{margin:0;line-height:1.5;font:14px Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;color:#424b51;background:#f2f2f2}a{color:#28a745;text-decoration:none}.tips{margin:68px auto 0;padding:0;width:420px;height:auto;background:#fff;border-radius:.2rem}.tips-head{margin:0 20px;padding:16px 0;border-bottom:1px solid #f6f6f6}.tips-head p{margin:0;padding-left:10px;line-height:16px;text-align:left;border-left:3px solid #ff5722}.tips-box{padding:20px;min-height:120px;color:#666}.btn a{display:inline-block;margin:20px auto 0;padding:.375rem .75rem;font-size:12px;color:#fff;background:#28a745;border-radius:.2rem;text-align:center;transition:all .6s}.btn a:focus{background:#006829;border-color:#005b24;box-shadow:0 0 0 0.2rem rgba(38,159,86,.5)}@media (max-width:768px){body{padding:0 15px}.tips{width:100%}}</style>\");";
  207. $rmsg .= "document.write(\"<div class='tips'>";
  208. $rmsg .= "<div class='tips-head'><p>提示信息</p></div>\");";
  209. $rmsg .= "document.write(\"<div class='tips-box'>\");";
  210. $rmsg .= "document.write(\"".str_replace("\"","“",$msg)."\");";
  211. $rmsg .= "document.write(\"";
  212. if($onlymsg==0)
  213. {
  214. if( $gourl != 'javascript:;' && $gourl != '')
  215. {
  216. $rmsg .= "<div class='btn'><a href='{$gourl}'>点击反应</a></div>\");";
  217. $rmsg .= "setTimeout('JumpUrl()',$litime);";
  218. } else {
  219. $rmsg .= "</div>\");";
  220. }
  221. } else {
  222. $rmsg .= "</div>\");";
  223. }
  224. $msg = $htmlhead.$rmsg.$htmlfoot;
  225. }
  226. echo $msg;
  227. }
  228. /**
  229. * 获取验证码的session值
  230. *
  231. * @return string
  232. */
  233. function GetCkVdValue()
  234. {
  235. @session_id($_COOKIE['PHPSESSID']);
  236. @session_start();
  237. return isset($_SESSION['securimage_code_value']) ? $_SESSION['securimage_code_value'] : '';
  238. }
  239. /**
  240. * PHP某些版本有Bug,不能在同一作用域中同时读session并改注销它,因此调用后需执行本函数
  241. *
  242. * @return void
  243. */
  244. function ResetVdValue()
  245. {
  246. @session_start();
  247. $_SESSION['securimage_code_value'] = '';
  248. }
  249. function IndexSub($idx, $num)
  250. {
  251. return intval($idx) - intval($num) == 0 ? '0 ' : intval($idx) - intval($num);
  252. }
  253. //用来返回index的active
  254. function IndexActive($idx)
  255. {
  256. if ($idx == 1) {
  257. return ' active';
  258. } else {
  259. return '';
  260. }
  261. }
  262. //自定义函数接口
  263. //这里主要兼容早期的用户扩展,v5.7之后我们建议使用小助手helper进行扩展
  264. if (file_exists(DEDEINC.'/extend.func.php')) {
  265. require_once(DEDEINC.'/extend.func.php');
  266. }