PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/forum/Sources/Post.php

https://github.com/leftnode/nooges.com
PHP | 2884 lines | 2136 code | 383 blank | 365 comment | 642 complexity | 47f4077f1fbab1cdc40d96c3af2121a7 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**********************************************************************************
  3. * Post.php *
  4. ***********************************************************************************
  5. * SMF: Simple Machines Forum *
  6. * Open-Source Project Inspired by Zef Hemel (zef@zefhemel.com) *
  7. * =============================================================================== *
  8. * Software Version: SMF 2.0 RC2 *
  9. * Software by: Simple Machines (http://www.simplemachines.org) *
  10. * Copyright 2006-2009 by: Simple Machines LLC (http://www.simplemachines.org) *
  11. * 2001-2006 by: Lewis Media (http://www.lewismedia.com) *
  12. * Support, News, Updates at: http://www.simplemachines.org *
  13. ***********************************************************************************
  14. * This program is free software; you may redistribute it and/or modify it under *
  15. * the terms of the provided license as published by Simple Machines LLC. *
  16. * *
  17. * This program is distributed in the hope that it is and will be useful, but *
  18. * WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY *
  19. * or FITNESS FOR A PARTICULAR PURPOSE. *
  20. * *
  21. * See the "license.txt" file for details of the Simple Machines license. *
  22. * The latest version can always be found at http://www.simplemachines.org. *
  23. **********************************************************************************/
  24. if (!defined('SMF'))
  25. die('Hacking attempt...');
  26. /* The job of this file is to handle everything related to posting replies,
  27. new topics, quotes, and modifications to existing posts. It also handles
  28. quoting posts by way of javascript.
  29. void Post()
  30. - handles showing the post screen, loading the post to be modified, and
  31. loading any post quoted.
  32. - additionally handles previews of posts.
  33. - uses the Post template and language file, main sub template.
  34. - allows wireless access using the protocol_post sub template.
  35. - requires different permissions depending on the actions, but most
  36. notably post_new, post_reply_own, and post_reply_any.
  37. - shows options for the editing and posting of calendar events and
  38. attachments, as well as the posting of polls.
  39. - accessed from ?action=post.
  40. void Post2()
  41. - actually posts or saves the message composed with Post().
  42. - requires various permissions depending on the action.
  43. - handles attachment, post, and calendar saving.
  44. - sends off notifications, and allows for announcements and moderation.
  45. - accessed from ?action=post2.
  46. void AnnounceTopic()
  47. - handle the announce topic function (action=announce).
  48. - checks the topic announcement permissions and loads the announcement
  49. template.
  50. - requires the announce_topic permission.
  51. - uses the ManageMembers template and Post language file.
  52. - call the right function based on the sub-action.
  53. void AnnouncementSelectMembergroup()
  54. - lets the user select the membergroups that will receive the topic
  55. announcement.
  56. void AnnouncementSend()
  57. - splits the members to be sent a topic announcement into chunks.
  58. - composes notification messages in all languages needed.
  59. - does the actual sending of the topic announcements in chunks.
  60. - calculates a rough estimate of the percentage items sent.
  61. void notifyMembersBoard(notifyData)
  62. - notifies members who have requested notification for new topics
  63. posted on a board of said posts.
  64. - receives data on the topics to send out notifications to by the passed in array.
  65. - only sends notifications to those who can *currently* see the topic
  66. (it doesn't matter if they could when they requested notification.)
  67. - loads the Post language file multiple times for each language if the
  68. userLanguage setting is set.
  69. void getTopic()
  70. - gets a summary of the most recent posts in a topic.
  71. - depends on the topicSummaryPosts setting.
  72. - if you are editing a post, only shows posts previous to that post.
  73. void QuoteFast()
  74. - loads a post an inserts it into the current editing text box.
  75. - uses the Post language file.
  76. - uses special (sadly browser dependent) javascript to parse entities
  77. for internationalization reasons.
  78. - accessed with ?action=quotefast.
  79. void JavaScriptModify()
  80. // !!!
  81. */
  82. function Post()
  83. {
  84. global $txt, $scripturl, $topic, $modSettings, $board;
  85. global $user_info, $sc, $board_info, $context, $settings;
  86. global $sourcedir, $options, $smcFunc, $language;
  87. loadLanguage('Post');
  88. // You can't reply with a poll... hacker.
  89. if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
  90. unset($_REQUEST['poll']);
  91. // Posting an event?
  92. $context['make_event'] = isset($_REQUEST['calendar']);
  93. $context['robot_no_index'] = true;
  94. // You must be posting to *some* board.
  95. if (empty($board) && !$context['make_event'])
  96. fatal_lang_error('no_board', false);
  97. require_once($sourcedir . '/Subs-Post.php');
  98. if (isset($_REQUEST['xml']))
  99. {
  100. $context['sub_template'] = 'post';
  101. // Just in case of an earlier error...
  102. $context['preview_message'] = '';
  103. $context['preview_subject'] = '';
  104. }
  105. // No message is comlete without a topic.
  106. if (empty($topic) && !empty($_REQUEST['msg']))
  107. {
  108. $request = $smcFunc['db_query']('', '
  109. SELECT id_topic
  110. FROM {db_prefix}messages
  111. WHERE id_msg = {int:msg}',
  112. array(
  113. 'msg' => (int) $_REQUEST['msg'],
  114. ));
  115. if ($smcFunc['db_num_rows']($request) != 1)
  116. unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
  117. else
  118. list($topic) = $smcFunc['db_fetch_row']($request);
  119. $smcFunc['db_free_result']($request);
  120. }
  121. // Check if it's locked. It isn't locked if no topic is specified.
  122. if (!empty($topic))
  123. {
  124. $request = $smcFunc['db_query']('', '
  125. SELECT
  126. t.locked, IFNULL(ln.id_topic, 0) AS notify, t.is_sticky, t.id_poll, t.num_replies, mf.id_member,
  127. t.id_first_msg, mf.subject,
  128. CASE WHEN ml.poster_time > ml.modified_time THEN ml.poster_time ELSE ml.modified_time END AS last_post_time
  129. FROM {db_prefix}topics AS t
  130. LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_topic = t.id_topic AND ln.id_member = {int:current_member})
  131. LEFT JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
  132. LEFT JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  133. WHERE t.id_topic = {int:current_topic}
  134. LIMIT 1',
  135. array(
  136. 'current_member' => $user_info['id'],
  137. 'current_topic' => $topic,
  138. )
  139. );
  140. list ($locked, $context['notify'], $sticky, $pollID, $context['num_replies'], $ID_MEMBER_POSTER, $id_first_msg, $first_subject, $lastPostTime) = $smcFunc['db_fetch_row']($request);
  141. $smcFunc['db_free_result']($request);
  142. // If this topic already has a poll, they sure can't add another.
  143. if (isset($_REQUEST['poll']) && $pollID > 0)
  144. unset($_REQUEST['poll']);
  145. if (empty($_REQUEST['msg']))
  146. {
  147. if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
  148. is_not_guest();
  149. // By default the reply will be approved...
  150. $context['becomes_approved'] = true;
  151. if ($ID_MEMBER_POSTER != $user_info['id'])
  152. {
  153. if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
  154. $context['becomes_approved'] = false;
  155. else
  156. isAllowedTo('post_reply_any');
  157. }
  158. elseif (!allowedTo('post_reply_any'))
  159. {
  160. if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
  161. $context['becomes_approved'] = false;
  162. else
  163. isAllowedTo('post_reply_own');
  164. }
  165. }
  166. else
  167. $context['becomes_approved'] = true;
  168. $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $ID_MEMBER_POSTER && allowedTo('lock_own'));
  169. $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);
  170. $context['notify'] = !empty($context['notify']);
  171. $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
  172. }
  173. else
  174. {
  175. $context['becomes_approved'] = true;
  176. if ((!$context['make_event'] || !empty($board)))
  177. {
  178. if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
  179. $context['becomes_approved'] = false;
  180. else
  181. isAllowedTo('post_new');
  182. }
  183. $locked = 0;
  184. // !!! These won't work if you're making an event.
  185. $context['can_lock'] = allowedTo(array('lock_any', 'lock_own'));
  186. $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);
  187. $context['notify'] = !empty($context['notify']);
  188. $context['sticky'] = !empty($_REQUEST['sticky']);
  189. }
  190. // !!! These won't work if you're posting an event!
  191. $context['can_notify'] = allowedTo('mark_any_notify');
  192. $context['can_move'] = allowedTo('move_any');
  193. $context['move'] = !empty($_REQUEST['move']);
  194. $context['announce'] = !empty($_REQUEST['announce']);
  195. // You can only annouce topics that will get approved...
  196. $context['can_announce'] = allowedTo('announce_topic') && $context['becomes_approved'];
  197. $context['locked'] = !empty($locked) || !empty($_REQUEST['lock']);
  198. // Generally don't show the approval box... (Assume we want things approved)
  199. $context['show_approval'] = false;
  200. // An array to hold all the attachments for this topic.
  201. $context['current_attachments'] = array();
  202. // Don't allow a post if it's locked and you aren't all powerful.
  203. if ($locked && !allowedTo('moderate_board'))
  204. fatal_lang_error('topic_locked', false);
  205. // Check the users permissions - is the user allowed to add or post a poll?
  206. if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
  207. {
  208. // New topic, new poll.
  209. if (empty($topic))
  210. isAllowedTo('poll_post');
  211. // This is an old topic - but it is yours! Can you add to it?
  212. elseif ($user_info['id'] == $ID_MEMBER_POSTER && !allowedTo('poll_add_any'))
  213. isAllowedTo('poll_add_own');
  214. // If you're not the owner, can you add to any poll?
  215. else
  216. isAllowedTo('poll_add_any');
  217. require_once($sourcedir . '/Subs-Members.php');
  218. $allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
  219. // Set up the poll options.
  220. $context['poll_options'] = array(
  221. 'max_votes' => empty($_POST['poll_max_votes']) ? '1' : max(1, $_POST['poll_max_votes']),
  222. 'hide' => empty($_POST['poll_hide']) ? 0 : $_POST['poll_hide'],
  223. 'expire' => !isset($_POST['poll_expire']) ? '' : $_POST['poll_expire'],
  224. 'change_vote' => isset($_POST['poll_change_vote']),
  225. 'guest_vote' => isset($_POST['poll_guest_vote']),
  226. 'guest_vote_enabled' => in_array(-1, $allowedVoteGroups['allowed']),
  227. );
  228. // Make all five poll choices empty.
  229. $context['choices'] = array(
  230. array('id' => 0, 'number' => 1, 'label' => '', 'is_last' => false),
  231. array('id' => 1, 'number' => 2, 'label' => '', 'is_last' => false),
  232. array('id' => 2, 'number' => 3, 'label' => '', 'is_last' => false),
  233. array('id' => 3, 'number' => 4, 'label' => '', 'is_last' => false),
  234. array('id' => 4, 'number' => 5, 'label' => '', 'is_last' => true)
  235. );
  236. }
  237. if ($context['make_event'])
  238. {
  239. // They might want to pick a board.
  240. if (!isset($context['current_board']))
  241. $context['current_board'] = 0;
  242. // Start loading up the event info.
  243. $context['event'] = array();
  244. $context['event']['title'] = isset($_REQUEST['evtitle']) ? htmlspecialchars(stripslashes($_REQUEST['evtitle'])) : '';
  245. $context['event']['id'] = isset($_REQUEST['eventid']) ? (int) $_REQUEST['eventid'] : -1;
  246. $context['event']['new'] = $context['event']['id'] == -1;
  247. // Permissions check!
  248. isAllowedTo('calendar_post');
  249. // Editing an event? (but NOT previewing!?)
  250. if (!$context['event']['new'] && !isset($_REQUEST['subject']))
  251. {
  252. // If the user doesn't have permission to edit the post in this topic, redirect them.
  253. if (($ID_MEMBER_POSTER != $user_info['id'] || !allowedTo('modify_own')) && !allowedTo('modify_any'))
  254. {
  255. require_once($sourcedir . '/Calendar.php');
  256. return CalendarPost();
  257. }
  258. // Get the current event information.
  259. $request = $smcFunc['db_query']('', '
  260. SELECT
  261. id_member, title, MONTH(start_date) AS month, DAYOFMONTH(start_date) AS day,
  262. YEAR(start_date) AS year, (TO_DAYS(end_date) - TO_DAYS(start_date)) AS span
  263. FROM {db_prefix}calendar
  264. WHERE id_event = {int:id_event}
  265. LIMIT 1',
  266. array(
  267. 'id_event' => $context['event']['id'],
  268. )
  269. );
  270. $row = $smcFunc['db_fetch_assoc']($request);
  271. $smcFunc['db_free_result']($request);
  272. // Make sure the user is allowed to edit this event.
  273. if ($row['id_member'] != $user_info['id'])
  274. isAllowedTo('calendar_edit_any');
  275. elseif (!allowedTo('calendar_edit_any'))
  276. isAllowedTo('calendar_edit_own');
  277. $context['event']['month'] = $row['month'];
  278. $context['event']['day'] = $row['day'];
  279. $context['event']['year'] = $row['year'];
  280. $context['event']['title'] = $row['title'];
  281. $context['event']['span'] = $row['span'] + 1;
  282. }
  283. else
  284. {
  285. $today = getdate();
  286. // You must have a month and year specified!
  287. if (!isset($_REQUEST['month']))
  288. $_REQUEST['month'] = $today['mon'];
  289. if (!isset($_REQUEST['year']))
  290. $_REQUEST['year'] = $today['year'];
  291. $context['event']['month'] = (int) $_REQUEST['month'];
  292. $context['event']['year'] = (int) $_REQUEST['year'];
  293. $context['event']['day'] = isset($_REQUEST['day']) ? $_REQUEST['day'] : ($_REQUEST['month'] == $today['mon'] ? $today['mday'] : 0);
  294. $context['event']['span'] = isset($_REQUEST['span']) ? $_REQUEST['span'] : 1;
  295. // Make sure the year and month are in the valid range.
  296. if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
  297. fatal_lang_error('invalid_month', false);
  298. if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
  299. fatal_lang_error('invalid_year', false);
  300. // Get a list of boards they can post in.
  301. $boards = boardsAllowedTo('post_new');
  302. if (empty($boards))
  303. fatal_lang_error('cannot_post_new', 'user');
  304. // Load a list of boards for this event in the context.
  305. require_once($sourcedir . '/Subs-MessageIndex.php');
  306. $boardListOptions = array(
  307. 'included_boards' => in_array(0, $boards) ? null : $boards,
  308. 'not_redirection' => true,
  309. 'use_permissions' => true,
  310. 'selected_board' => empty($context['current_board']) ? $modSettings['cal_defaultboard'] : $context['current_board'],
  311. );
  312. $context['event']['categories'] = getBoardList($boardListOptions);
  313. }
  314. // Find the last day of the month.
  315. $context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
  316. $context['event']['board'] = !empty($board) ? $board : $modSettings['cal_defaultboard'];
  317. }
  318. if (empty($context['post_errors']))
  319. $context['post_errors'] = array();
  320. // See if any new replies have come along.
  321. if (empty($_REQUEST['msg']) && !empty($topic))
  322. {
  323. if (empty($options['no_new_reply_warning']) && isset($_REQUEST['num_replies']))
  324. {
  325. $newReplies = $context['num_replies'] > $_REQUEST['num_replies'] ? $context['num_replies'] - $_REQUEST['num_replies'] : 0;
  326. if (!empty($newReplies))
  327. {
  328. if ($newReplies == 1)
  329. $txt['error_new_reply'] = isset($_GET['num_replies']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
  330. else
  331. $txt['error_new_replies'] = sprintf(isset($_GET['num_replies']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $newReplies);
  332. // If they've come from the display page then we treat the error differently....
  333. if (isset($_GET['num_replies']))
  334. $newRepliesError = $newReplies;
  335. else
  336. $context['post_error'][$newReplies == 1 ? 'new_reply' : 'new_replies'] = true;
  337. $modSettings['topicSummaryPosts'] = $newReplies > $modSettings['topicSummaryPosts'] ? max($modSettings['topicSummaryPosts'], 5) : $modSettings['topicSummaryPosts'];
  338. }
  339. }
  340. // Check whether this is a really old post being bumped...
  341. if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
  342. $oldTopicError = true;
  343. }
  344. // Get a response prefix (like 'Re:') in the default forum language.
  345. if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
  346. {
  347. if ($language === $user_info['language'])
  348. $context['response_prefix'] = $txt['response_prefix'];
  349. else
  350. {
  351. loadLanguage('index', $language, false);
  352. $context['response_prefix'] = $txt['response_prefix'];
  353. loadLanguage('index');
  354. }
  355. cache_put_data('response_prefix', $context['response_prefix'], 600);
  356. }
  357. // Previewing, modifying, or posting?
  358. if (isset($_REQUEST['message']) || !empty($context['post_error']))
  359. {
  360. // Validate inputs.
  361. if (empty($context['post_error']))
  362. {
  363. if (htmltrim__recursive(htmlspecialchars__recursive($_REQUEST['subject'])) == '')
  364. $context['post_error']['no_subject'] = true;
  365. if (htmltrim__recursive(htmlspecialchars__recursive($_REQUEST['message'])) == '')
  366. $context['post_error']['no_message'] = true;
  367. if (!empty($modSettings['max_messageLength']) && strlen($_REQUEST['message']) > $modSettings['max_messageLength'])
  368. $context['post_error']['long_message'] = true;
  369. // Are you... a guest?
  370. if ($user_info['is_guest'])
  371. {
  372. $_REQUEST['guestname'] = !isset($_REQUEST['guestname']) ? '' : trim($_REQUEST['guestname']);
  373. $_REQUEST['email'] = !isset($_REQUEST['email']) ? '' : trim($_REQUEST['email']);
  374. // Validate the name and email.
  375. if (!isset($_REQUEST['guestname']) || trim(strtr($_REQUEST['guestname'], '_', ' ')) == '')
  376. $context['post_error']['no_name'] = true;
  377. elseif ($smcFunc['strlen']($_REQUEST['guestname']) > 25)
  378. $context['post_error']['long_name'] = true;
  379. else
  380. {
  381. require_once($sourcedir . '/Subs-Members.php');
  382. if (isReservedName(htmlspecialchars($_REQUEST['guestname']), 0, true, false))
  383. $context['post_error']['bad_name'] = true;
  384. }
  385. if (empty($modSettings['guest_post_no_email']))
  386. {
  387. if (!isset($_REQUEST['email']) || $_REQUEST['email'] == '')
  388. $context['post_error']['no_email'] = true;
  389. elseif (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_REQUEST['email']) == 0)
  390. $context['post_error']['bad_email'] = true;
  391. }
  392. }
  393. // This is self explanatory - got any questions?
  394. if (isset($_REQUEST['question']) && trim($_REQUEST['question']) == '')
  395. $context['post_error']['no_question'] = true;
  396. // This means they didn't click Post and get an error.
  397. $really_previewing = true;
  398. }
  399. else
  400. {
  401. if (!isset($_REQUEST['subject']))
  402. $_REQUEST['subject'] = '';
  403. if (!isset($_REQUEST['message']))
  404. $_REQUEST['message'] = '';
  405. if (!isset($_REQUEST['icon']))
  406. $_REQUEST['icon'] = 'xx';
  407. // They are previewing if they asked to preview (i.e. came from quick reply).
  408. $really_previewing = !empty($_POST['preview']);
  409. }
  410. // In order to keep the approval status flowing through, we have to pass it through the form...
  411. $context['becomes_approved'] = empty($_REQUEST['not_approved']);
  412. $context['show_approval'] = isset($_REQUEST['approve']) ? ($_REQUEST['approve'] ? 2 : 1) : 0;
  413. $context['can_announce'] &= $context['becomes_approved'];
  414. // Set up the inputs for the form.
  415. $form_subject = strtr($smcFunc['htmlspecialchars']($_REQUEST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
  416. $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
  417. // Make sure the subject isn't too long - taking into account special characters.
  418. if ($smcFunc['strlen']($form_subject) > 100)
  419. $form_subject = $smcFunc['substr']($form_subject, 0, 100);
  420. // Have we inadvertently trimmed off the subject of useful information?
  421. if ($smcFunc['htmltrim']($form_subject) === '')
  422. $context['post_error']['no_subject'] = true;
  423. // Any errors occurred?
  424. if (!empty($context['post_error']))
  425. {
  426. loadLanguage('Errors');
  427. $context['error_type'] = 'minor';
  428. $context['post_error']['messages'] = array();
  429. foreach ($context['post_error'] as $post_error => $dummy)
  430. {
  431. if ($post_error == 'messages')
  432. continue;
  433. if ($post_error == 'long_message')
  434. $txt['error_' . $post_error] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
  435. $context['post_error']['messages'][] = $txt['error_' . $post_error];
  436. // If it's not a minor error flag it as such.
  437. if (!in_array($post_error, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification')))
  438. $context['error_type'] = 'serious';
  439. }
  440. }
  441. if (isset($_REQUEST['poll']))
  442. {
  443. $context['question'] = isset($_REQUEST['question']) ? $smcFunc['htmlspecialchars'](trim($_REQUEST['question'])) : '';
  444. $context['choices'] = array();
  445. $choice_id = 0;
  446. $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
  447. foreach ($_POST['options'] as $option)
  448. {
  449. if (trim($option) == '')
  450. continue;
  451. $context['choices'][] = array(
  452. 'id' => $choice_id++,
  453. 'number' => $choice_id,
  454. 'label' => $option,
  455. 'is_last' => false
  456. );
  457. }
  458. if (count($context['choices']) < 2)
  459. {
  460. $context['choices'][] = array(
  461. 'id' => $choice_id++,
  462. 'number' => $choice_id,
  463. 'label' => '',
  464. 'is_last' => false
  465. );
  466. $context['choices'][] = array(
  467. 'id' => $choice_id++,
  468. 'number' => $choice_id,
  469. 'label' => '',
  470. 'is_last' => false
  471. );
  472. }
  473. $context['choices'][count($context['choices']) - 1]['is_last'] = true;
  474. }
  475. // Are you... a guest?
  476. if ($user_info['is_guest'])
  477. {
  478. $_REQUEST['guestname'] = !isset($_REQUEST['guestname']) ? '' : trim($_REQUEST['guestname']);
  479. $_REQUEST['email'] = !isset($_REQUEST['email']) ? '' : trim($_REQUEST['email']);
  480. $_REQUEST['guestname'] = htmlspecialchars($_REQUEST['guestname']);
  481. $context['name'] = $_REQUEST['guestname'];
  482. $_REQUEST['email'] = htmlspecialchars($_REQUEST['email']);
  483. $context['email'] = $_REQUEST['email'];
  484. $user_info['name'] = $_REQUEST['guestname'];
  485. }
  486. // Only show the preview stuff if they hit Preview.
  487. if ($really_previewing == true || isset($_REQUEST['xml']))
  488. {
  489. // Set up the preview message and subject and censor them...
  490. $context['preview_message'] = $form_message;
  491. preparsecode($form_message, true);
  492. preparsecode($context['preview_message']);
  493. // Do all bulletin board code tags, with or without smileys.
  494. $context['preview_message'] = parse_bbc($context['preview_message'], isset($_REQUEST['ns']) ? 0 : 1);
  495. if ($form_subject != '')
  496. {
  497. $context['preview_subject'] = $form_subject;
  498. censorText($context['preview_subject']);
  499. censorText($context['preview_message']);
  500. }
  501. else
  502. $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
  503. // Protect any CDATA blocks.
  504. if (isset($_REQUEST['xml']))
  505. $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
  506. }
  507. // Set up the checkboxes.
  508. $context['notify'] = !empty($_REQUEST['notify']);
  509. $context['use_smileys'] = !isset($_REQUEST['ns']);
  510. $context['icon'] = isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : 'xx';
  511. // Set the destination action for submission.
  512. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '') . (isset($_REQUEST['poll']) ? ';poll' : '');
  513. $context['submit_label'] = isset($_REQUEST['msg']) ? $txt['save'] : $txt['post'];
  514. // Previewing an edit?
  515. if (isset($_REQUEST['msg']) && !empty($topic))
  516. {
  517. // Get the existing message.
  518. $request = $smcFunc['db_query']('', '
  519. SELECT
  520. m.id_member, m.modified_time, m.smileys_enabled, m.body,
  521. m.poster_name, m.poster_email, m.subject, m.icon, m.approved,
  522. IFNULL(a.size, -1) AS filesize, a.filename, a.id_attach,
  523. a.approved AS attachment_approved, t.id_member_started AS id_member_poster,
  524. m.poster_time
  525. FROM {db_prefix}messages AS m
  526. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
  527. LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type})
  528. WHERE m.id_msg = {int:id_msg}
  529. AND m.id_topic = {int:current_topic}',
  530. array(
  531. 'current_topic' => $topic,
  532. 'attachment_type' => 0,
  533. 'id_msg' => $_REQUEST['msg'],
  534. )
  535. );
  536. // The message they were trying to edit was most likely deleted.
  537. // !!! Change this error message?
  538. if ($smcFunc['db_num_rows']($request) == 0)
  539. fatal_lang_error('no_board', false);
  540. $row = $smcFunc['db_fetch_assoc']($request);
  541. $attachment_stuff = array($row);
  542. while ($row2 = $smcFunc['db_fetch_assoc']($request))
  543. $attachment_stuff[] = $row2;
  544. $smcFunc['db_free_result']($request);
  545. if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
  546. {
  547. // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
  548. if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
  549. fatal_lang_error('modify_post_time_passed', false);
  550. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
  551. isAllowedTo('modify_replies');
  552. else
  553. isAllowedTo('modify_own');
  554. }
  555. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
  556. isAllowedTo('modify_replies');
  557. else
  558. isAllowedTo('modify_any');
  559. if (!empty($modSettings['attachmentEnable']))
  560. {
  561. $request = $smcFunc['db_query']('', '
  562. SELECT IFNULL(size, -1) AS filesize, filename, id_attach, approved
  563. FROM {db_prefix}attachments
  564. WHERE id_msg = {int:id_msg}
  565. AND attachment_type = {int:attachment_type}',
  566. array(
  567. 'id_msg' => (int) $_REQUEST['msg'],
  568. 'attachment_type' => 0,
  569. )
  570. );
  571. while ($row = $smcFunc['db_fetch_assoc']($request))
  572. {
  573. if ($row['filesize'] <= 0)
  574. continue;
  575. $context['current_attachments'][] = array(
  576. 'name' => $row['filename'],
  577. 'id' => $row['id_attach'],
  578. 'approved' => $row['approved'],
  579. );
  580. }
  581. $smcFunc['db_free_result']($request);
  582. }
  583. // Allow moderators to change names....
  584. if (allowedTo('moderate_forum') && !empty($topic))
  585. {
  586. $request = $smcFunc['db_query']('', '
  587. SELECT id_member, poster_name, poster_email
  588. FROM {db_prefix}messages
  589. WHERE id_msg = {int:id_msg}
  590. AND id_topic = {int:current_topic}
  591. LIMIT 1',
  592. array(
  593. 'current_topic' => $topic,
  594. 'id_msg' => (int) $_REQUEST['msg'],
  595. )
  596. );
  597. $row = $smcFunc['db_fetch_assoc']($request);
  598. $smcFunc['db_free_result']($request);
  599. if (empty($row['id_member']))
  600. {
  601. $context['name'] = htmlspecialchars($row['poster_name']);
  602. $context['email'] = htmlspecialchars($row['poster_email']);
  603. }
  604. }
  605. }
  606. // No check is needed, since nothing is really posted.
  607. checkSubmitOnce('free');
  608. }
  609. // Editing a message...
  610. elseif (isset($_REQUEST['msg']) && !empty($topic))
  611. {
  612. checkSession('get');
  613. $_REQUEST['msg'] = (int) $_REQUEST['msg'];
  614. // Get the existing message.
  615. $request = $smcFunc['db_query']('', '
  616. SELECT
  617. m.id_member, m.modified_time, m.smileys_enabled, m.body,
  618. m.poster_name, m.poster_email, m.subject, m.icon, m.approved,
  619. IFNULL(a.size, -1) AS filesize, a.filename, a.id_attach,
  620. a.approved AS attachment_approved, t.id_member_started AS id_member_poster,
  621. m.poster_time
  622. FROM {db_prefix}messages AS m
  623. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
  624. LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type})
  625. WHERE m.id_msg = {int:id_msg}
  626. AND m.id_topic = {int:current_topic}',
  627. array(
  628. 'current_topic' => $topic,
  629. 'attachment_type' => 0,
  630. 'id_msg' => $_REQUEST['msg'],
  631. )
  632. );
  633. // The message they were trying to edit was most likely deleted.
  634. // !!! Change this error message?
  635. if ($smcFunc['db_num_rows']($request) == 0)
  636. fatal_lang_error('no_board', false);
  637. $row = $smcFunc['db_fetch_assoc']($request);
  638. $attachment_stuff = array($row);
  639. while ($row2 = $smcFunc['db_fetch_assoc']($request))
  640. $attachment_stuff[] = $row2;
  641. $smcFunc['db_free_result']($request);
  642. if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
  643. {
  644. // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
  645. if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
  646. fatal_lang_error('modify_post_time_passed', false);
  647. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
  648. isAllowedTo('modify_replies');
  649. else
  650. isAllowedTo('modify_own');
  651. }
  652. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
  653. isAllowedTo('modify_replies');
  654. else
  655. isAllowedTo('modify_any');
  656. // When was it last modified?
  657. if (!empty($row['modified_time']))
  658. $context['last_modified'] = timeformat($row['modified_time']);
  659. // Get the stuff ready for the form.
  660. $form_subject = $row['subject'];
  661. $form_message = un_preparsecode($row['body']);
  662. censorText($form_message);
  663. censorText($form_subject);
  664. // Check the boxes that should be checked.
  665. $context['use_smileys'] = !empty($row['smileys_enabled']);
  666. $context['icon'] = $row['icon'];
  667. // Show an "approve" box if the user can approve it, and the message isn't approved.
  668. if (!$row['approved'] && !$context['show_approval'])
  669. $context['show_approval'] = allowedTo('approve_posts');
  670. // Load up 'em attachments!
  671. foreach ($attachment_stuff as $attachment)
  672. {
  673. if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
  674. $context['current_attachments'][] = array(
  675. 'name' => $attachment['filename'],
  676. 'id' => $attachment['id_attach'],
  677. 'approved' => $attachment['attachment_approved'],
  678. );
  679. }
  680. // Allow moderators to change names....
  681. if (allowedTo('moderate_forum') && empty($row['id_member']))
  682. {
  683. $context['name'] = htmlspecialchars($row['poster_name']);
  684. $context['email'] = htmlspecialchars($row['poster_email']);
  685. }
  686. // Set the destinaton.
  687. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] . (isset($_REQUEST['poll']) ? ';poll' : '');
  688. $context['submit_label'] = $txt['save'];
  689. }
  690. // Posting...
  691. else
  692. {
  693. // By default....
  694. $context['use_smileys'] = true;
  695. $context['icon'] = 'xx';
  696. if ($user_info['is_guest'])
  697. {
  698. $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : '';
  699. $context['email'] =isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : '';
  700. }
  701. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['poll']) ? ';poll' : '');
  702. $context['submit_label'] = $txt['post'];
  703. // Posting a quoted reply?
  704. if (!empty($topic) && !empty($_REQUEST['quote']))
  705. {
  706. checkSession('get');
  707. // Make sure they _can_ quote this post, and if so get it.
  708. $request = $smcFunc['db_query']('', '
  709. SELECT m.subject, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body
  710. FROM {db_prefix}messages AS m
  711. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  712. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  713. WHERE m.id_msg = {int:id_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  714. AND m.approved = {int:is_approved}') . '
  715. LIMIT 1',
  716. array(
  717. 'id_msg' => (int) $_REQUEST['quote'],
  718. 'is_approved' => 1,
  719. )
  720. );
  721. if ($smcFunc['db_num_rows']($request) == 0)
  722. fatal_lang_error('quoted_post_deleted', false);
  723. list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
  724. $smcFunc['db_free_result']($request);
  725. // Add 'Re: ' to the front of the quoted subject.
  726. if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
  727. $form_subject = $context['response_prefix'] . $form_subject;
  728. // Censor the message and subject.
  729. censorText($form_message);
  730. censorText($form_subject);
  731. // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited!
  732. if (strpos($form_message, '[html]') !== false)
  733. {
  734. $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE);
  735. for ($i = 0, $n = count($parts); $i < $n; $i++)
  736. {
  737. // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
  738. if ($i % 4 == 0)
  739. $parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ise', '\'[html]\' . preg_replace(\'~<br\s?/?' . '>~i\', \'&lt;br /&gt;<br />\', \'$1\') . \'[/html]\'', $parts[$i]);
  740. }
  741. $form_message = implode('', $parts);
  742. }
  743. $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
  744. // Remove any nested quotes, if necessary.
  745. if (!empty($modSettings['removeNestedQuotes']))
  746. $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
  747. // Add a quote string on the front and end.
  748. $form_message = '[quote author=' . $mname . ' link=topic=' . $topic . '.msg' . (int) $_REQUEST['quote'] . '#msg' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
  749. }
  750. // Posting a reply without a quote?
  751. elseif (!empty($topic) && empty($_REQUEST['quote']))
  752. {
  753. // Get the first message's subject.
  754. $form_subject = $first_subject;
  755. // Add 'Re: ' to the front of the subject.
  756. if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
  757. $form_subject = $context['response_prefix'] . $form_subject;
  758. // Censor the subject.
  759. censorText($form_subject);
  760. $form_message = '';
  761. }
  762. else
  763. {
  764. $form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
  765. $form_message = '';
  766. }
  767. }
  768. // !!! This won't work if you're posting an event.
  769. if (allowedTo('post_attachment') || allowedTo('post_unapproved_attachments'))
  770. {
  771. if (empty($_SESSION['temp_attachments']))
  772. $_SESSION['temp_attachments'] = array();
  773. if (!empty($modSettings['currentAttachmentUploadDir']))
  774. {
  775. if (!is_array($modSettings['attachmentUploadDir']))
  776. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  777. // Just use the current path for temp files.
  778. $current_attach_dir = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
  779. }
  780. else
  781. $current_attach_dir = $modSettings['attachmentUploadDir'];
  782. // If this isn't a new post, check the current attachments.
  783. if (isset($_REQUEST['msg']))
  784. {
  785. $request = $smcFunc['db_query']('', '
  786. SELECT COUNT(*), SUM(size)
  787. FROM {db_prefix}attachments
  788. WHERE id_msg = {int:id_msg}
  789. AND attachment_type = {int:attachment_type}',
  790. array(
  791. 'id_msg' => (int) $_REQUEST['msg'],
  792. 'attachment_type' => 0,
  793. )
  794. );
  795. list ($quantity, $total_size) = $smcFunc['db_fetch_row']($request);
  796. $smcFunc['db_free_result']($request);
  797. }
  798. else
  799. {
  800. $quantity = 0;
  801. $total_size = 0;
  802. }
  803. $temp_start = 0;
  804. if (!empty($_SESSION['temp_attachments']))
  805. foreach ($_SESSION['temp_attachments'] as $attachID => $name)
  806. {
  807. $temp_start++;
  808. if (preg_match('~^post_tmp_' . $user_info['id'] . '_\d+$~', $attachID) == 0)
  809. {
  810. unset($_SESSION['temp_attachments'][$attachID]);
  811. continue;
  812. }
  813. if (!empty($_POST['attach_del']) && !in_array($attachID, $_POST['attach_del']))
  814. {
  815. $deleted_attachments = true;
  816. unset($_SESSION['temp_attachments'][$attachID]);
  817. @unlink($current_attach_dir . '/' . $attachID);
  818. continue;
  819. }
  820. $quantity++;
  821. $total_size += filesize($current_attach_dir . '/' . $attachID);
  822. $context['current_attachments'][] = array(
  823. 'name' => $name,
  824. 'id' => $attachID,
  825. 'approved' => 1,
  826. );
  827. }
  828. if (!empty($_POST['attach_del']))
  829. {
  830. $del_temp = array();
  831. foreach ($_POST['attach_del'] as $i => $dummy)
  832. $del_temp[$i] = (int) $dummy;
  833. foreach ($context['current_attachments'] as $k => $dummy)
  834. if (!in_array($dummy['id'], $del_temp))
  835. {
  836. $context['current_attachments'][$k]['unchecked'] = true;
  837. $deleted_attachments = !isset($deleted_attachments) || is_bool($deleted_attachments) ? 1 : $deleted_attachments + 1;
  838. $quantity--;
  839. }
  840. }
  841. if (!empty($_FILES['attachment']))
  842. foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
  843. {
  844. if ($_FILES['attachment']['name'][$n] == '')
  845. continue;
  846. if (!is_uploaded_file($_FILES['attachment']['tmp_name'][$n]) || (@ini_get('open_basedir') == '' && !file_exists($_FILES['attachment']['tmp_name'][$n])))
  847. fatal_lang_error('attach_timeout', 'critical');
  848. if (!empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)
  849. fatal_lang_error('file_too_big', false, array($modSettings['attachmentSizeLimit']));
  850. $quantity++;
  851. if (!empty($modSettings['attachmentNumPerPostLimit']) && $quantity > $modSettings['attachmentNumPerPostLimit'])
  852. fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));
  853. $total_size += $_FILES['attachment']['size'][$n];
  854. if (!empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024)
  855. fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit']));
  856. if (!empty($modSettings['attachmentCheckExtensions']))
  857. {
  858. if (!in_array(strtolower(substr(strrchr($_FILES['attachment']['name'][$n], '.'), 1)), explode(',', strtolower($modSettings['attachmentExtensions']))))
  859. fatal_error($_FILES['attachment']['name'][$n] . '.<br />' . $txt['cant_upload_type'] . ' ' . $modSettings['attachmentExtensions'] . '.', false);
  860. }
  861. if (!empty($modSettings['attachmentDirSizeLimit']))
  862. {
  863. // Make sure the directory isn't full.
  864. $dirSize = 0;
  865. $dir = @opendir($current_attach_dir) or fatal_lang_error('cant_access_upload_path', 'critical');
  866. while ($file = readdir($dir))
  867. {
  868. if ($file == '.' || $file == '..')
  869. continue;
  870. if (preg_match('~^post_tmp_\d+_\d+$~', $file) != 0)
  871. {
  872. // Temp file is more than 5 hours old!
  873. if (filemtime($current_attach_dir . '/' . $file) < time() - 18000)
  874. @unlink($current_attach_dir . '/' . $file);
  875. continue;
  876. }
  877. $dirSize += filesize($current_attach_dir . '/' . $file);
  878. }
  879. closedir($dir);
  880. // Too big! Maybe you could zip it or something...
  881. if ($_FILES['attachment']['size'][$n] + $dirSize > $modSettings['attachmentDirSizeLimit'] * 1024)
  882. fatal_lang_error('ran_out_of_space');
  883. }
  884. if (!is_writable($current_attach_dir))
  885. fatal_lang_error('attachments_no_write', 'critical');
  886. $attachID = 'post_tmp_' . $user_info['id'] . '_' . $temp_start++;
  887. $_SESSION['temp_attachments'][$attachID] = basename($_FILES['attachment']['name'][$n]);
  888. $context['current_attachments'][] = array(
  889. 'name' => basename($_FILES['attachment']['name'][$n]),
  890. 'id' => $attachID,
  891. 'approved' => 1,
  892. );
  893. $destName = $current_attach_dir . '/' . $attachID;
  894. if (!move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
  895. fatal_lang_error('attach_timeout', 'critical');
  896. @chmod($destName, 0644);
  897. }
  898. }
  899. // If we are coming here to make a reply, and someone has already replied... make a special warning message.
  900. if (isset($newRepliesError))
  901. {
  902. $context['post_error']['messages'][] = $newRepliesError == 1 ? $txt['error_new_reply'] : $txt['error_new_replies'];
  903. $context['error_type'] = 'minor';
  904. }
  905. if (isset($oldTopicError))
  906. {
  907. $context['post_error']['messages'][] = sprintf($txt['error_old_topic'], $modSettings['oldTopicDays']);
  908. $context['error_type'] = 'minor';
  909. }
  910. // What are you doing? Posting a poll, modifying, previewing, new post, or reply...
  911. if (isset($_REQUEST['poll']))
  912. $context['page_title'] = $txt['new_poll'];
  913. elseif ($context['make_event'])
  914. $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
  915. elseif (isset($_REQUEST['msg']))
  916. $context['page_title'] = $txt['modify_msg'];
  917. elseif (isset($_REQUEST['subject'], $context['preview_subject']))
  918. $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
  919. elseif (empty($topic))
  920. $context['page_title'] = $txt['start_new_topic'];
  921. else
  922. $context['page_title'] = $txt['post_reply'];
  923. // Build the link tree.
  924. if (empty($topic))
  925. $context['linktree'][] = array(
  926. 'name' => '<em>' . $txt['start_new_topic'] . '</em>'
  927. );
  928. else
  929. $context['linktree'][] = array(
  930. 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
  931. 'name' => $form_subject,
  932. 'extra_before' => '<span' . ($settings['linktree_inline'] ? ' class="smalltext"' : '') . '><strong class="nav">' . $context['page_title'] . ' ( </strong></span>',
  933. 'extra_after' => '<span' . ($settings['linktree_inline'] ? ' class="smalltext"' : '') . '><strong class="nav"> )</strong></span>'
  934. );
  935. // Give wireless a linktree url to the post screen, so that they can switch to full version.
  936. if (WIRELESS)
  937. $context['linktree'][count($context['linktree']) - 1]['url'] = $scripturl . '?action=post;' . (!empty($topic) ? 'topic=' . $topic : 'board=' . $board) . '.' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . (int) $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '') ;
  938. // If they've unchecked an attachment, they may still want to attach that many more files, but don't allow more than num_allowed_attachments.
  939. // !!! This won't work if you're posting an event.
  940. $context['num_allowed_attachments'] = empty($modSettings['attachmentNumPerPostLimit']) ? 50 : min($modSettings['attachmentNumPerPostLimit'] - count($context['current_attachments']) + (isset($deleted_attachments) ? $deleted_attachments : 0), $modSettings['attachmentNumPerPostLimit']);
  941. $context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments'))) && $context['num_allowed_attachments'] > 0;
  942. $context['can_post_attachment_unapproved'] = allowedTo('post_attachment');
  943. $context['subject'] = addcslashes($form_subject, '"');
  944. $context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
  945. // Needed for the editor and message icons.
  946. require_once($sourcedir . '/Subs-Editor.php');
  947. // Now create the editor.
  948. $editorOptions = array(
  949. 'id' => 'message',
  950. 'value' => $context['message'],
  951. 'labels' => array(
  952. 'post_button' => $context['submit_label'],
  953. ),
  954. // We do XML preview here.
  955. 'preview_type' => 2,
  956. );
  957. create_control_richedit($editorOptions);
  958. // Store the ID.
  959. $context['post_box_name'] = $editorOptions['id'];
  960. $context['attached'] = '';
  961. $context['make_poll'] = isset($_REQUEST['poll']);
  962. // Message icons - customized icons are off?
  963. $context['icons'] = getMessageIcons($board);
  964. if (!empty($context['icons']))
  965. $context['icons'][count($context['icons']) - 1]['is_last'] = true;
  966. $context['icon_url'] = '';
  967. for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
  968. {
  969. $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
  970. if ($context['icons'][$i]['selected'])
  971. $context['icon_url'] = $context['icons'][$i]['url'];
  972. }
  973. if (empty($context['icon_url']))
  974. {
  975. $context['icon_url'] = $settings[file_exists($settings['theme_dir'] . '/images/post/' . $context['icon'] . '.gif') ? 'images_url' : 'default_images_url'] . '/post/' . $context['icon'] . '.gif';
  976. array_unshift($context['icons'], array(
  977. 'value' => $context['icon'],
  978. 'name' => $txt['current_icon'],
  979. 'url' => $context['icon_url'],
  980. 'is_last' => empty($context['icons']),
  981. 'selected' => true,
  982. ));
  983. }
  984. if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
  985. getTopic();
  986. // If the user can post attachments prepare the warning labels.
  987. if ($context['can_post_attachment'])
  988. {
  989. $context['allowed_extensions'] = strtr($modSettings['attachmentExtensions'], array(',' => ', '));
  990. $context['attachment_restrictions'] = array();
  991. $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
  992. foreach ($attachmentRestrictionTypes as $type)
  993. if (!empty($modSettings[$type]))
  994. $context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type], $modSettings[$type]);
  995. }
  996. $context['back_to_topic'] = isset($_REQUEST['goback']) || (isset($_REQUEST['msg']) && !isset($_REQUEST['subject']));
  997. $context['show_additional_options'] = !empty($_POST['additional_options']) || !empty($_SESSION['temp_attachments']) || !empty($deleted_attachments);
  998. $context['is_new_topic'] = empty($topic);
  999. $context['is_new_post'] = !isset($_REQUEST['msg']);
  1000. $context['is_first_post'] = $context['is_new_topic'] || (isset($_REQUEST['msg']) && $_REQUEST['msg'] == $id_first_msg);
  1001. // Do we need to show the visual verification image?
  1002. $context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1));
  1003. if ($context['require_verification'])
  1004. {
  1005. require_once($sourcedir . '/Subs-Editor.php');
  1006. $verificationOptions = array(
  1007. 'id' => 'post',
  1008. );
  1009. $context['require_verification'] = create_control_verification($verificationOptions);
  1010. $context['visual_verification_id'] = $verificationOptions['id'];
  1011. }
  1012. // If they came from quick reply, and have to enter verification details, give them some notice.
  1013. if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
  1014. {
  1015. $context['post_error']['messages'][] = $txt['enter_verification_details'];
  1016. $context['error_type'] = 'minor';
  1017. }
  1018. // WYSIWYG only works if BBC is enabled
  1019. $modSettings['disable_wysiwyg'] = !empty($modSettings['disable_wysiwyg']) || empty($modSettings['enableBBC']);
  1020. // Register this form in the session variables.
  1021. checkSubmitOnce('register');
  1022. // Finally, load the template.
  1023. if (WIRELESS)
  1024. $context['sub_template'] = WIRELESS_PROTOCOL . '_post';
  1025. elseif (!isset($_REQUEST['xml']))
  1026. loadTemplate('Post');
  1027. }
  1028. function Post2()
  1029. {
  1030. global $board, $topic, $txt, $modSettings, $sourcedir, $context;
  1031. global $user_info, $board_info, $options, $smcFunc;
  1032. // No need!
  1033. $context['robot_no_index'] = true;
  1034. // If we came from WYSIWYG then turn it back into BBC regardless.
  1035. if (!empty($_REQUEST['message_mode']) && isset($_REQUEST['message']))
  1036. {
  1037. require_once($sourcedir . '/Subs-Editor.php');
  1038. $_REQUEST['message'] = html_to_bbc($_REQUEST['message']);
  1039. // We need to unhtml it now as it gets done shortly.
  1040. $_REQUEST['message'] = un_htmlspecialchars($_REQUEST['message']);
  1041. // We need this for everything else.
  1042. $_POST['message'] = $_REQUEST['message'];
  1043. }
  1044. // Previewing? Go back to start.
  1045. if (isset($_REQUEST['preview']))
  1046. return Post();
  1047. // Prevent double submission of this form.
  1048. checkSubmitOnce('check');
  1049. // No errors as yet.
  1050. $post_errors = array();
  1051. // If the session has timed out, let the user re-submit their form.
  1052. if (checkSession('post', '', false) != '')
  1053. $post_errors[] = 'session_timeout';
  1054. // Wrong verification code?
  1055. if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
  1056. {
  1057. require_once($sourcedir . '/Subs-Editor.php');
  1058. $verificationOptions = array(
  1059. 'id' => 'post',
  1060. );
  1061. $context['require_verification'] = create_control_verification($verificationOptions, empty($_REQUEST['from_qr']));
  1062. // If it's someone from quick reply, don't show them errors.
  1063. if (!empty($_REQUEST['from_qr']))
  1064. {
  1065. $context['post_error']['need_qr_verification'] = true;
  1066. return Post();
  1067. }
  1068. elseif (is_array($context['require_verification']))
  1069. $post_errors = array_merge($post_errors, $context['require_verification']);
  1070. }
  1071. require_once($sourcedir . '/Subs-Post.php');
  1072. loadLanguage('Post');
  1073. // If this isn't a new topic load the topic info that we need.
  1074. if (!empty($topic))
  1075. {
  1076. $request = $smcFunc['db_query']('', '
  1077. SELECT locked, is_sticky, id_poll, approved, num_replies, id_first_msg, id_member_started, id_board
  1078. FROM {db_prefix}topics
  1079. WHERE id_topic = {int:current_topic}
  1080. LIMIT 1',
  1081. array(
  1082. 'current_topic' => $topic,
  1083. )
  1084. );
  1085. $topic_info = $smcFunc['db_fetch_assoc']($request);
  1086. $smcFunc['db_free_result']($request);
  1087. // Though the topic should be there, it might have vanished.
  1088. if (!is_array($topic_info))
  1089. fatal_lang_error('topic_doesnt_exist');
  1090. // Did this topic suddenly move? Just checking...
  1091. if ($topic_info

Large files files are truncated, but you can click here to view the full file