PageRenderTime 54ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/source/include/post/post_newthread.php

https://github.com/kuaileshike/upload
PHP | 807 lines | 701 code | 100 blank | 6 comment | 261 complexity | 459311447afc1e339a1fcd7e28f06cfa MD5 | raw 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_newthread.php 31151 2012-07-19 08:23:40Z liulanbo $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if(empty($_G['forum']['fid']) || $_G['forum']['type'] == 'group') {
  12. showmessage('forum_nonexistence');
  13. }
  14. if(($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'])) {
  15. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  16. }
  17. if(!$_G['uid'] && !((!$_G['forum']['postperm'] && $_G['group']['allowpost']) || ($_G['forum']['postperm'] && forumperm($_G['forum']['postperm'])))) {
  18. if(!defined('IN_MOBILE')) {
  19. showmessage('postperm_login_nopermission', NULL, array(), array('login' => 1));
  20. } else {
  21. showmessage('postperm_login_nopermission_mobile', NULL, array('referer' => rawurlencode(dreferer())), array('login' => 1));
  22. }
  23. } elseif(empty($_G['forum']['allowpost'])) {
  24. if(!$_G['forum']['postperm'] && !$_G['group']['allowpost']) {
  25. showmessage('postperm_none_nopermission', NULL, array(), array('login' => 1));
  26. } elseif($_G['forum']['postperm'] && !forumperm($_G['forum']['postperm'])) {
  27. showmessagenoperm('postperm', $_G['fid'], $_G['forum']['formulaperm']);
  28. }
  29. } elseif($_G['forum']['allowpost'] == -1) {
  30. showmessage('post_forum_newthread_nopermission', NULL);
  31. }
  32. if(!$_G['uid'] && ($_G['setting']['need_avatar'] || $_G['setting']['need_email'] || $_G['setting']['need_friendnum'])) {
  33. showmessage('postperm_login_nopermission', NULL, array(), array('login' => 1));
  34. }
  35. checklowerlimit('post', 0, 1, $_G['forum']['fid']);
  36. if(!submitcheck('topicsubmit', 0, $seccodecheck, $secqaacheck)) {
  37. $savethreads = array();
  38. $savethreadothers = array();
  39. foreach(C::t('forum_post')->fetch_all_by_authorid(0, $_G['uid'], false, '', 0, 20, 1, -3) as $savethread) {
  40. $savethread['dateline'] = dgmdate($savethread['dateline'], 'u');
  41. if($_G['fid'] == $savethread['fid']) {
  42. $savethreads[] = $savethread;
  43. } else {
  44. $savethreadothers[] = $savethread;
  45. }
  46. }
  47. $savethreadcount = count($savethreads);
  48. $savethreadothercount = count($savethreadothers);
  49. if($savethreadothercount) {
  50. loadcache('forums');
  51. }
  52. $savecount = $savethreadcount + $savethreadothercount;
  53. unset($savethread);
  54. $isfirstpost = 1;
  55. $allownoticeauthor = 1;
  56. $tagoffcheck = '';
  57. $showthreadsorts = !empty($sortid) || $_G['forum']['threadsorts']['required'] && empty($special);
  58. if(empty($sortid) && empty($special) && $_G['forum']['threadsorts']['required'] && $_G['forum']['threadsorts']['types']) {
  59. $tmp = array_keys($_G['forum']['threadsorts']['types']);
  60. $sortid = $tmp[0];
  61. require_once libfile('post/threadsorts', 'include');
  62. }
  63. if($special == 2 && $_G['group']['allowposttrade']) {
  64. $expiration_7days = date('Y-m-d', TIMESTAMP + 86400 * 7);
  65. $expiration_14days = date('Y-m-d', TIMESTAMP + 86400 * 14);
  66. $trade['expiration'] = $expiration_month = date('Y-m-d', mktime(0, 0, 0, date('m')+1, date('d'), date('Y')));
  67. $expiration_3months = date('Y-m-d', mktime(0, 0, 0, date('m')+3, date('d'), date('Y')));
  68. $expiration_halfyear = date('Y-m-d', mktime(0, 0, 0, date('m')+6, date('d'), date('Y')));
  69. $expiration_year = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')+1));
  70. } elseif($specialextra) {
  71. $threadpluginclass = null;
  72. if(isset($_G['setting']['threadplugins'][$specialextra]['module'])) {
  73. $threadpluginfile = DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  74. if(file_exists($threadpluginfile)) {
  75. @include_once $threadpluginfile;
  76. $classname = 'threadplugin_'.$specialextra;
  77. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newthread')) {
  78. $threadplughtml = $threadpluginclass->newthread($_G['fid']);
  79. $buttontext = lang('plugin/'.$specialextra, $threadpluginclass->buttontext);
  80. $iconfile = $threadpluginclass->iconfile;
  81. $iconsflip = array_flip($_G['cache']['icons']);
  82. $thread['iconid'] = $iconsflip[$iconfile];
  83. }
  84. }
  85. }
  86. if(!is_object($threadpluginclass)) {
  87. $specialextra = '';
  88. }
  89. }
  90. if($special == 4) {
  91. $activity = array('starttimeto' => '', 'starttimefrom' => '', 'place' => '', 'class' => '', 'cost' => '', 'number' => '', 'gender' => '', 'expiration' => '');
  92. $activitytypelist = $_G['setting']['activitytype'] ? explode("\n", trim($_G['setting']['activitytype'])) : '';
  93. }
  94. if($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) {
  95. $attachlist = getattach(0);
  96. $attachs = $attachlist['attachs'];
  97. $imgattachs = $attachlist['imgattachs'];
  98. unset($attachlist);
  99. }
  100. !isset($attachs['unused']) && $attachs['unused'] = array();
  101. !isset($imgattachs['unused']) && $imgattachs['unused'] = array();
  102. getgpc('infloat') ? include template('forum/post_infloat') : include template('forum/post');
  103. } else {
  104. if(trim($subject) == '') {
  105. showmessage('post_sm_isnull');
  106. }
  107. if(!$sortid && !$special && trim($message) == '') {
  108. showmessage('post_sm_isnull');
  109. }
  110. if($post_invalid = checkpost($subject, $message, ($special || $sortid))) {
  111. showmessage($post_invalid, '', array('minpostsize' => $_G['setting']['minpostsize'], 'maxpostsize' => $_G['setting']['maxpostsize']));
  112. }
  113. if(checkflood()) {
  114. showmessage('post_flood_ctrl', '', array('floodctrl' => $_G['setting']['floodctrl']));
  115. } elseif(checkmaxperhour('tid')) {
  116. showmessage('thread_flood_ctrl_threads_per_hour', '', array('threads_per_hour' => $_G['group']['maxthreadsperhour']));
  117. }
  118. $_GET['save'] = $_G['uid'] ? $_GET['save'] : 0;
  119. if ($_G['group']['allowsetpublishdate'] && $_GET['cronpublish'] && $_GET['cronpublishdate']) {
  120. $publishdate = strtotime($_GET['cronpublishdate']);
  121. if ($publishdate > $_G['timestamp']) {
  122. $_GET['save'] = 1;
  123. } else {
  124. $publishdate = $_G['timestamp'];
  125. }
  126. } else {
  127. $publishdate = $_G['timestamp'];
  128. }
  129. $typeid = isset($typeid) && isset($_G['forum']['threadtypes']['types'][$typeid]) && (empty($_G['forum']['threadtypes']['moderators'][$typeid]) || $_G['forum']['ismoderator']) ? $typeid : 0;
  130. $displayorder = $modnewthreads ? -2 : (($_G['forum']['ismoderator'] && $_G['group']['allowstickthread'] && !empty($_GET['sticktopic'])) ? 1 : (empty($_GET['save']) ? 0 : -4));
  131. if($displayorder == -2) {
  132. C::t('forum_forum')->update($_G['fid'], array('modworks' => '1'));
  133. } elseif($displayorder == -4) {
  134. $_GET['addfeed'] = 0;
  135. }
  136. $digest = $_G['forum']['ismoderator'] && $_G['group']['allowdigestthread'] && !empty($_GET['addtodigest']) ? 1 : 0;
  137. $readperm = $_G['group']['allowsetreadperm'] ? $readperm : 0;
  138. $isanonymous = $_G['group']['allowanonymous'] && $_GET['isanonymous'] ? 1 : 0;
  139. $price = intval($price);
  140. $price = $_G['group']['maxprice'] && !$special ? ($price <= $_G['group']['maxprice'] ? $price : $_G['group']['maxprice']) : 0;
  141. if(!$typeid && $_G['forum']['threadtypes']['required'] && !$special) {
  142. showmessage('post_type_isnull');
  143. }
  144. if(!$sortid && $_G['forum']['threadsorts']['required'] && !$special) {
  145. showmessage('post_sort_isnull');
  146. }
  147. if($price > 0 && floor($price * (1 - $_G['setting']['creditstax'])) == 0) {
  148. showmessage('post_net_price_iszero');
  149. }
  150. if($special == 1) {
  151. $polloption = $_GET['tpolloption'] == 2 ? explode("\n", $_GET['polloptions']) : $_GET['polloption'];
  152. $pollarray = array();
  153. foreach($polloption as $key => $value) {
  154. $polloption[$key] = censor($polloption[$key]);
  155. if(trim($value) === '') {
  156. unset($polloption[$key]);
  157. }
  158. }
  159. if(count($polloption) > $_G['setting']['maxpolloptions']) {
  160. showmessage('post_poll_option_toomany', '', array('maxpolloptions' => $_G['setting']['maxpolloptions']));
  161. } elseif(count($polloption) < 2) {
  162. showmessage('post_poll_inputmore');
  163. }
  164. $curpolloption = count($polloption);
  165. $pollarray['maxchoices'] = empty($_GET['maxchoices']) ? 0 : ($_GET['maxchoices'] > $curpolloption ? $curpolloption : $_GET['maxchoices']);
  166. $pollarray['multiple'] = empty($_GET['maxchoices']) || $_GET['maxchoices'] == 1 ? 0 : 1;
  167. $pollarray['options'] = $polloption;
  168. $pollarray['visible'] = empty($_GET['visibilitypoll']);
  169. $pollarray['overt'] = !empty($_GET['overt']);
  170. if(preg_match("/^\d*$/", trim($_GET['expiration']))) {
  171. if(empty($_GET['expiration'])) {
  172. $pollarray['expiration'] = 0;
  173. } else {
  174. $pollarray['expiration'] = TIMESTAMP + 86400 * $_GET['expiration'];
  175. }
  176. } else {
  177. showmessage('poll_maxchoices_expiration_invalid');
  178. }
  179. } elseif($special == 3) {
  180. $rewardprice = intval($_GET['rewardprice']);
  181. if($rewardprice < 1) {
  182. showmessage('reward_credits_please');
  183. } elseif($rewardprice > 32767) {
  184. showmessage('reward_credits_overflow');
  185. } elseif($rewardprice < $_G['group']['minrewardprice'] || ($_G['group']['maxrewardprice'] > 0 && $rewardprice > $_G['group']['maxrewardprice'])) {
  186. if($_G['group']['maxrewardprice'] > 0) {
  187. showmessage('reward_credits_between', '', array('minrewardprice' => $_G['group']['minrewardprice'], 'maxrewardprice' => $_G['group']['maxrewardprice']));
  188. } else {
  189. showmessage('reward_credits_lower', '', array('minrewardprice' => $_G['group']['minrewardprice']));
  190. }
  191. } elseif(($realprice = $rewardprice + ceil($rewardprice * $_G['setting']['creditstax'])) > getuserprofile('extcredits'.$_G['setting']['creditstransextra'][2])) {
  192. showmessage('reward_credits_shortage');
  193. }
  194. $price = $rewardprice;
  195. } elseif($special == 4) {
  196. $activitytime = intval($_GET['activitytime']);
  197. if(empty($_GET['starttimefrom'][$activitytime])) {
  198. showmessage('activity_fromtime_please');
  199. } elseif(@strtotime($_GET['starttimefrom'][$activitytime]) === -1 || @strtotime($_GET['starttimefrom'][$activitytime]) === FALSE) {
  200. showmessage('activity_fromtime_error');
  201. } elseif($activitytime && ((@strtotime($_GET['starttimefrom']) > @strtotime($_GET['starttimeto']) || !$_GET['starttimeto']))) {
  202. showmessage('activity_fromtime_error');
  203. } elseif(!trim($_GET['activityclass'])) {
  204. showmessage('activity_sort_please');
  205. } elseif(!trim($_GET['activityplace'])) {
  206. showmessage('activity_address_please');
  207. } elseif(trim($_GET['activityexpiration']) && (@strtotime($_GET['activityexpiration']) === -1 || @strtotime($_GET['activityexpiration']) === FALSE)) {
  208. showmessage('activity_totime_error');
  209. }
  210. $activity = array();
  211. $activity['class'] = censor(dhtmlspecialchars(trim($_GET['activityclass'])));
  212. $activity['starttimefrom'] = @strtotime($_GET['starttimefrom'][$activitytime]);
  213. $activity['starttimeto'] = $activitytime ? @strtotime($_GET['starttimeto']) : 0;
  214. $activity['place'] = censor(dhtmlspecialchars(trim($_GET['activityplace'])));
  215. $activity['cost'] = intval($_GET['cost']);
  216. $activity['gender'] = intval($_GET['gender']);
  217. $activity['number'] = intval($_GET['activitynumber']);
  218. if($_GET['activityexpiration']) {
  219. $activity['expiration'] = @strtotime($_GET['activityexpiration']);
  220. } else {
  221. $activity['expiration'] = 0;
  222. }
  223. if(trim($_GET['activitycity'])) {
  224. $subject .= '['.dhtmlspecialchars(trim($_GET['activitycity'])).']';
  225. }
  226. $extfield = $_GET['extfield'];
  227. $extfield = explode("\n", $_GET['extfield']);
  228. foreach($extfield as $key => $value) {
  229. $extfield[$key] = censor(trim($value));
  230. if($extfield[$key] === '' || is_numeric($extfield[$key])) {
  231. unset($extfield[$key]);
  232. }
  233. }
  234. $extfield = array_unique($extfield);
  235. if(count($extfield) > $_G['setting']['activityextnum']) {
  236. showmessage('post_activity_extfield_toomany', '', array('maxextfield' => $_G['setting']['activityextnum']));
  237. }
  238. $activity['ufield'] = array('userfield' => $_GET['userfield'], 'extfield' => $extfield);
  239. $activity['ufield'] = serialize($activity['ufield']);
  240. if(intval($_GET['activitycredit']) > 0) {
  241. $activity['credit'] = intval($_GET['activitycredit']);
  242. }
  243. } elseif($special == 5) {
  244. if(empty($_GET['affirmpoint']) || empty($_GET['negapoint'])) {
  245. showmessage('debate_position_nofound');
  246. } elseif(!empty($_GET['endtime']) && (!($endtime = @strtotime($_GET['endtime'])) || $endtime < TIMESTAMP)) {
  247. showmessage('debate_endtime_invalid');
  248. } elseif(!empty($_GET['umpire'])) {
  249. if(!C::t('common_member')->fetch_uid_by_username($_GET['umpire'])) {
  250. $_GET['umpire'] = dhtmlspecialchars($_GET['umpire']);
  251. showmessage('debate_umpire_invalid', '', array('umpire' => $umpire));
  252. }
  253. }
  254. $affirmpoint = censor(dhtmlspecialchars($_GET['affirmpoint']));
  255. $negapoint = censor(dhtmlspecialchars($_GET['negapoint']));
  256. $stand = censor(intval($_GET['stand']));
  257. } elseif($specialextra) {
  258. @include_once DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  259. $classname = 'threadplugin_'.$specialextra;
  260. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newthread_submit')) {
  261. $threadpluginclass->newthread_submit($_G['fid']);
  262. }
  263. $special = 127;
  264. }
  265. $sortid = $special && $_G['forum']['threadsorts']['types'][$sortid] ? 0 : $sortid;
  266. $typeexpiration = intval($_GET['typeexpiration']);
  267. if($_G['forum']['threadsorts']['expiration'][$typeid] && !$typeexpiration) {
  268. showmessage('threadtype_expiration_invalid');
  269. }
  270. $_G['forum_optiondata'] = array();
  271. if($_G['forum']['threadsorts']['types'][$sortid] && !$_G['forum']['allowspecialonly']) {
  272. $_G['forum_optiondata'] = threadsort_validator($_GET['typeoption'], $pid);
  273. }
  274. $author = !$isanonymous ? $_G['username'] : '';
  275. $moderated = $digest || $displayorder > 0 ? 1 : 0;
  276. $thread['status'] = 0;
  277. $_GET['ordertype'] && $thread['status'] = setstatus(4, 1, $thread['status']);
  278. $_GET['hiddenreplies'] && $thread['status'] = setstatus(2, 1, $thread['status']);
  279. if($_G['group']['allowpostrushreply'] && $_GET['rushreply']) {
  280. $_GET['rushreplyfrom'] = strtotime($_GET['rushreplyfrom']);
  281. $_GET['rushreplyto'] = strtotime($_GET['rushreplyto']);
  282. $_GET['rewardfloor'] = trim($_GET['rewardfloor']);
  283. $_GET['stopfloor'] = intval($_GET['stopfloor']);
  284. $_GET['creditlimit'] = $_GET['creditlimit'] == '' ? '-996' : intval($_GET['creditlimit']);
  285. if($_GET['rushreplyfrom'] > $_GET['rushreplyto'] && !empty($_GET['rushreplyto'])) {
  286. showmessage('post_rushreply_timewrong');
  287. }
  288. if(($_GET['rushreplyfrom'] > $_G['timestamp']) || (!empty($_GET['rushreplyto']) && $_GET['rushreplyto'] < $_G['timestamp']) || ($_GET['stopfloor'] == 1) ) {
  289. $closed = true;
  290. }
  291. if(!empty($_GET['rewardfloor']) && !empty($_GET['stopfloor'])) {
  292. $floors = explode(',', $_GET['rewardfloor']);
  293. if(!empty($floors) && is_array($floors)) {
  294. foreach($floors AS $key => $floor) {
  295. if(strpos($floor, '*') === false) {
  296. if(intval($floor) == 0) {
  297. unset($floors[$key]);
  298. } elseif($floor > $_GET['stopfloor']) {
  299. unset($floors[$key]);
  300. }
  301. }
  302. }
  303. $_GET['rewardfloor'] = implode(',', $floors);
  304. }
  305. }
  306. $thread['status'] = setstatus(3, 1, $thread['status']);
  307. $thread['status'] = setstatus(1, 1, $thread['status']);
  308. }
  309. $_GET['allownoticeauthor'] && $thread['status'] = setstatus(6, 1, $thread['status']);
  310. $isgroup = $_G['forum']['status'] == 3 ? 1 : 0;
  311. if($_G['group']['allowreplycredit']) {
  312. $_GET['replycredit_extcredits'] = intval($_GET['replycredit_extcredits']);
  313. $_GET['replycredit_times'] = intval($_GET['replycredit_times']);
  314. $_GET['replycredit_membertimes'] = intval($_GET['replycredit_membertimes']);
  315. $_GET['replycredit_random'] = intval($_GET['replycredit_random']);
  316. $_GET['replycredit_random'] = $_GET['replycredit_random'] < 0 || $_GET['replycredit_random'] > 99 ? 0 : $_GET['replycredit_random'] ;
  317. $replycredit = $replycredit_real = 0;
  318. if($_GET['replycredit_extcredits'] > 0 && $_GET['replycredit_times'] > 0) {
  319. $replycredit_real = ceil(($_GET['replycredit_extcredits'] * $_GET['replycredit_times']) + ($_GET['replycredit_extcredits'] * $_GET['replycredit_times'] * $_G['setting']['creditstax']));
  320. if($replycredit_real > getuserprofile('extcredits'.$_G['setting']['creditstransextra'][10])) {
  321. showmessage('replycredit_morethan_self');
  322. } else {
  323. $replycredit = ceil($_GET['replycredit_extcredits'] * $_GET['replycredit_times']);
  324. }
  325. }
  326. }
  327. $newthread = array(
  328. 'fid' => $_G['fid'],
  329. 'posttableid' => 0,
  330. 'readperm' => $readperm,
  331. 'price' => $price,
  332. 'typeid' => $typeid,
  333. 'sortid' => $sortid,
  334. 'author' => $author,
  335. 'authorid' => $_G['uid'],
  336. 'subject' => $subject,
  337. 'dateline' => $publishdate,
  338. 'lastpost' => $publishdate,
  339. 'lastposter' => $author,
  340. 'displayorder' => $displayorder,
  341. 'digest' => $digest,
  342. 'special' => $special,
  343. 'attachment' => 0,
  344. 'moderated' => $moderated,
  345. 'status' => $thread['status'],
  346. 'isgroup' => $isgroup,
  347. 'replycredit' => $replycredit,
  348. 'closed' => $closed ? 1 : 0
  349. );
  350. $tid = C::t('forum_thread')->insert($newthread, true);
  351. useractionlog($_G['uid'], 'tid');
  352. if(!getuserprofile('threads') && $_G['setting']['newbie']) {
  353. C::t('forum_thread')->update($tid, array('icon' => $_G['setting']['newbie']));
  354. }
  355. if ($publishdate != $_G['timestamp']) {
  356. loadcache('cronpublish');
  357. $cron_publish_ids = dunserialize($_G['cache']['cronpublish']);
  358. $cron_publish_ids[$tid] = $tid;
  359. $cron_publish_ids = serialize($cron_publish_ids);
  360. savecache('cronpublish', $cron_publish_ids);
  361. }
  362. if(!$isanonymous) {
  363. C::t('common_member_field_home')->update($_G['uid'], array('recentnote'=>$subject));
  364. }
  365. if($special == 3 && $_G['group']['allowpostreward']) {
  366. updatemembercount($_G['uid'], array($_G['setting']['creditstransextra'][2] => -$realprice), 1, 'RTC', $tid);
  367. }
  368. if($moderated) {
  369. updatemodlog($tid, ($displayorder > 0 ? 'STK' : 'DIG'));
  370. updatemodworks(($displayorder > 0 ? 'STK' : 'DIG'), 1);
  371. }
  372. if($special == 1) {
  373. foreach($pollarray['options'] as $polloptvalue) {
  374. $polloptvalue = dhtmlspecialchars(trim($polloptvalue));
  375. C::t('forum_polloption')->insert(array('tid' => $tid, 'polloption' => $polloptvalue));
  376. }
  377. $polloptionpreview = '';
  378. $query = C::t('forum_polloption')->fetch_all_by_tid($tid, 1, 2);
  379. foreach($query as $option) {
  380. $polloptvalue = preg_replace("/\[url=(https?){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/i", "<a href=\"\\1://\\2\" target=\"_blank\">\\3</a>", $option['polloption']);
  381. $polloptionpreview .= $polloptvalue."\t";
  382. }
  383. $polloptionpreview = daddslashes($polloptionpreview);
  384. $data = array('tid' => $tid, 'multiple' => $pollarray['multiple'], 'visible' => $pollarray['visible'], 'maxchoices' => $pollarray['maxchoices'], 'expiration' => $pollarray['expiration'], 'overt' => $pollarray['overt'], 'pollpreview' => $polloptionpreview);
  385. C::t('forum_poll')->insert($data);
  386. } elseif($special == 4 && $_G['group']['allowpostactivity']) {
  387. $data = array('tid' => $tid, 'uid' => $_G['uid'], 'cost' => $activity['cost'], 'starttimefrom' => $activity['starttimefrom'], 'starttimeto' => $activity['starttimeto'], 'place' => $activity['place'], 'class' => $activity['class'], 'gender' => $activity['gender'], 'number' => $activity['number'], 'expiration' => $activity['expiration'], 'aid' => $_GET['activityaid'], 'ufield' => $activity['ufield'], 'credit' => $activity['credit']);
  388. C::t('forum_activity')->insert($data);
  389. } elseif($special == 5 && $_G['group']['allowpostdebate']) {
  390. C::t('forum_debate')->insert(array(
  391. 'tid' => $tid,
  392. 'uid' => $_G['uid'],
  393. 'starttime' => $publishdate,
  394. 'endtime' => $endtime,
  395. 'affirmdebaters' => 0,
  396. 'negadebaters' => 0,
  397. 'affirmvotes' => 0,
  398. 'negavotes' => 0,
  399. 'umpire' => $_GET['umpire'],
  400. 'winner' => '',
  401. 'bestdebater' => '',
  402. 'affirmpoint' => $affirmpoint,
  403. 'negapoint' => $negapoint,
  404. 'umpirepoint' => ''
  405. ));
  406. } elseif($special == 127) {
  407. $message .= chr(0).chr(0).chr(0).$specialextra;
  408. }
  409. if($_G['forum']['threadsorts']['types'][$sortid] && !empty($_G['forum_optiondata']) && is_array($_G['forum_optiondata'])) {
  410. $filedname = $valuelist = $separator = '';
  411. foreach($_G['forum_optiondata'] as $optionid => $value) {
  412. if($value) {
  413. $filedname .= $separator.$_G['forum_optionlist'][$optionid]['identifier'];
  414. $valuelist .= $separator."'".daddslashes($value)."'";
  415. $separator = ' ,';
  416. }
  417. if($_G['forum_optionlist'][$optionid]['type'] == 'image') {
  418. $identifier = $_G['forum_optionlist'][$optionid]['identifier'];
  419. $sortaids[] = intval($_GET['typeoption'][$identifier]['aid']);
  420. }
  421. C::t('forum_typeoptionvar')->insert(array(
  422. 'sortid' => $sortid,
  423. 'tid' => $tid,
  424. 'fid' => $_G['fid'],
  425. 'optionid' => $optionid,
  426. 'value' => censor($value),
  427. 'expiration' => ($typeexpiration ? $publishdate + $typeexpiration : 0),
  428. ));
  429. }
  430. if($filedname && $valuelist) {
  431. C::t('forum_optionvalue')->insert($sortid, "($filedname, tid, fid) VALUES ($valuelist, '$tid', '$_G[fid]')");
  432. }
  433. }
  434. if($_G['group']['allowat']) {
  435. $atlist = $atlist_tmp = array();
  436. preg_match_all("/@([^\r\n]*?)\s/i", $message.' ', $atlist_tmp);
  437. $atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, $_G['group']['allowat']);
  438. if(!empty($atlist_tmp)) {
  439. if(empty($_G['setting']['at_anyone'])) {
  440. foreach(C::t('home_follow')->fetch_all_by_uid_fusername($_G['uid'], $atlist_tmp) as $row) {
  441. $atlist[$row['followuid']] = $row['fusername'];
  442. }
  443. if(count($atlist) < $_G['group']['allowat']) {
  444. $query = C::t('home_friend')->fetch_all_by_uid_username($_G['uid'], $atlist_tmp);
  445. foreach($query as $row) {
  446. $atlist[$row['fuid']] = $row['fusername'];
  447. }
  448. }
  449. } else {
  450. foreach(C::t('common_member')->fetch_all_by_username($atlist_tmp) as $row) {
  451. $atlist[$row['uid']] = $row['username'];
  452. }
  453. }
  454. }
  455. if($atlist) {
  456. foreach($atlist as $atuid => $atusername) {
  457. $atsearch[] = "/@$atusername /i";
  458. $atreplace[] = "[url=home.php?mod=space&uid=$atuid]@{$atusername}[/url] ";
  459. }
  460. $message = preg_replace($atsearch, $atreplace, $message.' ', 1);
  461. }
  462. }
  463. $bbcodeoff = checkbbcodes($message, !empty($_GET['bbcodeoff']));
  464. $smileyoff = checksmilies($message, !empty($_GET['smileyoff']));
  465. $parseurloff = !empty($_GET['parseurloff']);
  466. $htmlon = $_G['group']['allowhtml'] && !empty($_GET['htmlon']) ? 1 : 0;
  467. $usesig = !empty($_GET['usesig']) && $_G['group']['maxsigsize'] ? 1 : 0;
  468. $class_tag = new tag();
  469. $tagstr = $class_tag->add_tag($_GET['tags'], $tid, 'tid');
  470. if($_G['group']['allowreplycredit']) {
  471. if($replycredit > 0 && $replycredit_real > 0) {
  472. updatemembercount($_G['uid'], array('extcredits'.$_G['setting']['creditstransextra'][10] => -$replycredit_real), 1, 'RCT', $tid);
  473. $insertdata = array(
  474. 'tid' => $tid,
  475. 'extcredits' => $_GET['replycredit_extcredits'],
  476. 'extcreditstype' => $_G['setting']['creditstransextra'][10],
  477. 'times' => $_GET['replycredit_times'],
  478. 'membertimes' => $_GET['replycredit_membertimes'],
  479. 'random' => $_GET['replycredit_random']
  480. );
  481. C::t('forum_replycredit')->insert($insertdata);
  482. }
  483. }
  484. if($_G['group']['allowpostrushreply'] && $_GET['rushreply']) {
  485. $rushdata = array('tid' => $tid, 'stopfloor' => $_GET['stopfloor'], 'starttimefrom' => $_GET['rushreplyfrom'], 'starttimeto' => $_GET['rushreplyto'], 'rewardfloor' => $_GET['rewardfloor'], 'creditlimit' => $_GET['creditlimit']);
  486. C::t('forum_threadrush')->insert($rushdata);
  487. }
  488. $pinvisible = $modnewthreads ? -2 : (empty($_GET['save']) ? 0 : -3);
  489. $message = preg_replace('/\[attachimg\](\d+)\[\/attachimg\]/is', '[attach]\1[/attach]', $message);
  490. $pid = insertpost(array(
  491. 'fid' => $_G['fid'],
  492. 'tid' => $tid,
  493. 'first' => '1',
  494. 'author' => $_G['username'],
  495. 'authorid' => $_G['uid'],
  496. 'subject' => $subject,
  497. 'dateline' => $publishdate,
  498. 'message' => $message,
  499. 'useip' => $_G['clientip'],
  500. 'invisible' => $pinvisible,
  501. 'anonymous' => $isanonymous,
  502. 'usesig' => $usesig,
  503. 'htmlon' => $htmlon,
  504. 'bbcodeoff' => $bbcodeoff,
  505. 'smileyoff' => $smileyoff,
  506. 'parseurloff' => $parseurloff,
  507. 'attachment' => '0',
  508. 'tags' => $tagstr,
  509. 'replycredit' => 0,
  510. 'status' => (defined('IN_MOBILE') ? 8 : 0)
  511. ));
  512. if($_G['group']['allowat'] && $atlist) {
  513. foreach($atlist as $atuid => $atusername) {
  514. notification_add($atuid, 'at', 'at_message', array('from_id' => $tid, 'from_idtype' => 'at', 'buyerid' => $_G['uid'], 'buyer' => $_G['username'], 'tid' => $tid, 'subject' => $subject, 'pid' => $pid, 'message' => messagecutstr($message, 150)));
  515. }
  516. set_atlist_cookie(array_keys($atlist));
  517. }
  518. $threadimageaid = 0;
  519. $threadimage = array();
  520. if($special == 4 && $_GET['activityaid']) {
  521. $threadimageaid = $_GET['activityaid'];
  522. convertunusedattach($_GET['activityaid'], $tid, $pid);
  523. }
  524. if($_G['forum']['threadsorts']['types'][$sortid] && !empty($_G['forum_optiondata']) && is_array($_G['forum_optiondata']) && $sortaids) {
  525. foreach($sortaids as $sortaid) {
  526. convertunusedattach($sortaid, $tid, $pid);
  527. }
  528. }
  529. if(($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) && ($_GET['attachnew'] || $sortid || !empty($_GET['activityaid']))) {
  530. updateattach($displayorder == -4 || $modnewthreads, $tid, $pid, $_GET['attachnew']);
  531. if(!$threadimageaid) {
  532. $threadimage = C::t('forum_attachment_n')->fetch_max_image('tid:'.$tid, 'tid', $tid);
  533. $threadimageaid = $threadimage['aid'];
  534. }
  535. }
  536. $values = array('fid' => $_G['fid'], 'tid' => $tid, 'pid' => $pid, 'coverimg' => '', 'sechash' => !empty($_GET['sechash']) ? $_GET['sechash'] : '');
  537. $param = array();
  538. if($_G['forum']['picstyle']) {
  539. if(!setthreadcover($pid, 0, $threadimageaid)) {
  540. preg_match_all("/(\[img\]|\[img=\d{1,4}[x|\,]\d{1,4}\])\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", $message, $imglist, PREG_SET_ORDER);
  541. $values['coverimg'] = "<p id=\"showsetcover\">".lang('message', 'post_newthread_set_cover')."<span id=\"setcoverwait\"></span></p><script>if($('forward_a')){\$('forward_a').style.display='none';setTimeout(\"$('forward_a').style.display=''\", 5000);};ajaxget('forum.php?mod=ajax&action=setthreadcover&tid=$tid&pid=$pid&fid=$_G[fid]&imgurl={$imglist[0][2]}&newthread=1', 'showsetcover', 'setcoverwait')</script>";
  542. $param['clean_msgforward'] = 1;
  543. $param['timeout'] = $param['refreshtime'] = 15;
  544. }
  545. }
  546. if($threadimageaid) {
  547. if(!$threadimage) {
  548. $threadimage = C::t('forum_attachment_n')->fetch('tid:'.$tid, $threadimageaid);
  549. }
  550. $threadimage = daddslashes($threadimage);
  551. C::t('forum_threadimage')->insert(array(
  552. 'tid' => $tid,
  553. 'attachment' => $threadimage['attachment'],
  554. 'remote' => $threadimage['remote'],
  555. ));
  556. }
  557. $statarr = array(0 => 'thread', 1 => 'poll', 2 => 'trade', 3 => 'reward', 4 => 'activity', 5 => 'debate', 127 => 'thread');
  558. include_once libfile('function/stat');
  559. updatestat($isgroup ? 'groupthread' : $statarr[$special]);
  560. dsetcookie('clearUserdata', 'forum');
  561. if($specialextra) {
  562. $classname = 'threadplugin_'.$specialextra;
  563. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newthread_submit_end')) {
  564. $threadpluginclass->newthread_submit_end($_G['fid'], $tid);
  565. }
  566. }
  567. if(!empty($_G['setting']['rewriterule']['forum_viewthread']) && in_array('forum_viewthread', $_G['setting']['rewritestatus'])) {
  568. $returnurl = rewriteoutput('forum_viewthread', 1, '', $tid, 1, '', $extra);
  569. } else {
  570. $returnurl = "forum.php?mod=viewthread&tid=$tid&extra=$extra";
  571. }
  572. if($modnewthreads) {
  573. updatemoderate('tid', $tid);
  574. C::t('forum_forum')->update_forum_counter($_G['fid'], 0, 0, 1);
  575. manage_addnotify('verifythread');
  576. showmessage('post_newthread_mod_succeed', $returnurl, $values, $param);
  577. } else {
  578. if($displayorder >= 0 && helper_access::check_module('follow') && !empty($_GET['adddynamic']) && !$isanonymous) {
  579. require_once libfile('function/discuzcode');
  580. require_once libfile('function/followcode');
  581. $feedcontent = array(
  582. 'tid' => $tid,
  583. 'content' => followcode($message, $tid, $pid, 1000),
  584. );
  585. C::t('forum_threadpreview')->insert($feedcontent);
  586. C::t('forum_thread')->update_status_by_tid($tid, '512');
  587. $followfeed = array(
  588. 'uid' => $_G['uid'],
  589. 'username' => $_G['username'],
  590. 'tid' => $tid,
  591. 'note' => '',
  592. 'dateline' => TIMESTAMP
  593. );
  594. $values['feedid'] = C::t('home_follow_feed')->insert($followfeed, true);
  595. C::t('common_member_count')->increase($_G['uid'], array('feeds'=>1));
  596. }
  597. $feed = array(
  598. 'icon' => '',
  599. 'title_template' => '',
  600. 'title_data' => array(),
  601. 'body_template' => '',
  602. 'body_data' => array(),
  603. 'title_data'=>array(),
  604. 'images'=>array()
  605. );
  606. if(!empty($_GET['addfeed']) && $_G['forum']['allowfeed'] && !$isanonymous) {
  607. $message = !$price && !$readperm ? $message : '';
  608. if($special == 0) {
  609. $feed['icon'] = 'thread';
  610. $feed['title_template'] = 'feed_thread_title';
  611. $feed['body_template'] = 'feed_thread_message';
  612. $feed['body_data'] = array(
  613. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=$tid\">$subject</a>",
  614. 'message' => messagecutstr($message, 150)
  615. );
  616. if(!empty($_G['forum_attachexist'])) {
  617. $imgattach = C::t('forum_attachment_n')->fetch_max_image('tid:'.$tid, 'pid', $pid);
  618. $firstaid = $imgattach['aid'];
  619. unset($imgattach);
  620. if($firstaid) {
  621. $feed['images'] = array(getforumimg($firstaid));
  622. $feed['image_links'] = array("forum.php?mod=viewthread&do=tradeinfo&tid=$tid&pid=$pid");
  623. }
  624. }
  625. } elseif($special > 0) {
  626. if($special == 1) {
  627. $pvs = explode("\t", messagecutstr($polloptionpreview, 150));
  628. $s = '';
  629. $i = 1;
  630. foreach($pvs as $pv) {
  631. $s .= $i.'. '.$pv.'<br />';
  632. }
  633. $s .= '&nbsp;&nbsp;&nbsp;...';
  634. $feed['icon'] = 'poll';
  635. $feed['title_template'] = 'feed_thread_poll_title';
  636. $feed['body_template'] = 'feed_thread_poll_message';
  637. $feed['body_data'] = array(
  638. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=$tid\">$subject</a>",
  639. 'message' => $s
  640. );
  641. } elseif($special == 3) {
  642. $feed['icon'] = 'reward';
  643. $feed['title_template'] = 'feed_thread_reward_title';
  644. $feed['body_template'] = 'feed_thread_reward_message';
  645. $feed['body_data'] = array(
  646. 'subject'=> "<a href=\"forum.php?mod=viewthread&tid=$tid\">$subject</a>",
  647. 'rewardprice'=> $rewardprice,
  648. 'extcredits' => $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][2]]['title'],
  649. );
  650. } elseif($special == 4) {
  651. $feed['icon'] = 'activity';
  652. $feed['title_template'] = 'feed_thread_activity_title';
  653. $feed['body_template'] = 'feed_thread_activity_message';
  654. $feed['body_data'] = array(
  655. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=$tid\">$subject</a>",
  656. 'starttimefrom' => $_GET['starttimefrom'][$activitytime],
  657. 'activityplace'=> $activity['place'],
  658. 'message' => messagecutstr($message, 150),
  659. );
  660. if($_GET['activityaid']) {
  661. $feed['images'] = array(getforumimg($_GET['activityaid']));
  662. $feed['image_links'] = array("forum.php?mod=viewthread&do=tradeinfo&tid=$tid&pid=$pid");
  663. }
  664. } elseif($special == 5) {
  665. $feed['icon'] = 'debate';
  666. $feed['title_template'] = 'feed_thread_debate_title';
  667. $feed['body_template'] = 'feed_thread_debate_message';
  668. $feed['body_data'] = array(
  669. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=$tid\">$subject</a>",
  670. 'message' => messagecutstr($message, 150),
  671. 'affirmpoint'=> messagecutstr($affirmpoint, 150),
  672. 'negapoint'=> messagecutstr($negapoint, 150)
  673. );
  674. }
  675. }
  676. $feed['title_data']['hash_data'] = "tid{$tid}";
  677. $feed['id'] = $tid;
  678. $feed['idtype'] = 'tid';
  679. if($feed['icon']) {
  680. postfeed($feed);
  681. }
  682. }
  683. if($displayorder != -4) {
  684. if($digest) {
  685. updatepostcredits('+', $_G['uid'], 'digest', $_G['fid']);
  686. }
  687. updatepostcredits('+', $_G['uid'], 'post', $_G['fid']);
  688. if($isgroup) {
  689. C::t('forum_groupuser')->update_counter_for_user($_G['uid'], $_G['fid'], 1);
  690. }
  691. $subject = str_replace("\t", ' ', $subject);
  692. $lastpost = "$tid\t".$subject."\t$_G[timestamp]\t$author";
  693. C::t('forum_forum')->update($_G['fid'], array('lastpost' => $lastpost));
  694. C::t('forum_forum')->update_forum_counter($_G['fid'], 1, 1, 1);
  695. if($_G['forum']['type'] == 'sub') {
  696. C::t('forum_forum')->update($_G['forum']['fup'], array('lastpost' => $lastpost));
  697. }
  698. }
  699. if($_G['forum']['status'] == 3) {
  700. C::t('forum_forumfield')->update($_G['fid'], array('lastupdate' => TIMESTAMP));
  701. require_once libfile('function/grouplog');
  702. updategroupcreditlog($_G['fid'], $_G['uid']);
  703. }
  704. showmessage('post_newthread_succeed', $returnurl, $values, $param);
  705. }
  706. }
  707. ?>