post_newthread.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 33695 2013-08-03 04:39:22Z nemohou $
  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['setting']['connect']['allow'] && $_G['setting']['accountguard']['postqqonly'] && !$_G['member']['conisbind']) {
  18. showmessage('postperm_qqonly_nopermission');
  19. }
  20. if(!$_G['uid'] && !((!$_G['forum']['postperm'] && $_G['group']['allowpost']) || ($_G['forum']['postperm'] && forumperm($_G['forum']['postperm'])))) {
  21. if(!defined('IN_MOBILE')) {
  22. showmessage('postperm_login_nopermission', NULL, array(), array('login' => 1));
  23. } else {
  24. showmessage('postperm_login_nopermission_mobile', NULL, array('referer' => rawurlencode(dreferer())), array('login' => 1));
  25. }
  26. } elseif(empty($_G['forum']['allowpost'])) {
  27. if(!$_G['forum']['postperm'] && !$_G['group']['allowpost']) {
  28. showmessage('postperm_none_nopermission', NULL, array(), array('login' => 1));
  29. } elseif($_G['forum']['postperm'] && !forumperm($_G['forum']['postperm'])) {
  30. showmessagenoperm('postperm', $_G['fid'], $_G['forum']['formulaperm']);
  31. }
  32. } elseif($_G['forum']['allowpost'] == -1) {
  33. showmessage('post_forum_newthread_nopermission', NULL);
  34. }
  35. if(!$_G['uid'] && ($_G['setting']['need_avatar'] || $_G['setting']['need_email'] || $_G['setting']['need_friendnum'])) {
  36. showmessage('postperm_login_nopermission', NULL, array(), array('login' => 1));
  37. }
  38. checklowerlimit('post', 0, 1, $_G['forum']['fid']);
  39. if(!submitcheck('topicsubmit', 0, $seccodecheck, $secqaacheck)) {
  40. $st_t = $_G['uid'].'|'.TIMESTAMP;
  41. dsetcookie('st_t', $st_t.'|'.md5($st_t.$_G['config']['security']['authkey']));
  42. if(helper_access::check_module('group')) {
  43. $mygroups = $groupids = array();
  44. $groupids = C::t('forum_groupuser')->fetch_all_fid_by_uids($_G['uid']);
  45. array_slice($groupids, 0, 20);
  46. $query = C::t('forum_forum')->fetch_all_info_by_fids($groupids);
  47. foreach($query as $group) {
  48. $mygroups[$group['fid']] = $group['name'];
  49. }
  50. }
  51. $savethreads = array();
  52. $savethreadothers = array();
  53. foreach(C::t('forum_post')->fetch_all_by_authorid(0, $_G['uid'], false, '', 0, 20, 1, -3) as $savethread) {
  54. $savethread['dateline'] = dgmdate($savethread['dateline'], 'u');
  55. if($_G['fid'] == $savethread['fid']) {
  56. $savethreads[] = $savethread;
  57. } else {
  58. $savethreadothers[] = $savethread;
  59. }
  60. }
  61. $savethreadcount = count($savethreads);
  62. $savethreadothercount = count($savethreadothers);
  63. if($savethreadothercount) {
  64. loadcache('forums');
  65. }
  66. $savecount = $savethreadcount + $savethreadothercount;
  67. unset($savethread);
  68. $isfirstpost = 1;
  69. $allownoticeauthor = 1;
  70. $tagoffcheck = '';
  71. $showthreadsorts = !empty($sortid) || $_G['forum']['threadsorts']['required'] && empty($special);
  72. if(empty($sortid) && empty($special) && $_G['forum']['threadsorts']['required'] && $_G['forum']['threadsorts']['types']) {
  73. $tmp = array_keys($_G['forum']['threadsorts']['types']);
  74. $sortid = $tmp[0];
  75. require_once libfile('post/threadsorts', 'include');
  76. }
  77. if($special == 2 && $_G['group']['allowposttrade']) {
  78. $expiration_7days = date('Y-m-d', TIMESTAMP + 86400 * 7);
  79. $expiration_14days = date('Y-m-d', TIMESTAMP + 86400 * 14);
  80. $trade['expiration'] = $expiration_month = date('Y-m-d', mktime(0, 0, 0, date('m')+1, date('d'), date('Y')));
  81. $expiration_3months = date('Y-m-d', mktime(0, 0, 0, date('m')+3, date('d'), date('Y')));
  82. $expiration_halfyear = date('Y-m-d', mktime(0, 0, 0, date('m')+6, date('d'), date('Y')));
  83. $expiration_year = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')+1));
  84. } elseif($specialextra) {
  85. $threadpluginclass = null;
  86. if(isset($_G['setting']['threadplugins'][$specialextra]['module'])) {
  87. $threadpluginfile = DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  88. if(file_exists($threadpluginfile)) {
  89. @include_once $threadpluginfile;
  90. $classname = 'threadplugin_'.$specialextra;
  91. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newthread')) {
  92. $threadplughtml = $threadpluginclass->newthread($_G['fid']);
  93. $buttontext = lang('plugin/'.$specialextra, $threadpluginclass->buttontext);
  94. $iconfile = $threadpluginclass->iconfile;
  95. $iconsflip = array_flip($_G['cache']['icons']);
  96. $thread['iconid'] = $iconsflip[$iconfile];
  97. }
  98. }
  99. }
  100. if(!is_object($threadpluginclass)) {
  101. $specialextra = '';
  102. }
  103. }
  104. if($special == 4) {
  105. $activity = array('starttimeto' => '', 'starttimefrom' => '', 'place' => '', 'class' => '', 'cost' => '', 'number' => '', 'gender' => '', 'expiration' => '');
  106. $activitytypelist = $_G['setting']['activitytype'] ? explode("\n", trim($_G['setting']['activitytype'])) : '';
  107. }
  108. if($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) {
  109. $attachlist = getattach(0);
  110. $attachs = $attachlist['attachs'];
  111. $imgattachs = $attachlist['imgattachs'];
  112. unset($attachlist);
  113. }
  114. !isset($attachs['unused']) && $attachs['unused'] = array();
  115. !isset($imgattachs['unused']) && $imgattachs['unused'] = array();
  116. getgpc('infloat') ? include template('forum/post_infloat') : include template('forum/post');
  117. } else {
  118. if($_GET['mygroupid']) {
  119. $mygroupid = explode('__', $_GET['mygroupid']);
  120. $mygid = intval($mygroupid[0]);
  121. if($mygid) {
  122. $mygname = $mygroupid[1];
  123. if(count($mygroupid) > 2) {
  124. unset($mygroupid[0]);
  125. $mygname = implode('__', $mygroupid);
  126. }
  127. $message .= '[groupid='.intval($mygid).']'.$mygname.'[/groupid]';
  128. C::t('forum_forum')->update_commoncredits(intval($mygroupid[0]));
  129. }
  130. }
  131. $modthread = C::m('forum_thread');
  132. $bfmethods = $afmethods = array();
  133. $params = array(
  134. 'subject' => $subject,
  135. 'message' => $message,
  136. 'typeid' => $typeid,
  137. 'sortid' => $sortid,
  138. 'special' => $special,
  139. );
  140. $_GET['save'] = $_G['uid'] ? $_GET['save'] : 0;
  141. if ($_G['group']['allowsetpublishdate'] && $_GET['cronpublish'] && $_GET['cronpublishdate']) {
  142. $publishdate = strtotime($_GET['cronpublishdate']);
  143. if ($publishdate > $_G['timestamp']) {
  144. $_GET['save'] = 1;
  145. } else {
  146. $publishdate = $_G['timestamp'];
  147. }
  148. } else {
  149. $publishdate = $_G['timestamp'];
  150. }
  151. $params['publishdate'] = $publishdate;
  152. $params['save'] = $_GET['save'];
  153. $params['sticktopic'] = $_GET['sticktopic'];
  154. $params['digest'] = $_GET['addtodigest'];
  155. $params['readperm'] = $readperm;
  156. $params['isanonymous'] = $_GET['isanonymous'];
  157. $params['price'] = $_GET['price'];
  158. if(in_array($special, array(1, 2, 3, 4, 5))) {
  159. $specials = array(
  160. 1 => 'extend_thread_poll',
  161. 2 => 'extend_thread_trade',
  162. 3 => 'extend_thread_reward',
  163. 4 => 'extend_thread_activity',
  164. 5 => 'extend_thread_debate'
  165. );
  166. $bfmethods[] = array('class' => $specials[$special], 'method' => 'before_newthread');
  167. $afmethods[] = array('class' => $specials[$special], 'method' => 'after_newthread');
  168. if(!empty($_GET['addfeed'])) {
  169. $modthread->attach_before_method('feed', array('class' => $specials[$special], 'method' => 'before_feed'));
  170. if($special == 2) {
  171. $modthread->attach_before_method('feed', array('class' => $specials[$special], 'method' => 'before_replyfeed'));
  172. }
  173. }
  174. }
  175. if($special == 1) {
  176. } elseif($special == 3) {
  177. } elseif($special == 4) {
  178. } elseif($special == 5) {
  179. } elseif($specialextra) {
  180. @include_once DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  181. $classname = 'threadplugin_'.$specialextra;
  182. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newthread_submit')) {
  183. $threadpluginclass->newthread_submit($_G['fid']);
  184. }
  185. $special = 127;
  186. $params['special'] = 127;
  187. $params['message'] .= chr(0).chr(0).chr(0).$specialextra;
  188. }
  189. $params['typeexpiration'] = $_GET['typeexpiration'];
  190. $params['ordertype'] = $_GET['ordertype'];
  191. $params['hiddenreplies'] = $_GET['hiddenreplies'];
  192. $params['allownoticeauthor'] = $_GET['allownoticeauthor'];
  193. $params['tags'] = $_GET['tags'];
  194. $params['bbcodeoff'] = $_GET['bbcodeoff'];
  195. $params['smileyoff'] = $_GET['smileyoff'];
  196. $params['parseurloff'] = $_GET['parseurloff'];
  197. $params['usesig'] = $_GET['usesig'];
  198. $params['htmlon'] = $_GET['htmlon'];
  199. if($_G['group']['allowimgcontent']) {
  200. $params['imgcontent'] = $_GET['imgcontent'];
  201. $params['imgcontentwidth'] = $_G['setting']['imgcontentwidth'] ? intval($_G['setting']['imgcontentwidth']) : 100;
  202. }
  203. $params['geoloc'] = diconv($_GET['geoloc'], 'UTF-8');
  204. if($_GET['rushreply']) {
  205. $bfmethods[] = array('class' => 'extend_thread_rushreply', 'method' => 'before_newthread');
  206. $afmethods[] = array('class' => 'extend_thread_rushreply', 'method' => 'after_newthread');
  207. }
  208. $bfmethods[] = array('class' => 'extend_thread_replycredit', 'method' => 'before_newthread');
  209. $afmethods[] = array('class' => 'extend_thread_replycredit', 'method' => 'after_newthread');
  210. if($sortid) {
  211. $bfmethods[] = array('class' => 'extend_thread_sort', 'method' => 'before_newthread');
  212. $afmethods[] = array('class' => 'extend_thread_sort', 'method' => 'after_newthread');
  213. }
  214. $bfmethods[] = array('class' => 'extend_thread_allowat', 'method' => 'before_newthread');
  215. $afmethods[] = array('class' => 'extend_thread_allowat', 'method' => 'after_newthread');
  216. $afmethods[] = array('class' => 'extend_thread_image', 'method' => 'after_newthread');
  217. if(!empty($_GET['adddynamic'])) {
  218. $afmethods[] = array('class' => 'extend_thread_follow', 'method' => 'after_newthread');
  219. }
  220. $modthread->attach_before_methods('newthread', $bfmethods);
  221. $modthread->attach_after_methods('newthread', $afmethods);
  222. $return = $modthread->newthread($params);
  223. $tid = $modthread->tid;
  224. $pid = $modthread->pid;
  225. dsetcookie('clearUserdata', 'forum');
  226. if($specialextra) {
  227. $classname = 'threadplugin_'.$specialextra;
  228. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newthread_submit_end')) {
  229. $threadpluginclass->newthread_submit_end($_G['fid'], $modthread->tid);
  230. }
  231. }
  232. if(!$modthread->param('modnewthreads') && !empty($_GET['addfeed'])) {
  233. $modthread->feed();
  234. }
  235. if(!empty($_G['setting']['rewriterule']['forum_viewthread']) && in_array('forum_viewthread', $_G['setting']['rewritestatus'])) {
  236. $returnurl = rewriteoutput('forum_viewthread', 1, '', $modthread->tid, 1, '', $extra);
  237. } else {
  238. $returnurl = "forum.php?mod=viewthread&tid={$modthread->tid}&extra=$extra";
  239. }
  240. $values = array('fid' => $modthread->forum('fid'), 'tid' => $modthread->tid, 'pid' => $modthread->pid, 'coverimg' => '', 'sechash' => !empty($_GET['sechash']) ? $_GET['sechash'] : '');
  241. showmessage($return, $returnurl, array_merge($values, (array)$modthread->param('values')), $modthread->param('param'));
  242. }
  243. ?>