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

661 lines
27KB

  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="position:relative;padding:.75rem 1.25rem;width:auto;font-size:12px;color:~color~;background:~background~;border-color:~border~;border:1px solid transparent;border-radius:.2rem">~content~</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. *
  34. * @version $id:common.func.php 4 16:39 2010年7月6日 tianya $
  35. * @package DedeBIZ.Libraries
  36. * @copyright Copyright (c) 2022 DedeBIZ.COM
  37. * @license https://www.dedebiz.com/license
  38. * @link https://www.dedebiz.com
  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. return mysqli_close($link);
  69. }
  70. }
  71. if (!function_exists('mysql_free_result') and function_exists('mysqli_free_result')) {
  72. function mysql_free_result($result)
  73. {
  74. return mysqli_free_result($result);
  75. }
  76. }
  77. if (!function_exists('split')) {
  78. function split($pattern, $string)
  79. {
  80. return explode($pattern, $string);
  81. }
  82. }
  83. }
  84. //一个支持在PHP Cli Server打印的方法
  85. function var_dump_cli($val,...$values)
  86. {
  87. ob_start();
  88. var_dump($val,$values);
  89. error_log(ob_get_clean(), 4);
  90. }
  91. function get_mime_type($filename)
  92. {
  93. if (!function_exists('finfo_open')) {
  94. return 'unknow/octet-stream';
  95. }
  96. $finfo = finfo_open(FILEINFO_MIME_TYPE);
  97. $mimeType = finfo_file($finfo, $filename);
  98. finfo_close($finfo);
  99. return $mimeType;
  100. }
  101. function is_all_numeric(array $array)
  102. {
  103. foreach ($array as $item) {
  104. if (!is_numeric($item)) return false;
  105. }
  106. return true;
  107. }
  108. function make_hash()
  109. {
  110. $rand = dede_random_bytes(16);
  111. $_SESSION['token'] = ($rand === FALSE)
  112. ? md5(uniqid(mt_rand(), TRUE))
  113. : bin2hex($rand);
  114. return $_SESSION['token'];
  115. }
  116. function dede_random_bytes($length)
  117. {
  118. if (empty($length) or !ctype_digit((string) $length)) {
  119. return FALSE;
  120. }
  121. if (function_exists('openssl_random_pseudo_bytes')) {
  122. return openssl_random_pseudo_bytes($length);
  123. }
  124. if (function_exists('random_bytes')) {
  125. try {
  126. return random_bytes((int) $length);
  127. } catch (Exception $e) {
  128. return FALSE;
  129. }
  130. }
  131. if (is_readable('/dev/urandom') && ($fp = fopen('/dev/urandom', 'rb')) !== FALSE) {
  132. version_compare(PHP_VERSION, '5.4.0', '>=') && stream_set_chunk_size($fp, $length);
  133. $output = fread($fp, $length);
  134. fclose($fp);
  135. if ($output !== FALSE) {
  136. return $output;
  137. }
  138. }
  139. return FALSE;
  140. }
  141. //SQL语句过滤程序,由80sec提供,这里作了适当的修改
  142. if (!function_exists('CheckSql')) {
  143. function CheckSql($db_string, $querytype = 'select')
  144. {
  145. global $cfg_cookie_encode;
  146. $clean = '';
  147. $error = '';
  148. $old_pos = 0;
  149. $pos = -1;
  150. $enkey = substr(md5(substr($cfg_cookie_encode.'dedebiz', 0, 5)), 0, 10);
  151. $log_file = DEDEDATA.'/checksql_'.$enkey.'_safe.txt';
  152. $userIP = GetIP();
  153. $getUrl = GetCurUrl();
  154. //如果是普通查询语句,直接过滤一些特殊语法
  155. if ($querytype == 'select') {
  156. $notallow1 = "[^0-9a-z@\._-]{1,}(union|sleep|benchmark|load_file|outfile)[^0-9a-z@\.-]{1,}";
  157. //$notallow2 = "--|/\*";
  158. if (preg_match("/".$notallow1."/i", $db_string)) {
  159. fputs(fopen($log_file, 'a+'), "$userIP||$getUrl||$db_string||SelectBreak\r\n");
  160. exit("<span>Safe Alert: Request Error step 1 !</span>");
  161. }
  162. }
  163. //完整的SQL检查
  164. while (TRUE) {
  165. $pos = strpos($db_string, '\'', $pos + 1);
  166. if ($pos === FALSE) {
  167. break;
  168. }
  169. $clean .= substr($db_string, $old_pos, $pos - $old_pos);
  170. while (TRUE) {
  171. $pos1 = strpos($db_string, '\'', $pos + 1);
  172. $pos2 = strpos($db_string, '\\', $pos + 1);
  173. if ($pos1 === FALSE) {
  174. break;
  175. } elseif ($pos2 == FALSE || $pos2 > $pos1) {
  176. $pos = $pos1;
  177. break;
  178. }
  179. $pos = $pos2 + 1;
  180. }
  181. $clean .= '$s$';
  182. $old_pos = $pos + 1;
  183. }
  184. $clean .= substr($db_string, $old_pos);
  185. $clean = trim(strtolower(preg_replace(array('~\s+~s'), array(' '), $clean)));
  186. if (
  187. strpos($clean, '@') !== FALSE or strpos($clean, 'char(') !== FALSE or strpos($clean, '"') !== FALSE
  188. or strpos($clean, '$s$$s$') !== FALSE
  189. ) {
  190. $fail = TRUE;
  191. if (preg_match("#^create table#i", $clean)) $fail = FALSE;
  192. $error = "unusual character";
  193. }
  194. //老版本的Mysql并不支持union,常用的程序里也不使用union,但是一些黑客使用它,所以检查它
  195. if (strpos($clean, 'union') !== FALSE && preg_match('~(^|[^a-z])union($|[^[a-z])~s', $clean) != 0) {
  196. $fail = TRUE;
  197. $error = "union detect";
  198. }
  199. //发布版本的程序可能比较少包括--,#这样的注释,但是黑客经常使用它们
  200. elseif (strpos($clean, '/*') > 2 || strpos($clean, '--') !== FALSE || strpos($clean, '#') !== FALSE) {
  201. $fail = TRUE;
  202. $error = "comment detect";
  203. }
  204. //这些函数不会被使用,但是黑客会用它来操作文件,down掉数据库
  205. elseif (strpos($clean, 'sleep') !== FALSE && preg_match('~(^|[^a-z])sleep($|[^[a-z])~s', $clean) != 0) {
  206. $fail = TRUE;
  207. $error = "slown down detect";
  208. } elseif (strpos($clean, 'benchmark') !== FALSE && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
  209. $fail = TRUE;
  210. $error = "slown down detect";
  211. } elseif (strpos($clean, 'load_file') !== FALSE && preg_match('~(^|[^a-z])load_file($|[^[a-z])~s', $clean) != 0) {
  212. $fail = TRUE;
  213. $error = "file fun detect";
  214. } elseif (strpos($clean, 'into outfile') !== FALSE && preg_match('~(^|[^a-z])into\s+outfile($|[^[a-z])~s', $clean) != 0) {
  215. $fail = TRUE;
  216. $error = "file fun detect";
  217. }
  218. //老版本的MYSQL不支持子查询,我们的程序里可能也用得少,但是黑客可以使用它来查询数据库敏感信息
  219. elseif (preg_match('~\([^)]*?select~s', $clean) != 0) {
  220. $fail = TRUE;
  221. $error = "sub select detect";
  222. }
  223. if (!empty($fail)) {
  224. fputs(fopen($log_file, 'a+'), "$userIP||$getUrl||$db_string||$error\r\n");
  225. exit("<span>Safe Alert: Request Error step 2!</span>");
  226. } else {
  227. return $db_string;
  228. }
  229. }
  230. }
  231. /**
  232. * 载入小助手,系统默认载入小助手
  233. * 在/data/helper.inc.php中进行默认小助手初始化的设置,创建一个示例为test.helper.php文件基本文档如下:
  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. /**
  304. * 显示更新信息
  305. *
  306. * @return void
  307. */
  308. function UpdateStat()
  309. {
  310. include_once(DEDEINC."/inc/inc_stat.php");
  311. return SpUpdateStat();
  312. }
  313. $arrs1 = array();
  314. $arrs2 = array();
  315. /**
  316. * 短消息函数,可以在某个动作处理后友好的提示信息
  317. *
  318. * @param string $msg 消息提示信息
  319. * @param string $gourl 跳转地址
  320. * @param int $onlymsg 仅显示信息
  321. * @param int $limittime 限制时间
  322. * @return void
  323. */
  324. function ShowMsg($msg, $gourl, $onlymsg = 0, $limittime = 0)
  325. {
  326. if (strtolower($GLOBALS['format'])==='json') {
  327. echo json_encode(array(
  328. "code"=>0,
  329. "msg"=>$msg,
  330. "gourl"=>$gourl,
  331. ));
  332. return;
  333. }
  334. if (empty($GLOBALS['cfg_plus_dir'])) $GLOBALS['cfg_plus_dir'] = '..';
  335. $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>";
  336. $htmlhead .= "<body><center><script>";
  337. $htmlfoot = "</script></center></body></html>";
  338. $litime = ($limittime == 0 ? 1000 : $limittime);
  339. $func = '';
  340. if ($gourl == '-1') {
  341. if ($limittime == 0) $litime = 5000;
  342. $gourl = "javascript:history.go(-1);";
  343. }
  344. if ($gourl == '' || $onlymsg == 1) {
  345. $msg = "<script>alert(\"".str_replace("\"", "“", $msg)."\");</script>";
  346. } else {
  347. //当网址为:close::objname时,关闭父框架的id=objname元素
  348. if (preg_match('/close::/', $gourl)) {
  349. $tgobj = trim(preg_replace('/close::/', '', $gourl));
  350. $gourl = 'javascript:;';
  351. $func .= "window.parent.document.getElementById('{$tgobj}').style.display='none';\r\n";
  352. }
  353. $func .= "var pgo=0;function JumpUrl(){if (pgo==0){location='$gourl'; pgo=1;}}";
  354. $rmsg = $func;
  355. $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:#f5f5f5}a{color:#1eb867;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 #f5f5f5}.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:#1eb867;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)}.text-primary{color:#007bff!important}@media (max-width:768px){body{padding:0 15px}.tips{width:100%}}</style>\");";
  356. $rmsg .= "document.write(\"<div class='tips'>";
  357. $rmsg .= "<div class='tips-head'><p>提示信息</p></div>\");";
  358. $rmsg .= "document.write(\"<div class='tips-box'>\");";
  359. $rmsg .= "document.write(\"".str_replace("\"", "“", $msg)."\");";
  360. $rmsg .= "document.write(\"";
  361. if ($onlymsg == 0) {
  362. if ($gourl != 'javascript:;' && $gourl != '') {
  363. $rmsg .= "<div class='btn'><a href='{$gourl}'>点击反应</a></div>\");";
  364. $rmsg .= "setTimeout('JumpUrl()',$litime);";
  365. } else {
  366. $rmsg .= "</div>\");";
  367. }
  368. } else {
  369. $rmsg .= "</div>\");";
  370. }
  371. $msg = $htmlhead.$rmsg.$htmlfoot;
  372. }
  373. echo $msg;
  374. }
  375. /**
  376. * 表中是否存在某个字段
  377. *
  378. * @param mixed $tablename 表名称
  379. * @param mixed $field 字段名
  380. * @return void
  381. */
  382. function TableHasField($tablename,$field)
  383. {
  384. global $dsql;
  385. $dsql->GetTableFields($tablename,"tfd");
  386. while ($r = $dsql->GetFieldObject("tfd")) {
  387. if ($r->name === $field) {
  388. return true;
  389. }
  390. }
  391. return false;
  392. }
  393. /**
  394. * 获取验证码的session值
  395. *
  396. * @return string
  397. */
  398. function GetCkVdValue()
  399. {
  400. @session_id($_COOKIE['PHPSESSID']);
  401. @session_start();
  402. return isset($_SESSION['securimage_code_value']) ? $_SESSION['securimage_code_value'] : '';
  403. }
  404. /**
  405. * PHP某些版本有Bug,不能在同一作用域中同时读session并改注销它,因此调用后需执行本函数
  406. *
  407. * @return void
  408. */
  409. function ResetVdValue()
  410. {
  411. @session_start();
  412. $_SESSION['securimage_code_value'] = '';
  413. }
  414. function IndexSub($idx, $num)
  415. {
  416. return intval($idx) - intval($num) == 0 ? '0 ' : intval($idx) - intval($num);
  417. }
  418. //用来返回index的active
  419. function IndexActive($idx)
  420. {
  421. if ($idx == 1) {
  422. return ' active';
  423. } else {
  424. return '';
  425. }
  426. }
  427. //是否是HTTPS
  428. function IsSSL()
  429. {
  430. if (@$_SERVER['HTTPS'] && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))) {
  431. return true;
  432. } elseif ('https' == @$_SERVER['REQUEST_SCHEME']) {
  433. return true;
  434. } elseif ('443' == $_SERVER['SERVER_PORT']) {
  435. return true;
  436. } elseif ('https' == @$_SERVER['HTTP_X_FORWARDED_PROTO']) {
  437. return true;
  438. }
  439. return false;
  440. }
  441. //获取对应版本号的更新SQL
  442. function GetUpdateSQL()
  443. {
  444. global $cfg_dbprefix,$cfg_dbtype,$cfg_db_language;
  445. $result = array();
  446. $query = '';
  447. $sql4tmp = "ENGINE=MyISAM DEFAULT CHARSET=".$cfg_db_language;
  448. $fp = fopen(DEDEROOT.'/install/update.txt','r');
  449. $sqls = array();
  450. $current_ver = "";
  451. while(!feof($fp))
  452. {
  453. $line = rtrim(fgets($fp,1024));
  454. if (preg_match("/\-\- ([\d\.]+)/",$line,$matches)) {
  455. if (count($sqls) > 0) {
  456. $result[$current_ver] = $sqls;
  457. }
  458. $sqls = array();
  459. $current_ver = $matches[1];
  460. }
  461. if (preg_match("#;$#", $line))
  462. {
  463. $query .= $line."\n";
  464. $query = str_replace('#@__',$cfg_dbprefix,$query);
  465. if ( $cfg_dbtype == 'sqlite' )
  466. {
  467. $query = preg_replace('/character set (.*?) /i','',$query);
  468. $query = preg_replace('/unsigned/i','',$query);
  469. $query = str_replace('TYPE=MyISAM','',$query);
  470. $query = preg_replace ('/TINYINT\(([\d]+)\)/i','INTEGER',$query);
  471. $query = preg_replace ('/mediumint\(([\d]+)\)/i','INTEGER',$query);
  472. $query = preg_replace ('/smallint\(([\d]+)\)/i','INTEGER',$query);
  473. $query = preg_replace('/int\(([\d]+)\)/i','INTEGER',$query);
  474. $query = preg_replace('/auto_increment/i','PRIMARY KEY AUTOINCREMENT',$query);
  475. $query = preg_replace('/,([\t\s ]+)KEY(.*?)MyISAM;/','',$query);
  476. $query = preg_replace('/,([\t\s ]+)KEY(.*?);/',');',$query);
  477. $query = preg_replace('/,([\t\s ]+)UNIQUE KEY(.*?);/',');',$query);
  478. $query = preg_replace('/set\(([^\)]*?)\)/','varchar',$query);
  479. $query = preg_replace('/enum\(([^\)]*?)\)/','varchar',$query);
  480. if ( preg_match("/PRIMARY KEY AUTOINCREMENT/",$query) )
  481. {
  482. $query = preg_replace('/,([\t\s ]+)PRIMARY KEY([\t\s ]+)\(`([0-9a-zA-Z]+)`\)/i','',$query);
  483. }
  484. $sqls[] = $query;
  485. // $db->exec($query);
  486. } else {
  487. if (preg_match('#CREATE#i', $query))
  488. {
  489. $sqls[] = preg_replace("#TYPE=MyISAM#i",$sql4tmp,$query);
  490. } else {
  491. $sqls[] = $query;
  492. }
  493. }
  494. $query='';
  495. } else if (!preg_match("#^(\/\/|--)#", $line))
  496. {
  497. $query .= $line;
  498. }
  499. }
  500. if (count($sqls) > 0) {
  501. $result[$current_ver] = $sqls;
  502. }
  503. fclose($fp);
  504. return $result;
  505. }
  506. //用户名称标签{dede:field.mid function="GetMemberInfos('uname',@me)"/}和[field:mid function="GetMemberInfos('uname',@me)"/]
  507. function GetMemberInfos($fields, $mid)
  508. {
  509. global $dsql;
  510. if ($mid <= 0) {
  511. $revalue = "Error";
  512. } else {
  513. $row=$dsql->GetOne("SELECT * FROM `#@__member` WHERE mid='{$mid}'");
  514. if (!is_array($row)) {
  515. $revalue = "Not user";
  516. } else {
  517. $revalue = $row[$fields];
  518. }
  519. }
  520. return $revalue;
  521. }
  522. //用户头像标签{dede:field.mid function='face(@me)'/}和[field:mid function='face(@me)'/]
  523. function face($mid)
  524. {
  525. global $dsql;
  526. if ($mid <> 0) {
  527. $row = $dsql->GetOne("SELECT * FROM `#@__member` WHERE mid='$mid'");
  528. if ($row['face'] == "") {
  529. $face = "/static/web/img/admin.png";
  530. } else {
  531. $face = $row['face'];
  532. $face = "$face";
  533. }
  534. }
  535. return $face;
  536. }
  537. //标签调用标签[field:id function='GetMyTags(@me,2)'/]2表示输出2个文档
  538. if (!function_exists('GetMyTags')) {
  539. function GetMyTags($aid, $num=3) {
  540. global $dsql,$cfg_cmspath;
  541. $tags = '';
  542. $query = "SELECT * FROM `#@__taglist` WHERE aid='$aid' LIMIT $num";
  543. $dsql->Execute('tag',$query);
  544. while($row = $dsql->GetArray('tag')) {
  545. $link = $cfg_cmspath."/apps/tags.php?/{$row['tid']}";
  546. $tags.= ($tags==''?"<a href='{$link}'>{$row['tag']}</a>" : "<a href='{$link}'>{$row['tag']}</a>");
  547. }
  548. return $tags;
  549. }
  550. }
  551. /*用户中心调用默认模板<?php pasterTempletDiy('head.htm');?>*/
  552. if (!function_exists('pasterTempletDiy')) {
  553. function pasterTempletDiy($path) {
  554. global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
  555. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$cfg_df_style.'/'.$path;
  556. $dtp = new PartView();
  557. $dtp->SetTemplet($tmpfile);
  558. $dtp->Display();
  559. }
  560. }
  561. //联动单筛选标签{dede:php}AddFilter(模型id,类型,'字段1,字段2');{/dede:php}
  562. function litimgurls($imgid = 0)
  563. {
  564. global $lit_imglist, $dsql;
  565. $row = $dsql->GetOne("SELECT c.addtable FROM `#@__archives` AS a LEFT JOIN `#@__channeltype` AS c ON a.channel=c.id WHERE a.id='$imgid'");
  566. $addtable = trim($row['addtable']);
  567. $row = $dsql->GetOne("SELECT imgurls FROM `$addtable` WHERE aid='$imgid'");
  568. $ChannelUnit = new ChannelUnit(2, $imgid);
  569. $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']);
  570. return $lit_imglist;
  571. }
  572. //联动单筛选字符过滤函数
  573. function string_filter($str, $stype = "inject")
  574. {
  575. if ($stype == "inject") {
  576. $str = str_replace(
  577. array("select", "insert", "update", "delete", "alter", "cas", "union", "into", "load_file", "outfile", "create", "join", "where", "like", "drop", "modify", "rename", "'", "/*", "*", "../", "./"),
  578. array("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""),
  579. $str
  580. );
  581. } else if ($stype == "xss") {
  582. $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",);
  583. $tarr = array(" ", "", "\\1\\2",);
  584. $str = preg_replace($farr, $tarr, $str);
  585. $str = str_replace(
  586. array("<", ">", "'", "\"", ";", "/*", "*", "../", "./"),
  587. array("&lt;", "&gt;", "", "", "", "", "", "", ""),
  588. $str
  589. );
  590. }
  591. return $str;
  592. }
  593. //联动单筛选发布三种类型
  594. function AddFilter($channelid, $type=1, $fieldsnamef=array(), $defaulttid=0, $toptid=0, $loadtype='autofield')
  595. {
  596. global $tid, $dsql, $id, $aid;
  597. $tid = $defaulttid ? $defaulttid : $tid;
  598. if ($id!="" || $aid!="") {
  599. $arcid = $id!="" ? $id : $aid;
  600. $tidsq = $dsql->GetOne("SELECT * FROM `#@__archives` WHERE id='$arcid'");
  601. $tid = $toptid==0 ? $tidsq["typeid"] : $tidsq["topid"];
  602. }
  603. $nofilter = (isset($_REQUEST['TotalResult']) ? "&TotalResult=".$_REQUEST['TotalResult'] : '').(isset($_REQUEST['PageNo']) ? "&PageNo=".$_REQUEST['PageNo'] : '');
  604. $filterarr = string_filter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/plus/list.php?tid=".$tid);
  605. $cInfos = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$channelid'");
  606. $fieldset=$cInfos['fieldset'];
  607. $dtp = new DedeTagParse();
  608. $dtp->SetNameSpace('field', '<', '>');
  609. $dtp->LoadSource($fieldset);
  610. $dede_addonfields = '';
  611. if (is_array($dtp->CTags)) {
  612. foreach($dtp->CTags as $tida=>$ctag)
  613. {
  614. $fieldsname = $fieldsnamef ? explode(",", $fieldsnamef) : explode(",", $ctag->GetName());
  615. if (($loadtype!='autofield' || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1)) && in_array($ctag->GetName(), $fieldsname)) {
  616. $href1 = explode($ctag->GetName().'=', $filterarr);
  617. $href2 = explode('&', $href1[1]);
  618. $fields_value = $href2[0];
  619. switch ($type) {
  620. case 1:
  621. $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>');
  622. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  623. for ($i=0; $i<count($addonfields_items); $i++)
  624. {
  625. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  626. $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>');
  627. }
  628. break;
  629. case 2:
  630. $dede_addonfields .= '<select name="filter'.$ctag->GetName().'" onchange="window.location=this.options[this.selectedIndex].value">
  631. '.'<option value="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'">全部</option>';
  632. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  633. for ($i=0; $i<count($addonfields_items); $i++)
  634. {
  635. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  636. $dede_addonfields .= '<option value="'.$href.'"'.($fields_value==urlencode($addonfields_items[$i]) ? ' selected="selected"' : '').'>'.$addonfields_items[$i].'</option>
  637. ';
  638. }
  639. $dede_addonfields .= '</select>
  640. ';
  641. break;
  642. case 3:
  643. $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? '<a title="全部" 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>');
  644. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  645. for ($i=0; $i<count($addonfields_items); $i++)
  646. {
  647. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  648. $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>');
  649. }
  650. break;
  651. }
  652. }
  653. }
  654. }
  655. echo $dede_addonfields;
  656. }
  657. //自定义函数接口
  658. if (file_exists(DEDEINC.'/extend.func.php')) {
  659. require_once(DEDEINC.'/extend.func.php');
  660. }
  661. ?>