| Conditions | 207 |
| Paths | > 20000 |
| Total Lines | 735 |
| Code Lines | 437 |
| Lines | 146 |
| Ratio | 19.86 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 23 | function MessageIndex() |
||
| 24 | { |
||
| 25 | global $txt, $scripturl, $board, $modSettings, $context; |
||
| 26 | global $options, $settings, $board_info, $user_info, $smcFunc, $sourcedir; |
||
| 27 | |||
| 28 | // If this is a redirection board head off. |
||
| 29 | if ($board_info['redirect']) |
||
| 30 | { |
||
| 31 | $smcFunc['db_query']('', ' |
||
| 32 | UPDATE {db_prefix}boards |
||
| 33 | SET num_posts = num_posts + 1 |
||
| 34 | WHERE id_board = {int:current_board}', |
||
| 35 | array( |
||
| 36 | 'current_board' => $board, |
||
| 37 | ) |
||
| 38 | ); |
||
| 39 | |||
| 40 | redirectexit($board_info['redirect']); |
||
| 41 | } |
||
| 42 | |||
| 43 | loadTemplate('MessageIndex'); |
||
| 44 | |||
| 45 | View Code Duplication | if (!$user_info['is_guest']) |
|
|
|
|||
| 46 | { |
||
| 47 | // We can't know they read it if we allow prefetches. |
||
| 48 | // But we'll actually mark it read later after we've done everything else. |
||
| 49 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
||
| 50 | { |
||
| 51 | ob_end_clean(); |
||
| 52 | header('HTTP/1.1 403 Prefetch Forbidden'); |
||
| 53 | die; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | $context['name'] = $board_info['name']; |
||
| 58 | $context['description'] = $board_info['description']; |
||
| 59 | if (!empty($board_info['description'])) |
||
| 60 | $context['meta_description'] = strip_tags($board_info['description']); |
||
| 61 | |||
| 62 | // How many topics do we have in total? |
||
| 63 | $board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics']; |
||
| 64 | |||
| 65 | // View all the topics, or just a few? |
||
| 66 | $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
||
| 67 | $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
||
| 68 | $maxindex = isset($_REQUEST['all']) && !empty($modSettings['enableAllMessages']) ? $board_info['total_topics'] : $context['topics_per_page']; |
||
| 69 | |||
| 70 | // Right, let's only index normal stuff! |
||
| 71 | View Code Duplication | if (count($_GET) > 1) |
|
| 72 | { |
||
| 73 | $session_name = session_name(); |
||
| 74 | foreach ($_GET as $k => $v) |
||
| 75 | { |
||
| 76 | if (!in_array($k, array('board', 'start', $session_name))) |
||
| 77 | $context['robot_no_index'] = true; |
||
| 78 | } |
||
| 79 | } |
||
| 80 | View Code Duplication | if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) |
|
| 81 | $context['robot_no_index'] = true; |
||
| 82 | |||
| 83 | // If we can view unapproved messages and there are some build up a list. |
||
| 84 | if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts'])) |
||
| 85 | { |
||
| 86 | $untopics = $board_info['unapproved_topics'] ? '<a href="' . $scripturl . '?action=moderate;area=postmod;sa=topics;brd=' . $board . '">' . $board_info['unapproved_topics'] . '</a>' : 0; |
||
| 87 | $unposts = $board_info['unapproved_posts'] ? '<a href="' . $scripturl . '?action=moderate;area=postmod;sa=posts;brd=' . $board . '">' . ($board_info['unapproved_posts'] - $board_info['unapproved_topics']) . '</a>' : 0; |
||
| 88 | $context['unapproved_posts_message'] = sprintf($txt['there_are_unapproved_topics'], $untopics, $unposts, $scripturl . '?action=moderate;area=postmod;sa=' . ($board_info['unapproved_topics'] ? 'topics' : 'posts') . ';brd=' . $board); |
||
| 89 | } |
||
| 90 | |||
| 91 | // We only know these. |
||
| 92 | if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) |
||
| 93 | $_REQUEST['sort'] = 'last_post'; |
||
| 94 | |||
| 95 | // Make sure the starting place makes sense and construct the page index. |
||
| 96 | if (isset($_REQUEST['sort'])) |
||
| 97 | $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $maxindex, true); |
||
| 98 | else |
||
| 99 | $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $maxindex, true); |
||
| 100 | $context['start'] = &$_REQUEST['start']; |
||
| 101 | |||
| 102 | // Set a canonical URL for this page. |
||
| 103 | $context['canonical_url'] = $scripturl . '?board=' . $board . '.' . $context['start']; |
||
| 104 | |||
| 105 | $can_show_all = !empty($modSettings['enableAllMessages']) && $maxindex > $modSettings['enableAllMessages']; |
||
| 106 | |||
| 107 | if (!($can_show_all && isset($_REQUEST['all']))) |
||
| 108 | { |
||
| 109 | $context['links'] = array( |
||
| 110 | 'first' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?board=' . $board . '.0' : '', |
||
| 111 | 'prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?board=' . $board . '.' . ($_REQUEST['start'] - $context['topics_per_page']) : '', |
||
| 112 | 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $board_info['total_topics'] ? $scripturl . '?board=' . $board . '.' . ($_REQUEST['start'] + $context['topics_per_page']) : '', |
||
| 113 | 'last' => $_REQUEST['start'] + $context['topics_per_page'] < $board_info['total_topics'] ? $scripturl . '?board=' . $board . '.' . (floor(($board_info['total_topics'] - 1) / $context['topics_per_page']) * $context['topics_per_page']) : '', |
||
| 114 | 'up' => $board_info['parent'] == 0 ? $scripturl . '?' : $scripturl . '?board=' . $board_info['parent'] . '.0' |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | |||
| 118 | $context['page_info'] = array( |
||
| 119 | 'current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1, |
||
| 120 | 'num_pages' => floor(($board_info['total_topics'] - 1) / $context['topics_per_page']) + 1 |
||
| 121 | ); |
||
| 122 | |||
| 123 | if (isset($_REQUEST['all']) && $can_show_all) |
||
| 124 | { |
||
| 125 | $maxindex = $modSettings['enableAllMessages']; |
||
| 126 | $_REQUEST['start'] = 0; |
||
| 127 | } |
||
| 128 | |||
| 129 | // Build a list of the board's moderators. |
||
| 130 | $context['moderators'] = &$board_info['moderators']; |
||
| 131 | $context['moderator_groups'] = &$board_info['moderator_groups']; |
||
| 132 | $context['link_moderators'] = array(); |
||
| 133 | View Code Duplication | if (!empty($board_info['moderators'])) |
|
| 134 | { |
||
| 135 | foreach ($board_info['moderators'] as $mod) |
||
| 136 | $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
||
| 137 | } |
||
| 138 | View Code Duplication | if (!empty($board_info['moderator_groups'])) |
|
| 139 | { |
||
| 140 | // By default just tack the moderator groups onto the end of the members |
||
| 141 | foreach ($board_info['moderator_groups'] as $mod_group) |
||
| 142 | $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
||
| 143 | } |
||
| 144 | |||
| 145 | // Now we tack the info onto the end of the linktree |
||
| 146 | View Code Duplication | if (!empty($context['link_moderators'])) |
|
| 147 | { |
||
| 148 | $context['linktree'][count($context['linktree']) - 1]['extra_after'] = '<span class="board_moderators">(' . (count($context['link_moderators']) == 1 ? $txt['moderator'] : $txt['moderators']) . ': ' . implode(', ', $context['link_moderators']) . ')</span>'; |
||
| 149 | } |
||
| 150 | |||
| 151 | // 'Print' the header and board info. |
||
| 152 | $context['page_title'] = strip_tags($board_info['name']); |
||
| 153 | |||
| 154 | // Set the variables up for the template. |
||
| 155 | $context['can_mark_notify'] = !$user_info['is_guest']; |
||
| 156 | $context['can_post_new'] = allowedTo('post_new') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_topics')); |
||
| 157 | $context['can_post_poll'] = $modSettings['pollMode'] == '1' && allowedTo('poll_post') && $context['can_post_new']; |
||
| 158 | $context['can_moderate_forum'] = allowedTo('moderate_forum'); |
||
| 159 | $context['can_approve_posts'] = allowedTo('approve_posts'); |
||
| 160 | |||
| 161 | require_once($sourcedir . '/Subs-BoardIndex.php'); |
||
| 162 | $boardIndexOptions = array( |
||
| 163 | 'include_categories' => false, |
||
| 164 | 'base_level' => $board_info['child_level'] + 1, |
||
| 165 | 'parent_id' => $board_info['id'], |
||
| 166 | 'set_latest_post' => false, |
||
| 167 | 'countChildPosts' => !empty($modSettings['countChildPosts']), |
||
| 168 | ); |
||
| 169 | $context['boards'] = getBoardIndex($boardIndexOptions); |
||
| 170 | |||
| 171 | // Nosey, nosey - who's viewing this topic? |
||
| 172 | View Code Duplication | if (!empty($settings['display_who_viewing'])) |
|
| 173 | { |
||
| 174 | $context['view_members'] = array(); |
||
| 175 | $context['view_members_list'] = array(); |
||
| 176 | $context['view_num_hidden'] = 0; |
||
| 177 | |||
| 178 | $request = $smcFunc['db_query']('', ' |
||
| 179 | SELECT |
||
| 180 | lo.id_member, lo.log_time, mem.real_name, mem.member_name, mem.show_online, |
||
| 181 | mg.online_color, mg.id_group, mg.group_name |
||
| 182 | FROM {db_prefix}log_online AS lo |
||
| 183 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lo.id_member) |
||
| 184 | LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_member_group} THEN mem.id_post_group ELSE mem.id_group END) |
||
| 185 | WHERE INSTR(lo.url, {string:in_url_string}) > 0 OR lo.session = {string:session}', |
||
| 186 | array( |
||
| 187 | 'reg_member_group' => 0, |
||
| 188 | 'in_url_string' => '"board":' . $board, |
||
| 189 | 'session' => $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(), |
||
| 190 | ) |
||
| 191 | ); |
||
| 192 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 193 | { |
||
| 194 | if (empty($row['id_member'])) |
||
| 195 | continue; |
||
| 196 | |||
| 197 | if (!empty($row['online_color'])) |
||
| 198 | $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
||
| 199 | else |
||
| 200 | $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
||
| 201 | |||
| 202 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
||
| 203 | if ($is_buddy) |
||
| 204 | $link = '<strong>' . $link . '</strong>'; |
||
| 205 | |||
| 206 | if (!empty($row['show_online']) || allowedTo('moderate_forum')) |
||
| 207 | $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
||
| 208 | // @todo why are we filling this array of data that are just counted (twice) and discarded? ??? |
||
| 209 | $context['view_members'][$row['log_time'] . $row['member_name']] = array( |
||
| 210 | 'id' => $row['id_member'], |
||
| 211 | 'username' => $row['member_name'], |
||
| 212 | 'name' => $row['real_name'], |
||
| 213 | 'group' => $row['id_group'], |
||
| 214 | 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], |
||
| 215 | 'link' => $link, |
||
| 216 | 'is_buddy' => $is_buddy, |
||
| 217 | 'hidden' => empty($row['show_online']), |
||
| 218 | ); |
||
| 219 | |||
| 220 | if (empty($row['show_online'])) |
||
| 221 | $context['view_num_hidden']++; |
||
| 222 | } |
||
| 223 | $context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']); |
||
| 224 | $smcFunc['db_free_result']($request); |
||
| 225 | |||
| 226 | // Put them in "last clicked" order. |
||
| 227 | krsort($context['view_members_list']); |
||
| 228 | krsort($context['view_members']); |
||
| 229 | } |
||
| 230 | |||
| 231 | // Default sort methods. |
||
| 232 | $sort_methods = array( |
||
| 233 | 'subject' => 'mf.subject', |
||
| 234 | 'starter' => 'COALESCE(memf.real_name, mf.poster_name)', |
||
| 235 | 'last_poster' => 'COALESCE(meml.real_name, ml.poster_name)', |
||
| 236 | 'replies' => 't.num_replies', |
||
| 237 | 'views' => 't.num_views', |
||
| 238 | 'first_post' => 't.id_topic', |
||
| 239 | 'last_post' => 't.id_last_msg' |
||
| 240 | ); |
||
| 241 | |||
| 242 | // They didn't pick one, default to by last post descending. |
||
| 243 | if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']])) |
||
| 244 | { |
||
| 245 | $context['sort_by'] = 'last_post'; |
||
| 246 | $_REQUEST['sort'] = 'id_last_msg'; |
||
| 247 | $ascending = isset($_REQUEST['asc']); |
||
| 248 | } |
||
| 249 | // Otherwise default to ascending. |
||
| 250 | View Code Duplication | else |
|
| 251 | { |
||
| 252 | $context['sort_by'] = $_REQUEST['sort']; |
||
| 253 | $_REQUEST['sort'] = $sort_methods[$_REQUEST['sort']]; |
||
| 254 | $ascending = !isset($_REQUEST['desc']); |
||
| 255 | } |
||
| 256 | |||
| 257 | $context['sort_direction'] = $ascending ? 'up' : 'down'; |
||
| 258 | $txt['starter'] = $txt['started_by']; |
||
| 259 | |||
| 260 | foreach ($sort_methods as $key => $val) |
||
| 261 | $context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>'; |
||
| 262 | |||
| 263 | // Calculate the fastest way to get the topics. |
||
| 264 | $start = (int) $_REQUEST['start']; |
||
| 265 | if ($start > ($board_info['total_topics'] - 1) / 2) |
||
| 266 | { |
||
| 267 | $ascending = !$ascending; |
||
| 268 | $fake_ascending = true; |
||
| 269 | $maxindex = $board_info['total_topics'] < $start + $maxindex + 1 ? $board_info['total_topics'] - $start : $maxindex; |
||
| 270 | $start = $board_info['total_topics'] < $start + $maxindex + 1 ? 0 : $board_info['total_topics'] - $start - $maxindex; |
||
| 271 | } |
||
| 272 | else |
||
| 273 | $fake_ascending = false; |
||
| 274 | |||
| 275 | // Setup the default topic icons... |
||
| 276 | $context['icon_sources'] = array(); |
||
| 277 | foreach ($context['stable_icons'] as $icon) |
||
| 278 | $context['icon_sources'][$icon] = 'images_url'; |
||
| 279 | |||
| 280 | $topic_ids = array(); |
||
| 281 | $context['topics'] = array(); |
||
| 282 | |||
| 283 | // Sequential pages are often not optimized, so we add an additional query. |
||
| 284 | $pre_query = $start > 0; |
||
| 285 | if ($pre_query && $maxindex > 0) |
||
| 286 | { |
||
| 287 | $request = $smcFunc['db_query']('', ' |
||
| 288 | SELECT t.id_topic |
||
| 289 | FROM {db_prefix}topics AS t' . ($context['sort_by'] === 'last_poster' ? ' |
||
| 290 | INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)' : (in_array($context['sort_by'], array('starter', 'subject')) ? ' |
||
| 291 | INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)' : '')) . ($context['sort_by'] === 'starter' ? ' |
||
| 292 | LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)' : '') . ($context['sort_by'] === 'last_poster' ? ' |
||
| 293 | LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' : '') . ' |
||
| 294 | WHERE t.id_board = {int:current_board}' . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : ' |
||
| 295 | AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . ' |
||
| 296 | ORDER BY is_sticky' . ($fake_ascending ? '' : ' DESC') . ', {raw:sort}' . ($ascending ? '' : ' DESC') . ' |
||
| 297 | LIMIT {int:start}, {int:maxindex}', |
||
| 298 | array( |
||
| 299 | 'current_board' => $board, |
||
| 300 | 'current_member' => $user_info['id'], |
||
| 301 | 'is_approved' => 1, |
||
| 302 | 'id_member_guest' => 0, |
||
| 303 | 'start' => $start, |
||
| 304 | 'maxindex' => $maxindex, |
||
| 305 | 'sort' => $_REQUEST['sort'], |
||
| 306 | ) |
||
| 307 | ); |
||
| 308 | $topic_ids = array(); |
||
| 309 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 310 | $topic_ids[] = $row['id_topic']; |
||
| 311 | } |
||
| 312 | |||
| 313 | // Grab the appropriate topic information... |
||
| 314 | if (!$pre_query || !empty($topic_ids)) |
||
| 315 | { |
||
| 316 | // For search engine effectiveness we'll link guests differently. |
||
| 317 | $context['pageindex_multiplier'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
||
| 318 | |||
| 319 | $message_index_parameters = array( |
||
| 320 | 'current_board' => $board, |
||
| 321 | 'current_member' => $user_info['id'], |
||
| 322 | 'topic_list' => $topic_ids, |
||
| 323 | 'is_approved' => 1, |
||
| 324 | 'find_set_topics' => implode(',', $topic_ids), |
||
| 325 | 'start' => $start, |
||
| 326 | 'maxindex' => $maxindex, |
||
| 327 | ); |
||
| 328 | $message_index_selects = array(); |
||
| 329 | $message_index_tables = array(); |
||
| 330 | call_integration_hook('integrate_message_index', array(&$message_index_selects, &$message_index_tables, &$message_index_parameters)); |
||
| 331 | |||
| 332 | $result = $smcFunc['db_query']('substring', ' |
||
| 333 | SELECT |
||
| 334 | t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board, |
||
| 335 | ' . ($user_info['is_guest'] ? '0' : 'COALESCE(lt.id_msg, COALESCE(lmr.id_msg, -1)) + 1') . ' AS new_from, |
||
| 336 | t.id_last_msg, t.approved, t.unapproved_posts, ml.poster_time AS last_poster_time, t.id_redirect_topic, |
||
| 337 | ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon, |
||
| 338 | ml.poster_name AS last_member_name, ml.id_member AS last_id_member,' . (!empty($settings['avatars_on_indexes']) ? ' meml.avatar, meml.email_address, memf.avatar AS first_member_avatar, memf.email_address AS first_member_mail, COALESCE(af.id_attach, 0) AS first_member_id_attach, af.filename AS first_member_filename, af.attachment_type AS first_member_attach_type, COALESCE(al.id_attach, 0) AS last_member_id_attach, al.filename AS last_member_filename, al.attachment_type AS last_member_attach_type,' : '') . ' |
||
| 339 | COALESCE(meml.real_name, ml.poster_name) AS last_display_name, t.id_first_msg, |
||
| 340 | mf.poster_time AS first_poster_time, mf.subject AS first_subject, mf.icon AS first_icon, |
||
| 341 | mf.poster_name AS first_member_name, mf.id_member AS first_id_member, |
||
| 342 | COALESCE(memf.real_name, mf.poster_name) AS first_display_name, ' . (!empty($modSettings['preview_characters']) ? ' |
||
| 343 | SUBSTRING(ml.body, 1, ' . ($modSettings['preview_characters'] + 256) . ') AS last_body, |
||
| 344 | SUBSTRING(mf.body, 1, ' . ($modSettings['preview_characters'] + 256) . ') AS first_body,' : '') . 'ml.smileys_enabled AS last_smileys, mf.smileys_enabled AS first_smileys |
||
| 345 | ' . (!empty($message_index_selects) ? (', ' . implode(', ', $message_index_selects)) : '') . ' |
||
| 346 | FROM {db_prefix}topics AS t |
||
| 347 | INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) |
||
| 348 | INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg) |
||
| 349 | LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member) |
||
| 350 | LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)' . (!empty($settings['avatars_on_indexes']) ? ' |
||
| 351 | LEFT JOIN {db_prefix}attachments AS af ON (af.id_member = memf.id_member) |
||
| 352 | LEFT JOIN {db_prefix}attachments AS al ON (al.id_member = meml.id_member)' : '') . '' . ($user_info['is_guest'] ? '' : ' |
||
| 353 | LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member}) |
||
| 354 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})') . ' |
||
| 355 | ' . (!empty($message_index_tables) ? implode("\n\t", $message_index_tables) : '') . ' |
||
| 356 | WHERE ' . ($pre_query ? 't.id_topic IN ({array_int:topic_list})' : 't.id_board = {int:current_board}') . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : ' |
||
| 357 | AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . ' |
||
| 358 | ORDER BY ' . ($pre_query ? 'FIND_IN_SET(t.id_topic, {string:find_set_topics})' : 'is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' . $_REQUEST['sort'] . ($ascending ? '' : ' DESC')) . ' |
||
| 359 | LIMIT ' . ($pre_query ? '' : '{int:start}, ') . '{int:maxindex}', |
||
| 360 | $message_index_parameters |
||
| 361 | ); |
||
| 362 | |||
| 363 | // Begin 'printing' the message index for current board. |
||
| 364 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
||
| 365 | { |
||
| 366 | if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
||
| 367 | continue; |
||
| 368 | |||
| 369 | if (!$pre_query) |
||
| 370 | $topic_ids[] = $row['id_topic']; |
||
| 371 | |||
| 372 | // Reference the main color class. |
||
| 373 | $colorClass = 'windowbg'; |
||
| 374 | |||
| 375 | // Does the theme support message previews? |
||
| 376 | if (!empty($modSettings['preview_characters'])) |
||
| 377 | { |
||
| 378 | // Limit them to $modSettings['preview_characters'] characters |
||
| 379 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
||
| 380 | View Code Duplication | if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) |
|
| 381 | $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...'; |
||
| 382 | |||
| 383 | // Censor the subject and message preview. |
||
| 384 | censorText($row['first_subject']); |
||
| 385 | censorText($row['first_body']); |
||
| 386 | |||
| 387 | // Don't censor them twice! |
||
| 388 | if ($row['id_first_msg'] == $row['id_last_msg']) |
||
| 389 | { |
||
| 390 | $row['last_subject'] = $row['first_subject']; |
||
| 391 | $row['last_body'] = $row['first_body']; |
||
| 392 | } |
||
| 393 | else |
||
| 394 | { |
||
| 395 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
||
| 396 | View Code Duplication | if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) |
|
| 397 | $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...'; |
||
| 398 | |||
| 399 | censorText($row['last_subject']); |
||
| 400 | censorText($row['last_body']); |
||
| 401 | } |
||
| 402 | } |
||
| 403 | View Code Duplication | else |
|
| 404 | { |
||
| 405 | $row['first_body'] = ''; |
||
| 406 | $row['last_body'] = ''; |
||
| 407 | censorText($row['first_subject']); |
||
| 408 | |||
| 409 | if ($row['id_first_msg'] == $row['id_last_msg']) |
||
| 410 | $row['last_subject'] = $row['first_subject']; |
||
| 411 | else |
||
| 412 | censorText($row['last_subject']); |
||
| 413 | } |
||
| 414 | |||
| 415 | // Decide how many pages the topic should have. |
||
| 416 | if ($row['num_replies'] + 1 > $context['messages_per_page']) |
||
| 417 | { |
||
| 418 | // We can't pass start by reference. |
||
| 419 | $start = -1; |
||
| 420 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false); |
||
| 421 | |||
| 422 | // If we can use all, show all. |
||
| 423 | View Code Duplication | if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) |
|
| 424 | $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
||
| 425 | } |
||
| 426 | else |
||
| 427 | $pages = ''; |
||
| 428 | |||
| 429 | // We need to check the topic icons exist... |
||
| 430 | if (!empty($modSettings['messageIconChecks_enable'])) |
||
| 431 | { |
||
| 432 | View Code Duplication | if (!isset($context['icon_sources'][$row['first_icon']])) |
|
| 433 | $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
||
| 434 | View Code Duplication | if (!isset($context['icon_sources'][$row['last_icon']])) |
|
| 435 | $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
||
| 436 | } |
||
| 437 | else |
||
| 438 | { |
||
| 439 | View Code Duplication | if (!isset($context['icon_sources'][$row['first_icon']])) |
|
| 440 | $context['icon_sources'][$row['first_icon']] = 'images_url'; |
||
| 441 | View Code Duplication | if (!isset($context['icon_sources'][$row['last_icon']])) |
|
| 442 | $context['icon_sources'][$row['last_icon']] = 'images_url'; |
||
| 443 | } |
||
| 444 | |||
| 445 | if (!empty($board_info['recycle'])) |
||
| 446 | $row['first_icon'] = 'recycled'; |
||
| 447 | |||
| 448 | // Is this topic pending approval, or does it have any posts pending approval? |
||
| 449 | if ($context['can_approve_posts'] && $row['unapproved_posts']) |
||
| 450 | $colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost'); |
||
| 451 | |||
| 452 | // Sticky topics should get a different color, too. |
||
| 453 | if ($row['is_sticky']) |
||
| 454 | $colorClass .= ' sticky'; |
||
| 455 | |||
| 456 | // Locked topics get special treatment as well. |
||
| 457 | if ($row['locked']) |
||
| 458 | $colorClass .= ' locked'; |
||
| 459 | |||
| 460 | // 'Print' the topic info. |
||
| 461 | $context['topics'][$row['id_topic']] = array_merge($row, array( |
||
| 462 | 'id' => $row['id_topic'], |
||
| 463 | 'first_post' => array( |
||
| 464 | 'id' => $row['id_first_msg'], |
||
| 465 | 'member' => array( |
||
| 466 | 'username' => $row['first_member_name'], |
||
| 467 | 'name' => $row['first_display_name'], |
||
| 468 | 'id' => $row['first_id_member'], |
||
| 469 | 'href' => !empty($row['first_id_member']) ? $scripturl . '?action=profile;u=' . $row['first_id_member'] : '', |
||
| 470 | 'link' => !empty($row['first_id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['first_id_member'] . '" title="' . $txt['profile_of'] . ' ' . $row['first_display_name'] . '" class="preview">' . $row['first_display_name'] . '</a>' : $row['first_display_name'] |
||
| 471 | ), |
||
| 472 | 'time' => timeformat($row['first_poster_time']), |
||
| 473 | 'timestamp' => forum_time(true, $row['first_poster_time']), |
||
| 474 | 'subject' => $row['first_subject'], |
||
| 475 | 'preview' => $row['first_body'], |
||
| 476 | 'icon' => $row['first_icon'], |
||
| 477 | 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png', |
||
| 478 | 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0', |
||
| 479 | 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['first_subject'] . '</a>', |
||
| 480 | ), |
||
| 481 | 'last_post' => array( |
||
| 482 | 'id' => $row['id_last_msg'], |
||
| 483 | 'member' => array( |
||
| 484 | 'username' => $row['last_member_name'], |
||
| 485 | 'name' => $row['last_display_name'], |
||
| 486 | 'id' => $row['last_id_member'], |
||
| 487 | 'href' => !empty($row['last_id_member']) ? $scripturl . '?action=profile;u=' . $row['last_id_member'] : '', |
||
| 488 | 'link' => !empty($row['last_id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['last_id_member'] . '">' . $row['last_display_name'] . '</a>' : $row['last_display_name'] |
||
| 489 | ), |
||
| 490 | 'time' => timeformat($row['last_poster_time']), |
||
| 491 | 'timestamp' => forum_time(true, $row['last_poster_time']), |
||
| 492 | 'subject' => $row['last_subject'], |
||
| 493 | 'preview' => $row['last_body'], |
||
| 494 | 'icon' => $row['last_icon'], |
||
| 495 | 'icon_url' => $settings[$context['icon_sources'][$row['last_icon']]] . '/post/' . $row['last_icon'] . '.png', |
||
| 496 | 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($user_info['is_guest'] ? ('.' . (!empty($options['view_newest_first']) ? 0 : ((int) (($row['num_replies']) / $context['pageindex_multiplier'])) * $context['pageindex_multiplier']) . '#msg' . $row['id_last_msg']) : (($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new')), |
||
| 497 | 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($user_info['is_guest'] ? ('.' . (!empty($options['view_newest_first']) ? 0 : ((int) (($row['num_replies']) / $context['pageindex_multiplier'])) * $context['pageindex_multiplier']) . '#msg' . $row['id_last_msg']) : (($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new')) . '" ' . ($row['num_replies'] == 0 ? '' : 'rel="nofollow"') . '>' . $row['last_subject'] . '</a>' |
||
| 498 | ), |
||
| 499 | 'is_sticky' => !empty($row['is_sticky']), |
||
| 500 | 'is_locked' => !empty($row['locked']), |
||
| 501 | 'is_redirect' => !empty($row['id_redirect_topic']), |
||
| 502 | 'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0, |
||
| 503 | 'is_posted_in' => false, |
||
| 504 | 'is_watched' => false, |
||
| 505 | 'icon' => $row['first_icon'], |
||
| 506 | 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png', |
||
| 507 | 'subject' => $row['first_subject'], |
||
| 508 | 'new' => $row['new_from'] <= $row['id_msg_modified'], |
||
| 509 | 'new_from' => $row['new_from'], |
||
| 510 | 'newtime' => $row['new_from'], |
||
| 511 | 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new', |
||
| 512 | 'pages' => $pages, |
||
| 513 | 'replies' => comma_format($row['num_replies']), |
||
| 514 | 'views' => comma_format($row['num_views']), |
||
| 515 | 'approved' => $row['approved'], |
||
| 516 | 'unapproved_posts' => $row['unapproved_posts'], |
||
| 517 | 'css_class' => $colorClass, |
||
| 518 | )); |
||
| 519 | if (!empty($settings['avatars_on_indexes'])) |
||
| 520 | { |
||
| 521 | // Last post member avatar |
||
| 522 | $context['topics'][$row['id_topic']]['last_post']['member']['avatar'] = set_avatar_data(array( |
||
| 523 | 'avatar' => $row['avatar'], |
||
| 524 | 'email' => $row['email_address'], |
||
| 525 | 'filename' => !empty($row['last_member_filename']) ? $row['last_member_filename'] : '', |
||
| 526 | )); |
||
| 527 | |||
| 528 | // First post member avatar |
||
| 529 | $context['topics'][$row['id_topic']]['first_post']['member']['avatar'] = set_avatar_data(array( |
||
| 530 | 'avatar' => $row['first_member_avatar'], |
||
| 531 | 'email' => $row['first_member_mail'], |
||
| 532 | 'filename' => !empty($row['first_member_filename']) ? $row['first_member_filename'] : '', |
||
| 533 | )); |
||
| 534 | } |
||
| 535 | } |
||
| 536 | $smcFunc['db_free_result']($result); |
||
| 537 | |||
| 538 | // Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...) |
||
| 539 | if ($fake_ascending) |
||
| 540 | $context['topics'] = array_reverse($context['topics'], true); |
||
| 541 | |||
| 542 | if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'] && !empty($topic_ids)) |
||
| 543 | { |
||
| 544 | $result = $smcFunc['db_query']('', ' |
||
| 545 | SELECT id_topic |
||
| 546 | FROM {db_prefix}messages |
||
| 547 | WHERE id_topic IN ({array_int:topic_list}) |
||
| 548 | AND id_member = {int:current_member} |
||
| 549 | GROUP BY id_topic |
||
| 550 | LIMIT {int:limit}', |
||
| 551 | array( |
||
| 552 | 'current_member' => $user_info['id'], |
||
| 553 | 'topic_list' => $topic_ids, |
||
| 554 | 'limit' => count($topic_ids), |
||
| 555 | ) |
||
| 556 | ); |
||
| 557 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
||
| 558 | $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
||
| 559 | $smcFunc['db_free_result']($result); |
||
| 560 | } |
||
| 561 | } |
||
| 562 | |||
| 563 | $context['jump_to'] = array( |
||
| 564 | 'label' => addslashes(un_htmlspecialchars($txt['jump_to'])), |
||
| 565 | 'board_name' => $smcFunc['htmlspecialchars'](strtr(strip_tags($board_info['name']), array('&' => '&'))), |
||
| 566 | 'child_level' => $board_info['child_level'], |
||
| 567 | ); |
||
| 568 | |||
| 569 | // Is Quick Moderation active/needed? |
||
| 570 | if (!empty($options['display_quick_mod']) && !empty($context['topics'])) |
||
| 571 | { |
||
| 572 | $context['can_markread'] = $context['user']['is_logged']; |
||
| 573 | $context['can_lock'] = allowedTo('lock_any'); |
||
| 574 | $context['can_sticky'] = allowedTo('make_sticky'); |
||
| 575 | $context['can_move'] = allowedTo('move_any'); |
||
| 576 | $context['can_remove'] = allowedTo('remove_any'); |
||
| 577 | $context['can_merge'] = allowedTo('merge_any'); |
||
| 578 | // Ignore approving own topics as it's unlikely to come up... |
||
| 579 | $context['can_approve'] = $modSettings['postmod_active'] && allowedTo('approve_posts') && !empty($board_info['unapproved_topics']); |
||
| 580 | // Can we restore topics? |
||
| 581 | $context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']); |
||
| 582 | |||
| 583 | if ($user_info['is_admin'] || $modSettings['topic_move_any']) |
||
| 584 | $context['can_move_any'] = true; |
||
| 585 | else |
||
| 586 | { |
||
| 587 | // We'll use this in a minute |
||
| 588 | $boards_allowed = boardsAllowedTo('post_new'); |
||
| 589 | |||
| 590 | // How many boards can you do this on besides this one? |
||
| 591 | $context['can_move_any'] = count($boards_allowed) > 1; |
||
| 592 | } |
||
| 593 | |||
| 594 | // Set permissions for all the topics. |
||
| 595 | foreach ($context['topics'] as $t => $topic) |
||
| 596 | { |
||
| 597 | $started = $topic['first_post']['member']['id'] == $user_info['id']; |
||
| 598 | $context['topics'][$t]['quick_mod'] = array( |
||
| 599 | 'lock' => allowedTo('lock_any') || ($started && allowedTo('lock_own')), |
||
| 600 | 'sticky' => allowedTo('make_sticky'), |
||
| 601 | 'move' => (allowedTo('move_any') || ($started && allowedTo('move_own')) && $context['can_move_any']), |
||
| 602 | 'modify' => allowedTo('modify_any') || ($started && allowedTo('modify_own')), |
||
| 603 | 'remove' => allowedTo('remove_any') || ($started && allowedTo('remove_own')), |
||
| 604 | 'approve' => $context['can_approve'] && $topic['unapproved_posts'] |
||
| 605 | ); |
||
| 606 | $context['can_lock'] |= ($started && allowedTo('lock_own')); |
||
| 607 | $context['can_move'] |= ($started && allowedTo('move_own') && $context['can_move_any']); |
||
| 608 | $context['can_remove'] |= ($started && allowedTo('remove_own')); |
||
| 609 | } |
||
| 610 | |||
| 611 | // Can we use quick moderation checkboxes? |
||
| 612 | if ($options['display_quick_mod'] == 1) |
||
| 613 | $context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore']; |
||
| 614 | // Or the icons? |
||
| 615 | else |
||
| 616 | $context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move']; |
||
| 617 | } |
||
| 618 | |||
| 619 | if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) |
||
| 620 | { |
||
| 621 | $context['qmod_actions'] = array('approve', 'remove', 'lock', 'sticky', 'move', 'merge', 'restore', 'markread'); |
||
| 622 | call_integration_hook('integrate_quick_mod_actions'); |
||
| 623 | } |
||
| 624 | |||
| 625 | // Mark current and parent boards as seen. |
||
| 626 | if (!$user_info['is_guest']) |
||
| 627 | { |
||
| 628 | $smcFunc['db_insert']('replace', |
||
| 629 | '{db_prefix}log_boards', |
||
| 630 | array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'), |
||
| 631 | array($modSettings['maxMsgID'], $user_info['id'], $board), |
||
| 632 | array('id_member', 'id_board') |
||
| 633 | ); |
||
| 634 | |||
| 635 | if (!empty($board_info['parent_boards'])) |
||
| 636 | { |
||
| 637 | $smcFunc['db_query']('', ' |
||
| 638 | UPDATE {db_prefix}log_boards |
||
| 639 | SET id_msg = {int:id_msg} |
||
| 640 | WHERE id_member = {int:current_member} |
||
| 641 | AND id_board IN ({array_int:board_list})', |
||
| 642 | array( |
||
| 643 | 'current_member' => $user_info['id'], |
||
| 644 | 'board_list' => array_keys($board_info['parent_boards']), |
||
| 645 | 'id_msg' => $modSettings['maxMsgID'], |
||
| 646 | ) |
||
| 647 | ); |
||
| 648 | |||
| 649 | // We've seen all these boards now! |
||
| 650 | foreach ($board_info['parent_boards'] as $k => $dummy) |
||
| 651 | if (isset($_SESSION['topicseen_cache'][$k])) |
||
| 652 | unset($_SESSION['topicseen_cache'][$k]); |
||
| 653 | } |
||
| 654 | |||
| 655 | if (isset($_SESSION['topicseen_cache'][$board])) |
||
| 656 | unset($_SESSION['topicseen_cache'][$board]); |
||
| 657 | |||
| 658 | $request = $smcFunc['db_query']('', ' |
||
| 659 | SELECT id_topic, id_board, sent |
||
| 660 | FROM {db_prefix}log_notify |
||
| 661 | WHERE id_member = {int:current_member} |
||
| 662 | AND (' . (!empty($context['topics']) ? 'id_topic IN ({array_int:topics}) OR ' : '') . 'id_board = {int:current_board})', |
||
| 663 | array( |
||
| 664 | 'current_board' => $board, |
||
| 665 | 'topics' => !empty($context['topics']) ? array_keys($context['topics']) : array(), |
||
| 666 | 'current_member' => $user_info['id'], |
||
| 667 | ) |
||
| 668 | ); |
||
| 669 | $context['is_marked_notify'] = false; // this is for the *board* only |
||
| 670 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 671 | { |
||
| 672 | if (!empty($row['id_board'])) |
||
| 673 | { |
||
| 674 | $context['is_marked_notify'] = true; |
||
| 675 | $board_sent = $row['sent']; |
||
| 676 | } |
||
| 677 | if (!empty($row['id_topic'])) |
||
| 678 | $context['topics'][$row['id_topic']]['is_watched'] = true; |
||
| 679 | } |
||
| 680 | $smcFunc['db_free_result']($request); |
||
| 681 | |||
| 682 | View Code Duplication | if ($context['is_marked_notify'] && !empty($board_sent)) |
|
| 683 | { |
||
| 684 | $smcFunc['db_query']('', ' |
||
| 685 | UPDATE {db_prefix}log_notify |
||
| 686 | SET sent = {int:is_sent} |
||
| 687 | WHERE id_member = {int:current_member} |
||
| 688 | AND id_board = {int:current_board}', |
||
| 689 | array( |
||
| 690 | 'current_board' => $board, |
||
| 691 | 'current_member' => $user_info['id'], |
||
| 692 | 'is_sent' => 0, |
||
| 693 | ) |
||
| 694 | ); |
||
| 695 | } |
||
| 696 | |||
| 697 | require_once($sourcedir . '/Subs-Notify.php'); |
||
| 698 | $pref = getNotifyPrefs($user_info['id'], array('board_notify', 'board_notify_' . $board), true); |
||
| 699 | $pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array(); |
||
| 700 | $pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0); |
||
| 701 | $context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1)); |
||
| 702 | } |
||
| 703 | else |
||
| 704 | { |
||
| 705 | $context['is_marked_notify'] = false; |
||
| 706 | $context['board_notification_mode'] = 1; |
||
| 707 | } |
||
| 708 | |||
| 709 | // If there are children, but no topics and no ability to post topics... |
||
| 710 | $context['no_topic_listing'] = !empty($context['boards']) && empty($context['topics']) && !$context['can_post_new']; |
||
| 711 | |||
| 712 | // Show a message in case a recently posted message became unapproved. |
||
| 713 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false; |
||
| 714 | |||
| 715 | // Don't want to show this forever... |
||
| 716 | if ($context['becomesUnapproved']) |
||
| 717 | unset($_SESSION['becomesUnapproved']); |
||
| 718 | |||
| 719 | // Build the message index button array. |
||
| 720 | $context['normal_buttons'] = array(); |
||
| 721 | |||
| 722 | View Code Duplication | if ($context['can_post_new']) |
|
| 723 | $context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true); |
||
| 724 | |||
| 725 | View Code Duplication | if ($context['can_post_poll']) |
|
| 726 | $context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'); |
||
| 727 | |||
| 728 | View Code Duplication | if (!$context['user']['is_logged']) |
|
| 729 | $context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
||
| 730 | |||
| 731 | if ($context['can_mark_notify']) |
||
| 732 | $context['normal_buttons']['notify'] = array( |
||
| 733 | 'lang' => true, |
||
| 734 | 'text' => 'notify_board_' . $context['board_notification_mode'], |
||
| 735 | 'sub_buttons' => array( |
||
| 736 | array( |
||
| 737 | 'text' => 'notify_board_1', |
||
| 738 | 'url' => $scripturl . '?action=notifyboard;board=' . $board . ';mode=1;' . $context['session_var'] . '=' . $context['session_id'], |
||
| 739 | ), |
||
| 740 | array( |
||
| 741 | 'text' => 'notify_board_2', |
||
| 742 | 'url' => $scripturl . '?action=notifyboard;board=' . $board . ';mode=2;' . $context['session_var'] . '=' . $context['session_id'], |
||
| 743 | ), |
||
| 744 | array( |
||
| 745 | 'text' => 'notify_board_3', |
||
| 746 | 'url' => $scripturl . '?action=notifyboard;board=' . $board . ';mode=3;' . $context['session_var'] . '=' . $context['session_id'], |
||
| 747 | ), |
||
| 748 | ), |
||
| 749 | ); |
||
| 750 | |||
| 751 | // Javascript for inline editing. |
||
| 752 | loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic'); |
||
| 753 | |||
| 754 | // Allow adding new buttons easily. |
||
| 755 | // Note: $context['normal_buttons'] is added for backward compatibility with 2.0, but is deprecated and should not be used |
||
| 756 | call_integration_hook('integrate_messageindex_buttons', array(&$context['normal_buttons'])); |
||
| 757 | } |
||
| 758 | |||
| 1327 | ?> |
||
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.