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

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