PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/source/include/post/post_newthread.php

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