table_home_doing.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: table_home_doing.php 30377 2012-05-24 09:52:22Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_home_doing extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'home_doing';
  15. $this->_pk = 'doid';
  16. parent::__construct();
  17. }
  18. public function update_replynum_by_doid($inc_replynum, $doid) {
  19. return DB::query('UPDATE %t SET replynum=replynum+\'%d\' WHERE doid=%d', array($this->_table, $inc_replynum, $doid));
  20. }
  21. public function delete_by_uid($uid) {
  22. if(!$uid) {
  23. return null;
  24. }
  25. return DB::delete($this->_table, DB::field('uid', $uid));
  26. }
  27. public function fetch_all_by_uid_doid($uids, $bannedids = '', $paramorderby = '', $startrow = 0, $items = 0, $status = true, $allfileds = false) {
  28. $parameter = array($this->_table);
  29. $orderby = $paramorderby && in_array($paramorderby, array('dateline', 'replynum')) ? 'ORDER BY '.DB::order($paramorderby, 'DESC') : 'ORDER BY '.DB::order('dateline', 'DESC');
  30. $wheres = array();
  31. if($uids) {
  32. $parameter[] = $uids;
  33. $wheres[] = 'uid IN (%n)';
  34. }
  35. if($bannedids) {
  36. $parameter[] = $bannedids;
  37. $wheres[] = 'doid NOT IN (%n)';
  38. }
  39. if($status) {
  40. $wheres[] = ' status = 0';
  41. }
  42. $wheresql = !empty($wheres) && is_array($wheres) ? ' WHERE '.implode(' AND ', $wheres) : '';
  43. if(empty($wheresql)) {
  44. return null;
  45. }
  46. return DB::fetch_all('SELECT '.($allfileds ? '*' : 'doid').' FROM %t '.$wheresql.' '.$orderby.DB::limit($startrow, $items), $parameter);
  47. }
  48. public function fetch_all_search($start, $limit, $fetchtype, $uids, $useip, $keywords, $lengthlimit, $starttime, $endtime, $basickeywords = 0, $doid = '', $findex = '') {
  49. $parameter = array($this->_table);
  50. $wherearr = array();
  51. if($doid) {
  52. $parameter[] = (array)$doid;
  53. $wherearr[] = 'doid IN(%n)';
  54. }
  55. if(is_array($uids) && count($uids)) {
  56. $parameter[] = $uids;
  57. $wherearr[] = 'uid IN(%n)';
  58. }
  59. if($useip) {
  60. $parameter[] = str_replace('*', '%', $useip);
  61. $wherearr[] = 'ip LIKE %s';
  62. }
  63. if($keywords) {
  64. if(!$basickeywords) {
  65. $sqlkeywords = '';
  66. $or = '';
  67. $keywords = explode(',', str_replace(' ', '', $keywords));
  68. for($i = 0; $i < count($keywords); $i++) {
  69. $keywords[$i] = addslashes(stripsearchkey($keywords[$i]));
  70. if(preg_match("/\{(\d+)\}/", $keywords[$i])) {
  71. $keywords[$i] = preg_replace("/\\\{(\d+)\\\}/", ".{0,\\1}", preg_quote($keywords[$i], '/'));
  72. $sqlkeywords .= " $or message REGEXP '".$keywords[$i]."'";
  73. } else {
  74. $sqlkeywords .= " $or message LIKE '%".$keywords[$i]."%'";
  75. }
  76. $or = 'OR';
  77. }
  78. $parameter[] = $sqlkeywords;
  79. $wherearr[] = '%i';
  80. } else {
  81. $parameter[] = '%'.$basickeywords.'%';
  82. $wherearr[] = 'message LIKE %s';
  83. }
  84. }
  85. if($lengthlimit) {
  86. $parameter[] = intval($lengthlimit);
  87. $wherearr[] = 'LENGTH(message) < %d';
  88. }
  89. if($starttime) {
  90. $parameter[] = is_numeric($starttime) ? $starttime : strtotime($starttime);
  91. $wherearr[] = 'dateline>%d';
  92. }
  93. if($endtime) {
  94. $parameter[] = is_numeric($endtime) ? $endtime : strtotime($endtime);
  95. $wherearr[] = 'dateline<%d';
  96. }
  97. if($fetchtype == 3) {
  98. $selectfield = "count(*)";
  99. } elseif ($fetchtype == 2) {
  100. $selectfield = "doid";
  101. } else {
  102. $selectfield = "*";
  103. $parameter[] = DB::limit($start, $limit);
  104. $ordersql = ' ORDER BY dateline DESC %i';
  105. }
  106. if($findex) {
  107. $findex = 'USE INDEX(dateline)';
  108. }
  109. $wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
  110. if($fetchtype == 3) {
  111. return DB::result_first("SELECT $selectfield FROM %t $wheresql", $parameter);
  112. } else {
  113. return DB::fetch_all("SELECT $selectfield FROM %t {$findex} $wheresql $ordersql", $parameter);
  114. }
  115. }
  116. }
  117. ?>