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

121 lines
5.0KB

  1. <?php
  2. /**
  3. * 获取栏目列表标签
  4. *
  5. * @version $id:channel.lib.php 9:29 2010年7月6日 tianya $
  6. * @package DedeBIZ.Taglib
  7. * @copyright Copyright (c) 2022 DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. function lib_channel(&$ctag, &$refObj)
  12. {
  13. global $dsql;
  14. $attlist = "typeid|0,reid|0,row|100,col|1,type|son,currentstyle|,cacheid|";
  15. FillAttsDefault($ctag->CAttribute->Items, $attlist);
  16. extract($ctag->CAttribute->Items, EXTR_SKIP);
  17. $innertext = $ctag->GetInnerText();
  18. $line = empty($row) ? 100 : $row;
  19. $likeType = '';
  20. //读取固定的缓存块
  21. $cacheid = trim($cacheid);
  22. if ($cacheid != '') {
  23. $likeType = GetCacheBlock($cacheid);
  24. if ($likeType != '') return $likeType;
  25. }
  26. $reid = 0;
  27. $topid = 0;
  28. //如果属性里没指定栏目id,从引用类里获取栏目信息
  29. if (empty($typeid)) {
  30. if (isset($refObj->TypeLink->TypeInfos['id'])) {
  31. $typeid = $refObj->TypeLink->TypeInfos['id'];
  32. $reid = $refObj->TypeLink->TypeInfos['reid'];
  33. $topid = $refObj->TypeLink->TypeInfos['topid'];
  34. } else {
  35. $typeid = 0;
  36. }
  37. }
  38. //如果指定了栏目id,从数据库获取栏目信息
  39. else {
  40. $row2 = $dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$typeid' ");
  41. if (is_array($row2)) {
  42. $typeid = $row2['id'];
  43. $reid = $row2['reid'];
  44. $topid = $row2['topid'];
  45. $issetInfos = true;
  46. }
  47. }
  48. if ($type == '' || $type == 'sun') $type = 'son';
  49. if ($innertext == '') $innertext = GetSysTemplets("channel_list.htm");
  50. if ($type == 'top') {
  51. $sql = "SELECT * FROM `#@__arctype` WHERE reid=0 AND ishidden<>1 ORDER BY sortrank ASC LIMIT 0, $line";
  52. } else if ($type == 'son') {
  53. if ($typeid == 0) return '';
  54. $sql = "SELECT * FROM `#@__arctype` WHERE reid='$typeid' AND ishidden<>1 ORDER BY sortrank ASC LIMIT 0, $line";
  55. } else if ($type == 'self') {
  56. if ($reid == 0) return '';
  57. $sql = "SELECT * FROM `#@__arctype` WHERE reid='$reid' AND ishidden<>1 ORDER BY sortrank ASC LIMIT 0, $line";
  58. }
  59. $needRel = false;
  60. $dtp2 = new DedeTagParse();
  61. $dtp2->SetNameSpace('field', '[', ']');
  62. $dtp2->LoadSource($innertext);
  63. //检查是否有子栏目,并返回rel提示用于二级菜单
  64. if (preg_match('#:rel#', $innertext)) $needRel = true;
  65. if (empty($sql)) return '';
  66. $dsql->SetQuery($sql);
  67. $dsql->Execute();
  68. $totalRow = $dsql->GetTotalRow();
  69. //如果用子栏目模式,当没有子栏目时显示同级栏目
  70. if ($type == 'son' && $reid != 0 && $totalRow == 0) {
  71. $sql = "SELECT * FROM `#@__arctype` WHERE reid='$reid' AND ishidden<>1 ORDER BY sortrank ASC LIMIT 0, $line";
  72. $dsql->SetQuery($sql);
  73. $dsql->Execute();
  74. }
  75. $GLOBALS['autoindex'] = 0;
  76. for ($i = 0; $i < $line; $i++) {
  77. if ($col > 1) $likeType .= "<dl>\r\n";
  78. for ($j = 0; $j < $col; $j++) {
  79. if ($col > 1) $likeType .= "<dd>\r\n";
  80. if ($row = $dsql->GetArray()) {
  81. $row['sonids'] = $row['rel'] = '';
  82. if ($needRel) {
  83. $row['sonids'] = GetSonIds($row['id'], 0, false);
  84. if ($row['sonids'] == '') $row['rel'] = '';
  85. else $row['rel'] = " rel='dropmenu{$row['id']}'";
  86. }
  87. //处理同级栏目中,当前栏目的样式
  88. if (($row['id'] == $typeid || ($topid == $row['id'] && $type == 'top')) && $currentstyle != '') {
  89. $linkOkstr = $currentstyle;
  90. $row['typelink'] = GetOneTypeUrlA($row);
  91. $linkOkstr = str_replace("~rel~", $row['rel'], $linkOkstr);
  92. $linkOkstr = str_replace("~id~", $row['id'], $linkOkstr);
  93. $linkOkstr = str_replace("~typelink~", $row['typelink'], $linkOkstr);
  94. $linkOkstr = str_replace("~typename~", $row['typename'], $linkOkstr);
  95. $likeType .= $linkOkstr;
  96. } else {
  97. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
  98. if (is_array($dtp2->CTags)) {
  99. foreach ($dtp2->CTags as $tagid => $ctag) {
  100. if (isset($row[$ctag->GetName()])) $dtp2->Assign($tagid, $row[$ctag->GetName()]);
  101. }
  102. }
  103. $likeType .= $dtp2->GetResult();
  104. }
  105. }
  106. if ($col > 1) $likeType .= "</dd>\r\n";
  107. $GLOBALS['autoindex']++;
  108. }//Loop Col
  109. if ($col > 1) {
  110. $i += $col - 1;
  111. $likeType .= " </dl>\r\n";
  112. }
  113. }//Loop for $i
  114. $dsql->FreeResult();
  115. if ($cacheid != '') {
  116. WriteCacheBlock($cacheid, $likeType);
  117. }
  118. return $likeType;
  119. }
  120. ?>