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

536 lines
24KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. //显示类似BS的提示信息
  4. define('ALERT_PRIMARY', 1);
  5. define('ALERT_SECONDARY', 2);
  6. define('ALERT_SUCCESS', 3);
  7. define('ALERT_DANGER', 4);
  8. define('ALERT_WARNING', 5);
  9. define('ALERT_INFO', 6);
  10. define('ALERT_LIGHT', 7);
  11. define('ALERT_DARK', 8);
  12. define('ALERT_COLORS', array(
  13. ALERT_PRIMARY => array('#cfe2ff','#b6d4fe','#084298'),
  14. ALERT_SECONDARY => array('#e2e3e5','#d3d6d8','#41464b'),
  15. ALERT_SUCCESS => array('#d1e7dd','#badbcc','#0f5132'),
  16. ALERT_DANGER => array('#f8d7da','#f5c2c7','#842029'),
  17. ALERT_WARNING => array('#fff3cd','#ffecb5','#664d03'),
  18. ALERT_INFO => array('#cff4fc','#b6effb','#055160'),
  19. ALERT_LIGHT => array('#fefefe','#fdfdfe','#636464'),
  20. ALERT_DARK => array('#d3d3d4','#bcbebf','#141619'),
  21. ));
  22. define("ALERT_TPL", '<div style="width:98%;margin:0 auto"><div style="font-size:12px;margin:1rem auto;color:~color~;background:~background~;border-color:~border~;position:relative;padding:.75rem 1.25rem;border:1px solid transparent;border-radius:.2rem">~content~</div></div>');
  23. //$content:内容 $type:alert类型
  24. function DedeAlert($content, $type = ALERT_PRIMARY)
  25. {
  26. $content = htmlspecialchars($content);
  27. $colors = isset(ALERT_COLORS[$type])? ALERT_COLORS[$type] : ALERT_COLORS[ALERT_PRIMARY];
  28. list($background, $border, $color) = $colors;
  29. return str_replace(array('~color~','~background~','~border~', '~content~'),array($color,$background,$border,$content),ALERT_TPL);
  30. }
  31. /**
  32. * 系统核心函数存放文件
  33. * @version $Id: common.func.php 4 16:39 2010年7月6日Z tianya $
  34. * @package DedeBIZ.Libraries
  35. * @copyright Copyright (c) 2022, DedeBIZ.COM
  36. * @license https://www.dedebiz.com/license
  37. * @link https://www.dedebiz.com
  38. */
  39. if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
  40. if (!function_exists('mysql_connect') and function_exists('mysqli_connect')) {
  41. function mysql_connect($server, $username, $password)
  42. {
  43. return mysqli_connect($server, $username, $password);
  44. }
  45. }
  46. if (!function_exists('mysql_query') and function_exists('mysqli_query')) {
  47. function mysql_query($query, $link)
  48. {
  49. return mysqli_query($link, $query);
  50. }
  51. }
  52. if (!function_exists('mysql_select_db') and function_exists('mysqli_select_db')) {
  53. function mysql_select_db($database_name, $link)
  54. {
  55. return mysqli_select_db($link, $database_name);
  56. }
  57. }
  58. if (!function_exists('mysql_fetch_array') and function_exists('mysqli_fetch_array')) {
  59. function mysql_fetch_array($result)
  60. {
  61. return mysqli_fetch_array($result);
  62. }
  63. }
  64. if (!function_exists('mysql_close') and function_exists('mysqli_close')) {
  65. function mysql_close($link)
  66. {
  67. return mysqli_close($link);
  68. }
  69. }
  70. if (!function_exists('mysql_free_result') and function_exists('mysqli_free_result')) {
  71. function mysql_free_result($result)
  72. {
  73. return mysqli_free_result($result);
  74. }
  75. }
  76. if (!function_exists('split')) {
  77. function split($pattern, $string)
  78. {
  79. return explode($pattern, $string);
  80. }
  81. }
  82. }
  83. //一个支持在PHP Cli Server打印的方法
  84. function var_dump_cli($val)
  85. {
  86. ob_start();
  87. var_dump($val);
  88. error_log(ob_get_clean(), 4);
  89. }
  90. function get_mime_type($filename)
  91. {
  92. if (!function_exists('finfo_open')) {
  93. return 'unknow/octet-stream';
  94. }
  95. $finfo = finfo_open(FILEINFO_MIME_TYPE);
  96. $mimeType = finfo_file($finfo, $filename);
  97. finfo_close($finfo);
  98. return $mimeType;
  99. }
  100. function is_all_numeric(array $array)
  101. {
  102. foreach ($array as $item) {
  103. if (!is_numeric($item)) return false;
  104. }
  105. return true;
  106. }
  107. function make_hash()
  108. {
  109. $rand = dede_random_bytes(16);
  110. $_SESSION['token'] = ($rand === FALSE)
  111. ? md5(uniqid(mt_rand(), TRUE))
  112. : bin2hex($rand);
  113. return $_SESSION['token'];
  114. }
  115. function dede_random_bytes($length)
  116. {
  117. if (empty($length) or !ctype_digit((string) $length)) {
  118. return FALSE;
  119. }
  120. if (function_exists('openssl_random_pseudo_bytes')) {
  121. return openssl_random_pseudo_bytes($length);
  122. }
  123. if (function_exists('random_bytes')) {
  124. try {
  125. return random_bytes((int) $length);
  126. } catch (Exception $e) {
  127. return FALSE;
  128. }
  129. }
  130. if (is_readable('/dev/urandom') && ($fp = fopen('/dev/urandom', 'rb')) !== FALSE) {
  131. version_compare(PHP_VERSION, '5.4.0', '>=') && stream_set_chunk_size($fp, $length);
  132. $output = fread($fp, $length);
  133. fclose($fp);
  134. if ($output !== FALSE) {
  135. return $output;
  136. }
  137. }
  138. return FALSE;
  139. }
  140. //SQL语句过滤程序,由80sec提供,这里作了适当的修改
  141. if (!function_exists('CheckSql')) {
  142. function CheckSql($db_string, $querytype = 'select')
  143. {
  144. global $cfg_cookie_encode;
  145. $clean = '';
  146. $error = '';
  147. $old_pos = 0;
  148. $pos = -1;
  149. $enkey = substr(md5(substr($cfg_cookie_encode.'dedebiz', 0, 5)), 0, 10);
  150. $log_file = DEDEDATA.'/checksql_'.$enkey.'_safe.txt';
  151. $userIP = GetIP();
  152. $getUrl = GetCurUrl();
  153. //如果是普通查询语句,直接过滤一些特殊语法
  154. if ($querytype == 'select') {
  155. $notallow1 = "[^0-9a-z@\._-]{1,}(union|sleep|benchmark|load_file|outfile)[^0-9a-z@\.-]{1,}";
  156. //$notallow2 = "--|/\*";
  157. if (preg_match("/".$notallow1."/i", $db_string)) {
  158. fputs(fopen($log_file, 'a+'), "$userIP||$getUrl||$db_string||SelectBreak\r\n");
  159. exit("<span>Safe Alert: Request Error step 1 !</span>");
  160. }
  161. }
  162. //完整的SQL检查
  163. while (TRUE) {
  164. $pos = strpos($db_string, '\'', $pos + 1);
  165. if ($pos === FALSE) {
  166. break;
  167. }
  168. $clean .= substr($db_string, $old_pos, $pos - $old_pos);
  169. while (TRUE) {
  170. $pos1 = strpos($db_string, '\'', $pos + 1);
  171. $pos2 = strpos($db_string, '\\', $pos + 1);
  172. if ($pos1 === FALSE) {
  173. break;
  174. } elseif ($pos2 == FALSE || $pos2 > $pos1) {
  175. $pos = $pos1;
  176. break;
  177. }
  178. $pos = $pos2 + 1;
  179. }
  180. $clean .= '$s$';
  181. $old_pos = $pos + 1;
  182. }
  183. $clean .= substr($db_string, $old_pos);
  184. $clean = trim(strtolower(preg_replace(array('~\s+~s'), array(' '), $clean)));
  185. if (
  186. strpos($clean, '@') !== FALSE or strpos($clean, 'char(') !== FALSE or strpos($clean, '"') !== FALSE
  187. or strpos($clean, '$s$$s$') !== FALSE
  188. ) {
  189. $fail = TRUE;
  190. if (preg_match("#^create table#i", $clean)) $fail = FALSE;
  191. $error = "unusual character";
  192. }
  193. //老版本的Mysql并不支持union,常用的程序里也不使用union,但是一些黑客使用它,所以检查它
  194. if (strpos($clean, 'union') !== FALSE && preg_match('~(^|[^a-z])union($|[^[a-z])~s', $clean) != 0) {
  195. $fail = TRUE;
  196. $error = "union detect";
  197. }
  198. //发布版本的程序可能比较少包括--,#这样的注释,但是黑客经常使用它们
  199. elseif (strpos($clean, '/*') > 2 || strpos($clean, '--') !== FALSE || strpos($clean, '#') !== FALSE) {
  200. $fail = TRUE;
  201. $error = "comment detect";
  202. }
  203. //这些函数不会被使用,但是黑客会用它来操作文件,down掉数据库
  204. elseif (strpos($clean, 'sleep') !== FALSE && preg_match('~(^|[^a-z])sleep($|[^[a-z])~s', $clean) != 0) {
  205. $fail = TRUE;
  206. $error = "slown down detect";
  207. } elseif (strpos($clean, 'benchmark') !== FALSE && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
  208. $fail = TRUE;
  209. $error = "slown down detect";
  210. } elseif (strpos($clean, 'load_file') !== FALSE && preg_match('~(^|[^a-z])load_file($|[^[a-z])~s', $clean) != 0) {
  211. $fail = TRUE;
  212. $error = "file fun detect";
  213. } elseif (strpos($clean, 'into outfile') !== FALSE && preg_match('~(^|[^a-z])into\s+outfile($|[^[a-z])~s', $clean) != 0) {
  214. $fail = TRUE;
  215. $error = "file fun detect";
  216. }
  217. //老版本的MYSQL不支持子查询,我们的程序里可能也用得少,但是黑客可以使用它来查询数据库敏感信息
  218. elseif (preg_match('~\([^)]*?select~s', $clean) != 0) {
  219. $fail = TRUE;
  220. $error = "sub select detect";
  221. }
  222. if (!empty($fail)) {
  223. fputs(fopen($log_file, 'a+'), "$userIP||$getUrl||$db_string||$error\r\n");
  224. exit("<span>Safe Alert: Request Error step 2!</span>");
  225. } else {
  226. return $db_string;
  227. }
  228. }
  229. }
  230. /**
  231. * 载入小助手,系统默认载入小助手
  232. * 在/data/helper.inc.php中进行默认小助手初始化的设置
  233. * 使用示例:
  234. * 在开发中,首先需要创建一个小助手函数,目录在\include\helpers中
  235. * 例如,我们创建一个示例为test.helper.php,文件基本内容如下:
  236. * <code>
  237. * if ( ! function_exists('HelloDede'))
  238. * {
  239. * function HelloDede()
  240. * {
  241. * echo "Hello! Dede";
  242. * }
  243. * }
  244. * </code>
  245. * 则我们在开发中使用这个小助手的时候直接使用函数helper('test');初始化它
  246. * 然后在文件中就可以直接使用:HelloDede();来进行调用.
  247. *
  248. * @access public
  249. * @param mix $helpers 小助手名称,可以是数组,可以是单个字符串
  250. * @return void
  251. */
  252. $_helpers = array();
  253. function helper($helpers)
  254. {
  255. //如果是数组,则进行递归操作
  256. if (is_array($helpers)) {
  257. foreach ($helpers as $dede) {
  258. helper($dede);
  259. }
  260. return;
  261. }
  262. if (isset($_helpers[$helpers])) {
  263. return;
  264. }
  265. if (file_exists(DEDEINC.'/helpers/'.$helpers.'.helper.php')) {
  266. include_once(DEDEINC.'/helpers/'.$helpers.'.helper.php');
  267. $_helpers[$helpers] = TRUE;
  268. }
  269. //无法载入小助手
  270. if (!isset($_helpers[$helpers])) {
  271. exit('Unable to load the requested file: helpers/'.$helpers.'.helper.php');
  272. }
  273. }
  274. function dede_htmlspecialchars($str)
  275. {
  276. global $cfg_soft_lang;
  277. if (version_compare(PHP_VERSION, '5.4.0', '<')) return htmlspecialchars($str);
  278. if ($cfg_soft_lang == 'gb2312') return htmlspecialchars($str, ENT_COMPAT, 'ISO-8859-1');
  279. else return htmlspecialchars($str);
  280. }
  281. /**
  282. * 载入小助手,这里用户可能载入用helps载入多个小助手
  283. *
  284. * @access public
  285. * @param string
  286. * @return string
  287. */
  288. function helpers($helpers)
  289. {
  290. helper($helpers);
  291. }
  292. //兼容php4的file_put_contents
  293. if (!function_exists('file_put_contents')) {
  294. function file_put_contents($n, $d)
  295. {
  296. $f = @fopen($n, "w");
  297. if (!$f) {
  298. return FALSE;
  299. } else {
  300. fwrite($f, $d);
  301. fclose($f);
  302. return TRUE;
  303. }
  304. }
  305. }
  306. /**
  307. * 显示更新信息
  308. *
  309. * @return void
  310. */
  311. function UpdateStat()
  312. {
  313. include_once(DEDEINC."/inc/inc_stat.php");
  314. return SpUpdateStat();
  315. }
  316. $arrs1 = array();
  317. $arrs2 = array();
  318. /**
  319. * 短消息函数,可以在某个动作处理后友好的提示信息
  320. *
  321. * @param string $msg 消息提示信息
  322. * @param string $gourl 跳转地址
  323. * @param int $onlymsg 仅显示信息
  324. * @param int $limittime 限制时间
  325. * @return void
  326. */
  327. function ShowMsg($msg, $gourl, $onlymsg = 0, $limittime = 0)
  328. {
  329. global $cfg_soft_lang, $cfg_cmsurl;
  330. if (empty($GLOBALS['cfg_plus_dir'])) $GLOBALS['cfg_plus_dir'] = '..';
  331. $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>";
  332. $htmlhead .= "<body><center><script>";
  333. $htmlfoot = "</script></center></body></html>";
  334. $litime = ($limittime == 0 ? 1000 : $limittime);
  335. $func = '';
  336. if ($gourl == '-1') {
  337. if ($limittime == 0) $litime = 5000;
  338. $gourl = "javascript:history.go(-1);";
  339. }
  340. if ($gourl == '' || $onlymsg == 1) {
  341. $msg = "<script>alert(\"".str_replace("\"", "“", $msg)."\");</script>";
  342. } else {
  343. //当网址为:close::objname 时, 关闭父框架的id=objname元素
  344. if (preg_match('/close::/', $gourl)) {
  345. $tgobj = trim(preg_replace('/close::/', '', $gourl));
  346. $gourl = 'javascript:;';
  347. $func .= "window.parent.document.getElementById('{$tgobj}').style.display='none';\r\n";
  348. }
  349. $func .= "var pgo=0;function JumpUrl(){if (pgo==0){location='$gourl'; pgo=1;}}";
  350. $rmsg = $func;
  351. $rmsg .= "document.write(\"<style>body{margin:0;line-height:1.5;font:14px Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;color:#545b62;background:#f8f8f8}a{color:#28a745;text-decoration:none}.tips{margin:70px auto 0;padding:0;width:500px;height:auto;background:#fff;border-radius:.2rem;box-shadow:0 .125rem .25rem rgba(0,0,0,.075)}.tips-head{margin:0 20px;padding:16px 0;border-bottom:1px solid #f8f8f8}.tips-head p{margin:0;padding-left:10px;line-height:16px;text-align:left;border-left:3px solid #dc3545}.tips-box{padding:20px;min-height:130px;color:#545b62}.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>\");";
  352. $rmsg .= "document.write(\"<div class='tips'>";
  353. $rmsg .= "<div class='tips-head'><p>提示信息</p></div>\");";
  354. $rmsg .= "document.write(\"<div class='tips-box'>\");";
  355. $rmsg .= "document.write(\"".str_replace("\"", "“", $msg)."\");";
  356. $rmsg .= "document.write(\"";
  357. if ($onlymsg == 0) {
  358. if ($gourl != 'javascript:;' && $gourl != '') {
  359. $rmsg .= "<div class='btn'><a href='{$gourl}'>点击反应</a></div>\");";
  360. $rmsg .= "setTimeout('JumpUrl()',$litime);";
  361. } else {
  362. $rmsg .= "</div>\");";
  363. }
  364. } else {
  365. $rmsg .= "</div>\");";
  366. }
  367. $msg = $htmlhead.$rmsg.$htmlfoot;
  368. }
  369. echo $msg;
  370. }
  371. /**
  372. * 获取验证码的session值
  373. *
  374. * @return string
  375. */
  376. function GetCkVdValue()
  377. {
  378. @session_id($_COOKIE['PHPSESSID']);
  379. @session_start();
  380. return isset($_SESSION['securimage_code_value']) ? $_SESSION['securimage_code_value'] : '';
  381. }
  382. /**
  383. * PHP某些版本有Bug,不能在同一作用域中同时读session并改注销它,因此调用后需执行本函数
  384. *
  385. * @return void
  386. */
  387. function ResetVdValue()
  388. {
  389. @session_start();
  390. $_SESSION['securimage_code_value'] = '';
  391. }
  392. function IndexSub($idx, $num)
  393. {
  394. return intval($idx) - intval($num) == 0 ? '0 ' : intval($idx) - intval($num);
  395. }
  396. //用来返回index的active
  397. function IndexActive($idx)
  398. {
  399. if ($idx == 1) {
  400. return ' active';
  401. } else {
  402. return '';
  403. }
  404. }
  405. //是否是HTTPS
  406. function IsSSL()
  407. {
  408. if ($_SERVER['HTTPS'] && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))) {
  409. return true;
  410. } elseif ('https' == $_SERVER['REQUEST_SCHEME']) {
  411. return true;
  412. } elseif ('443' == $_SERVER['SERVER_PORT']) {
  413. return true;
  414. } elseif ('https' == $_SERVER['HTTP_X_FORWARDED_PROTO']) {
  415. return true;
  416. }
  417. return false;
  418. }
  419. /*调用前台主题模板<?php pasterTempletDiy('header.htm');?>*/
  420. if (!function_exists('pasterTempletDiy')) {
  421. function pasterTempletDiy($path) {
  422. global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
  423. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$cfg_df_style.'/'.$path;
  424. $dtp = new PartView();
  425. $dtp->SetTemplet($tmpfile);
  426. $dtp->Display();
  427. }
  428. }
  429. //多选联动筛选功能{dede:php}AddFilter(模型id,类型,"字段1,字段2,字段3");{/dede:php}
  430. function litimgurls($imgid = 0)
  431. {
  432. global $lit_imglist, $dsql;
  433. $row = $dsql->GetOne("SELECT c.addtable FROM `#@__archives` AS a LEFT JOIN `#@__channeltype` AS c ON a.channel=c.id where a.id='$imgid'");
  434. $addtable = trim($row['addtable']);
  435. $row = $dsql->GetOne("Select imgurls From `$addtable` where aid='$imgid'");
  436. $ChannelUnit = new ChannelUnit(2, $imgid);
  437. $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']);
  438. return $lit_imglist;
  439. }
  440. //字符过滤函数安全
  441. function string_filter($str, $stype = "inject")
  442. {
  443. if ($stype == "inject") {
  444. $str = str_replace(
  445. array("select", "insert", "update", "delete", "alter", "cas", "union", "into", "load_file", "outfile", "create", "join", "where", "like", "drop", "modify", "rename", "'", "/*", "*", "../", "./"),
  446. array("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""),
  447. $str
  448. );
  449. } else if ($stype == "xss") {
  450. $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",);
  451. $tarr = array(" ", "", "\\1\\2",);
  452. $str = preg_replace($farr, $tarr, $str);
  453. $str = str_replace(
  454. array("<", ">", "'", "\"", ";", "/*", "*", "../", "./"),
  455. array("&lt;", "&gt;", "", "", "", "", "", "", ""),
  456. $str
  457. );
  458. }
  459. return $str;
  460. }
  461. //联动筛选载入自定义表单发布
  462. function AddFilter($channelid, $type = 1, $fieldsnamef = "", $defaulttid = 0, $loadtype = 'autofield')
  463. {
  464. global $tid, $dsql, $id;
  465. $tid = $defaulttid ? $defaulttid : $tid;
  466. $id = intval($id);
  467. $tid = intval($tid);
  468. $channelid = intval($channelid);
  469. if ($id != "") {
  470. $tidsq = $dsql->GetOne("SELECT typeid FROM `#@__archives` WHERE id='$id'");
  471. $tid = $tidsq["typeid"];
  472. }
  473. $nofilter = (isset($_REQUEST['TotalResult']) ? "&TotalResult=".(int)$_REQUEST['TotalResult'] : '').(isset($_REQUEST['PageNo']) ? "&PageNo=".(int)$_REQUEST['PageNo'] : '');
  474. $filterarr = string_filter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/apps/list.php?tid=".$tid);
  475. $cInfos = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$channelid'");
  476. $fieldset = stripslashes($cInfos['fieldset']);
  477. $dtp = new DedeTagParse();
  478. $dtp->SetNameSpace('field', '<', '>');
  479. $dtp->LoadSource($fieldset);
  480. $dede_addonfields = '';
  481. if (is_array($dtp->CTags)) {
  482. foreach ($dtp->CTags as $tida => $ctag) {
  483. $fieldsname = $fieldsnamef ? explode(",", $fieldsnamef) : explode(",", $ctag->GetName());
  484. if (($loadtype != 'autofield' || ($loadtype == 'autofield' && $ctag->GetAtt('autofield') == 1)) && in_array($ctag->GetName(), $fieldsname)) {
  485. $href1 = explode($ctag->GetName().'=', $filterarr);
  486. $href2 = explode('&', $href1[1]);
  487. $fields_value = $href2[0];
  488. $fields_value1 = explode('|', $fields_value);
  489. $dede_addonfields .= ''.$ctag->GetAtt('itemname').':';
  490. switch ($type) {
  491. case 1:
  492. $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is", $filterarr, $regm) ? '<a href="'.str_replace("&".$ctag->GetName()."=".$fields_value, "", $filterarr).'" style="display:inline-block;padding:.25rem .5rem;line-height:1.5;color:#fff;background:#1eb867;border-color:#1eb867;border-radius:.2rem">全部</a>' : '<span style="display:inline-block;padding:.25rem .5rem;line-height:1.5;color:#fff;background:#dc3545;border-color:#dc3545;border-radius:.2rem">全部</span>').'&nbsp;';
  493. $addonfields_items = explode(",", $ctag->GetAtt('default'));
  494. for ($i = 0; $i < count($addonfields_items); $i++) {
  495. $href = stripos($filterarr, $ctag->GetName().'=') ? str_replace("=".$fields_value, "=".$fields_value."|".urlencode($addonfields_items[$i]), $filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  496. $is_select = in_array(urlencode($addonfields_items[$i]), $fields_value1) ? 1 : 0;
  497. $fields_value2 = "";
  498. for ($j = 0; $j < count($fields_value1); $j++) {
  499. $fields_value2 .= $fields_value1[$j] != urlencode($addonfields_items[$i]) ? $fields_value1[$j].($j < count($fields_value1) - 1 ? "|" : "") : "";
  500. }
  501. $fields_value2 = rtrim($fields_value2, "|");
  502. $href3 = str_replace(array("&".$ctag->GetName()."=".$fields_value, $ctag->GetName()."=".$fields_value, "&".$ctag->GetName()."=&"), array("&".$ctag->GetName()."=".$fields_value2, $ctag->GetName()."=".$fields_value2, "&"), $filterarr);
  503. $href3 = !end(explode("=", $href3)) ? str_replace("&".end(explode("&", $href3)), "", $href3) : $href3;
  504. $dede_addonfields .= ($fields_value != urlencode($addonfields_items[$i]) && $is_select != 1 ? '<a title="'.$addonfields_items[$i].'" href="'.$href.'" style="display:inline-block;padding:.25rem .5rem;line-height:1.5;color:#fff;background:#1eb867;border-color:#1eb867;border-radius:.2rem">'.$addonfields_items[$i].'</a>' : '<a title="'.$addonfields_items[$i].'" href="'.$href3.'" style="display:inline-block;padding:.25rem .5rem;line-height:1.5;color:#fff;background:#dc3545;border-color:#dc3545;border-radius:.2rem">'.$addonfields_items[$i].'<span style="margin-left:6px;color:#fff">×</span></a>')."&nbsp;";
  505. }
  506. $dede_addonfields .= '<br>';
  507. break;
  508. case 2:
  509. $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is", $filterarr, $regm) ? '<a href="'.str_replace("&".$ctag->GetName()."=".$fields_value, "", $filterarr).'">全部</a>' : '<span>全部</span>').'&nbsp;';
  510. $addonfields_items = explode(",", $ctag->GetAtt('default'));
  511. for ($i = 0; $i < count($addonfields_items); $i++) {
  512. $href = stripos($filterarr, $ctag->GetName().'=') ? str_replace("=".$fields_value, "=".$fields_value."|".urlencode($addonfields_items[$i]), $filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  513. $is_select = in_array(urlencode($addonfields_items[$i]), $fields_value1) ? 1 : 0;
  514. $fields_value2 = "";
  515. for ($j = 0; $j < count($fields_value1); $j++) {
  516. $fields_value2 .= $fields_value1[$j] != urlencode($addonfields_items[$i]) ? $fields_value1[$j].($j < count($fields_value1) - 1 ? "|" : "") : "";
  517. }
  518. $fields_value2 = rtrim($fields_value2, "|");
  519. $href3 = str_replace(array("&".$ctag->GetName()."=".$fields_value, $ctag->GetName()."=".$fields_value, "&".$ctag->GetName()."=&"), array("&".$ctag->GetName()."=".$fields_value2, $ctag->GetName()."=".$fields_value2, "&"), $filterarr);
  520. $href3 = !end(explode("=", $href3)) ? str_replace("&".end(explode("&", $href3)), "", $href3) : $href3;
  521. $dede_addonfields .= ($fields_value != urlencode($addonfields_items[$i]) && $is_select != 1 ? '<input type="checkbox" title="'.$addonfields_items[$i].'" value="'.$href.'" onclick="window.location=this.value"> <a title="'.$addonfields_items[$i].'" href="'.$href.'">'.$addonfields_items[$i].'</a>' : '<input type="checkbox" checked="checked" title="'.$addonfields_items[$i].'" value="'.$href3.'" onclick="window.location=this.value"> <a title="'.$addonfields_items[$i].'" href="'.$href3.'" class="cur">'.$addonfields_items[$i].'</a>')."&nbsp;";
  522. }
  523. $dede_addonfields .= '<br>';
  524. break;
  525. }
  526. }
  527. }
  528. }
  529. echo $dede_addonfields;
  530. }
  531. //自定义函数接口
  532. if (file_exists(DEDEINC.'/extend.func.php')) {
  533. require_once(DEDEINC.'/extend.func.php');
  534. }