extend_thread_trade.php
16.9 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: extend_thread_trade.php 34221 2013-11-15 09:10:23Z nemohou $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class extend_thread_trade extends extend_thread_base {
private $trademessage;
public function before_newthread($parameters) {
$item_price = floatval($_GET['item_price']);
$item_credit = intval($_GET['item_credit']);
$_GET['item_name'] = censor($_GET['item_name']);
if(!trim($_GET['item_name'])) {
return $this->showmessage('trade_please_name');
} elseif($this->group['maxtradeprice'] && $item_price > 0 && ($this->group['mintradeprice'] > $item_price || $this->group['maxtradeprice'] < $item_price)) {
return $this->showmessage('trade_price_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
} elseif($this->group['maxtradeprice'] && $item_credit > 0 && ($this->group['mintradeprice'] > $item_credit || $this->group['maxtradeprice'] < $item_credit)) {
return $this->showmessage('trade_credit_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
} elseif(!$this->group['maxtradeprice'] && $item_price > 0 && $this->group['mintradeprice'] > $item_price) {
return $this->showmessage('trade_price_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
} elseif(!$this->group['maxtradeprice'] && $item_credit > 0 && $this->group['mintradeprice'] > $item_credit) {
return $this->showmessage('trade_credit_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
} elseif($item_price <= 0 && $item_credit <= 0) {
return $this->showmessage('trade_pricecredit_need');
} elseif($_GET['item_number'] < 1) {
return $this->showmessage('tread_please_number');
}
if(!empty($_FILES['tradeattach']['tmp_name'][0])) {
$_FILES['attach'] = array_merge_recursive((array)$_FILES['attach'], $_FILES['tradeattach']);
}
if(($this->group['allowpostattach'] || $this->group['allowpostimage']) && is_array($_FILES['attach'])) {
foreach($_FILES['attach']['name'] as $attachname) {
if($attachname != '') {
checklowerlimit('postattach', 0, 1, $this->forum['fid']);
break;
}
}
}
$this->trademessage = $parameters['message'];
$this->param['message'] = '';
}
public function after_newthread() {
if(!$this->tid) {
return;
}
$this->trademessage = preg_replace('/\[attachimg\](\d+)\[\/attachimg\]/is', '[attach]\1[/attach]', $this->trademessage);
$pid = insertpost(array(
'fid' => $this->forum['fid'],
'tid' => $this->tid,
'first' => '0',
'author' => $this->member['username'],
'authorid' => $this->member['uid'],
'subject' => $this->param['subject'],
'dateline' => getglobal('timestamp'),
'message' => $this->trademessage,
'useip' => getglobal('clientip'),
'invisible' => 0,
'anonymous' => $this->param['isanonymous'],
'usesig' => $_GET['usesig'],
'htmlon' => $this->param['htmlon'],
'bbcodeoff' => 0,
'smileyoff' => $this->param['smileyoff'],
'parseurloff' => $this->param['parseurloff'],
'attachment' => 0,
'tags' => $this->param['tagstr'],
'status' => (defined('IN_MOBILE') ? 8 : 0)
));
($this->group['allowpostattach'] || $this->group['allowpostimage']) && ($_GET['attachnew'] || $_GET['tradeaid']) && updateattach($this->param['displayorder'] == -4 || $this->param['modnewthreads'], $this->tid, $pid, $_GET['attachnew']);
require_once libfile('function/trade');
$author = !$this->param['isanonymous'] ? $this->member['username'] : '';
trade_create(array(
'tid' => $this->tid,
'pid' => $pid,
'aid' => $_GET['tradeaid'],
'item_expiration' => $_GET['item_expiration'],
'thread' => $this->thread,
'discuz_uid' => $this->member['uid'],
'author' => $author,
'seller' => empty($_GET['paymethod']) && $_GET['seller'] ? dhtmlspecialchars(trim($_GET['seller'])) : '',
'tenpayaccount' => $_GET['tenpay_account'],
'item_name' => $_GET['item_name'],
'item_price' => $_GET['item_price'],
'item_number' => $_GET['item_number'],
'item_quality' => $_GET['item_quality'],
'item_locus' => $_GET['item_locus'],
'transport' => $_GET['transport'],
'postage_mail' => $_GET['postage_mail'],
'postage_express' => $_GET['postage_express'],
'postage_ems' => $_GET['postage_ems'],
'item_type' => $_GET['item_type'],
'item_costprice' => $_GET['item_costprice'],
'item_credit' => $_GET['item_credit'],
'item_costcredit' => $_GET['item_costcredit']
));
if(!empty($_GET['tradeaid'])) {
convertunusedattach($_GET['tradeaid'], $this->tid, $pid);
}
}
public function before_feed() {
if(!empty($_GET['addfeed']) && $this->forum['allowfeed'] && !$this->param['isanonymous']) {
$this->feed['icon'] = 'goods';
$this->feed['title_template'] = 'feed_thread_goods_title';
if($_GET['item_price'] > 0) {
if($this->setting['creditstransextra'][5] != -1 && $_GET['item_credit']) {
$this->feed['body_template'] = 'feed_thread_goods_message_1';
} else {
$this->feed['body_template'] = 'feed_thread_goods_message_2';
}
} else {
$this->feed['body_template'] = 'feed_thread_goods_message_3';
}
$this->feed['body_data'] = array(
'itemname'=> "<a href=\"forum.php?mod=viewthread&do=tradeinfo&tid=".$this->tid."&pid=$pid\">$_GET[item_name]</a>",
'itemprice'=> $_GET['item_price'],
'itemcredit'=> $_GET['item_credit'],
'creditunit'=> $this->setting['extcredits'][$this->setting['creditstransextra'][5]]['unit'].$this->setting['extcredits'][$this->setting['creditstransextra'][5]]['title']
);
if($_GET['tradeaid']) {
$this->feed['images'] = array(getforumimg($_GET['tradeaid']));
$this->feed['image_links'] = array("forum.php?mod=viewthread&do=tradeinfo&tid=".$this->tid."&pid=$pid");
}
if($_GET['tradeaid']) {
$attachment = C::t('forum_attachment_n')->fetch('tid:'.$this->tid, $_GET['tradeaid']);
if(in_array($attachment['filetype'], array('image/gif', 'image/jpeg', 'image/png'))) {
$imgurl = $this->setting['attachurl'].'forum/'.($attachment['thumb'] && $attachment['filetype'] != 'image/gif' ? getimgthumbname($attachment['attachment']) : $attachment['attachment']);
$this->feed['images'][] = $attachment['attachment'] ? $imgurl : '';
$this->feed['image_links'][] = $attachment['attachment'] ? "forum.php?mod=viewthread&tid=".$this->tid : '';
}
}
}
}
public function after_feed() {
global $extra;
$values = array('fid' => $this->forum['fid'], 'tid' => $this->tid, 'pid' => $this->pid, 'coverimg' => '');
$values = array_merge($values, (array)$this->param['values'], $this->param['param']);
if(!empty($_GET['continueadd'])) {
showmessage('post_newthread_succeed', "forum.php?mod=post&action=reply&fid=".$this->forum['fid']."&tid=".$this->tid."&addtrade=yes", $values, array('header' => true));
} else {
showmessage('post_newthread_succeed', "forum.php?mod=viewthread&tid=".$this->tid."&extra=$extra", $values);
}
}
public function before_newreply($parameters) {
$item_price = floatval($_GET['item_price']);
$item_credit = intval($_GET['item_credit']);
if(!trim($_GET['item_name'])) {
return $this->showmessage('trade_please_name');
} elseif($this->group['maxtradeprice'] && $item_price > 0 && ($this->group['mintradeprice'] > $item_price || $this->group['maxtradeprice'] < $item_price)) {
return $this->showmessage('trade_price_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
} elseif($this->group['maxtradeprice'] && $item_credit > 0 && ($this->group['mintradeprice'] > $item_credit || $this->group['maxtradeprice'] < $item_credit)) {
return $this->showmessage('trade_credit_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
} elseif(!$this->group['maxtradeprice'] && $item_price > 0 && $this->group['mintradeprice'] > $item_price) {
return $this->showmessage('trade_price_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
} elseif(!$this->group['maxtradeprice'] && $item_credit > 0 && $this->group['mintradeprice'] > $item_credit) {
return $this->showmessage('trade_credit_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
} elseif($item_price <= 0 && $item_credit <= 0) {
return $this->showmessage('trade_pricecredit_need');
} elseif($_GET['item_number'] < 1) {
return $this->showmessage('tread_please_number');
}
}
public function after_newreply() {
if(!$this->pid) {
return;
}
if($this->param['special'] == 2 && $this->group['allowposttrade'] && $this->thread['authorid'] == $this->member['uid'] && !empty($_GET['trade']) && !empty($_GET['item_name'])) {
$author = (!$this->param['isanonymous']) ? $this->member['username'] : '';
require_once libfile('function/trade');
trade_create(array(
'tid' => $this->thread['tid'],
'pid' => $this->pid,
'aid' => $_GET['tradeaid'],
'item_expiration' => $_GET['item_expiration'],
'thread' => $this->thread,
'discuz_uid' => $this->member['uid'],
'author' => $author,
'seller' => empty($_GET['paymethod']) && $_GET['seller'] ? dhtmlspecialchars(trim($_GET['seller'])) : '',
'item_name' => $_GET['item_name'],
'item_price' => $_GET['item_price'],
'item_number' => $_GET['item_number'],
'item_quality' => $_GET['item_quality'],
'item_locus' => $_GET['item_locus'],
'transport' => $_GET['transport'],
'postage_mail' => $_GET['postage_mail'],
'postage_express' => $_GET['postage_express'],
'postage_ems' => $_GET['postage_ems'],
'item_type' => $_GET['item_type'],
'item_costprice' => $_GET['item_costprice'],
'item_credit' => $_GET['item_credit'],
'item_costcredit' => $_GET['item_costcredit']
));
if(!empty($_GET['tradeaid'])) {
convertunusedattach($_GET['tradeaid'], $this->thread['tid'], $this->pid);
}
}
if(!$this->forum['allowfeed'] || !$_GET['addfeed']) {
$this->after_replyfeed();
}
}
public function before_replyfeed() {
if($this->forum['allowfeed'] && !$this->param['isanonymous']) {
if($this->param['special'] == 2 && !empty($_GET['trade'])) {
$creditstransextra = $this->setting['creditstransextra'];
$extcredits = $this->setting['extcredits'];
$this->feed['icon'] = 'goods';
$this->feed['title_template'] = 'feed_thread_goods_title';
if($_GET['item_price'] > 0) {
if($creditstransextra[5] != -1 && $_GET['item_credit']) {
$this->feed['body_template'] = 'feed_thread_goods_message_1';
} else {
$this->feed['body_template'] = 'feed_thread_goods_message_2';
}
} else {
$this->feed['body_template'] = 'feed_thread_goods_message_3';
}
$this->feed['body_data'] = array(
'itemname'=> "<a href=\"forum.php?mod=viewthread&do=tradeinfo&tid=".$this->thread['tid']."&pid=".$this->pid."\">".dhtmlspecialchars($_GET['item_name'])."</a>",
'itemprice'=> $_GET['item_price'],
'itemcredit'=> $_GET['item_credit'],
'creditunit'=> $extcredits[$creditstransextra[5]]['unit'].$extcredits[$creditstransextra[5]]['title'],
);
if($_GET['tradeaid']) {
$this->feed['images'] = array(getforumimg($_GET['tradeaid']));
$this->feed['image_links'] = array("forum.php?mod=viewthread&do=tradeinfo&tid=".$this->thread['tid']."&pid=".$this->pid);
}
}
}
}
public function after_replyfeed() {
global $extra;
if($this->param['special'] == 2 && $this->group['allowposttrade'] && $this->thread['authorid'] == $this->member['uid']) {
if(!empty($_GET['continueadd'])) {
dheader("location: forum.php?mod=post&action=reply&fid=".$this->forum['fid']."&firstpid=".$this->pid."&tid=".$this->thread['tid']."&addtrade=yes");
} else {
if($this->param['modnewreplies']) {
$url = "forum.php?mod=viewthread&tid=".$this->thread['tid'];
} else {
$url = "forum.php?mod=viewthread&tid=".$this->thread['tid']."&pid=".$this->pid."&page=".$this->param['page']."&extra=".$extra."#pid".$this->pid;
}
return $this->showmessage('trade_add_succeed', $url, $this->param['showmsgparam']);
}
}
}
public function before_editpost($parameters) {
global $closed;
if($parameters['special'] == 2 && $this->group['allowposttrade']) {
if($trade = C::t('forum_trade')->fetch_goods($this->thread['tid'], $this->post['pid'])) {
$seller = empty($_GET['paymethod']) && $_GET['seller'] ? censor(dhtmlspecialchars(trim($_GET['seller']))) : '';
$item_name = censor(dhtmlspecialchars(trim($_GET['item_name'])));
$item_price = floatval($_GET['item_price']);
$item_credit = intval($_GET['item_credit']);
$item_locus = censor(dhtmlspecialchars(trim($_GET['item_locus'])));
$item_number = intval($_GET['item_number']);
$item_quality = intval($_GET['item_quality']);
$item_transport = intval($_GET['item_transport']);
$postage_mail = intval($_GET['postage_mail']);
$postage_express = intval(trim($_GET['postage_express']));
$postage_ems = intval($_GET['postage_ems']);
$item_type = intval($_GET['item_type']);
$item_costprice = floatval($_GET['item_costprice']);
if(!trim($item_name)) {
showmessage('trade_please_name');
} elseif($this->group['maxtradeprice'] && $item_price > 0 && ($this->group['mintradeprice'] > $item_price || $this->group['maxtradeprice'] < $item_price)) {
showmessage('trade_price_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
} elseif($this->group['maxtradeprice'] && $item_credit > 0 && ($this->group['mintradeprice'] > $item_credit || $this->group['maxtradeprice'] < $item_credit)) {
showmessage('trade_credit_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
} elseif(!$this->group['maxtradeprice'] && $item_price > 0 && $this->group['mintradeprice'] > $item_price) {
showmessage('trade_price_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
} elseif(!$this->group['maxtradeprice'] && $item_credit > 0 && $this->group['mintradeprice'] > $item_credit) {
showmessage('trade_credit_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
} elseif($item_price <= 0 && $item_credit <= 0) {
showmessage('trade_pricecredit_need');
} elseif($item_number < 1) {
showmessage('tread_please_number');
}
if($trade['aid'] && $_GET['tradeaid'] && $trade['aid'] != $_GET['tradeaid']) {
$attach = C::t('forum_attachment_n')->fetch('tid:'.$this->thread['tid'], $trade['aid']);
C::t('forum_attachment')->delete($trade['aid']);
C::t('forum_attachment_n')->delete('tid:'.$this->thread['tid'], $trade['aid']);
dunlink($attach);
$this->param['threadimageaid'] = $_GET['tradeaid'];
convertunusedattach($_GET['tradeaid'], $this->thread['tid'], $this->post['pid']);
}
$expiration = $_GET['item_expiration'] ? @strtotime($_GET['item_expiration']) : 0;
$closed = $expiration > 0 && @strtotime($_GET['item_expiration']) < TIMESTAMP ? 1 : $closed;
switch($_GET['transport']) {
case 'seller':$item_transport = 1;break;
case 'buyer':$item_transport = 2;break;
case 'virtual':$item_transport = 3;break;
case 'logistics':$item_transport = 4;break;
}
if(!$item_price || $item_price <= 0) {
$item_price = $postage_mail = $postage_express = $postage_ems = '';
}
$data = array('aid' => $_GET['tradeaid'], 'account' => $seller, 'tenpayaccount' => $_GET['tenpay_account'], 'subject' => $item_name, 'price' => $item_price, 'amount' => $item_number, 'quality' => $item_quality, 'locus' => $item_locus, 'transport' => $item_transport, 'ordinaryfee' => $postage_mail, 'expressfee' => $postage_express, 'emsfee' => $postage_ems, 'itemtype' => $item_type, 'expiration' => $expiration, 'closed' => $closed, 'costprice' => $item_costprice, 'credit' => $item_credit, 'costcredit' => $_GET['item_costcredit']);
C::t('forum_trade')->update($this->thread['tid'], $this->post['pid'], $data);
if(!empty($_GET['infloat'])) {
$viewpid = C::t('forum_post')->fetch_threadpost_by_tid_invisible($this->thread['tid']);
$viewpid = $viewpid['pid'];
$this->param['redirecturl'] = "forum.php?mod=viewthread&tid=".$this->thread['tid']."&viewpid=$viewpid#pid$viewpid";
} else {
$this->param['redirecturl'] = "forum.php?mod=viewthread&do=tradeinfo&tid=".$this->thread['tid']."&pid=".$this->post['pid'];
}
}
}
}
public function after_deletepost() {
if($this->thread['special'] == 2) {
C::t('forum_trade')->delete_by_id_idtype($this->post['pid'], 'pid');
}
}
}
?>