dz_newthread.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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: dz_newthread.php 33590 2013-07-12 06:39:08Z andyzheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class dz_newthread extends extends_data {
  12. function __construct() {
  13. parent::__construct();
  14. }
  15. function common() {
  16. global $_G;
  17. loadcache('mobile_pnewthread');
  18. loadcache('forums');
  19. $maxnum = 50000;
  20. $maxtid = C::t('forum_thread')->fetch_max_tid();
  21. $limittid = max(0,($maxtid - $maxnum));
  22. $this->page = intval($_GET['page']) ? intval($_GET['page']) : 1;
  23. $start = ($this->page - 1)*$this->perpage;
  24. $num = $this->perpage;
  25. if($_G['cache']['mobile_pnewthread'] && (TIMESTAMP - $_G['cache']['mobile_pnewthread']['cachetime']) < 900) {
  26. $tids = array_slice($_G['cache']['mobile_pnewthread']['data'], $start ,$num);
  27. if(empty($tids)) {
  28. return;
  29. }
  30. } else {
  31. $tids = array();
  32. }
  33. $tsql = $addsql = '';
  34. $updatecache = false;
  35. $fids = array();
  36. if($_G['setting']['followforumid']) {
  37. $addsql .= ' AND '.DB::field('fid', $_G['setting']['followforumid'], '<>');
  38. }
  39. if($tids) {
  40. $tids = dintval($tids, true);
  41. $tidsql = DB::field('tid', $tids);
  42. } else {
  43. $tidsql = 'tid>'.intval($limittid);
  44. $addsql .= ' AND displayorder>=0 ORDER BY tid DESC LIMIT 600';
  45. $tids = array();
  46. foreach($_G['cache']['forums'] as $fid => $forum) {
  47. if($forum['type'] != 'group' && $forum['status'] > 0 && (!$forum['viewperm'] && $_G['group']['readaccess']) || ($forum['viewperm'] && forumperm($forum['viewperm']))) {
  48. $fids[] = $fid;
  49. }
  50. }
  51. if(empty($fids)) {
  52. return ;
  53. }
  54. $updatecache = true;
  55. }
  56. $list = $threadids = array();
  57. $n = 0;
  58. $query = DB::query("SELECT * FROM ".DB::table('forum_thread')." WHERE ".$tidsql.$addsql);
  59. while($thread = DB::fetch($query)) {
  60. if(empty($tids) && ($thread['isgroup'] || !in_array($thread['fid'], $fids))) {
  61. continue;
  62. }
  63. if($thread['displayorder'] < 0) {
  64. continue;
  65. }
  66. $threadids[] = $thread['tid'];
  67. if($tids || ($n >= $start && $n < ($start + $num))) {
  68. $list[$thread['tid']] = $thread;
  69. }
  70. $n ++;
  71. }
  72. $threadlist = array();
  73. if($tids) {
  74. foreach($tids as $key => $tid) {
  75. if($list[$tid]) {
  76. $threadlist[$key] = $list[$tid];
  77. }
  78. }
  79. } else {
  80. $threadlist = $list;
  81. }
  82. unset($list);
  83. if($updatecache) {
  84. $data = array('cachetime' => TIMESTAMP, 'data' => $threadids);
  85. $_G['cache']['mobile_pnewthread'] = $data;
  86. savecache('mobile_pnewthread', $_G['cache']['mobile_pnewthread']);
  87. }
  88. foreach($threadlist as $thread) {
  89. $this->field('author', '0', $thread['author']);
  90. $this->field('dateline', '0', $thread['dateline']);
  91. $this->field('replies', '1', $thread['replies']);
  92. $this->field('views', '2', $thread['views']);
  93. $this->id = $thread['tid'];
  94. $this->title = $thread['subject'];
  95. $this->image = '';
  96. $this->icon = '1';
  97. $this->poptype = '0';
  98. $this->popvalue = '';
  99. $this->clicktype = 'tid';
  100. $this->clickvalue = $thread['tid'];
  101. $this->insertrow();
  102. }
  103. }
  104. }
  105. ?>