forum_post.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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: forum_post.php 36293 2016-12-14 02:50:56Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. define('NOROBOT', TRUE);
  12. cknewuser();
  13. require_once libfile('class/credit');
  14. require_once libfile('function/post');
  15. $pid = intval(getgpc('pid'));
  16. $sortid = intval(getgpc('sortid'));
  17. $typeid = intval(getgpc('typeid'));
  18. $special = intval(getgpc('special'));
  19. parse_str($_GET['extra'], $_GET['extra']);
  20. $_GET['extra'] = http_build_query($_GET['extra']);
  21. $postinfo = array('subject' => '');
  22. $thread = array('readperm' => '', 'pricedisplay' => '', 'hiddenreplies' => '');
  23. $_G['forum_dtype'] = $_G['forum_checkoption'] = $_G['forum_optionlist'] = $tagarray = $_G['forum_typetemplate'] = array();
  24. if($sortid) {
  25. require_once libfile('post/threadsorts', 'include');
  26. }
  27. if($_G['forum']['status'] == 3) {
  28. if(!helper_access::check_module('group')) {
  29. showmessage('group_status_off');
  30. }
  31. require_once libfile('function/group');
  32. $status = groupperm($_G['forum'], $_G['uid'], 'post');
  33. if($status == -1) {
  34. showmessage('forum_not_group', 'index.php');
  35. } elseif($status == 1) {
  36. showmessage('forum_group_status_off');
  37. } elseif($status == 2) {
  38. showmessage('forum_group_noallowed', "forum.php?mod=group&fid=$_G[fid]");
  39. } elseif($status == 3) {
  40. showmessage('forum_group_moderated');
  41. } elseif($status == 4) {
  42. if($_G['uid']) {
  43. showmessage('forum_group_not_groupmember', "", array('fid' => $_G['fid']), array('showmsg' => 1));
  44. } else {
  45. showmessage('forum_group_not_groupmember_guest', "", array('fid' => $_G['fid']), array('showmsg' => 1, 'login' => 1));
  46. }
  47. } elseif($status == 5) {
  48. showmessage('forum_group_moderated', "", array('fid' => $_G['fid']), array('showmsg' => 1));
  49. }
  50. }
  51. if(empty($_GET['action'])) {
  52. showmessage('undefined_action', NULL);
  53. } elseif($_GET['action'] == 'albumphoto') {
  54. require libfile('post/albumphoto', 'include');
  55. } elseif(($_G['forum']['simple'] & 1) || $_G['forum']['redirect']) {
  56. showmessage('forum_disablepost');
  57. }
  58. require_once libfile('function/discuzcode');
  59. $space = array();
  60. space_merge($space, 'field_home');
  61. if($_GET['action'] == 'reply') {
  62. $addfeedcheck = !empty($space['privacy']['feed']['newreply']) ? 'checked="checked"': '';
  63. } else {
  64. $addfeedcheck = !empty($space['privacy']['feed']['newthread']) ? 'checked="checked"': '';
  65. }
  66. $navigation = $navtitle = '';
  67. if(!empty($_GET['cedit'])) {
  68. unset($_G['inajax'], $_GET['infloat'], $_GET['ajaxtarget'], $_GET['handlekey']);
  69. }
  70. if($_GET['action'] == 'edit' || $_GET['action'] == 'reply') {
  71. $thread = C::t('forum_thread')->fetch($_G['tid']);
  72. if(!$_G['forum_auditstatuson'] && !($thread['displayorder']>=0 || (in_array($thread['displayorder'], array(-4, -2)) && $thread['authorid']==$_G['uid']))) {
  73. $thread = array();
  74. }
  75. if(!empty($thread)) {
  76. if($thread['readperm'] && $thread['readperm'] > $_G['group']['readaccess'] && !$_G['forum']['ismoderator'] && $thread['authorid'] != $_G['uid']) {
  77. showmessage('thread_nopermission', NULL, array('readperm' => $thread['readperm']), array('login' => 1));
  78. }
  79. $_G['fid'] = $thread['fid'];
  80. $special = $thread['special'];
  81. } else {
  82. showmessage('thread_nonexistence');
  83. }
  84. if($thread['closed'] == 1 && !$_G['forum']['ismoderator']) {
  85. showmessage('post_thread_closed');
  86. }
  87. }
  88. if($_G['forum']['status'] == 3) {
  89. $returnurl = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].(!empty($_GET['extra']) ? '&action=list&'.preg_replace("/^(&)*/", '', $_GET['extra']) : '').'#groupnav';
  90. $nav = get_groupnav($_G['forum']);
  91. $navigation = ' <em>&rsaquo;</em> <a href="group.php">'.$_G['setting']['navs'][3]['navname'].'</a> '.$nav['nav'];
  92. } else {
  93. loadcache('forums');
  94. $returnurl = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].(!empty($_GET['extra']) ? '&'.preg_replace("/^(&)*/", '', $_GET['extra']) : '');
  95. $navigation = ' <em>&rsaquo;</em> <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a>';
  96. if($_G['forum']['type'] == 'sub') {
  97. $fup = $_G['cache']['forums'][$_G['forum']['fup']]['fup'];
  98. $t_link = $_G['cache']['forums'][$fup]['type'] == 'group' ? 'forum.php?gid='.$fup : 'forum.php?mod=forumdisplay&fid='.$fup;
  99. $navigation .= ' <em>&rsaquo;</em> <a href="'.$t_link.'">'.($_G['cache']['forums'][$fup]['name']).'</a>';
  100. }
  101. if($_G['forum']['fup']) {
  102. $fup = $_G['forum']['fup'];
  103. $t_link = $_G['cache']['forums'][$fup]['type'] == 'group' ? 'forum.php?gid='.$fup : 'forum.php?mod=forumdisplay&fid='.$fup;
  104. $navigation .= ' <em>&rsaquo;</em> <a href="'.$t_link.'">'.($_G['cache']['forums'][$fup]['name']).'</a>';
  105. }
  106. $t_link = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].($_GET['extra'] && !IS_ROBOT ? '&'.$_GET['extra'] : '');
  107. $navigation .= ' <em>&rsaquo;</em> <a href="'.$t_link.'">'.($_G['forum']['name']).'</a>';
  108. unset($t_link, $t_name);
  109. }
  110. periodscheck('postbanperiods');
  111. if($_G['forum']['password'] && $_G['forum']['password'] != $_G['cookie']['fidpw'.$_G['fid']]) {
  112. showmessage('forum_passwd', "forum.php?mod=forumdisplay&fid=$_G[fid]");
  113. }
  114. if(empty($_G['forum']['allowview'])) {
  115. if(!$_G['forum']['viewperm'] && !$_G['group']['readaccess']) {
  116. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  117. } elseif($_G['forum']['viewperm'] && !forumperm($_G['forum']['viewperm'])) {
  118. showmessagenoperm('viewperm', $_G['fid']);
  119. }
  120. } elseif($_G['forum']['allowview'] == -1) {
  121. showmessage('forum_access_view_disallow');
  122. }
  123. formulaperm($_G['forum']['formulaperm']);
  124. if(!$_G['adminid'] && $_G['setting']['newbiespan'] && (!getuserprofile('lastpost') || TIMESTAMP - getuserprofile('lastpost') < $_G['setting']['newbiespan'] * 60) && TIMESTAMP - $_G['member']['regdate'] < $_G['setting']['newbiespan'] * 60) {
  125. showmessage('post_newbie_span', '', array('newbiespan' => $_G['setting']['newbiespan']));
  126. }
  127. $special = $special > 0 && $special < 7 || $special == 127 ? intval($special) : 0;
  128. $_G['forum']['allowpostattach'] = isset($_G['forum']['allowpostattach']) ? $_G['forum']['allowpostattach'] : '';
  129. $_G['group']['allowpostattach'] = $_G['forum']['allowpostattach'] != -1 && ($_G['forum']['allowpostattach'] == 1 || (!$_G['forum']['postattachperm'] && $_G['group']['allowpostattach']) || ($_G['forum']['postattachperm'] && forumperm($_G['forum']['postattachperm'])));
  130. $_G['forum']['allowpostimage'] = isset($_G['forum']['allowpostimage']) ? $_G['forum']['allowpostimage'] : '';
  131. $_G['group']['allowpostimage'] = $_G['forum']['allowpostimage'] != -1 && ($_G['forum']['allowpostimage'] == 1 || (!$_G['forum']['postimageperm'] && $_G['group']['allowpostimage']) || ($_G['forum']['postimageperm'] && forumperm($_G['forum']['postimageperm'])));
  132. $_G['group']['attachextensions'] = $_G['forum']['attachextensions'] ? $_G['forum']['attachextensions'] : $_G['group']['attachextensions'];
  133. require_once libfile('function/upload');
  134. $swfconfig = getuploadconfig($_G['uid'], $_G['fid']);
  135. $imgexts = str_replace(array(';', '*.'), array(', ', ''), $swfconfig['imageexts']['ext']);
  136. $allowuploadnum = $allowuploadtoday = TRUE;
  137. if($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) {
  138. if($_G['group']['maxattachnum']) {
  139. $allowuploadnum = $_G['group']['maxattachnum'] - getuserprofile('todayattachs');
  140. $allowuploadnum = $allowuploadnum < 0 ? 0 : $allowuploadnum;
  141. if(!$allowuploadnum) {
  142. $allowuploadtoday = false;
  143. }
  144. }
  145. if($_G['group']['maxsizeperday']) {
  146. $allowuploadsize = $_G['group']['maxsizeperday'] - getuserprofile('todayattachsize');
  147. $allowuploadsize = $allowuploadsize < 0 ? 0 : $allowuploadsize;
  148. if(!$allowuploadsize) {
  149. $allowuploadtoday = false;
  150. }
  151. $allowuploadsize = $allowuploadsize / 1048576 >= 1 ? round(($allowuploadsize / 1048576), 1).'MB' : round(($allowuploadsize / 1024)).'KB';
  152. }
  153. }
  154. $allowpostimg = $_G['group']['allowpostimage'] && $imgexts;
  155. $enctype = ($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) ? 'enctype="multipart/form-data"' : '';
  156. $maxattachsize_mb = $_G['group']['maxattachsize'] / 1048576 >= 1 ? round(($_G['group']['maxattachsize'] / 1048576), 1).'MB' : round(($_G['group']['maxattachsize'] / 1024)).'KB';
  157. $_G['group']['maxprice'] = isset($_G['setting']['extcredits'][$_G['setting']['creditstrans']]) ? $_G['group']['maxprice'] : 0;
  158. $extra = !empty($_GET['extra']) ? rawurlencode($_GET['extra']) : '';
  159. $notifycheck = empty($emailnotify) ? '' : 'checked="checked"';
  160. $stickcheck = empty($sticktopic) ? '' : 'checked="checked"';
  161. $digestcheck = empty($addtodigest) ? '' : 'checked="checked"';
  162. $subject = isset($_GET['subject']) ? dhtmlspecialchars(censor(trim($_GET['subject']))) : '';
  163. $subject = !empty($subject) ? str_replace("\t", ' ', $subject) : $subject;
  164. $message = isset($_GET['message']) ? censor($_GET['message']) : '';
  165. $polloptions = isset($polloptions) ? censor(trim($polloptions)) : '';
  166. $readperm = isset($_GET['readperm']) ? intval($_GET['readperm']) : 0;
  167. $price = isset($_GET['price']) ? intval($_GET['price']) : 0;
  168. if(empty($bbcodeoff) && !$_G['group']['allowhidecode'] && !empty($message) && preg_match("/\[hide=?d?\d*,?\d*\].*?\[\/hide\]/is", preg_replace("/(\[code\](.+?)\[\/code\])/is", ' ', $message))) {
  169. showmessage('post_hide_nopermission');
  170. }
  171. $urloffcheck = $usesigcheck = $smileyoffcheck = $codeoffcheck = $htmloncheck = $emailcheck = '';
  172. list($seccodecheck, $secqaacheck) = seccheck('post', $_GET['action']);
  173. $_G['group']['allowpostpoll'] = $_G['group']['allowpost'] && $_G['group']['allowpostpoll'] && ($_G['forum']['allowpostspecial'] & 1);
  174. $_G['group']['allowposttrade'] = $_G['group']['allowpost'] && $_G['group']['allowposttrade'] && ($_G['forum']['allowpostspecial'] & 2);
  175. $_G['group']['allowpostreward'] = $_G['group']['allowpost'] && $_G['group']['allowpostreward'] && ($_G['forum']['allowpostspecial'] & 4);
  176. $_G['group']['allowpostactivity'] = $_G['group']['allowpost'] && $_G['group']['allowpostactivity'] && ($_G['forum']['allowpostspecial'] & 8);
  177. $_G['group']['allowpostdebate'] = $_G['group']['allowpost'] && $_G['group']['allowpostdebate'] && ($_G['forum']['allowpostspecial'] & 16);
  178. $usesigcheck = $_G['uid'] && $_G['group']['maxsigsize'] ? 'checked="checked"' : '';
  179. $ordertypecheck = !empty($thread['tid']) && getstatus($thread['status'], 4) ? 'checked="checked"' : '';
  180. $imgcontentcheck = !empty($thread['tid']) && getstatus($thread['status'], 15) ? 'checked="checked"' : '';
  181. $specialextra = !empty($_GET['specialextra']) ? $_GET['specialextra'] : '';
  182. $_G['forum']['threadplugin'] = dunserialize($_G['forum']['threadplugin']);
  183. if($specialextra && $_G['group']['allowpost'] && $_G['setting']['threadplugins'] &&
  184. (!array_key_exists($specialextra, $_G['setting']['threadplugins']) ||
  185. !@in_array($specialextra, is_array($_G['forum']['threadplugin']) ? $_G['forum']['threadplugin'] : dunserialize($_G['forum']['threadplugin'])) ||
  186. !@in_array($specialextra, $_G['group']['allowthreadplugin']))) {
  187. $specialextra = '';
  188. }
  189. if($special == 3 && !isset($_G['setting']['extcredits'][$_G['setting']['creditstrans']])) {
  190. showmessage('reward_credits_closed');
  191. }
  192. $_G['group']['allowanonymous'] = $_G['forum']['allowanonymous'] || $_G['group']['allowanonymous'] ? 1 : 0;
  193. if($_GET['action'] == 'newthread' && $_G['forum']['allowspecialonly'] && !$special) {
  194. if($_G['group']['allowpostpoll']) {
  195. $special = 1;
  196. } elseif($_G['group']['allowposttrade']) {
  197. $special = 2;
  198. } elseif($_G['group']['allowpostreward']) {
  199. $special = 3;
  200. } elseif($_G['group']['allowpostactivity']) {
  201. $special = 4;
  202. } elseif($_G['group']['allowpostdebate']) {
  203. $special = 5;
  204. } elseif($_G['group']['allowpost'] && $_G['setting']['threadplugins'] && $_G['group']['allowthreadplugin']) {
  205. if(empty($_GET['specialextra'])) {
  206. foreach($_G['forum']['threadplugin'] as $tpid) {
  207. if(array_key_exists($tpid, $_G['setting']['threadplugins']) && @in_array($tpid, $_G['group']['allowthreadplugin'])){
  208. $specialextra=$tpid;
  209. break;
  210. }
  211. }
  212. }
  213. $threadpluginary = array_intersect($_G['forum']['threadplugin'], $_G['group']['allowthreadplugin']);
  214. $specialextra = in_array($specialextra, $threadpluginary) ? $specialextra : '';
  215. }
  216. if(!$special && !$specialextra) {
  217. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  218. }
  219. }
  220. if(!$sortid && !$specialextra) {
  221. $postspecialcheck[$special] = ' class="a"';
  222. }
  223. $editorid = 'e';
  224. $_G['setting']['editoroptions'] = str_pad(decbin($_G['setting']['editoroptions']), 3, 0, STR_PAD_LEFT);
  225. $editormode = $_G['setting']['editoroptions']{0};
  226. $allowswitcheditor = $_G['setting']['editoroptions']{1};
  227. $editor = array(
  228. 'editormode' => $editormode,
  229. 'allowswitcheditor' => $allowswitcheditor,
  230. 'allowhtml' => $_G['forum']['allowhtml'],
  231. 'allowsmilies' => $_G['forum']['allowsmilies'],
  232. 'allowbbcode' => $_G['forum']['allowbbcode'],
  233. 'allowimgcode' => $_G['forum']['allowimgcode'],
  234. 'allowresize' => 1,
  235. 'allowchecklength' => 1,
  236. 'allowtopicreset' => 1,
  237. 'textarea' => 'message',
  238. 'simplemode' => !isset($_G['cookie']['editormode_'.$editorid]) ? !$_G['setting']['editoroptions']{2} : $_G['cookie']['editormode_'.$editorid],
  239. );
  240. if($specialextra) {
  241. $special = 127;
  242. }
  243. if($_GET['action'] == 'newthread') {
  244. $policykey = 'post';
  245. } elseif($_GET['action'] == 'reply') {
  246. $policykey = 'reply';
  247. } else {
  248. $policykey = '';
  249. }
  250. if($policykey) {
  251. $postcredits = $_G['forum'][$policykey.'credits'] ? $_G['forum'][$policykey.'credits'] : $_G['setting']['creditspolicy'][$policykey];
  252. }
  253. $albumlist = array();
  254. if(helper_access::check_module('album') && $_G['group']['allowupload'] && $_G['uid']) {
  255. $query = C::t('home_album')->fetch_all_by_uid($_G['uid'], 'updatetime');
  256. foreach($query as $value) {
  257. if($value['picnum']) {
  258. $albumlist[] = $value;
  259. }
  260. }
  261. }
  262. $posturl = "action=$_GET[action]&fid=$_G[fid]".
  263. (!empty($_G['tid']) ? "&tid=$_G[tid]" : '').
  264. (!empty($pid) ? "&pid=$pid" : '').
  265. (!empty($special) ? "&special=$special" : '').
  266. (!empty($sortid) ? "&sortid=$sortid" : '').
  267. (!empty($typeid) ? "&typeid=$typeid" : '').
  268. (!empty($_GET['firstpid']) ? "&firstpid=$firstpid" : '').
  269. (!empty($_GET['addtrade']) ? "&addtrade=$addtrade" : '');
  270. if($_GET['action'] == 'reply') {
  271. check_allow_action('allowreply');
  272. } else {
  273. check_allow_action('allowpost');
  274. }
  275. if($special == 4) {
  276. $_G['setting']['activityfield'] = $_G['setting']['activityfield'] ? dunserialize($_G['setting']['activityfield']) : array();
  277. }
  278. if(helper_access::check_module('album') && $_G['group']['allowupload'] && $_G['setting']['albumcategorystat'] && !empty($_G['cache']['albumcategory'])) {
  279. require_once libfile('function/portalcp');
  280. }
  281. $navtitle = lang('core', 'title_'.$_GET['action'].'_post');
  282. if($_GET['action'] == 'newthread' || $_GET['action'] == 'newtrade') {
  283. loadcache('groupreadaccess');
  284. $navtitle .= ' - '.$_G['forum']['name'];
  285. require_once libfile('post/newthread', 'include');
  286. } elseif($_GET['action'] == 'reply') {
  287. $navtitle .= ' - '.$thread['subject'].' - '.$_G['forum']['name'];
  288. require_once libfile('post/newreply', 'include');
  289. } elseif($_GET['action'] == 'edit') {
  290. loadcache('groupreadaccess');
  291. $navtitle .= ' - '.$thread['subject'].' - '.$_G['forum']['name'];
  292. require_once libfile('post/editpost', 'include');
  293. }
  294. function check_allow_action($action = 'allowpost') {
  295. global $_G;
  296. if(isset($_G['forum'][$action]) && $_G['forum'][$action] == -1) {
  297. showmessage('forum_access_disallow');
  298. }
  299. }
  300. function recent_use_tag() {
  301. $tagarray = $stringarray = array();
  302. $string = '';
  303. $i = 0;
  304. $query = C::t('common_tagitem')->select(0, 0, 'tid', 'itemid', 'DESC', 10);
  305. foreach($query as $result) {
  306. if($i > 4) {
  307. break;
  308. }
  309. if($tagarray[$result['tagid']] == '') {
  310. $i++;
  311. }
  312. $tagarray[$result['tagid']] = 1;
  313. }
  314. if($tagarray) {
  315. $query = C::t('common_tag')->fetch_all(array_keys($tagarray));
  316. foreach($query as $result) {
  317. $tagarray[$result[tagid]] = $result['tagname'];
  318. }
  319. }
  320. return $tagarray;
  321. }
  322. ?>