extend_thread_poll.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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_poll.php 36284 2016-12-12 00:47:50Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class extend_thread_poll extends extend_thread_base {
  12. public $pollarray;
  13. public $polloptionpreview;
  14. public function before_newthread($parameters){
  15. $polloption = $_GET['tpolloption'] == 2 ? explode("\n", $_GET['polloptions']) : $_GET['polloption'];
  16. foreach($polloption as $key => $value) {
  17. $polloption[$key] = censor($polloption[$key]);
  18. if(trim($value) === '') {
  19. unset($polloption[$key]);
  20. }
  21. }
  22. $maxpolloptions = $this->setting['maxpolloptions'];
  23. if(count($polloption) > $maxpolloptions) {
  24. showmessage('post_poll_option_toomany', '', array('maxpolloptions' => $maxpolloptions));
  25. } elseif(count($polloption) < 2) {
  26. showmessage('post_poll_inputmore');
  27. }
  28. $curpolloption = count($polloption);
  29. $this->pollarray['maxchoices'] = empty($_GET['maxchoices']) ? 0 : ($_GET['maxchoices'] > $curpolloption ? $curpolloption : $_GET['maxchoices']);
  30. $this->pollarray['multiple'] = empty($_GET['maxchoices']) || $_GET['maxchoices'] == 1 ? 0 : 1;
  31. $this->pollarray['options'] = $polloption;
  32. $this->pollarray['visible'] = empty($_GET['visibilitypoll']);
  33. $this->pollarray['overt'] = !empty($_GET['overt']);
  34. $this->pollarray['pollimage'] = $_GET['pollimage'];
  35. $this->pollarray['isimage'] = 0;
  36. if(preg_match("/^\d*$/", trim($_GET['expiration']))) {
  37. if(empty($_GET['expiration'])) {
  38. $this->pollarray['expiration'] = 0;
  39. } else {
  40. $this->pollarray['expiration'] = TIMESTAMP + 86400 * $_GET['expiration'];
  41. }
  42. } else {
  43. showmessage('poll_maxchoices_expiration_invalid');
  44. }
  45. if($_GET['polloptions'] || $_GET['polloption']) {
  46. $this->param['extramessage'] = "\t".implode("\t", $_GET['tpolloption'] == 2 ? explode("\n", $_GET['polloptions']) : $_GET['polloption']);
  47. }
  48. }
  49. public function after_newthread() {
  50. foreach($this->pollarray['options'] as $ppkey => $polloptvalue) {
  51. $polloptvalue = dhtmlspecialchars(trim($polloptvalue));
  52. $polloptionid = C::t('forum_polloption')->insert(array('tid' => $this->tid, 'polloption' => $polloptvalue), true);
  53. if($this->pollarray['pollimage'][$ppkey]) {
  54. C::t('forum_polloption_image')->update($this->pollarray['pollimage'][$ppkey], array('poid' => $polloptionid, 'tid' => $this->tid, 'pid' => $this->pid));
  55. $this->pollarray['isimage'] = 1;
  56. }
  57. }
  58. $this->polloptionpreview = '';
  59. $query = C::t('forum_polloption')->fetch_all_by_tid($this->tid, 1, 2);
  60. foreach($query as $option) {
  61. $polloptvalue = preg_replace("/\[url=(https?){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/i", "<a href=\"\\1://\\2\" target=\"_blank\">\\3</a>", $option['polloption']);
  62. $this->polloptionpreview .= $polloptvalue."\t";
  63. }
  64. $this->polloptionpreview = daddslashes($this->polloptionpreview);
  65. $data = array('tid' => $this->tid, 'multiple' => $this->pollarray['multiple'], 'visible' => $this->pollarray['visible'], 'maxchoices' => $this->pollarray['maxchoices'], 'expiration' => $this->pollarray['expiration'], 'overt' => $this->pollarray['overt'], 'pollpreview' => $polloptionpreview, 'isimage' => $this->pollarray['isimage']);
  66. C::t('forum_poll')->insert($data);
  67. }
  68. public function before_feed() {
  69. $pvs = explode("\t", messagecutstr($this->polloptionpreview, 150));
  70. $s = '';
  71. $i = 1;
  72. foreach($pvs as $pv) {
  73. $s .= $i.'. '.$pv.'<br />';
  74. }
  75. $s .= '&nbsp;&nbsp;&nbsp;...';
  76. $this->feed['icon'] = 'poll';
  77. $this->feed['title_template'] = 'feed_thread_poll_title';
  78. $this->feed['body_template'] = 'feed_thread_poll_message';
  79. $this->feed['body_data'] = array(
  80. 'subject' => "<a href=\"forum.php?mod=viewthread&tid={$this->tid}\">".$this->param['subject']."</a>",
  81. 'message' => $s
  82. );
  83. }
  84. public function before_editpost($parameters) {
  85. $isfirstpost = $this->post['first'] ? 1 : 0;
  86. $isorigauthor = $this->member['uid'] && $this->member['uid'] == $this->post['authorid'];
  87. if($isfirstpost) {
  88. if($this->thread['special'] == 1 && ($this->group['alloweditpoll'] || $isorigauthor) && !empty($_GET['polls'])) {
  89. $pollarray = array();
  90. foreach($_GET['polloption'] as $key => $val) {
  91. if(trim($val) === '') {
  92. unset($_GET['polloption'][$key]);
  93. }
  94. }
  95. $pollarray['options'] = $_GET['polloption'];
  96. if($pollarray['options']) {
  97. if(count($pollarray['options']) > $this->setting['maxpolloptions']) {
  98. showmessage('post_poll_option_toomany', '', array('maxpolloptions' => $this->setting['maxpolloptions']));
  99. }
  100. foreach($pollarray['options'] as $key => $value) {
  101. $pollarray['options'][$key] = censor($pollarray['options'][$key]);
  102. if(!trim($value)) {
  103. C::t('forum_polloption')->delete_safe_tid($this->thread['tid'], $key);
  104. unset($pollarray['options'][$key]);
  105. }
  106. }
  107. $this->param['threadupdatearr']['special'] = 1;
  108. foreach($_GET['displayorder'] as $key => $value) {
  109. if(preg_match("/^-?\d*$/", $value)) {
  110. $pollarray['displayorder'][$key] = $value;
  111. }
  112. }
  113. $curpolloption = count($pollarray['options']);
  114. $pollarray['maxchoices'] = empty($_GET['maxchoices']) ? 0 : ($_GET['maxchoices'] > $curpolloption ? $curpolloption : $_GET['maxchoices']);
  115. $pollarray['multiple'] = empty($_GET['maxchoices']) || $_GET['maxchoices'] == 1 ? 0 : 1;
  116. $pollarray['visible'] = empty($_GET['visibilitypoll']);
  117. $pollarray['expiration'] = $_GET['expiration'];
  118. $pollarray['overt'] = !empty($_GET['overt']);
  119. $pollarray['pollimage'] = $_GET['pollimage'];
  120. foreach($_GET['polloptionid'] as $key => $value) {
  121. if(!preg_match("/^\d*$/", $value)) {
  122. showmessage('submit_invalid');
  123. }
  124. }
  125. $expiration = intval($_GET['expiration']);
  126. if($close) {
  127. $pollarray['expiration'] = TIMESTAMP;
  128. } elseif($expiration) {
  129. if(empty($pollarray['expiration'])) {
  130. $pollarray['expiration'] = 0;
  131. } else {
  132. $pollarray['expiration'] = TIMESTAMP + 86400 * $expiration;
  133. }
  134. }
  135. $optid = array();
  136. $query = C::t('forum_polloption')->fetch_all_by_tid($this->thread['tid']);
  137. foreach($query as $tempoptid) {
  138. $optid[] = $tempoptid['polloptionid'];
  139. }
  140. foreach($pollarray['options'] as $key => $value) {
  141. $value = dhtmlspecialchars(trim($value));
  142. if(in_array($_GET['polloptionid'][$key], $optid)) {
  143. if($this->group['alloweditpoll']) {
  144. C::t('forum_polloption')->update_safe_tid($_GET['polloptionid'][$key], $this->thread['tid'], $pollarray['displayorder'][$key], $value);
  145. } else {
  146. C::t('forum_polloption')->update_safe_tid($_GET['polloptionid'][$key], $this->thread['tid'], $pollarray['displayorder'][$key]);
  147. }
  148. } else {
  149. $polloptionid = C::t('forum_polloption')->insert(array('tid' => $this->thread['tid'], 'displayorder' => $pollarray['displayorder'][$key], 'polloption' => $value), true);
  150. if($pollarray['pollimage'][$key]) {
  151. C::t('forum_polloption_image')->update($pollarray['pollimage'][$key], array('poid' => $polloptionid, 'tid' => $this->thread['tid'], 'pid' => $this->post['pid']));
  152. $pollarray['isimage'] = 1;
  153. }
  154. }
  155. }
  156. $polloptionpreview = '';
  157. $query = C::t('forum_polloption')->fetch_all_by_tid($this->thread['tid'], 1, 2);
  158. foreach($query as $option) {
  159. $polloptvalue = preg_replace("/\[url=(https?){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/i", "<a href=\"\\1://\\2\" target=\"_blank\">\\3</a>", $option['polloption']);
  160. $polloptionpreview .= $polloptvalue."\t";
  161. }
  162. $polloptionpreview = daddslashes($polloptionpreview);
  163. $data = array('multiple' => $pollarray['multiple'], 'visible' => $pollarray['visible'], 'maxchoices' => $pollarray['maxchoices'], 'expiration' => $pollarray['expiration'], 'overt' => $pollarray['overt'], 'pollpreview' => $polloptionpreview);
  164. if($pollarray['isimage']) {
  165. $data['isimage'] = 1;
  166. }
  167. C::t('forum_poll')->update($this->thread['tid'], $data);
  168. } else {
  169. $this->param['threadupdatearr']['special'] = 0;
  170. C::t('forum_poll')->delete($this->thread['tid']);
  171. C::t('forum_polloption')->delete_safe_tid($this->thread['tid']);
  172. }
  173. }
  174. }
  175. }
  176. }
  177. ?>