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

628 lines
24KB

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