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

81 lines
2.8KB

  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) 2020, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. function lib_tag(&$ctag, &$refObj)
  13. {
  14. global $dsql, $envs, $cfg_cmsurl;
  15. //属性处理
  16. $attlist = "row|30,sort|new,getall|0,typeid|0";
  17. FillAttsDefault($ctag->CAttribute->Items, $attlist);
  18. extract($ctag->CAttribute->Items, EXTR_SKIP);
  19. $InnerText = $ctag->GetInnerText();
  20. if (trim($InnerText) == '') $InnerText = GetSysTemplets('tag_one.htm');
  21. $revalue = '';
  22. $ltype = $sort;
  23. $num = $row;
  24. $dd = $dsql->GetOne("SELECT ROUND(AVG(total)) as tt FROM `#@__tagindex`"); // 取一个平均
  25. $addsql = "WHERE 1=1 AND total >= {$dd['tt']}";
  26. if ($getall == 0 && isset($refObj->Fields['tags']) && !empty($refObj->Fields['aid'])) {
  27. $dsql->SetQuery("SELECT tid FROM `#@__taglist` WHERE aid = '{$refObj->Fields['aid']}' ");
  28. $dsql->Execute();
  29. $ids = '';
  30. while ($row = $dsql->GetArray()) {
  31. $ids .= ($ids == '' ? $row['tid'] : ',' . $row['tid']);
  32. }
  33. if ($ids != '') {
  34. $addsql .= " AND id IN($ids)";
  35. }
  36. if ($addsql == '') return '';
  37. } else {
  38. if (!empty($typeid)) {
  39. $addsql .= " AND typeid='$typeid'";
  40. }
  41. }
  42. if ($ltype == 'rand') $orderby = 'rand() ';
  43. else if ($ltype == 'week') $orderby = ' weekcc DESC ';
  44. else if ($ltype == 'month') $orderby = ' monthcc DESC ';
  45. else if ($ltype == 'hot') $orderby = ' count DESC ';
  46. else if ($ltype == 'total') $orderby = ' total DESC ';
  47. else $orderby = 'addtime DESC ';
  48. $dsql->SetQuery("SELECT * FROM `#@__tagindex` $addsql ORDER BY $orderby LIMIT 0,$num");
  49. $dsql->Execute();
  50. $ctp = new DedeTagParse();
  51. $ctp->SetNameSpace('field', '[', ']');
  52. $ctp->LoadSource($InnerText);
  53. while ($row = $dsql->GetArray()) {
  54. $row['keyword'] = $row['tag'];
  55. $row['tag'] = dede_htmlspecialchars($row['tag']);
  56. if (isset($envs['makeTag']) && $envs['makeTag'] == 1) {
  57. $row['link'] = $cfg_cmsurl . "/a/tags/" . GetPinyin($row['keyword']) . "/";
  58. } else {
  59. $row['link'] = $cfg_cmsurl . "/tags.php?/" . urlencode($row['keyword']) . "/";
  60. }
  61. $row['highlight'] = mt_rand(1, 10);
  62. foreach ($ctp->CTags as $tagid => $ctag) {
  63. if (isset($row[$ctag->GetName()])) {
  64. $ctp->Assign($tagid, $row[$ctag->GetName()]);
  65. }
  66. }
  67. $revalue .= $ctp->GetResult();
  68. }
  69. return $revalue;
  70. }