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

152 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 = 20;
  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. $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET title='{$title}',keywords='{$kw}',`description`='{$des}' WHERE id = {$tid}");
  81. echo json_encode(array('code' => 200, 'result' => true));
  82. }
  83. /*
  84. function fetch()
  85. */
  86. else if ($action == 'fetch') {
  87. $wheresql = '';
  88. $start = isset($start) && is_numeric($start) ? $start : 0;
  89. $where = array();
  90. if (isset($startaid) && is_numeric($startaid) && $startaid > 0) {
  91. $where[] = " id>=$startaid ";
  92. } else {
  93. $startaid = 0;
  94. }
  95. if (isset($endaid) && is_numeric($endaid) && $endaid > 0) {
  96. $where[] = " id<=$endaid ";
  97. } else {
  98. $endaid = 0;
  99. }
  100. if (!empty($where)) {
  101. $wheresql = " WHERE arcrank>-1 AND ".implode(' AND ', $where);
  102. }
  103. $query = "SELECT id as aid,arcrank,typeid,keywords FROM `#@__archives` $wheresql LIMIT $start, 100";
  104. $dsql->SetQuery($query);
  105. $dsql->Execute();
  106. $complete = true;
  107. $now = time();
  108. while ($row = $dsql->GetArray()) {
  109. $aid = $row['aid'];
  110. $typeid = $row['typeid'];
  111. $arcrank = $row['arcrank'];
  112. $row['keywords'] = trim($row['keywords']);
  113. if ($row['keywords'] != '' && !preg_match("#,#", $row['keywords'])) {
  114. $keyarr = explode(' ', $row['keywords']);
  115. } else {
  116. $keyarr = explode(',', $row['keywords']);
  117. }
  118. foreach ($keyarr as $keyword) {
  119. $keyword = trim($keyword);
  120. if ($keyword != '' && strlen($keyword) < 13) {
  121. $keyword = addslashes($keyword);
  122. $row = $dsql->GetOne("SELECT id,total FROM `#@__tagindex` WHERE tag LIKE '$keyword'");
  123. if (is_array($row)) {
  124. $tid = $row['id'];
  125. $trow = $dsql->GetOne("SELECT COUNT(*) as dd FROM `#@__taglist` WHERE tag LIKE '$keyword'");
  126. if (intval($trow['dd']) != $row['total']) {
  127. $query = "UPDATE `#@__tagindex` SET `total`=".$trow['dd'].",uptime=$now WHERE id='$tid' ";
  128. $dsql->ExecuteNoneQuery($query);
  129. }
  130. } else {
  131. $query = " INSERT INTO `#@__tagindex`(`tag`,`count`,`total`,`weekcc`,`monthcc`,`weekup`,`monthup`,`addtime`,`uptime`) VALUES('$keyword','0','1','0','0','$timestamp','$timestamp','$timestamp','$now');";
  132. $dsql->ExecuteNoneQuery($query);
  133. $tid = $dsql->GetLastID();
  134. }
  135. $query = "REPLACE INTO `#@__taglist`(`tid`,`aid`,`typeid`,`arcrank`,`tag`) VALUES ('$tid', '$aid', '$typeid','$arcrank','$keyword'); ";
  136. $dsql->ExecuteNoneQuery($query);
  137. }
  138. }
  139. $complete = FALSE;
  140. }
  141. if ($complete) {
  142. ShowMsg("tags获取完成", 'tags_main.php');
  143. exit();
  144. }
  145. $start = $start + 100;
  146. $goto = "tags_main.php?action=fetch&startaid=$startaid&endaid=$endaid&start=$start";
  147. ShowMsg('继续获取tags ', $goto, 0, 500);
  148. exit();
  149. }