Yoshi2889 /
SMF2.1
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * This file currently only contains one function to collect the data needed to |
||
| 5 | * show a list of boards for the board index and the message index. |
||
| 6 | * |
||
| 7 | * Simple Machines Forum (SMF) |
||
| 8 | * |
||
| 9 | * @package SMF |
||
| 10 | * @author Simple Machines http://www.simplemachines.org |
||
| 11 | * @copyright 2017 Simple Machines and individual contributors |
||
| 12 | * @license http://www.simplemachines.org/about/smf/license.php BSD |
||
| 13 | * |
||
| 14 | * @version 2.1 Beta 4 |
||
| 15 | */ |
||
| 16 | |||
| 17 | if (!defined('SMF')) |
||
| 18 | die('No direct access...'); |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Fetches a list of boards and (optional) categories including |
||
| 22 | * statistical information, child boards and moderators. |
||
| 23 | * - Used by both the board index (main data) and the message index (child |
||
| 24 | * boards). |
||
| 25 | * - Depending on the include_categories setting returns an associative |
||
| 26 | * array with categories->boards->child_boards or an associative array |
||
| 27 | * with boards->child_boards. |
||
| 28 | * @param array $boardIndexOptions An array of boardindex options |
||
| 29 | * @return array An array of information for displaying the boardindex |
||
| 30 | */ |
||
| 31 | |||
| 32 | function getBoardIndex($boardIndexOptions) |
||
| 33 | { |
||
| 34 | global $smcFunc, $scripturl, $user_info, $modSettings, $txt; |
||
| 35 | global $settings, $options, $context, $sourcedir; |
||
| 36 | |||
| 37 | require_once($sourcedir . '/Subs-Boards.php'); |
||
| 38 | |||
| 39 | // For performance, track the latest post while going through the boards. |
||
| 40 | if (!empty($boardIndexOptions['set_latest_post'])) |
||
| 41 | $latest_post = array( |
||
| 42 | 'timestamp' => 0, |
||
| 43 | 'ref' => 0, |
||
| 44 | ); |
||
| 45 | |||
| 46 | // Find all boards and categories, as well as related information. This will be sorted by the natural order of boards and categories, which we control. |
||
| 47 | $result_boards = $smcFunc['db_query']('', ' |
||
| 48 | SELECT' . ($boardIndexOptions['include_categories'] ? ' |
||
| 49 | c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . ' |
||
| 50 | b.id_board, b.name AS board_name, b.description, |
||
| 51 | CASE WHEN b.redirect != {string:blank_string} THEN 1 ELSE 0 END AS is_redirect, |
||
| 52 | b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent, |
||
| 53 | COALESCE(m.poster_time, 0) AS poster_time, COALESCE(mem.member_name, m.poster_name) AS poster_name, |
||
| 54 | m.subject, m.id_topic, COALESCE(mem.real_name, m.poster_name) AS real_name, |
||
| 55 | ' . ($user_info['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : ' |
||
| 56 | (CASE WHEN COALESCE(lb.id_msg, 0) >= b.id_msg_updated THEN 1 ELSE 0 END) AS is_read, COALESCE(lb.id_msg, -1) + 1 AS new_from,' . ($boardIndexOptions['include_categories'] ? ' |
||
| 57 | c.can_collapse,' : '')) . ' |
||
| 58 | COALESCE(mem.id_member, 0) AS id_member, mem.avatar, m.id_msg' . (!empty($settings['avatars_on_boardIndex']) ? ', mem.email_address, mem.avatar, COALESCE(am.id_attach, 0) AS member_id_attach, am.filename AS member_filename, am.attachment_type AS member_attach_type' : '') . ' |
||
| 59 | FROM {db_prefix}boards AS b' . ($boardIndexOptions['include_categories'] ? ' |
||
| 60 | LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . ' |
||
| 61 | LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg) |
||
| 62 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!empty($settings['avatars_on_boardIndex']) ? ' |
||
| 63 | LEFT JOIN {db_prefix}attachments AS am ON (am.id_member = m.id_member)' : '') . '' . ($user_info['is_guest'] ? '' : ' |
||
| 64 | LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})') . ' |
||
| 65 | WHERE {query_see_board}' . (empty($boardIndexOptions['countChildPosts']) ? (empty($boardIndexOptions['base_level']) ? '' : ' |
||
| 66 | AND b.child_level >= {int:child_level}') : ' |
||
| 67 | AND b.child_level BETWEEN ' . $boardIndexOptions['base_level'] . ' AND ' . ($boardIndexOptions['base_level'] + 1)) . ' |
||
| 68 | ORDER BY ' . (!empty($boardIndexOptions['include_categories']) ? 'c.cat_order, ' : '') . 'b.child_level, b.board_order', |
||
| 69 | array( |
||
| 70 | 'current_member' => $user_info['id'], |
||
| 71 | 'child_level' => $boardIndexOptions['base_level'], |
||
| 72 | 'blank_string' => '', |
||
| 73 | ) |
||
| 74 | ); |
||
| 75 | |||
| 76 | // Start with an empty array. |
||
| 77 | if ($boardIndexOptions['include_categories']) |
||
| 78 | $categories = array(); |
||
| 79 | else |
||
| 80 | $this_category = array(); |
||
| 81 | $boards = array(); |
||
| 82 | |||
| 83 | // Run through the categories and boards (or only boards).... |
||
| 84 | while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) |
||
| 85 | { |
||
| 86 | // Perhaps we are ignoring this board? |
||
| 87 | $ignoreThisBoard = in_array($row_board['id_board'], $user_info['ignoreboards']); |
||
| 88 | $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0'; |
||
| 89 | |||
| 90 | // Add parent boards to the $boards list later used to fetch moderators |
||
| 91 | if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) |
||
| 92 | $boards[] = $row_board['id_board']; |
||
| 93 | |||
| 94 | if ($boardIndexOptions['include_categories']) |
||
| 95 | { |
||
| 96 | // Haven't set this category yet. |
||
| 97 | if (empty($categories[$row_board['id_cat']])) |
||
| 98 | { |
||
| 99 | $categories[$row_board['id_cat']] = array( |
||
|
0 ignored issues
–
show
|
|||
| 100 | 'id' => $row_board['id_cat'], |
||
| 101 | 'name' => $row_board['cat_name'], |
||
| 102 | 'description' => $row_board['cat_desc'], |
||
| 103 | 'is_collapsed' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1 && !empty($options['collapse_category_' . $row_board['id_cat']]), |
||
| 104 | 'can_collapse' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1, |
||
| 105 | 'href' => $scripturl . '#c' . $row_board['id_cat'], |
||
| 106 | 'boards' => array(), |
||
| 107 | 'new' => false, |
||
| 108 | 'css_class' => '', |
||
| 109 | ); |
||
| 110 | $categories[$row_board['id_cat']]['link'] = '<a id="c' . $row_board['id_cat'] . '"></a>' . (!$context['user']['is_guest'] ? '<a href="' . $scripturl . '?action=unread;c=' . $row_board['id_cat'] . '" title="' . sprintf($txt['new_posts_in_category'], strip_tags($row_board['cat_name'])) . '">' . $row_board['cat_name'] . '</a>' : $row_board['cat_name']); |
||
| 111 | } |
||
| 112 | |||
| 113 | // If this board has new posts in it (and isn't the recycle bin!) then the category is new. |
||
| 114 | if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) |
||
| 115 | $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != ''; |
||
| 116 | |||
| 117 | // Avoid showing category unread link where it only has redirection boards. |
||
| 118 | $categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect']; |
||
| 119 | |||
| 120 | // Let's save some typing. Climbing the array might be slower, anyhow. |
||
| 121 | $this_category = &$categories[$row_board['id_cat']]['boards']; |
||
| 122 | } |
||
| 123 | |||
| 124 | // This is a parent board. |
||
| 125 | if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) |
||
| 126 | { |
||
| 127 | // Is this a new board, or just another moderator? |
||
| 128 | if (!isset($this_category[$row_board['id_board']])) |
||
| 129 | { |
||
| 130 | // Not a child. |
||
| 131 | $isChild = false; |
||
| 132 | |||
| 133 | $this_category[$row_board['id_board']] = array( |
||
|
0 ignored issues
–
show
The variable
$this_category does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 134 | 'new' => empty($row_board['is_read']), |
||
| 135 | 'id' => $row_board['id_board'], |
||
| 136 | 'name' => $row_board['board_name'], |
||
| 137 | 'description' => $row_board['description'], |
||
| 138 | 'moderators' => array(), |
||
| 139 | 'moderator_groups' => array(), |
||
| 140 | 'link_moderators' => array(), |
||
| 141 | 'link_moderator_groups' => array(), |
||
| 142 | 'children' => array(), |
||
| 143 | 'link_children' => array(), |
||
| 144 | 'children_new' => false, |
||
| 145 | 'topics' => $row_board['num_topics'], |
||
| 146 | 'posts' => $row_board['num_posts'], |
||
| 147 | 'is_redirect' => $row_board['is_redirect'], |
||
| 148 | 'unapproved_topics' => $row_board['unapproved_topics'], |
||
| 149 | 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'], |
||
| 150 | 'can_approve_posts' => !empty($user_info['mod_cache']['ap']) && ($user_info['mod_cache']['ap'] == array(0) || in_array($row_board['id_board'], $user_info['mod_cache']['ap'])), |
||
| 151 | 'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0', |
||
| 152 | 'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['board_name'] . '</a>', |
||
| 153 | 'board_class' => 'off', |
||
| 154 | 'css_class' => '', |
||
| 155 | ); |
||
| 156 | |||
| 157 | // We can do some of the figuring-out-what-icon now. |
||
| 158 | // For certain types of thing we also set up what the tooltip is. |
||
| 159 | if ($this_category[$row_board['id_board']]['is_redirect']) |
||
| 160 | { |
||
| 161 | $this_category[$row_board['id_board']]['board_class'] = 'redirect'; |
||
| 162 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board']; |
||
| 163 | } |
||
| 164 | View Code Duplication | elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
| 165 | { |
||
| 166 | // If we're showing to guests, we want to give them the idea that something interesting is going on! |
||
| 167 | $this_category[$row_board['id_board']]['board_class'] = 'on'; |
||
| 168 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts']; |
||
| 169 | } |
||
| 170 | else |
||
| 171 | { |
||
| 172 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts']; |
||
| 173 | } |
||
| 174 | } |
||
| 175 | } |
||
| 176 | // Found a child board.... make sure we've found its parent and the child hasn't been set already. |
||
| 177 | elseif (isset($this_category[$row_board['id_parent']]['children']) && !isset($this_category[$row_board['id_parent']]['children'][$row_board['id_board']])) |
||
| 178 | { |
||
| 179 | // A valid child! |
||
| 180 | $isChild = true; |
||
| 181 | |||
| 182 | $this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array( |
||
| 183 | 'id' => $row_board['id_board'], |
||
| 184 | 'name' => $row_board['board_name'], |
||
| 185 | 'description' => $row_board['description'], |
||
| 186 | 'short_description' => shorten_subject(strip_tags($row_board['description']), 128), |
||
| 187 | 'new' => empty($row_board['is_read']) && $row_board['poster_name'] != '', |
||
| 188 | 'topics' => $row_board['num_topics'], |
||
| 189 | 'posts' => $row_board['num_posts'], |
||
| 190 | 'is_redirect' => $row_board['is_redirect'], |
||
| 191 | 'unapproved_topics' => $row_board['unapproved_topics'], |
||
| 192 | 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'], |
||
| 193 | 'can_approve_posts' => !empty($user_info['mod_cache']['ap']) && ($user_info['mod_cache']['ap'] == array(0) || in_array($row_board['id_board'], $user_info['mod_cache']['ap'])), |
||
| 194 | 'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0', |
||
| 195 | 'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['board_name'] . '</a>' |
||
| 196 | ); |
||
| 197 | |||
| 198 | // Counting child board posts is... slow :/. |
||
| 199 | if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect']) |
||
| 200 | { |
||
| 201 | $this_category[$row_board['id_parent']]['posts'] += $row_board['num_posts']; |
||
| 202 | $this_category[$row_board['id_parent']]['topics'] += $row_board['num_topics']; |
||
| 203 | } |
||
| 204 | |||
| 205 | // Does this board contain new boards? |
||
| 206 | $this_category[$row_board['id_parent']]['children_new'] |= empty($row_board['is_read']); |
||
| 207 | |||
| 208 | // Update the icon if appropriate |
||
| 209 | View Code Duplication | if ($this_category[$row_board['id_parent']]['children_new'] && $this_category[$row_board['id_parent']]['board_class'] == 'off') |
|
| 210 | { |
||
| 211 | $this_category[$row_board['id_parent']]['board_class'] = 'on2'; |
||
| 212 | $this_category[$row_board['id_parent']]['board_tooltip'] = $txt['new_posts']; |
||
| 213 | } |
||
| 214 | |||
| 215 | // This is easier to use in many cases for the theme.... |
||
| 216 | $this_category[$row_board['id_parent']]['link_children'][] = &$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['link']; |
||
| 217 | } |
||
| 218 | // Child of a child... just add it on... |
||
| 219 | elseif (!empty($boardIndexOptions['countChildPosts'])) |
||
| 220 | { |
||
| 221 | if (!isset($parent_map)) |
||
| 222 | $parent_map = array(); |
||
| 223 | |||
| 224 | if (!isset($parent_map[$row_board['id_parent']])) |
||
| 225 | foreach ($this_category as $id => $board) |
||
| 226 | { |
||
| 227 | if (!isset($board['children'][$row_board['id_parent']])) |
||
| 228 | continue; |
||
| 229 | |||
| 230 | $parent_map[$row_board['id_parent']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]); |
||
| 231 | $parent_map[$row_board['id_board']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]); |
||
| 232 | |||
| 233 | break; |
||
| 234 | } |
||
| 235 | |||
| 236 | if (isset($parent_map[$row_board['id_parent']]) && !$row_board['is_redirect']) |
||
| 237 | { |
||
| 238 | $parent_map[$row_board['id_parent']][0]['posts'] += $row_board['num_posts']; |
||
| 239 | $parent_map[$row_board['id_parent']][0]['topics'] += $row_board['num_topics']; |
||
| 240 | $parent_map[$row_board['id_parent']][1]['posts'] += $row_board['num_posts']; |
||
| 241 | $parent_map[$row_board['id_parent']][1]['topics'] += $row_board['num_topics']; |
||
| 242 | |||
| 243 | continue; |
||
| 244 | } |
||
| 245 | |||
| 246 | continue; |
||
| 247 | } |
||
| 248 | // Found a child of a child - skip. |
||
| 249 | else |
||
| 250 | continue; |
||
| 251 | |||
| 252 | // Prepare the subject, and make sure it's not too long. |
||
| 253 | censorText($row_board['subject']); |
||
| 254 | $row_board['short_subject'] = shorten_subject($row_board['subject'], 24); |
||
| 255 | $this_last_post = array( |
||
| 256 | 'id' => $row_board['id_msg'], |
||
| 257 | 'time' => $row_board['poster_time'] > 0 ? timeformat($row_board['poster_time']) : $txt['not_applicable'], |
||
| 258 | 'timestamp' => forum_time(true, $row_board['poster_time']), |
||
| 259 | 'subject' => $row_board['short_subject'], |
||
| 260 | 'member' => array( |
||
| 261 | 'id' => $row_board['id_member'], |
||
| 262 | 'username' => $row_board['poster_name'] != '' ? $row_board['poster_name'] : $txt['not_applicable'], |
||
| 263 | 'name' => $row_board['real_name'], |
||
| 264 | 'href' => $row_board['poster_name'] != '' && !empty($row_board['id_member']) ? $scripturl . '?action=profile;u=' . $row_board['id_member'] : '', |
||
| 265 | 'link' => $row_board['poster_name'] != '' ? (!empty($row_board['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row_board['id_member'] . '">' . $row_board['real_name'] . '</a>' : $row_board['real_name']) : $txt['not_applicable'], |
||
| 266 | ), |
||
| 267 | 'start' => 'msg' . $row_board['new_from'], |
||
| 268 | 'topic' => $row_board['id_topic'] |
||
| 269 | ); |
||
| 270 | |||
| 271 | if (!empty($settings['avatars_on_boardIndex'])) |
||
| 272 | $this_last_post['member']['avatar'] = set_avatar_data(array( |
||
| 273 | 'avatar' => $row_board['avatar'], |
||
| 274 | 'email' => $row_board['email_address'], |
||
| 275 | 'filename' => !empty($row['member_filename']) ? $row_board['member_filename'] : '', |
||
| 276 | )); |
||
| 277 | |||
| 278 | // Provide the href and link. |
||
| 279 | if ($row_board['subject'] != '') |
||
| 280 | { |
||
| 281 | $this_last_post['href'] = $scripturl . '?topic=' . $row_board['id_topic'] . '.msg' . ($user_info['is_guest'] ? $row_board['id_msg'] : $row_board['new_from']) . (empty($row_board['is_read']) ? ';boardseen' : '') . '#new'; |
||
| 282 | $this_last_post['link'] = '<a href="' . $this_last_post['href'] . '" title="' . $row_board['subject'] . '">' . $row_board['short_subject'] . '</a>'; |
||
| 283 | /* The board's and children's 'last_post's have: |
||
| 284 | time, timestamp (a number that represents the time.), id (of the post), topic (topic id.), |
||
| 285 | link, href, subject, start (where they should go for the first unread post.), |
||
| 286 | and member. (which has id, name, link, href, username in it.) */ |
||
| 287 | $this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']); |
||
| 288 | } |
||
| 289 | else |
||
| 290 | { |
||
| 291 | $this_last_post['href'] = ''; |
||
| 292 | $this_last_post['link'] = $txt['not_applicable']; |
||
| 293 | $this_last_post['last_post_message'] = ''; |
||
| 294 | } |
||
| 295 | |||
| 296 | // Set the last post in the parent board. |
||
| 297 | if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']))) |
||
| 298 | $this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post; |
||
|
0 ignored issues
–
show
The variable
$isChild does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 299 | // Just in the child...? |
||
| 300 | if ($isChild) |
||
| 301 | { |
||
| 302 | $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
||
| 303 | |||
| 304 | // If there are no posts in this board, it really can't be new... |
||
| 305 | $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != ''; |
||
| 306 | } |
||
| 307 | // No last post for this board? It's not new then, is it..? |
||
| 308 | elseif ($row_board['poster_name'] == '') |
||
| 309 | $this_category[$row_board['id_board']]['new'] = false; |
||
| 310 | |||
| 311 | // Determine a global most recent topic. |
||
| 312 | if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) |
||
|
0 ignored issues
–
show
The variable
$latest_post does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 313 | $latest_post = array( |
||
| 314 | 'timestamp' => $row_board['poster_time'], |
||
| 315 | 'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'], |
||
| 316 | ); |
||
| 317 | } |
||
| 318 | $smcFunc['db_free_result']($result_boards); |
||
| 319 | |||
| 320 | // Fetch the board's moderators and moderator groups |
||
| 321 | $boards = array_unique($boards); |
||
| 322 | $moderators = getBoardModerators($boards); |
||
| 323 | $groups = getBoardModeratorGroups($boards); |
||
| 324 | if ($boardIndexOptions['include_categories']) |
||
| 325 | { |
||
| 326 | foreach ($categories as $k => $category) |
||
| 327 | { |
||
| 328 | foreach ($category['boards'] as $j => $board) |
||
| 329 | { |
||
| 330 | View Code Duplication | if (!empty($moderators[$board['id']])) |
|
| 331 | { |
||
| 332 | $categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']]; |
||
| 333 | foreach ($moderators[$board['id']] as $moderator) |
||
| 334 | $categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link']; |
||
| 335 | } |
||
| 336 | if (!empty($groups[$board['id']])) |
||
| 337 | { |
||
| 338 | $categories[$k]['boards'][$j]['moderator_groups'] = $groups[$board['id']]; |
||
| 339 | foreach ($groups[$board['id']] as $group) |
||
| 340 | { |
||
| 341 | $categories[$k]['boards'][$j]['link_moderators'][] = $group['link']; |
||
| 342 | $categories[$k]['boards'][$j]['link_moderator_groups'][] = $group['link']; |
||
| 343 | } |
||
| 344 | } |
||
| 345 | } |
||
| 346 | } |
||
| 347 | } |
||
| 348 | else |
||
| 349 | { |
||
| 350 | foreach ($this_category as $k => $board) |
||
| 351 | { |
||
| 352 | if (!empty($moderators[$board['id']])) |
||
| 353 | { |
||
| 354 | $this_category[$k]['moderators'] = $moderators[$board['id']]; |
||
| 355 | foreach ($moderators[$board['id']] as $moderator) |
||
| 356 | $this_category[$k]['link_moderators'][] = $moderator['link']; |
||
| 357 | } |
||
| 358 | View Code Duplication | if (!empty($groups[$board['id']])) |
|
| 359 | { |
||
| 360 | $this_category[$k]['moderator_groups'] = $groups[$board['id']]; |
||
| 361 | foreach ($groups[$board['id']] as $group) |
||
| 362 | { |
||
| 363 | $this_category[$k]['link_moderators'][] = $group['link']; |
||
| 364 | $this_category[$k]['link_moderator_groups'][] = $group['link']; |
||
| 365 | } |
||
| 366 | } |
||
| 367 | } |
||
| 368 | } |
||
| 369 | |||
| 370 | if ($boardIndexOptions['include_categories']) |
||
| 371 | sortCategories($categories); |
||
| 372 | else |
||
| 373 | sortBoards($this_category); |
||
| 374 | |||
| 375 | // By now we should know the most recent post...if we wanna know it that is. |
||
| 376 | if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) |
||
| 377 | $context['latest_post'] = $latest_post['ref']; |
||
| 378 | |||
| 379 | // I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea. |
||
| 380 | if ($boardIndexOptions['include_categories']) |
||
| 381 | call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
||
| 382 | else |
||
| 383 | call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
||
| 384 | |||
| 385 | return $boardIndexOptions['include_categories'] ? $categories : $this_category; |
||
| 386 | } |
||
| 387 | |||
| 388 | ?> |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: