PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/source/include/post/post_editpost.php

https://github.com/kuaileshike/upload
PHP | 1124 lines | 995 code | 123 blank | 6 comment | 496 complexity | cdff4cc7872638cc407628eec40fd14f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  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: post_editpost.php 31980 2012-10-30 01:53:07Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $orig = C::t('forum_post')->fetch('tid:'.$_G['tid'], $pid, false);
  12. $isfirstpost = $orig['first'] ? 1 : 0;
  13. if($isfirstpost && (($special == 1 && !$_G['group']['allowpostpoll']) || ($special == 2 && !$_G['group']['allowposttrade']) || ($special == 3 && !$_G['group']['allowpostreward']) || ($special == 4 && !$_G['group']['allowpostactivity']) || ($special == 5 && !$_G['group']['allowpostdebate']))) {
  14. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  15. }
  16. if($orig && $orig['fid'] == $_G['fid'] && $orig['tid'] == $_G['tid']) {
  17. $user = getuserbyuid($orig['authorid']);
  18. $orig['adminid'] = $user['adminid'];
  19. } else {
  20. $orig = array();
  21. }
  22. if($_G['setting']['magicstatus']) {
  23. $magiclog = C::t('forum_threadmod')->fetch_by_tid_magicid($_G['tid'], 10);
  24. $magicid = $magiclog['magicid'];
  25. $_G['group']['allowanonymous'] = $_G['group']['allowanonymous'] || $magicid ? 1 : $_G['group']['allowanonymous'];
  26. }
  27. $isorigauthor = $_G['uid'] && $_G['uid'] == $orig['authorid'];
  28. $isanonymous = ($_G['group']['allowanonymous'] || $orig['anonymous']) && getgpc('isanonymous') ? 1 : 0;
  29. $audit = $orig['invisible'] == -2 || $thread['displayorder'] == -2 ? $_GET['audit'] : 0;
  30. if(empty($orig)) {
  31. showmessage('post_nonexistence');
  32. } elseif((!$_G['forum']['ismoderator'] || !$_G['group']['alloweditpost'] || (in_array($orig['adminid'], array(1, 2, 3)) && $_G['adminid'] > $orig['adminid'])) && !(($_G['forum']['alloweditpost'] || $orig['invisible'] == -3)&& $isorigauthor)) {
  33. showmessage('post_edit_nopermission', NULL);
  34. } elseif($isorigauthor && !$_G['forum']['ismoderator'] && $orig['invisible'] != -3) {
  35. $alloweditpost_status = getstatus($_G['setting']['alloweditpost'], $special + 1);
  36. if(!$alloweditpost_status && $_G['group']['edittimelimit'] && TIMESTAMP - $orig['dateline'] > $_G['group']['edittimelimit'] * 60) {
  37. showmessage('post_edit_timelimit', NULL, array('edittimelimit' => $_G['group']['edittimelimit']));
  38. }
  39. }
  40. $thread['pricedisplay'] = $thread['price'] == -1 ? 0 : $thread['price'];
  41. if($special == 5) {
  42. $debate = array_merge($thread, daddslashes(C::t('forum_debate')->fetch($_G['tid'])));
  43. $firststand = C::t('forum_debatepost')->get_firststand($_G['tid'], $_G['uid']);
  44. if(!$isfirstpost && $debate['endtime'] && $debate['endtime'] < TIMESTAMP && !$_G['forum']['ismoderator']) {
  45. showmessage('debate_end');
  46. }
  47. if($isfirstpost && $debate['umpirepoint'] && !$_G['forum']['ismoderator']) {
  48. showmessage('debate_umpire_comment_invalid');
  49. }
  50. }
  51. $rushreply = getstatus($thread['status'], 3);
  52. if($isfirstpost && $isorigauthor && $_G['group']['allowreplycredit']) {
  53. if($replycredit_rule = C::t('forum_replycredit')->fetch($_G['tid'])) {
  54. if($thread['replycredit']) {
  55. $replycredit_rule['lasttimes'] = $thread['replycredit'] / $replycredit_rule['extcredits'];
  56. }
  57. $replycredit_rule['extcreditstype'] = $replycredit_rule['extcreditstype'] ? $replycredit_rule['extcreditstype'] : $_G['setting']['creditstransextra'][10];
  58. }
  59. }
  60. if(!submitcheck('editsubmit')) {
  61. $thread['hiddenreplies'] = getstatus($thread['status'], 2);
  62. $postinfo = C::t('forum_post')->fetch('tid:'.$_G['tid'], $pid);
  63. if($postinfo['fid'] != $_G['fid'] || $postinfo['tid'] != $_G['tid']) {
  64. $postinfo = array();
  65. }
  66. $usesigcheck = $postinfo['usesig'] ? 'checked="checked"' : '';
  67. $urloffcheck = $postinfo['parseurloff'] ? 'checked="checked"' : '';
  68. $smileyoffcheck = $postinfo['smileyoff'] == 1 ? 'checked="checked"' : '';
  69. $codeoffcheck = $postinfo['bbcodeoff'] == 1 ? 'checked="checked"' : '';
  70. $tagoffcheck = $postinfo['htmlon'] & 2 ? 'checked="checked"' : '';
  71. $htmloncheck = $postinfo['htmlon'] & 1 ? 'checked="checked"' : '';
  72. if($htmloncheck) {
  73. $editor['editormode'] = 0;
  74. $editor['allowswitcheditor'] = 0;
  75. }
  76. $showthreadsorts = ($thread['sortid'] || !empty($sortid)) && $isfirstpost;
  77. $sortid = empty($sortid) ? $thread['sortid'] : $sortid;
  78. $poll = $temppoll = '';
  79. if($isfirstpost) {
  80. if($postinfo['tags']) {
  81. $tagarray_all = $array_temp = $threadtag_array = array();
  82. $tagarray_all = explode("\t", $postinfo['tags']);
  83. if($tagarray_all) {
  84. foreach($tagarray_all as $var) {
  85. if($var) {
  86. $array_temp = explode(',', $var);
  87. $threadtag_array[] = $array_temp['1'];
  88. }
  89. }
  90. }
  91. $postinfo['tag'] = implode(',', $threadtag_array);
  92. }
  93. $allownoticeauthor = getstatus($thread['status'], 6);
  94. if($rushreply) {
  95. $postinfo['rush'] = C::t('forum_threadrush')->fetch($_G['tid']);
  96. if($postinfo['rush']['creditlimit'] == -996) {
  97. $postinfo['rush']['creditlimit'] = '';
  98. }
  99. $postinfo['rush']['stopfloor'] = $postinfo['rush']['stopfloor'] ? $postinfo['rush']['stopfloor'] : '';
  100. $postinfo['rush']['starttimefrom'] = $postinfo['rush']['starttimefrom'] ? dgmdate($postinfo['rush']['starttimefrom'], 'Y-m-d H:i') : '';
  101. $postinfo['rush']['starttimeto'] = $postinfo['rush']['starttimeto'] ? dgmdate($postinfo['rush']['starttimeto'], 'Y-m-d H:i') : '';
  102. }
  103. if($special == 127) {
  104. $sppos = strpos($postinfo['message'], chr(0).chr(0).chr(0));
  105. $specialextra = substr($postinfo['message'], $sppos + 3);
  106. if($specialextra && array_key_exists($specialextra, $_G['setting']['threadplugins']) && in_array($specialextra, $_G['forum']['threadplugin']) && in_array($specialextra, $_G['group']['allowthreadplugin'])) {
  107. $postinfo['message'] = substr($postinfo['message'], 0, $sppos);
  108. } else {
  109. showmessage('post_edit_nopermission_threadplign');
  110. $special = 0;
  111. $specialextra = '';
  112. }
  113. }
  114. $thread['freecharge'] = $_G['setting']['maxchargespan'] && TIMESTAMP - $thread['dateline'] >= $_G['setting']['maxchargespan'] * 3600 ? 1 : 0;
  115. $freechargehours = !$thread['freecharge'] ? $_G['setting']['maxchargespan'] - intval((TIMESTAMP - $thread['dateline']) / 3600) : 0;
  116. if($thread['special'] == 1 && ($_G['group']['alloweditpoll'] || $thread['authorid'] == $_G['uid'])) {
  117. $pollinfo = C::t('forum_poll')->fetch($_G['tid']);
  118. $query = C::t('forum_polloption')->fetch_all_by_tid($_G['tid']);
  119. foreach($query as $temppoll) {
  120. $poll['multiple'] = $pollinfo['multiple'];
  121. $poll['visible'] = $pollinfo['visible'];
  122. $poll['maxchoices'] = $pollinfo['maxchoices'];
  123. $poll['expiration'] = $pollinfo['expiration'];
  124. $poll['overt'] = $pollinfo['overt'];
  125. $poll['polloptionid'][] = $temppoll['polloptionid'];
  126. $poll['displayorder'][] = $temppoll['displayorder'];
  127. $poll['polloption'][] = $temppoll['polloption'];
  128. }
  129. } elseif($thread['special'] == 3) {
  130. $rewardprice = $thread['price'];
  131. } elseif($thread['special'] == 4) {
  132. $activitytypelist = $_G['setting']['activitytype'] ? explode("\n", trim($_G['setting']['activitytype'])) : '';
  133. $activity = C::t('forum_activity')->fetch($_G['tid']);
  134. $activity['starttimefrom'] = dgmdate($activity['starttimefrom'], 'Y-m-d H:i');
  135. $activity['starttimeto'] = $activity['starttimeto'] ? dgmdate($activity['starttimeto'], 'Y-m-d H:i') : '';
  136. $activity['expiration'] = $activity['expiration'] ? dgmdate($activity['expiration'], 'Y-m-d H:i') : '';
  137. $activity['ufield'] = $activity['ufield'] ? dunserialize($activity['ufield']) : array();
  138. if($activity['ufield']['extfield']) {
  139. $activity['ufield']['extfield'] = implode("\n", $activity['ufield']['extfield']);
  140. }
  141. } elseif($thread['special'] == 5 ) {
  142. $debate['endtime'] = $debate['endtime'] ? dgmdate($debate['endtime'], 'Y-m-d H:i') : '';
  143. }
  144. if ($_G['group']['allowsetpublishdate']) {
  145. loadcache('cronpublish');
  146. $cron_publish_ids = dunserialize(getglobal('cache/cronpublish'));
  147. if (in_array($_G['tid'], $cron_publish_ids)) {
  148. $cronpublish = 1;
  149. $cronpublishdate = dgmdate($thread['dateline'], "dt");
  150. }
  151. }
  152. }
  153. if($thread['special'] == 2 && ($thread['authorid'] == $_G['uid'] && $_G['group']['allowposttrade'] || $_G['group']['allowedittrade'])) {
  154. $trade = C::t('forum_trade')->fetch_goods(0, $pid);
  155. if($trade) {
  156. $trade['expiration'] = $trade['expiration'] ? date('Y-m-d', $trade['expiration']) : '';
  157. $trade['costprice'] = $trade['costprice'] > 0 ? $trade['costprice'] : '';
  158. $trade['message'] = dhtmlspecialchars($trade['message']);
  159. $expiration_7days = date('Y-m-d', TIMESTAMP + 86400 * 7);
  160. $expiration_14days = date('Y-m-d', TIMESTAMP + 86400 * 14);
  161. $expiration_month = date('Y-m-d', mktime(0, 0, 0, date('m')+1, date('d'), date('Y')));
  162. $expiration_3months = date('Y-m-d', mktime(0, 0, 0, date('m')+3, date('d'), date('Y')));
  163. $expiration_halfyear = date('Y-m-d', mktime(0, 0, 0, date('m')+6, date('d'), date('Y')));
  164. $expiration_year = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')+1));
  165. } else {
  166. $special = 0;
  167. $trade = array();
  168. }
  169. }
  170. if($isfirstpost && $specialextra) {
  171. @include_once DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  172. $classname = 'threadplugin_'.$specialextra;
  173. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'editpost')) {
  174. $threadplughtml = $threadpluginclass->editpost($_G['fid'], $_G['tid']);
  175. }
  176. }
  177. $postinfo['subject'] = str_replace('"', '&quot;', $postinfo['subject']);
  178. $postinfo['message'] = dhtmlspecialchars($postinfo['message']);
  179. $language = lang('forum/misc');
  180. $postinfo['message'] = preg_replace($postinfo['htmlon'] ? $language['post_edithtml_regexp'] : (!$_G['forum']['allowbbcode'] || $postinfo['bbcodeoff'] ? $language['post_editnobbcode_regexp'] : $language['post_edit_regexp']), '', $postinfo['message']);
  181. if($special == 5) {
  182. $standselected = array($firststand => 'selected="selected"');
  183. }
  184. if($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) {
  185. $attachlist = getattach($pid);
  186. $attachs = $attachlist['attachs'];
  187. $imgattachs = $attachlist['imgattachs'];
  188. unset($attachlist);
  189. $attachfind = $attachreplace = array();
  190. if(!empty($attachs['used'])) {
  191. foreach($attachs['used'] as $attach) {
  192. if($attach['isimage']) {
  193. $attachfind[] = "/\[attach\]$attach[aid]\[\/attach\]/i";
  194. $attachreplace[] = '[attachimg]'.$attach['aid'].'[/attachimg]';
  195. }
  196. }
  197. }
  198. if(!empty($imgattachs['used'])) {
  199. foreach($imgattachs['used'] as $attach) {
  200. $attachfind[] = "/\[attach\]$attach[aid]\[\/attach\]/i";
  201. $attachreplace[] = '[attachimg]'.$attach['aid'].'[/attachimg]';
  202. }
  203. }
  204. $attachfind && $postinfo['message'] = preg_replace($attachfind, $attachreplace, $postinfo['message']);
  205. }
  206. if($special == 2 && $trade['aid'] && !empty($imgattachs['used']) && is_array($imgattachs['used'])) {
  207. foreach($imgattachs['used'] as $k => $tradeattach) {
  208. if($tradeattach['aid'] == $trade['aid']) {
  209. unset($imgattachs['used'][$k]);
  210. break;
  211. }
  212. }
  213. }
  214. if($special == 4 && $activity['aid'] && !empty($imgattachs['used']) && is_array($imgattachs['used'])) {
  215. foreach($imgattachs['used'] as $k => $activityattach) {
  216. if($activityattach['aid'] == $activity['aid']) {
  217. unset($imgattachs['used'][$k]);
  218. break;
  219. }
  220. }
  221. }
  222. if($sortid) {
  223. require_once libfile('post/threadsorts', 'include');
  224. foreach($_G['forum_optionlist'] as $option) {
  225. if($option['type'] == 'image') {
  226. foreach($imgattachs['used'] as $k => $sortattach) {
  227. if($sortattach['aid'] == $option['value']['aid']) {
  228. unset($imgattachs['used'][$k]);
  229. break;
  230. }
  231. }
  232. }
  233. }
  234. }
  235. $imgattachs['unused'] = !$sortid ? $imgattachs['unused'] : '';
  236. include template('forum/post');
  237. } else {
  238. $redirecturl = "forum.php?mod=viewthread&tid=$_G[tid]&page=$_GET[page]&extra=$extra".($vid && $isfirstpost ? "&vid=$vid" : '')."#pid$pid";
  239. if(empty($_GET['delete'])) {
  240. if($post_invalid = checkpost($subject, $message, $isfirstpost && ($special || $sortid))) {
  241. showmessage($post_invalid, '', array('minpostsize' => $_G['setting']['minpostsize'], 'maxpostsize' => $_G['setting']['maxpostsize']));
  242. }
  243. $threadupdatearr = array();
  244. if(!$isorigauthor && !$_G['group']['allowanonymous']) {
  245. if($orig['anonymous'] && !$isanonymous) {
  246. $isanonymous = 0;
  247. $threadupdatearr['author'] = $orig['author'];
  248. $anonymousadd = 0;
  249. } else {
  250. $isanonymous = $orig['anonymous'];
  251. $anonymousadd = '';
  252. }
  253. } else {
  254. $threadupdatearr['author'] = $isanonymous ? '' : $orig['author'];
  255. $anonymousadd = $isanonymous;
  256. }
  257. if($isfirstpost) {
  258. if(trim($subject) == '' && $thread['special'] != 2) {
  259. showmessage('post_sm_isnull');
  260. }
  261. if(!$sortid && !$thread['special'] && trim($message) == '') {
  262. showmessage('post_sm_isnull');
  263. }
  264. $typeid = isset($_G['forum']['threadtypes']['types'][$typeid]) ? $typeid : 0;
  265. if(!$_G['forum']['ismoderator'] && !empty($_G['forum']['threadtypes']['moderators'][$thread['typeid']])) {
  266. $typeid = $thread['typeid'];
  267. }
  268. $sortid = isset($_G['forum']['threadsorts']['types'][$sortid]) ? $sortid : 0;
  269. $typeexpiration = intval($_GET['typeexpiration']);
  270. if(!$typeid && $_G['forum']['threadtypes']['required'] && !$thread['special']) {
  271. showmessage('post_type_isnull');
  272. }
  273. $publishdate = null;
  274. if ($_G['group']['allowsetpublishdate'] && $thread['displayorder'] == -4) {
  275. loadcache('cronpublish');
  276. $cron_publish_ids = dunserialize($_G['cache']['cronpublish']);
  277. if (!$_GET['cronpublish'] && in_array($_G['tid'], $cron_publish_ids)) {
  278. unset($cron_publish_ids[$_G['tid']]);
  279. $cron_publish_ids = serialize($cron_publish_ids);
  280. savecache('cronpublish', $cron_publish_ids);
  281. } elseif ($_GET['cronpublish'] && $_GET['cronpublishdate']) {
  282. $threadupdatearr['dateline'] = $publishdate = strtotime($_GET['cronpublishdate']);
  283. $_GET['save'] = 1;
  284. if (!in_array($_G['tid'], $cron_publish_ids)) {
  285. $cron_publish_ids[$_G['tid']] = $_G['tid'];
  286. $cron_publish_ids = serialize($cron_publish_ids);
  287. savecache('cronpublish', $cron_publish_ids);
  288. }
  289. }
  290. }
  291. $readperm = $_G['group']['allowsetreadperm'] ? intval($readperm) : ($isorigauthor ? 0 : 'ignore');
  292. if($thread['special'] == 3) {
  293. $price = $isorigauthor ? ($thread['price'] > 0 && $thread['price'] != $_GET['rewardprice'] ? $_GET['rewardprice'] : 0) : $thread['price'];
  294. } else {
  295. $price = intval($_GET['price']);
  296. $price = $thread['price'] < 0 && !$thread['special']
  297. ?($isorigauthor || !$price ? -1 : $price)
  298. :($_G['group']['maxprice'] ? ($price <= $_G['group']['maxprice'] ? ($price > 0 ? $price : 0) : $_G['group']['maxprice']) : ($isorigauthor ? $price : $thread['price']));
  299. if($price > 0 && floor($price * (1 - $_G['setting']['creditstax'])) == 0) {
  300. showmessage('post_net_price_iszero');
  301. }
  302. }
  303. if($thread['special'] == 1 && ($_G['group']['alloweditpoll'] || $isorigauthor) && !empty($_GET['polls'])) {
  304. $pollarray = '';
  305. foreach($_GET['polloption'] as $key => $val) {
  306. if(trim($val) === '') {
  307. unset($_GET['polloption'][$key]);
  308. }
  309. }
  310. $pollarray['options'] = $_GET['polloption'];
  311. if($pollarray['options']) {
  312. if(count($pollarray['options']) > $_G['setting']['maxpolloptions']) {
  313. showmessage('post_poll_option_toomany', '', array('maxpolloptions' => $_G['setting']['maxpolloptions']));
  314. }
  315. foreach($pollarray['options'] as $key => $value) {
  316. $pollarray['options'][$key] = censor($pollarray['options'][$key]);
  317. if(!trim($value)) {
  318. C::t('forum_polloption')->delete_safe_tid($_G['tid'], $key);
  319. unset($pollarray['options'][$key]);
  320. }
  321. }
  322. $threadupdatearr['special'] = 1;
  323. foreach($_GET['displayorder'] as $key => $value) {
  324. if(preg_match("/^-?\d*$/", $value)) {
  325. $pollarray['displayorder'][$key] = $value;
  326. }
  327. }
  328. $curpolloption = count($pollarray['options']);
  329. $pollarray['maxchoices'] = empty($_GET['maxchoices']) ? 0 : ($_GET['maxchoices'] > $curpolloption ? $curpolloption : $_GET['maxchoices']);
  330. $pollarray['multiple'] = empty($_GET['maxchoices']) || $_GET['maxchoices'] == 1 ? 0 : 1;
  331. $pollarray['visible'] = empty($_GET['visibilitypoll']);
  332. $pollarray['expiration'] = $_GET['expiration'];
  333. $pollarray['overt'] = !empty($_GET['overt']);
  334. foreach($_GET['polloptionid'] as $key => $value) {
  335. if(!preg_match("/^\d*$/", $value)) {
  336. showmessage('submit_invalid');
  337. }
  338. }
  339. $expiration = intval($_GET['expiration']);
  340. if($close) {
  341. $pollarray['expiration'] = TIMESTAMP;
  342. } elseif($expiration) {
  343. if(empty($pollarray['expiration'])) {
  344. $pollarray['expiration'] = 0;
  345. } else {
  346. $pollarray['expiration'] = TIMESTAMP + 86400 * $expiration;
  347. }
  348. }
  349. $optid = '';
  350. $query = C::t('forum_polloption')->fetch_all_by_tid($_G['tid']);
  351. foreach($query as $tempoptid) {
  352. $optid[] = $tempoptid['polloptionid'];
  353. }
  354. foreach($pollarray['options'] as $key => $value) {
  355. $value = dhtmlspecialchars(trim($value));
  356. if(in_array($_GET['polloptionid'][$key], $optid)) {
  357. if($_G['group']['alloweditpoll']) {
  358. C::t('forum_polloption')->update_safe_tid($_GET['polloptionid'][$key], $_G['tid'], $pollarray['displayorder'][$key], $value);
  359. } else {
  360. C::t('forum_polloption')->update_safe_tid($_GET['polloptionid'][$key], $_G['tid'], $pollarray['displayorder'][$key]);
  361. }
  362. } else {
  363. C::t('forum_polloption')->insert(array('tid' => $_G['tid'], 'displayorder' => $pollarray['displayorder'][$key], 'polloption' => $value));
  364. }
  365. }
  366. $polloptionpreview = '';
  367. $query = C::t('forum_polloption')->fetch_all_by_tid($_G['tid'], 1, 2);
  368. foreach($query as $option) {
  369. $polloptvalue = preg_replace("/\[url=(https?){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/i", "<a href=\"\\1://\\2\" target=\"_blank\">\\3</a>", $option['polloption']);
  370. $polloptionpreview .= $polloptvalue."\t";
  371. }
  372. $polloptionpreview = daddslashes($polloptionpreview);
  373. $data = array('multiple' => $pollarray['multiple'], 'visible' => $pollarray['visible'], 'maxchoices' => $pollarray['maxchoices'], 'expiration' => $pollarray['expiration'], 'overt' => $pollarray['overt'], 'pollpreview' => $polloptionpreview);
  374. C::t('forum_poll')->update($_G['tid'], $data);
  375. } else {
  376. $threadupdatearr['special'] = 0;
  377. C::t('forum_poll')->delete($_G['tid']);
  378. C::t('forum_polloption')->delete_safe_tid($_G['tid']);
  379. }
  380. } elseif($thread['special'] == 3 && $isorigauthor) {
  381. $rewardprice = intval($_GET['rewardprice']);
  382. if($thread['price'] > 0 && $thread['price'] != $_GET['rewardprice']) {
  383. if($rewardprice <= 0){
  384. showmessage('reward_credits_invalid');
  385. }
  386. $addprice = ceil(($rewardprice - $thread['price']) + ($rewardprice - $thread['price']) * $_G['setting']['creditstax']);
  387. if($rewardprice < $thread['price']) {
  388. showmessage('reward_credits_fall');
  389. } elseif($rewardprice < $_G['group']['minrewardprice'] || ($_G['group']['maxrewardprice'] > 0 && $rewardprice > $_G['group']['maxrewardprice'])) {
  390. showmessage('reward_credits_between', '', array('minrewardprice' => $_G['group']['minrewardprice'], 'maxrewardprice' => $_G['group']['maxrewardprice']));
  391. } elseif($addprice > getuserprofile('extcredits'.$_G['setting']['creditstransextra'][2])) {
  392. showmessage('reward_credits_shortage');
  393. }
  394. $realprice = ceil($thread['price'] + $thread['price'] * $_G['setting']['creditstax']);
  395. updatemembercount($thread['authorid'], array($_G['setting']['creditstransextra'][2] => -$addprice));
  396. C::t('common_credit_log')->update_by_uid_operation_relatedid($thread['authorid'], 'RTC', $_G['tid'], array('extcredits'.$_G['setting']['creditstransextra'][2] => $realprice));
  397. }
  398. if(!$_G['forum']['ismoderator']) {
  399. if($thread['replies'] > 1) {
  400. $subject = addslashes($thread['subject']);
  401. }
  402. }
  403. $price = $rewardprice;
  404. } elseif($thread['special'] == 4 && $_G['group']['allowpostactivity']) {
  405. $activitytime = intval($_GET['activitytime']);
  406. if(empty($_GET['starttimefrom'][$activitytime])) {
  407. showmessage('activity_fromtime_please');
  408. } elseif(strtotime($_GET['starttimefrom'][$activitytime]) === -1 || @strtotime($_GET['starttimefrom'][$activitytime]) === FALSE) {
  409. showmessage('activity_fromtime_error');
  410. } elseif($activitytime && ((@strtotime($_GET['starttimefrom']) > @strtotime($_GET['starttimeto']) || !$_GET['starttimeto']))) {
  411. showmessage('activity_fromtime_error');
  412. } elseif(!trim($_GET['activityclass'])) {
  413. showmessage('activity_sort_please');
  414. } elseif(!trim($_GET['activityplace'])) {
  415. showmessage('activity_address_please');
  416. } elseif(trim($_GET['activityexpiration']) && (@strtotime($_GET['activityexpiration']) === -1 || @strtotime($_GET['activityexpiration']) === FALSE)) {
  417. showmessage('activity_totime_error');
  418. }
  419. $activity = array();
  420. $activity['class'] = censor(dhtmlspecialchars(trim($_GET['activityclass'])));
  421. $activity['starttimefrom'] = @strtotime($_GET['starttimefrom'][$activitytime]);
  422. $activity['starttimeto'] = $activitytime ? @strtotime($_GET['starttimeto']) : 0;
  423. $activity['place'] = censor(dhtmlspecialchars(trim($_GET['activityplace'])));
  424. $activity['cost'] = intval($_GET['cost']);
  425. $activity['gender'] = intval($_GET['gender']);
  426. $activity['number'] = intval($_GET['activitynumber']);
  427. if($_GET['activityexpiration']) {
  428. $activity['expiration'] = @strtotime($_GET['activityexpiration']);
  429. } else {
  430. $activity['expiration'] = 0;
  431. }
  432. $extfield = $_GET['extfield'];
  433. $extfield = explode("\n", $_GET['extfield']);
  434. foreach($extfield as $key => $value) {
  435. $extfield[$key] = censor(trim($value));
  436. if($extfield[$key] === '' || is_numeric($extfield[$key])) {
  437. unset($extfield[$key]);
  438. }
  439. }
  440. $extfield = array_unique($extfield);
  441. if(count($extfield) > $_G['setting']['activityextnum']) {
  442. showmessage('post_activity_extfield_toomany', '', array('maxextfield' => $_G['setting']['activityextnum']));
  443. }
  444. $activity['ufield'] = array('userfield' => $_GET['userfield'], 'extfield' => $extfield);
  445. $activity['ufield'] = serialize($activity['ufield']);
  446. if(intval($_GET['activitycredit']) > 0) {
  447. $activity['credit'] = intval($_GET['activitycredit']);
  448. }
  449. $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']);
  450. C::t('forum_activity')->update($_G['tid'], $data);
  451. } elseif($thread['special'] == 5 && $_G['group']['allowpostdebate']) {
  452. if(empty($_GET['affirmpoint']) || empty($_GET['negapoint'])) {
  453. showmessage('debate_position_nofound');
  454. } elseif(!empty($_GET['endtime']) && (!($endtime = @strtotime($_GET['endtime'])) || $endtime < TIMESTAMP)) {
  455. showmessage('debate_endtime_invalid');
  456. } elseif(!empty($_GET['umpire'])) {
  457. if(!C::t('common_member')->fetch_uid_by_username($_GET['umpire'])) {
  458. $_GET['umpire'] = dhtmlspecialchars($_GET['umpire']);
  459. showmessage('debate_umpire_invalid');
  460. }
  461. }
  462. $affirmpoint = censor(dhtmlspecialchars($_GET['affirmpoint']));
  463. $negapoint = censor(dhtmlspecialchars($_GET['negapoint']));
  464. C::t('forum_debate')->update($_G['tid'], array('affirmpoint' => $affirmpoint, 'negapoint' => $negapoint, 'endtime' => $endtime, 'umpire' => $_GET['umpire']));
  465. } elseif($specialextra) {
  466. @include_once DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  467. $classname = 'threadplugin_'.$specialextra;
  468. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'editpost_submit')) {
  469. $threadpluginclass->editpost_submit($_G['fid'], $_G['tid']);
  470. }
  471. }
  472. $_G['forum_optiondata'] = array();
  473. if($_G['forum']['threadsorts']['types'][$sortid] && $_G['forum_checkoption']) {
  474. $_G['forum_optiondata'] = threadsort_validator($_GET['typeoption'], $pid);
  475. }
  476. $threadimageaid = 0;
  477. $threadimage = array();
  478. if($_G['forum']['threadsorts']['types'][$sortid] && $_G['forum_optiondata'] && is_array($_G['forum_optiondata'])) {
  479. $sql = $separator = $filedname = $valuelist = '';
  480. foreach($_G['forum_optiondata'] as $optionid => $value) {
  481. $value = censor($value);
  482. if($_G['forum_optionlist'][$optionid]['type'] == 'image') {
  483. $identifier = $_G['forum_optionlist'][$optionid]['identifier'];
  484. $newsortaid = intval($_GET['typeoption'][$identifier]['aid']);
  485. if($newsortaid && $_GET['oldsortaid'][$identifier] && $newsortaid != $_GET['oldsortaid'][$identifier]) {
  486. $attach = C::t('forum_attachment_n')->fetch('tid:'.$_G['tid'], $_GET['oldsortaid'][$identifier]);
  487. C::t('forum_attachment')->delete($_GET['oldsortaid'][$identifier]);
  488. C::t('forum_attachment_n')->delete('tid:'.$_G['tid'], $_GET['oldsortaid'][$identifier]);
  489. dunlink($attach);
  490. $threadimageaid = $newsortaid;
  491. convertunusedattach($newsortaid, $_G['tid'], $pid);
  492. }
  493. }
  494. if($_G['forum_optionlist'][$optionid]['unchangeable']) {
  495. continue;
  496. }
  497. if(($_G['forum_optionlist'][$optionid]['search'] || in_array($_G['forum_optionlist'][$optionid]['type'], array('radio', 'select', 'number'))) && $value) {
  498. $filedname .= $separator.$_G['forum_optionlist'][$optionid]['identifier'];
  499. $valuelist .= $separator."'$value'";
  500. $sql .= $separator.$_G['forum_optionlist'][$optionid]['identifier']."='$value'";
  501. $separator = ' ,';
  502. }
  503. C::t('forum_typeoptionvar')->update_by_tid($_G['tid'], array('value' => $value, 'sortid' => $sortid), false, false, $optionid);
  504. }
  505. if($typeexpiration) {
  506. C::t('forum_typeoptionvar')->update_by_tid($_G['tid'], array('expiration' => (TIMESTAMP + $typeexpiration)), false, false, null, $sortid);
  507. }
  508. if($sql || ($filedname && $valuelist)) {
  509. if(C::t('forum_optionvalue')->fetch_all_tid($sortid, "WHERE tid='$_G[tid]'")) {
  510. if($sql) {
  511. C::t('forum_optionvalue')->update($sortid, $_G['tid'], $_G['fid'], $sql);
  512. }
  513. } elseif($filedname && $valuelist) {
  514. C::t('forum_optionvalue')->insert($sortid, "($filedname, tid, fid) VALUES ($valuelist, '$_G[tid]', '$_G[fid]')");
  515. }
  516. }
  517. }
  518. $thread['status'] = setstatus(4, $_GET['ordertype'], $thread['status']);
  519. $thread['status'] = setstatus(2, $_GET['hiddenreplies'], $thread['status']);
  520. $thread['status'] = setstatus(6, $_GET['allownoticeauthor'] ? 1 : 0, $thread['status']);
  521. $displayorder = empty($_GET['save']) ? ($thread['displayorder'] == -4 ? -4 : $thread['displayorder']) : -4;
  522. if($isorigauthor && $_G['group']['allowreplycredit']) {
  523. $_POST['replycredit_extcredits'] = intval($_POST['replycredit_extcredits']);
  524. $_POST['replycredit_times'] = intval($_POST['replycredit_times']);
  525. $_POST['replycredit_membertimes'] = intval($_POST['replycredit_membertimes']) > 0 ? intval($_POST['replycredit_membertimes']) : 1;
  526. $_POST['replycredit_random'] = intval($_POST['replycredit_random']) < 0 || intval($_POST['replycredit_random']) > 99 ? 0 : intval($_POST['replycredit_random']) ;
  527. if($_POST['replycredit_extcredits'] > 0 && $_POST['replycredit_times'] > 0) {
  528. $replycredit = $_POST['replycredit_extcredits'] * $_POST['replycredit_times'];
  529. $replycredit_diff = $replycredit - $thread['replycredit'];
  530. if($replycredit_diff > 0) {
  531. $replycredit_diff = ceil($replycredit_diff + ($replycredit_diff * $_G['setting']['creditstax']));
  532. if(!$replycredit_rule) {
  533. $replycredit_rule = array();
  534. if($_G['setting']['creditstransextra']['10']) {
  535. $replycredit_rule['extcreditstype'] = $_G['setting']['creditstransextra']['10'];
  536. }
  537. }
  538. if($replycredit_diff > getuserprofile('extcredits'.$replycredit_rule['extcreditstype'])) {
  539. showmessage('post_edit_thread_replaycredit_nocredit');
  540. }
  541. }
  542. if($replycredit_diff) {
  543. updatemembercount($_G['uid'], array($replycredit_rule['extcreditstype'] => ($replycredit_diff > 0 ? -$replycredit_diff : abs($replycredit_diff))), 1, ($replycredit_diff > 0 ? 'RCT' : 'RCB'), $_G['tid']);
  544. }
  545. } elseif(($_POST['replycredit_extcredits'] == 0 || $_POST['replycredit_times'] == 0) && $thread['replycredit'] > 0) {
  546. $replycredit = 0;
  547. C::t('forum_replycredit')->delete($_G['tid']);
  548. updatemembercount($thread['authorid'], array($replycredit_rule['extcreditstype'] => $thread['replycredit']), 1, 'RCB', $_G['tid']);
  549. $threadupdatearr['replycredit'] = 0;
  550. } else {
  551. $replycredit = $thread['replycredit'];
  552. }
  553. if($replycredit) {
  554. $threadupdatearr['replycredit'] = $replycredit;
  555. $replydata = array(
  556. 'tid' => $_G['tid'],
  557. 'extcredits' => $_POST['replycredit_extcredits'],
  558. 'extcreditstype' => $replycredit_rule['extcreditstype'],
  559. 'times' => $_POST['replycredit_times'],
  560. 'membertimes' => $_POST['replycredit_membertimes'],
  561. 'random' => $_POST['replycredit_random']
  562. );
  563. C::t('forum_replycredit')->insert($replydata, false, true);
  564. }
  565. }
  566. if($rushreply) {
  567. $_GET['rushreplyfrom'] = strtotime($_GET['rushreplyfrom']);
  568. $_GET['rushreplyto'] = strtotime($_GET['rushreplyto']);
  569. $_GET['rewardfloor'] = trim($_GET['rewardfloor']);
  570. $_GET['stopfloor'] = intval($_GET['stopfloor']);
  571. $_GET['creditlimit'] = $_GET['creditlimit'] == '' ? '-996' : intval($_GET['creditlimit']);
  572. if($_GET['rushreplyfrom'] > $_GET['rushreplyto'] && !empty($_GET['rushreplyto'])) {
  573. showmessage('post_rushreply_timewrong');
  574. }
  575. $maxposition = C::t('forum_post')->fetch_maxposition_by_tid($thread['posttableid'], $_G['tid']);
  576. if($thread['closed'] == 1 && ((!$_GET['rushreplyfrom'] && !$_GET['rushreplyto']) || ($_GET['rushreplyfrom'] < $_G['timestamp'] && $_GET['rushreplyto'] > $_G['timestamp']) || (!$_GET['rushreplyfrom'] && $_GET['rushreplyto'] > $_G['timestamp']) || ($_GET['stopfloor'] && $_GET['stopfloor'] > $maxposition) )) {
  577. $threadupdatearr['closed'] = 0;
  578. } elseif($thread['closed'] == 0 && (($_GET['rushreplyfrom'] && $_GET['rushreplyfrom'] > $_G['timestamp']) || ($_GET['rushreplyto'] && $_GET['rushreplyto'] && $_GET['rushreplyto'] < $_G['timestamp']) || ($_GET['stopfloor'] && $_GET['stopfloor'] <= $maxposition) )) {
  579. $threadupdatearr['closed'] = 1;
  580. }
  581. if(!empty($_GET['rewardfloor']) && !empty($_GET['stopfloor'])) {
  582. $floors = explode(',', $_GET['rewardfloor']);
  583. if(!empty($floors)) {
  584. foreach($floors AS $key => $floor) {
  585. if(strpos($floor, '*') === false) {
  586. if(intval($floor) == 0) {
  587. unset($floors[$key]);
  588. } elseif($floor > $_GET['stopfloor']) {
  589. unset($floors[$key]);
  590. }
  591. }
  592. }
  593. }
  594. $_GET['rewardfloor'] = implode(',', $floors);
  595. }
  596. $rushdata = array('stopfloor' => $_GET['stopfloor'], 'starttimefrom' => $_GET['rushreplyfrom'], 'starttimeto' => $_GET['rushreplyto'], 'rewardfloor' => $_GET['rewardfloor'], 'creditlimit' => $_GET['creditlimit']);
  597. C::t('forum_threadrush')->update($_G['tid'], $rushdata);
  598. }
  599. $threadupdatearr['typeid'] = $typeid;
  600. $threadupdatearr['sortid'] = $sortid;
  601. $threadupdatearr['subject'] = $subject;
  602. if($readperm !== 'ignore') {
  603. $threadupdatearr['readperm'] = $readperm;
  604. }
  605. $threadupdatearr['price'] = $price;
  606. $threadupdatearr['status'] = $thread['status'];
  607. if($_G['forum_auditstatuson'] && $audit == 1) {
  608. $threadupdatearr['displayorder'] = 0;
  609. $threadupdatearr['moderated'] = 1;
  610. } else {
  611. $threadupdatearr['displayorder'] = $displayorder;
  612. }
  613. C::t('forum_thread')->update($_G['tid'], $threadupdatearr, true);
  614. if($_G['tid'] > 1) {
  615. if($_G['thread']['closed'] > 1) {
  616. C::t('forum_thread')->update($_G['thread']['closed'], array('subject' => $subject), true);
  617. } elseif(empty($_G['thread']['isgroup'])) {
  618. $threadclosed = C::t('forum_threadclosed')->fetch($_G['tid']);
  619. if($threadclosed['redirect']) {
  620. C::t('forum_thread')->update($threadclosed['redirect'], array('subject' => $subject), true);
  621. }
  622. }
  623. }
  624. $class_tag = new tag();
  625. $tagstr = $class_tag->update_field($_GET['tags'], $_G['tid'], 'tid', $_G['thread']);
  626. } else {
  627. if($subject == '' && $message == '' && $thread['special'] != 2) {
  628. showmessage('post_sm_isnull');
  629. }
  630. }
  631. $htmlon = $_G['group']['allowhtml'] && !empty($_GET['htmlon']) ? 1 : 0;
  632. if($_G['setting']['editedby'] && (TIMESTAMP - $orig['dateline']) > 60 && $_G['adminid'] != 1) {
  633. $editor = $isanonymous && $isorigauthor ? lang('forum/misc', 'anonymous') : $_G['username'];
  634. $edittime = dgmdate(TIMESTAMP);
  635. $message = lang('forum/misc', $htmlon ? 'post_edithtml' : (!$_G['forum']['allowbbcode'] || $_GET['bbcodeoff'] ? 'post_editnobbcode' : 'post_edit'), array('editor' => $editor, 'edittime' => $edittime)) . $message;
  636. }
  637. if($_G['group']['allowat']) {
  638. $atlist = $atlist_tmp = $ateduids = array();
  639. $atnum = $maxselect = 0;
  640. foreach(C::t('home_notification')->fetch_all_by_authorid_fromid($_G['uid'], $_G['tid'], 'at') as $row) {
  641. $atnum ++;
  642. $ateduids[$row[uid]] = $row['uid'];
  643. }
  644. $maxselect = $_G['group']['allowat'] - $atnum;
  645. preg_match_all("/@([^\r\n]*?)\s/i", $message.' ', $atlist_tmp);
  646. $atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, $_G['group']['allowat']);
  647. if($maxselect > 0 && !empty($atlist_tmp)) {
  648. if(empty($_G['setting']['at_anyone'])) {
  649. foreach(C::t('home_follow')->fetch_all_by_uid_fusername($_G['uid'], $atlist_tmp) as $row) {
  650. if(!in_array($row['followuid'], $ateduids)) {
  651. $atlist[$row[followuid]] = $row['fusername'];
  652. }
  653. if(count($atlist) == $maxselect) {
  654. break;
  655. }
  656. }
  657. if(count($atlist) < $maxselect) {
  658. $query = C::t('home_friend')->fetch_all_by_uid_username($_G['uid'], $atlist_tmp);
  659. foreach($query as $row) {
  660. if(!in_array($row['followuid'], $ateduids)) {
  661. $atlist[$row[fuid]] = $row['fusername'];
  662. }
  663. }
  664. }
  665. } else {
  666. foreach(C::t('common_member')->fetch_all_by_username($atlist_tmp) as $row) {
  667. if(!in_array($row['uid'], $ateduids)) {
  668. $atlist[$row[uid]] = $row['username'];
  669. }
  670. if(count($atlist) == $maxselect) {
  671. break;
  672. }
  673. }
  674. }
  675. if($atlist) {
  676. foreach($atlist as $atuid => $atusername) {
  677. $atsearch[] = "/@$atusername /i";
  678. $atreplace[] = "[url=home.php?mod=space&uid=$atuid]@{$atusername}[/url] ";
  679. }
  680. $message = preg_replace($atsearch, $atreplace, $message.' ', 1);
  681. }
  682. }
  683. }
  684. $bbcodeoff = checkbbcodes($message, !empty($_GET['bbcodeoff']));
  685. $smileyoff = checksmilies($message, !empty($_GET['smileyoff']));
  686. $tagoff = $isfirstpost ? !empty($tagoff) : 0;
  687. $attachupdate = !empty($_GET['delattachop']) || ($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) && ($_GET['attachnew'] || $special == 2 && $_GET['tradeaid'] || $special == 4 && $_GET['activityaid'] || $isfirstpost && $sortid);
  688. if($attachupdate) {
  689. updateattach($thread['displayorder'] == -4 || $_G['forum_auditstatuson'], $_G['tid'], $pid, $_GET['attachnew'], $_GET['attachupdate'], $orig['authorid']);
  690. }
  691. if($special == 2 && $_G['group']['allowposttrade']) {
  692. if($trade = C::t('forum_trade')->fetch_goods($_G['tid'], $pid)) {
  693. $seller = empty($_GET['paymethod']) && $_GET['seller'] ? censor(dhtmlspecialchars(trim($_GET['seller']))) : '';
  694. $item_name = censor(dhtmlspecialchars(trim($_GET['item_name'])));
  695. $item_price = floatval($_GET['item_price']);
  696. $item_credit = intval($_GET['item_credit']);
  697. $item_locus = censor(dhtmlspecialchars(trim($_GET['item_locus'])));
  698. $item_number = intval($_GET['item_number']);
  699. $item_quality = intval($_GET['item_quality']);
  700. $item_transport = intval($_GET['item_transport']);
  701. $postage_mail = intval($_GET['postage_mail']);
  702. $postage_express = intval(trim($_GET['postage_express']));
  703. $postage_ems = intval($_GET['postage_ems']);
  704. $item_type = intval($_GET['item_type']);
  705. $item_costprice = floatval($_GET['item_costprice']);
  706. if(!trim($item_name)) {
  707. showmessage('trade_please_name');
  708. } elseif($_G['group']['maxtradeprice'] && $item_price > 0 && ($_G['group']['mintradeprice'] > $item_price || $_G['group']['maxtradeprice'] < $item_price)) {
  709. showmessage('trade_price_between', '', array('mintradeprice' => $_G['group']['mintradeprice'], 'maxtradeprice' => $_G['group']['maxtradeprice']));
  710. } elseif($_G['group']['maxtradeprice'] && $item_credit > 0 && ($_G['group']['mintradeprice'] > $item_credit || $_G['group']['maxtradeprice'] < $item_credit)) {
  711. showmessage('trade_credit_between', '', array('mintradeprice' => $_G['group']['mintradeprice'], 'maxtradeprice' => $_G['group']['maxtradeprice']));
  712. } elseif(!$_G['group']['maxtradeprice'] && $item_price > 0 && $_G['group']['mintradeprice'] > $item_price) {
  713. showmessage('trade_price_more_than', '', array('mintradeprice' => $_G['group']['mintradeprice']));
  714. } elseif(!$_G['group']['maxtradeprice'] && $item_credit > 0 && $_G['group']['mintradeprice'] > $item_credit) {
  715. showmessage('trade_credit_more_than', '', array('mintradeprice' => $_G['group']['mintradeprice']));
  716. } elseif($item_price <= 0 && $item_credit <= 0) {
  717. showmessage('trade_pricecredit_need');
  718. } elseif($item_number < 1) {
  719. showmessage('tread_please_number');
  720. }
  721. if($trade['aid'] && $_GET['tradeaid'] && $trade['aid'] != $_GET['tradeaid']) {
  722. $attach = C::t('forum_attachment_n')->fetch('tid:'.$_G['tid'], $trade['aid']);
  723. C::t('forum_attachment')->delete($trade['aid']);
  724. C::t('forum_attachment_n')->delete('tid:'.$_G['tid'], $trade['aid']);
  725. dunlink($attach);
  726. $threadimageaid = $_GET['tradeaid'];
  727. convertunusedattach($_GET['tradeaid'], $_G['tid'], $pid);
  728. }
  729. $expiration = $_GET['item_expiration'] ? @strtotime($_GET['item_expiration']) : 0;
  730. $closed = $expiration > 0 && @strtotime($_GET['item_expiration']) < TIMESTAMP ? 1 : $closed;
  731. switch($_GET['transport']) {
  732. case 'seller':$item_transport = 1;break;
  733. case 'buyer':$item_transport = 2;break;
  734. case 'virtual':$item_transport = 3;break;
  735. case 'logistics':$item_transport = 4;break;
  736. }
  737. if(!$item_price || $item_price <= 0) {
  738. $item_price = $postage_mail = $postage_express = $postage_ems = '';
  739. }
  740. $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']);
  741. C::t('forum_trade')->update($_G['tid'], $pid, $data);
  742. if(!empty($_GET['infloat'])) {
  743. $viewpid = C::t('forum_post')->fetch_threadpost_by_tid_invisible($_G['tid']);
  744. $viewpid = $viewpid['pid'];
  745. $redirecturl = "forum.php?mod=viewthread&tid=$_G[tid]&viewpid=$viewpid#pid$viewpid";
  746. } else {
  747. $redirecturl = "forum.php?mod=viewthread&do=tradeinfo&tid=$_G[tid]&pid=$pid";
  748. }
  749. }
  750. }
  751. if($special == 4 && $isfirstpost && $_G['group']['allowpostactivity']) {
  752. $activity = C::t('forum_activity')->fetch($_G['tid']);
  753. $activityaid = $activity['aid'];
  754. if($activityaid && $activityaid != $_GET['activityaid']) {
  755. $attach = C::t('forum_attachment_n')->fetch('tid:'.$_G['tid'], $activityaid);
  756. C::t('forum_attachment')->delete($activityaid);
  757. C::t('forum_attachment_n')->delete('tid:'.$_G['tid'], $activityaid);
  758. dunlink($attach);
  759. }
  760. if($_GET['activityaid']) {
  761. $threadimageaid = $_GET['activityaid'];
  762. convertunusedattach($_GET['activityaid'], $_G['tid'], $pid);
  763. C::t('forum_activity')->update($_G['tid'], array('aid' => $_GET['activityaid']));
  764. }
  765. }
  766. if($isfirstpost && $attachupdate) {
  767. if(!$threadimageaid) {
  768. $threadimage = C::t('forum_attachment_n')->fetch_max_image('tid:'.$_G['tid'], 'pid', $pid);
  769. $threadimageaid = $threadimage['aid'];
  770. }
  771. if($_G['forum']['picstyle']) {
  772. if(empty($thread['cover'])) {
  773. setthreadcover($pid, 0, $threadimageaid);
  774. } else {
  775. setthreadcover($pid, $_G['tid'], 0, 1);
  776. }
  777. }
  778. if($threadimageaid) {
  779. if(!$threadimage) {
  780. $threadimage = C::t('forum_attachment_n')->fetch_max_image('tid:'.$_G['tid'], 'tid', $_G['tid']);
  781. }
  782. C::t('forum_threadimage')->delete_by_tid($_G['tid']);
  783. C::t('forum_threadimage')->insert(array(
  784. 'tid' => $_G['tid'],
  785. 'attachment' => $threadimage['attachment'],
  786. 'remote' => $threadimage['remote'],
  787. ));
  788. }
  789. }
  790. $feed = array();
  791. if($special == 127) {
  792. $message .= chr(0).chr(0).chr(0).$specialextra;
  793. }
  794. if($_G['forum_auditstatuson'] && $audit == 1) {
  795. C::t('forum_post')->update($thread['posttableid'], $pid, array('status' => 4), false, false, null, -2, null, 0);
  796. updatepostcredits('+', $orig['authorid'], ($isfirstpost ? 'post' : 'reply'), $_G['fid']);
  797. updatemodworks('MOD', 1);
  798. updatemodlog($_G['tid'], 'MOD');
  799. }
  800. $displayorder = $pinvisible = 0;
  801. if($isfirstpost) {
  802. $displayorder = $modnewthreads ? -2 : $thread['displayorder'];
  803. $pinvisible = $modnewthreads ? -2 : (empty($_GET['save']) ? 0 : -3);
  804. } else {
  805. $pinvisible = $modnewreplies ? -2 : ($thread['displayorder'] == -4 ? -3 : 0);
  806. }
  807. $message = preg_replace('/\[attachimg\](\d+)\[\/attachimg\]/is', '[attach]\1[/attach]', $message);
  808. $parseurloff = !empty($_GET['parseurloff']);
  809. $setarr = array(
  810. 'message' => $message,
  811. 'usesig' => $_GET['usesig'],
  812. 'htmlon' => $htmlon,
  813. 'bbcodeoff' => $bbcodeoff,
  814. 'parseurloff' => $parseurloff,
  815. 'smileyoff' => $smileyoff,
  816. 'subject' => $subject,
  817. 'tags' => $tagstr
  818. );
  819. if($anonymousadd !== '') {
  820. $setarr['anonymous'] = $anonymousadd;
  821. }
  822. if($publishdate) {
  823. $setarr['dateline'] = $publishdate;
  824. }
  825. if($_G['forum_auditstatuson'] && $audit == 1) {
  826. $setarr['invisible'] = 0;
  827. } else {
  828. $setarr['invisible'] = $pinvisible;
  829. }
  830. C::t('forum_post')->update('tid:'.$_G['tid'], $pid, $setarr);
  831. if($_G['group']['allowat'] && $atlist) {
  832. foreach($atlist as $atuid => $atusername) {
  833. notification_add($atuid, 'at', 'at_message', array('from_id' => $_G['tid'], 'from_idtype' => 'at', 'buyerid' => $_G['uid'], 'buyer' => $_G['username'], 'tid' => $_G['tid'], 'subject' => $thread['subject'], 'pid' => $pid, 'message' => messagecutstr($message, 150)));
  834. }
  835. set_atlist_cookie(array_keys($atlist));
  836. }
  837. $_G['forum']['lastpost'] = explode("\t", $_G['forum']['lastpost']);
  838. if($orig['dateline'] == $_G['forum']['lastpost'][2] && ($orig['author'] == $_G['forum']['lastpost'][3] || ($_G['forum']['lastpost'][3] == '' && $orig['anonymous']))) {
  839. $lastpost = "$_G[tid]\t".($isfirstpost ? $subject : $thread['subject'])."\t$orig[dateline]\t".($isanonymous ? '' : $orig['author']);
  840. C::t('forum_forum')->update($_G['fid'], array('lastpost' => $lastpost));
  841. }
  842. if(!$_G['forum_auditstatuson'] || $audit != 1) {
  843. if($isfirstpost && $modnewthreads) {
  844. C::t('forum_thread')->update($_G['tid'], array('displayorder' => -2));
  845. manage_addnotify('verifythread');
  846. } elseif(!$isfirstpost && $modnewreplies) {
  847. C::t('forum_thread')->increase($_G['tid'], array('replies' => -1));
  848. manage_addnotify('verifypost');
  849. }
  850. if($modnewreplies || $modnewthreads) {
  851. C::t('forum_forum')->update($_G['fid'], array('modworks' => '1'));
  852. }
  853. }
  854. if($isfirstpost) {
  855. require_once libfile('function/discuzcode');
  856. require_once libfile('function/followcode');
  857. $feed = C::t('forum_threadpreview')->fetch($_G['tid']);
  858. if($feed) {
  859. C::t('forum_threadpreview')->update($_G['tid'], array('content' => followcode($message, $_G['tid'], $pid, 1000)));
  860. }
  861. }
  862. if($thread['lastpost'] == $orig['dateline'] && ((!$orig['anonymous'] && $thread['lastposter'] == $orig['author']) || ($orig['anonymous'] && $thread['lastposter'] == '')) && $orig['anonymous'] != $isanonymous) {
  863. C::t('forum_thread')->update($_G['tid'], array('lastposter' => $isanonymous ? '' : $orig['author']), true);
  864. }
  865. if(!$isorigauthor) {
  866. updatemodworks('EDT', 1);
  867. require_once libfile('function/misc');
  868. modlog($thread, 'EDT');
  869. }
  870. if($isfirstpost && $thread['displayorder'] == -4 && empty($_GET['save'])) {
  871. threadpubsave($thread['tid']);
  872. }
  873. } else {
  874. if(!$_G['setting']['editperdel']) {
  875. showmessage('post_edit_thread_ban_del', NULL);
  876. }
  877. if($isfirstpost && $thread['replies'] > 0) {
  878. showmessage(($thread['special'] == 3 ? 'post_edit_reward_already_reply' : 'post_edit_thread_already_reply'), NULL);
  879. }
  880. if($thread['special'] == 3) {
  881. if($thread['price'] < 0 && ($thread['dateline'] + 1 == $orig['dateline'])) {
  882. showmessage('post_edit_reward_nopermission', NULL);
  883. }
  884. }
  885. if($rushreply) {
  886. showmessage('post_edit_delete_rushreply_nopermission', NULL);
  887. }
  888. if($thread['displayorder'] >= 0) {
  889. updatepostcredits('-', $orig['authorid'], ($isfirstpost ? 'post' : 'reply'), $_G['fid']);
  890. }
  891. if($thread['special'] == 3 && $isfirstpost) {
  892. updatemembercount($orig['authorid'], array($_G['setting']['creditstransextra'][2] => $thread['price']));
  893. C::t('common_credit_log')->delete_by_uid_operation_relatedid($thread['authorid'], 'RTC', $_G['tid']);
  894. }
  895. if($thread['replycredit'] && $isfirstpost && !$isanonymous) {
  896. updatemembercount($orig['authorid'], array($replycredit_rule['extcreditstype'] => $thread['replycredit']), true, 'RCB', $_G['tid']);
  897. C::t('forum_replycredit')->delete($_G['tid']);
  898. } elseif (!$isfirstpost && !$isanonymous) {
  899. $postreplycredit = C::t('forum_post')->fetch('tid:'.$_G['tid'], $pid);
  900. $postreplycredit = $postreplycredit['replycredit'];
  901. if($postreplycredit) {
  902. C::t('forum_post')->update('tid:'.$_G['tid'], $pid, array('replycredit' => 0));
  903. updatemembercount($orig['authorid'], array($replycredit_rule['extcreditstype'] => '-'.$postreplycredit));
  904. }
  905. }
  906. $thread_attachment = $post_attachment = 0;
  907. foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$_G['tid'], 'tid', $_G['tid']) as $attach) {
  908. if($attach['pid'] == $pid) {
  909. if($thread['displayorder'] >= 0) {
  910. $post_attachment++;
  911. }
  912. dunlink($attach);
  913. } else {
  914. $thread_attachment = 1;
  915. }
  916. }
  917. if($post_attachment) {
  918. C::t('forum_attachment')->delete_by_id('pid', $pid);
  919. DB::query("DELETE FROM ".DB::table(getattachtablebytid($_G['tid']))." WHERE pid='$pid'", 'UNBUFFEREED');
  920. updatecreditbyaction('postattach', $orig['authorid'], array(), '', -$post_attachment);
  921. }
  922. C::t('forum_post')->delete('tid:'.$_G['tid'], $pid);
  923. C::t('forum_postcomment')->delete_by_rpid($pid);
  924. if($thread['special'] == 2) {
  925. C::t('forum_trade')->delete_by_id_idtype($pid, 'pid');
  926. }
  927. $forumcounter = array();
  928. if($isfirstpost) {
  929. $forumcounter['threads'] = $forumcounter['posts'] = -1;
  930. $tablearray = array('forum_relatedthread', 'forum_debate', 'forum_debatepost', 'forum_polloption', 'forum_poll');
  931. foreach ($tablearray as $table) {
  932. DB::query("DELETE FROM ".DB::table($table)." WHERE tid='$_G[tid]'", 'UNBUFFERED');
  933. }
  934. C::t('forum_thread')->delete_by_tid($_G['tid']);
  935. C::t('common_moderate')->delete($_G['tid'], 'tid');
  936. C::t('forum_threadmod')->delete_by_tid($_G['tid']);
  937. C::t('forum_typeoptionvar')->delete_by_tid($_G['tid']);
  938. if($_G['setting']['globalstick'] && in_array($thread['displayorder'], array(2, 3))) {
  939. require_once libfile('function/cache');
  940. updatecache('globalstick');
  941. }
  942. } else {
  943. $forumcounter['posts'] = -1;
  944. $lastpost = C::t('forum_post')->fetch_visiblepost_by_tid('tid:'.$_G['tid'], $_G['tid'], 0, 1);
  945. $lastpost['author'] = !$lastpost['anonymous'] ? addslashes($lastpost['author']) : '';
  946. $updatefieldarr = array(
  947. 'replies' => -1,
  948. 'attachment' => array($thread_attachment),
  949. 'lastposter' => array($lastpost['author']),
  950. 'lastpost' => array($lastpost['dateline'])
  951. );
  952. C::t('forum_thread')->increase($_G['tid'], $updatefieldarr);
  953. }
  954. $_G['forum']['lastpost'] = explode("\t", $_G['forum']['lastpost']);
  955. if($orig['dateline'] == $_G['forum']['lastpost'][2] && ($orig['author'] == $_G['forum']['lastpost'][3] || ($_G['forum']['lastpost'][3] == '' && $orig['anonymous']))) {
  956. $lastthread = C::t('forum_thread')->fetch_by_fid_displayorder($_G['fid']);
  957. C::t('forum_forum')->update($_G['fid'], array('lastpost' => "$lastthread[tid]\t$lastthread[subject]\t$lastthread[lastpost]\t$lastthread[lastposter]"));
  958. }
  959. C::t('forum_forum')->update_forum_counter($_G['fid'], $forumcounter['threads'], $forumcounter['posts']);
  960. }
  961. if($specialextra) {
  962. @include_once DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  963. $classname = 'threadplugin_'.$specialextra;
  964. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'editpost_submit_end')) {
  965. $threadpluginclass->editpost_submit_end($_G['fid'], $_G['tid']);
  966. }
  967. }
  968. if($_G['forum']['threadcaches']) {
  969. deletethreadcaches($_G['tid']);
  970. }
  971. $param = array('fid' => $_G['fid'], 'tid' => $_G['tid'], 'pid' => $pid);
  972. dsetcookie('clearUserdata', 'forum');
  973. if($_G['forum_auditstatuson']) {
  974. if($audit == 1) {
  975. updatemoderate($isfirstpost ? 'tid' : 'pid', $isfirstpost ? $_G['tid'] : $pid, '2');
  976. showmessage('auditstatuson_succeed', $redirecturl, $param);
  977. } else {
  978. updatemoderate($isfirstpost ? 'tid' : 'pid', $isfirstpost ? $_G['tid'] : $pid);
  979. showmessage('audit_edit_succeed', '', $param, array('alert' => 'right'));
  980. }
  981. } else {
  982. if(!empty($_GET['delete']) && $isfirstpost) {
  983. showmessage('post_edit_delete_succeed', "forum.php?mod=forumdisplay&fid=$…

Large files files are truncated, but you can click here to view the full file