extend_thread_debate.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_debate.php 30673 2012-06-11 07:51:54Z svn_project_zhangjie $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class extend_thread_debate extends extend_thread_base {
  12. public $affirmpoint;
  13. public $negapoint;
  14. public $endtime;
  15. public $stand;
  16. public function before_newthread($parameters) {
  17. if(empty($_GET['affirmpoint']) || empty($_GET['negapoint'])) {
  18. showmessage('debate_position_nofound');
  19. } elseif(!empty($_GET['endtime']) && (!($this->endtime = @strtotime($_GET['endtime'])) || $this->endtime < TIMESTAMP)) {
  20. showmessage('debate_endtime_invalid');
  21. } elseif(!empty($_GET['umpire'])) {
  22. if(!C::t('common_member')->fetch_uid_by_username($_GET['umpire'])) {
  23. $_GET['umpire'] = dhtmlspecialchars($_GET['umpire']);
  24. showmessage('debate_umpire_invalid', '', array('umpire' => $_GET['umpire']));
  25. }
  26. }
  27. $this->affirmpoint = censor(dhtmlspecialchars($_GET['affirmpoint']));
  28. $this->negapoint = censor(dhtmlspecialchars($_GET['negapoint']));
  29. $this->stand = intval($_GET['stand']);
  30. $this->param['extramessage'] = "\t".$_GET['affirmpoint']."\t".$_GET['negapoint'];
  31. }
  32. public function after_newthread() {
  33. if($this->group['allowpostdebate']) {
  34. C::t('forum_debate')->insert(array(
  35. 'tid' => $this->tid,
  36. 'uid' => $this->member['uid'],
  37. 'starttime' => $this->param['publishdate'],
  38. 'endtime' => $this->endtime,
  39. 'affirmdebaters' => 0,
  40. 'negadebaters' => 0,
  41. 'affirmvotes' => 0,
  42. 'negavotes' => 0,
  43. 'umpire' => $_GET['umpire'],
  44. 'winner' => '',
  45. 'bestdebater' => '',
  46. 'affirmpoint' => $this->affirmpoint,
  47. 'negapoint' => $this->negapoint,
  48. 'umpirepoint' => ''
  49. ));
  50. }
  51. }
  52. public function before_feed() {
  53. $message = !$this->param['price'] && !$this->param['readperm'] ? $this->param['message'] : '';
  54. $this->feed['icon'] = 'debate';
  55. $this->feed['title_template'] = 'feed_thread_debate_title';
  56. $this->feed['body_template'] = 'feed_thread_debate_message';
  57. $this->feed['body_data'] = array(
  58. 'subject' => "<a href=\"forum.php?mod=viewthread&tid={$this->tid}\">{$this->param['subject']}</a>",
  59. 'message' => messagecutstr($message, 150),
  60. 'affirmpoint'=> messagecutstr($this->affirmpoint, 150),
  61. 'negapoint'=> messagecutstr($this->negapoint, 150)
  62. );
  63. }
  64. public function after_newreply() {
  65. global $firststand, $stand;
  66. if($this->param['special'] == 5) {
  67. if(!$firststand) {
  68. C::t('forum_debate')->update_debaters($this->thread['tid'], $stand);
  69. } else {
  70. $stand = $firststand;
  71. }
  72. C::t('forum_debate')->update_replies($this->thread['tid'], $stand);
  73. C::t('forum_debatepost')->insert(array(
  74. 'tid' => $this->thread['tid'],
  75. 'pid' => $this->pid,
  76. 'uid' => $this->member['uid'],
  77. 'dateline' => getglobal('timestamp'),
  78. 'stand' => $stand,
  79. 'voters' => 0,
  80. 'voterids' => '',
  81. ));
  82. }
  83. }
  84. public function before_replyfeed() {
  85. global $stand;
  86. if($this->forum['allowfeed'] && !$this->param['isanonymous']) {
  87. if($this->param['special'] == 5 && $this->thread['authorid'] != $this->member['uid']) {
  88. $this->feed['icon'] = 'debate';
  89. if($stand == 1) {
  90. $this->feed['title_template'] = 'feed_thread_debatevote_title_1';
  91. } elseif($stand == 2) {
  92. $this->feed['title_template'] = 'feed_thread_debatevote_title_2';
  93. } else {
  94. $this->feed['title_template'] = 'feed_thread_debatevote_title_3';
  95. }
  96. $this->feed['title_data'] = array(
  97. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=".$this->thread['tid']."\">".$this->thread['subject']."</a>",
  98. 'author' => "<a href=\"home.php?mod=space&uid=".$this->thread['authorid']."\">".$this->thread['author']."</a>"
  99. );
  100. }
  101. }
  102. }
  103. public function before_editpost($parameters) {
  104. $isfirstpost = $this->post['first'] ? 1 : 0;
  105. if($isfirstpost) {
  106. if($this->thread['special'] == 5 && $this->group['allowpostdebate']) {
  107. if(empty($_GET['affirmpoint']) || empty($_GET['negapoint'])) {
  108. showmessage('debate_position_nofound');
  109. } elseif(!empty($_GET['endtime']) && (!($endtime = @strtotime($_GET['endtime'])) || $endtime < TIMESTAMP)) {
  110. showmessage('debate_endtime_invalid');
  111. } elseif(!empty($_GET['umpire'])) {
  112. if(!C::t('common_member')->fetch_uid_by_username($_GET['umpire'])) {
  113. $_GET['umpire'] = dhtmlspecialchars($_GET['umpire']);
  114. showmessage('debate_umpire_invalid');
  115. }
  116. }
  117. $affirmpoint = censor(dhtmlspecialchars($_GET['affirmpoint']));
  118. $negapoint = censor(dhtmlspecialchars($_GET['negapoint']));
  119. C::t('forum_debate')->update($this->thread['tid'], array('affirmpoint' => $affirmpoint, 'negapoint' => $negapoint, 'endtime' => $endtime, 'umpire' => $_GET['umpire']));
  120. }
  121. }
  122. }
  123. }
  124. ?>