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

145 lines
5.6KB

  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 * FROM `#@__tagindex` $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. }
  34. //function update()
  35. else if ($action == 'update') {
  36. $tid = (empty($tid) ? 0 : intval($tid));
  37. $count = (empty($count) ? 0 : intval($count));
  38. if (empty($tid)) {
  39. ShowMsg('请选择需要删除的标签', '-1');
  40. exit();
  41. }
  42. $query = "UPDATE `#@__tagindex` SET `count`='$count' WHERE id='$tid' ";
  43. $dsql->ExecuteNoneQuery($query);
  44. ShowMsg("成功保存标签点击信息", 'tags_main.php');
  45. exit();
  46. }
  47. //function delete()
  48. else if ($action == 'delete') {
  49. if (@is_array($ids)) {
  50. $stringids = implode(',', $ids);
  51. } else if (!empty($ids)) {
  52. $stringids = $ids;
  53. } else {
  54. ShowMsg('请选择需要删除的标签', '-1');
  55. exit();
  56. }
  57. $query = "DELETE FROM `#@__tagindex` WHERE id IN ($stringids)";
  58. if ($dsql->ExecuteNoneQuery($query)) {
  59. $query = "DELETE FROM `#@__taglist` WHERE tid IN ($stringids)";
  60. $dsql->ExecuteNoneQuery($query);
  61. ShowMsg("删除[$stringids]标签成功", 'tags_main.php');
  62. } else {
  63. ShowMsg("删除[$stringids]标签失败", 'tags_main.php');
  64. }
  65. exit();
  66. } else if ($action == 'get_one') {
  67. $tid = (empty($tid) ? 0 : intval($tid));
  68. $row = $dsql->GetOne("SELECT * FROM `#@__tagindex` WHERE id = $tid");
  69. echo json_encode($row);
  70. exit;
  71. } else if ($action == 'set_one') {
  72. $tid = (empty($tid) ? 0 : intval($tid));
  73. $title = empty($title) ? "" : HtmlReplace($title, 0);
  74. $kw = empty($kw) ? "" : HtmlReplace($kw, 0);
  75. $des = empty($des) ? "" : HtmlReplace($des, 0);
  76. $now = time();
  77. $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET title='{$title}',keywords='{$kw}',`description`='{$des}',`uptime`='{$now}' WHERE id = {$tid}");
  78. echo json_encode(array('code' => 200, 'result' => true));
  79. }
  80. //function fetch()
  81. else if ($action == 'fetch') {
  82. $wheresql = '';
  83. $start = isset($start) && is_numeric($start) ? $start : 0;
  84. $where = array();
  85. if (isset($startaid) && is_numeric($startaid) && $startaid > 0) {
  86. $where[] = " id>=$startaid ";
  87. } else {
  88. $startaid = 0;
  89. }
  90. if (isset($endaid) && is_numeric($endaid) && $endaid > 0) {
  91. $where[] = " id<=$endaid ";
  92. } else {
  93. $endaid = 0;
  94. }
  95. if (!empty($where)) {
  96. $wheresql = " WHERE arcrank>-1 AND ".implode(' AND ', $where);
  97. }
  98. $query = "SELECT id as aid,arcrank,typeid,keywords FROM `#@__archives` $wheresql LIMIT $start, 100";
  99. $dsql->SetQuery($query);
  100. $dsql->Execute();
  101. $complete = true;
  102. $now = time();
  103. while ($row = $dsql->GetArray()) {
  104. $aid = $row['aid'];
  105. $typeid = $row['typeid'];
  106. $arcrank = $row['arcrank'];
  107. $row['keywords'] = trim($row['keywords']);
  108. if ($row['keywords'] != '' && !preg_match("#,#", $row['keywords'])) {
  109. $keyarr = explode(' ', $row['keywords']);
  110. } else {
  111. $keyarr = explode(',', $row['keywords']);
  112. }
  113. foreach ($keyarr as $keyword) {
  114. $keyword = trim($keyword);
  115. if ($keyword != '' && strlen($keyword) < 24) {
  116. $keyword = addslashes($keyword);
  117. $row = $dsql->GetOne("SELECT id,total FROM `#@__tagindex` WHERE tag LIKE '$keyword'");
  118. if (is_array($row)) {
  119. $tid = $row['id'];
  120. $trow = $dsql->GetOne("SELECT COUNT(*) as dd FROM `#@__taglist` WHERE tag LIKE '$keyword'");
  121. if (intval($trow['dd']) != $row['total']) {
  122. $query = "UPDATE `#@__tagindex` SET `total`=".$trow['dd'].",uptime=$now WHERE id='$tid' ";
  123. $dsql->ExecuteNoneQuery($query);
  124. }
  125. } else {
  126. $query = "INSERT INTO `#@__tagindex` (`tag`,`count`,`total`,`weekcc`,`monthcc`,`weekup`,`monthup`,`addtime`,`uptime`) VALUES ('$keyword','0','1','0','0','$timestamp','$timestamp','$timestamp','$now');";
  127. $dsql->ExecuteNoneQuery($query);
  128. $tid = $dsql->GetLastID();
  129. }
  130. $query = "REPLACE INTO `#@__taglist` (`tid`,`aid`,`typeid`,`arcrank`,`tag`) VALUES ('$tid', '$aid', '$typeid','$arcrank','$keyword'); ";
  131. $dsql->ExecuteNoneQuery($query);
  132. }
  133. }
  134. $complete = FALSE;
  135. }
  136. if ($complete) {
  137. ShowMsg('完成标签获取', 'tags_main.php');
  138. exit();
  139. }
  140. $start = $start + 100;
  141. $goto = "tags_main.php?action=fetch&startaid=$startaid&endaid=$endaid&start=$start";
  142. ShowMsg('正在获取标签', $goto);
  143. exit();
  144. }
  145. ?>