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

70 lines
2.7KB

  1. <?php
  2. if (!defined('DEDEINC')) exit ('dedebiz');
  3. /**
  4. * TAG标签
  5. *
  6. * @version $id:tag.lib.php 9:29 2010年7月6日 tianya $
  7. * @package DedeBIZ.Taglib
  8. * @copyright Copyright (c) 2022 DedeBIZ.COM
  9. * @license GNU GPL v2 (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, $cfg_tags_dir;
  15. $attlist = "row|30,sort|new,getall|0,typeid|0,ishtml|0";
  16. FillAttsDefault($ctag->CAttribute->Items, $attlist);
  17. extract($ctag->CAttribute->Items, EXTR_SKIP);
  18. $InnerText = $ctag->GetInnerText();
  19. if (trim($InnerText) == '') $InnerText = GetSysTemplets('tag_one.htm');
  20. $revalue = '';
  21. $ltype = $sort;
  22. $num = $row;
  23. $addsql = '';
  24. $tagsdir = str_replace("{cmspath}", "", $cfg_tags_dir);
  25. if ($getall == 0 && isset($refObj->Fields['tags']) && !empty($refObj->Fields['aid'])) {
  26. $dsql->SetQuery("SELECT tid FROM `#@__taglist` WHERE aid = '{$refObj->Fields['aid']}' ");
  27. $dsql->Execute();
  28. $ids = '';
  29. while ($row = $dsql->GetArray()) {
  30. $ids .= ($ids == '' ? $row['tid'] : ','.$row['tid']);
  31. }
  32. if ($ids != '') {
  33. $addsql .= " WHERE id IN($ids) ";
  34. }
  35. if ($addsql == '') return '';
  36. } else {
  37. if (!empty($typeid)) {
  38. $addsql .= " WHERE typeid='$typeid' ";
  39. }
  40. }
  41. if ($ltype == 'rand') $orderby = ' rand() ';
  42. else if ($ltype == 'week') $orderby = ' weekcc DESC ';
  43. else if ($ltype == 'month') $orderby = ' monthcc DESC ';
  44. else if ($ltype == 'hot') $orderby = ' count DESC ';
  45. else if ($ltype == 'total') $orderby = ' total DESC ';
  46. else $orderby = ' addtime DESC ';
  47. $dsql->SetQuery("SELECT * FROM `#@__tagindex` $addsql ORDER BY $orderby LIMIT 0,$num");
  48. $dsql->Execute();
  49. $ctp = new DedeTagParse();
  50. $ctp->SetNameSpace('field', '[', ']');
  51. $ctp->LoadSource($InnerText);
  52. while ($row = $dsql->GetArray()) {
  53. $row['keyword'] = $row['tag'];
  54. $row['tag'] = dede_htmlspecialchars($row['tag']);
  55. if (isset($envs['makeTag']) && $envs['makeTag'] == 1 || $ishtml == 1) {
  56. $row['link'] = $cfg_cmsurl.$tagsdir."/".$row['id']."/";
  57. } else {
  58. $row['link'] = $cfg_cmsurl."/apps/tags.php?/".$row['id']."/";
  59. }
  60. $row['highlight'] = mt_rand(1, 10);
  61. foreach ($ctp->CTags as $tagid => $ctag) {
  62. if (isset($row[$ctag->GetName()])) {
  63. $ctp->Assign($tagid, $row[$ctag->GetName()]);
  64. }
  65. }
  66. $revalue .= $ctp->GetResult();
  67. }
  68. return $revalue;
  69. }
  70. ?>