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

661 lines
26KB

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