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