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