PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/sources/controllers/Display.controller.php

https://github.com/Arantor/Elkarte
PHP | 1452 lines | 1025 code | 179 blank | 248 comment | 330 complexity | 0a34e23940845633bfc6140159aa3881 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0

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

  1. <?php
  2. /**
  3. * @name ElkArte Forum
  4. * @copyright ElkArte Forum contributors
  5. * @license BSD http://opensource.org/licenses/BSD-3-Clause
  6. *
  7. * This software is a derived product, based on:
  8. *
  9. * Simple Machines Forum (SMF)
  10. * copyright: 2011 Simple Machines (http://www.simplemachines.org)
  11. * license: BSD, See included LICENSE.TXT for terms and conditions.
  12. *
  13. * @version 1.0 Alpha
  14. *
  15. * This is perhaps the most important and probably most accessed file in all
  16. * of ELKARTE. This file controls topic, message, and attachment display.
  17. *
  18. */
  19. if (!defined('ELKARTE'))
  20. die('No access...');
  21. /**
  22. * The central part of the board - topic display.
  23. * This function loads the posts in a topic up so they can be displayed.
  24. * It uses the main sub template of the Display template.
  25. * It requires a topic, and can go to the previous or next topic from it.
  26. * It jumps to the correct post depending on a number/time/IS_MSG passed.
  27. * It depends on the messages_per_page, defaultMaxMessages and enableAllMessages settings.
  28. * It is accessed by ?topic=id_topic.START.
  29. */
  30. function Display()
  31. {
  32. global $scripturl, $txt, $modSettings, $context, $settings, $smcFunc;
  33. global $options, $user_info, $board_info, $topic, $board;
  34. global $attachments, $messages_request, $topicinfo, $language, $all_posters;
  35. // What are you gonna display if these are empty?!
  36. if (empty($topic))
  37. fatal_lang_error('no_board', false);
  38. // Load the template
  39. loadTemplate('Display');
  40. // And the topic functions
  41. require_once(SUBSDIR . '/Topic.subs.php');
  42. // Not only does a prefetch make things slower for the server, but it makes it impossible to know if they read it.
  43. if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
  44. {
  45. ob_end_clean();
  46. header('HTTP/1.1 403 Prefetch Forbidden');
  47. die;
  48. }
  49. // How much are we sticking on each page?
  50. $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
  51. // Let's do some work on what to search index.
  52. if (count($_GET) > 2)
  53. {
  54. foreach ($_GET as $k => $v)
  55. {
  56. if (!in_array($k, array('topic', 'board', 'start', session_name())))
  57. $context['robot_no_index'] = true;
  58. }
  59. }
  60. if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
  61. $context['robot_no_index'] = true;
  62. // Find the previous or next topic. Make a fuss if there are no more.
  63. if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
  64. {
  65. // No use in calculating the next topic if there's only one.
  66. if ($board_info['num_topics'] > 1)
  67. {
  68. $includeUnapproved = (!$modSettings['postmod_active'] || allowedTo('approve_posts'));
  69. $includeStickies = !empty($modSettings['enableStickyTopics']);
  70. $topic = $_REQUEST['prev_next'] === 'prev' ? previousTopic($topic, $board, $user_info['id'], $includeUnapproved, $includeStickies) : nextTopic($topic, $board, $user_info['id'], $includeUnapproved, $includeStickies);
  71. $context['current_topic'] = $topic;
  72. }
  73. // Go to the newest message on this topic.
  74. $_REQUEST['start'] = 'new';
  75. }
  76. // Add 1 to the number of views of this topic (except for robots).
  77. if (!$user_info['possibly_robot'] && (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic))
  78. {
  79. increaseViewCounter($topic);
  80. $_SESSION['last_read_topic'] = $topic;
  81. }
  82. $topic_parameters = array(
  83. 'current_member' => $user_info['id'],
  84. 'current_topic' => $topic,
  85. 'current_board' => $board,
  86. );
  87. $topic_selects = array();
  88. $topic_tables = array();
  89. call_integration_hook('integrate_display_topic', array($topic_selects, $topic_tables, $topic_parameters));
  90. // @todo Why isn't this cached?
  91. // @todo if we get id_board in this query and cache it, we can save a query on posting
  92. // Load the topic details
  93. $topicinfo = getTopicInfo($topic_parameters, true, $topic_selects, $topic_tables);
  94. if (empty($topicinfo))
  95. fatal_lang_error('not_a_topic', false);
  96. // Is this a moved topic that we are redirecting to?
  97. if (!empty($topicinfo['id_redirect_topic']))
  98. {
  99. markTopicsRead(array($user_info['id'], $topic, $topicinfo['id_last_msg'], 0), $topicinfo['new_from'] !== 0);
  100. redirectexit('topic=' . $topicinfo['id_redirect_topic'] . '.0');
  101. }
  102. $context['real_num_replies'] = $context['num_replies'] = $topicinfo['num_replies'];
  103. $context['topic_first_message'] = $topicinfo['id_first_msg'];
  104. $context['topic_last_message'] = $topicinfo['id_last_msg'];
  105. $context['topic_disregarded'] = isset($topicinfo['disregarded']) ? $topicinfo['disregarded'] : 0;
  106. // Add up unapproved replies to get real number of replies...
  107. if ($modSettings['postmod_active'] && allowedTo('approve_posts'))
  108. $context['real_num_replies'] += $topicinfo['unapproved_posts'] - ($topicinfo['approved'] ? 0 : 1);
  109. // If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
  110. $includeUnapproved = !$modSettings['postmod_active'] || allowedTo('approve_posts');
  111. if (!$includeUnapproved && $topicinfo['unapproved_posts'] && !$user_info['is_guest'])
  112. {
  113. $myUnapprovedPosts = unapprovedPosts($topic, $user_info['id']);
  114. $context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($topicinfo['approved'] ? 1 : 0);
  115. }
  116. elseif ($user_info['is_guest'])
  117. $context['total_visible_posts'] = $context['num_replies'] + ($topicinfo['approved'] ? 1 : 0);
  118. else
  119. $context['total_visible_posts'] = $context['num_replies'] + $topicinfo['unapproved_posts'] + ($topicinfo['approved'] ? 1 : 0);
  120. // When was the last time this topic was replied to? Should we warn them about it?
  121. $request = $smcFunc['db_query']('', '
  122. SELECT poster_time
  123. FROM {db_prefix}messages
  124. WHERE id_msg = {int:id_last_msg}
  125. LIMIT 1',
  126. array(
  127. 'id_last_msg' => $topicinfo['id_last_msg'],
  128. )
  129. );
  130. list ($lastPostTime) = $smcFunc['db_fetch_row']($request);
  131. $smcFunc['db_free_result']($request);
  132. $context['oldTopicError'] = !empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($topicinfo['is_sticky']);
  133. // The start isn't a number; it's information about what to do, where to go.
  134. if (!is_numeric($_REQUEST['start']))
  135. {
  136. // Redirect to the page and post with new messages, originally by Omar Bazavilvazo.
  137. if ($_REQUEST['start'] == 'new')
  138. {
  139. // Guests automatically go to the last post.
  140. if ($user_info['is_guest'])
  141. {
  142. $context['start_from'] = $context['total_visible_posts'] - 1;
  143. $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
  144. }
  145. else
  146. {
  147. // Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
  148. $request = $smcFunc['db_query']('', '
  149. SELECT IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from
  150. FROM {db_prefix}topics AS t
  151. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = {int:current_topic} AND lt.id_member = {int:current_member})
  152. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})
  153. WHERE t.id_topic = {int:current_topic}
  154. LIMIT 1',
  155. array(
  156. 'current_board' => $board,
  157. 'current_member' => $user_info['id'],
  158. 'current_topic' => $topic,
  159. )
  160. );
  161. list ($new_from) = $smcFunc['db_fetch_row']($request);
  162. $smcFunc['db_free_result']($request);
  163. // Fall through to the next if statement.
  164. $_REQUEST['start'] = 'msg' . $new_from;
  165. }
  166. }
  167. // Start from a certain time index, not a message.
  168. if (substr($_REQUEST['start'], 0, 4) == 'from')
  169. {
  170. $timestamp = (int) substr($_REQUEST['start'], 4);
  171. if ($timestamp === 0)
  172. $_REQUEST['start'] = 0;
  173. else
  174. {
  175. // Find the number of messages posted before said time...
  176. $request = $smcFunc['db_query']('', '
  177. SELECT COUNT(*)
  178. FROM {db_prefix}messages
  179. WHERE poster_time < {int:timestamp}
  180. AND id_topic = {int:current_topic}' . ($modSettings['postmod_active'] && $topicinfo['unapproved_posts'] && !allowedTo('approve_posts') ? '
  181. AND (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')' : ''),
  182. array(
  183. 'current_topic' => $topic,
  184. 'current_member' => $user_info['id'],
  185. 'is_approved' => 1,
  186. 'timestamp' => $timestamp,
  187. )
  188. );
  189. list ($context['start_from']) = $smcFunc['db_fetch_row']($request);
  190. $smcFunc['db_free_result']($request);
  191. // Handle view_newest_first options, and get the correct start value.
  192. $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : $context['total_visible_posts'] - $context['start_from'] - 1;
  193. }
  194. }
  195. // Link to a message...
  196. elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
  197. {
  198. $virtual_msg = (int) substr($_REQUEST['start'], 3);
  199. if (!$topicinfo['unapproved_posts'] && $virtual_msg >= $topicinfo['id_last_msg'])
  200. $context['start_from'] = $context['total_visible_posts'] - 1;
  201. elseif (!$topicinfo['unapproved_posts'] && $virtual_msg <= $topicinfo['id_first_msg'])
  202. $context['start_from'] = 0;
  203. else
  204. {
  205. // Find the start value for that message......
  206. $request = $smcFunc['db_query']('', '
  207. SELECT COUNT(*)
  208. FROM {db_prefix}messages
  209. WHERE id_msg < {int:virtual_msg}
  210. AND id_topic = {int:current_topic}' . ($modSettings['postmod_active'] && $topicinfo['unapproved_posts'] && !allowedTo('approve_posts') ? '
  211. AND (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')' : ''),
  212. array(
  213. 'current_member' => $user_info['id'],
  214. 'current_topic' => $topic,
  215. 'virtual_msg' => $virtual_msg,
  216. 'is_approved' => 1,
  217. 'no_member' => 0,
  218. )
  219. );
  220. list ($context['start_from']) = $smcFunc['db_fetch_row']($request);
  221. $smcFunc['db_free_result']($request);
  222. }
  223. // We need to reverse the start as well in this case.
  224. $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : $context['total_visible_posts'] - $context['start_from'] - 1;
  225. }
  226. }
  227. // Create a previous next string if the selected theme has it as a selected option.
  228. $context['previous_next'] = $modSettings['enablePreviousNext'] ? '<a href="' . $scripturl . '?topic=' . $topic . '.0;prev_next=prev#new">' . $txt['previous_next_back'] . '</a> - <a href="' . $scripturl . '?topic=' . $topic . '.0;prev_next=next#new">' . $txt['previous_next_forward'] . '</a>' : '';
  229. // Check if spellchecking is both enabled and actually working. (for quick reply.)
  230. $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && function_exists('pspell_new');
  231. // Do we need to show the visual verification image?
  232. $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));
  233. if ($context['require_verification'])
  234. {
  235. require_once(SUBSDIR . '/Editor.subs.php');
  236. $verificationOptions = array(
  237. 'id' => 'post',
  238. );
  239. $context['require_verification'] = create_control_verification($verificationOptions);
  240. $context['visual_verification_id'] = $verificationOptions['id'];
  241. }
  242. // Are we showing signatures - or disabled fields?
  243. $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
  244. $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
  245. // Censor the title...
  246. censorText($topicinfo['subject']);
  247. $context['page_title'] = $topicinfo['subject'];
  248. // Is this topic sticky, or can it even be?
  249. $topicinfo['is_sticky'] = empty($modSettings['enableStickyTopics']) ? '0' : $topicinfo['is_sticky'];
  250. // Default this topic to not marked for notifications... of course...
  251. $context['is_marked_notify'] = false;
  252. // Did we report a post to a moderator just now?
  253. $context['report_sent'] = isset($_GET['reportsent']);
  254. // Let's get nosey, who is viewing this topic?
  255. if (!empty($settings['display_who_viewing']))
  256. {
  257. // Start out with no one at all viewing it.
  258. $context['view_members'] = array();
  259. $context['view_members_list'] = array();
  260. $context['view_num_hidden'] = 0;
  261. // Search for members who have this topic set in their GET data.
  262. $request = $smcFunc['db_query']('', '
  263. SELECT
  264. lo.id_member, lo.log_time, mem.real_name, mem.member_name, mem.show_online,
  265. mg.online_color, mg.id_group, mg.group_name
  266. FROM {db_prefix}log_online AS lo
  267. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lo.id_member)
  268. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_id_group} THEN mem.id_post_group ELSE mem.id_group END)
  269. WHERE INSTR(lo.url, {string:in_url_string}) > 0 OR lo.session = {string:session}',
  270. array(
  271. 'reg_id_group' => 0,
  272. 'in_url_string' => 's:5:"topic";i:' . $topic . ';',
  273. 'session' => $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(),
  274. )
  275. );
  276. while ($row = $smcFunc['db_fetch_assoc']($request))
  277. {
  278. if (empty($row['id_member']))
  279. continue;
  280. if (!empty($row['online_color']))
  281. $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
  282. else
  283. $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  284. $is_buddy = in_array($row['id_member'], $user_info['buddies']);
  285. if ($is_buddy)
  286. $link = '<strong>' . $link . '</strong>';
  287. // Add them both to the list and to the more detailed list.
  288. if (!empty($row['show_online']) || allowedTo('moderate_forum'))
  289. $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
  290. $context['view_members'][$row['log_time'] . $row['member_name']] = array(
  291. 'id' => $row['id_member'],
  292. 'username' => $row['member_name'],
  293. 'name' => $row['real_name'],
  294. 'group' => $row['id_group'],
  295. 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
  296. 'link' => $link,
  297. 'is_buddy' => $is_buddy,
  298. 'hidden' => empty($row['show_online']),
  299. );
  300. if (empty($row['show_online']))
  301. $context['view_num_hidden']++;
  302. }
  303. // The number of guests is equal to the rows minus the ones we actually used ;).
  304. $context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']);
  305. $smcFunc['db_free_result']($request);
  306. // Sort the list.
  307. krsort($context['view_members']);
  308. krsort($context['view_members_list']);
  309. }
  310. // If all is set, but not allowed... just unset it.
  311. $can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
  312. if (isset($_REQUEST['all']) && !$can_show_all)
  313. unset($_REQUEST['all']);
  314. // Otherwise, it must be allowed... so pretend start was -1.
  315. elseif (isset($_REQUEST['all']))
  316. $_REQUEST['start'] = -1;
  317. // Construct the page index, allowing for the .START method...
  318. $context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
  319. $context['start'] = $_REQUEST['start'];
  320. // This is information about which page is current, and which page we're on - in case you don't like the constructed page index. (again, wireles..)
  321. $context['page_info'] = array(
  322. 'current_page' => $_REQUEST['start'] / $context['messages_per_page'] + 1,
  323. 'num_pages' => floor(($context['total_visible_posts'] - 1) / $context['messages_per_page']) + 1,
  324. );
  325. // Figure out all the link to the next/prev/first/last/etc. for wireless mainly.
  326. $context['links'] = array(
  327. 'first' => $_REQUEST['start'] >= $context['messages_per_page'] ? $scripturl . '?topic=' . $topic . '.0' : '',
  328. 'prev' => $_REQUEST['start'] >= $context['messages_per_page'] ? $scripturl . '?topic=' . $topic . '.' . ($_REQUEST['start'] - $context['messages_per_page']) : '',
  329. 'next' => $_REQUEST['start'] + $context['messages_per_page'] < $context['total_visible_posts'] ? $scripturl . '?topic=' . $topic. '.' . ($_REQUEST['start'] + $context['messages_per_page']) : '',
  330. 'last' => $_REQUEST['start'] + $context['messages_per_page'] < $context['total_visible_posts'] ? $scripturl . '?topic=' . $topic. '.' . (floor($context['total_visible_posts'] / $context['messages_per_page']) * $context['messages_per_page']) : '',
  331. 'up' => $scripturl . '?board=' . $board . '.0'
  332. );
  333. // If they are viewing all the posts, show all the posts, otherwise limit the number.
  334. if ($can_show_all)
  335. {
  336. if (isset($_REQUEST['all']))
  337. {
  338. // No limit! (actually, there is a limit, but...)
  339. $context['messages_per_page'] = -1;
  340. $context['page_index'] .= empty($modSettings['compactTopicPagesEnable']) ? '<strong>' . $txt['all'] . '</strong> ' : '[<strong>' . $txt['all'] . '</strong>] ';
  341. // Set start back to 0...
  342. $_REQUEST['start'] = 0;
  343. }
  344. // They aren't using it, but the *option* is there, at least.
  345. else
  346. $context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
  347. }
  348. // Build the link tree.
  349. $context['linktree'][] = array(
  350. 'url' => $scripturl . '?topic=' . $topic . '.0',
  351. 'name' => $topicinfo['subject'],
  352. );
  353. // Build a list of this board's moderators.
  354. $context['moderators'] = &$board_info['moderators'];
  355. $context['link_moderators'] = array();
  356. if (!empty($board_info['moderators']))
  357. {
  358. // Add a link for each moderator...
  359. foreach ($board_info['moderators'] as $mod)
  360. $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
  361. // And show it after the board's name.
  362. $context['linktree'][count($context['linktree']) - 2]['extra_after'] = '<span class="board_moderators"> (' . (count($context['link_moderators']) == 1 ? $txt['moderator'] : $txt['moderators']) . ': ' . implode(', ', $context['link_moderators']) . ')</span>';
  363. }
  364. // Information about the current topic...
  365. $context['is_locked'] = $topicinfo['locked'];
  366. $context['is_sticky'] = $topicinfo['is_sticky'];
  367. $context['is_very_hot'] = $topicinfo['num_replies'] >= $modSettings['hotTopicVeryPosts'];
  368. $context['is_hot'] = $topicinfo['num_replies'] >= $modSettings['hotTopicPosts'];
  369. $context['is_approved'] = $topicinfo['approved'];
  370. // @todo Tricks? We don't want to show the poll icon in the topic class here, so pretend it's not one.
  371. $context['is_poll'] = false;
  372. determineTopicClass($context);
  373. $context['is_poll'] = $topicinfo['id_poll'] > 0 && $modSettings['pollMode'] == '1' && allowedTo('poll_view');
  374. // Did this user start the topic or not?
  375. $context['user']['started'] = $user_info['id'] == $topicinfo['id_member_started'] && !$user_info['is_guest'];
  376. $context['topic_starter_id'] = $topicinfo['id_member_started'];
  377. // Set the topic's information for the template.
  378. $context['subject'] = $topicinfo['subject'];
  379. $context['num_views'] = $topicinfo['num_views'];
  380. $context['num_views_text'] = $context['num_views'] == 1 ? $txt['read_one_time'] : sprintf($txt['read_many_times'], $context['num_views']);
  381. $context['mark_unread_time'] = !empty($virtual_msg) ? $virtual_msg : $topicinfo['new_from'];
  382. // Set a canonical URL for this page.
  383. $context['canonical_url'] = $scripturl . '?topic=' . $topic . '.' . $context['start'];
  384. // For quick reply we need a response prefix in the default forum language.
  385. if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
  386. {
  387. if ($language === $user_info['language'])
  388. $context['response_prefix'] = $txt['response_prefix'];
  389. else
  390. {
  391. loadLanguage('index', $language, false);
  392. $context['response_prefix'] = $txt['response_prefix'];
  393. loadLanguage('index');
  394. }
  395. cache_put_data('response_prefix', $context['response_prefix'], 600);
  396. }
  397. // If we want to show event information in the topic, prepare the data.
  398. if (allowedTo('calendar_view') && !empty($modSettings['cal_showInTopic']) && !empty($modSettings['cal_enabled']))
  399. {
  400. // First, try create a better time format, ignoring the "time" elements.
  401. if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
  402. $date_string = $user_info['time_format'];
  403. else
  404. $date_string = $matches[0];
  405. // Any calendar information for this topic?
  406. $request = $smcFunc['db_query']('', '
  407. SELECT cal.id_event, cal.start_date, cal.end_date, cal.title, cal.id_member, mem.real_name
  408. FROM {db_prefix}calendar AS cal
  409. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = cal.id_member)
  410. WHERE cal.id_topic = {int:current_topic}
  411. ORDER BY start_date',
  412. array(
  413. 'current_topic' => $topic,
  414. )
  415. );
  416. $context['linked_calendar_events'] = array();
  417. while ($row = $smcFunc['db_fetch_assoc']($request))
  418. {
  419. // Prepare the dates for being formatted.
  420. $start_date = sscanf($row['start_date'], '%04d-%02d-%02d');
  421. $start_date = mktime(12, 0, 0, $start_date[1], $start_date[2], $start_date[0]);
  422. $end_date = sscanf($row['end_date'], '%04d-%02d-%02d');
  423. $end_date = mktime(12, 0, 0, $end_date[1], $end_date[2], $end_date[0]);
  424. $context['linked_calendar_events'][] = array(
  425. 'id' => $row['id_event'],
  426. 'title' => $row['title'],
  427. 'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
  428. 'modify_href' => $scripturl . '?action=post;msg=' . $topicinfo['id_first_msg'] . ';topic=' . $topic . '.0;calendar;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  429. 'can_export' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
  430. 'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  431. 'start_date' => timeformat($start_date, $date_string, 'none'),
  432. 'start_timestamp' => $start_date,
  433. 'end_date' => timeformat($end_date, $date_string, 'none'),
  434. 'end_timestamp' => $end_date,
  435. 'is_last' => false
  436. );
  437. }
  438. $smcFunc['db_free_result']($request);
  439. if (!empty($context['linked_calendar_events']))
  440. $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
  441. }
  442. // Create the poll info if it exists.
  443. if ($context['is_poll'])
  444. {
  445. // Get the question and if it's locked.
  446. $request = $smcFunc['db_query']('', '
  447. SELECT
  448. p.question, p.voting_locked, p.hide_results, p.expire_time, p.max_votes, p.change_vote,
  449. p.guest_vote, p.id_member, IFNULL(mem.real_name, p.poster_name) AS poster_name, p.num_guest_voters, p.reset_poll
  450. FROM {db_prefix}polls AS p
  451. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = p.id_member)
  452. WHERE p.id_poll = {int:id_poll}
  453. LIMIT 1',
  454. array(
  455. 'id_poll' => $topicinfo['id_poll'],
  456. )
  457. );
  458. $pollinfo = $smcFunc['db_fetch_assoc']($request);
  459. $smcFunc['db_free_result']($request);
  460. $request = $smcFunc['db_query']('', '
  461. SELECT COUNT(DISTINCT id_member) AS total
  462. FROM {db_prefix}log_polls
  463. WHERE id_poll = {int:id_poll}
  464. AND id_member != {int:not_guest}',
  465. array(
  466. 'id_poll' => $topicinfo['id_poll'],
  467. 'not_guest' => 0,
  468. )
  469. );
  470. list ($pollinfo['total']) = $smcFunc['db_fetch_row']($request);
  471. $smcFunc['db_free_result']($request);
  472. // Total voters needs to include guest voters
  473. $pollinfo['total'] += $pollinfo['num_guest_voters'];
  474. // Get all the options, and calculate the total votes.
  475. $request = $smcFunc['db_query']('', '
  476. SELECT pc.id_choice, pc.label, pc.votes, IFNULL(lp.id_choice, -1) AS voted_this
  477. FROM {db_prefix}poll_choices AS pc
  478. LEFT JOIN {db_prefix}log_polls AS lp ON (lp.id_choice = pc.id_choice AND lp.id_poll = {int:id_poll} AND lp.id_member = {int:current_member} AND lp.id_member != {int:not_guest})
  479. WHERE pc.id_poll = {int:id_poll}',
  480. array(
  481. 'current_member' => $user_info['id'],
  482. 'id_poll' => $topicinfo['id_poll'],
  483. 'not_guest' => 0,
  484. )
  485. );
  486. $pollOptions = array();
  487. $realtotal = 0;
  488. $pollinfo['has_voted'] = false;
  489. while ($row = $smcFunc['db_fetch_assoc']($request))
  490. {
  491. censorText($row['label']);
  492. $pollOptions[$row['id_choice']] = $row;
  493. $realtotal += $row['votes'];
  494. $pollinfo['has_voted'] |= $row['voted_this'] != -1;
  495. }
  496. $smcFunc['db_free_result']($request);
  497. // If this is a guest we need to do our best to work out if they have voted, and what they voted for.
  498. if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
  499. {
  500. if (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $topicinfo['id_poll'] . ',') !== false)
  501. {
  502. // ;id,timestamp,[vote,vote...]; etc
  503. $guestinfo = explode(';', $_COOKIE['guest_poll_vote']);
  504. // Find the poll we're after.
  505. foreach ($guestinfo as $i => $guestvoted)
  506. {
  507. $guestvoted = explode(',', $guestvoted);
  508. if ($guestvoted[0] == $topicinfo['id_poll'])
  509. break;
  510. }
  511. // Has the poll been reset since guest voted?
  512. if ($pollinfo['reset_poll'] > $guestvoted[1])
  513. {
  514. // Remove the poll info from the cookie to allow guest to vote again
  515. unset($guestinfo[$i]);
  516. if (!empty($guestinfo))
  517. $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
  518. else
  519. unset($_COOKIE['guest_poll_vote']);
  520. }
  521. else
  522. {
  523. // What did they vote for?
  524. unset($guestvoted[0], $guestvoted[1]);
  525. foreach ($pollOptions as $choice => $details)
  526. {
  527. $pollOptions[$choice]['voted_this'] = in_array($choice, $guestvoted) ? 1 : -1;
  528. $pollinfo['has_voted'] |= $pollOptions[$choice]['voted_this'] != -1;
  529. }
  530. unset($choice, $details, $guestvoted);
  531. }
  532. unset($guestinfo, $guestvoted, $i);
  533. }
  534. }
  535. // Set up the basic poll information.
  536. $context['poll'] = array(
  537. 'id' => $topicinfo['id_poll'],
  538. 'image' => 'normal_' . (empty($pollinfo['voting_locked']) ? 'poll' : 'locked_poll'),
  539. 'question' => parse_bbc($pollinfo['question']),
  540. 'total_votes' => $pollinfo['total'],
  541. 'change_vote' => !empty($pollinfo['change_vote']),
  542. 'is_locked' => !empty($pollinfo['voting_locked']),
  543. 'options' => array(),
  544. 'lock' => allowedTo('poll_lock_any') || ($context['user']['started'] && allowedTo('poll_lock_own')),
  545. 'edit' => allowedTo('poll_edit_any') || ($context['user']['started'] && allowedTo('poll_edit_own')),
  546. 'allowed_warning' => $pollinfo['max_votes'] > 1 ? sprintf($txt['poll_options6'], min(count($pollOptions), $pollinfo['max_votes'])) : '',
  547. 'is_expired' => !empty($pollinfo['expire_time']) && $pollinfo['expire_time'] < time(),
  548. 'expire_time' => !empty($pollinfo['expire_time']) ? timeformat($pollinfo['expire_time']) : 0,
  549. 'has_voted' => !empty($pollinfo['has_voted']),
  550. 'starter' => array(
  551. 'id' => $pollinfo['id_member'],
  552. 'name' => $row['poster_name'],
  553. 'href' => $pollinfo['id_member'] == 0 ? '' : $scripturl . '?action=profile;u=' . $pollinfo['id_member'],
  554. 'link' => $pollinfo['id_member'] == 0 ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $pollinfo['id_member'] . '">' . $row['poster_name'] . '</a>'
  555. )
  556. );
  557. // Make the lock and edit permissions defined above more directly accessible.
  558. $context['allow_lock_poll'] = $context['poll']['lock'];
  559. $context['allow_edit_poll'] = $context['poll']['edit'];
  560. // You're allowed to vote if:
  561. // 1. the poll did not expire, and
  562. // 2. you're either not a guest OR guest voting is enabled... and
  563. // 3. you're not trying to view the results, and
  564. // 4. the poll is not locked, and
  565. // 5. you have the proper permissions, and
  566. // 6. you haven't already voted before.
  567. $context['allow_vote'] = !$context['poll']['is_expired'] && (!$user_info['is_guest'] || ($pollinfo['guest_vote'] && allowedTo('poll_vote'))) && empty($pollinfo['voting_locked']) && allowedTo('poll_vote') && !$context['poll']['has_voted'];
  568. // You're allowed to view the results if:
  569. // 1. you're just a super-nice-guy, or
  570. // 2. anyone can see them (hide_results == 0), or
  571. // 3. you can see them after you voted (hide_results == 1), or
  572. // 4. you've waited long enough for the poll to expire. (whether hide_results is 1 or 2.)
  573. $context['allow_poll_view'] = allowedTo('moderate_board') || $pollinfo['hide_results'] == 0 || ($pollinfo['hide_results'] == 1 && $context['poll']['has_voted']) || $context['poll']['is_expired'];
  574. $context['poll']['show_results'] = $context['allow_poll_view'] && (isset($_REQUEST['viewresults']) || isset($_REQUEST['viewResults']));
  575. // You're allowed to change your vote if:
  576. // 1. the poll did not expire, and
  577. // 2. you're not a guest... and
  578. // 3. the poll is not locked, and
  579. // 4. you have the proper permissions, and
  580. // 5. you have already voted, and
  581. // 6. the poll creator has said you can!
  582. $context['allow_change_vote'] = !$context['poll']['is_expired'] && !$user_info['is_guest'] && empty($pollinfo['voting_locked']) && allowedTo('poll_vote') && $context['poll']['has_voted'] && $context['poll']['change_vote'];
  583. // You're allowed to return to voting options if:
  584. // 1. you are (still) allowed to vote.
  585. // 2. you are currently seeing the results.
  586. $context['allow_return_vote'] = $context['allow_vote'] && $context['poll']['show_results'];
  587. // Calculate the percentages and bar lengths...
  588. $divisor = $realtotal == 0 ? 1 : $realtotal;
  589. // Determine if a decimal point is needed in order for the options to add to 100%.
  590. $precision = $realtotal == 100 ? 0 : 1;
  591. // Now look through each option, and...
  592. foreach ($pollOptions as $i => $option)
  593. {
  594. // First calculate the percentage, and then the width of the bar...
  595. $bar = round(($option['votes'] * 100) / $divisor, $precision);
  596. $barWide = $bar == 0 ? 1 : floor(($bar * 8) / 3);
  597. // Now add it to the poll's contextual theme data.
  598. $context['poll']['options'][$i] = array(
  599. 'id' => 'options-' . $i,
  600. 'percent' => $bar,
  601. 'votes' => $option['votes'],
  602. 'voted_this' => $option['voted_this'] != -1,
  603. 'bar' => '<span style="white-space: nowrap;"><img src="' . $settings['images_url'] . '/poll_' . ($context['right_to_left'] ? 'right' : 'left') . '.png" alt="" /><img src="' . $settings['images_url'] . '/poll_middle.png" width="' . $barWide . '" height="12" alt="-" /><img src="' . $settings['images_url'] . '/poll_' . ($context['right_to_left'] ? 'left' : 'right') . '.png" alt="" /></span>',
  604. // Note: IE < 8 requires us to set a width on the container, too.
  605. 'bar_ndt' => $bar > 0 ? '<div class="bar" style="width: ' . ($bar * 3.5 + 4) . 'px;"><div style="width: ' . $bar * 3.5 . 'px;"></div></div>' : '',
  606. 'bar_width' => $barWide,
  607. 'option' => parse_bbc($option['label']),
  608. 'vote_button' => '<input type="' . ($pollinfo['max_votes'] > 1 ? 'checkbox' : 'radio') . '" name="options[]" id="options-' . $i . '" value="' . $i . '" class="input_' . ($pollinfo['max_votes'] > 1 ? 'check' : 'radio') . '" />'
  609. );
  610. }
  611. // Build the poll moderation button array.
  612. $context['poll_buttons'] = array(
  613. 'vote' => array('test' => 'allow_return_vote', 'text' => 'poll_return_vote', 'image' => 'poll_options.png', 'lang' => true, 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']),
  614. 'results' => array('test' => 'allow_poll_view', 'text' => 'poll_results', 'image' => 'poll_results.png', 'lang' => true, 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'),
  615. 'change_vote' => array('test' => 'allow_change_vote', 'text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'lang' => true, 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']),
  616. 'lock' => array('test' => 'allow_lock_poll', 'text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'lang' => true, 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
  617. 'edit' => array('test' => 'allow_edit_poll', 'text' => 'poll_edit', 'image' => 'poll_edit.png', 'lang' => true, 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']),
  618. 'remove_poll' => array('test' => 'can_remove_poll', 'text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . $txt['poll_remove_warn'] . '\');"', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
  619. );
  620. // Allow mods to add additional buttons here
  621. call_integration_hook('integrate_poll_buttons');
  622. }
  623. // Calculate the fastest way to get the messages!
  624. $ascending = empty($options['view_newest_first']);
  625. $start = $_REQUEST['start'];
  626. $limit = $context['messages_per_page'];
  627. $firstIndex = 0;
  628. if ($start >= $context['total_visible_posts'] / 2 && $context['messages_per_page'] != -1)
  629. {
  630. $ascending = !$ascending;
  631. $limit = $context['total_visible_posts'] <= $start + $limit ? $context['total_visible_posts'] - $start : $limit;
  632. $start = $context['total_visible_posts'] <= $start + $limit ? 0 : $context['total_visible_posts'] - $start - $limit;
  633. $firstIndex = $limit - 1;
  634. }
  635. // Get each post and poster in this topic.
  636. $request = $smcFunc['db_query']('display_get_post_poster', '
  637. SELECT id_msg, id_member, approved
  638. FROM {db_prefix}messages
  639. WHERE id_topic = {int:current_topic}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : (!empty($modSettings['db_mysql_group_by_fix']) ? '' : '
  640. GROUP BY id_msg') . '
  641. HAVING (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . '
  642. ORDER BY id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '
  643. LIMIT ' . $start . ', ' . $limit),
  644. array(
  645. 'current_member' => $user_info['id'],
  646. 'current_topic' => $topic,
  647. 'is_approved' => 1,
  648. 'blank_id_member' => 0,
  649. )
  650. );
  651. $messages = array();
  652. $all_posters = array();
  653. while ($row = $smcFunc['db_fetch_assoc']($request))
  654. {
  655. if (!empty($row['id_member']))
  656. $all_posters[$row['id_msg']] = $row['id_member'];
  657. $messages[] = $row['id_msg'];
  658. }
  659. $smcFunc['db_free_result']($request);
  660. $posters = array_unique($all_posters);
  661. call_integration_hook('integrate_display_message_list', array($messages, $posters));
  662. // Guests can't mark topics read or for notifications, just can't sorry.
  663. if (!$user_info['is_guest'] && !empty($messages))
  664. {
  665. $mark_at_msg = max($messages);
  666. if ($mark_at_msg >= $topicinfo['id_last_msg'])
  667. $mark_at_msg = $modSettings['maxMsgID'];
  668. if ($mark_at_msg >= $topicinfo['new_from'])
  669. markTopicsRead(array($user_info['id'], $topic, $mark_at_msg, $topicinfo['disregarded']), $topicinfo['new_from'] !== 0);
  670. updateReadNotificationsFor($topic, $board);
  671. // Have we recently cached the number of new topics in this board, and it's still a lot?
  672. if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
  673. $_SESSION['topicseen_cache'][$board]--;
  674. // Mark board as seen if this is the only new topic.
  675. elseif (isset($_REQUEST['topicseen']))
  676. {
  677. // Use the mark read tables... and the last visit to figure out if this should be read or not.
  678. $numNewTopics = getUnreadCountSince($board, empty($_SESSION['id_msg_last_visit']) ? 0 : $_SESSION['id_msg_last_visit']);
  679. // If there're no real new topics in this board, mark the board as seen.
  680. if (empty($numNewTopics))
  681. $_REQUEST['boardseen'] = true;
  682. else
  683. $_SESSION['topicseen_cache'][$board] = $numNewTopics;
  684. }
  685. // Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
  686. elseif (isset($_SESSION['topicseen_cache'][$board]))
  687. $_SESSION['topicseen_cache'][$board]--;
  688. // Mark board as seen if we came using last post link from BoardIndex. (or other places...)
  689. if (isset($_REQUEST['boardseen']))
  690. {
  691. $smcFunc['db_insert']('replace',
  692. '{db_prefix}log_boards',
  693. array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'),
  694. array($modSettings['maxMsgID'], $user_info['id'], $board),
  695. array('id_member', 'id_board')
  696. );
  697. }
  698. }
  699. $attachments = array();
  700. // If there _are_ messages here... (probably an error otherwise :!)
  701. if (!empty($messages))
  702. {
  703. require_once(SUBSDIR . '/Attachments.subs.php');
  704. // Fetch attachments.
  705. $includeUnapproved = !$modSettings['postmod_active'] || allowedTo('approve_posts');
  706. if (!empty($modSettings['attachmentEnable']) && allowedTo('view_attachments'))
  707. $attachments = getAttachments($messages, $includeUnapproved, 'filter_accessible_attachment');
  708. $msg_parameters = array(
  709. 'message_list' => $messages,
  710. 'new_from' => $topicinfo['new_from'],
  711. );
  712. $msg_selects = array();
  713. $msg_tables = array();
  714. call_integration_hook('integrate_query_message', array($msg_selects, $msg_tables, $msg_parameters));
  715. // What? It's not like it *couldn't* be only guests in this topic...
  716. if (!empty($posters))
  717. loadMemberData($posters);
  718. $messages_request = $smcFunc['db_query']('', '
  719. SELECT
  720. id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, body,
  721. smileys_enabled, poster_name, poster_email, approved,
  722. id_msg_modified < {int:new_from} AS is_read
  723. ' . (!empty($msg_selects) ? implode(',', $msg_selects) : '') . '
  724. FROM {db_prefix}messages
  725. ' . (!empty($msg_tables) ? implode("\n\t", $msg_tables) : '') . '
  726. WHERE id_msg IN ({array_int:message_list})
  727. ORDER BY id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),
  728. $msg_parameters
  729. );
  730. // Go to the last message if the given time is beyond the time of the last message.
  731. if (isset($context['start_from']) && $context['start_from'] >= $topicinfo['num_replies'])
  732. $context['start_from'] = $topicinfo['num_replies'];
  733. // Since the anchor information is needed on the top of the page we load these variables beforehand.
  734. $context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
  735. if (empty($options['view_newest_first']))
  736. $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
  737. else
  738. $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $topicinfo['num_replies'] - $context['start_from'];
  739. }
  740. else
  741. {
  742. $messages_request = false;
  743. $context['first_message'] = 0;
  744. $context['first_new_message'] = false;
  745. }
  746. $context['jump_to'] = array(
  747. 'label' => addslashes(un_htmlspecialchars($txt['jump_to'])),
  748. 'board_name' => htmlspecialchars(strtr(strip_tags($board_info['name']), array('&amp;' => '&'))),
  749. 'child_level' => $board_info['child_level'],
  750. );
  751. // Set the callback. (do you REALIZE how much memory all the messages would take?!?)
  752. // This will be called from the template.
  753. $context['get_message'] = 'prepareDisplayContext';
  754. // Now set all the wonderful, wonderful permissions... like moderation ones...
  755. $common_permissions = array(
  756. 'can_approve' => 'approve_posts',
  757. 'can_ban' => 'manage_bans',
  758. 'can_sticky' => 'make_sticky',
  759. 'can_merge' => 'merge_any',
  760. 'can_split' => 'split_any',
  761. 'calendar_post' => 'calendar_post',
  762. 'can_mark_notify' => 'mark_any_notify',
  763. 'can_send_topic' => 'send_topic',
  764. 'can_send_pm' => 'pm_send',
  765. 'can_send_email' => 'send_email_to_members',
  766. 'can_report_moderator' => 'report_any',
  767. 'can_moderate_forum' => 'moderate_forum',
  768. 'can_issue_warning' => 'issue_warning',
  769. 'can_restore_topic' => 'move_any',
  770. 'can_restore_msg' => 'move_any',
  771. );
  772. foreach ($common_permissions as $contextual => $perm)
  773. $context[$contextual] = allowedTo($perm);
  774. // Permissions with _any/_own versions. $context[YYY] => ZZZ_any/_own.
  775. $anyown_permissions = array(
  776. 'can_move' => 'move',
  777. 'can_lock' => 'lock',
  778. 'can_delete' => 'remove',
  779. 'can_add_poll' => 'poll_add',
  780. 'can_remove_poll' => 'poll_remove',
  781. 'can_reply' => 'post_reply',
  782. 'can_reply_unapproved' => 'post_unapproved_replies',
  783. );
  784. foreach ($anyown_permissions as $contextual => $perm)
  785. $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
  786. // Cleanup all the permissions with extra stuff...
  787. $context['can_mark_notify'] &= !$context['user']['is_guest'];
  788. $context['can_sticky'] &= !empty($modSettings['enableStickyTopics']);
  789. $context['calendar_post'] &= !empty($modSettings['cal_enabled']);
  790. $context['can_add_poll'] &= $modSettings['pollMode'] == '1' && $topicinfo['id_poll'] <= 0;
  791. $context['can_remove_poll'] &= $modSettings['pollMode'] == '1' && $topicinfo['id_poll'] > 0;
  792. $context['can_reply'] &= empty($topicinfo['locked']) || allowedTo('moderate_board');
  793. $context['can_reply_unapproved'] &= $modSettings['postmod_active'] && (empty($topicinfo['locked']) || allowedTo('moderate_board'));
  794. $context['can_issue_warning'] &= in_array('w', $context['admin_features']) && $modSettings['warning_settings'][0] == 1;
  795. // Handle approval flags...
  796. $context['can_reply_approved'] = $context['can_reply'];
  797. $context['can_reply'] |= $context['can_reply_unapproved'];
  798. $context['can_quote'] = $context['can_reply'] && (empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])));
  799. $context['can_mark_unread'] = !$user_info['is_guest'] && $settings['show_mark_read'];
  800. $context['can_disregard'] = !$user_info['is_guest'] && $modSettings['enable_disregard'];
  801. $context['can_send_topic'] = (!$modSettings['postmod_active'] || $topicinfo['approved']) && allowedTo('send_topic');
  802. $context['can_print'] = empty($modSettings['disable_print_topic']);
  803. // Start this off for quick moderation - it will be or'd for each post.
  804. $context['can_remove_post'] = allowedTo('delete_any') || (allowedTo('delete_replies') && $context['user']['started']);
  805. // Can restore topic? That's if the topic is in the recycle board and has a previous restore state.
  806. $context['can_restore_topic'] &= !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board && !empty($topicinfo['id_previous_board']);
  807. $context['can_restore_msg'] &= !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board && !empty($topicinfo['id_previous_topic']);
  808. // Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
  809. $context['drafts_save'] = !empty($modSettings['drafts_enabled']) && !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
  810. $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']) && allowedTo('post_autosave_draft');
  811. if (!empty($context['drafts_save']))
  812. loadLanguage('Drafts');
  813. if (!empty($context['drafts_autosave']))
  814. loadJavascriptFile('drafts.js');
  815. // Load up the Quick ModifyTopic and Quick Reply scripts
  816. loadJavascriptFile('topic.js');
  817. // Load up the "double post" sequencing magic.
  818. if (!empty($options['display_quick_reply']))
  819. {
  820. checkSubmitOnce('register');
  821. $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : '';
  822. $context['email'] = isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : '';
  823. if (!empty($options['use_editor_quick_reply']) && $context['can_reply'])
  824. {
  825. // Needed for the editor and message icons.
  826. require_once(SUBSDIR . '/Editor.subs.php');
  827. // Now create the editor.
  828. $editorOptions = array(
  829. 'id' => 'message',
  830. 'value' => '',
  831. 'labels' => array(
  832. 'post_button' => $txt['post'],
  833. ),
  834. // add height and width for the editor
  835. 'height' => '250px',
  836. 'width' => '100%',
  837. // We do XML preview here.
  838. 'preview_type' => 0,
  839. );
  840. create_control_richedit($editorOptions);
  841. // Store the ID.
  842. $context['post_box_name'] = $editorOptions['id'];
  843. $context['attached'] = '';
  844. $context['make_poll'] = isset($_REQUEST['poll']);
  845. // Message icons - customized icons are off?
  846. $context['icons'] = getMessageIcons($board);
  847. if (!empty($context['icons']))
  848. $context['icons'][count($context['icons']) - 1]['is_last'] = true;
  849. }
  850. }
  851. // Build the normal button array.
  852. $context['normal_buttons'] = array(
  853. 'reply' => array('test' => 'can_reply', 'text' => 'reply', 'image' => 'reply.png', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true),
  854. 'add_poll' => array('test' => 'can_add_poll', 'text' => 'add_poll', 'image' => 'add_poll.png', 'lang' => true, 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']),
  855. 'notify' => array('test' => 'can_mark_notify', 'text' => $context['is_marked_notify'] ? 'unnotify' : 'notify', 'image' => ($context['is_marked_notify'] ? 'un' : '') . 'notify.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_topic'] : $txt['notification_enable_topic']) . '\');"', 'url' => $scripturl . '?action=notify;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
  856. 'mark_unread' => array('test' => 'can_mark_unread', 'text' => 'mark_unread', 'image' => 'markunread.png', 'lang' => true, 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
  857. 'disregard' => array('test' => 'can_disregard', 'text' => ($context['topic_disregarded'] ? 'un' : '') . 'disregard', 'image' => ($context['topic_disregarded'] ? 'un' : '') . 'disregard.png', 'lang' => true, 'url' => $scripturl . '?action=disregardtopic;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['topic_disregarded'] ? 'off' : 'on') . ';' . $context['session_var'] . '=' . $context['session_id']),
  858. 'send' => array('test' => 'can_send_topic', 'text' => 'send_topic', 'image' => 'sendtopic.png', 'lang' => true, 'url' => $scripturl . '?action=emailuser;sa=sendtopic;topic=' . $context['current_topic'] . '.0'),
  859. 'print' => array('test' => 'can_print', 'text' => 'print', 'image' => 'print.png', 'lang' => true, 'custom' => 'rel="new_win nofollow"', 'url' => $scripturl . '?action=topic;sa=printpage;topic=' . $context['current_topic'] . '.0'),
  860. );
  861. // Build the mod button array
  862. $context['mod_buttons'] = array(
  863. 'move' => array('test' => 'can_move', 'text' => 'move_topic', 'image' => 'admin_move.png', 'lang' => true, 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'),
  864. 'delete' => array('test' => 'can_delete', 'text' => 'remove_topic', 'image' => 'admin_rem.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . $txt['are_sure_remove_topic'] . '\');"', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']),
  865. 'lock' => array('test' => 'can_lock', 'text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'lang' => true, 'url' => $scripturl . '?action=topic;sa=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
  866. 'sticky' => array('test' => 'can_sticky', 'text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'lang' => true, 'url' => $scripturl . '?action=topic;sa=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
  867. 'merge' => array('test' => 'can_merge', 'text' => 'merge', 'image' => 'merge.png', 'lang' => true, 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']),
  868. 'calendar' => array('test' => 'calendar_post', 'text' => 'calendar_link', 'image' => 'linktocal.png', 'lang' => true, 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'),
  869. );
  870. // Restore topic. eh? No monkey business.
  871. if ($context['can_restore_topic'])
  872. $context['mod_buttons'][] = array('text' => 'restore_topic', 'image' => '', 'lang' => true, 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
  873. // Allow adding new mod buttons easily.
  874. // Note: $context['normal_buttons'] and $context['mod_buttons'] are here for backward compatibility with 2.0, but are deprecated and should not be used
  875. call_integration_hook('integrate_display_buttons', array($context['normal_buttons']));
  876. // Note: integrate_mod_buttons is no longer necessary and is now deprecated, it is kept for backward compatibility with 2.0
  877. call_integration_hook('integrate_mod_buttons', array($context['mod_buttons']));
  878. }
  879. /**
  880. * Callback for the message display.
  881. * It actually gets and prepares the message context.
  882. * This function will start over from the beginning if reset i…

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