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

98 lines
3.3KB

  1. <?php
  2. //function GetTags($num,$ltype='new',$InnerText='')
  3. /**
  4. * TAG调用标签
  5. *
  6. * @version $Id: tag.lib.php 1 9:29 2010年7月6日Z tianya $
  7. * @package DedeCMS.Taglib
  8. * @copyright Copyright (c) 2007 - 2020, DesDev, Inc.
  9. * @license http://help.dedecms.com/usersguide/license.html
  10. * @link http://www.dedecms.com
  11. */
  12. /*>>dede>>
  13. <name>TAG调用</name>
  14. <type>全局标记</type>
  15. <for>V55,V56,V57</for>
  16. <description>TAG调用标签</description>
  17. <demo>
  18. {dede:tag sort='new' getall='0'}
  19. <a href='[field:link/]'>[field:tag /]</a>
  20. {/dede:tag}
  21. </demo>
  22. <attributes>
  23. <iterm>row:调用条数</iterm>
  24. <iterm>sort:排序方式 month,rand,week</iterm>
  25. <iterm>getall:获取类型 0 为当前内容页TAG标记,1为获取全部TAG标记</iterm>
  26. </attributes>
  27. >>dede>>*/
  28. function lib_tag(&$ctag, &$refObj)
  29. {
  30. global $dsql, $envs, $cfg_cmsurl;
  31. //属性处理
  32. $attlist = "row|30,sort|new,getall|0,typeid|0";
  33. FillAttsDefault($ctag->CAttribute->Items, $attlist);
  34. extract($ctag->CAttribute->Items, EXTR_SKIP);
  35. $InnerText = $ctag->GetInnerText();
  36. if (trim($InnerText) == '') $InnerText = GetSysTemplets('tag_one.htm');
  37. $revalue = '';
  38. $ltype = $sort;
  39. $num = $row;
  40. $dd = $dsql->GetOne("SELECT ROUND(AVG(total)) as tt FROM `#@__tagindex`"); // 取一个平均
  41. $addsql = "WHERE 1=1 AND total >= {$dd['tt']}";
  42. if ($getall == 0 && isset($refObj->Fields['tags']) && !empty($refObj->Fields['aid'])) {
  43. $dsql->SetQuery("SELECT tid FROM `#@__taglist` WHERE aid = '{$refObj->Fields['aid']}' ");
  44. $dsql->Execute();
  45. $ids = '';
  46. while ($row = $dsql->GetArray()) {
  47. $ids .= ($ids == '' ? $row['tid'] : ',' . $row['tid']);
  48. }
  49. if ($ids != '') {
  50. $addsql .= " AND id IN($ids) AND";
  51. }
  52. if ($addsql == '') return '';
  53. } else {
  54. if (!empty($typeid)) {
  55. $addsql .= " AND typeid='$typeid'";
  56. }
  57. }
  58. if ($ltype == 'rand') $orderby = 'rand() ';
  59. else if ($ltype == 'week') $orderby = ' weekcc DESC ';
  60. else if ($ltype == 'month') $orderby = ' monthcc DESC ';
  61. else if ($ltype == 'hot') $orderby = ' count DESC ';
  62. else if ($ltype == 'total') $orderby = ' total DESC ';
  63. else $orderby = 'addtime DESC ';
  64. $dsql->SetQuery("SELECT * FROM `#@__tagindex` $addsql ORDER BY $orderby LIMIT 0,$num");
  65. $dsql->Execute();
  66. $ctp = new DedeTagParse();
  67. $ctp->SetNameSpace('field', '[', ']');
  68. $ctp->LoadSource($InnerText);
  69. while ($row = $dsql->GetArray()) {
  70. $row['keyword'] = $row['tag'];
  71. $row['tag'] = dede_htmlspecialchars($row['tag']);
  72. if (isset($envs['makeTag']) && $envs['makeTag'] == 1) {
  73. $row['link'] = $cfg_cmsurl . "/a/tags/" . GetPinyin($row['keyword']) . "/";
  74. } else {
  75. $row['link'] = $cfg_cmsurl . "/tags.php?/" . urlencode($row['keyword']) . "/";
  76. }
  77. $row['highlight'] = mt_rand(1, 10);
  78. foreach ($ctp->CTags as $tagid => $ctag) {
  79. if (isset($row[$ctag->GetName()])) {
  80. $ctp->Assign($tagid, $row[$ctag->GetName()]);
  81. }
  82. }
  83. $revalue .= $ctp->GetResult();
  84. }
  85. return $revalue;
  86. }