extend_thread_activity.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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_activity.php 35202 2015-02-04 08:07:39Z hypowang $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class extend_thread_activity extends extend_thread_base {
  12. public $activity;
  13. public $activitytime;
  14. public function before_newthread($parameters) {
  15. $this->activitytime = intval($_GET['activitytime']);
  16. if(empty($_GET['starttimefrom'][$this->activitytime])) {
  17. showmessage('activity_fromtime_please');
  18. } elseif(@strtotime($_GET['starttimefrom'][$this->activitytime]) === -1 || @strtotime($_GET['starttimefrom'][$this->activitytime]) === FALSE) {
  19. showmessage('activity_fromtime_error');
  20. } elseif($this->activitytime && ((@strtotime($_GET['starttimefrom']) > @strtotime($_GET['starttimeto']) || !$_GET['starttimeto']))) {
  21. showmessage('activity_fromtime_error');
  22. } elseif(!trim($_GET['activityclass'])) {
  23. showmessage('activity_sort_please');
  24. } elseif(!trim($_GET['activityplace'])) {
  25. showmessage('activity_address_please');
  26. } elseif(trim($_GET['activityexpiration']) && (@strtotime($_GET['activityexpiration']) === -1 || @strtotime($_GET['activityexpiration']) === FALSE)) {
  27. showmessage('activity_totime_error');
  28. }
  29. $this->activity = array();
  30. $this->activity['class'] = censor(dhtmlspecialchars(trim($_GET['activityclass'])));
  31. $this->activity['starttimefrom'] = @strtotime($_GET['starttimefrom'][$this->activitytime]);
  32. $this->activity['starttimeto'] = $this->activitytime ? @strtotime($_GET['starttimeto']) : 0;
  33. $this->activity['place'] = censor(dhtmlspecialchars(trim($_GET['activityplace'])));
  34. $this->activity['cost'] = intval($_GET['cost']);
  35. $this->activity['gender'] = intval($_GET['gender']);
  36. $this->activity['number'] = intval($_GET['activitynumber']);
  37. if($_GET['activityexpiration']) {
  38. $this->activity['expiration'] = @strtotime($_GET['activityexpiration']);
  39. } else {
  40. $this->activity['expiration'] = 0;
  41. }
  42. if(trim($_GET['activitycity'])) {
  43. $this->param['subject'] = $parameters['subject'].'['.dhtmlspecialchars(trim($_GET['activitycity'])).']';
  44. }
  45. $extfield = $_GET['extfield'];
  46. $extfield = explode("\n", $_GET['extfield']);
  47. foreach($extfield as $key => $value) {
  48. $extfield[$key] = dhtmlspecialchars(strip_tags(censor(trim($value))));
  49. if($extfield[$key] === '' || is_numeric($extfield[$key])) {
  50. unset($extfield[$key]);
  51. }
  52. }
  53. $extfield = array_unique($extfield);
  54. if(count($extfield) > $this->setting['activityextnum']) {
  55. showmessage('post_activity_extfield_toomany', '', array('maxextfield' => $this->setting['activityextnum']));
  56. }
  57. $this->activity['ufield'] = array('userfield' => $_GET['userfield'], 'extfield' => $extfield);
  58. $this->activity['ufield'] = serialize($this->activity['ufield']);
  59. if(intval($_GET['activitycredit']) > 0) {
  60. $this->activity['credit'] = intval($_GET['activitycredit']);
  61. }
  62. $this->param['extramessage'] = "\t".$_GET['activityplace']."\t".$_GET['activitycity']."\t".$_GET['activityclass'];
  63. }
  64. public function after_newthread() {
  65. if($this->group['allowpostactivity']) {
  66. $data = array('tid' => $this->tid, 'uid' => $this->member['uid'], 'cost' => $this->activity['cost'], 'starttimefrom' => $this->activity['starttimefrom'], 'starttimeto' => $this->activity['starttimeto'], 'place' => $this->activity['place'], 'class' => $this->activity['class'], 'gender' => $this->activity['gender'], 'number' => $this->activity['number'], 'expiration' => $this->activity['expiration'], 'aid' => $_GET['activityaid'], 'ufield' => $this->activity['ufield'], 'credit' => $this->activity['credit']);
  67. C::t('forum_activity')->insert($data);
  68. }
  69. }
  70. public function before_feed() {
  71. $message = !$this->param['price'] && !$this->param['readperm'] ? $this->param['message'] : '';
  72. $this->feed['icon'] = 'activity';
  73. $this->feed['title_template'] = 'feed_thread_activity_title';
  74. $this->feed['body_template'] = 'feed_thread_activity_message';
  75. $this->feed['body_data'] = array(
  76. 'subject' => "<a href=\"forum.php?mod=viewthread&tid={$this->tid}\">{$this->param['subject']}</a>",
  77. 'starttimefrom' => $_GET['starttimefrom'][$this->activitytime],
  78. 'activityplace'=> $this->activity['place'],
  79. 'message' => messagecutstr($message, 150),
  80. );
  81. if($_GET['activityaid']) {
  82. $this->feed['images'] = array(getforumimg($_GET['activityaid']));
  83. $this->feed['image_links'] = array("forum.php?mod=viewthread&do=tradeinfo&tid={$this->tid}&pid={$this->pid}");
  84. }
  85. }
  86. public function before_editpost($parameters) {
  87. $isfirstpost = $this->post['first'] ? 1 : 0;
  88. if($isfirstpost) {
  89. if($this->thread['special'] == 4 && $this->group['allowpostactivity']) {
  90. $activitytime = intval($_GET['activitytime']);
  91. if(empty($_GET['starttimefrom'][$activitytime])) {
  92. showmessage('activity_fromtime_please');
  93. } elseif(strtotime($_GET['starttimefrom'][$activitytime]) === -1 || @strtotime($_GET['starttimefrom'][$activitytime]) === FALSE) {
  94. showmessage('activity_fromtime_error');
  95. } elseif($activitytime && ((@strtotime($_GET['starttimefrom']) > @strtotime($_GET['starttimeto']) || !$_GET['starttimeto']))) {
  96. showmessage('activity_fromtime_error');
  97. } elseif(!trim($_GET['activityclass'])) {
  98. showmessage('activity_sort_please');
  99. } elseif(!trim($_GET['activityplace'])) {
  100. showmessage('activity_address_please');
  101. } elseif(trim($_GET['activityexpiration']) && (@strtotime($_GET['activityexpiration']) === -1 || @strtotime($_GET['activityexpiration']) === FALSE)) {
  102. showmessage('activity_totime_error');
  103. }
  104. $activity = array();
  105. $activity['class'] = censor(dhtmlspecialchars(trim($_GET['activityclass'])));
  106. $activity['starttimefrom'] = @strtotime($_GET['starttimefrom'][$activitytime]);
  107. $activity['starttimeto'] = $activitytime ? @strtotime($_GET['starttimeto']) : 0;
  108. $activity['place'] = censor(dhtmlspecialchars(trim($_GET['activityplace'])));
  109. $activity['cost'] = intval($_GET['cost']);
  110. $activity['gender'] = intval($_GET['gender']);
  111. $activity['number'] = intval($_GET['activitynumber']);
  112. if($_GET['activityexpiration']) {
  113. $activity['expiration'] = @strtotime($_GET['activityexpiration']);
  114. } else {
  115. $activity['expiration'] = 0;
  116. }
  117. $extfield = $_GET['extfield'];
  118. $extfield = explode("\n", $_GET['extfield']);
  119. foreach($extfield as $key => $value) {
  120. $extfield[$key] = dhtmlspecialchars(strip_tags(censor(trim($value))));
  121. if($extfield[$key] === '' || is_numeric($extfield[$key])) {
  122. unset($extfield[$key]);
  123. }
  124. }
  125. $extfield = array_unique($extfield);
  126. if(count($extfield) > $this->setting['activityextnum']) {
  127. showmessage('post_activity_extfield_toomany', '', array('maxextfield' => $this->setting['activityextnum']));
  128. }
  129. $activity['ufield'] = array('userfield' => $_GET['userfield'], 'extfield' => $extfield);
  130. $activity['ufield'] = serialize($activity['ufield']);
  131. if(intval($_GET['activitycredit']) > 0) {
  132. $activity['credit'] = intval($_GET['activitycredit']);
  133. }
  134. $data = array('cost' => $activity['cost'], 'starttimefrom' => $activity['starttimefrom'], 'starttimeto' => $activity['starttimeto'], 'place' => $activity['place'], 'class' => $activity['class'], 'gender' => $activity['gender'], 'number' => $activity['number'], 'expiration' => $activity['expiration'], 'ufield' => $activity['ufield'], 'credit' => $activity['credit']);
  135. C::t('forum_activity')->update($this->thread['tid'], $data);
  136. }
  137. }
  138. if($parameters['special'] == 4 && $isfirstpost && $this->group['allowpostactivity']) {
  139. $activity = C::t('forum_activity')->fetch($this->thread['tid']);
  140. $activityaid = $activity['aid'];
  141. if($activityaid && $activityaid != $_GET['activityaid']) {
  142. $attach = C::t('forum_attachment_n')->fetch('tid:'.$this->thread['tid'], $activityaid);
  143. C::t('forum_attachment')->delete($activityaid);
  144. C::t('forum_attachment_n')->delete('tid:'.$this->thread['tid'], $activityaid);
  145. dunlink($attach);
  146. }
  147. if($_GET['activityaid']) {
  148. $threadimageaid = $_GET['activityaid'];
  149. convertunusedattach($_GET['activityaid'], $this->thread['tid'], $this->post['pid']);
  150. C::t('forum_activity')->update($this->thread['tid'], array('aid' => $_GET['activityaid']));
  151. }
  152. }
  153. }
  154. }
  155. ?>