国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

532 satır
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日Z 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,
  279. tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  280. $addfieldsSql
  281. FROM `$maintable` arc LEFT JOIN `#@__arctype` tp on arc.typeid=tp.id
  282. $addfieldsSqlJoin
  283. $orwhere $ordersql $limitsql";
  284. //统一hash
  285. $taghash = md5(serialize($ctag).$typeid);
  286. $needSaveCache = true;
  287. //进行tagid的默认处理
  288. if ($pagesize > 0) $tagid = AttDef($tagid, 'tag'.$taghash);
  289. if ($idlist != '' || $GLOBALS['_arclistEnv'] == 'index' || $cfg_index_cache == 0) {
  290. $needSaveCache = false;
  291. } else {
  292. $idlist = GetArclistCache($taghash);
  293. if ($idlist != '') {
  294. $needSaveCache = false;
  295. }
  296. //如果使用的是内容缓存,直接返回结果
  297. if ($cfg_cache_type == 'content' && $idlist != '') {
  298. $idlist = ($idlist == 0 ? '' : $idlist);
  299. return $idlist;
  300. }
  301. }
  302. //指定了id或使用缓存中的id
  303. if ($idlist != '') {
  304. $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
  305. $addfieldsSql
  306. FROM `$maintable` arc left join `#@__arctype` tp on arc.typeid=tp.id
  307. $addfieldsSqlJoin
  308. WHERE arc.id in($idlist) $ordersql ";
  309. }
  310. $dsql->SetQuery($query);
  311. $dsql->Execute('al');
  312. $artlist = '';
  313. if ($pagesize > 0) $artlist .= " <div id='{$tagid}'>\r\n";
  314. if ($col > 1) $artlist = "<table width='$tablewidth' cellspacing='0' cellpadding='0'>\r\n";
  315. $dtp2 = new DedeTagParse();
  316. $dtp2->SetNameSpace('field', '[', ']');
  317. $dtp2->LoadString($innertext);
  318. $GLOBALS['autoindex'] = 0;
  319. $ids = array();
  320. $orderWeight = array();
  321. for ($i = 0; $i < $line; $i++) {
  322. if ($col > 1) $artlist .= "<tr>\r\n";
  323. for ($j = 0; $j < $col; $j++) {
  324. if ($col > 1) $artlist .= " <td width='$colWidth'>\r\n";
  325. if ($row = $dsql->GetArray("al")) {
  326. $ids[] = $row['id'];
  327. //处理一些特殊字段
  328. $row['info'] = $row['infos'] = cn_substr($row['description'], $infolen);
  329. $row['id'] = $row['id'];
  330. if ($row['corank'] > 0 && $row['arcrank'] == 0) {
  331. $row['arcrank'] = $row['corank'];
  332. }
  333. $row['filename'] = $row['arcurl'] = GetFileUrl(
  334. $row['id'],
  335. $row['typeid'],
  336. $row['senddate'],
  337. $row['title'],
  338. $row['ismake'],
  339. $row['arcrank'],
  340. $row['namerule'],
  341. $row['typedir'],
  342. $row['money'],
  343. $row['filename'],
  344. $row['moresite'],
  345. $row['siteurl'],
  346. $row['sitepath']
  347. );
  348. $row['typeurl'] = GetTypeUrl(
  349. $row['typeid'],
  350. $row['typedir'],
  351. $row['isdefault'],
  352. $row['defaultname'],
  353. $row['ispart'],
  354. $row['namerule2'],
  355. $row['moresite'],
  356. $row['siteurl'],
  357. $row['sitepath']
  358. );
  359. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  360. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/defaultpic.jpg';
  361. }
  362. if (!preg_match("#^(http|https):\/\/#i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  363. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  364. }
  365. $row['picname'] = $row['litpic'];
  366. $row['stime'] = GetDateMK($row['pubdate']);
  367. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  368. $row['image'] = "<img src='".$row['picname']."' width='$imgwidth' height='$imgheight' title='".preg_replace("#['><]#", "", $row['title'])."'>";
  369. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  370. $row['fulltitle'] = $row['title'];
  371. $row['title'] = cn_substr($row['title'], $titlelen);
  372. if ($row['color'] != '') $row['title'] = "<span style='color:".$row['color']."'>".$row['title']."</span>";
  373. if (preg_match('#b#', $row['flag'])) $row['title'] = "".$row['title']."";
  374. //$row['title'] = "".$row['title']."";
  375. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  376. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  377. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  378. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  379. if (is_array($dtp2->CTags)) {
  380. foreach ($dtp2->CTags as $k => $ctag) {
  381. if ($ctag->GetName() == 'array') {
  382. //传递整个数组,在runphp模式中有特殊作用
  383. $dtp2->Assign($k, $row);
  384. } else {
  385. if (isset($row[$ctag->GetName()])) $dtp2->Assign($k, $row[$ctag->GetName()]);
  386. else $dtp2->Assign($k, '');
  387. }
  388. }
  389. $GLOBALS['autoindex']++;
  390. }
  391. if ($pagesize > 0) {
  392. if ($GLOBALS['autoindex'] <= $pagesize) {
  393. $liststr = $dtp2->GetResult();
  394. $artlist .= $liststr."\r\n";
  395. } else {
  396. $artlist .= "";
  397. $orderWeight[] = array(
  398. 'weight' => $row['weight'],
  399. 'arclist' => ''
  400. );
  401. }
  402. } else {
  403. $liststr = $dtp2->GetResult();
  404. $artlist .= $liststr."\r\n";
  405. }
  406. $orderWeight[] = array(
  407. 'weight' => $row['weight'],
  408. 'arclist' => $liststr
  409. );
  410. }//if hasRow
  411. else {
  412. $artlist .= '';
  413. }
  414. //进行判断,如果启用排序则内容输出为重新排序后的内容
  415. //var_dump($isweight=='y' && count($orderWeight) == $line);
  416. $isweight = strtolower($isweight);
  417. if ($isweight == 'y') {
  418. $artlist = '';
  419. $orderWeight = list_sort_by($orderWeight, 'weight', 'asc');
  420. foreach ($orderWeight as $vv) {
  421. $artlist .= $vv['arclist'];
  422. }
  423. }
  424. if ($col > 1) $artlist .= " </td>\r\n";
  425. }//Loop Col
  426. if ($col > 1) $i += $col - 1;
  427. if ($col > 1) $artlist .= " </tr>\r\n";
  428. }//loop line
  429. if ($col > 1) $artlist .= " </table>\r\n";
  430. $dsql->FreeResult("al");
  431. $idsstr = join(',', $ids);
  432. //分页特殊处理
  433. if ($pagesize > 0) {
  434. $artlist .= " </div>\r\n";
  435. $row = $dsql->GetOne("SELECT tagid FROM `#@__arcmulti` WHERE tagid='$tagid'");
  436. $uptime = time();
  437. $attstr = addslashes(serialize($attarray));
  438. $innertext = addslashes($innertext);
  439. if (!is_array($row)) {
  440. $query = "INSERT INTO `#@__arcmulti`(tagid,uptime,innertext,pagesize,arcids,ordersql,addfieldsSql,addfieldsSqlJoin,attstr)
  441. VALUES('$tagid','$uptime','$innertext','$pagesize','$idsstr','$ordersql','$addfieldsSql','$addfieldsSqlJoin','$attstr');
  442. ";
  443. $dsql->ExecuteNoneQuery($query);
  444. } else {
  445. $query = "UPDATE `#@__arcmulti` SET uptime='$uptime', innertext='$innertext', pagesize='$pagesize', arcids='$idsstr', ordersql='$ordersql', addfieldsSql='$addfieldsSql', addfieldsSqlJoin='$addfieldsSqlJoin', attstr='$attstr' WHERE tagid='$tagid'";
  446. $dsql->ExecuteNoneQuery($query);
  447. }
  448. }
  449. //保存ID缓存
  450. if ($needSaveCache) {
  451. if ($idsstr == '') $idsstr = '0';
  452. if ($cfg_cache_type == 'content' && $idsstr != '0') {
  453. $idsstr = addslashes($artlist);
  454. }
  455. $inquery = "INSERT INTO `#@__arccache`(`md5hash`,`uptime`,`cachedata`) VALUES ('".$taghash."','".time()."', '$idsstr'); ";
  456. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arccache` WHERE md5hash='".$taghash."' ");
  457. $dsql->ExecuteNoneQuery($inquery);
  458. }
  459. return $artlist;
  460. }
  461. /**
  462. * 查询缓存
  463. *
  464. * @access public
  465. * @param string $md5hash 唯一识别hash
  466. * @return string
  467. */
  468. function GetArclistCache($md5hash)
  469. {
  470. global $dsql, $envs, $cfg_makesign_cache, $cfg_index_cache, $cfg_cache_type;
  471. if ($cfg_index_cache <= 0) return '';
  472. if (isset($envs['makesign']) && $cfg_makesign_cache == 'N') return '';
  473. $mintime = time() - $cfg_index_cache;
  474. $arr = $dsql->GetOne("SELECT cachedata,uptime FROM `#@__arccache` WHERE md5hash = '$md5hash' ");
  475. if (!is_array($arr)) {
  476. return '';
  477. } else if ($arr['uptime'] < $mintime) {
  478. return '';
  479. } else {
  480. return $arr['cachedata'];
  481. }
  482. }
  483. /**
  484. * 获取自动频道ID
  485. *
  486. * @access public
  487. * @param string $sortid
  488. * @param string $topid
  489. * @return string
  490. */
  491. function lib_GetAutoChannelID($sortid, $topid)
  492. {
  493. global $dsql;
  494. if (empty($sortid)) $sortid = 1;
  495. $getstart = $sortid - 1;
  496. $row = $dsql->GetOne("SELECT id,typename FROM `#@__arctype` WHERE reid='{$topid}' And ispart<2 And ishidden<>'1' ORDER BY sortrank asc limit $getstart,1");
  497. if (!is_array($row)) return 0;
  498. else return $row['id'];
  499. }
  500. /**
  501. * 对查询结果集进行排序
  502. *
  503. * @access public
  504. * @param array $list 查询结果
  505. * @param string $field 排序的字段名
  506. * @param array $sortby 排序类型 asc正向排序 desc逆向排序 nat自然排序
  507. * @return array
  508. */
  509. function list_sort_by($list, $field, $sortby = 'asc')
  510. {
  511. if (is_array($list)) {
  512. $refer = $resultSet = array();
  513. foreach ($list as $i => $data)
  514. $refer[$i] = &$data[$field];
  515. switch ($sortby) {
  516. case 'asc'://正向排序
  517. asort($refer);
  518. break;
  519. case 'desc'://逆向排序
  520. arsort($refer);
  521. break;
  522. case 'nat'://自然排序
  523. natcasesort($refer);
  524. break;
  525. }
  526. foreach ($refer as $key => $val)
  527. $resultSet[] = &$list[$key];
  528. return $resultSet;
  529. }
  530. return false;
  531. }