PageRenderTime 200ms CodeModel.GetById 24ms RepoModel.GetById 6ms app.codeStats 0ms

/source/include/post/post_newreply.php

https://github.com/jinbo51/DiscuzX
PHP | 447 lines | 355 code | 86 blank | 6 comment | 170 complexity | cf37d36f232567cda808f248654cf2a5 MD5 | raw file
Possible License(s): BSD-3-Clause
  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 33239 2013-05-08 07:35:08Z nemohou $
  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. 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. ));
  83. C::t('forum_post')->update('tid:'.$_G['tid'], $_GET['pid'], array('comment' => 1));
  84. $comments = $thread['comments'] ? $thread['comments'] + 1 : C::t('forum_postcomment')->count_by_tid($_G['tid']);
  85. C::t('forum_thread')->update($_G['tid'], array('comments' => $comments));
  86. !empty($_G['uid']) && updatepostcredits('+', $_G['uid'], 'reply', $_G['fid']);
  87. if(!empty($_G['uid']) && $_G['uid'] != $post['authorid']) {
  88. notification_add($post['authorid'], 'pcomment', 'comment_add', array(
  89. 'tid' => $_G['tid'],
  90. 'pid' => $_GET['pid'],
  91. 'subject' => $thread['subject'],
  92. 'from_id' => $_G['tid'],
  93. 'from_idtype' => 'pcomment',
  94. 'commentmsg' => cutstr(str_replace(array('[b]', '[/b]', '[/color]'), '', preg_replace("/\[color=([#\w]+?)\]/i", "", $comment)), 200)
  95. ));
  96. }
  97. update_threadpartake($post['tid']);
  98. $pcid = C::t('forum_postcomment')->fetch_standpoint_by_pid($_GET['pid']);
  99. $pcid = $pcid['id'];
  100. if(!empty($_G['uid']) && $_GET['commentitem']) {
  101. $totalcomment = array();
  102. foreach(C::t('forum_postcomment')->fetch_all_by_pid_score($_GET['pid'], 1) as $comment) {
  103. $comment['comment'] = addslashes($comment['comment']);
  104. if(strexists($comment['comment'], '<br />')) {
  105. if(preg_match_all("/([^:]+?):\s<i>(\d+)<\/i>/", $comment['comment'], $a)) {
  106. foreach($a[1] as $k => $itemk) {
  107. $totalcomment[trim($itemk)][] = $a[2][$k];
  108. }
  109. }
  110. }
  111. }
  112. $totalv = '';
  113. foreach($totalcomment as $itemk => $itemv) {
  114. $totalv .= strip_tags(trim($itemk)).': <i>'.(floatval(sprintf('%1.1f', array_sum($itemv) / count($itemv)))).'</i> ';
  115. }
  116. if($pcid) {
  117. C::t('forum_postcomment')->update($pcid, array('comment' => $totalv, 'dateline' => TIMESTAMP + 1));
  118. } else {
  119. C::t('forum_postcomment')->insert(array(
  120. 'tid' => $post['tid'],
  121. 'pid' => $post['pid'],
  122. 'author' => '',
  123. 'authorid' => '-1',
  124. 'dateline' => TIMESTAMP + 1,
  125. 'comment' => $totalv
  126. ));
  127. }
  128. }
  129. C::t('forum_postcache')->delete($post['pid']);
  130. 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']));
  131. }
  132. if($special == 127) {
  133. $postinfo = C::t('forum_post')->fetch_threadpost_by_tid_invisible($_G['tid']);
  134. $sppos = strrpos($postinfo['message'], chr(0).chr(0).chr(0));
  135. $specialextra = substr($postinfo['message'], $sppos + 3);
  136. }
  137. if(getstatus($thread['status'], 3)) {
  138. $rushinfo = C::t('forum_threadrush')->fetch($_G['tid']);
  139. if($rushinfo['creditlimit'] != -996) {
  140. $checkcreditsvalue = $_G['setting']['creditstransextra'][11] ? getuserprofile('extcredits'.$_G['setting']['creditstransextra'][11]) : $_G['member']['credits'];
  141. if($checkcreditsvalue < $rushinfo['creditlimit']) {
  142. $creditlimit_title = $_G['setting']['creditstransextra'][11] ? $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][11]]['title'] : lang('forum/misc', 'credit_total');
  143. showmessage('post_rushreply_creditlimit', '', array('creditlimit_title' => $creditlimit_title, 'creditlimit' => $rushinfo['creditlimit']));
  144. }
  145. }
  146. }
  147. if(!submitcheck('replysubmit', 0, $seccodecheck, $secqaacheck)) {
  148. if($thread['special'] == 2 && ((!isset($_GET['addtrade']) || $thread['authorid'] != $_G['uid']) && !$tradenum = C::t('forum_trade')->fetch_counter_thread_goods($_G['tid']))) {
  149. showmessage('trade_newreply_nopermission', NULL);
  150. }
  151. $language = lang('forum/misc');
  152. $noticeauthor = $noticetrimstr = '';
  153. if(isset($_GET['repquote']) && $_GET['repquote'] = intval($_GET['repquote'])) {
  154. $thaquote = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['repquote']);
  155. if(!($thaquote && ($thaquote['invisible'] == 0 || $thaquote['authorid'] == $_G['uid'] && $thaquote['invisible'] == -2))) {
  156. $thaquote = array();
  157. }
  158. if($thaquote['tid'] != $_G['tid']) {
  159. showmessage('reply_quotepost_error', NULL);
  160. }
  161. if(getstatus($thread['status'], 2) && $thaquote['authorid'] != $_G['uid'] && $_G['uid'] != $thread['authorid'] && $thaquote['first'] != 1 && !$_G['forum']['ismoderator']) {
  162. showmessage('reply_quotepost_error', NULL);
  163. }
  164. if(!($thread['price'] && !$thread['special'] && $thaquote['first'])) {
  165. $quotefid = $thaquote['fid'];
  166. $message = $thaquote['message'];
  167. if(strpos($message, '[/password]') !== FALSE) {
  168. $message = '';
  169. }
  170. if($_G['setting']['bannedmessages'] && $thaquote['authorid']) {
  171. $author = getuserbyuid($thaquote['authorid']);
  172. if(!$author['groupid'] || $author['groupid'] == 4 || $author['groupid'] == 5) {
  173. $message = $language['post_banned'];
  174. } elseif($thaquote['status'] & 1) {
  175. $message = $language['post_single_banned'];
  176. }
  177. }
  178. $time = dgmdate($thaquote['dateline']);
  179. $message = messagecutstr($message, 100);
  180. $message = implode("\n", array_slice(explode("\n", $message), 0, 3));
  181. $thaquote['useip'] = substr($thaquote['useip'], 0, strrpos($thaquote['useip'], '.')).'.x';
  182. if($thaquote['author'] && $thaquote['anonymous']) {
  183. $thaquote['author'] = lang('forum/misc', 'anonymoususer');
  184. } elseif(!$thaquote['author']) {
  185. $thaquote['author'] = lang('forum/misc', 'guestuser').' '.$thaquote['useip'];
  186. } else {
  187. $thaquote['author'] = $thaquote['author'];
  188. }
  189. $post_reply_quote = lang('forum/misc', 'post_reply_quote', array('author' => $thaquote['author'], 'time' => $time));
  190. $noticeauthormsg = dhtmlspecialchars($message);
  191. if(!defined('IN_MOBILE')) {
  192. $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]";
  193. } else {
  194. $message = "[quote][color=#999999]{$post_reply_quote}[/color]\n[color=#999999]{$message}[/color][/quote]";
  195. }
  196. $quotemessage = discuzcode($message, 0, 0);
  197. $noticeauthor = dhtmlspecialchars(authcode('q|'.$thaquote['authorid'], 'ENCODE'));
  198. $noticetrimstr = dhtmlspecialchars($message);
  199. $message = '';
  200. }
  201. $reppid = $_GET['repquote'];
  202. } elseif(isset($_GET['reppost']) && $_GET['reppost'] = intval($_GET['reppost'])) {
  203. $thapost = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['reppost']);
  204. if(!($thapost && ($thapost['invisible'] == 0 || $thapost['authorid'] == $_G['uid'] && $thapost['invisible'] == -2))) {
  205. $thapost = array();
  206. }
  207. if($thapost['tid'] != $_G['tid']) {
  208. showmessage('targetpost_donotbelongto_thisthread', NULL);
  209. }
  210. $thapost['useip'] = substr($thapost['useip'], 0, strrpos($thapost['useip'], '.')).'.x';
  211. if($thapost['author'] && $thapost['anonymous']) {
  212. $thapost['author'] = '[color=Olive]'.lang('forum/misc', 'anonymoususer').'[/color]';
  213. } elseif(!$thapost['author']) {
  214. $thapost['author'] = '[color=Olive]'.lang('forum/misc', 'guestuser').'[/color] '.$thapost['useip'];
  215. } else {
  216. $thapost['author'] = '[color=Olive]'.$thapost['author'].'[/color]';
  217. }
  218. $quotemessage = discuzcode($message, 0, 0);
  219. $noticeauthormsg = dhtmlspecialchars(messagecutstr($thapost['message'], 100));
  220. $noticeauthor = dhtmlspecialchars(authcode('r|'.$thapost['authorid'], 'ENCODE'));
  221. $noticetrimstr = dhtmlspecialchars($message);
  222. $message = '';
  223. $reppid = $_GET['reppost'];
  224. }
  225. if(isset($_GET['addtrade']) && $thread['special'] == 2 && $_G['group']['allowposttrade'] && $thread['authorid'] == $_G['uid']) {
  226. $expiration_7days = date('Y-m-d', TIMESTAMP + 86400 * 7);
  227. $expiration_14days = date('Y-m-d', TIMESTAMP + 86400 * 14);
  228. $trade['expiration'] = $expiration_month = date('Y-m-d', mktime(0, 0, 0, date('m')+1, date('d'), date('Y')));
  229. $expiration_3months = date('Y-m-d', mktime(0, 0, 0, date('m')+3, date('d'), date('Y')));
  230. $expiration_halfyear = date('Y-m-d', mktime(0, 0, 0, date('m')+6, date('d'), date('Y')));
  231. $expiration_year = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')+1));
  232. }
  233. if($thread['replies'] <= $_G['ppp']) {
  234. $postlist = array();
  235. if($thread['price'] > 0 && $thread['special'] == 0) {
  236. $postlist = C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], $_G['tid'], true, 'DESC', 0, 0, 0, 0);
  237. } else {
  238. $postlist = C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], $_G['tid'], true, 'DESC', 0, 0, null, 0);
  239. }
  240. if($_G['setting']['bannedmessages']) {
  241. $uids = array();
  242. foreach($postlist as $post) {
  243. $uids[] = $post['authorid'];
  244. }
  245. $users = C::t('common_member')->fetch_all($uids);
  246. }
  247. foreach($postlist as $k => $post) {
  248. $post['dateline'] = dgmdate($post['dateline'], 'u');
  249. if($_G['setting']['bannedmessages'] && ($post['authorid'] && (!$post['groupid'] || $post['groupid'] == 4 || $post['groupid'] == 5))) {
  250. $post['message'] = $language['post_banned'];
  251. } elseif($post['status'] & 1) {
  252. $post['message'] = $language['post_single_banned'];
  253. } else {
  254. $post['message'] = preg_replace("/\[hide=?\d*\](.*?)\[\/hide\]/is", "[b]$language[post_hidden][/b]", $post['message']);
  255. $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']);
  256. }
  257. if($_G['setting']['bannedmessages']) {
  258. $post['groupid'] = $users[$post['authorid']]['groupid'];
  259. }
  260. $postlist[$k] = $post;
  261. }
  262. }
  263. unset($uids, $users);
  264. if($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) {
  265. $attachlist = getattach(0);
  266. $attachs = $attachlist['attachs'];
  267. $imgattachs = $attachlist['imgattachs'];
  268. unset($attachlist);
  269. }
  270. getgpc('infloat') ? include template('forum/post_infloat') : include template('forum/post');
  271. } else {
  272. $modpost = C::m('forum_post', $_G['tid']);
  273. $bfmethods = $afmethods = array();
  274. $params = array(
  275. 'subject' => $subject,
  276. 'message' => $message,
  277. 'special' => $special,
  278. 'extramessage' => $extramessage,
  279. 'bbcodeoff' => $_GET['bbcodeoff'],
  280. 'smileyoff' => $_GET['smileyoff'],
  281. 'htmlon' => $_GET['htmlon'],
  282. 'parseurloff' => $_GET['parseurloff'],
  283. 'usesig' => $_GET['usesig'],
  284. 'isanonymous' => $_GET['isanonymous'],
  285. 'noticetrimstr' => $_GET['noticetrimstr'],
  286. 'noticeauthor' => $_GET['noticeauthor'],
  287. 'from' => $_GET['from'],
  288. 'sechash' => $_GET['sechash'],
  289. 'geoloc' => diconv($_GET['geoloc'], 'UTF-8'),
  290. );
  291. if(!empty($_GET['trade']) && $thread['special'] == 2 && $_G['group']['allowposttrade']) {
  292. $bfmethods[] = array('class' => 'extend_thread_trade', 'method' => 'before_newreply');
  293. }
  294. $attentionon = empty($_GET['attention_add']) ? 0 : 1;
  295. $attentionoff = empty($attention_remove) ? 0 : 1;
  296. $bfmethods[] = array('class' => 'extend_thread_rushreply', 'method' => 'before_newreply');
  297. if($_G['group']['allowat']) {
  298. $bfmethods[] = array('class' => 'extend_thread_allowat', 'method' => 'before_newreply');
  299. }
  300. $bfmethods[] = array('class' => 'extend_thread_comment', 'method' => 'before_newreply');
  301. $modpost->attach_before_method('newreply', array('class' => 'extend_thread_filter', 'method' => 'before_newreply'));
  302. if($_G['group']['allowat']) {
  303. $afmethods[] = array('class' => 'extend_thread_allowat', 'method' => 'after_newreply');
  304. }
  305. $afmethods[] = array('class' => 'extend_thread_rushreply', 'method' => 'after_newreply');
  306. $afmethods[] = array('class' => 'extend_thread_comment', 'method' => 'after_newreply');
  307. if(helper_access::check_module('follow') && !empty($_GET['adddynamic'])) {
  308. $afmethods[] = array('class' => 'extend_thread_follow', 'method' => 'after_newreply');
  309. }
  310. if($thread['replycredit'] > 0 && $thread['authorid'] != $_G['uid'] && $_G['uid']) {
  311. $afmethods[] = array('class' => 'extend_thread_replycredit', 'method' => 'after_newreply');
  312. }
  313. if($special == 5) {
  314. $afmethods[] = array('class' => 'extend_thread_debate', 'method' => 'after_newreply');
  315. }
  316. $afmethods[] = array('class' => 'extend_thread_image', 'method' => 'after_newreply');
  317. if($special == 2 && $_G['group']['allowposttrade'] && $thread['authorid'] == $_G['uid']) {
  318. $afmethods[] = array('class' => 'extend_thread_trade', 'method' => 'after_newreply');
  319. }
  320. $afmethods[] = array('class' => 'extend_thread_filter', 'method' => 'after_newreply');
  321. if($_G['forum']['allowfeed']) {
  322. if($special == 2 && !empty($_GET['trade'])) {
  323. $modpost->attach_before_method('replyfeed', array('class' => 'extend_thread_trade', 'method' => 'before_replyfeed'));
  324. $modpost->attach_after_method('replyfeed', array('class' => 'extend_thread_trade', 'method' => 'after_replyfeed'));
  325. } elseif($special == 3 && $thread['authorid'] != $_G['uid']) {
  326. $modpost->attach_before_method('replyfeed', array('class' => 'extend_thread_reward', 'method' => 'before_replyfeed'));
  327. } elseif($special == 5 && $thread['authorid'] != $_G['uid']) {
  328. $modpost->attach_before_method('replyfeed', array('class' => 'extend_thread_debate', 'method' => 'before_replyfeed'));
  329. }
  330. }
  331. if(!isset($_GET['addfeed'])) {
  332. $space = array();
  333. space_merge($space, 'field_home');
  334. $_GET['addfeed'] = $space['privacy']['feed']['newreply'];
  335. }
  336. $modpost->attach_before_methods('newreply', $bfmethods);
  337. $modpost->attach_after_methods('newreply', $afmethods);
  338. $return = $modpost->newreply($params);
  339. $pid = $modpost->pid;
  340. if($specialextra) {
  341. @include_once DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  342. $classname = 'threadplugin_'.$specialextra;
  343. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newreply_submit_end')) {
  344. $threadpluginclass->newreply_submit_end($_G['fid'], $_G['tid']);
  345. }
  346. }
  347. if($modpost->pid && !$modpost->param('modnewreplies')) {
  348. if(!empty($_GET['addfeed'])) {
  349. $modpost->replyfeed();
  350. }
  351. }
  352. if($modpost->param('modnewreplies')) {
  353. $url = "forum.php?mod=viewthread&tid=".$_G['tid'];
  354. } else {
  355. $url = "forum.php?mod=viewthread&tid=".$_G['tid']."&pid=".$modpost->pid."&page=".$modpost->param('page')."&extra=".$extra."#pid".$modpost->pid;
  356. }
  357. if(!isset($inspacecpshare)) {
  358. showmessage($return , $url, $modpost->param('showmsgparam'));
  359. }
  360. }
  361. ?>