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

151 lines
5.6KB

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