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

506 lines
23KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 文档列表标签
  5. *
  6. * @version $id:arclist.lib.php 3 9:19 2010年7月13日 tianya $
  7. * @package DedeBIZ.Taglib
  8. * @copyright Copyright (c) 2022 DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. /**
  13. * arclist解析标签
  14. *
  15. * @access public
  16. * @param object $ctag 解析标签
  17. * @param object $refObj 引用对象
  18. * @return string 成功后返回解析后的标签文档
  19. */
  20. function lib_arclist(&$ctag, &$refObj)
  21. {
  22. global $envs;
  23. $autopartid = 0;
  24. $tagid = '';
  25. $tagname = $ctag->GetTagName();
  26. $channelid = $ctag->GetAtt('channelid');
  27. //添加对分页文档的处理
  28. $pagesize = $ctag->GetAtt('pagesize');
  29. if ($pagesize == '') {
  30. $multi = 0;
  31. } else {
  32. $tagid = $ctag->GetAtt('tagid');
  33. }
  34. //arclist是否需要weight排序,默认为"N",如果需要排序则设置为"Y"
  35. $isweight = $ctag->GetAtt('isweight');
  36. if ($tagname == 'imglist' || $tagname == 'imginfolist') {
  37. $listtype = 'image';
  38. } else if ($tagname == 'specart') {
  39. $channelid = -1;
  40. $listtype = '';
  41. } else if ($tagname == 'coolart') {
  42. $listtype = 'commend';
  43. } else if ($tagname == 'autolist') {
  44. $autopartid = $ctag->GetAtt('partsort');
  45. } else {
  46. $listtype = $ctag->GetAtt('type');
  47. }
  48. //排序
  49. if ($ctag->GetAtt('sort') != '') $orderby = $ctag->GetAtt('sort');
  50. else if ($tagname == 'hotart') $orderby = 'click';
  51. else $orderby = $ctag->GetAtt('orderby');
  52. //对相应的标记使用不同的默认innertext
  53. if (trim($ctag->GetInnerText()) != '') $innertext = $ctag->GetInnerText();
  54. else if ($tagname == 'imglist') $innertext = GetSysTemplets('part_imglist.htm');
  55. else if ($tagname == 'imginfolist') $innertext = GetSysTemplets('part_imginfolist.htm');
  56. else $innertext = GetSysTemplets("part_arclist.htm");
  57. //兼容titlelength
  58. if ($ctag->GetAtt('titlelength') != '') $titlelen = $ctag->GetAtt('titlelength');
  59. else $titlelen = $ctag->GetAtt('titlelen');
  60. //兼容infolength
  61. if ($ctag->GetAtt('infolength') != '') $infolen = $ctag->GetAtt('infolength');
  62. else $infolen = $ctag->GetAtt('infolen');
  63. $typeid = trim($ctag->GetAtt('typeid'));
  64. if (empty($typeid)) {
  65. $typeid = (isset($refObj->Fields['typeid']) ? $refObj->Fields['typeid'] : $envs['typeid']);
  66. }
  67. if ($listtype == 'autolist') {
  68. $typeid = lib_GetAutoChannelID($ctag->GetAtt('partsort'), $typeid);
  69. }
  70. if ($ctag->GetAtt('att') == '') {
  71. $flag = $ctag->GetAtt('flag');
  72. } else {
  73. $flag = $ctag->GetAtt('att');
  74. }
  75. return lib_arclistDone ($refObj, $ctag, $typeid, $ctag->GetAtt('row'), $ctag->GetAtt('col'), $titlelen, $infolen, $ctag->GetAtt('imgwidth'), $ctag->GetAtt('imgheight'), $listtype, $orderby, $ctag->GetAtt('keyword'), $innertext, $envs['aid'], $ctag->GetAtt('idlist'), $channelid, $ctag->GetAtt('limit'), $flag,$ctag->GetAtt('orderway'), $ctag->GetAtt('subday'), $ctag->GetAtt('noflag'), $tagid, $pagesize,$isweight, $ctag->GetAtt('notypeid')
  76. );
  77. }
  78. /**
  79. * arclist解析函数
  80. *
  81. * @access public
  82. * @param object $refObj 引用对象
  83. * @param object $ctag 标签
  84. * @param int $typeid 栏目id
  85. * @param int $row 调用行数
  86. * @param int $titlelen 字符串长度
  87. * @param int $infolen 描述信息长度
  88. * @param int $imgwidth 图片宽度
  89. * @param int $imgheight 图片高度
  90. * @param string $listtype 列表类型
  91. * @param string $orderby 排列顺序
  92. * @param string $keyword 关键词
  93. * @param string $innertext 底层模板
  94. * @param int $arcid 文档id
  95. * @param string $idlist ID列表
  96. * @param int $channelid 栏目id
  97. * @param string $limit 限制
  98. * @param string $att 属性
  99. * @param string $order 排序类型
  100. * @param int $subday 天内
  101. * @param string $noflag 属性标记
  102. * @param string $tagid 标签id
  103. * @param string $pagesize 显示条数
  104. * @param string $isweight 是否需要对检索出来的文档按照weight排序
  105. * @return string
  106. */
  107. function lib_arclistDone (&$refObj, &$ctag, $typeid=0, $row=10, $col=1, $titlelen=30, $infolen=160, $imgwidth=120, $imgheight=90, $listtype='all', $orderby='default', $keyword='', $innertext='', $arcid=0, $idlist='', $channelid=0, $limit='', $att='', $order='desc', $subday=0, $noflag='',$tagid='', $pagesize=0, $isweight='N', $notypeid=0)
  108. {
  109. global $dsql, $PubFields, $cfg_keyword_like, $cfg_index_cache, $_arclistEnv, $envs, $cfg_cache_type, $cfg_digg_update;
  110. $row = AttDef($row, 10);
  111. $titlelen = AttDef($titlelen, 30);
  112. $infolen = AttDef($infolen, 160);
  113. $imgwidth = AttDef($imgwidth, 120);
  114. $imgheight = AttDef($imgheight, 120);
  115. $listtype = AttDef($listtype, 'all');
  116. $arcid = AttDef($arcid, 0);
  117. $channelid = AttDef($channelid, 0);
  118. $orderby = AttDef($orderby, 'default');
  119. $orderWay = AttDef($order, 'desc');
  120. $subday = AttDef($subday, 0);
  121. $pagesize = AttDef($pagesize, 0);
  122. $line = $row;
  123. $orderby = strtolower($orderby);
  124. $keyword = trim($keyword);
  125. $innertext = trim($innertext);
  126. $tablewidth = $ctag->GetAtt('tablewidth');
  127. $writer = $ctag->GetAtt('writer');
  128. if ($tablewidth == "") $tablewidth = 100;
  129. if (empty($col)) $col = 1;
  130. $colWidth = ceil(100 / $col);
  131. $tablewidth = $tablewidth."%";
  132. $colWidth = $colWidth."%";
  133. //记录属性,以便分页样式统一调用
  134. $attarray = compact('row', 'titlelen', 'infolen', 'imgwidth', 'imgheight', 'listtype', 'arcid', 'channelid', 'orderby', 'orderWay', 'subday', 'pagesize', 'orderby', 'keyword', 'tablewidth', 'col', 'colWidth');
  135. if ($innertext == '') $innertext = GetSysTemplets('part_arclist.htm');
  136. if (@$ctag->GetAtt('getall') == 1) $getall = 1;
  137. else $getall = 0;
  138. if ($att == '0') $att = '';
  139. if ($att == '3') $att = 'f';
  140. if ($att == '1') $att = 'h';
  141. $orwheres = array();
  142. $maintable = '#@__archives';
  143. //按不同情况设定SQL条件 排序方式
  144. if ($idlist == '') {
  145. if ($orderby == 'near' && $cfg_keyword_like == 'N') {
  146. $keyword = '';
  147. }
  148. if ($writer == 'this') {
  149. $wmid = isset($refObj->Fields['mid']) ? $refObj->Fields['mid'] : 0;
  150. $orwheres[] = " arc.mid = '$wmid' ";
  151. }
  152. //时间限制(用于调用最近热门文档、热门评论之类)这里的时间只能计算到天,否则缓存功能无效
  153. if ($subday > 0) {
  154. $ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
  155. $limitday = $ntime - ($subday * 24 * 3600);
  156. $orwheres[] = " arc.senddate > $limitday ";
  157. }
  158. //关键词条件
  159. if ($keyword != '') {
  160. $keyword = str_replace(',', '|', $keyword);
  161. $orwheres[] = " CONCAT(arc.title,arc.keywords) REGEXP '$keyword' ";
  162. }
  163. //文档属性
  164. if (preg_match('/commend/i', $listtype)) $orwheres[] = " FIND_IN_SET('c', arc.flag)>0 ";
  165. if (preg_match('/image/i', $listtype)) $orwheres[] = " FIND_IN_SET('p', arc.flag)>0 ";
  166. if ($att != '') {
  167. $flags = explode(',', $att);
  168. for ($i = 0; isset($flags[$i]); $i++) $orwheres[] = " FIND_IN_SET('{$flags[$i]}', arc.flag)>0 ";
  169. }
  170. if (!empty($typeid) && $typeid != 'top') {
  171. //指定了多个栏目时,不再获取子类的id
  172. if (preg_match('#,#', $typeid)) {
  173. //指定了getall属性或首页模板例外
  174. if ($getall == 1 || empty($refObj->Fields['typeid'])) {
  175. $typeids = explode(',', $typeid);
  176. foreach ($typeids as $ttid) {
  177. $typeidss[] = GetSonIds($ttid);
  178. }
  179. $typeidStr = join(',', $typeidss);
  180. $typeidss = explode(',', $typeidStr);
  181. $typeidssok = array_unique($typeidss);
  182. $typeid = join(',', $typeidssok);
  183. }
  184. $orwheres[] = " arc.typeid IN ($typeid) ";
  185. } else {
  186. //处理交叉栏目
  187. $CrossID = '';
  188. if ($ctag->GetAtt('cross') == '1') {
  189. $arr = $dsql->GetOne("SELECT `id`,`topid`,`cross`,`crossid`,`ispart`,`typename` FROM `#@__arctype` WHERE id='$typeid' ");
  190. if ($arr['cross'] == 0 || ($arr['cross'] == 2 && trim($arr['crossid'] == ''))) {
  191. $orwheres[] = ' arc.typeid IN ('.GetSonIds($typeid).')';
  192. } else {
  193. $selquery = '';
  194. if ($arr['cross'] == 1) {
  195. $selquery = "SELECT id,topid FROM `#@__arctype` WHERE typename LIKE '{$arr['typename']}' AND id<>'{$typeid}' AND topid<>'{$typeid}' ";
  196. } else {
  197. $arr['crossid'] = preg_replace('#[^0-9,]#', '', trim($arr['crossid']));
  198. if ($arr['crossid'] != '') $selquery = "SELECT id,topid FROM `#@__arctype` WHERE id IN('{$arr['crossid']}') AND id<>'{$typeid}' AND topid<>'{$typeid}' ";
  199. }
  200. if ($selquery != '') {
  201. $dsql->SetQuery($selquery);
  202. $dsql->Execute();
  203. while ($arr = $dsql->GetArray()) {
  204. $CrossID .= ($CrossID == '' ? $arr['id'] : ','.$arr['id']);
  205. }
  206. }
  207. }
  208. }
  209. if ($CrossID == '') $orwheres[] = ' arc.typeid IN ('.GetSonIds($typeid).')';
  210. else $orwheres[] = ' arc.typeid IN ('.GetSonIds($typeid).','.$CrossID.')';
  211. }
  212. }
  213. //栏目id
  214. if (preg_match('#spec#i', $listtype)) $channelid == -1;
  215. if (!empty($channelid)) $orwheres[] = " And arc.channel = '$channelid' ";
  216. if (!empty($noflag)) {
  217. if (!preg_match('#,#', $noflag)) {
  218. $orwheres[] = " FIND_IN_SET('$noflag', arc.flag)<1 ";
  219. } else {
  220. $noflags = explode(',', $noflag);
  221. foreach ($noflags as $noflag) {
  222. if (trim($noflag) == '') continue;
  223. $orwheres[] = " FIND_IN_SET('$noflag', arc.flag)<1 ";
  224. }
  225. }
  226. }
  227. $orwheres[] = 'arc.arcrank > -1';
  228. //否定指定栏目
  229. if (!empty($notypeid)) {
  230. $orwheres[] = "and arc.typeid NOT IN (".GetSonIds($notypeid).")";
  231. }
  232. //由于这个条件会导致缓存功能失去意义,因此取消
  233. //if ($arcid!=0) $orwheres[] = " arc.id<>'$arcid' ";
  234. }
  235. //文档排序的方式
  236. $ordersql = '';
  237. if ($orderby == 'hot' || $orderby == 'click') $ordersql = " ORDER BY arc.click $orderWay";
  238. else if ($orderby == 'sortrank' || $orderby == 'pubdate') $ordersql = " ORDER BY arc.sortrank $orderWay";
  239. else if ($orderby == 'id') $ordersql = " ORDER BY arc.id $orderWay";
  240. else if ($orderby == 'near') $ordersql = " ORDER BY ABS(arc.id - ".$arcid.")";
  241. else if ($orderby == 'lastpost') $ordersql = " ORDER BY arc.lastpost $orderWay";
  242. else if ($orderby == 'scores') $ordersql = " ORDER BY arc.scores $orderWay";
  243. //添加按好评数和差评数调用
  244. else if ($orderby == 'goodpost') $ordersql = " order by arc.goodpost $orderWay";
  245. else if ($orderby == 'badpost') $ordersql = " order by arc.badpost $orderWay";
  246. else if ($orderby == 'rand') $ordersql = " ORDER BY rand()";
  247. else $ordersql = " ORDER BY arc.sortrank $orderWay";
  248. //limit条件
  249. $limit = trim(preg_replace('#limit#is', '', $limit));
  250. if ($limit != '') {
  251. $limitsql = " LIMIT $limit ";
  252. $limitarr = explode(',', $limit);
  253. $line = isset($limitarr[1]) ? $limitarr[1] : $line;
  254. } else $limitsql = " LIMIT 0,$line ";
  255. $orwhere = '';
  256. if (isset($orwheres[0])) {
  257. $orwhere = join(' And ', $orwheres);
  258. $orwhere = preg_replace("#^ And#is", '', $orwhere);
  259. $orwhere = preg_replace("#And[ ]{1,}And#is", 'And ', $orwhere);
  260. }
  261. if ($orwhere != '') $orwhere = " WHERE $orwhere and tp.ishidden != 1 ";
  262. //获取附加表信息
  263. $addfield = trim($ctag->GetAtt('addfields'));
  264. $addfieldsSql = '';
  265. $addfieldsSqlJoin = '';
  266. if ($addfield != '' && !empty($channelid)) {
  267. $row = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
  268. if (isset($row['addtable']) && trim($row['addtable']) != '') {
  269. $addtable = trim($row['addtable']);
  270. $addfields = explode(',', $addfield);
  271. $row['addtable'] = trim($row['addtable']);
  272. $addfieldsSql = ",addf.".join(',addf.', $addfields);
  273. $addfieldsSqlJoin = " LEFT JOIN `$addtable` addf ON addf.aid = arc.id ";
  274. }
  275. }
  276. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath,mb.uname,mb.face $addfieldsSql FROM `$maintable` arc LEFT JOIN `#@__arctype` tp on arc.typeid=tp.id LEFT JOIN `#@__member` mb on arc.mid = mb.mid $addfieldsSqlJoin $orwhere $ordersql $limitsql";
  277. //统一hash
  278. $taghash = md5(serialize($ctag).$typeid);
  279. $needSaveCache = true;
  280. //进行tagid的默认处理
  281. if ($pagesize > 0) $tagid = AttDef($tagid, 'tag'.$taghash);
  282. if ($idlist != '' || $GLOBALS['_arclistEnv'] == 'index' || $cfg_index_cache == 0) {
  283. $needSaveCache = false;
  284. } else {
  285. $idlist = GetArclistCache($taghash);
  286. if ($idlist != '') {
  287. $needSaveCache = false;
  288. }
  289. //如果使用的是文档缓存,直接返回结果
  290. if ($cfg_cache_type == 'content' && $idlist != '') {
  291. $idlist = ($idlist == 0 ? '' : $idlist);
  292. return $idlist;
  293. }
  294. }
  295. //指定了id或使用缓存中的id
  296. if ($idlist != '') {
  297. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath $addfieldsSql FROM `$maintable` arc left join `#@__arctype` tp on arc.typeid=tp.id $addfieldsSqlJoin WHERE arc.id in($idlist) $ordersql ";
  298. }
  299. $dsql->SetQuery($query);
  300. $dsql->Execute('al');
  301. $artlist = '';
  302. if ($pagesize > 0) $artlist .= "<div id='{$tagid}'>\r\n";
  303. if ($col > 1) $artlist = "<table width='$tablewidth' cellspacing='0' cellpadding='0'>\r\n";
  304. $dtp2 = new DedeTagParse();
  305. $dtp2->SetNameSpace('field', '[', ']');
  306. $dtp2->LoadString($innertext);
  307. $GLOBALS['autoindex'] = 0;
  308. $ids = array();
  309. $orderWeight = array();
  310. for ($i = 0; $i < $line; $i++) {
  311. if ($col > 1) $artlist .= "<tr>\r\n";
  312. for ($j = 0; $j < $col; $j++) {
  313. if ($col > 1) $artlist .= "<td width='$colWidth'>\r\n";
  314. if ($row = $dsql->GetArray("al")) {
  315. $ids[] = $row['id'];
  316. //处理一些特殊字段
  317. $row['info'] = $row['infos'] = cn_substr($row['description'], $infolen);
  318. $row['id'] = $row['id'];
  319. if ($row['corank'] > 0 && $row['arcrank'] == 0) {
  320. $row['arcrank'] = $row['corank'];
  321. }
  322. $row['filename'] = $row['arcurl'] = GetFileUrl(
  323. $row['id'],
  324. $row['typeid'],
  325. $row['senddate'],
  326. $row['title'],
  327. $row['ismake'],
  328. $row['arcrank'],
  329. $row['namerule'],
  330. $row['typedir'],
  331. $row['money'],
  332. $row['filename'],
  333. $row['moresite'],
  334. $row['siteurl'],
  335. $row['sitepath']
  336. );
  337. $row['typeurl'] = GetTypeUrl(
  338. $row['typeid'],
  339. $row['typedir'],
  340. $row['isdefault'],
  341. $row['defaultname'],
  342. $row['ispart'],
  343. $row['namerule2'],
  344. $row['moresite'],
  345. $row['siteurl'],
  346. $row['sitepath']
  347. );
  348. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  349. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
  350. }
  351. if (!preg_match("#^(http|https):\/\/#i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  352. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  353. }
  354. $row['picname'] = $row['litpic'];
  355. $row['stime'] = GetDateMK($row['pubdate']);
  356. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  357. $row['image'] = "<img src='".$row['picname']."' width='$imgwidth' height='$imgheight' title='".preg_replace("#['><]#", "", $row['title'])."'>";
  358. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  359. $row['fulltitle'] = $row['title'];
  360. $row['title'] = cn_substr($row['title'], $titlelen);
  361. if ($row['color'] != '') $row['title'] = "<span style='color:".$row['color']."'>".$row['title']."</span>";
  362. if (preg_match('#b#', $row['flag'])) $row['title'] = "".$row['title']."";
  363. //$row['title'] = "".$row['title']."";
  364. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  365. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  366. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  367. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  368. $row['face'] = empty($row['face'])? $GLOBALS['cfg_mainsite'].'/static/web/img/admin.png' : $row['face'];
  369. if (is_array($dtp2->CTags)) {
  370. foreach ($dtp2->CTags as $k => $ctag) {
  371. if ($ctag->GetName() == 'array') {
  372. //传递整个数组,在runphp模式中有特殊作用
  373. $dtp2->Assign($k, $row);
  374. } else {
  375. if (isset($row[$ctag->GetName()])) $dtp2->Assign($k, $row[$ctag->GetName()]);
  376. else $dtp2->Assign($k, '');
  377. }
  378. }
  379. $GLOBALS['autoindex']++;
  380. }
  381. if ($pagesize > 0) {
  382. if ($GLOBALS['autoindex'] <= $pagesize) {
  383. $liststr = $dtp2->GetResult();
  384. $artlist .= $liststr."\r\n";
  385. } else {
  386. $artlist .= "";
  387. $orderWeight[] = array(
  388. 'weight' => $row['weight'],
  389. 'arclist' => ''
  390. );
  391. }
  392. } else {
  393. $liststr = $dtp2->GetResult();
  394. $artlist .= $liststr."\r\n";
  395. }
  396. $orderWeight[] = array(
  397. 'weight' => $row['weight'],
  398. 'arclist' => $liststr
  399. );
  400. }//if hasRow
  401. else {
  402. $artlist .= '';
  403. }
  404. //进行判断,如果启用排序则文档输出为重新排序后的文档
  405. //var_dump($isweight=='y' && count($orderWeight) == $line);
  406. $isweight = strtolower($isweight);
  407. if ($isweight == 'y') {
  408. $artlist = '';
  409. $orderWeight = list_sort_by($orderWeight, 'weight', 'asc');
  410. foreach ($orderWeight as $vv) {
  411. $artlist .= $vv['arclist'];
  412. }
  413. }
  414. if ($col > 1) $artlist .= "</td>\r\n";
  415. }//Loop Col
  416. if ($col > 1) $i += $col - 1;
  417. if ($col > 1) $artlist .= "</tr>\r\n";
  418. }//loop line
  419. if ($col > 1) $artlist .= "</table>\r\n";
  420. $dsql->FreeResult("al");
  421. $idsstr = join(',', $ids);
  422. //保存ID缓存
  423. if ($needSaveCache) {
  424. if ($idsstr == '') $idsstr = '0';
  425. if ($cfg_cache_type == 'content' && $idsstr != '0') {
  426. $idsstr = addslashes($artlist);
  427. }
  428. $inquery = "INSERT INTO `#@__arccache` (`md5hash`,`uptime`,`cachedata`) VALUES ('".$taghash."','".time()."', '$idsstr'); ";
  429. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arccache` WHERE md5hash='".$taghash."' ");
  430. $dsql->ExecuteNoneQuery($inquery);
  431. }
  432. return $artlist;
  433. }
  434. /**
  435. * 查询缓存
  436. *
  437. * @access public
  438. * @param string $md5hash 唯一识别hash
  439. * @return string
  440. */
  441. function GetArclistCache($md5hash)
  442. {
  443. global $dsql, $envs, $cfg_makesign_cache, $cfg_index_cache, $cfg_cache_type;
  444. if ($cfg_index_cache <= 0) return '';
  445. if (isset($envs['makesign']) && $cfg_makesign_cache == 'N') return '';
  446. $mintime = time() - $cfg_index_cache;
  447. $arr = $dsql->GetOne("SELECT cachedata,uptime FROM `#@__arccache` WHERE md5hash = '$md5hash' ");
  448. if (!is_array($arr)) {
  449. return '';
  450. } else if ($arr['uptime'] < $mintime) {
  451. return '';
  452. } else {
  453. return $arr['cachedata'];
  454. }
  455. }
  456. /**
  457. * 获取自动栏目id
  458. *
  459. * @access public
  460. * @param string $sortid
  461. * @param string $topid
  462. * @return string
  463. */
  464. function lib_GetAutoChannelID($sortid, $topid)
  465. {
  466. global $dsql;
  467. if (empty($sortid)) $sortid = 1;
  468. $getstart = $sortid - 1;
  469. $row = $dsql->GetOne("SELECT id,typename FROM `#@__arctype` WHERE reid='{$topid}' And ispart<2 And ishidden<>'1' ORDER BY sortrank asc limit $getstart,1");
  470. if (!is_array($row)) return 0;
  471. else return $row['id'];
  472. }
  473. /**
  474. * 对查询结果集进行排序
  475. *
  476. * @access public
  477. * @param array $list 查询结果
  478. * @param string $field 排序的字段名
  479. * @param array $sortby 排序类型 asc正向排序 desc逆向排序 nat自然排序
  480. * @return array
  481. */
  482. function list_sort_by($list, $field, $sortby = 'asc')
  483. {
  484. if (is_array($list)) {
  485. $refer = $resultSet = array();
  486. foreach ($list as $i => $data)
  487. $refer[$i] = &$data[$field];
  488. switch ($sortby) {
  489. case 'asc'://正向排序
  490. asort($refer);
  491. break;
  492. case 'desc'://逆向排序
  493. arsort($refer);
  494. break;
  495. case 'nat'://自然排序
  496. natcasesort($refer);
  497. break;
  498. }
  499. foreach ($refer as $key => $val)
  500. $resultSet[] = &$list[$key];
  501. return $resultSet;
  502. }
  503. return false;
  504. }
  505. ?>