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

136 lines
5.7KB

  1. <?php
  2. /**
  3. * 标签管理
  4. *
  5. * @version $id:tag_test_action.php 23:07 2010年7月20日 tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2022 DedeBIZ.COM
  8. * @license GNU GPL v2 (https://www.dedebiz.com/license)
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__).'/config.php');
  12. CheckPurview('sys_Keyword');
  13. require_once(DEDEINC.'/datalistcp.class.php');
  14. $timestamp = time();
  15. if (empty($tag)) $tag = '';
  16. if (empty($action)) {
  17. $orderby = empty($orderby) ? 'id' : preg_replace("#[^a-z]#i", '', $orderby);
  18. $orderway = isset($orderway) && $orderway == 'asc' ? 'asc' : 'desc';
  19. if (!empty($tag)) $where = " WHERE tag like '%$tag%'";
  20. else $where = '';
  21. $neworderway = ($orderway == 'desc' ? 'asc' : 'desc');
  22. $query = "SELECT T.*,TI.* FROM `#@__tagindex` T LEFT JOIN `#@__tagindex_infos` TI ON TI.tagid=T.id $where ORDER BY $orderby $orderway";
  23. $dlist = new DataListCP();
  24. $tag = stripslashes($tag);
  25. $dlist->SetParameter("tag", $tag);
  26. $dlist->SetParameter("orderway", $orderway);
  27. $dlist->SetParameter("orderby", $orderby);
  28. $dlist->pagesize = 30;
  29. $dlist->SetTemplet(DEDEADMIN."/templets/tags_main.htm");
  30. $dlist->SetSource($query);
  31. $dlist->Display();
  32. exit();
  33. } else if ($action == 'update') {
  34. $tid = (empty($tid) ? 0 : intval($tid));
  35. $count = (empty($count) ? 0 : intval($count));
  36. $litpic = (empty($litpic) ? '' : HtmlReplace($litpic, -1));
  37. $title = (empty($title) ? '' : HtmlReplace($title, -1));
  38. $keywords = (empty($keywords) ? '' : HtmlReplace($keywords, -1));
  39. $description = (empty($description) ? '' : HtmlReplace($description, -1));
  40. if (empty($tid)) {
  41. die('请选择需要更新的标签');
  42. }
  43. $query = "UPDATE `#@__tagindex` SET `count`='$count',`title`='$title',`keywords`='$keywords',`description`='$description' WHERE id='$tid' ";
  44. $dsql->ExecuteNoneQuery($query);
  45. $row = $dsql->GetOne("SELECT COUNT(*) AS dd FROM `#@__tagindex_infos` WHERE tagid = $tid");
  46. if ($row['dd'] > 0) {
  47. $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex_infos` SET `litpic`=='$litpic'");
  48. } else {
  49. $dsql->ExecuteNoneQuery("INSERT INTO `#@__tagindex_infos` (`tagid`,`litpic`) VALUES ('$tid','$litpic')");
  50. }
  51. echo "success";
  52. exit();
  53. } else if ($action == 'delete') {
  54. if (@is_array($ids)) {
  55. $stringids = implode(',', $ids);
  56. } else if (!empty($ids)) {
  57. $stringids = $ids;
  58. } else {
  59. ShowMsg('请选择需要删除的标签', '-1');
  60. exit();
  61. }
  62. $query = "DELETE FROM `#@__tagindex` WHERE id IN ($stringids)";
  63. if ($dsql->ExecuteNoneQuery($query)) {
  64. $query = "DELETE FROM `#@__taglist` WHERE tid IN ($stringids)";
  65. $dsql->ExecuteNoneQuery($query);
  66. $dsql->ExecuteNoneQuery("DELETE FROM `#@__tagindex_infos` WHERE tagid IN ($stringids)");
  67. ShowMsg("删除[$stringids]标签成功", 'tags_main.php');
  68. } else {
  69. ShowMsg("删除[$stringids]标签失败", 'tags_main.php');
  70. }
  71. exit();
  72. } else if ($action == 'fetch') {
  73. $wheresql = '';
  74. $start = isset($start) && is_numeric($start) ? $start : 0;
  75. $where = array();
  76. if (isset($startaid) && is_numeric($startaid) && $startaid > 0) {
  77. $where[] = " id>=$startaid ";
  78. } else {
  79. $startaid = 0;
  80. }
  81. if (isset($endaid) && is_numeric($endaid) && $endaid > 0) {
  82. $where[] = " id<=$endaid ";
  83. } else {
  84. $endaid = 0;
  85. }
  86. if (!empty($where)) {
  87. $wheresql = " WHERE arcrank>-1 AND ".implode(' AND ', $where);
  88. }
  89. $query = "SELECT id as aid,arcrank,typeid,keywords FROM `#@__archives` $wheresql LIMIT $start, 100";
  90. $dsql->SetQuery($query);
  91. $dsql->Execute();
  92. $complete = true;
  93. $now = time();
  94. while ($row = $dsql->GetArray()) {
  95. $aid = $row['aid'];
  96. $typeid = $row['typeid'];
  97. $arcrank = $row['arcrank'];
  98. $row['keywords'] = trim($row['keywords']);
  99. if ($row['keywords'] != '' && !preg_match("#,#", $row['keywords'])) {
  100. $keyarr = explode(' ', $row['keywords']);
  101. } else {
  102. $keyarr = explode(',', $row['keywords']);
  103. }
  104. foreach ($keyarr as $keyword) {
  105. $keyword = trim($keyword);
  106. if ($keyword != '' && strlen($keyword) < 24) {
  107. $keyword = addslashes($keyword);
  108. $row = $dsql->GetOne("SELECT id,total FROM `#@__tagindex` WHERE tag LIKE '$keyword'");
  109. if (is_array($row)) {
  110. $tid = $row['id'];
  111. $trow = $dsql->GetOne("SELECT COUNT(*) as dd FROM `#@__taglist` WHERE tag LIKE '$keyword'");
  112. if (intval($trow['dd']) != $row['total']) {
  113. $query = "UPDATE `#@__tagindex` SET `total`=".$trow['dd'].",uptime=$now WHERE id='$tid' ";
  114. $dsql->ExecuteNoneQuery($query);
  115. }
  116. } else {
  117. $query = "INSERT INTO `#@__tagindex` (`tag`,`count`,`total`,`weekcc`,`monthcc`,`weekup`,`monthup`,`addtime`,`uptime`) VALUES ('$keyword','0','1','0','0','$timestamp','$timestamp','$timestamp','$now');";
  118. $dsql->ExecuteNoneQuery($query);
  119. $tid = $dsql->GetLastID();
  120. }
  121. $query = "REPLACE INTO `#@__taglist` (`tid`,`aid`,`typeid`,`arcrank`,`tag`) VALUES ('$tid','$aid','$typeid','$arcrank','$keyword'); ";
  122. $dsql->ExecuteNoneQuery($query);
  123. }
  124. }
  125. $complete = FALSE;
  126. }
  127. if ($complete) {
  128. ShowMsg('完成标签获取', 'tags_main.php');
  129. exit();
  130. }
  131. $start = $start + 100;
  132. $goto = "tags_main.php?action=fetch&startaid=$startaid&endaid=$endaid&start=$start";
  133. ShowMsg('正在获取标签', $goto);
  134. exit();
  135. }
  136. ?>