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

111 line
3.2KB

  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. $addsql = '';
  41. if($getall==0 && isset($refObj->Fields['tags']) && !empty($refObj->Fields['aid']))
  42. {
  43. $dsql->SetQuery("SELECT tid FROM `#@__taglist` WHERE aid = '{$refObj->Fields['aid']}' ");
  44. $dsql->Execute();
  45. $ids = '';
  46. while($row = $dsql->GetArray())
  47. {
  48. $ids .= ( $ids=='' ? $row['tid'] : ','.$row['tid'] );
  49. }
  50. if($ids != '')
  51. {
  52. $addsql = " WHERE id IN($ids) ";
  53. }
  54. if($addsql=='') return '';
  55. }
  56. else
  57. {
  58. if(!empty($typeid))
  59. {
  60. $addsql = " WHERE typeid='$typeid' ";
  61. }
  62. }
  63. if($ltype=='rand') $orderby = 'rand() ';
  64. else if($ltype=='week') $orderby=' weekcc DESC ';
  65. else if($ltype=='month') $orderby=' monthcc DESC ';
  66. else if($ltype=='hot') $orderby=' count DESC ';
  67. else if($ltype=='total') $orderby=' total DESC ';
  68. else $orderby = 'addtime DESC ';
  69. $dsql->SetQuery("SELECT * FROM `#@__tagindex` $addsql ORDER BY $orderby LIMIT 0,$num");
  70. $dsql->Execute();
  71. $ctp = new DedeTagParse();
  72. $ctp->SetNameSpace('field','[',']');
  73. $ctp->LoadSource($InnerText);
  74. while($row = $dsql->GetArray())
  75. {
  76. $row['keyword'] = $row['tag'];
  77. $row['tag'] = dede_htmlspecialchars($row['tag']);
  78. $row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";
  79. $row['highlight'] = 0;
  80. if($row['monthcc']>1000 || $row['weekcc']>300 )
  81. {
  82. $row['highlight'] = mt_rand(3,4);
  83. }
  84. else if($row['count']>3000)
  85. {
  86. $row['highlight'] = mt_rand(5,6);
  87. }
  88. else
  89. {
  90. $row['highlight'] = mt_rand(1,2);
  91. }
  92. foreach($ctp->CTags as $tagid=>$ctag)
  93. {
  94. if(isset($row[$ctag->GetName()]))
  95. {
  96. $ctp->Assign($tagid,$row[$ctag->GetName()]);
  97. }
  98. }
  99. $revalue .= $ctp->GetResult();
  100. }
  101. return $revalue;
  102. }