function showPosts($memID) { global $txt, $user_info, $scripturl, $modSettings; global $context, $user_profile, $sourcedir, $smcFunc, $board; // Some initial context. $context['start'] = (int) $_REQUEST['start']; $context['current_member'] = $memID; // Create the tabs for the template. $context[$context['profile_menu_name']]['tab_data'] = array('title' => $txt['showPosts'], 'description' => $txt['showPosts_help'], 'icon' => 'profile_sm.gif', 'tabs' => array('messages' => array(), 'topics' => array(), 'attach' => array())); // Set the page title $context['page_title'] = $txt['showPosts'] . ' - ' . $user_profile[$memID]['real_name']; // Is the load average too high to allow searching just now? if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) { fatal_lang_error('loadavg_show_posts_disabled', false); } // If we're specifically dealing with attachments use that function! if (isset($_GET['sa']) && $_GET['sa'] == 'attach') { return showAttachments($memID); } // Are we just viewing topics? $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false; // If just deleting a message, do it and then redirect back. if (isset($_GET['delete']) && !$context['is_topics']) { checkSession('get'); // We need msg info for logging. $request = $smcFunc['db_query']('', ' SELECT subject, id_member, id_topic, id_board FROM {db_prefix}messages WHERE id_msg = {int:id_msg}', array('id_msg' => (int) $_GET['delete'])); $info = $smcFunc['db_fetch_row']($request); $smcFunc['db_free_result']($request); // Trying to remove a message that doesn't exist. if (empty($info)) { redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); } // We can be lazy, since removeMessage() will check the permissions for us. require_once $sourcedir . '/RemoveTopic.php'; removeMessage((int) $_GET['delete']); // Add it to the mod log. if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3])); } // Back to... where we are now ;). redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); } // Default to 10. if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { $_REQUEST['viewscount'] = '10'; } if ($context['is_topics']) { $request = $smcFunc['db_query']('', ' SELECT COUNT(*) FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : ' INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . ' WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? ' AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' AND t.approved = {int:is_approved}'), array('current_member' => $memID, 'is_approved' => 1, 'board' => $board)); } else { $request = $smcFunc['db_query']('', ' SELECT COUNT(*) FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' AND m.approved = {int:is_approved}'), array('current_member' => $memID, 'is_approved' => 1, 'board' => $board)); } list($msgCount) = $smcFunc['db_fetch_row']($request); $smcFunc['db_free_result']($request); $request = $smcFunc['db_query']('', ' SELECT MIN(id_msg), MAX(id_msg) FROM {db_prefix}messages AS m WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' AND m.approved = {int:is_approved}'), array('current_member' => $memID, 'is_approved' => 1, 'board' => $board)); list($min_msg_member, $max_msg_member) = $smcFunc['db_fetch_row']($request); $smcFunc['db_free_result']($request); $reverse = false; $range_limit = ''; $maxIndex = (int) $modSettings['defaultMaxMessages']; // Make sure the starting place makes sense and construct our friend the page index. $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex); $context['current_page'] = $context['start'] / $maxIndex; // Reverse the query if we're past 50% of the pages for better performance. $start = $context['start']; $reverse = $_REQUEST['start'] > $msgCount / 2; if ($reverse) { $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages']; $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages']; } // Guess the range of messages to be shown. if ($msgCount > 1000) { $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + 0.1 * ($max_msg_member - $min_msg_member)); // Make a bigger margin for topics only. if ($context['is_topics']) { $margin *= 5; $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin); } else { $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); } } // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks. $looped = false; while (true) { if ($context['is_topics']) { $request = $smcFunc['db_query']('', ' SELECT b.id_board, b.name AS bname, c.id_cat, c.name AS cname, t.id_member_started, t.id_first_msg, t.id_last_msg, t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg FROM {db_prefix}topics AS t INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg) WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? ' AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : ' AND ' . $range_limit) . ' AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . ' ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . ' LIMIT ' . $start . ', ' . $maxIndex, array('current_member' => $memID, 'is_approved' => 1, 'board' => $board)); } else { $request = $smcFunc['db_query']('', ' SELECT b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg, t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled, m.subject, m.poster_time, m.approved FROM {db_prefix}messages AS m INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : ' AND ' . $range_limit) . ' AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . ' ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . ' LIMIT ' . $start . ', ' . $maxIndex, array('current_member' => $memID, 'is_approved' => 1, 'board' => $board)); } // Make sure we quit this loop. if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) { break; } $looped = true; $range_limit = ''; } // Start counting at the number of the first message displayed. $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start']; $context['posts'] = array(); $board_ids = array('own' => array(), 'any' => array()); while ($row = $smcFunc['db_fetch_assoc']($request)) { // Censor.... censorText($row['body']); censorText($row['subject']); // Do the code. $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); // And the array... $context['posts'][$counter += $reverse ? -1 : 1] = array('body' => $row['body'], 'counter' => $counter, 'alternate' => $counter % 2, 'category' => array('name' => $row['cname'], 'id' => $row['id_cat']), 'board' => array('name' => $row['bname'], 'id' => $row['id_board']), 'topic' => $row['id_topic'], 'subject' => $row['subject'], 'start' => 'msg' . $row['id_msg'], 'time' => timeformat($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'id' => $row['id_msg'], 'can_reply' => false, 'can_mark_notify' => false, 'can_delete' => false, 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()), 'approved' => $row['approved']); if ($user_info['id'] == $row['id_member_started']) { $board_ids['own'][$row['id_board']][] = $counter; } $board_ids['any'][$row['id_board']][] = $counter; } $smcFunc['db_free_result']($request); // All posts were retrieved in reverse order, get them right again. if ($reverse) { $context['posts'] = array_reverse($context['posts'], true); } // These are all the permissions that are different from board to board.. if ($context['is_topics']) { $permissions = array('own' => array('post_reply_own' => 'can_reply'), 'any' => array('post_reply_any' => 'can_reply', 'mark_any_notify' => 'can_mark_notify')); } else { $permissions = array('own' => array('post_reply_own' => 'can_reply', 'delete_own' => 'can_delete'), 'any' => array('post_reply_any' => 'can_reply', 'mark_any_notify' => 'can_mark_notify', 'delete_any' => 'can_delete')); } // For every permission in the own/any lists... foreach ($permissions as $type => $list) { foreach ($list as $permission => $allowed) { // Get the boards they can do this on... $boards = boardsAllowedTo($permission); // Hmm, they can do it on all boards, can they? if (!empty($boards) && $boards[0] == 0) { $boards = array_keys($board_ids[$type]); } // Now go through each board they can do the permission on. foreach ($boards as $board_id) { // There aren't any posts displayed from this board. if (!isset($board_ids[$type][$board_id])) { continue; } // Set the permission to true ;). foreach ($board_ids[$type][$board_id] as $counter) { $context['posts'][$counter][$allowed] = true; } } } } // Clean up after posts that cannot be deleted and quoted. $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])); foreach ($context['posts'] as $counter => $dummy) { $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible']; $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled; } }
function showPosts($memID) { global $txt, $user_info, $scripturl, $modSettings; global $context, $user_profile, $sourcedir, $board, $memberContext, $options; EoS_Smarty::loadTemplate('profile/profile_base'); $context['need_synhlt'] = true; // Some initial context. $context['start'] = (int) $_REQUEST['start']; $context['current_member'] = $memID; // Create the tabs for the template. $context[$context['profile_menu_name']]['tab_data'] = array('title' => $txt['showPosts'], 'description' => $txt['showPosts_help'], 'tabs' => array('messages' => array(), 'topics' => array(), 'attach' => array())); // Set the page title $context['page_title'] = $txt['showPosts'] . ' - ' . $user_profile[$memID]['real_name']; $context['pageindex_multiplier'] = commonAPI::getMessagesPerPage(); $context['can_approve_posts'] = false; // Is the load average too high to allow searching just now? if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) { fatal_lang_error('loadavg_show_posts_disabled', false); } if (isset($_GET['sa']) && !empty($modSettings['karmaMode']) && ($_GET['sa'] == 'likes' || $_GET['sa'] == 'likesout')) { require_once $sourcedir . '/Ratings.php'; return LikesByUser($memID); } EoS_Smarty::getConfigInstance()->registerHookTemplate('profile_content_area', 'profile/show_content'); $boards_hidden_1 = boardsAllowedTo('see_hidden1'); $boards_hidden_2 = boardsAllowedTo('see_hidden2'); $boards_hidden_3 = boardsAllowedTo('see_hidden3'); // If we're specifically dealing with attachments use that function! if (isset($_GET['sa']) && $_GET['sa'] == 'attach') { return showAttachments($memID); } // Are we just viewing topics? $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false; // If just deleting a message, do it and then redirect back. if (isset($_GET['delete']) && !$context['is_topics']) { checkSession('get'); // We need msg info for logging. $request = smf_db_query(' SELECT subject, id_member, id_topic, id_board FROM {db_prefix}messages WHERE id_msg = {int:id_msg}', array('id_msg' => (int) $_GET['delete'])); $info = mysql_fetch_row($request); mysql_free_result($request); // Trying to remove a message that doesn't exist. if (empty($info)) { redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); } // We can be lazy, since removeMessage() will check the permissions for us. require_once $sourcedir . '/RemoveTopic.php'; removeMessage((int) $_GET['delete']); // Add it to the mod log. if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3])); } // Back to... where we are now ;). redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); } // Default to 10. if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { $_REQUEST['viewscount'] = '10'; } if ($context['is_topics']) { $request = smf_db_query(' SELECT COUNT(*) FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : ' INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . ' WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? ' AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' AND t.approved = {int:is_approved}'), array('current_member' => $memID, 'is_approved' => 1, 'board' => $board)); } else { $request = smf_db_query(' SELECT COUNT(*) FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' AND m.approved = {int:is_approved}'), array('current_member' => $memID, 'is_approved' => 1, 'board' => $board)); } list($msgCount) = mysql_fetch_row($request); mysql_free_result($request); $request = smf_db_query(' SELECT MIN(id_msg), MAX(id_msg) FROM {db_prefix}messages AS m WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' AND m.approved = {int:is_approved}'), array('current_member' => $memID, 'is_approved' => 1, 'board' => $board)); list($min_msg_member, $max_msg_member) = mysql_fetch_row($request); mysql_free_result($request); $reverse = false; $range_limit = ''; $maxIndex = (int) $modSettings['defaultMaxMessages']; // Make sure the starting place makes sense and construct our friend the page index. $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex); $context['current_page'] = $context['start'] / $maxIndex; // Reverse the query if we're past 50% of the pages for better performance. $start = $context['start']; $reverse = $_REQUEST['start'] > $msgCount / 2; if ($reverse && !$context['is_topics']) { $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages']; $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages']; } // Guess the range of messages to be shown. if ($msgCount > 1000) { $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + 0.1 * ($max_msg_member - $min_msg_member)); // Make a bigger margin for topics only. if ($context['is_topics']) { $margin *= 5; $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin); } else { $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); } } // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks. $context['results_counter'] = 0; $topicids = array(); if ($context['is_topics']) { $context['postbit_callback'] = 'template_topicbit'; $prereq = smf_db_query(' SELECT t.id_topic FROM {db_prefix}topics AS t LEFT JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? ' AND t.id_board = {int:board}' : '') . ' AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' AND t.approved = {int:is_approved}') . ' ORDER BY t.id_topic DESC LIMIT ' . $start . ', ' . $modSettings['defaultMaxMessages'], array('current_member' => $memID, 'is_approved' => 1, 'board' => $board)); while ($row = mysql_fetch_row($prereq)) { $topicids[] = $row[0]; } mysql_free_result($prereq); if (count($topicids)) { $request = smf_db_query(' SELECT b.id_board, b.name AS board_name, t.id_member_started, t.id_first_msg, t.id_last_msg, t.id_prefix, t.is_sticky, t.locked, t.num_views, t.num_replies, t.id_poll, t.approved, t.unapproved_posts, m.id_member, m.subject AS first_subject, m.poster_time, m.id_topic, m.id_msg, m.icon, m2.poster_name AS last_member_name, m2.id_member AS last_id_member, m2.poster_time AS last_post_time, IFNULL(meml.real_name, m2.poster_name) AS last_display_name, m2.subject AS last_subject, m2.icon AS last_icon, p.name AS prefix_name FROM {db_prefix}topics AS t LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg) LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = t.id_member_updated) LEFT JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) LEFT JOIN {db_prefix}messages AS m2 ON (m2.id_msg = t.id_last_msg) LEFT JOIN {db_prefix}prefixes AS p ON (p.id_prefix = t.id_prefix) WHERE t.id_topic IN({array_int:topicids}) ORDER BY t.id_topic DESC', array('topicids' => $topicids)); } } else { $context['postbit_callback'] = 'template_postbit_compact'; $request = smf_db_query(' SELECT b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg, t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled, m.id_member, m.icon, m.subject, m.poster_time, m.modified_time, m.approved, mc.body AS cached_body, ' . (!empty($modSettings['karmaMode']) ? 'c1.likes_count, c1.like_status, c1.updated AS like_updated, l.rtype AS liked, ' : '0 AS likes_count, 0 AS like_status, 0 AS like_updated, 0 AS liked, ') . ' m2.id_member AS id_first_member, m2.subject AS first_subject, m2.poster_time AS time_started, IFNULL(mem2.real_name, m2.poster_name) AS first_poster_name FROM {db_prefix}messages AS m INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) INNER JOIN {db_prefix}messages AS m2 ON (m2.id_msg = t.id_first_msg) LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = m2.id_member) LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) ' . (!empty($modSettings['karmaMode']) ? ' LEFT JOIN {db_prefix}likes AS l ON (l.id_msg = m.id_msg AND l.ctype = 1 AND l.id_user = {int:id_user}) LEFT JOIN {db_prefix}like_cache AS c1 ON (c1.id_msg = m.id_msg AND c1.ctype = 1)' : '') . ' LEFT JOIN {db_prefix}messages_cache AS mc on mc.id_msg = m.id_msg AND mc.style = {int:style} AND mc.lang = {int:lang} WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : ' AND ' . $range_limit) . ' AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . ' ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . ' LIMIT ' . $start . ', ' . $maxIndex, array('current_member' => $memID, 'is_approved' => 1, 'board' => $board, 'style' => $user_info['smiley_set_id'], 'lang' => $user_info['language_id'], 'id_user' => $user_info['id'])); } // Start counting at the number of the first message displayed. $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start']; $context['posts'] = array(); $board_ids = array('own' => array(), 'any' => array()); if (!empty($modSettings['karmaMode'])) { require_once $sourcedir . '/lib/Subs-Ratings.php'; $boards_like_see = boardsAllowedTo('like_see'); $boards_like_give = boardsAllowedTo('like_give'); } else { $boards_like_see = array(); $boards_like_give = array(); $context['can_see_like'] = $context['can_give_like'] = false; } $time_now = time(); if ($context['is_topics']) { $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; $context['messages_per_page'] = commonAPI::getMessagesPerPage(); if (count($topicids)) { loadMemberContext($memID, true); while ($row = mysql_fetch_assoc($request)) { $context['results_counter']++; if ($row['num_replies'] + 1 > $context['messages_per_page']) { $pages = ' '; // We can't pass start by reference. $start = -1; $pages .= constructPageIndex(URL::topic($row['id_topic'], $row['first_subject'], '%1$d'), $start, $row['num_replies'] + 1, $context['messages_per_page'], true); // If we can use all, show all. if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) { $pages .= '<a class="navPages" href="' . URL::topic($row['id_topic'], $row['first_subject'], 0) . ';all">' . $txt['show_all'] . '</a>'; } $pages .= ' '; } else { $pages = ''; } $f_post_mem_href = !empty($row['id_member_started']) ? URL::user($row['id_member_started'], $memberContext[$memID]['name']) : ''; $t_href = URL::topic($row['id_topic'], $row['first_subject'], 0); $l_post_mem_href = !empty($row['last_id_member']) ? URL::user($row['last_id_member'], $row['last_display_name']) : ''; $l_post_msg_href = URL::topic($row['id_topic'], $row['last_subject'], $user_info['is_guest'] ? !empty($options['view_newest_first']) ? 0 : (int) ($row['num_replies'] / $context['pageindex_multiplier']) * $context['pageindex_multiplier'] : 0, $user_info['is_guest'] ? true : false, $user_info['is_guest'] ? '' : '.msg' . $row['id_last_msg'], $user_info['is_guest'] ? '#msg' . $row['id_last_msg'] : '#new'); $context['topics'][$row['id_topic']] = array('id' => $row['id_topic'], 'first_post' => array('member' => array('username' => $memberContext[$memID]['username'], 'name' => $memberContext[$memID]['name'], 'id' => $memID, 'href' => $f_post_mem_href, 'link' => !empty($row['first_id_member']) ? '<a onclick="getMcard(' . $row['id_member_started'] . ', $(this));return(false);" href="' . $f_post_mem_href . '" title="' . $txt['profile_of'] . ' ' . $row['first_display_name'] . '">' . $row['first_display_name'] . '</a>' : $memberContext[$memID]['name'], 'avatar' => &$memberContext[$memID]['avatar']['image']), 'icon_url' => getPostIcon($row['icon']), 'time' => timeformat($row['poster_time']), 'href' => $t_href, 'link' => '<a href="' . $t_href . '">' . $row['first_subject'] . '</a>', 'id' => $row['id_first_msg']), 'last_post' => array('id' => $row['id_last_msg'], 'member' => array('username' => $row['last_member_name'], 'name' => $row['last_display_name'], 'id' => $row['last_id_member'], 'href' => $l_post_mem_href, 'link' => !empty($row['last_id_member']) ? '<a onclick="getMcard(' . $row['last_id_member'] . ', $(this));return(false);" href="' . $l_post_mem_href . '">' . $row['last_display_name'] . '</a>' : $row['last_display_name']), 'time' => timeformat($row['last_post_time']), 'timestamp' => forum_time(true, $row['last_post_time']), 'subject' => $row['last_subject'], 'icon' => $row['last_icon'], 'icon_url' => getPostIcon($row['last_icon']), 'href' => $l_post_msg_href, 'link' => '<a href="' . $l_post_msg_href . ($row['num_replies'] == 0 ? '' : ' rel="nofollow"') . '>' . $row['last_subject'] . '</a>'), 'is_posted_in' => false, 'new' => false, 'is_sticky' => $row['is_sticky'], 'is_locked' => $row['locked'], 'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0, 'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'], 'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'], 'views' => $row['num_views'], 'replies' => $row['num_replies'], 'prefix' => $row['prefix_name'] ? '<a href="' . $scripturl . '?board=' . $board . ';prefix=' . $row['id_prefix'] . '" class="prefix">' . (html_entity_decode($row['prefix_name']) . '</a>') : '', 'pages' => $pages, 'approved' => $row['approved'], 'unapproved_posts' => $row['unapproved_posts'], 'is_old' => !empty($modSettings['oldTopicDays']) ? $context['time_now'] - $row['last_post_time'] > $modSettings['oldTopicDays'] * 86400 : false, 'board' => isset($row['id_board']) && !empty($row['id_board']) ? array('name' => $row['board_name'], 'id' => $row['id_board'], 'href' => URL::board($row['id_board'], $row['board_name'])) : array('name' => '', 'id' => 0, 'href' => '')); determineTopicClass($context['topics'][$row['id_topic']]); } mysql_free_result($request); } } else { loadMemberContext($memID); while ($row = mysql_fetch_assoc($request)) { $context['results_counter']++; $check_boards = array(0, $row['id_board']); // 0 is for admin $context['can_see_hidden_level1'] = count(array_intersect($check_boards, $boards_hidden_1)) > 0; $context['can_see_hidden_level2'] = count(array_intersect($check_boards, $boards_hidden_2)) > 0; $context['can_see_hidden_level3'] = count(array_intersect($check_boards, $boards_hidden_3)) > 0; $context['can_see_like'] = count(array_intersect($check_boards, $boards_like_see)) > 0; $context['can_give_like'] = count(array_intersect($check_boards, $boards_like_give)) > 0; // Censor.... censorText($row['body']); censorText($row['subject']); getCachedPost($row); // And the array... $i = $counter += $reverse ? -1 : 1; $thref = URL::topic($row['id_topic'], $row['first_subject'], 0, false, '.msg' . $row['id_msg'], '#' . $row['id_msg']); $topichref = URL::topic($row['id_topic'], $row['first_subject'], 0); $bhref = URL::board($row['id_board'], $row['bname'], 0, false); $fhref = empty($row['id_first_member']) ? '' : URL::user($row['id_first_member'], $row['first_poster_name']); $context['posts'][$i] = array('body' => $row['body'], 'counter' => $counter, 'icon' => $row['icon'], 'icon_url' => getPostIcon($row['icon']), 'category' => array('id' => $row['id_cat'], 'name' => $row['cname'], 'href' => $scripturl . '#c' . $row['id_cat'], 'link' => '<a href="' . $scripturl . '#c' . $row['id_cat'] . '">' . $row['cname'] . '</a>'), 'board' => array('id' => $row['id_board'], 'name' => $row['bname'], 'href' => $bhref, 'link' => '<a href="' . $bhref . '">' . $row['bname'] . '</a>'), 'member' => &$memberContext[$memID], 'href' => $thref, 'link' => '<a href="' . $thref . '" rel="nofollow">' . $row['subject'] . '</a>', 'subject' => $row['subject'], 'time' => timeformat($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'first_poster' => array('id' => $row['id_first_member'], 'name' => $row['first_poster_name'], 'href' => $fhref, 'link' => empty($row['id_first_member']) ? $row['first_poster_name'] : '<a href="' . $fhref . '">' . $row['first_poster_name'] . '</a>', 'time' => timeformat($row['time_started'])), 'topic' => array('id' => $row['id_topic'], 'href' => $topichref, 'link' => '<a href="' . $topichref . '" rel="nofollow">' . $row['first_subject'] . '</a>'), 'permahref' => $scripturl . '?msg=' . $row['id_msg'], 'permalink' => $txt['view_in_thread'], 'id' => $row['id_msg'], 'id_member' => $memID, 'can_reply' => false, 'can_mark_notify' => false, 'can_delete' => false, 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()), 'approved' => $row['approved'], 'likes_count' => $row['likes_count'], 'like_status' => $row['like_status'], 'liked' => $row['liked'], 'like_updated' => $row['like_updated'], 'likers' => '', 'likelink' => ''); if ($context['can_see_like']) { Ratings::addContent($context['posts'][$i], $context['can_give_like'], $time_now); } if ($user_info['id'] == $row['id_member_started']) { $board_ids['own'][$row['id_board']][] = $counter; } $board_ids['any'][$row['id_board']][] = $counter; } mysql_free_result($request); } // All posts were retrieved in reverse order, get them right again. if ($reverse) { $context['posts'] = array_reverse($context['posts'], true); } // These are all the permissions that are different from board to board.. if ($context['is_topics']) { $permissions = array('own' => array('post_reply_own' => 'can_reply'), 'any' => array('post_reply_any' => 'can_reply', 'mark_any_notify' => 'can_mark_notify')); } else { $permissions = array('own' => array('post_reply_own' => 'can_reply', 'delete_own' => 'can_delete'), 'any' => array('post_reply_any' => 'can_reply', 'mark_any_notify' => 'can_mark_notify', 'delete_any' => 'can_delete')); } // For every permission in the own/any lists... foreach ($permissions as $type => $list) { foreach ($list as $permission => $allowed) { // Get the boards they can do this on... $boards = boardsAllowedTo($permission); // Hmm, they can do it on all boards, can they? if (!empty($boards) && $boards[0] == 0) { $boards = array_keys($board_ids[$type]); } // Now go through each board they can do the permission on. foreach ($boards as $board_id) { // There aren't any posts displayed from this board. if (!isset($board_ids[$type][$board_id])) { continue; } // Set the permission to true ;). foreach ($board_ids[$type][$board_id] as $counter) { $context['posts'][$counter][$allowed] = true; } } } } // Clean up after posts that cannot be deleted and quoted. $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])); foreach ($context['posts'] as $counter => $dummy) { $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible']; $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled; } }