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

523 lines
24KB

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