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

644 lines
27KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 系统核心函数存放文件
  5. *
  6. * @version $id:common.func.php 4 16:39 2010年7月6日 tianya $
  7. * @package DedeBIZ.Libraries
  8. * @copyright Copyright (c) 2022 DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. //类似Bootstrap警告框
  13. define('ALERT_PRIMARY', 1);
  14. define('ALERT_SECONDARY', 2);
  15. define('ALERT_SUCCESS', 3);
  16. define('ALERT_DANGER', 4);
  17. define('ALERT_WARNING', 5);
  18. define('ALERT_INFO', 6);
  19. define('ALERT_LIGHT', 7);
  20. define('ALERT_DARK', 8);
  21. define('ALERT_COLORS', array(
  22. ALERT_PRIMARY => array('#cfe2ff','#b6d4fe','#084298'),
  23. ALERT_SECONDARY => array('#e2e3e5','#d3d6d8','#41464b'),
  24. ALERT_SUCCESS => array('#d1e7dd','#badbcc','#0f5132'),
  25. ALERT_DANGER => array('#f8d7da','#f5c2c7','#842029'),
  26. ALERT_WARNING => array('#fff3cd','#ffecb5','#664d03'),
  27. ALERT_INFO => array('#cff4fc','#b6effb','#055160'),
  28. ALERT_LIGHT => array('#fefefe','#fdfdfe','#636464'),
  29. ALERT_DARK => array('#d3d3d4','#bcbebf','#141619'),
  30. ));
  31. define("ALERT_TPL", '<div style="position:relative;padding:.75rem 1.25rem;margin-bottom:1rem;width:auto;font-size:12px;color:~color~;background:~background~;border-color:~border~;border:1px solid transparent;border-radius:.5rem">~content~</div>');
  32. //$content:文档,$type:alert类型
  33. function DedeAlert($content, $type = ALERT_PRIMARY, $isHTML=false)
  34. {
  35. $content = $isHTML? RemoveXSS($content) : htmlspecialchars($content);
  36. $colors = isset(ALERT_COLORS[$type])? ALERT_COLORS[$type] : ALERT_COLORS[ALERT_PRIMARY];
  37. list($background, $border, $color) = $colors;
  38. return str_replace(array('~color~','~background~','~border~', '~content~'),array($color,$background,$border,$content),ALERT_TPL);
  39. }
  40. if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
  41. if (!function_exists('mysql_connect') and function_exists('mysqli_connect')) {
  42. function mysql_connect($server, $username, $password)
  43. {
  44. return mysqli_connect($server, $username, $password);
  45. }
  46. }
  47. if (!function_exists('mysql_query') and function_exists('mysqli_query')) {
  48. function mysql_query($query, $link)
  49. {
  50. return mysqli_query($link, $query);
  51. }
  52. }
  53. if (!function_exists('mysql_select_db') and function_exists('mysqli_select_db')) {
  54. function mysql_select_db($database_name, $link)
  55. {
  56. return mysqli_select_db($link, $database_name);
  57. }
  58. }
  59. if (!function_exists('mysql_fetch_array') and function_exists('mysqli_fetch_array')) {
  60. function mysql_fetch_array($result)
  61. {
  62. return mysqli_fetch_array($result);
  63. }
  64. }
  65. if (!function_exists('mysql_close') and function_exists('mysqli_close')) {
  66. function mysql_close($link)
  67. {
  68. if ($link) {
  69. return @mysqli_close($link);
  70. } else {
  71. return false;
  72. }
  73. }
  74. }
  75. if (!function_exists('mysql_free_result') and function_exists('mysqli_free_result')) {
  76. function mysql_free_result($result)
  77. {
  78. return mysqli_free_result($result);
  79. }
  80. }
  81. if (!function_exists('split')) {
  82. function split($pattern, $string)
  83. {
  84. return explode($pattern, $string);
  85. }
  86. }
  87. }
  88. //一个支持在PHP Cli Server打印的方法
  89. function var_dump_cli($val,...$values)
  90. {
  91. ob_start();
  92. var_dump($val,$values);
  93. error_log(ob_get_clean(), 4);
  94. }
  95. function get_mime_type($filename)
  96. {
  97. if (!function_exists('finfo_open')) {
  98. return 'unknow/octet-stream';
  99. }
  100. $finfo = finfo_open(FILEINFO_MIME_TYPE);
  101. $mimeType = finfo_file($finfo, $filename);
  102. finfo_close($finfo);
  103. return $mimeType;
  104. }
  105. function is_all_numeric(array $array)
  106. {
  107. foreach ($array as $item) {
  108. if (!is_numeric($item)) return false;
  109. }
  110. return true;
  111. }
  112. function make_hash()
  113. {
  114. $rand = dede_random_bytes(16);
  115. $_SESSION['token'] = ($rand === FALSE) ? md5(uniqid(mt_rand(), TRUE)) : bin2hex($rand);
  116. return $_SESSION['token'];
  117. }
  118. function dede_random_bytes($length)
  119. {
  120. if (empty($length) or !ctype_digit((string) $length)) {
  121. return FALSE;
  122. }
  123. if (function_exists('openssl_random_pseudo_bytes')) {
  124. return openssl_random_pseudo_bytes($length);
  125. }
  126. if (function_exists('random_bytes')) {
  127. try {
  128. return random_bytes((int) $length);
  129. } catch (Exception $e) {
  130. return FALSE;
  131. }
  132. }
  133. if (is_readable('/dev/urandom') && ($fp = fopen('/dev/urandom', 'rb')) !== FALSE) {
  134. version_compare(PHP_VERSION, '5.4.0', '>=') && stream_set_chunk_size($fp, $length);
  135. $output = fread($fp, $length);
  136. fclose($fp);
  137. if ($output !== FALSE) {
  138. return $output;
  139. }
  140. }
  141. return FALSE;
  142. }
  143. //SQL语句过滤程序,由80sec提供,这里作了适当的修改
  144. if (!function_exists('CheckSql')) {
  145. function CheckSql($db_string, $querytype = 'select')
  146. {
  147. global $cfg_cookie_encode;
  148. $clean = '';
  149. $error = '';
  150. $old_pos = 0;
  151. $pos = -1;
  152. $enkey = substr(md5(substr($cfg_cookie_encode.'dedebiz', 0, 5)), 0, 10);
  153. $log_file = DEDEDATA.'/checksql_'.$enkey.'_safe.txt';
  154. $userIP = GetIP();
  155. $getUrl = GetCurUrl();
  156. //如果是普通查询语句,直接过滤一些特殊语法
  157. if ($querytype == 'select') {
  158. $notallow1 = "[^0-9a-z@\._-]{1,}(union|sleep|benchmark|load_file|outfile)[^0-9a-z@\.-]{1,}";
  159. if (preg_match("/".$notallow1."/i", $db_string)) {
  160. fputs(fopen($log_file, 'a+'), "$userIP||$getUrl||$db_string||SelectBreak\r\n");
  161. exit("<span>Safe Alert: Request Error step 1 !</span>");
  162. }
  163. }
  164. //完整的SQL检查
  165. while (TRUE) {
  166. $pos = strpos($db_string, '\'', $pos + 1);
  167. if ($pos === FALSE) {
  168. break;
  169. }
  170. $clean .= substr($db_string, $old_pos, $pos - $old_pos);
  171. while (TRUE) {
  172. $pos1 = strpos($db_string, '\'', $pos + 1);
  173. $pos2 = strpos($db_string, '\\', $pos + 1);
  174. if ($pos1 === FALSE) {
  175. break;
  176. } elseif ($pos2 == FALSE || $pos2 > $pos1) {
  177. $pos = $pos1;
  178. break;
  179. }
  180. $pos = $pos2 + 1;
  181. }
  182. $clean .= '$s$';
  183. $old_pos = $pos + 1;
  184. }
  185. $clean .= substr($db_string, $old_pos);
  186. $clean = trim(strtolower(preg_replace(array('~\s+~s'), array(' '), $clean)));
  187. if (
  188. strpos($clean, '@') !== FALSE or strpos($clean, 'char(') !== FALSE or strpos($clean, '"') !== FALSE
  189. or strpos($clean, '$s$$s$') !== FALSE
  190. ) {
  191. $fail = TRUE;
  192. if (preg_match("#^create table#i", $clean)) $fail = FALSE;
  193. $error = "unusual character";
  194. }
  195. //老版本数据库不支持union,程序不使用union,但黑客使用它,所以检查它
  196. if (strpos($clean, 'union') !== FALSE && preg_match('~(^|[^a-z])union($|[^[a-z])~s', $clean) != 0) {
  197. $fail = TRUE;
  198. $error = "union detect";
  199. }
  200. //发布版本的程序可能比较少包括--,#这样的注释,但黑客经常使用它们
  201. elseif (strpos($clean, '/*') > 2 || strpos($clean, '--') !== FALSE || strpos($clean, '#') !== FALSE) {
  202. $fail = TRUE;
  203. $error = "comment detect";
  204. }
  205. //这些函数不会被使用,但是黑客会用它来操作文件,down掉数据库
  206. elseif (strpos($clean, 'sleep') !== FALSE && preg_match('~(^|[^a-z])sleep($|[^[a-z])~s', $clean) != 0) {
  207. $fail = TRUE;
  208. $error = "slown down detect";
  209. } elseif (strpos($clean, 'benchmark') !== FALSE && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
  210. $fail = TRUE;
  211. $error = "slown down detect";
  212. } elseif (strpos($clean, 'load_file') !== FALSE && preg_match('~(^|[^a-z])load_file($|[^[a-z])~s', $clean) != 0) {
  213. $fail = TRUE;
  214. $error = "file fun detect";
  215. } elseif (strpos($clean, 'into outfile') !== FALSE && preg_match('~(^|[^a-z])into\s+outfile($|[^[a-z])~s', $clean) != 0) {
  216. $fail = TRUE;
  217. $error = "file fun detect";
  218. }
  219. //老版本数据库不支持子查询,该功能也用得少,但黑客可以使用它来查询数据库敏感信息
  220. elseif (preg_match('~\([^)]*?select~s', $clean) != 0) {
  221. $fail = TRUE;
  222. $error = "sub select detect";
  223. }
  224. if (!empty($fail)) {
  225. fputs(fopen($log_file, 'a+'), "$userIP||$getUrl||$db_string||$error\r\n");
  226. exit("<span>Safe Alert: Request Error step 2!</span>");
  227. } else {
  228. return $db_string;
  229. }
  230. }
  231. }
  232. /**
  233. * 载入小助手,系统默认载入小助手示例:
  234. * <code>
  235. * if (!function_exists('HelloDede'))
  236. * {
  237. * function HelloDede()
  238. * {
  239. * echo "Hello! Dede";
  240. * }
  241. * }
  242. * </code>
  243. * 开发中使用这个小助手的时候直接使用函数helper('test');初始化它,然后在文件中就可以直接使用:HelloDede();调用
  244. *
  245. * @access public
  246. * @param mix $helpers 小助手名称,可以是数组,可以是单个字符串
  247. * @return void
  248. */
  249. $_helpers = array();
  250. function helper($helpers)
  251. {
  252. //如果是数组,则进行递归操作
  253. if (is_array($helpers)) {
  254. foreach ($helpers as $dede) {
  255. helper($dede);
  256. }
  257. return;
  258. }
  259. if (isset($_helpers[$helpers])) {
  260. return;
  261. }
  262. if (file_exists(DEDEINC.'/helpers/'.$helpers.'.helper.php')) {
  263. include_once(DEDEINC.'/helpers/'.$helpers.'.helper.php');
  264. $_helpers[$helpers] = TRUE;
  265. }
  266. //无法载入小助手
  267. if (!isset($_helpers[$helpers])) {
  268. exit('Unable to load the requested file: helpers/'.$helpers.'.helper.php');
  269. }
  270. }
  271. function dede_htmlspecialchars($str)
  272. {
  273. global $cfg_soft_lang;
  274. if (version_compare(PHP_VERSION, '5.4.0', '<')) return htmlspecialchars($str);
  275. if ($cfg_soft_lang == 'gb2312') return htmlspecialchars($str, ENT_COMPAT, 'ISO-8859-1');
  276. else return htmlspecialchars($str);
  277. }
  278. /**
  279. * 载入小助手,这里会员可能载入用helps载入多个小助手
  280. *
  281. * @access public
  282. * @param string
  283. * @return string
  284. */
  285. function helpers($helpers)
  286. {
  287. helper($helpers);
  288. }
  289. //兼容php4的file_put_contents
  290. if (!function_exists('file_put_contents')) {
  291. function file_put_contents($n, $d)
  292. {
  293. $f = @fopen($n, "w");
  294. if (!$f) {
  295. return FALSE;
  296. } else {
  297. fwrite($f, $d);
  298. fclose($f);
  299. return TRUE;
  300. }
  301. }
  302. }
  303. $arrs1 = array();
  304. $arrs2 = array();
  305. /**
  306. * 短消息函数,可以在某个动作处理后友好的系统提示
  307. *
  308. * @param string $msg 消息系统提示
  309. * @param string $gourl 跳转地址
  310. * @param int $onlymsg 仅显示信息
  311. * @param int $limittime 限制时间
  312. * @return void
  313. */
  314. function ShowMsg($msg, $gourl, $onlymsg = 0, $limittime = 0)
  315. {
  316. if (isset($GLOBALS['format']) && strtolower($GLOBALS['format'])==='json') {
  317. echo json_encode(array(
  318. "code"=>0,
  319. "msg"=>$msg,
  320. "gourl"=>$gourl,
  321. ));
  322. return;
  323. }
  324. if (empty($GLOBALS['cfg_plus_dir'])) $GLOBALS['cfg_plus_dir'] = '..';
  325. $htmlhead = "<!DOCTYPE html><html><head><meta charset='utf-8'><meta http-equiv='X-UA-Compatible' content='IE=Edge,chrome=1'><title>系统提示</title><base target='_self'></head><body><script>";
  326. $htmlfoot = "</script></body></html>";
  327. $litime = ($limittime == 0 ? 1000 : $limittime);
  328. $func = '';
  329. if ($gourl == '-1') {
  330. if ($limittime == 0) $litime = 5000;
  331. $gourl = "javascript:history.go(-1);";
  332. }
  333. if ($gourl == '' || $onlymsg == 1) {
  334. $msg = "<script>alert(\"".str_replace("\"", "“", $msg)."\");</script>";
  335. } else {
  336. //当网址为:close::objname时,关闭父框架的id=objname元素
  337. if (preg_match('/close::/', $gourl)) {
  338. $tgobj = trim(preg_replace('/close::/', '', $gourl));
  339. $gourl = 'javascript:;';
  340. $func .= "window.parent.document.getElementById('{$tgobj}').style.display='none';\r\n";
  341. }
  342. $func .= "var pgo=0;function JumpUrl(){if (pgo==0){location='$gourl'; pgo=1;}}";
  343. $rmsg = $func;
  344. $rmsg .= "document.write(\"<style>body{margin:0;line-height:1.6;letter-spacing:.6px;font:14px Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;color:#545b62;background:#f5f5f5}a{color:#007bff;text-decoration:none}.tips-box{margin:70px auto 0;width:500px;height:auto;background:#fff;border-radius:.5rem;box-shadow:0 .125rem .25rem rgba(0,0,0,.075)}.tips-head{margin:0 20px;padding:18px 0;border-bottom:1px solid #f5f5f5}.tips-head p{margin:0;padding-left:10px;line-height:16px;text-align:left;border-left:3px solid #dc3545}.tips-body{padding:20px;min-height:130px;color:#545b62}.btn{margin-top:20px;text-align:center}.btn a{display:inline-block;padding:.375rem .75rem;font-size:12px;color:#fff;background:#1eb867;border-radius:.5rem;text-align:center;transition:all .5s}.btn a:focus{background:#006829;border-color:#005b24;box-shadow:0 0 0 0.2rem rgba(72,180,97,.5)}.text-primary{color:#007bff}@media (max-width:768px){.tips{padding:0 15px}.tips,.tips-box{width:100%}}</style>\");";
  345. $rmsg .= "document.write(\"<div class='tips'><div class='tips-box'><div class='tips-head'><p>系统提示</p></div>\");";
  346. $rmsg .= "document.write(\"<div class='tips-body'>\");";
  347. $rmsg .= "document.write(\"".str_replace("\"", "“", $msg)."\");";
  348. $rmsg .= "document.write(\"";
  349. if ($onlymsg == 0) {
  350. if ($gourl != 'javascript:;' && $gourl != '') {
  351. $rmsg .= "<div class='btn'><a href='{$gourl}'>点击反应</a></div>\");";
  352. $rmsg .= "setTimeout('JumpUrl()',$litime);";
  353. } else {
  354. $rmsg .= "</div>\");";
  355. }
  356. } else {
  357. $rmsg .= "</div></div>\");";
  358. }
  359. $msg = $htmlhead.$rmsg.$htmlfoot;
  360. }
  361. echo $msg;
  362. }
  363. /**
  364. * 表中是否存在某个字段
  365. *
  366. * @param mixed $tablename 表名称
  367. * @param mixed $field 字段名
  368. * @return void
  369. */
  370. function TableHasField($tablename,$field)
  371. {
  372. global $dsql;
  373. $dsql->GetTableFields($tablename,"tfd");
  374. while ($r = $dsql->GetFieldObject("tfd")) {
  375. if ($r->name === $field) {
  376. return true;
  377. }
  378. }
  379. return false;
  380. }
  381. function GetSimpleServerSoftware()
  382. {
  383. if (preg_match("#^php#i",$_SERVER["SERVER_SOFTWARE"])) {
  384. return 'PHP Server';
  385. } else if (preg_match("#^apache#i",$_SERVER["SERVER_SOFTWARE"])){
  386. return 'Apache';
  387. } else if (preg_match("#^nginx#i",$_SERVER["SERVER_SOFTWARE"])){
  388. return 'Nginx';
  389. } else if (preg_match("#^microsoft-iis#i",$_SERVER["SERVER_SOFTWARE"])){
  390. return 'IIS';
  391. } else if (preg_match("#^caddy#i",$_SERVER["SERVER_SOFTWARE"])){
  392. return 'Caddy';
  393. } else {
  394. return 'Other';
  395. }
  396. }
  397. /**
  398. * 获取验证码的session值
  399. *
  400. * @return string
  401. */
  402. function GetCkVdValue()
  403. {
  404. @session_id($_COOKIE['PHPSESSID']);
  405. @session_start();
  406. return isset($_SESSION['securimage_code_value']) ? $_SESSION['securimage_code_value'] : '';
  407. }
  408. /**
  409. * PHP某些版本有Bug,不能在同一作用域中同时读session并改注销它,因此调用后需执行本函数
  410. *
  411. * @return void
  412. */
  413. function ResetVdValue()
  414. {
  415. @session_start();
  416. $_SESSION['securimage_code_value'] = '';
  417. }
  418. function IndexSub($idx, $num)
  419. {
  420. return intval($idx) - intval($num) == 0 ? '0 ' : intval($idx) - intval($num);
  421. }
  422. /**
  423. * HideEmail隐藏邮箱
  424. *
  425. * @param mixed $email
  426. * @return string
  427. */
  428. function HideEmail($email)
  429. {
  430. if (empty($email)) return "暂无";
  431. $em = explode("@",$email);
  432. $name = implode('@', array_slice($em, 0, count($em)-1));
  433. $len = floor(strlen($name)/2);
  434. return substr($name,0, $len).str_repeat('*', $len)."@".end($em);
  435. }
  436. //用来返回index的active
  437. function IndexActive($idx)
  438. {
  439. if ($idx == 1) {
  440. return ' active';
  441. } else {
  442. return '';
  443. }
  444. }
  445. //是否是HTTPS
  446. function IsSSL()
  447. {
  448. if (@$_SERVER['HTTPS'] && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))) {
  449. return true;
  450. } elseif ('https' == @$_SERVER['REQUEST_SCHEME']) {
  451. return true;
  452. } elseif ('443' == $_SERVER['SERVER_PORT']) {
  453. return true;
  454. } elseif ('https' == @$_SERVER['HTTP_X_FORWARDED_PROTO']) {
  455. return true;
  456. }
  457. return false;
  458. }
  459. //获取对应版本号的更新SQL
  460. function GetUpdateSQL()
  461. {
  462. global $cfg_dbprefix, $cfg_dbtype, $cfg_db_language;
  463. $result = array();
  464. $query = '';
  465. $sql4tmp = "ENGINE=MyISAM DEFAULT CHARSET=".$cfg_db_language;
  466. $fp = fopen(DEDEROOT.'/install/update.txt','r');
  467. $sqls = array();
  468. $current_ver = "";
  469. while(!feof($fp))
  470. {
  471. $line = rtrim(fgets($fp,1024));
  472. if (preg_match("/\-\- ([\d\.]+)/",$line,$matches)) {
  473. if (count($sqls) > 0) {
  474. $result[$current_ver] = $sqls;
  475. }
  476. $sqls = array();
  477. $current_ver = $matches[1];
  478. }
  479. if (preg_match("#;$#", $line)) {
  480. $query .= $line."\n";
  481. $query = str_replace('#@__',$cfg_dbprefix,$query);
  482. if ($cfg_dbtype == 'sqlite') {
  483. $query = preg_replace('/character set (.*?) /i','',$query);
  484. $query = preg_replace('/unsigned/i','',$query);
  485. $query = str_replace('TYPE=MyISAM','',$query);
  486. $query = preg_replace ('/TINYINT\(([\d]+)\)/i','INTEGER',$query);
  487. $query = preg_replace ('/mediumint\(([\d]+)\)/i','INTEGER',$query);
  488. $query = preg_replace ('/smallint\(([\d]+)\)/i','INTEGER',$query);
  489. $query = preg_replace('/int\(([\d]+)\)/i','INTEGER',$query);
  490. $query = preg_replace('/auto_increment/i','PRIMARY KEY AUTOINCREMENT',$query);
  491. $query = preg_replace('/,([\t\s ]+)KEY(.*?)MyISAM;/','',$query);
  492. $query = preg_replace('/,([\t\s ]+)KEY(.*?);/',');',$query);
  493. $query = preg_replace('/,([\t\s ]+)UNIQUE KEY(.*?);/',');',$query);
  494. $query = preg_replace('/set\(([^\)]*?)\)/','varchar',$query);
  495. $query = preg_replace('/enum\(([^\)]*?)\)/','varchar',$query);
  496. if (preg_match("/PRIMARY KEY AUTOINCREMENT/",$query)) {
  497. $query = preg_replace('/,([\t\s ]+)PRIMARY KEY([\t\s ]+)\(`([0-9a-zA-Z]+)`\)/i','',$query);
  498. }
  499. $sqls[] = $query;
  500. } else {
  501. if (preg_match('#CREATE#i', $query)) {
  502. $sqls[] = preg_replace("#TYPE=MyISAM#i",$sql4tmp,$query);
  503. } else {
  504. $sqls[] = $query;
  505. }
  506. }
  507. $query='';
  508. } else if (!preg_match("#^(\/\/|--)#", $line)) {
  509. $query .= $line;
  510. }
  511. }
  512. if (count($sqls) > 0) {
  513. $result[$current_ver] = $sqls;
  514. }
  515. fclose($fp);
  516. return $result;
  517. }
  518. /*会员中心调用默认主题模板<?php pasterTempletDiy('head.htm');?>*/
  519. if (!function_exists('pasterTempletDiy')) {
  520. function pasterTempletDiy($path)
  521. {
  522. global $cfg_basedir, $cfg_templets_dir, $cfg_df_style;
  523. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$cfg_df_style.'/'.$path;
  524. $dtp = new PartView();
  525. $dtp->SetTemplet($tmpfile);
  526. $dtp->Display();
  527. }
  528. }
  529. //标签调用标签[field:id function='GetMyTags(@me,2)'/]2表示调用文档2个标签
  530. if (!function_exists('GetMyTags')) {
  531. function GetMyTags($aid, $num=3)
  532. {
  533. global $dsql, $cfg_cmspath;
  534. $tags = '';
  535. $query = "SELECT * FROM `#@__taglist` WHERE aid='$aid' LIMIT $num";
  536. $dsql->Execute('tag',$query);
  537. while($row = $dsql->GetArray('tag')) {
  538. $link = $cfg_cmspath."/apps/tags.php?/{$row['tid']}";
  539. $tags.= ($tags==''?"<a href='{$link}'>{$row['tag']}</a>" : "<a href='{$link}'>{$row['tag']}</a>");
  540. }
  541. return $tags;
  542. }
  543. }
  544. //联动单筛选标签{dede:php}AddFilter(模型id,类型,'字段1,字段2');{/dede:php}类型对应以下case数值
  545. function litimgurls($imgid = 0)
  546. {
  547. global $lit_imglist, $dsql;
  548. $row = $dsql->GetOne("SELECT c.addtable FROM `#@__archives` AS a LEFT JOIN `#@__channeltype` AS c ON a.channel=c.id WHERE a.id='$imgid'");
  549. $addtable = trim($row['addtable']);
  550. $row = $dsql->GetOne("SELECT imgurls FROM `$addtable` WHERE aid='$imgid'");
  551. $ChannelUnit = new ChannelUnit(2, $imgid);
  552. $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']);
  553. return $lit_imglist;
  554. }
  555. //联动单筛选字符过滤函数
  556. function string_filter($str, $stype = "inject")
  557. {
  558. if ($stype == "inject") {
  559. $str = str_replace(
  560. array("select", "insert", "update", "delete", "alter", "cas", "union", "into", "load_file", "outfile", "create", "join", "where", "like", "drop", "modify", "rename", "'", "/*", "*", "../", "./"),
  561. array("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""),
  562. $str
  563. );
  564. } else if ($stype == "xss") {
  565. $farr = array("/\s+/", "/<(\/?)(script|META|STYLE|HTML|HEAD|BODY|STYLE |i?frame|b|strong|style|html|img|P|o:p|iframe|u|em|strike|BR|div|a|TABLE|TBODY|object|tr|td|st1:chsdate|FONT|span|MARQUEE|body|title|\r\n|link|meta|\?|\%)([^>]*?)>/isU", "/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",);
  566. $tarr = array(" ", "", "\\1\\2",);
  567. $str = preg_replace($farr, $tarr, $str);
  568. $str = str_replace(
  569. array("<", ">", "'", "\"", ";", "/*", "*", "../", "./"),
  570. array("&lt;", "&gt;", "", "", "", "", "", "", ""),
  571. $str
  572. );
  573. }
  574. return $str;
  575. }
  576. //联动单筛选发布三种类型
  577. function AddFilter($channelid, $type=1, $fieldsnamef='', $defaulttid=0, $toptid=0, $loadtype='autofield')
  578. {
  579. global $tid, $dsql, $id, $aid;
  580. $tid = $defaulttid ? $defaulttid : $tid;
  581. if ($id!="" || $aid!="") {
  582. $arcid = $id!="" ? $id : $aid;
  583. $tidsq = $dsql->GetOne("SELECT * FROM `#@__archives` WHERE id='$arcid'");
  584. $tid = $toptid==0 ? $tidsq["typeid"] : $tidsq["topid"];
  585. }
  586. $nofilter = (isset($_REQUEST['TotalResult']) ? "&TotalResult=".$_REQUEST['TotalResult'] : '').(isset($_REQUEST['PageNo']) ? "&PageNo=".$_REQUEST['PageNo'] : '');
  587. $filterarr = string_filter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/apps/list.php?tid=".$tid);
  588. $cInfos = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$channelid'");
  589. $fieldset=$cInfos['fieldset'];
  590. $dtp = new DedeTagParse();
  591. $dtp->SetNameSpace('field', '<', '>');
  592. $dtp->LoadSource($fieldset);
  593. $dede_addonfields = '';
  594. if (is_array($dtp->CTags)) {
  595. foreach($dtp->CTags as $tida=>$ctag)
  596. {
  597. $fieldsname = $fieldsnamef ? explode(",", $fieldsnamef) : explode(",", $ctag->GetName());
  598. if (($loadtype!='autofield' || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1)) && in_array($ctag->GetName(), $fieldsname)) {
  599. $href1 = explode($ctag->GetName().'=', $filterarr);
  600. $href2 = explode('&', $href1[1]);
  601. $fields_value = $href2[0];
  602. switch ($type) {
  603. case 1:
  604. $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? '<a href="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'" class="btn btn-outline-success btn-sm">全部</a>' : '<a href="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'" class="btn btn-success btn-sm">全部</a>');
  605. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  606. for ($i=0; $i<count($addonfields_items); $i++)
  607. {
  608. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  609. $dede_addonfields .= ($fields_value!=urlencode($addonfields_items[$i]) ? '<a title="'.$addonfields_items[$i].'" href="'.$href.'" class="btn btn-outline-success btn-sm">'.$addonfields_items[$i].'</a>' : '<a href="'.$href.'" class="btn btn-success btn-sm">'.$addonfields_items[$i].'</a>');
  610. }
  611. break;
  612. case 2:
  613. $dede_addonfields .= '<select name="filter'.$ctag->GetName().'" onchange="window.location=this.options[this.selectedIndex].value">
  614. '.'<option value="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'">全部</option>';
  615. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  616. for ($i=0; $i<count($addonfields_items); $i++)
  617. {
  618. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  619. $dede_addonfields .= '<option value="'.$href.'"'.($fields_value==urlencode($addonfields_items[$i]) ? ' selected="selected"' : '').'>'.$addonfields_items[$i].'</option>
  620. ';
  621. }
  622. $dede_addonfields .= '</select>
  623. ';
  624. break;
  625. case 3:
  626. $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? '<a href="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'"><input type="radio" name="filter'.$ctag->GetName().'" value="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'" onclick="window.location=this.value">全部</a>' : '<span><input type="radio" name="filter'.$ctag->GetName().'" checked="checked">全部</span>');
  627. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  628. for ($i=0; $i<count($addonfields_items); $i++)
  629. {
  630. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  631. $dede_addonfields .= ($fields_value!=urlencode($addonfields_items[$i]) ? '<a title="'.$addonfields_items[$i].'" href="'.$href.'"><input type="radio" name="filter'.$ctag->GetName().'" value="'.$href.'" onclick="window.location=this.value">'.$addonfields_items[$i].'</a>' : '<span><input type="radio" name="filter'.$ctag->GetName().'" checked="checked">'.$addonfields_items[$i].'</span>');
  632. }
  633. break;
  634. }
  635. }
  636. }
  637. }
  638. echo $dede_addonfields;
  639. }
  640. //自定义函数接口
  641. if (file_exists(DEDEINC.'/extend.func.php')) {
  642. require_once(DEDEINC.'/extend.func.php');
  643. }
  644. ?>