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

505 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 GNU GPL v2 (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. //文档排序的方式
  234. $ordersql = '';
  235. if ($orderby == 'hot' || $orderby == 'click') $ordersql = " ORDER BY arc.click $orderWay";
  236. else if ($orderby == 'sortrank' || $orderby == 'pubdate') $ordersql = " ORDER BY arc.sortrank $orderWay";
  237. else if ($orderby == 'id') $ordersql = " ORDER BY arc.id $orderWay";
  238. else if ($orderby == 'near') $ordersql = " ORDER BY ABS(arc.id - ".$arcid.")";
  239. else if ($orderby == 'lastpost') $ordersql = " ORDER BY arc.lastpost $orderWay";
  240. else if ($orderby == 'scores') $ordersql = " ORDER BY arc.scores $orderWay";
  241. //添加按好评数和差评数调用
  242. else if ($orderby == 'goodpost') $ordersql = " ORDER BY arc.goodpost $orderWay";
  243. else if ($orderby == 'badpost') $ordersql = " ORDER BY arc.badpost $orderWay";
  244. else if ($orderby == 'rand') $ordersql = " ORDER BY rand()";
  245. else $ordersql = " ORDER BY arc.sortrank $orderWay";
  246. //limit条件
  247. $limit = trim(preg_replace('#limit#is', '', $limit));
  248. if ($limit != '') {
  249. $limitsql = " LIMIT $limit ";
  250. $limitarr = explode(',', $limit);
  251. $line = isset($limitarr[1]) ? $limitarr[1] : $line;
  252. } else $limitsql = " LIMIT 0,$line ";
  253. $orwhere = '';
  254. if (isset($orwheres[0])) {
  255. $orwhere = join(' And ', $orwheres);
  256. $orwhere = preg_replace("#^ And#is", '', $orwhere);
  257. $orwhere = preg_replace("#And[ ]{1,}And#is", 'And ', $orwhere);
  258. }
  259. if ($orwhere != '') $orwhere = "WHERE $orwhere and tp.ishidden != 1";
  260. //获取附加表信息
  261. $addfield = trim($ctag->GetAtt('addfields'));
  262. $addfieldsSql = '';
  263. $addfieldsSqlJoin = '';
  264. if ($addfield != '' && !empty($channelid)) {
  265. $row = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
  266. if (isset($row['addtable']) && trim($row['addtable']) != '') {
  267. $addtable = trim($row['addtable']);
  268. $addfields = explode(',', $addfield);
  269. $row['addtable'] = trim($row['addtable']);
  270. $addfieldsSql = ",addf.".join(',addf.', $addfields);
  271. $addfieldsSqlJoin = " LEFT JOIN `$addtable` addf ON addf.aid = arc.id ";
  272. }
  273. }
  274. $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.userid,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";
  275. //统一hash
  276. $taghash = md5(serialize($ctag).$typeid);
  277. $needSaveCache = true;
  278. //进行tagid的默认处理
  279. if ($pagesize > 0) $tagid = AttDef($tagid, 'tag'.$taghash);
  280. if ($idlist != '' || $GLOBALS['_arclistEnv'] == 'index' || $cfg_index_cache == 0) {
  281. $needSaveCache = false;
  282. } else {
  283. $idlist = GetArclistCache($taghash);
  284. if ($idlist != '') {
  285. $needSaveCache = false;
  286. }
  287. //如果使用的是文档缓存,直接返回结果
  288. if ($cfg_cache_type == 'content' && $idlist != '') {
  289. $idlist = ($idlist == 0 ? '' : $idlist);
  290. return $idlist;
  291. }
  292. }
  293. //指定了id或使用缓存中的id
  294. if ($idlist != '') {
  295. $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.userid,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 WHERE arc.id in($idlist) $ordersql ";
  296. }
  297. $dsql->SetQuery($query);
  298. $dsql->Execute('al');
  299. $artlist = '';
  300. if ($pagesize > 0) $artlist .= "<div id='{$tagid}'>\r\n";
  301. if ($col > 1) $artlist = "<table width='$tablewidth'>\r\n";
  302. $dtp2 = new DedeTagParse();
  303. $dtp2->SetNameSpace('field', '[', ']');
  304. $dtp2->LoadString($innertext);
  305. $GLOBALS['autoindex'] = 0;
  306. $ids = array();
  307. $orderWeight = array();
  308. for ($i = 0; $i < $line; $i++) {
  309. if ($col > 1) $artlist .= "<tr>\r\n";
  310. for ($j = 0; $j < $col; $j++) {
  311. if ($col > 1) $artlist .= "<td width='$colWidth'>\r\n";
  312. if ($row = $dsql->GetArray("al")) {
  313. $ids[] = $row['id'];
  314. //处理一些特殊字段
  315. $row['info'] = $row['infos'] = cn_substr($row['description'], $infolen);
  316. $row['aid'] = $row['id'];
  317. if ($row['corank'] > 0 && $row['arcrank'] == 0) {
  318. $row['arcrank'] = $row['corank'];
  319. }
  320. $row['filename'] = $row['arcurl'] = GetFileUrl(
  321. $row['id'],
  322. $row['typeid'],
  323. $row['senddate'],
  324. $row['title'],
  325. $row['ismake'],
  326. $row['arcrank'],
  327. $row['namerule'],
  328. $row['typedir'],
  329. $row['money'],
  330. $row['filename'],
  331. $row['moresite'],
  332. $row['siteurl'],
  333. $row['sitepath']
  334. );
  335. $row['typeurl'] = GetTypeUrl(
  336. $row['typeid'],
  337. $row['typedir'],
  338. $row['isdefault'],
  339. $row['defaultname'],
  340. $row['ispart'],
  341. $row['namerule2'],
  342. $row['moresite'],
  343. $row['siteurl'],
  344. $row['sitepath']
  345. );
  346. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  347. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
  348. }
  349. if (!preg_match("#^(http|https):\/\/#i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  350. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  351. }
  352. $row['picname'] = $row['litpic'];
  353. $row['stime'] = GetDateMK($row['pubdate']);
  354. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  355. $row['image'] = "<img src='".$row['picname']."' width='$imgwidth' height='$imgheight' title='".preg_replace("#['><]#", "", $row['title'])."'>";
  356. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  357. $row['fulltitle'] = $row['title'];
  358. $row['title'] = cn_substr($row['title'], $titlelen);
  359. if ($row['color'] != '') $row['title'] = "<span style='color:".$row['color']."'>".$row['title']."</span>";
  360. if (preg_match('#b#', $row['flag'])) $row['title'] = "".$row['title']."";
  361. //$row['title'] = "".$row['title']."";
  362. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  363. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  364. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  365. $row['userurl'] = $GLOBALS['cfg_memberurl'].'/index.php?uid='.$row['userid'];
  366. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  367. $row['face'] = empty($row['face'])? $GLOBALS['cfg_mainsite'].'/static/web/img/admin.png' : $row['face'];
  368. if (is_array($dtp2->CTags)) {
  369. foreach ($dtp2->CTags as $k => $ctag) {
  370. if ($ctag->GetName() == 'array') {
  371. //传递整个数组,在runphp模式中有特殊作用
  372. $dtp2->Assign($k, $row);
  373. } else {
  374. if (isset($row[$ctag->GetName()])) $dtp2->Assign($k, $row[$ctag->GetName()]);
  375. else $dtp2->Assign($k, '');
  376. }
  377. }
  378. $GLOBALS['autoindex']++;
  379. }
  380. if ($pagesize > 0) {
  381. if ($GLOBALS['autoindex'] <= $pagesize) {
  382. $liststr = $dtp2->GetResult();
  383. $artlist .= $liststr."\r\n";
  384. } else {
  385. $artlist .= "";
  386. $orderWeight[] = array(
  387. 'weight' => $row['weight'],
  388. 'arclist' => ''
  389. );
  390. }
  391. } else {
  392. $liststr = $dtp2->GetResult();
  393. $artlist .= $liststr."\r\n";
  394. }
  395. $orderWeight[] = array(
  396. 'weight' => $row['weight'],
  397. 'arclist' => $liststr
  398. );
  399. }//if hasRow
  400. else {
  401. $artlist .= '';
  402. }
  403. //进行判断,如果启用排序则文档输出为重新排序后的文档
  404. //var_dump($isweight=='y' && count($orderWeight) == $line);
  405. $isweight = strtolower($isweight);
  406. if ($isweight == 'y') {
  407. $artlist = '';
  408. $orderWeight = list_sort_by($orderWeight, 'weight', 'asc');
  409. foreach ($orderWeight as $vv) {
  410. $artlist .= $vv['arclist'];
  411. }
  412. }
  413. if ($col > 1) $artlist .= "</td>\r\n";
  414. }//Loop Col
  415. if ($col > 1) $i += $col - 1;
  416. if ($col > 1) $artlist .= "</tr>\r\n";
  417. }//loop line
  418. if ($col > 1) $artlist .= "</table>\r\n";
  419. $dsql->FreeResult("al");
  420. $idsstr = join(',', $ids);
  421. //保存ID缓存
  422. if ($needSaveCache) {
  423. if ($idsstr == '') $idsstr = '0';
  424. if ($cfg_cache_type == 'content' && $idsstr != '0') {
  425. $idsstr = addslashes($artlist);
  426. }
  427. $inquery = "INSERT INTO `#@__arccache` (`md5hash`,`uptime`,`cachedata`) VALUES ('".$taghash."','".time()."', '$idsstr'); ";
  428. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arccache` WHERE md5hash='".$taghash."' ");
  429. $dsql->ExecuteNoneQuery($inquery);
  430. }
  431. return $artlist;
  432. }
  433. /**
  434. * 查询缓存
  435. *
  436. * @access public
  437. * @param string $md5hash 唯一识别hash
  438. * @return string
  439. */
  440. function GetArclistCache($md5hash)
  441. {
  442. global $dsql, $envs, $cfg_makesign_cache, $cfg_index_cache, $cfg_cache_type;
  443. if ($cfg_index_cache <= 0) return '';
  444. if (isset($envs['makesign']) && $cfg_makesign_cache == 'N') return '';
  445. $mintime = time() - $cfg_index_cache;
  446. $arr = $dsql->GetOne("SELECT cachedata,uptime FROM `#@__arccache` WHERE md5hash = '$md5hash' ");
  447. if (!is_array($arr)) {
  448. return '';
  449. } else if ($arr['uptime'] < $mintime) {
  450. return '';
  451. } else {
  452. return $arr['cachedata'];
  453. }
  454. }
  455. /**
  456. * 获取自动栏目id
  457. *
  458. * @access public
  459. * @param string $sortid
  460. * @param string $topid
  461. * @return string
  462. */
  463. function lib_GetAutoChannelID($sortid, $topid)
  464. {
  465. global $dsql;
  466. if (empty($sortid)) $sortid = 1;
  467. $getstart = $sortid - 1;
  468. $row = $dsql->GetOne("SELECT id,typename FROM `#@__arctype` WHERE reid='{$topid}' And ispart<2 And ishidden<>'1' ORDER BY sortrank asc limit $getstart,1");
  469. if (!is_array($row)) return 0;
  470. else return $row['id'];
  471. }
  472. /**
  473. * 对查询结果集进行排序
  474. *
  475. * @access public
  476. * @param array $list 查询结果
  477. * @param string $field 排序的字段名
  478. * @param array $sortby 排序类型 asc正向排序 desc逆向排序 nat自然排序
  479. * @return mixed
  480. */
  481. function list_sort_by($list, $field, $sortby = 'asc')
  482. {
  483. if (is_array($list)) {
  484. $refer = $resultSet = array();
  485. foreach ($list as $i => $data)
  486. $refer[$i] = &$data[$field];
  487. switch ($sortby) {
  488. case 'asc'://正向排序
  489. asort($refer);
  490. break;
  491. case 'desc'://逆向排序
  492. arsort($refer);
  493. break;
  494. case 'nat'://自然排序
  495. natcasesort($refer);
  496. break;
  497. }
  498. foreach ($refer as $key => $val)
  499. $resultSet[] = &$list[$key];
  500. return $resultSet;
  501. }
  502. return false;
  503. }
  504. ?>