post_newreply.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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_newreply.php 33709 2013-08-06 09:06:56Z andyzheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. require_once libfile('function/forumlist');
  12. $isfirstpost = 0;
  13. $_G['group']['allowimgcontent'] = 0;
  14. $showthreadsorts = 0;
  15. $quotemessage = '';
  16. if($special == 5) {
  17. $debate = array_merge($thread, daddslashes(C::t('forum_debate')->fetch($_G['tid'])));
  18. $firststand = C::t('forum_debatepost')->get_firststand($_G['tid'], $_G['uid']);
  19. $stand = $firststand ? $firststand : intval($_GET['stand']);
  20. if($debate['endtime'] && $debate['endtime'] < TIMESTAMP) {
  21. showmessage('debate_end');
  22. }
  23. }
  24. if(!$_G['uid'] && !((!$_G['forum']['replyperm'] && $_G['group']['allowreply']) || ($_G['forum']['replyperm'] && forumperm($_G['forum']['replyperm'])))) {
  25. showmessage('replyperm_login_nopermission', NULL, array(), array('login' => 1));
  26. } elseif(empty($_G['forum']['allowreply'])) {
  27. if(!$_G['forum']['replyperm'] && !$_G['group']['allowreply']) {
  28. showmessage('replyperm_none_nopermission', NULL, array(), array('login' => 1));
  29. } elseif($_G['forum']['replyperm'] && !forumperm($_G['forum']['replyperm'])) {
  30. showmessagenoperm('replyperm', $_G['forum']['fid']);
  31. }
  32. } elseif($_G['forum']['allowreply'] == -1) {
  33. showmessage('post_forum_newreply_nopermission', NULL);
  34. }
  35. if(!$_G['uid'] && ($_G['setting']['need_avatar'] || $_G['setting']['need_email'] || $_G['setting']['need_friendnum'])) {
  36. showmessage('replyperm_login_nopermission', NULL, array(), array('login' => 1));
  37. }
  38. if(empty($thread)) {
  39. showmessage('thread_nonexistence');
  40. } elseif($thread['price'] > 0 && $thread['special'] == 0 && !$_G['uid']) {
  41. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  42. }
  43. checklowerlimit('reply', 0, 1, $_G['forum']['fid']);
  44. if($_G['setting']['commentnumber'] && !empty($_GET['comment'])) {
  45. if(!submitcheck('commentsubmit', 0, $seccodecheck, $secqaacheck)) {
  46. showmessage('submitcheck_error', NULL);
  47. }
  48. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
  49. if(!$post) {
  50. showmessage('post_nonexistence', NULL);
  51. }
  52. if($thread['closed'] && !$_G['forum']['ismoderator'] && !$thread['isgroup']) {
  53. showmessage('post_thread_closed');
  54. } elseif(!$thread['isgroup'] && $post_autoclose = checkautoclose($thread)) {
  55. showmessage($post_autoclose, '', array('autoclose' => $_G['forum']['autoclose']));
  56. } elseif(checkflood()) {
  57. showmessage('post_flood_ctrl', '', array('floodctrl' => $_G['setting']['floodctrl']));
  58. } elseif(checkmaxperhour('pid')) {
  59. showmessage('post_flood_ctrl_posts_per_hour', '', array('posts_per_hour' => $_G['group']['maxpostsperhour']));
  60. }
  61. $commentscore = '';
  62. if(!empty($_GET['commentitem']) && !empty($_G['uid']) && $post['authorid'] != $_G['uid']) {
  63. foreach($_GET['commentitem'] as $itemk => $itemv) {
  64. if($itemv !== '') {
  65. $commentscore .= strip_tags(trim($itemk)).': <i>'.intval($itemv).'</i> ';
  66. }
  67. }
  68. }
  69. $comment = cutstr(($commentscore ? $commentscore.'<br />' : '').censor(trim(dhtmlspecialchars($_GET['message'])), '***'), 200, ' ');
  70. if(!$comment) {
  71. showmessage('post_sm_isnull');
  72. }
  73. $pcid = C::t('forum_postcomment')->insert(array(
  74. 'tid' => $post['tid'],
  75. 'pid' => $post['pid'],
  76. 'author' => $_G['username'],
  77. 'authorid' => $_G['uid'],
  78. 'dateline' => TIMESTAMP,
  79. 'comment' => $comment,
  80. 'score' => $commentscore ? 1 : 0,
  81. 'useip' => $_G['clientip'],
  82. 'port'=> $_G['remoteport']
  83. ), true);
  84. C::t('forum_post')->update('tid:'.$_G['tid'], $_GET['pid'], array('comment' => 1));
  85. $comments = $thread['comments'] ? $thread['comments'] + 1 : C::t('forum_postcomment')->count_by_tid($_G['tid']);
  86. C::t('forum_thread')->update($_G['tid'], array('comments' => $comments));
  87. !empty($_G['uid']) && updatepostcredits('+', $_G['uid'], 'reply', $_G['fid']);
  88. if(!empty($_G['uid']) && $_G['uid'] != $post['authorid']) {
  89. notification_add($post['authorid'], 'pcomment', 'comment_add', array(
  90. 'tid' => $_G['tid'],
  91. 'pid' => $_GET['pid'],
  92. 'subject' => $thread['subject'],
  93. 'from_id' => $_G['tid'],
  94. 'from_idtype' => 'pcomment',
  95. 'commentmsg' => cutstr(str_replace(array('[b]', '[/b]', '[/color]'), '', preg_replace("/\[color=([#\w]+?)\]/i", "", $comment)), 200)
  96. ));
  97. }
  98. update_threadpartake($post['tid']);
  99. $pcid = C::t('forum_postcomment')->fetch_standpoint_by_pid($_GET['pid']);
  100. $pcid = $pcid['id'];
  101. if(!empty($_G['uid']) && $_GET['commentitem']) {
  102. $totalcomment = array();
  103. foreach(C::t('forum_postcomment')->fetch_all_by_pid_score($_GET['pid'], 1) as $comment) {
  104. $comment['comment'] = addslashes($comment['comment']);
  105. if(strexists($comment['comment'], '<br />')) {
  106. if(preg_match_all("/([^:]+?):\s<i>(\d+)<\/i>/", $comment['comment'], $a)) {
  107. foreach($a[1] as $k => $itemk) {
  108. $totalcomment[trim($itemk)][] = $a[2][$k];
  109. }
  110. }
  111. }
  112. }
  113. $totalv = '';
  114. foreach($totalcomment as $itemk => $itemv) {
  115. $totalv .= strip_tags(trim($itemk)).': <i>'.(floatval(sprintf('%1.1f', array_sum($itemv) / count($itemv)))).'</i> ';
  116. }
  117. if($pcid) {
  118. C::t('forum_postcomment')->update($pcid, array('comment' => $totalv, 'dateline' => TIMESTAMP + 1));
  119. } else {
  120. C::t('forum_postcomment')->insert(array(
  121. 'tid' => $post['tid'],
  122. 'pid' => $post['pid'],
  123. 'author' => '',
  124. 'authorid' => '-1',
  125. 'dateline' => TIMESTAMP + 1,
  126. 'comment' => $totalv
  127. ));
  128. }
  129. }
  130. C::t('forum_postcache')->delete($post['pid']);
  131. showmessage('comment_add_succeed', "forum.php?mod=viewthread&tid=$post[tid]&pid=$post[pid]&page=$_GET[page]&extra=$extra#pid$post[pid]", array('tid' => $post['tid'], 'pid' => $post['pid']));
  132. }
  133. if($special == 127) {
  134. $postinfo = C::t('forum_post')->fetch_threadpost_by_tid_invisible($_G['tid']);
  135. $sppos = strrpos($postinfo['message'], chr(0).chr(0).chr(0));
  136. $specialextra = substr($postinfo['message'], $sppos + 3);
  137. }
  138. if(getstatus($thread['status'], 3)) {
  139. $rushinfo = C::t('forum_threadrush')->fetch($_G['tid']);
  140. if($rushinfo['creditlimit'] != -996) {
  141. $checkcreditsvalue = $_G['setting']['creditstransextra'][11] ? getuserprofile('extcredits'.$_G['setting']['creditstransextra'][11]) : $_G['member']['credits'];
  142. if($checkcreditsvalue < $rushinfo['creditlimit']) {
  143. $creditlimit_title = $_G['setting']['creditstransextra'][11] ? $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][11]]['title'] : lang('forum/misc', 'credit_total');
  144. showmessage('post_rushreply_creditlimit', '', array('creditlimit_title' => $creditlimit_title, 'creditlimit' => $rushinfo['creditlimit']));
  145. }
  146. }
  147. }
  148. if(!submitcheck('replysubmit', 0, $seccodecheck, $secqaacheck)) {
  149. $st_p = $_G['uid'].'|'.TIMESTAMP;
  150. dsetcookie('st_p', $st_p.'|'.md5($st_p.$_G['config']['security']['authkey']));
  151. if($thread['special'] == 2 && ((!isset($_GET['addtrade']) || $thread['authorid'] != $_G['uid']) && !$tradenum = C::t('forum_trade')->fetch_counter_thread_goods($_G['tid']))) {
  152. showmessage('trade_newreply_nopermission', NULL);
  153. }
  154. $language = lang('forum/misc');
  155. $noticeauthor = $noticetrimstr = '';
  156. if(isset($_GET['repquote']) && $_GET['repquote'] = intval($_GET['repquote'])) {
  157. $thaquote = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['repquote']);
  158. if(!($thaquote && ($thaquote['invisible'] == 0 || $thaquote['authorid'] == $_G['uid'] && $thaquote['invisible'] == -2))) {
  159. $thaquote = array();
  160. }
  161. if($thaquote['tid'] != $_G['tid']) {
  162. showmessage('reply_quotepost_error', NULL);
  163. }
  164. if(getstatus($thread['status'], 2) && $thaquote['authorid'] != $_G['uid'] && $_G['uid'] != $thread['authorid'] && $thaquote['first'] != 1 && !$_G['forum']['ismoderator']) {
  165. showmessage('reply_quotepost_error', NULL);
  166. }
  167. if(!($thread['price'] && !$thread['special'] && $thaquote['first'])) {
  168. $quotefid = $thaquote['fid'];
  169. $message = $thaquote['message'];
  170. if(strpos($message, '[/password]') !== FALSE) {
  171. $message = '';
  172. }
  173. if($_G['setting']['bannedmessages'] && $thaquote['authorid']) {
  174. $author = getuserbyuid($thaquote['authorid']);
  175. if(!$author['groupid'] || $author['groupid'] == 4 || $author['groupid'] == 5) {
  176. $message = $language['post_banned'];
  177. } elseif($thaquote['status'] & 1) {
  178. $message = $language['post_single_banned'];
  179. }
  180. }
  181. $time = dgmdate($thaquote['dateline']);
  182. $message = messagecutstr($message, 100);
  183. $message = implode("\n", array_slice(explode("\n", $message), 0, 3));
  184. $thaquote['useip'] = substr($thaquote['useip'], 0, strrpos($thaquote['useip'], '.')).'.x';
  185. if($thaquote['author'] && $thaquote['anonymous']) {
  186. $thaquote['author'] = lang('forum/misc', 'anonymoususer');
  187. } elseif(!$thaquote['author']) {
  188. $thaquote['author'] = lang('forum/misc', 'guestuser').' '.$thaquote['useip'];
  189. } else {
  190. $thaquote['author'] = $thaquote['author'];
  191. }
  192. $post_reply_quote = lang('forum/misc', 'post_reply_quote', array('author' => $thaquote['author'], 'time' => $time));
  193. $noticeauthormsg = dhtmlspecialchars($message);
  194. if(!defined('IN_MOBILE')) {
  195. $message = "[quote][size=2][url=forum.php?mod=redirect&goto=findpost&pid=$_GET[repquote]&ptid={$_G['tid']}][color=#999999]{$post_reply_quote}[/color][/url][/size]\n{$message}[/quote]";
  196. } else {
  197. $message = "[quote][color=#999999]{$post_reply_quote}[/color]\n[color=#999999]{$message}[/color][/quote]";
  198. }
  199. $quotemessage = discuzcode($message, 0, 0);
  200. $noticeauthor = dhtmlspecialchars(authcode('q|'.$thaquote['authorid'], 'ENCODE'));
  201. $noticetrimstr = dhtmlspecialchars($message);
  202. $message = '';
  203. }
  204. $reppid = $_GET['repquote'];
  205. } elseif(isset($_GET['reppost']) && $_GET['reppost'] = intval($_GET['reppost'])) {
  206. $thapost = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['reppost']);
  207. if(!($thapost && ($thapost['invisible'] == 0 || $thapost['authorid'] == $_G['uid'] && $thapost['invisible'] == -2))) {
  208. $thapost = array();
  209. }
  210. if($thapost['tid'] != $_G['tid']) {
  211. showmessage('targetpost_donotbelongto_thisthread', NULL);
  212. }
  213. $thapost['useip'] = substr($thapost['useip'], 0, strrpos($thapost['useip'], '.')).'.x';
  214. if($thapost['author'] && $thapost['anonymous']) {
  215. $thapost['author'] = '[color=Olive]'.lang('forum/misc', 'anonymoususer').'[/color]';
  216. } elseif(!$thapost['author']) {
  217. $thapost['author'] = '[color=Olive]'.lang('forum/misc', 'guestuser').'[/color] '.$thapost['useip'];
  218. } else {
  219. $thapost['author'] = '[color=Olive]'.$thapost['author'].'[/color]';
  220. }
  221. $quotemessage = discuzcode($message, 0, 0);
  222. $noticeauthormsg = dhtmlspecialchars(messagecutstr($thapost['message'], 100));
  223. $noticeauthor = dhtmlspecialchars(authcode('r|'.$thapost['authorid'], 'ENCODE'));
  224. $noticetrimstr = dhtmlspecialchars($message);
  225. $message = '';
  226. $reppid = $_GET['reppost'];
  227. }
  228. if(isset($_GET['addtrade']) && $thread['special'] == 2 && $_G['group']['allowposttrade'] && $thread['authorid'] == $_G['uid']) {
  229. $expiration_7days = date('Y-m-d', TIMESTAMP + 86400 * 7);
  230. $expiration_14days = date('Y-m-d', TIMESTAMP + 86400 * 14);
  231. $trade['expiration'] = $expiration_month = date('Y-m-d', mktime(0, 0, 0, date('m')+1, date('d'), date('Y')));
  232. $expiration_3months = date('Y-m-d', mktime(0, 0, 0, date('m')+3, date('d'), date('Y')));
  233. $expiration_halfyear = date('Y-m-d', mktime(0, 0, 0, date('m')+6, date('d'), date('Y')));
  234. $expiration_year = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')+1));
  235. }
  236. if($thread['replies'] <= $_G['ppp']) {
  237. $postlist = array();
  238. if($thread['price'] > 0 && $thread['special'] == 0) {
  239. $postlist = C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], $_G['tid'], true, 'DESC', 0, 0, 0, 0);
  240. } else {
  241. $postlist = C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], $_G['tid'], true, 'DESC', 0, 0, null, 0);
  242. }
  243. if($_G['setting']['bannedmessages']) {
  244. $uids = array();
  245. foreach($postlist as $post) {
  246. $uids[] = $post['authorid'];
  247. }
  248. $users = C::t('common_member')->fetch_all($uids);
  249. }
  250. foreach($postlist as $k => $post) {
  251. $post['dateline'] = dgmdate($post['dateline'], 'u');
  252. if($_G['setting']['bannedmessages'] && ($post['authorid'] && (!$post['groupid'] || $post['groupid'] == 4 || $post['groupid'] == 5))) {
  253. $post['message'] = $language['post_banned'];
  254. } elseif($post['status'] & 1) {
  255. $post['message'] = $language['post_single_banned'];
  256. } else {
  257. $post['message'] = preg_replace("/\[hide=?\d*\](.*?)\[\/hide\]/is", "[b]$language[post_hidden][/b]", $post['message']);
  258. $post['message'] = discuzcode($post['message'], $post['smileyoff'], $post['bbcodeoff'], $post['htmlon'] & 1, $_G['forum']['allowsmilies'], $_G['forum']['allowbbcode'], $_G['forum']['allowimgcode'], $_G['forum']['allowhtml'], $_G['forum']['jammer']);
  259. }
  260. if($_G['setting']['bannedmessages']) {
  261. $post['groupid'] = $users[$post['authorid']]['groupid'];
  262. }
  263. $postlist[$k] = $post;
  264. }
  265. }
  266. unset($uids, $users);
  267. if($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) {
  268. $attachlist = getattach(0);
  269. $attachs = $attachlist['attachs'];
  270. $imgattachs = $attachlist['imgattachs'];
  271. unset($attachlist);
  272. }
  273. getgpc('infloat') ? include template('forum/post_infloat') : include template('forum/post');
  274. } else {
  275. $modpost = C::m('forum_post', $_G['tid']);
  276. $bfmethods = $afmethods = array();
  277. $params = array(
  278. 'subject' => $subject,
  279. 'message' => $message,
  280. 'special' => $special,
  281. 'extramessage' => $extramessage,
  282. 'bbcodeoff' => $_GET['bbcodeoff'],
  283. 'smileyoff' => $_GET['smileyoff'],
  284. 'htmlon' => $_GET['htmlon'],
  285. 'parseurloff' => $_GET['parseurloff'],
  286. 'usesig' => $_GET['usesig'],
  287. 'isanonymous' => $_GET['isanonymous'],
  288. 'noticetrimstr' => $_GET['noticetrimstr'],
  289. 'noticeauthor' => $_GET['noticeauthor'],
  290. 'from' => $_GET['from'],
  291. 'sechash' => $_GET['sechash'],
  292. 'geoloc' => diconv($_GET['geoloc'], 'UTF-8'),
  293. );
  294. if(!empty($_GET['trade']) && $thread['special'] == 2 && $_G['group']['allowposttrade']) {
  295. $bfmethods[] = array('class' => 'extend_thread_trade', 'method' => 'before_newreply');
  296. }
  297. $attentionon = empty($_GET['attention_add']) ? 0 : 1;
  298. $attentionoff = empty($attention_remove) ? 0 : 1;
  299. $bfmethods[] = array('class' => 'extend_thread_rushreply', 'method' => 'before_newreply');
  300. if($_G['group']['allowat']) {
  301. $bfmethods[] = array('class' => 'extend_thread_allowat', 'method' => 'before_newreply');
  302. }
  303. $bfmethods[] = array('class' => 'extend_thread_comment', 'method' => 'before_newreply');
  304. $modpost->attach_before_method('newreply', array('class' => 'extend_thread_filter', 'method' => 'before_newreply'));
  305. if($_G['group']['allowat']) {
  306. $afmethods[] = array('class' => 'extend_thread_allowat', 'method' => 'after_newreply');
  307. }
  308. $afmethods[] = array('class' => 'extend_thread_rushreply', 'method' => 'after_newreply');
  309. $afmethods[] = array('class' => 'extend_thread_comment', 'method' => 'after_newreply');
  310. if(helper_access::check_module('follow') && !empty($_GET['adddynamic'])) {
  311. $afmethods[] = array('class' => 'extend_thread_follow', 'method' => 'after_newreply');
  312. }
  313. if($thread['replycredit'] > 0 && $thread['authorid'] != $_G['uid'] && $_G['uid']) {
  314. $afmethods[] = array('class' => 'extend_thread_replycredit', 'method' => 'after_newreply');
  315. }
  316. if($special == 5) {
  317. $afmethods[] = array('class' => 'extend_thread_debate', 'method' => 'after_newreply');
  318. }
  319. $afmethods[] = array('class' => 'extend_thread_image', 'method' => 'after_newreply');
  320. if($special == 2 && $_G['group']['allowposttrade'] && $thread['authorid'] == $_G['uid']) {
  321. $afmethods[] = array('class' => 'extend_thread_trade', 'method' => 'after_newreply');
  322. }
  323. $afmethods[] = array('class' => 'extend_thread_filter', 'method' => 'after_newreply');
  324. if($_G['forum']['allowfeed']) {
  325. if($special == 2 && !empty($_GET['trade'])) {
  326. $modpost->attach_before_method('replyfeed', array('class' => 'extend_thread_trade', 'method' => 'before_replyfeed'));
  327. $modpost->attach_after_method('replyfeed', array('class' => 'extend_thread_trade', 'method' => 'after_replyfeed'));
  328. } elseif($special == 3 && $thread['authorid'] != $_G['uid']) {
  329. $modpost->attach_before_method('replyfeed', array('class' => 'extend_thread_reward', 'method' => 'before_replyfeed'));
  330. } elseif($special == 5 && $thread['authorid'] != $_G['uid']) {
  331. $modpost->attach_before_method('replyfeed', array('class' => 'extend_thread_debate', 'method' => 'before_replyfeed'));
  332. }
  333. }
  334. if(!isset($_GET['addfeed'])) {
  335. $space = array();
  336. space_merge($space, 'field_home');
  337. $_GET['addfeed'] = $space['privacy']['feed']['newreply'];
  338. }
  339. $modpost->attach_before_methods('newreply', $bfmethods);
  340. $modpost->attach_after_methods('newreply', $afmethods);
  341. $return = $modpost->newreply($params);
  342. $pid = $modpost->pid;
  343. if($specialextra) {
  344. @include_once DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  345. $classname = 'threadplugin_'.$specialextra;
  346. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newreply_submit_end')) {
  347. $threadpluginclass->newreply_submit_end($_G['fid'], $_G['tid']);
  348. }
  349. }
  350. if($modpost->pid && !$modpost->param('modnewreplies')) {
  351. if(!empty($_GET['addfeed'])) {
  352. $modpost->replyfeed();
  353. }
  354. }
  355. if($modpost->param('modnewreplies')) {
  356. $url = "forum.php?mod=viewthread&tid=".$_G['tid'];
  357. } else {
  358. $antitheft = '';
  359. if(!empty($_G['setting']['antitheft']['allow']) && empty($_G['setting']['antitheft']['disable']['thread']) && empty($_G['forum']['noantitheft'])) {
  360. $sign = helper_antitheft::get_sign($_G['tid'], 'tid');
  361. if($sign) {
  362. $antitheft = '&_dsign='.$sign;
  363. }
  364. }
  365. $url = "forum.php?mod=viewthread&tid=".$_G['tid']."&pid=".$modpost->pid."&page=".$modpost->param('page')."$antitheft&extra=".$extra."#pid".$modpost->pid;
  366. }
  367. if(!isset($inspacecpshare)) {
  368. showmessage($return , $url, $modpost->param('showmsgparam'));
  369. }
  370. }
  371. ?>