Viewing Paste 423

Formated Paste

  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.  
  25. if (!defined('SMF'))
  26. die('Hacking attempt...');
  27.  
  28. /* The job of this file is to handle everything related to posting replies,
  29. new topics, quotes, and modifications to existing posts. It also handles
  30. quoting posts by way of javascript.
  31.  
  32. void Post()
  33. - handles showing the post screen, loading the post to be modified, and
  34. loading any post quoted.
  35. - additionally handles previews of posts.
  36. - uses the Post template and language file, main sub template.
  37. - allows wireless access using the protocol_post sub template.
  38. - requires different permissions depending on the actions, but most
  39. notably post_new, post_reply_own, and post_reply_any.
  40. - shows options for the editing and posting of calendar events and
  41. attachments, as well as the posting of polls.
  42. - accessed from ?action=post.
  43.  
  44. void Post2()
  45. - actually posts or saves the message composed with Post().
  46. - requires various permissions depending on the action.
  47. - handles attachment, post, and calendar saving.
  48. - sends off notifications, and allows for announcements and moderation.
  49. - accessed from ?action=post2.
  50.  
  51. void AnnounceTopic()
  52. - handle the announce topic function (action=announce).
  53. - checks the topic announcement permissions and loads the announcement
  54. template.
  55. - requires the announce_topic permission.
  56. - uses the ManageMembers template and Post language file.
  57. - call the right function based on the sub-action.
  58.  
  59. void AnnouncementSelectMembergroup()
  60. - lets the user select the membergroups that will receive the topic
  61. announcement.
  62.  
  63. void AnnouncementSend()
  64. - splits the members to be sent a topic announcement into chunks.
  65. - composes notification messages in all languages needed.
  66. - does the actual sending of the topic announcements in chunks.
  67. - calculates a rough estimate of the percentage items sent.
  68.  
  69. void notifyMembersBoard(notifyData)
  70. - notifies members who have requested notification for new topics
  71. posted on a board of said posts.
  72. - receives data on the topics to send out notifications to by the passed in array.
  73. - only sends notifications to those who can *currently* see the topic
  74. (it doesn't matter if they could when they requested notification.)
  75. - loads the Post language file multiple times for each language if the
  76. userLanguage setting is set.
  77.  
  78. void getTopic()
  79. - gets a summary of the most recent posts in a topic.
  80. - depends on the topicSummaryPosts setting.
  81. - if you are editing a post, only shows posts previous to that post.
  82.  
  83. void QuoteFast()
  84. - loads a post an inserts it into the current editing text box.
  85. - uses the Post language file.
  86. - uses special (sadly browser dependent) javascript to parse entities
  87. for internationalization reasons.
  88. - accessed with ?action=quotefast.
  89.  
  90. void JavaScriptModify()
  91. // !!!
  92. */
  93.  
  94. function Post()
  95. {
  96. global $txt, $scripturl, $topic, $modSettings, $board;
  97. global $user_info, $sc, $board_info, $context, $settings;
  98. global $sourcedir, $options, $smcFunc, $language;
  99.  
  100. loadLanguage('Post');
  101.  
  102. // You can't reply with a poll... hacker.
  103. if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
  104. unset($_REQUEST['poll']);
  105.  
  106. // Posting an event?
  107. $context['make_event'] = isset($_REQUEST['calendar']);
  108. $context['robot_no_index'] = true;
  109.  
  110. // You must be posting to *some* board.
  111. if (empty($board) && !$context['make_event'])
  112. fatal_lang_error('no_board', false);
  113.  
  114. require_once($sourcedir . '/Subs-Post.php');
  115.  
  116. if (isset($_REQUEST['xml']))
  117. {
  118. $context['sub_template'] = 'post';
  119.  
  120. // Just in case of an earlier error...
  121. $context['preview_message'] = '';
  122. $context['preview_subject'] = '';
  123. }
  124.  
  125. // No message is comlete without a topic.
  126. if (empty($topic) && !empty($_REQUEST['msg']))
  127. {
  128. $request = $smcFunc['db_query']('', '
  129. SELECT id_topic
  130. FROM {db_prefix}messages
  131. WHERE id_msg = {int:msg}',
  132. 'msg' => (int) $_REQUEST['msg'],
  133. ));
  134. if ($smcFunc['db_num_rows']($request) != 1)
  135. unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
  136. else
  137. list($topic) = $smcFunc['db_fetch_row']($request);
  138. $smcFunc['db_free_result']($request);
  139. }
  140.  
  141. // Check if it's locked. It isn't locked if no topic is specified.
  142. if (!empty($topic))
  143. {
  144. $request = $smcFunc['db_query']('', '
  145. SELECT
  146. t.locked, IFNULL(ln.id_topic, 0) AS notify, t.is_sticky, t.id_poll, t.num_replies, mf.id_member,
  147. t.id_first_msg, mf.subject,
  148. CASE WHEN ml.poster_time > ml.modified_time THEN ml.poster_time ELSE ml.modified_time END AS last_post_time
  149. FROM {db_prefix}topics AS t
  150. LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_topic = t.id_topic AND ln.id_member = {int:current_member})
  151. LEFT JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
  152. LEFT JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  153. WHERE t.id_topic = {int:current_topic}
  154. LIMIT 1',
  155. 'current_member' => $user_info['id'],
  156. 'current_topic' => $topic,
  157. )
  158. );
  159. list ($locked, $context['notify'], $sticky, $pollID, $context['num_replies'], $ID_MEMBER_POSTER, $id_first_msg, $first_subject, $lastPostTime) = $smcFunc['db_fetch_row']($request);
  160. $smcFunc['db_free_result']($request);
  161.  
  162. // If this topic already has a poll, they sure can't add another.
  163. if (isset($_REQUEST['poll']) && $pollID > 0)
  164. unset($_REQUEST['poll']);
  165.  
  166. if (empty($_REQUEST['msg']))
  167. {
  168. if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
  169. is_not_guest();
  170.  
  171. // By default the reply will be approved...
  172. $context['becomes_approved'] = true;
  173. if ($ID_MEMBER_POSTER != $user_info['id'])
  174. {
  175. if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
  176. $context['becomes_approved'] = false;
  177. else
  178. isAllowedTo('post_reply_any');
  179. }
  180. elseif (!allowedTo('post_reply_any'))
  181. {
  182. if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
  183. $context['becomes_approved'] = false;
  184. else
  185. isAllowedTo('post_reply_own');
  186. }
  187. }
  188. else
  189. $context['becomes_approved'] = true;
  190.  
  191. $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $ID_MEMBER_POSTER && allowedTo('lock_own'));
  192. $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);
  193.  
  194. $context['notify'] = !empty($context['notify']);
  195. $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
  196. }
  197. else
  198. {
  199. $context['becomes_approved'] = true;
  200. if ((!$context['make_event'] || !empty($board)))
  201. {
  202. if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
  203. $context['becomes_approved'] = false;
  204. else
  205. isAllowedTo('post_new');
  206. }
  207.  
  208. $locked = 0;
  209. // !!! These won't work if you're making an event.
  210. $context['can_lock'] = allowedTo(array('lock_any', 'lock_own'));
  211. $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);
  212.  
  213. $context['notify'] = !empty($context['notify']);
  214. $context['sticky'] = !empty($_REQUEST['sticky']);
  215. }
  216.  
  217. // !!! These won't work if you're posting an event!
  218. $context['can_notify'] = allowedTo('mark_any_notify');
  219. $context['can_move'] = allowedTo('move_any');
  220. $context['move'] = !empty($_REQUEST['move']);
  221. $context['announce'] = !empty($_REQUEST['announce']);
  222. // You can only annouce topics that will get approved...
  223. $context['can_announce'] = allowedTo('announce_topic') && $context['becomes_approved'];
  224. $context['locked'] = !empty($locked) || !empty($_REQUEST['lock']);
  225.  
  226. // Generally don't show the approval box... (Assume we want things approved)
  227. $context['show_approval'] = false;
  228.  
  229. // An array to hold all the attachments for this topic.
  230. $context['current_attachments'] = array();
  231.  
  232. // Don't allow a post if it's locked and you aren't all powerful.
  233. if ($locked && !allowedTo('moderate_board'))
  234. fatal_lang_error('topic_locked', false);
  235. // Check the users permissions - is the user allowed to add or post a poll?
  236. if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
  237. {
  238. // New topic, new poll.
  239. if (empty($topic))
  240. isAllowedTo('poll_post');
  241. // This is an old topic - but it is yours! Can you add to it?
  242. elseif ($user_info['id'] == $ID_MEMBER_POSTER && !allowedTo('poll_add_any'))
  243. isAllowedTo('poll_add_own');
  244. // If you're not the owner, can you add to any poll?
  245. else
  246. isAllowedTo('poll_add_any');
  247.  
  248. require_once($sourcedir . '/Subs-Members.php');
  249. $allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
  250.  
  251. // Set up the poll options.
  252. $context['poll_options'] = array(
  253. 'max_votes' => empty($_POST['poll_max_votes']) ? '1' : max(1, $_POST['poll_max_votes']),
  254. 'hide' => empty($_POST['poll_hide']) ? 0 : $_POST['poll_hide'],
  255. 'expire' => !isset($_POST['poll_expire']) ? '' : $_POST['poll_expire'],
  256. 'change_vote' => isset($_POST['poll_change_vote']),
  257. 'guest_vote' => isset($_POST['poll_guest_vote']),
  258. 'guest_vote_enabled' => in_array(-1, $allowedVoteGroups['allowed']),
  259. );
  260.  
  261. // Make all five poll choices empty.
  262. $context['choices'] = array(
  263. array('id' => 0, 'number' => 1, 'label' => '', 'is_last' => false),
  264. array('id' => 1, 'number' => 2, 'label' => '', 'is_last' => false),
  265. array('id' => 2, 'number' => 3, 'label' => '', 'is_last' => false),
  266. array('id' => 3, 'number' => 4, 'label' => '', 'is_last' => false),
  267. array('id' => 4, 'number' => 5, 'label' => '', 'is_last' => true)
  268. );
  269. }
  270.  
  271. if ($context['make_event'])
  272. {
  273. // They might want to pick a board.
  274. if (!isset($context['current_board']))
  275. $context['current_board'] = 0;
  276.  
  277. // Start loading up the event info.
  278. $context['event'] = array();
  279. $context['event']['title'] = isset($_REQUEST['evtitle']) ? htmlspecialchars(stripslashes($_REQUEST['evtitle'])) : '';
  280.  
  281. $context['event']['id'] = isset($_REQUEST['eventid']) ? (int) $_REQUEST['eventid'] : -1;
  282. $context['event']['new'] = $context['event']['id'] == -1;
  283.  
  284. // Permissions check!
  285. isAllowedTo('calendar_post');
  286.  
  287. // Editing an event? (but NOT previewing!?)
  288. if (!$context['event']['new'] && !isset($_REQUEST['subject']))
  289. {
  290. // If the user doesn't have permission to edit the post in this topic, redirect them.
  291. if (($ID_MEMBER_POSTER != $user_info['id'] || !allowedTo('modify_own')) && !allowedTo('modify_any'))
  292. {
  293. require_once($sourcedir . '/Calendar.php');
  294. return CalendarPost();
  295. }
  296.  
  297. // Get the current event information.
  298. $request = $smcFunc['db_query']('', '
  299. SELECT
  300. id_member, title, MONTH(start_date) AS month, DAYOFMONTH(start_date) AS day,
  301. YEAR(start_date) AS year, (TO_DAYS(end_date) - TO_DAYS(start_date)) AS span
  302. FROM {db_prefix}calendar
  303. WHERE id_event = {int:id_event}
  304. LIMIT 1',
  305. 'id_event' => $context['event']['id'],
  306. )
  307. );
  308. $row = $smcFunc['db_fetch_assoc']($request);
  309. $smcFunc['db_free_result']($request);
  310.  
  311. // Make sure the user is allowed to edit this event.
  312. if ($row['id_member'] != $user_info['id'])
  313. isAllowedTo('calendar_edit_any');
  314. elseif (!allowedTo('calendar_edit_any'))
  315. isAllowedTo('calendar_edit_own');
  316.  
  317. $context['event']['month'] = $row['month'];
  318. $context['event']['day'] = $row['day'];
  319. $context['event']['year'] = $row['year'];
  320. $context['event']['title'] = $row['title'];
  321. $context['event']['span'] = $row['span'] + 1;
  322. }
  323. else
  324. {
  325. $today = getdate();
  326.  
  327. // You must have a month and year specified!
  328. if (!isset($_REQUEST['month']))
  329. $_REQUEST['month'] = $today['mon'];
  330. if (!isset($_REQUEST['year']))
  331. $_REQUEST['year'] = $today['year'];
  332.  
  333. $context['event']['month'] = (int) $_REQUEST['month'];
  334. $context['event']['year'] = (int) $_REQUEST['year'];
  335. $context['event']['day'] = isset($_REQUEST['day']) ? $_REQUEST['day'] : ($_REQUEST['month'] == $today['mon'] ? $today['mday'] : 0);
  336. $context['event']['span'] = isset($_REQUEST['span']) ? $_REQUEST['span'] : 1;
  337.  
  338. // Make sure the year and month are in the valid range.
  339. if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
  340. fatal_lang_error('invalid_month', false);
  341. if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
  342. fatal_lang_error('invalid_year', false);
  343.  
  344. // Get a list of boards they can post in.
  345. $boards = boardsAllowedTo('post_new');
  346. if (empty($boards))
  347. fatal_lang_error('cannot_post_new', 'user');
  348.  
  349. // Load a list of boards for this event in the context.
  350. require_once($sourcedir . '/Subs-MessageIndex.php');
  351. $boardListOptions = array(
  352. 'included_boards' => in_array(0, $boards) ? null : $boards,
  353. 'not_redirection' => true,
  354. 'use_permissions' => true,
  355. 'selected_board' => empty($context['current_board']) ? $modSettings['cal_defaultboard'] : $context['current_board'],
  356. );
  357. $context['event']['categories'] = getBoardList($boardListOptions);
  358. }
  359.  
  360. // Find the last day of the month.
  361. $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']));
  362.  
  363. $context['event']['board'] = !empty($board) ? $board : $modSettings['cal_defaultboard'];
  364. }
  365.  
  366. if (empty($context['post_errors']))
  367. $context['post_errors'] = array();
  368.  
  369. // See if any new replies have come along.
  370. if (empty($_REQUEST['msg']) && !empty($topic))
  371. {
  372. if (empty($options['no_new_reply_warning']) && isset($_REQUEST['num_replies']))
  373. {
  374. $newReplies = $context['num_replies'] > $_REQUEST['num_replies'] ? $context['num_replies'] - $_REQUEST['num_replies'] : 0;
  375.  
  376. if (!empty($newReplies))
  377. {
  378. if ($newReplies == 1)
  379. $txt['error_new_reply'] = isset($_GET['num_replies']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
  380. else
  381. $txt['error_new_replies'] = sprintf(isset($_GET['num_replies']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $newReplies);
  382.  
  383. // If they've come from the display page then we treat the error differently....
  384. if (isset($_GET['num_replies']))
  385. $newRepliesError = $newReplies;
  386. else
  387. $context['post_error'][$newReplies == 1 ? 'new_reply' : 'new_replies'] = true;
  388.  
  389. $modSettings['topicSummaryPosts'] = $newReplies > $modSettings['topicSummaryPosts'] ? max($modSettings['topicSummaryPosts'], 5) : $modSettings['topicSummaryPosts'];
  390. }
  391. }
  392. // Check whether this is a really old post being bumped...
  393. if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
  394. $oldTopicError = true;
  395. }
  396.  
  397. // Get a response prefix (like 'Re:') in the default forum language.
  398. if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
  399. {
  400. if ($language === $user_info['language'])
  401. $context['response_prefix'] = $txt['response_prefix'];
  402. else
  403. {
  404. loadLanguage('index', $language, false);
  405. $context['response_prefix'] = $txt['response_prefix'];
  406. loadLanguage('index');
  407. }
  408. cache_put_data('response_prefix', $context['response_prefix'], 600);
  409. }
  410.  
  411. // Previewing, modifying, or posting?
  412. if (isset($_REQUEST['message']) || !empty($context['post_error']))
  413. {
  414. // Validate inputs.
  415. if (empty($context['post_error']))
  416. {
  417. if (htmltrim__recursive(htmlspecialchars__recursive($_REQUEST['subject'])) == '')
  418. $context['post_error']['no_subject'] = true;
  419. if (htmltrim__recursive(htmlspecialchars__recursive($_REQUEST['message'])) == '')
  420. $context['post_error']['no_message'] = true;
  421. if (!empty($modSettings['max_messageLength']) && strlen($_REQUEST['message']) > $modSettings['max_messageLength'])
  422. $context['post_error']['long_message'] = true;
  423.  
  424. // Are you... a guest?
  425. if ($user_info['is_guest'])
  426. {
  427. $_REQUEST['guestname'] = !isset($_REQUEST['guestname']) ? '' : trim($_REQUEST['guestname']);
  428. $_REQUEST['email'] = !isset($_REQUEST['email']) ? '' : trim($_REQUEST['email']);
  429.  
  430. // Validate the name and email.
  431. if (!isset($_REQUEST['guestname']) || trim(strtr($_REQUEST['guestname'], '_', ' ')) == '')
  432. $context['post_error']['no_name'] = true;
  433. elseif ($smcFunc['strlen']($_REQUEST['guestname']) > 25)
  434. $context['post_error']['long_name'] = true;
  435. else
  436. {
  437. require_once($sourcedir . '/Subs-Members.php');
  438. if (isReservedName(htmlspecialchars($_REQUEST['guestname']), 0, true, false))
  439. $context['post_error']['bad_name'] = true;
  440. }
  441.  
  442. if (empty($modSettings['guest_post_no_email']))
  443. {
  444. if (!isset($_REQUEST['email']) || $_REQUEST['email'] == '')
  445. $context['post_error']['no_email'] = true;
  446. elseif (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_REQUEST['email']) == 0)
  447. $context['post_error']['bad_email'] = true;
  448. }
  449. }
  450.  
  451. // This is self explanatory - got any questions?
  452. if (isset($_REQUEST['question']) && trim($_REQUEST['question']) == '')
  453. $context['post_error']['no_question'] = true;
  454.  
  455. // This means they didn't click Post and get an error.
  456. $really_previewing = true;
  457. }
  458. else
  459. {
  460. if (!isset($_REQUEST['subject']))
  461. $_REQUEST['subject'] = '';
  462. if (!isset($_REQUEST['message']))
  463. $_REQUEST['message'] = '';
  464. if (!isset($_REQUEST['icon']))
  465. $_REQUEST['icon'] = 'xx';
  466.  
  467. // They are previewing if they asked to preview (i.e. came from quick reply).
  468. $really_previewing = !empty($_POST['preview']);
  469. }
  470.  
  471. // In order to keep the approval status flowing through, we have to pass it through the form...
  472. $context['becomes_approved'] = empty($_REQUEST['not_approved']);
  473. $context['show_approval'] = isset($_REQUEST['approve']) ? ($_REQUEST['approve'] ? 2 : 1) : 0;
  474. $context['can_announce'] &= $context['becomes_approved'];
  475.  
  476. // Set up the inputs for the form.
  477. $form_subject = strtr($smcFunc['htmlspecialchars']($_REQUEST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
  478. $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
  479.  
  480. // Make sure the subject isn't too long - taking into account special characters.
  481. if ($smcFunc['strlen']($form_subject) > 100)
  482. $form_subject = $smcFunc['substr']($form_subject, 0, 100);
  483.  
  484. // Have we inadvertently trimmed off the subject of useful information?
  485. if ($smcFunc['htmltrim']($form_subject) === '')
  486. $context['post_error']['no_subject'] = true;
  487.  
  488. // Any errors occurred?
  489. if (!empty($context['post_error']))
  490. {
  491. loadLanguage('Errors');
  492.  
  493. $context['error_type'] = 'minor';
  494.  
  495. $context['post_error']['messages'] = array();
  496. foreach ($context['post_error'] as $post_error => $dummy)
  497. {
  498. if ($post_error == 'messages')
  499. continue;
  500.  
  501. if ($post_error == 'long_message')
  502. $txt['error_' . $post_error] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
  503.  
  504. $context['post_error']['messages'][] = $txt['error_' . $post_error];
  505.  
  506. // If it's not a minor error flag it as such.
  507. if (!in_array($post_error, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification')))
  508. $context['error_type'] = 'serious';
  509. }
  510. }
  511.  
  512. if (isset($_REQUEST['poll']))
  513. {
  514. $context['question'] = isset($_REQUEST['question']) ? $smcFunc['htmlspecialchars'](trim($_REQUEST['question'])) : '';
  515.  
  516. $context['choices'] = array();
  517. $choice_id = 0;
  518.  
  519. $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
  520. foreach ($_POST['options'] as $option)
  521. {
  522. if (trim($option) == '')
  523. continue;
  524.  
  525. $context['choices'][] = array(
  526. 'id' => $choice_id++,
  527. 'number' => $choice_id,
  528. 'label' => $option,
  529. 'is_last' => false
  530. );
  531. }
  532.  
  533. if (count($context['choices']) < 2)
  534. {
  535. $context['choices'][] = array(
  536. 'id' => $choice_id++,
  537. 'number' => $choice_id,
  538. 'label' => '',
  539. 'is_last' => false
  540. );
  541. $context['choices'][] = array(
  542. 'id' => $choice_id++,
  543. 'number' => $choice_id,
  544. 'label' => '',
  545. 'is_last' => false
  546. );
  547. }
  548. $context['choices'][count($context['choices']) - 1]['is_last'] = true;
  549. }
  550.  
  551. // Are you... a guest?
  552. if ($user_info['is_guest'])
  553. {
  554. $_REQUEST['guestname'] = !isset($_REQUEST['guestname']) ? '' : trim($_REQUEST['guestname']);
  555. $_REQUEST['email'] = !isset($_REQUEST['email']) ? '' : trim($_REQUEST['email']);
  556.  
  557. $_REQUEST['guestname'] = htmlspecialchars($_REQUEST['guestname']);
  558. $context['name'] = $_REQUEST['guestname'];
  559. $_REQUEST['email'] = htmlspecialchars($_REQUEST['email']);
  560. $context['email'] = $_REQUEST['email'];
  561.  
  562. $user_info['name'] = $_REQUEST['guestname'];
  563. }
  564.  
  565. // Only show the preview stuff if they hit Preview.
  566. if ($really_previewing == true || isset($_REQUEST['xml']))
  567. {
  568. // Set up the preview message and subject and censor them...
  569. $context['preview_message'] = $form_message;
  570. preparsecode($form_message, true);
  571. preparsecode($context['preview_message']);
  572.  
  573. // Do all bulletin board code tags, with or without smileys.
  574. $context['preview_message'] = parse_bbc($context['preview_message'], isset($_REQUEST['ns']) ? 0 : 1);
  575.  
  576. if ($form_subject != '')
  577. {
  578. $context['preview_subject'] = $form_subject;
  579.  
  580. censorText($context['preview_subject']);
  581. censorText($context['preview_message']);
  582. }
  583. else
  584. $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
  585.  
  586. // Protect any CDATA blocks.
  587. if (isset($_REQUEST['xml']))
  588. $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
  589. }
  590.  
  591. // Set up the checkboxes.
  592. $context['notify'] = !empty($_REQUEST['notify']);
  593. $context['use_smileys'] = !isset($_REQUEST['ns']);
  594.  
  595. $context['icon'] = isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : 'xx';
  596.  
  597. // Set the destination action for submission.
  598. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '') . (isset($_REQUEST['poll']) ? ';poll' : '');
  599. $context['submit_label'] = isset($_REQUEST['msg']) ? $txt['save'] : $txt['post'];
  600.  
  601. // Previewing an edit?
  602. if (isset($_REQUEST['msg']) && !empty($topic))
  603. {
  604. // Get the existing message.
  605. $request = $smcFunc['db_query']('', '
  606. SELECT
  607. m.id_member, m.modified_time, m.smileys_enabled, m.body,
  608. m.poster_name, m.poster_email, m.subject, m.icon, m.approved,
  609. IFNULL(a.size, -1) AS filesize, a.filename, a.id_attach,
  610. a.approved AS attachment_approved, t.id_member_started AS id_member_poster,
  611. m.poster_time
  612. FROM {db_prefix}messages AS m
  613. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
  614. LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type})
  615. WHERE m.id_msg = {int:id_msg}
  616. AND m.id_topic = {int:current_topic}',
  617. 'current_topic' => $topic,
  618. 'attachment_type' => 0,
  619. 'id_msg' => $_REQUEST['msg'],
  620. )
  621. );
  622. // The message they were trying to edit was most likely deleted.
  623. // !!! Change this error message?
  624. if ($smcFunc['db_num_rows']($request) == 0)
  625. fatal_lang_error('no_board', false);
  626. $row = $smcFunc['db_fetch_assoc']($request);
  627.  
  628. $attachment_stuff = array($row);
  629. while ($row2 = $smcFunc['db_fetch_assoc']($request))
  630. $attachment_stuff[] = $row2;
  631. $smcFunc['db_free_result']($request);
  632.  
  633. if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
  634. {
  635. // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
  636. if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
  637. fatal_lang_error('modify_post_time_passed', false);
  638. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
  639. isAllowedTo('modify_replies');
  640. else
  641. isAllowedTo('modify_own');
  642. }
  643. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
  644. isAllowedTo('modify_replies');
  645. else
  646. isAllowedTo('modify_any');
  647.  
  648. if (!empty($modSettings['attachmentEnable']))
  649. {
  650. $request = $smcFunc['db_query']('', '
  651. SELECT IFNULL(size, -1) AS filesize, filename, id_attach, approved
  652. FROM {db_prefix}attachments
  653. WHERE id_msg = {int:id_msg}
  654. AND attachment_type = {int:attachment_type}',
  655. 'id_msg' => (int) $_REQUEST['msg'],
  656. 'attachment_type' => 0,
  657. )
  658. );
  659. while ($row = $smcFunc['db_fetch_assoc']($request))
  660. {
  661. if ($row['filesize'] <= 0)
  662. continue;
  663. $context['current_attachments'][] = array(
  664. 'name' => $row['filename'],
  665. 'id' => $row['id_attach'],
  666. 'approved' => $row['approved'],
  667. );
  668. }
  669. $smcFunc['db_free_result']($request);
  670. }
  671.  
  672. // Allow moderators to change names....
  673. if (allowedTo('moderate_forum') && !empty($topic))
  674. {
  675. $request = $smcFunc['db_query']('', '
  676. SELECT id_member, poster_name, poster_email
  677. FROM {db_prefix}messages
  678. WHERE id_msg = {int:id_msg}
  679. AND id_topic = {int:current_topic}
  680. LIMIT 1',
  681. 'current_topic' => $topic,
  682. 'id_msg' => (int) $_REQUEST['msg'],
  683. )
  684. );
  685. $row = $smcFunc['db_fetch_assoc']($request);
  686. $smcFunc['db_free_result']($request);
  687.  
  688. if (empty($row['id_member']))
  689. {
  690. $context['name'] = htmlspecialchars($row['poster_name']);
  691. $context['email'] = htmlspecialchars($row['poster_email']);
  692. }
  693. }
  694. }
  695.  
  696. // No check is needed, since nothing is really posted.
  697. checkSubmitOnce('free');
  698. }
  699. // Editing a message...
  700. elseif (isset($_REQUEST['msg']) && !empty($topic))
  701. {
  702. checkSession('get');
  703. $_REQUEST['msg'] = (int) $_REQUEST['msg'];
  704.  
  705. // Get the existing message.
  706. $request = $smcFunc['db_query']('', '
  707. SELECT
  708. m.id_member, m.modified_time, m.smileys_enabled, m.body,
  709. m.poster_name, m.poster_email, m.subject, m.icon, m.approved,
  710. IFNULL(a.size, -1) AS filesize, a.filename, a.id_attach,
  711. a.approved AS attachment_approved, t.id_member_started AS id_member_poster,
  712. m.poster_time
  713. FROM {db_prefix}messages AS m
  714. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
  715. LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type})
  716. WHERE m.id_msg = {int:id_msg}
  717. AND m.id_topic = {int:current_topic}',
  718. 'current_topic' => $topic,
  719. 'attachment_type' => 0,
  720. 'id_msg' => $_REQUEST['msg'],
  721. )
  722. );
  723. // The message they were trying to edit was most likely deleted.
  724. // !!! Change this error message?
  725. if ($smcFunc['db_num_rows']($request) == 0)
  726. fatal_lang_error('no_board', false);
  727. $row = $smcFunc['db_fetch_assoc']($request);
  728.  
  729. $attachment_stuff = array($row);
  730. while ($row2 = $smcFunc['db_fetch_assoc']($request))
  731. $attachment_stuff[] = $row2;
  732. $smcFunc['db_free_result']($request);
  733.  
  734. if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
  735. {
  736. // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
  737. if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
  738. fatal_lang_error('modify_post_time_passed', false);
  739. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
  740. isAllowedTo('modify_replies');
  741. else
  742. isAllowedTo('modify_own');
  743. }
  744. elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
  745. isAllowedTo('modify_replies');
  746. else
  747. isAllowedTo('modify_any');
  748.  
  749. // When was it last modified?
  750. if (!empty($row['modified_time']))
  751. $context['last_modified'] = timeformat($row['modified_time']);
  752.  
  753. // Get the stuff ready for the form.
  754. $form_subject = $row['subject'];
  755. $form_message = un_preparsecode($row['body']);
  756. censorText($form_message);
  757. censorText($form_subject);
  758.  
  759. // Check the boxes that should be checked.
  760. $context['use_smileys'] = !empty($row['smileys_enabled']);
  761. $context['icon'] = $row['icon'];
  762.  
  763. // Show an "approve" box if the user can approve it, and the message isn't approved.
  764. if (!$row['approved'] && !$context['show_approval'])
  765. $context['show_approval'] = allowedTo('approve_posts');
  766.  
  767. // Load up 'em attachments!
  768. foreach ($attachment_stuff as $attachment)
  769. {
  770. if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
  771. $context['current_attachments'][] = array(
  772. 'name' => $attachment['filename'],
  773. 'id' => $attachment['id_attach'],
  774. 'approved' => $attachment['attachment_approved'],
  775. );
  776. }
  777.  
  778. // Allow moderators to change names....
  779. if (allowedTo('moderate_forum') && empty($row['id_member']))
  780. {
  781. $context['name'] = htmlspecialchars($row['poster_name']);
  782. $context['email'] = htmlspecialchars($row['poster_email']);
  783. }
  784.  
  785. // Set the destinaton.
  786. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] . (isset($_REQUEST['poll']) ? ';poll' : '');
  787. $context['submit_label'] = $txt['save'];
  788. }
  789. // Posting...
  790. else
  791. {
  792. // By default....
  793. $context['use_smileys'] = true;
  794. $context['icon'] = 'xx';
  795.  
  796. if ($user_info['is_guest'])
  797. {
  798. $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : '';
  799. $context['email'] =isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : '';
  800. }
  801. $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['poll']) ? ';poll' : '');
  802.  
  803. $context['submit_label'] = $txt['post'];
  804.  
  805. // Posting a quoted reply?
  806. if (!empty($topic) && !empty($_REQUEST['quote']))
  807. {
  808. checkSession('get');
  809.  
  810. // Make sure they _can_ quote this post, and if so get it.
  811. $request = $smcFunc['db_query']('', '
  812. SELECT m.subject, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body
  813. FROM {db_prefix}messages AS m
  814. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  815. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  816. WHERE m.id_msg = {int:id_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  817. AND m.approved = {int:is_approved}') . '
  818. LIMIT 1',
  819. 'id_msg' => (int) $_REQUEST['quote'],
  820. 'is_approved' => 1,
  821. )
  822. );
  823. if ($smcFunc['db_num_rows']($request) == 0)
  824. fatal_lang_error('quoted_post_deleted', false);
  825. list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
  826. $smcFunc['db_free_result']($request);
  827.  
  828. // Add 'Re: ' to the front of the quoted subject.
  829. if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
  830. $form_subject = $context['response_prefix'] . $form_subject;
  831.  
  832. // Censor the message and subject.
  833. censorText($form_message);
  834. censorText($form_subject);
  835.  
  836. // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited!
  837. if (strpos($form_message, '[html]') !== false)
  838. {
  839. $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE);
  840. for ($i = 0, $n = count($parts); $i < $n; $i++)
  841. {
  842. // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
  843. if ($i % 4 == 0)
  844. $parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ise', '\'[html]\' . preg_replace(\'~<br\s?/?' . '>~i\', \'&lt;br /&gt;<br />\', \'$1\') . \'[/html]\'', $parts[$i]);
  845. }
  846. $form_message = implode('', $parts);
  847. }
  848.  
  849. $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
  850.  
  851. // Remove any nested quotes, if necessary.
  852. if (!empty($modSettings['removeNestedQuotes']))
  853. $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
  854.  
  855. // Add a quote string on the front and end.
  856. $form_message = '[quote author=' . $mname . ' link=topic=' . $topic . '.msg' . (int) $_REQUEST['quote'] . '#msg' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
  857. }
  858. // Posting a reply without a quote?
  859. elseif (!empty($topic) && empty($_REQUEST['quote']))
  860. {
  861. // Get the first message's subject.
  862. $form_subject = $first_subject;
  863.  
  864. // Add 'Re: ' to the front of the subject.
  865. if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
  866. $form_subject = $context['response_prefix'] . $form_subject;
  867.  
  868. // Censor the subject.
  869. censorText($form_subject);
  870.  
  871. $form_message = '';
  872. }
  873. else
  874. {
  875. $form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
  876. $form_message = '';
  877. }
  878. }
  879.  
  880. // !!! This won't work if you're posting an event.
  881. if (allowedTo('post_attachment') || allowedTo('post_unapproved_attachments'))
  882. {
  883. if (empty($_SESSION['temp_attachments']))
  884. $_SESSION['temp_attachments'] = array();
  885.  
  886. if (!empty($modSettings['currentAttachmentUploadDir']))
  887. {
  888. if (!is_array($modSettings['attachmentUploadDir']))
  889. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  890.  
  891. // Just use the current path for temp files.
  892. $current_attach_dir = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
  893. }
  894. else
  895. $current_attach_dir = $modSettings['attachmentUploadDir'];
  896.  
  897. // If this isn't a new post, check the current attachments.
  898. if (isset($_REQUEST['msg']))
  899. {
  900. $request = $smcFunc['db_query']('', '
  901. SELECT COUNT(*), SUM(size)
  902. FROM {db_prefix}attachments
  903. WHERE id_msg = {int:id_msg}
  904. AND attachment_type = {int:attachment_type}',
  905. 'id_msg' => (int) $_REQUEST['msg'],
  906. 'attachment_type' => 0,
  907. )
  908. );
  909. list ($quantity, $total_size) = $smcFunc['db_fetch_row']($request);
  910. $smcFunc['db_free_result']($request);
  911. }
  912. else
  913. {
  914. $quantity = 0;
  915. $total_size = 0;
  916. }
  917.  
  918. $temp_start = 0;
  919.  
  920. if (!empty($_SESSION['temp_attachments']))
  921. foreach ($_SESSION['temp_attachments'] as $attachID => $name)
  922. {
  923. $temp_start++;
  924.  
  925. if (preg_match('~^post_tmp_' . $user_info['id'] . '_\d+$~', $attachID) == 0)
  926. {
  927. unset($_SESSION['temp_attachments'][$attachID]);
  928. continue;
  929. }
  930.  
  931. if (!empty($_POST['attach_del']) && !in_array($attachID, $_POST['attach_del']))
  932. {
  933. $deleted_attachments = true;
  934. unset($_SESSION['temp_attachments'][$attachID]);
  935. @unlink($current_attach_dir . '/' . $attachID);
  936. continue;
  937. }
  938.  
  939. $quantity++;
  940. $total_size += filesize($current_attach_dir . '/' . $attachID);
  941.  
  942. $context['current_attachments'][] = array(
  943. 'name' => $name,
  944. 'id' => $attachID,
  945. 'approved' => 1,
  946. );
  947. }
  948.  
  949. if (!empty($_POST['attach_del']))
  950. {
  951. $del_temp = array();
  952. foreach ($_POST['attach_del'] as $i => $dummy)
  953. $del_temp[$i] = (int) $dummy;
  954.  
  955. foreach ($context['current_attachments'] as $k => $dummy)
  956. if (!in_array($dummy['id'], $del_temp))
  957. {
  958. $context['current_attachments'][$k]['unchecked'] = true;
  959. $deleted_attachments = !isset($deleted_attachments) || is_bool($deleted_attachments) ? 1 : $deleted_attachments + 1;
  960. $quantity--;
  961. }
  962. }
  963.  
  964. if (!empty($_FILES['attachment']))
  965. foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
  966. {
  967. if ($_FILES['attachment']['name'][$n] == '')
  968. continue;
  969.  
  970. if (!is_uploaded_file($_FILES['attachment']['tmp_name'][$n]) || (@ini_get('open_basedir') == '' && !file_exists($_FILES['attachment']['tmp_name'][$n])))
  971. fatal_lang_error('attach_timeout', 'critical');
  972.  
  973. if (!empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)
  974. fatal_lang_error('file_too_big', false, array($modSettings['attachmentSizeLimit']));
  975.  
  976. $quantity++;
  977. if (!empty($modSettings['attachmentNumPerPostLimit']) && $quantity > $modSettings['attachmentNumPerPostLimit'])
  978. fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));
  979.  
  980. $total_size += $_FILES['attachment']['size'][$n];
  981. if (!empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024)
  982. fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit']));
  983.  
  984. if (!empty($modSettings['attachmentCheckExtensions']))
  985. {
  986. if (!in_array(strtolower(substr(strrchr($_FILES['attachment']['name'][$n], '.'), 1)), explode(',', strtolower($modSettings['attachmentExtensions']))))
  987. fatal_error($_FILES['attachment']['name'][$n] . '.<br />' . $txt['cant_upload_type'] . ' ' . $modSettings['attachmentExtensions'] . '.', false);
  988. }
  989.  
  990. if (!empty($modSettings['attachmentDirSizeLimit']))
  991. {
  992. // Make sure the directory isn't full.
  993. $dirSize = 0;
  994. $dir = @opendir($current_attach_dir) or fatal_lang_error('cant_access_upload_path', 'critical');
  995. while ($file = readdir($dir))
  996. {
  997. if ($file == '.' || $file == '..')
  998. continue;
  999.  
  1000. if (preg_match('~^post_tmp_\d+_\d+$~', $file) != 0)
  1001. {
  1002. // Temp file is more than 5 hours old!
  1003. if (filemtime($current_attach_dir . '/' . $file) < time() - 18000)
  1004. @unlink($current_attach_dir . '/' . $file);
  1005. continue;
  1006. }
  1007.  
  1008. $dirSize += filesize($current_attach_dir . '/' . $file);
  1009. }
  1010. closedir($dir);
  1011.  
  1012. // Too big! Maybe you could zip it or something...
  1013. if ($_FILES['attachment']['size'][$n] + $dirSize > $modSettings['attachmentDirSizeLimit'] * 1024)
  1014. fatal_lang_error('ran_out_of_space');
  1015. }
  1016.  
  1017. if (!is_writable($current_attach_dir))
  1018. fatal_lang_error('attachments_no_write', 'critical');
  1019.  
  1020. $attachID = 'post_tmp_' . $user_info['id'] . '_' . $temp_start++;
  1021. $_SESSION['temp_attachments'][$attachID] = basename($_FILES['attachment']['name'][$n]);
  1022. $context['current_attachments'][] = array(
  1023. 'name' => basename($_FILES['attachment']['name'][$n]),
  1024. 'id' => $attachID,
  1025. 'approved' => 1,
  1026. );
  1027.  
  1028. $destName = $current_attach_dir . '/' . $attachID;
  1029.  
  1030. if (!move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
  1031. fatal_lang_error('attach_timeout', 'critical');
  1032. @chmod($destName, 0644);
  1033. }
  1034. }
  1035.  
  1036. // If we are coming here to make a reply, and someone has already replied... make a special warning message.
  1037. if (isset($newRepliesError))
  1038. {
  1039. $context['post_error']['messages'][] = $newRepliesError == 1 ? $txt['error_new_reply'] : $txt['error_new_replies'];
  1040. $context['error_type'] = 'minor';
  1041. }
  1042.  
  1043. if (isset($oldTopicError))
  1044. {
  1045. $context['post_error']['messages'][] = sprintf($txt['error_old_topic'], $modSettings['oldTopicDays']);
  1046. $context['error_type'] = 'minor';
  1047. }
  1048.  
  1049. // What are you doing? Posting a poll, modifying, previewing, new post, or reply...
  1050. if (isset($_REQUEST['poll']))
  1051. $context['page_title'] = $txt['new_poll'];
  1052. elseif ($context['make_event'])
  1053. $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
  1054. elseif (isset($_REQUEST['msg']))
  1055. $context['page_title'] = $txt['modify_msg'];
  1056. elseif (isset($_REQUEST['subject'], $context['preview_subject']))
  1057. $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
  1058. elseif (empty($topic))
  1059. $context['page_title'] = $txt['start_new_topic'];
  1060. else
  1061. $context['page_title'] = $txt['post_reply'];
  1062.  
  1063. // Build the link tree.
  1064. if (empty($topic))
  1065. $context['linktree'][] = array(
  1066. 'name' => '<em>' . $txt['start_new_topic'] . '</em>'
  1067. );
  1068. else
  1069. $context['linktree'][] = array(
  1070. 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
  1071. 'name' => $form_subject,
  1072. 'extra_before' => '<span' . ($settings['linktree_inline'] ? ' class="smalltext"' : '') . '><strong class="nav">' . $context['page_title'] . ' ( </strong></span>',
  1073. 'extra_after' => '<span' . ($settings['linktree_inline'] ? ' class="smalltext"' : '') . '><strong class="nav"> )</strong></span>'
  1074. );
  1075.  
  1076. // Give wireless a linktree url to the post screen, so that they can switch to full version.
  1077. if (WIRELESS)
  1078. $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'] : '') ;
  1079.  
  1080. // 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.
  1081. // !!! This won't work if you're posting an event.
  1082. $context['num_allowed_attachments'] = empty($modSettings['attachmentNumPerPostLimit']) ? 50 : min($modSettings['attachmentNumPerPostLimit'] - count($context['current_attachments']) + (isset($deleted_attachments) ? $deleted_attachments : 0), $modSettings['attachmentNumPerPostLimit']);
  1083. $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;
  1084. $context['can_post_attachment_unapproved'] = allowedTo('post_attachment');
  1085.  
  1086. $context['subject'] = addcslashes($form_subject, '"');
  1087. $context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
  1088.  
  1089. // Needed for the editor and message icons.
  1090. require_once($sourcedir . '/Subs-Editor.php');
  1091.  
  1092. // Now create the editor.
  1093. $editorOptions = array(
  1094. 'id' => 'message',
  1095. 'value' => $context['message'],
  1096. 'labels' => array(
  1097. 'post_button' => $context['submit_label'],
  1098. ),
  1099. // We do XML preview here.
  1100. 'preview_type' => 2,
  1101. );
  1102. create_control_richedit($editorOptions);
  1103.  
  1104. // Store the ID.
  1105. $context['post_box_name'] = $editorOptions['id'];
  1106.  
  1107. $context['attached'] = '';
  1108. $context['make_poll'] = isset($_REQUEST['poll']);
  1109.  
  1110. // Message icons - customized icons are off?
  1111. $context['icons'] = getMessageIcons($board);
  1112.  
  1113. if (!empty($context['icons']))
  1114. $context['icons'][count($context['icons']) - 1]['is_last'] = true;
  1115.  
  1116. $context['icon_url'] = '';
  1117. for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
  1118. {
  1119. $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
  1120. if ($context['icons'][$i]['selected'])
  1121. $context['icon_url'] = $context['icons'][$i]['url'];
  1122. }
  1123. if (empty($context['icon_url']))
  1124. {
  1125. $context['icon_url'] = $settings[file_exists($settings['theme_dir'] . '/images/post/' . $context['icon'] . '.gif') ? 'images_url' : 'default_images_url'] . '/post/' . $context['icon'] . '.gif';
  1126. array_unshift($context['icons'], array(
  1127. 'value' => $context['icon'],
  1128. 'name' => $txt['current_icon'],
  1129. 'url' => $context['icon_url'],
  1130. 'is_last' => empty($context['icons']),
  1131. 'selected' => true,
  1132. ));
  1133. }
  1134.  
  1135. if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
  1136. getTopic();
  1137.  
  1138. // If the user can post attachments prepare the warning labels.
  1139. if ($context['can_post_attachment'])
  1140. {
  1141. $context['allowed_extensions'] = strtr($modSettings['attachmentExtensions'], array(',' => ', '));
  1142. $context['attachment_restrictions'] = array();
  1143. $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
  1144. foreach ($attachmentRestrictionTypes as $type)
  1145. if (!empty($modSettings[$type]))
  1146. $context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type], $modSettings[$type]);
  1147. }
  1148.  
  1149. $context['back_to_topic'] = isset($_REQUEST['goback']) || (isset($_REQUEST['msg']) && !isset($_REQUEST['subject']));
  1150. $context['show_additional_options'] = !empty($_POST['additional_options']) || !empty($_SESSION['temp_attachments']) || !empty($deleted_attachments);
  1151.  
  1152. $context['is_new_topic'] = empty($topic);
  1153. $context['is_new_post'] = !isset($_REQUEST['msg']);
  1154. $context['is_first_post'] = $context['is_new_topic'] || (isset($_REQUEST['msg']) && $_REQUEST['msg'] == $id_first_msg);
  1155.  
  1156. // Do we need to show the visual verification image?
  1157. $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));
  1158. if ($context['require_verification'])
  1159. {
  1160. require_once($sourcedir . '/Subs-Editor.php');
  1161. $verificationOptions = array(
  1162. 'id' => 'post',
  1163. );
  1164. $context['require_verification'] = create_control_verification($verificationOptions);
  1165. $context['visual_verification_id'] = $verificationOptions['id'];
  1166. }
  1167.  
  1168. // If they came from quick reply, and have to enter verification details, give them some notice.
  1169. if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
  1170. {
  1171. $context['post_error']['messages'][] = $txt['enter_verification_details'];
  1172. $context['error_type'] = 'minor';
  1173. }
  1174.  
  1175. // WYSIWYG only works if BBC is enabled
  1176. $modSettings['disable_wysiwyg'] = !empty($modSettings['disable_wysiwyg']) || empty($modSettings['enableBBC']);
  1177.  
  1178. // Register this form in the session variables.
  1179. checkSubmitOnce('register');
  1180.  
  1181. // Finally, load the template.
  1182. if (WIRELESS)
  1183. $context['sub_template'] = WIRELESS_PROTOCOL . '_post';
  1184. elseif (!isset($_REQUEST['xml']))
  1185. loadTemplate('Post');
  1186. }
  1187.  
  1188. function Post2()
  1189. {
  1190. global $board, $topic, $txt, $modSettings, $sourcedir, $context;
  1191. global $user_info, $board_info, $options, $smcFunc;
  1192.  
  1193. // No need!
  1194. $context['robot_no_index'] = true;
  1195.  
  1196. // If we came from WYSIWYG then turn it back into BBC regardless.
  1197. if (!empty($_REQUEST['message_mode']) && isset($_REQUEST['message']))
  1198. {
  1199. require_once($sourcedir . '/Subs-Editor.php');
  1200.  
  1201. $_REQUEST['message'] = html_to_bbc($_REQUEST['message']);
  1202.  
  1203. // We need to unhtml it now as it gets done shortly.
  1204. $_REQUEST['message'] = un_htmlspecialchars($_REQUEST['message']);
  1205.  
  1206. // We need this for everything else.
  1207. $_POST['message'] = $_REQUEST['message'];
  1208. }
  1209.  
  1210. // Previewing? Go back to start.
  1211. if (isset($_REQUEST['preview']))
  1212. return Post();
  1213.  
  1214. // Prevent double submission of this form.
  1215. checkSubmitOnce('check');
  1216.  
  1217. // No errors as yet.
  1218. $post_errors = array();
  1219.  
  1220. // If the session has timed out, let the user re-submit their form.
  1221. if (checkSession('post', '', false) != '')
  1222. $post_errors[] = 'session_timeout';
  1223.  
  1224. // Wrong verification code?
  1225. 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)))
  1226. {
  1227. require_once($sourcedir . '/Subs-Editor.php');
  1228. $verificationOptions = array(
  1229. 'id' => 'post',
  1230. );
  1231. $context['require_verification'] = create_control_verification($verificationOptions, empty($_REQUEST['from_qr']));
  1232. // If it's someone from quick reply, don't show them errors.
  1233. if (!empty($_REQUEST['from_qr']))
  1234. {
  1235. $context['post_error']['need_qr_verification'] = true;
  1236. return Post();
  1237. }
  1238. elseif (is_array($context['require_verification']))
  1239. $post_errors = array_merge($post_errors, $context['require_verification']);
  1240. }
  1241.  
  1242. require_once($sourcedir . '/Subs-Post.php');
  1243. loadLanguage('Post');
  1244.  
  1245. // If this isn't a new topic load the topic info that we need.
  1246. if (!empty($topic))
  1247. {
  1248. $request = $smcFunc['db_query']('', '
  1249. SELECT locked, is_sticky, id_poll, approved, num_replies, id_first_msg, id_member_started, id_board
  1250. FROM {db_prefix}topics
  1251. WHERE id_topic = {int:current_topic}
  1252. LIMIT 1',
  1253. 'current_topic' => $topic,
  1254. )
  1255. );
  1256. $topic_info = $smcFunc['db_fetch_assoc']($request);
  1257. $smcFunc['db_free_result']($request);
  1258.  
  1259. // Though the topic should be there, it might have vanished.
  1260. if (!is_array($topic_info))
  1261. fatal_lang_error('topic_doesnt_exist');
  1262.  
  1263. // Did this topic suddenly move? Just checking...
  1264. if ($topic_info['id_board'] != $board)
  1265. fatal_lang_error('not_a_topic');
  1266. }
  1267.  
  1268. // Replying to a topic?
  1269. if (!empty($topic) && !isset($_REQUEST['msg']))
  1270. {
  1271. // Don't allow a post if it's locked.
  1272. if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
  1273. fatal_lang_error('topic_locked', false);
  1274.  
  1275. // Sorry, multiple polls aren't allowed... yet. You should stop giving me ideas :P.
  1276. if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
  1277. unset($_REQUEST['poll']);
  1278.  
  1279. // Do the permissions and approval stuff...
  1280. $becomesApproved = true;
  1281. if ($topic_info['id_member_started'] != $user_info['id'])
  1282. {
  1283. if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
  1284. $becomesApproved = false;
  1285. else
  1286. isAllowedTo('post_reply_any');
  1287. }
  1288. elseif (!allowedTo('post_reply_any'))
  1289. {
  1290. if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
  1291. $becomesApproved = false;
  1292. else
  1293. isAllowedTo('post_reply_own');
  1294. }
  1295.  
  1296. if (isset($_POST['lock']))
  1297. {
  1298. // Nothing is changed to the lock.
  1299. if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
  1300. unset($_POST['lock']);
  1301. // You're have no permission to lock this topic.
  1302. elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
  1303. unset($_POST['lock']);
  1304. // You are allowed to (un)lock your own topic only.
  1305. elseif (!allowedTo('lock_any'))
  1306. {
  1307. // You cannot override a moderator lock.
  1308. if ($topic_info['locked'] == 1)
  1309. unset($_POST['lock']);
  1310. else
  1311. $_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
  1312. }
  1313. // Hail mighty moderator, (un)lock this topic immediately.
  1314. else
  1315. $_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
  1316. }
  1317.  
  1318. // So you wanna (un)sticky this...let's see.
  1319. if (isset($_POST['sticky']) && (empty($modSettings['enableStickyTopics']) || $_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
  1320. unset($_POST['sticky']);
  1321.  
  1322. // If the number of replies has changed, if the setting is enabled, go back to Post() - which handles the error.
  1323. $newReplies = isset($_POST['num_replies']) && $topic_info['num_replies'] > $_POST['num_replies'] ? $topic_info['num_replies'] - $_POST['num_replies'] : 0;
  1324. if (empty($options['no_new_reply_warning']) && !empty($newReplies))
  1325. {
  1326. $_REQUEST['preview'] = true;
  1327. return Post();
  1328. }
  1329.  
  1330. $posterIsGuest = $user_info['is_guest'];
  1331. }
  1332. // Posting a new topic.
  1333. elseif (empty($topic))
  1334. {
  1335. // Now don't be silly, new topics will get their own id_msg soon enough.
  1336. unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
  1337.  
  1338. // Do like, the permissions, for safety and stuff...
  1339. $becomesApproved = true;
  1340. if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
  1341. $becomesApproved = false;
  1342. else
  1343. isAllowedTo('post_new');
  1344.  
  1345. if (isset($_POST['lock']))
  1346. {
  1347. // New topics are by default not locked.
  1348. if (empty($_POST['lock']))
  1349. unset($_POST['lock']);
  1350. // Besides, you need permission.
  1351. elseif (!allowedTo(array('lock_any', 'lock_own')))
  1352. unset($_POST['lock']);
  1353. // A moderator-lock (1) can override a user-lock (2).
  1354. else
  1355. $_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
  1356. }
  1357.  
  1358. if (isset($_POST['sticky']) && (empty($modSettings['enableStickyTopics']) || empty($_POST['sticky']) || !allowedTo('make_sticky')))
  1359. unset($_POST['sticky']);
  1360.  
  1361. $posterIsGuest = $user_info['is_guest'];
  1362. }
  1363. // Modifying an existing message?
  1364. elseif (isset($_REQUEST['msg']) && !empty($topic))
  1365. {
  1366. $_REQUEST['msg'] = (int) $_REQUEST['msg'];
  1367.  
  1368. $request = $smcFunc['db_query']('', '
  1369. SELECT id_member, poster_name, poster_email, poster_time, approved
  1370. FROM {db_prefix}messages
  1371. WHERE id_msg = {int:id_msg}
  1372. LIMIT 1',
  1373. 'id_msg' => $_REQUEST['msg'],
  1374. )
  1375. );
  1376. if ($smcFunc['db_num_rows']($request) == 0)
  1377. fatal_lang_error('cant_find_messages', false);
  1378. $row = $smcFunc['db_fetch_assoc']($request);
  1379. $smcFunc['db_free_result']($request);
  1380.  
  1381. if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
  1382. fatal_lang_error('topic_locked', false);
  1383.  
  1384. if (isset($_POST['lock']))
  1385. {
  1386. // Nothing changes to the lock status.
  1387. if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
  1388. unset($_POST['lock']);
  1389. // You're simply not allowed to (un)lock this.
  1390. elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
  1391. unset($_POST['lock']);
  1392. // You're only allowed to lock your own topics.
  1393. elseif (!allowedTo('lock_any'))
  1394. {
  1395. // You're not allowed to break a moderator's lock.
  1396. if ($topic_info['locked'] == 1)
  1397. unset($_POST['lock']);
  1398. // Lock it with a soft lock or unlock it.
  1399. else
  1400. $_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
  1401. }
  1402. // You must be the moderator.
  1403. else
  1404. $_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
  1405. }
  1406.  
  1407. // Change the sticky status of this topic?
  1408. if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
  1409. unset($_POST['sticky']);
  1410.  
  1411. if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
  1412. {
  1413. if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
  1414. fatal_lang_error('modify_post_time_passed', false);
  1415. elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
  1416. isAllowedTo('modify_replies');
  1417. else
  1418. isAllowedTo('modify_own');
  1419. }
  1420. elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
  1421. {
  1422. isAllowedTo('modify_replies');
  1423.  
  1424. // If you're modifying a reply, I say it better be logged...
  1425. $moderationAction = true;
  1426. }
  1427. else
  1428. {
  1429. isAllowedTo('modify_any');
  1430.  
  1431. // Log it, assuming you're not modifying your own post.
  1432. if ($row['id_member'] != $user_info['id'])
  1433. $moderationAction = true;
  1434. }
  1435.  
  1436. $posterIsGuest = empty($row['id_member']);
  1437.  
  1438. // Can they approve it?
  1439. $can_approve = allowedTo('approve_posts');
  1440. $becomesApproved = $modSettings['postmod_active'] ? ($can_approve && !$row['approved'] ? (!empty($_REQUEST['approve']) ? 1 : 0) : $row['approved']) : 1;
  1441. $approve_has_changed = $row['approved'] != $becomesApproved;
  1442.  
  1443. if (!allowedTo('moderate_forum') || !$posterIsGuest)
  1444. {
  1445. $_POST['guestname'] = $row['poster_name'];
  1446. $_POST['email'] = $row['poster_email'];
  1447. }
  1448. }
  1449.  
  1450. // If the poster is a guest evaluate the legality of name and email.
  1451. if ($posterIsGuest)
  1452. {
  1453. $_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
  1454. $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
  1455.  
  1456. if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
  1457. $post_errors[] = 'no_name';
  1458. if ($smcFunc['strlen']($_POST['guestname']) > 25)
  1459. $post_errors[] = 'long_name';
  1460.  
  1461. if (empty($modSettings['guest_post_no_email']))
  1462. {
  1463. // Only check if they changed it!
  1464. if (!isset($row) || $row['poster_email'] != $_POST['email'])
  1465. {
  1466. if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
  1467. $post_errors[] = 'no_email';
  1468. if (!allowedTo('moderate_forum') && preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['email']) == 0)
  1469. $post_errors[] = 'bad_email';
  1470. }
  1471.  
  1472. // Now make sure this email address is not banned from posting.
  1473. isBannedEmail($_POST['email'], 'cannot_post', sprintf($txt['you_are_post_banned'], $txt['guest_title']));
  1474. }
  1475.  
  1476. // In case they are making multiple posts this visit, help them along by storing their name.
  1477. if (empty($post_errors))
  1478. {
  1479. $_SESSION['guest_name'] = $_POST['guestname'];
  1480. $_SESSION['guest_email'] = $_POST['email'];
  1481. }
  1482. }
  1483.  
  1484. // Check the subject and message.
  1485. if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
  1486. $post_errors[] = 'no_subject';
  1487. if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
  1488. $post_errors[] = 'no_message';
  1489. elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
  1490. $post_errors[] = 'long_message';
  1491. else
  1492. {
  1493. // Prepare the message a bit for some additional testing.
  1494. $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
  1495.  
  1496. // Preparse code. (Zef)
  1497. if ($user_info['is_guest'])
  1498. $user_info['name'] = $_POST['guestname'];
  1499. preparsecode($_POST['message']);
  1500.  
  1501. // Let's see if there's still some content left without the tags.
  1502. if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
  1503. $post_errors[] = 'no_message';
  1504. }
  1505. if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
  1506. $post_errors[] = 'no_event';
  1507. // You are not!
  1508. if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
  1509. fatal_error('Knave! Masquerader! Charlatan!', false);
  1510.  
  1511. // Validate the poll...
  1512. if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
  1513. {
  1514. if (!empty($topic) && !isset($_REQUEST['msg']))
  1515. fatal_lang_error('no_access', false);
  1516.  
  1517. // This is a new topic... so it's a new poll.
  1518. if (empty($topic))
  1519. isAllowedTo('poll_post');
  1520. // Can you add to your own topics?
  1521. elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
  1522. isAllowedTo('poll_add_own');
  1523. // Can you add polls to any topic, then?
  1524. else
  1525. isAllowedTo('poll_add_any');
  1526.  
  1527. if (!isset($_POST['question']) || trim($_POST['question']) == '')
  1528. $post_errors[] = 'no_question';
  1529.  
  1530. $_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
  1531.  
  1532. // Get rid of empty ones.
  1533. foreach ($_POST['options'] as $k => $option)
  1534. if ($option == '')
  1535. unset($_POST['options'][$k], $_POST['options'][$k]);
  1536.  
  1537. // What are you going to vote between with one choice?!?
  1538. if (count($_POST['options']) < 2)
  1539. $post_errors[] = 'poll_few';
  1540. }
  1541.  
  1542. if ($posterIsGuest)
  1543. {
  1544. // If user is a guest, make sure the chosen name isn't taken.
  1545. require_once($sourcedir . '/Subs-Members.php');
  1546. if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
  1547. $post_errors[] = 'bad_name';
  1548. }
  1549. // If the user isn't a guest, get his or her name and email.
  1550. elseif (!isset($_REQUEST['msg']))
  1551. {
  1552. $_POST['guestname'] = $user_info['username'];
  1553. $_POST['email'] = $user_info['email'];
  1554. }
  1555.  
  1556. // Any mistakes?
  1557. if (!empty($post_errors))
  1558. {
  1559. loadLanguage('Errors');
  1560. // Previewing.
  1561. $_REQUEST['preview'] = true;
  1562.  
  1563. $context['post_error'] = array('messages' => array());
  1564. foreach ($post_errors as $post_error)
  1565. {
  1566. $context['post_error'][$post_error] = true;
  1567. if ($post_error == 'long_message')
  1568. $txt['error_' . $post_error] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
  1569.  
  1570. $context['post_error']['messages'][] = $txt['error_' . $post_error];
  1571. }
  1572.  
  1573. return Post();
  1574. }
  1575.  
  1576. // Make sure the user isn't spamming the board.
  1577. if (!isset($_REQUEST['msg']))
  1578. spamProtection('post');
  1579.  
  1580. // At about this point, we're posting and that's that.
  1581.  
  1582. // Add special html entities to the subject, name, and email.
  1583. $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
  1584. $_POST['guestname'] = htmlspecialchars($_POST['guestname']);
  1585. $_POST['email'] = htmlspecialchars($_POST['email']);
  1586.  
  1587. // At this point, we want to make sure the subject isn't too long.
  1588. if ($smcFunc['strlen']($_POST['subject']) > 100)
  1589. $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
  1590.  
  1591. // Make the poll...
  1592. if (isset($_REQUEST['poll']))
  1593. {
  1594. // Make sure that the user has not entered a ridiculous number of
Name:
Email:
Code/text to paste:
  • Enable code highlighting
  • Code Language:
  • A duck, cat and a goose walk into a bar. How many animals walked into a bar?:
Highslide for Wordpress Plugin