table_portal_comment.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_portal_comment.php 29122 2012-03-27 05:57:21Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_portal_comment extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'portal_comment';
  15. $this->_pk = 'cid';
  16. parent::__construct();
  17. }
  18. public function fetch_all_by_id_idtype($id, $idtype = '', $orderby = '', $ordersc = 'DESC', $start = 0, $limit = 0) {
  19. if(!$id) {
  20. return null;
  21. }
  22. $sql = array(DB::field('id', $id));
  23. if($idtype) {
  24. $sql[] = DB::field('idtype', $idtype);
  25. }
  26. $wheresql = implode(' AND ', $sql);
  27. if($orderby = DB::order($orderby, $ordersc)) {
  28. $wheresql .= ' ORDER BY '.$orderby;
  29. }
  30. if($limit) {
  31. $wheresql .= DB::limit($start, $limit);
  32. }
  33. return DB::fetch_all('SELECT * FROM %t WHERE %i', array($this->_table, $wheresql));
  34. }
  35. public function count_by_id_idtype($id, $idtype) {
  36. if(!$id || !$idtype) {
  37. return null;
  38. }
  39. $sql = DB::field('id', $id).' AND '.DB::field('idtype', $idtype);
  40. return DB::result_first('SELECT count(*) FROM %t WHERE %i', array($this->_table, $sql));
  41. }
  42. public function delete_by_id_idtype($id, $idtype) {
  43. if(!$id) {
  44. return null;
  45. }
  46. $para = DB::field('id', $id);
  47. if($idtype) {
  48. $para .= ' AND '.DB::field('idtype', $idtype);
  49. }
  50. return DB::delete($this->_table, $para);
  51. }
  52. public function count_all_by_search($aid, $authorid, $starttime, $endtime, $idtype, $message) {
  53. return $this->fetch_all_by_search($aid, $authorid, $starttime, $endtime, $idtype, $message, 0, 0, 2);
  54. }
  55. public function fetch_all_by_search($aid, $authorid, $starttime, $endtime, $idtype, $message, $start = 0, $limit = 0, $type = 1) {
  56. $idtype = in_array($idtype, array('aid', 'topicid')) ? $idtype : 'aid';
  57. $tablename = $idtype == 'aid' ? 'portal_article_title' : 'portal_topic';
  58. $sql = '';
  59. $sql .= $aid ? ' AND c.'.DB::field('id', $aid) : '';
  60. $sql .= $authorid ? ' AND c.'.DB::field('uid', $authorid) : '';
  61. $sql .= $starttime ? ' AND c.'.DB::field('dateline', $starttime, '>') : '';
  62. $sql .= $endtime ? ' AND c.'.DB::field('dateline', $endtime, '<') : '';
  63. if($message != '') {
  64. $sqlmessage = '';
  65. $or = '';
  66. $message = daddslashes($message);
  67. $message = explode(',', str_replace(' ', '', $message));
  68. for($i = 0; $i < count($message); $i++) {
  69. if(preg_match("/\{(\d+)\}/", $message[$i])) {
  70. $message[$i] = preg_replace("/\\\{(\d+)\\\}/", ".{0,\\1}", preg_quote($message[$i], '/'));
  71. $sqlmessage .= " $or c.message REGEXP '".$message[$i]."'";
  72. } else {
  73. $sqlmessage .= " $or c.message LIKE '%".$message[$i]."%'";
  74. }
  75. $or = 'OR';
  76. }
  77. if($sqlmessage) {
  78. $sql .= " AND ($sqlmessage)";
  79. }
  80. }
  81. if($type == 2) {
  82. return DB::result_first('SELECT count(*) FROM %t c WHERE 1 %i', array($this->_table, $sql));
  83. } else {
  84. return DB::fetch_all('SELECT c.*, a.title FROM %t c LEFT JOIN %t a ON a.`'.$idtype.'`=c.id WHERE 1 %i ORDER BY c.dateline DESC %i', array($this->_table, $tablename, $sql, DB::limit($start, $limit)));
  85. }
  86. }
  87. }
  88. ?>