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

170 lines
5.3KB

  1. <?php
  2. /**
  3. * 获取TAGS管理
  4. *
  5. * @version $Id: tag_test_action.php 1 23:07 2010年7月20日Z tianya $
  6. * @package DedeCMS.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. {
  18. $orderby = empty($orderby) ? 'id' : preg_replace("#[^a-z]#i", '', $orderby);
  19. $orderway = isset($orderway) && $orderway == 'asc' ? 'asc' : 'desc';
  20. if(!empty($tag)) $where = " where tag like '%$tag%'";
  21. else $where = '';
  22. $neworderway = ($orderway == 'desc' ? 'asc' : 'desc');
  23. $query = "SELECT * FROM `#@__tagindex` $where ORDER BY $orderby $orderway";
  24. $dlist = new DataListCP();
  25. $tag = stripslashes($tag);
  26. $dlist->SetParameter("tag", $tag);
  27. $dlist->SetParameter("orderway", $orderway);
  28. $dlist->SetParameter("orderby", $orderby);
  29. $dlist->pageSize = 20;
  30. $dlist->SetTemplet(DEDEADMIN."/templets/tags_main.htm");
  31. $dlist->SetSource($query);
  32. $dlist->Display();
  33. exit();
  34. }
  35. /*
  36. function update()
  37. */
  38. else if($action == 'update')
  39. {
  40. $tid = (empty($tid) ? 0 : intval($tid) );
  41. $count = (empty($count) ? 0 : intval($count) );
  42. if(empty($tid))
  43. {
  44. ShowMsg('没有选择要删除的tag!','-1');
  45. exit();
  46. }
  47. $query = "UPDATE `#@__tagindex` SET `count`='$count' WHERE id='$tid' ";
  48. $dsql->ExecuteNoneQuery($query);
  49. ShowMsg("成功保存标签的点击信息!", 'tags_main.php');
  50. exit();
  51. }
  52. /*
  53. function delete()
  54. */
  55. else if($action == 'delete')
  56. {
  57. if(@is_array($ids))
  58. {
  59. $stringids = implode(',', $ids);
  60. }
  61. else if(!empty($ids))
  62. {
  63. $stringids = $ids;
  64. }
  65. else
  66. {
  67. ShowMsg('没有选择要删除的tag','-1');
  68. exit();
  69. }
  70. $query = "DELETE FROM `#@__tagindex` WHERE id IN ($stringids)";
  71. if($dsql->ExecuteNoneQuery($query))
  72. {
  73. $query = "DELETE FROM `#@__taglist` WHERE tid IN ($stringids)";
  74. $dsql->ExecuteNoneQuery($query);
  75. ShowMsg("删除tags[ $stringids ]成功", 'tags_main.php');
  76. }
  77. else
  78. {
  79. ShowMsg("删除tags[ $stringids ]失败", 'tags_main.php');
  80. }
  81. exit();
  82. }
  83. /*
  84. function fetch()
  85. */
  86. else if($action == 'fetch')
  87. {
  88. $wheresql = '';
  89. $start = isset($start) && is_numeric($start) ? $start : 0;
  90. $where = array();
  91. if(isset($startaid) && is_numeric($startaid) && $startaid > 0)
  92. {
  93. $where[] = " id>=$startaid ";
  94. }
  95. else
  96. {
  97. $startaid = 0;
  98. }
  99. if(isset($endaid) && is_numeric($endaid) && $endaid > 0)
  100. {
  101. $where[] = " id<=$endaid ";
  102. }
  103. else
  104. {
  105. $endaid = 0;
  106. }
  107. if(!empty($where))
  108. {
  109. $wheresql = " WHERE arcrank>-1 AND ".implode(' AND ', $where);
  110. }
  111. $query = "SELECT id as aid,arcrank,typeid,keywords FROM `#@__archives` $wheresql LIMIT $start, 100";
  112. $dsql->SetQuery($query);
  113. $dsql->Execute();
  114. $complete = true;
  115. $now = time();
  116. while($row = $dsql->GetArray())
  117. {
  118. $aid = $row['aid'];
  119. $typeid = $row['typeid'];
  120. $arcrank = $row['arcrank'];
  121. $row['keywords'] = trim($row['keywords']);
  122. if($row['keywords']!='' && !preg_match("#,#", $row['keywords']))
  123. {
  124. $keyarr = explode(' ', $row['keywords']);
  125. }
  126. else
  127. {
  128. $keyarr = explode(',', $row['keywords']);
  129. }
  130. foreach($keyarr as $keyword)
  131. {
  132. $keyword = trim($keyword);
  133. if($keyword != '' && strlen($keyword)<13 )
  134. {
  135. $keyword = addslashes($keyword);
  136. $row = $dsql->GetOne("SELECT id,total FROM `#@__tagindex` WHERE tag LIKE '$keyword'");
  137. if(is_array($row))
  138. {
  139. $tid = $row['id'];
  140. $trow = $dsql->GetOne("SELECT COUNT(*) as dd FROM `#@__taglist` WHERE tag LIKE '$keyword'");
  141. if (intval($trow['dd']) != $row['total'] ) {
  142. $query = "UPDATE `#@__tagindex` SET `total`=".$trow['dd'].",uptime=$now WHERE id='$tid' ";
  143. $dsql->ExecuteNoneQuery($query);
  144. }
  145. }
  146. else
  147. {
  148. $query = " INSERT INTO `#@__tagindex`(`tag`,`count`,`total`,`weekcc`,`monthcc`,`weekup`,`monthup`,`addtime`,`uptime`) VALUES('$keyword','0','1','0','0','$timestamp','$timestamp','$timestamp','$now');";
  149. $dsql->ExecuteNoneQuery($query);
  150. $tid = $dsql->GetLastID();
  151. }
  152. $query = "REPLACE INTO `#@__taglist`(`tid`,`aid`,`typeid`,`arcrank`,`tag`) VALUES ('$tid', '$aid', '$typeid','$arcrank','$keyword'); ";
  153. $dsql->ExecuteNoneQuery($query);
  154. }
  155. }
  156. $complete = FALSE;
  157. }
  158. if($complete)
  159. {
  160. ShowMsg("tags获取完成", 'tags_main.php');
  161. exit();
  162. }
  163. $start = $start + 100;
  164. $goto = "tags_main.php?action=fetch&startaid=$startaid&endaid=$endaid&start=$start";
  165. ShowMsg('继续获取tags ...', $goto, 0, 500);
  166. exit();
  167. }