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