extend_thread_trade.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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_trade.php 34221 2013-11-15 09:10:23Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class extend_thread_trade extends extend_thread_base {
  12. private $trademessage;
  13. public function before_newthread($parameters) {
  14. $item_price = floatval($_GET['item_price']);
  15. $item_credit = intval($_GET['item_credit']);
  16. $_GET['item_name'] = censor($_GET['item_name']);
  17. if(!trim($_GET['item_name'])) {
  18. return $this->showmessage('trade_please_name');
  19. } elseif($this->group['maxtradeprice'] && $item_price > 0 && ($this->group['mintradeprice'] > $item_price || $this->group['maxtradeprice'] < $item_price)) {
  20. return $this->showmessage('trade_price_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
  21. } elseif($this->group['maxtradeprice'] && $item_credit > 0 && ($this->group['mintradeprice'] > $item_credit || $this->group['maxtradeprice'] < $item_credit)) {
  22. return $this->showmessage('trade_credit_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
  23. } elseif(!$this->group['maxtradeprice'] && $item_price > 0 && $this->group['mintradeprice'] > $item_price) {
  24. return $this->showmessage('trade_price_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
  25. } elseif(!$this->group['maxtradeprice'] && $item_credit > 0 && $this->group['mintradeprice'] > $item_credit) {
  26. return $this->showmessage('trade_credit_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
  27. } elseif($item_price <= 0 && $item_credit <= 0) {
  28. return $this->showmessage('trade_pricecredit_need');
  29. } elseif($_GET['item_number'] < 1) {
  30. return $this->showmessage('tread_please_number');
  31. }
  32. if(!empty($_FILES['tradeattach']['tmp_name'][0])) {
  33. $_FILES['attach'] = array_merge_recursive((array)$_FILES['attach'], $_FILES['tradeattach']);
  34. }
  35. if(($this->group['allowpostattach'] || $this->group['allowpostimage']) && is_array($_FILES['attach'])) {
  36. foreach($_FILES['attach']['name'] as $attachname) {
  37. if($attachname != '') {
  38. checklowerlimit('postattach', 0, 1, $this->forum['fid']);
  39. break;
  40. }
  41. }
  42. }
  43. $this->trademessage = $parameters['message'];
  44. $this->param['message'] = '';
  45. }
  46. public function after_newthread() {
  47. if(!$this->tid) {
  48. return;
  49. }
  50. $this->trademessage = preg_replace('/\[attachimg\](\d+)\[\/attachimg\]/is', '[attach]\1[/attach]', $this->trademessage);
  51. $pid = insertpost(array(
  52. 'fid' => $this->forum['fid'],
  53. 'tid' => $this->tid,
  54. 'first' => '0',
  55. 'author' => $this->member['username'],
  56. 'authorid' => $this->member['uid'],
  57. 'subject' => $this->param['subject'],
  58. 'dateline' => getglobal('timestamp'),
  59. 'message' => $this->trademessage,
  60. 'useip' => getglobal('clientip'),
  61. 'invisible' => 0,
  62. 'anonymous' => $this->param['isanonymous'],
  63. 'usesig' => $_GET['usesig'],
  64. 'htmlon' => $this->param['htmlon'],
  65. 'bbcodeoff' => 0,
  66. 'smileyoff' => $this->param['smileyoff'],
  67. 'parseurloff' => $this->param['parseurloff'],
  68. 'attachment' => 0,
  69. 'tags' => $this->param['tagstr'],
  70. 'status' => (defined('IN_MOBILE') ? 8 : 0)
  71. ));
  72. ($this->group['allowpostattach'] || $this->group['allowpostimage']) && ($_GET['attachnew'] || $_GET['tradeaid']) && updateattach($this->param['displayorder'] == -4 || $this->param['modnewthreads'], $this->tid, $pid, $_GET['attachnew']);
  73. require_once libfile('function/trade');
  74. $author = !$this->param['isanonymous'] ? $this->member['username'] : '';
  75. trade_create(array(
  76. 'tid' => $this->tid,
  77. 'pid' => $pid,
  78. 'aid' => $_GET['tradeaid'],
  79. 'item_expiration' => $_GET['item_expiration'],
  80. 'thread' => $this->thread,
  81. 'discuz_uid' => $this->member['uid'],
  82. 'author' => $author,
  83. 'seller' => empty($_GET['paymethod']) && $_GET['seller'] ? dhtmlspecialchars(trim($_GET['seller'])) : '',
  84. 'tenpayaccount' => $_GET['tenpay_account'],
  85. 'item_name' => $_GET['item_name'],
  86. 'item_price' => $_GET['item_price'],
  87. 'item_number' => $_GET['item_number'],
  88. 'item_quality' => $_GET['item_quality'],
  89. 'item_locus' => $_GET['item_locus'],
  90. 'transport' => $_GET['transport'],
  91. 'postage_mail' => $_GET['postage_mail'],
  92. 'postage_express' => $_GET['postage_express'],
  93. 'postage_ems' => $_GET['postage_ems'],
  94. 'item_type' => $_GET['item_type'],
  95. 'item_costprice' => $_GET['item_costprice'],
  96. 'item_credit' => $_GET['item_credit'],
  97. 'item_costcredit' => $_GET['item_costcredit']
  98. ));
  99. if(!empty($_GET['tradeaid'])) {
  100. convertunusedattach($_GET['tradeaid'], $this->tid, $pid);
  101. }
  102. }
  103. public function before_feed() {
  104. if(!empty($_GET['addfeed']) && $this->forum['allowfeed'] && !$this->param['isanonymous']) {
  105. $this->feed['icon'] = 'goods';
  106. $this->feed['title_template'] = 'feed_thread_goods_title';
  107. if($_GET['item_price'] > 0) {
  108. if($this->setting['creditstransextra'][5] != -1 && $_GET['item_credit']) {
  109. $this->feed['body_template'] = 'feed_thread_goods_message_1';
  110. } else {
  111. $this->feed['body_template'] = 'feed_thread_goods_message_2';
  112. }
  113. } else {
  114. $this->feed['body_template'] = 'feed_thread_goods_message_3';
  115. }
  116. $this->feed['body_data'] = array(
  117. 'itemname'=> "<a href=\"forum.php?mod=viewthread&do=tradeinfo&tid=".$this->tid."&pid=$pid\">$_GET[item_name]</a>",
  118. 'itemprice'=> $_GET['item_price'],
  119. 'itemcredit'=> $_GET['item_credit'],
  120. 'creditunit'=> $this->setting['extcredits'][$this->setting['creditstransextra'][5]]['unit'].$this->setting['extcredits'][$this->setting['creditstransextra'][5]]['title']
  121. );
  122. if($_GET['tradeaid']) {
  123. $this->feed['images'] = array(getforumimg($_GET['tradeaid']));
  124. $this->feed['image_links'] = array("forum.php?mod=viewthread&do=tradeinfo&tid=".$this->tid."&pid=$pid");
  125. }
  126. if($_GET['tradeaid']) {
  127. $attachment = C::t('forum_attachment_n')->fetch('tid:'.$this->tid, $_GET['tradeaid']);
  128. if(in_array($attachment['filetype'], array('image/gif', 'image/jpeg', 'image/png'))) {
  129. $imgurl = $this->setting['attachurl'].'forum/'.($attachment['thumb'] && $attachment['filetype'] != 'image/gif' ? getimgthumbname($attachment['attachment']) : $attachment['attachment']);
  130. $this->feed['images'][] = $attachment['attachment'] ? $imgurl : '';
  131. $this->feed['image_links'][] = $attachment['attachment'] ? "forum.php?mod=viewthread&tid=".$this->tid : '';
  132. }
  133. }
  134. }
  135. }
  136. public function after_feed() {
  137. global $extra;
  138. $values = array('fid' => $this->forum['fid'], 'tid' => $this->tid, 'pid' => $this->pid, 'coverimg' => '');
  139. $values = array_merge($values, (array)$this->param['values'], $this->param['param']);
  140. if(!empty($_GET['continueadd'])) {
  141. showmessage('post_newthread_succeed', "forum.php?mod=post&action=reply&fid=".$this->forum['fid']."&tid=".$this->tid."&addtrade=yes", $values, array('header' => true));
  142. } else {
  143. showmessage('post_newthread_succeed', "forum.php?mod=viewthread&tid=".$this->tid."&extra=$extra", $values);
  144. }
  145. }
  146. public function before_newreply($parameters) {
  147. $item_price = floatval($_GET['item_price']);
  148. $item_credit = intval($_GET['item_credit']);
  149. if(!trim($_GET['item_name'])) {
  150. return $this->showmessage('trade_please_name');
  151. } elseif($this->group['maxtradeprice'] && $item_price > 0 && ($this->group['mintradeprice'] > $item_price || $this->group['maxtradeprice'] < $item_price)) {
  152. return $this->showmessage('trade_price_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
  153. } elseif($this->group['maxtradeprice'] && $item_credit > 0 && ($this->group['mintradeprice'] > $item_credit || $this->group['maxtradeprice'] < $item_credit)) {
  154. return $this->showmessage('trade_credit_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
  155. } elseif(!$this->group['maxtradeprice'] && $item_price > 0 && $this->group['mintradeprice'] > $item_price) {
  156. return $this->showmessage('trade_price_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
  157. } elseif(!$this->group['maxtradeprice'] && $item_credit > 0 && $this->group['mintradeprice'] > $item_credit) {
  158. return $this->showmessage('trade_credit_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
  159. } elseif($item_price <= 0 && $item_credit <= 0) {
  160. return $this->showmessage('trade_pricecredit_need');
  161. } elseif($_GET['item_number'] < 1) {
  162. return $this->showmessage('tread_please_number');
  163. }
  164. }
  165. public function after_newreply() {
  166. if(!$this->pid) {
  167. return;
  168. }
  169. if($this->param['special'] == 2 && $this->group['allowposttrade'] && $this->thread['authorid'] == $this->member['uid'] && !empty($_GET['trade']) && !empty($_GET['item_name'])) {
  170. $author = (!$this->param['isanonymous']) ? $this->member['username'] : '';
  171. require_once libfile('function/trade');
  172. trade_create(array(
  173. 'tid' => $this->thread['tid'],
  174. 'pid' => $this->pid,
  175. 'aid' => $_GET['tradeaid'],
  176. 'item_expiration' => $_GET['item_expiration'],
  177. 'thread' => $this->thread,
  178. 'discuz_uid' => $this->member['uid'],
  179. 'author' => $author,
  180. 'seller' => empty($_GET['paymethod']) && $_GET['seller'] ? dhtmlspecialchars(trim($_GET['seller'])) : '',
  181. 'item_name' => $_GET['item_name'],
  182. 'item_price' => $_GET['item_price'],
  183. 'item_number' => $_GET['item_number'],
  184. 'item_quality' => $_GET['item_quality'],
  185. 'item_locus' => $_GET['item_locus'],
  186. 'transport' => $_GET['transport'],
  187. 'postage_mail' => $_GET['postage_mail'],
  188. 'postage_express' => $_GET['postage_express'],
  189. 'postage_ems' => $_GET['postage_ems'],
  190. 'item_type' => $_GET['item_type'],
  191. 'item_costprice' => $_GET['item_costprice'],
  192. 'item_credit' => $_GET['item_credit'],
  193. 'item_costcredit' => $_GET['item_costcredit']
  194. ));
  195. if(!empty($_GET['tradeaid'])) {
  196. convertunusedattach($_GET['tradeaid'], $this->thread['tid'], $this->pid);
  197. }
  198. }
  199. if(!$this->forum['allowfeed'] || !$_GET['addfeed']) {
  200. $this->after_replyfeed();
  201. }
  202. }
  203. public function before_replyfeed() {
  204. if($this->forum['allowfeed'] && !$this->param['isanonymous']) {
  205. if($this->param['special'] == 2 && !empty($_GET['trade'])) {
  206. $creditstransextra = $this->setting['creditstransextra'];
  207. $extcredits = $this->setting['extcredits'];
  208. $this->feed['icon'] = 'goods';
  209. $this->feed['title_template'] = 'feed_thread_goods_title';
  210. if($_GET['item_price'] > 0) {
  211. if($creditstransextra[5] != -1 && $_GET['item_credit']) {
  212. $this->feed['body_template'] = 'feed_thread_goods_message_1';
  213. } else {
  214. $this->feed['body_template'] = 'feed_thread_goods_message_2';
  215. }
  216. } else {
  217. $this->feed['body_template'] = 'feed_thread_goods_message_3';
  218. }
  219. $this->feed['body_data'] = array(
  220. 'itemname'=> "<a href=\"forum.php?mod=viewthread&do=tradeinfo&tid=".$this->thread['tid']."&pid=".$this->pid."\">".dhtmlspecialchars($_GET['item_name'])."</a>",
  221. 'itemprice'=> $_GET['item_price'],
  222. 'itemcredit'=> $_GET['item_credit'],
  223. 'creditunit'=> $extcredits[$creditstransextra[5]]['unit'].$extcredits[$creditstransextra[5]]['title'],
  224. );
  225. if($_GET['tradeaid']) {
  226. $this->feed['images'] = array(getforumimg($_GET['tradeaid']));
  227. $this->feed['image_links'] = array("forum.php?mod=viewthread&do=tradeinfo&tid=".$this->thread['tid']."&pid=".$this->pid);
  228. }
  229. }
  230. }
  231. }
  232. public function after_replyfeed() {
  233. global $extra;
  234. if($this->param['special'] == 2 && $this->group['allowposttrade'] && $this->thread['authorid'] == $this->member['uid']) {
  235. if(!empty($_GET['continueadd'])) {
  236. dheader("location: forum.php?mod=post&action=reply&fid=".$this->forum['fid']."&firstpid=".$this->pid."&tid=".$this->thread['tid']."&addtrade=yes");
  237. } else {
  238. if($this->param['modnewreplies']) {
  239. $url = "forum.php?mod=viewthread&tid=".$this->thread['tid'];
  240. } else {
  241. $url = "forum.php?mod=viewthread&tid=".$this->thread['tid']."&pid=".$this->pid."&page=".$this->param['page']."&extra=".$extra."#pid".$this->pid;
  242. }
  243. return $this->showmessage('trade_add_succeed', $url, $this->param['showmsgparam']);
  244. }
  245. }
  246. }
  247. public function before_editpost($parameters) {
  248. global $closed;
  249. if($parameters['special'] == 2 && $this->group['allowposttrade']) {
  250. if($trade = C::t('forum_trade')->fetch_goods($this->thread['tid'], $this->post['pid'])) {
  251. $seller = empty($_GET['paymethod']) && $_GET['seller'] ? censor(dhtmlspecialchars(trim($_GET['seller']))) : '';
  252. $item_name = censor(dhtmlspecialchars(trim($_GET['item_name'])));
  253. $item_price = floatval($_GET['item_price']);
  254. $item_credit = intval($_GET['item_credit']);
  255. $item_locus = censor(dhtmlspecialchars(trim($_GET['item_locus'])));
  256. $item_number = intval($_GET['item_number']);
  257. $item_quality = intval($_GET['item_quality']);
  258. $item_transport = intval($_GET['item_transport']);
  259. $postage_mail = intval($_GET['postage_mail']);
  260. $postage_express = intval(trim($_GET['postage_express']));
  261. $postage_ems = intval($_GET['postage_ems']);
  262. $item_type = intval($_GET['item_type']);
  263. $item_costprice = floatval($_GET['item_costprice']);
  264. if(!trim($item_name)) {
  265. showmessage('trade_please_name');
  266. } elseif($this->group['maxtradeprice'] && $item_price > 0 && ($this->group['mintradeprice'] > $item_price || $this->group['maxtradeprice'] < $item_price)) {
  267. showmessage('trade_price_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
  268. } elseif($this->group['maxtradeprice'] && $item_credit > 0 && ($this->group['mintradeprice'] > $item_credit || $this->group['maxtradeprice'] < $item_credit)) {
  269. showmessage('trade_credit_between', '', array('mintradeprice' => $this->group['mintradeprice'], 'maxtradeprice' => $this->group['maxtradeprice']));
  270. } elseif(!$this->group['maxtradeprice'] && $item_price > 0 && $this->group['mintradeprice'] > $item_price) {
  271. showmessage('trade_price_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
  272. } elseif(!$this->group['maxtradeprice'] && $item_credit > 0 && $this->group['mintradeprice'] > $item_credit) {
  273. showmessage('trade_credit_more_than', '', array('mintradeprice' => $this->group['mintradeprice']));
  274. } elseif($item_price <= 0 && $item_credit <= 0) {
  275. showmessage('trade_pricecredit_need');
  276. } elseif($item_number < 1) {
  277. showmessage('tread_please_number');
  278. }
  279. if($trade['aid'] && $_GET['tradeaid'] && $trade['aid'] != $_GET['tradeaid']) {
  280. $attach = C::t('forum_attachment_n')->fetch('tid:'.$this->thread['tid'], $trade['aid']);
  281. C::t('forum_attachment')->delete($trade['aid']);
  282. C::t('forum_attachment_n')->delete('tid:'.$this->thread['tid'], $trade['aid']);
  283. dunlink($attach);
  284. $this->param['threadimageaid'] = $_GET['tradeaid'];
  285. convertunusedattach($_GET['tradeaid'], $this->thread['tid'], $this->post['pid']);
  286. }
  287. $expiration = $_GET['item_expiration'] ? @strtotime($_GET['item_expiration']) : 0;
  288. $closed = $expiration > 0 && @strtotime($_GET['item_expiration']) < TIMESTAMP ? 1 : $closed;
  289. switch($_GET['transport']) {
  290. case 'seller':$item_transport = 1;break;
  291. case 'buyer':$item_transport = 2;break;
  292. case 'virtual':$item_transport = 3;break;
  293. case 'logistics':$item_transport = 4;break;
  294. }
  295. if(!$item_price || $item_price <= 0) {
  296. $item_price = $postage_mail = $postage_express = $postage_ems = '';
  297. }
  298. $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']);
  299. C::t('forum_trade')->update($this->thread['tid'], $this->post['pid'], $data);
  300. if(!empty($_GET['infloat'])) {
  301. $viewpid = C::t('forum_post')->fetch_threadpost_by_tid_invisible($this->thread['tid']);
  302. $viewpid = $viewpid['pid'];
  303. $this->param['redirecturl'] = "forum.php?mod=viewthread&tid=".$this->thread['tid']."&viewpid=$viewpid#pid$viewpid";
  304. } else {
  305. $this->param['redirecturl'] = "forum.php?mod=viewthread&do=tradeinfo&tid=".$this->thread['tid']."&pid=".$this->post['pid'];
  306. }
  307. }
  308. }
  309. }
  310. public function after_deletepost() {
  311. if($this->thread['special'] == 2) {
  312. C::t('forum_trade')->delete_by_id_idtype($this->post['pid'], 'pid');
  313. }
  314. }
  315. }
  316. ?>