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

175 lines
6.3KB

  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. if (is_array($row2)) {
  65. $typeid = $row2['id'];
  66. $reid = $row2['reid'];
  67. $topid = $row2['topid'];
  68. $issetInfos = true;
  69. }
  70. }
  71. if($type=='' || $type=='sun') $type='son';
  72. if($innertext=='') $innertext = GetSysTemplets("channel_list.htm");
  73. if($type=='top')
  74. {
  75. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
  76. From `#@__arctype` WHERE reid=0 And ishidden<>1 order by sortrank asc limit 0, $line ";
  77. }
  78. else if($type=='son')
  79. {
  80. if($typeid==0) return '';
  81. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
  82. From `#@__arctype` WHERE reid='$typeid' And ishidden<>1 order by sortrank asc limit 0, $line ";
  83. }
  84. else if($type=='self')
  85. {
  86. if($reid==0) return '';
  87. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
  88. FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
  89. }
  90. //And id<>'$typeid'
  91. $needRel = false;
  92. $dtp2 = new DedeTagParse();
  93. $dtp2->SetNameSpace('field','[',']');
  94. $dtp2->LoadSource($innertext);
  95. //检查是否有子栏目,并返回rel提示(用于二级菜单)
  96. if(preg_match('#:rel#', $innertext)) $needRel = true;
  97. if(empty($sql)) return '';
  98. $dsql->SetQuery($sql);
  99. $dsql->Execute();
  100. $totalRow = $dsql->GetTotalRow();
  101. //如果用子栏目模式,当没有子栏目时显示同级栏目
  102. if($type=='son' && $reid!=0 && $totalRow==0)
  103. {
  104. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
  105. FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
  106. $dsql->SetQuery($sql);
  107. $dsql->Execute();
  108. }
  109. $GLOBALS['autoindex'] = 0;
  110. for($i=0;$i < $line;$i++)
  111. {
  112. if($col>1) $likeType .= "<dl>\r\n";
  113. for($j=0; $j<$col; $j++)
  114. {
  115. if($col>1) $likeType .= "<dd>\r\n";
  116. if($row=$dsql->GetArray())
  117. {
  118. $row['sonids'] = $row['rel'] = '';
  119. if($needRel)
  120. {
  121. $row['sonids'] = GetSonIds($row['id'], 0, false);
  122. if($row['sonids']=='') $row['rel'] = '';
  123. else $row['rel'] = " rel='dropmenu{$row['id']}'";
  124. }
  125. //处理同级栏目中,当前栏目的样式
  126. if( ($row['id']==$typeid || ($topid==$row['id'] && $type=='top') ) && $currentstyle!='' )
  127. {
  128. $linkOkstr = $currentstyle;
  129. $row['typelink'] = GetOneTypeUrlA($row);
  130. $linkOkstr = str_replace("~rel~",$row['rel'],$linkOkstr);
  131. $linkOkstr = str_replace("~id~",$row['id'],$linkOkstr);
  132. $linkOkstr = str_replace("~typelink~",$row['typelink'],$linkOkstr);
  133. $linkOkstr = str_replace("~typename~",$row['typename'],$linkOkstr);
  134. $likeType .= $linkOkstr;
  135. }
  136. else
  137. {
  138. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
  139. if(is_array($dtp2->CTags))
  140. {
  141. foreach($dtp2->CTags as $tagid=>$ctag)
  142. {
  143. if(isset($row[$ctag->GetName()])) $dtp2->Assign($tagid,$row[$ctag->GetName()]);
  144. }
  145. }
  146. $likeType .= $dtp2->GetResult();
  147. }
  148. }
  149. if($col>1) $likeType .= "</dd>\r\n";
  150. $GLOBALS['autoindex']++;
  151. }
  152. //Loop Col
  153. if($col>1)
  154. {
  155. $i += $col - 1;
  156. $likeType .= " </dl>\r\n";
  157. }
  158. }
  159. //Loop for $i
  160. $dsql->FreeResult();
  161. if($cacheid !='') {
  162. WriteCacheBlock($cacheid, $likeType);
  163. }
  164. return $likeType;
  165. }