extend_thread_rushreply.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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: extend_thread_rushreply.php 34216 2013-11-14 02:32:06Z hypowang $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class extend_thread_rushreply extends extend_thread_base {
  12. public function before_newthread($parameters) {
  13. if($this->group['allowpostrushreply']) {
  14. $_GET['rushreplyfrom'] = strtotime($_GET['rushreplyfrom']);
  15. $_GET['rushreplyto'] = strtotime($_GET['rushreplyto']);
  16. $_GET['rewardfloor'] = preg_replace('#[^0-9|*|,]#', '', $_GET['rewardfloor']);
  17. $_GET['stopfloor'] = intval($_GET['stopfloor']);
  18. $_GET['replylimit'] = intval($_GET['replylimit']);
  19. $_GET['creditlimit'] = $_GET['creditlimit'] == '' ? '-996' : intval($_GET['creditlimit']);
  20. if($_GET['rushreplyfrom'] > $_GET['rushreplyto'] && !empty($_GET['rushreplyto'])) {
  21. showmessage('post_rushreply_timewrong');
  22. }
  23. if(($_GET['rushreplyfrom'] > TIMESTAMP) || (!empty($_GET['rushreplyto']) && $_GET['rushreplyto'] < TIMESTAMP) || ($_GET['stopfloor'] == 1) ) {
  24. $this->param['closed'] = true;
  25. }
  26. if(!empty($_GET['rewardfloor']) && !empty($_GET['stopfloor'])) {
  27. $floors = explode(',', $_GET['rewardfloor']);
  28. if(!empty($floors) && is_array($floors)) {
  29. foreach($floors AS $key => $floor) {
  30. if(strpos($floor, '*') === false) {
  31. if(intval($floor) == 0) {
  32. unset($floors[$key]);
  33. } elseif($floor > $_GET['stopfloor']) {
  34. unset($floors[$key]);
  35. }
  36. }
  37. }
  38. $_GET['rewardfloor'] = implode(',', $floors);
  39. }
  40. }
  41. $parameters['tstatus'] = setstatus(3, 1, $parameters['tstatus']);
  42. $parameters['tstatus'] = setstatus(1, 1, $parameters['tstatus']);
  43. $this->param['tstatus'] = $parameters['tstatus'];
  44. }
  45. }
  46. public function after_newthread() {
  47. if($this->group['allowpostrushreply']) {
  48. $rushdata = array('tid' => $this->tid, 'stopfloor' => $_GET['stopfloor'], 'starttimefrom' => $_GET['rushreplyfrom'], 'starttimeto' => $_GET['rushreplyto'], 'rewardfloor' => $_GET['rewardfloor'], 'creditlimit' => $_GET['creditlimit'], 'replylimit' => $_GET['replylimit']);
  49. C::t('forum_threadrush')->insert($rushdata);
  50. }
  51. }
  52. public function before_newreply() {
  53. global $_G, $rushinfo;
  54. if(getstatus($this->thread['status'], 3) && $rushinfo['replylimit'] > 0) {
  55. $replycount = C::t('forum_post')->count_by_tid_invisible_authorid($this->thread['tid'], $_G['uid']);
  56. if($replycount >= $rushinfo['replylimit']) {
  57. showmessage('noreply_replynum_error');
  58. }
  59. }
  60. }
  61. public function after_newreply() {
  62. global $rushinfo;
  63. if(getstatus($this->thread['status'], 3) && $this->param['maxposition']) {
  64. $rushstopfloor = $rushinfo['stopfloor'];
  65. if($rushstopfloor > 0 && $this->thread['closed'] == 0 && $this->param['maxposition'] >= $rushstopfloor) {
  66. $this->param['updatethreaddata'] = array_merge((array)$this->param['updatethreaddata'], array('closed' => 1));
  67. }
  68. }
  69. }
  70. public function before_editpost($parameters) {
  71. global $_G, $rushreply;
  72. $isfirstpost = $this->post['first'] ? 1 : 0;
  73. if($isfirstpost) {
  74. if($rushreply) {
  75. $_GET['rushreplyfrom'] = strtotime($_GET['rushreplyfrom']);
  76. $_GET['rushreplyto'] = strtotime($_GET['rushreplyto']);
  77. $_GET['rewardfloor'] = preg_replace('#[^0-9|*|,]#', '', $_GET['rewardfloor']);
  78. $_GET['stopfloor'] = intval($_GET['stopfloor']);
  79. $_GET['replylimit'] = intval($_GET['replylimit']);
  80. $_GET['creditlimit'] = $_GET['creditlimit'] == '' ? '-996' : intval($_GET['creditlimit']);
  81. if($_GET['rushreplyfrom'] > $_GET['rushreplyto'] && !empty($_GET['rushreplyto'])) {
  82. showmessage('post_rushreply_timewrong');
  83. }
  84. $maxposition = C::t('forum_post')->fetch_maxposition_by_tid($this->thread['posttableid'], $this->thread['tid']);
  85. if($this->thread['closed'] == 1 && ((!$_GET['rushreplyfrom'] && !$_GET['rushreplyto']) || ($_GET['rushreplyfrom'] < $_G['timestamp'] && $_GET['rushreplyto'] > $_G['timestamp']) || (!$_GET['rushreplyfrom'] && $_GET['rushreplyto'] > $_G['timestamp']) || ($_GET['stopfloor'] && $_GET['stopfloor'] > $maxposition) )) {
  86. $this->param['threadupdatearr']['closed'] = 0;
  87. } elseif($this->thread['closed'] == 0 && (($_GET['rushreplyfrom'] && $_GET['rushreplyfrom'] > $_G['timestamp']) || ($_GET['rushreplyto'] && $_GET['rushreplyto'] && $_GET['rushreplyto'] < $_G['timestamp']) || ($_GET['stopfloor'] && $_GET['stopfloor'] <= $maxposition) )) {
  88. $this->param['threadupdatearr']['closed'] = 1;
  89. }
  90. if(!empty($_GET['rewardfloor']) && !empty($_GET['stopfloor'])) {
  91. $floors = explode(',', $_GET['rewardfloor']);
  92. if(!empty($floors)) {
  93. foreach($floors AS $key => $floor) {
  94. if(strpos($floor, '*') === false) {
  95. if(intval($floor) == 0) {
  96. unset($floors[$key]);
  97. } elseif($floor > $_GET['stopfloor']) {
  98. unset($floors[$key]);
  99. }
  100. }
  101. }
  102. }
  103. $_GET['rewardfloor'] = implode(',', $floors);
  104. }
  105. $rushdata = array('stopfloor' => $_GET['stopfloor'], 'starttimefrom' => $_GET['rushreplyfrom'], 'starttimeto' => $_GET['rushreplyto'], 'rewardfloor' => $_GET['rewardfloor'], 'creditlimit' => $_GET['creditlimit'], 'replylimit' => $_GET['replylimit']);
  106. C::t('forum_threadrush')->update($this->thread['tid'], $rushdata);
  107. }
  108. }
  109. }
  110. public function before_deletepost() {
  111. global $rushreply;
  112. if($rushreply) {
  113. showmessage('post_edit_delete_rushreply_nopermission', NULL);
  114. }
  115. }
  116. }
  117. ?>