table_portal_article_title.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_article_title.php 31618 2012-09-14 09:32:26Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_portal_article_title extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'portal_article_title';
  15. $this->_pk = 'aid';
  16. parent::__construct();
  17. }
  18. public function update_click($cid, $clickid, $incclick) {
  19. $clickid = intval($clickid);
  20. if($clickid < 1 || $clickid > 8 || empty($cid) || empty($incclick)) {
  21. return false;
  22. }
  23. return DB::query('UPDATE %t SET click'.$clickid.' = click'.$clickid.'+\'%d\' WHERE aid = %d', array($this->_table, $incclick, $cid));
  24. }
  25. public function fetch_count_for_cat($catid) {
  26. if(empty($catid)) {
  27. return 0;
  28. }
  29. return DB::result_first('SELECT COUNT(*) FROM %t WHERE catid=%d', array($this->_table, $catid));
  30. }
  31. public function fetch_count_for_idtype($id, $idtype) {
  32. return DB::result_first("SELECT COUNT(*) FROM %t WHERE id=%d AND idtype=%s", array($this->_table, $id, $idtype));
  33. }
  34. public function fetch_all_for_cat($catid, $status = null, $orderaid = 0, $start = 0, $limit = 0) {
  35. if(empty($catid)) {
  36. return array();
  37. }
  38. $statussql = $status !== null ? ' AND '.DB::field('status', $status) : '';
  39. $orderaidsql = $orderaid ? ' ORDER BY aid DESC' : '';
  40. return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('catid', $catid).$statussql.$orderaidsql.DB::limit($start, $limit), array($this->_table));
  41. }
  42. public function update_for_cat($catid, $data) {
  43. if(empty($catid) || empty($data)) {
  44. return false;
  45. }
  46. return DB::update($this->_table, $data, DB::field('catid', $catid));
  47. }
  48. public function range($start = 0, $limit = 0) {
  49. return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' ORDER BY dateline DESC'.DB::limit($start, $limit));
  50. }
  51. public function fetch_all_by_sql($where, $order = '', $start = 0, $limit = 0, $count = 0, $alias = '') {
  52. $where = $where && !is_array($where) ? " WHERE $where" : '';
  53. if(is_array($order)) {
  54. $order = '';
  55. }
  56. if($count) {
  57. return DB::result_first('SELECT count(*) FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order));
  58. }
  59. return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order));
  60. }
  61. public function fetch_all_by_title($idtype, $subject) {
  62. $parameter = array($this->_table);
  63. $or = $wheresql = '';
  64. $subject = explode(',', str_replace(' ', '', $subject));
  65. if(empty($subject)) {
  66. return array();
  67. }
  68. for($i = 0; $i < count($subject); $i++) {
  69. if(preg_match("/\{(\d+)\}/", $subject[$i])) {
  70. $subject[$i] = preg_replace("/\\\{(\d+)\\\}/", ".{0,\\1}", preg_quote($subject[$i], '/'));
  71. $wheresql .= " $or title REGEXP %s";
  72. $parameter[] = $subject[$i];
  73. } else {
  74. $wheresql .= " $or title LIKE %s";
  75. $parameter[] = '%'.$subject[$i].'%';
  76. }
  77. $or = 'OR';
  78. }
  79. return DB::fetch_all("SELECT $idtype FROM %t WHERE $wheresql", $parameter);
  80. }
  81. public function fetch_all_for_search($aids, $orderby = '', $ascdesc = '', $start = 0, $limit = 0) {
  82. return DB::fetch_all("SELECT at.*,ac.viewnum, ac.commentnum FROM ".DB::table($this->_table)." at LEFT JOIN ".DB::table('portal_article_count')." ac ON at.aid=ac.aid WHERE at.".DB::field('aid', $aids).($orderby ? " ORDER BY ".DB::order($orderby, $ascdesc) : ' ').DB::limit($start, $limit));
  83. }
  84. public function repair_htmlmade($ids) {
  85. if(($ids = dintval($ids, true))) {
  86. return DB::update($this->_table, array('htmlmade' => 0), DB::field($this->_pk, $ids));
  87. }
  88. return false;
  89. }
  90. public function fetch_all_aid_by_dateline($dateline, $catids = array(), $startid = 0, $endid = 0) {
  91. $data = array();
  92. $where = array();
  93. if($startid) {
  94. $where[] = DB::field('aid', intval($startid), '>=');
  95. }
  96. if($endid) {
  97. $where[] = DB::field('aid', intval($endid), '<=');
  98. }
  99. if($catids) {
  100. $where[] = DB::field('catid', dintval($catids, true));
  101. }
  102. if($dateline) {
  103. $where[] = DB::field('dateline', intval($dateline), '>=');
  104. }
  105. if($where) {
  106. $data = DB::fetch_all('SELECT aid FROM '.DB::table($this->_table).' WHERE '. implode(' AND ', $where).' LIMIT 200000', NULL, $this->_pk);
  107. }
  108. return $data;
  109. }
  110. public function fetch_preaid_by_catid_aid($catid, $aid) {
  111. $ret = 0;
  112. if(($catid = intval($catid)) && ($aid = intval($aid))) {
  113. $ret = DB::result_first('SELECT aid FROM %t WHERE catid=%d AND aid<%d ORDER BY aid DESC LIMIT 1', array($this->_table, $catid, $aid));
  114. }
  115. return $ret;
  116. }
  117. public function fetch_nextaid_by_catid_aid($catid, $aid) {
  118. $ret = 0;
  119. if(($catid = intval($catid)) && ($aid = intval($aid))) {
  120. $ret = DB::result_first('SELECT aid FROM %t WHERE catid=%d AND aid>%d ORDER BY aid ASC LIMIT 1', array($this->_table, $catid, $aid));
  121. }
  122. return $ret;
  123. }
  124. }
  125. ?>