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

172 lines
6.2KB

  1. <?php
  2. /**
  3. * 获取栏目列表标签
  4. *
  5. * @version $Id: channel.lib.php 1 9:29 2010年7月6日Z tianya $
  6. * @package DedeCMS.Taglib
  7. * @copyright Copyright (c) 2007 - 2020, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.com
  10. */
  11. /*>>dede>>
  12. <name>频道标签</name>
  13. <type>全局标记</type>
  14. <for>V55,V56,V57</for>
  15. <description>用于获取栏目列表</description>
  16. <demo>
  17. {dede:channel type='top' row='8' currentstyle="<li><a href='~typelink~' class='thisclass'>~typename~</a> </li>"}
  18. <li><a href='[field:typelink/]'>[field:typename/]</a> </li>
  19. {/dede:channel}
  20. </demo>
  21. <attributes>
  22. <iterm>typeid:栏目ID</iterm>
  23. <iterm>reid:上级栏目ID</iterm>
  24. <iterm>row:调用栏目数</iterm>
  25. <iterm>col:分多少列显示(默认为单列)</iterm>
  26. <iterm>type:son表示下级栏目,self表示同级栏目,top顶级栏目</iterm>
  27. <iterm>currentstyle:应用样式</iterm>
  28. </attributes>
  29. >>dede>>*/
  30. function lib_channel(&$ctag,&$refObj)
  31. {
  32. global $dsql;
  33. $attlist = "typeid|0,reid|0,row|100,col|1,type|son,currentstyle|,cacheid|";
  34. FillAttsDefault($ctag->CAttribute->Items,$attlist);
  35. extract($ctag->CAttribute->Items, EXTR_SKIP);
  36. $innertext = $ctag->GetInnerText();
  37. $line = empty($row) ? 100 : $row;
  38. $likeType = '';
  39. //读取固定的缓存块
  40. $cacheid = trim($cacheid);
  41. if($cacheid !='') {
  42. $likeType = GetCacheBlock($cacheid);
  43. if($likeType != '') return $likeType;
  44. }
  45. $reid = 0;
  46. $topid = 0;
  47. //如果属性里没指定栏目id,从引用类里获取栏目信息
  48. if(empty($typeid))
  49. {
  50. if( isset($refObj->TypeLink->TypeInfos['id']) )
  51. {
  52. $typeid = $refObj->TypeLink->TypeInfos['id'];
  53. $reid = $refObj->TypeLink->TypeInfos['reid'];
  54. $topid = $refObj->TypeLink->TypeInfos['topid'];
  55. }
  56. else {
  57. $typeid = 0;
  58. }
  59. }
  60. //如果指定了栏目id,从数据库获取栏目信息
  61. else
  62. {
  63. $row2 = $dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$typeid' ");
  64. $typeid = $row2['id'];
  65. $reid = $row2['reid'];
  66. $topid = $row2['topid'];
  67. $issetInfos = true;
  68. }
  69. if($type=='' || $type=='sun') $type='son';
  70. if($innertext=='') $innertext = GetSysTemplets("channel_list.htm");
  71. if($type=='top')
  72. {
  73. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
  74. From `#@__arctype` WHERE reid=0 And ishidden<>1 order by sortrank asc limit 0, $line ";
  75. }
  76. else if($type=='son')
  77. {
  78. if($typeid==0) return '';
  79. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
  80. From `#@__arctype` WHERE reid='$typeid' And ishidden<>1 order by sortrank asc limit 0, $line ";
  81. }
  82. else if($type=='self')
  83. {
  84. if($reid==0) return '';
  85. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
  86. FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
  87. }
  88. //And id<>'$typeid'
  89. $needRel = false;
  90. $dtp2 = new DedeTagParse();
  91. $dtp2->SetNameSpace('field','[',']');
  92. $dtp2->LoadSource($innertext);
  93. //检查是否有子栏目,并返回rel提示(用于二级菜单)
  94. if(preg_match('#:rel#', $innertext)) $needRel = true;
  95. if(empty($sql)) return '';
  96. $dsql->SetQuery($sql);
  97. $dsql->Execute();
  98. $totalRow = $dsql->GetTotalRow();
  99. //如果用子栏目模式,当没有子栏目时显示同级栏目
  100. if($type=='son' && $reid!=0 && $totalRow==0)
  101. {
  102. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
  103. FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
  104. $dsql->SetQuery($sql);
  105. $dsql->Execute();
  106. }
  107. $GLOBALS['autoindex'] = 0;
  108. for($i=0;$i < $line;$i++)
  109. {
  110. if($col>1) $likeType .= "<dl>\r\n";
  111. for($j=0; $j<$col; $j++)
  112. {
  113. if($col>1) $likeType .= "<dd>\r\n";
  114. if($row=$dsql->GetArray())
  115. {
  116. $row['sonids'] = $row['rel'] = '';
  117. if($needRel)
  118. {
  119. $row['sonids'] = GetSonIds($row['id'], 0, false);
  120. if($row['sonids']=='') $row['rel'] = '';
  121. else $row['rel'] = " rel='dropmenu{$row['id']}'";
  122. }
  123. //处理同级栏目中,当前栏目的样式
  124. if( ($row['id']==$typeid || ($topid==$row['id'] && $type=='top') ) && $currentstyle!='' )
  125. {
  126. $linkOkstr = $currentstyle;
  127. $row['typelink'] = GetOneTypeUrlA($row);
  128. $linkOkstr = str_replace("~rel~",$row['rel'],$linkOkstr);
  129. $linkOkstr = str_replace("~id~",$row['id'],$linkOkstr);
  130. $linkOkstr = str_replace("~typelink~",$row['typelink'],$linkOkstr);
  131. $linkOkstr = str_replace("~typename~",$row['typename'],$linkOkstr);
  132. $likeType .= $linkOkstr;
  133. }
  134. else
  135. {
  136. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
  137. if(is_array($dtp2->CTags))
  138. {
  139. foreach($dtp2->CTags as $tagid=>$ctag)
  140. {
  141. if(isset($row[$ctag->GetName()])) $dtp2->Assign($tagid,$row[$ctag->GetName()]);
  142. }
  143. }
  144. $likeType .= $dtp2->GetResult();
  145. }
  146. }
  147. if($col>1) $likeType .= "</dd>\r\n";
  148. $GLOBALS['autoindex']++;
  149. }
  150. //Loop Col
  151. if($col>1)
  152. {
  153. $i += $col - 1;
  154. $likeType .= " </dl>\r\n";
  155. }
  156. }
  157. //Loop for $i
  158. $dsql->FreeResult();
  159. if($cacheid !='') {
  160. WriteCacheBlock($cacheid, $likeType);
  161. }
  162. return $likeType;
  163. }