table_portal_topic.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_topic.php 32654 2013-02-28 03:55:27Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_portal_topic extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'portal_topic';
  15. $this->_pk = 'topicid';
  16. parent::__construct();
  17. }
  18. public function count_by_search_where($wherearr) {
  19. $wheresql = empty($wherearr) ? '' : implode(' AND ', $wherearr);
  20. return DB::result_first('SELECT COUNT(*) FROM '.DB::table($this->_table).($wheresql ? ' WHERE '.$wheresql : ''));
  21. }
  22. public function fetch_all_by_search_where($wherearr, $ordersql, $start, $limit) {
  23. $wheresql = empty($wherearr) ? '' : implode(' AND ', $wherearr);
  24. return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).($wheresql ? ' WHERE '.$wheresql : '').' '.$ordersql.DB::limit($start, $limit), null, 'topicid');
  25. }
  26. public function fetch_by_name($name) {
  27. return $name ? DB::fetch_first('SELECT * FROM %t WHERE name=%s LIMIT 1', array($this->_table, $name)) : false;
  28. }
  29. public function increase($ids, $data) {
  30. $ids = array_map('intval', (array)$ids);
  31. $sql = array();
  32. $allowkey = array('commentnum', 'viewnum');
  33. foreach($data as $key => $value) {
  34. if(($value = intval($value)) && in_array($key, $allowkey)) {
  35. $sql[] = "`$key`=`$key`+'$value'";
  36. }
  37. }
  38. if(!empty($sql)){
  39. DB::query('UPDATE '.DB::table($this->_table).' SET '.implode(',', $sql).' WHERE topicid IN ('.dimplode($ids).')', 'UNBUFFERED');
  40. }
  41. }
  42. public function fetch_all_by_title($idtype, $subject) {
  43. if(empty($idtype) || !is_string($idtype) || empty($subject)) {
  44. return array();
  45. }
  46. $parameter = array($this->_table);
  47. $or = $wheresql = '';
  48. $subject = explode(',', str_replace(' ', '', $subject));
  49. for($i = 0; $i < count($subject); $i++) {
  50. if(preg_match("/\{(\d+)\}/", $subject[$i])) {
  51. $subject[$i] = preg_replace("/\\\{(\d+)\\\}/", ".{0,\\1}", preg_quote($subject[$i], '/'));
  52. $wheresql .= " $or title REGEXP %s";
  53. $parameter[] = $subject[$i];
  54. } else {
  55. $wheresql .= " $or title LIKE %s";
  56. $parameter[] = '%'.$subject[$i].'%';
  57. }
  58. $or = 'OR';
  59. }
  60. return DB::fetch_all("SELECT $idtype FROM %t WHERE $wheresql", $parameter);
  61. }
  62. public function repair_htmlmade($ids) {
  63. if(($ids = dintval($ids, true))) {
  64. return DB::update($this->_table, array('htmlmade' => 0), DB::field($this->_pk, $ids));
  65. }
  66. return false;
  67. }
  68. public function fetch_all_topicid_by_dateline($dateline) {
  69. $data = array();
  70. $where = array();
  71. if($dateline) {
  72. $where[] = DB::field('dateline', intval($dateline), '>=');
  73. }
  74. $where[] = "closed='0'";
  75. if($where) {
  76. $data = DB::fetch_all('SELECT topicid FROM '.DB::table($this->_table).' WHERE '. implode(' AND ', $where).' LIMIT 20000', NULL, $this->_pk);
  77. }
  78. return $data;
  79. }
  80. }
  81. ?>