Chris@76: boards->child_boards or an associative array Chris@76: with boards->child_boards. Chris@76: */ Chris@76: Chris@76: function getBoardIndex($boardIndexOptions) Chris@76: { Chris@76: global $smcFunc, $scripturl, $user_info, $modSettings, $txt; Chris@76: global $settings, $context; Chris@76: Chris@76: // For performance, track the latest post while going through the boards. Chris@76: if (!empty($boardIndexOptions['set_latest_post'])) Chris@76: $latest_post = array( Chris@76: 'timestamp' => 0, Chris@76: 'ref' => 0, Chris@76: ); Chris@76: Chris@76: // 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. Chris@76: $result_boards = $smcFunc['db_query']('boardindex_fetch_boards', ' Chris@76: SELECT' . ($boardIndexOptions['include_categories'] ? ' Chris@76: c.id_cat, c.name AS cat_name,' : '') . ' Chris@76: b.id_board, b.name AS board_name, b.description, Chris@76: CASE WHEN b.redirect != {string:blank_string} THEN 1 ELSE 0 END AS is_redirect, Chris@76: b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent, Chris@76: IFNULL(m.poster_time, 0) AS poster_time, IFNULL(mem.member_name, m.poster_name) AS poster_name, Chris@76: m.subject, m.id_topic, IFNULL(mem.real_name, m.poster_name) AS real_name, Chris@76: ' . ($user_info['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : ' Chris@76: (IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_read, IFNULL(lb.id_msg, -1) + 1 AS new_from,' . ($boardIndexOptions['include_categories'] ? ' Chris@76: c.can_collapse, IFNULL(cc.id_member, 0) AS is_collapsed,' : '')) . ' Chris@76: IFNULL(mem.id_member, 0) AS id_member, m.id_msg, Chris@76: IFNULL(mods_mem.id_member, 0) AS id_moderator, mods_mem.real_name AS mod_real_name Chris@76: FROM {db_prefix}boards AS b' . ($boardIndexOptions['include_categories'] ? ' Chris@76: LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . ' Chris@76: LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg) Chris@76: LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . ($user_info['is_guest'] ? '' : ' Chris@76: LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})' . ($boardIndexOptions['include_categories'] ? ' Chris@76: LEFT JOIN {db_prefix}collapsed_categories AS cc ON (cc.id_cat = c.id_cat AND cc.id_member = {int:current_member})' : '')) . ' Chris@76: LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board) Chris@76: LEFT JOIN {db_prefix}members AS mods_mem ON (mods_mem.id_member = mods.id_member) Chris@76: WHERE {query_see_board}' . (empty($boardIndexOptions['countChildPosts']) ? (empty($boardIndexOptions['base_level']) ? '' : ' Chris@76: AND b.child_level >= {int:child_level}') : ' Chris@76: AND b.child_level BETWEEN ' . $boardIndexOptions['base_level'] . ' AND ' . ($boardIndexOptions['base_level'] + 1)), Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: 'child_level' => $boardIndexOptions['base_level'], Chris@76: 'blank_string' => '', Chris@76: ) Chris@76: ); Chris@76: Chris@76: // Start with an empty array. Chris@76: if ($boardIndexOptions['include_categories']) Chris@76: $categories = array(); Chris@76: else Chris@76: $this_category = array(); Chris@76: Chris@76: // Run through the categories and boards (or only boards).... Chris@76: while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) Chris@76: { Chris@76: // Perhaps we are ignoring this board? Chris@76: $ignoreThisBoard = in_array($row_board['id_board'], $user_info['ignoreboards']); Chris@76: $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0'; Chris@76: Chris@76: if ($boardIndexOptions['include_categories']) Chris@76: { Chris@76: // Haven't set this category yet. Chris@76: if (empty($categories[$row_board['id_cat']])) Chris@76: { Chris@76: $categories[$row_board['id_cat']] = array( Chris@76: 'id' => $row_board['id_cat'], Chris@76: 'name' => $row_board['cat_name'], Chris@76: 'is_collapsed' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1 && $row_board['is_collapsed'] > 0, Chris@76: 'can_collapse' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1, Chris@76: 'collapse_href' => isset($row_board['can_collapse']) ? $scripturl . '?action=collapse;c=' . $row_board['id_cat'] . ';sa=' . ($row_board['is_collapsed'] > 0 ? 'expand;' : 'collapse;') . $context['session_var'] . '=' . $context['session_id'] . '#c' . $row_board['id_cat'] : '', Chris@76: 'collapse_image' => isset($row_board['can_collapse']) ? '+' : '', Chris@76: 'href' => $scripturl . '#c' . $row_board['id_cat'], Chris@76: 'boards' => array(), Chris@76: 'new' => false Chris@76: ); Chris@76: $categories[$row_board['id_cat']]['link'] = '' . ($categories[$row_board['id_cat']]['can_collapse'] ? '' . $row_board['cat_name'] . '' : $row_board['cat_name']); Chris@76: } Chris@76: Chris@76: // If this board has new posts in it (and isn't the recycle bin!) then the category is new. Chris@76: if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) Chris@76: $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != ''; Chris@76: Chris@76: // Avoid showing category unread link where it only has redirection boards. Chris@76: $categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect']; Chris@76: Chris@76: // Collapsed category - don't do any of this. Chris@76: if ($categories[$row_board['id_cat']]['is_collapsed']) Chris@76: continue; Chris@76: Chris@76: // Let's save some typing. Climbing the array might be slower, anyhow. Chris@76: $this_category = &$categories[$row_board['id_cat']]['boards']; Chris@76: } Chris@76: Chris@76: // This is a parent board. Chris@76: if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) Chris@76: { Chris@76: // Is this a new board, or just another moderator? Chris@76: if (!isset($this_category[$row_board['id_board']])) Chris@76: { Chris@76: // Not a child. Chris@76: $isChild = false; Chris@76: Chris@76: $this_category[$row_board['id_board']] = array( Chris@76: 'new' => empty($row_board['is_read']), Chris@76: 'id' => $row_board['id_board'], Chris@76: 'name' => $row_board['board_name'], Chris@76: 'description' => $row_board['description'], Chris@76: 'moderators' => array(), Chris@76: 'link_moderators' => array(), Chris@76: 'children' => array(), Chris@76: 'link_children' => array(), Chris@76: 'children_new' => false, Chris@76: 'topics' => $row_board['num_topics'], Chris@76: 'posts' => $row_board['num_posts'], Chris@76: 'is_redirect' => $row_board['is_redirect'], Chris@76: 'unapproved_topics' => $row_board['unapproved_topics'], Chris@76: 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'], Chris@76: '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'])), Chris@76: 'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0', Chris@76: 'link' => '' . $row_board['board_name'] . '' Chris@76: ); Chris@76: } Chris@76: if (!empty($row_board['id_moderator'])) Chris@76: { Chris@76: $this_category[$row_board['id_board']]['moderators'][$row_board['id_moderator']] = array( Chris@76: 'id' => $row_board['id_moderator'], Chris@76: 'name' => $row_board['mod_real_name'], Chris@76: 'href' => $scripturl . '?action=profile;u=' . $row_board['id_moderator'], Chris@76: 'link' => '' . $row_board['mod_real_name'] . '' Chris@76: ); Chris@76: $this_category[$row_board['id_board']]['link_moderators'][] = '' . $row_board['mod_real_name'] . ''; Chris@76: } Chris@76: } Chris@76: // Found a child board.... make sure we've found its parent and the child hasn't been set already. Chris@76: elseif (isset($this_category[$row_board['id_parent']]['children']) && !isset($this_category[$row_board['id_parent']]['children'][$row_board['id_board']])) Chris@76: { Chris@76: // A valid child! Chris@76: $isChild = true; Chris@76: Chris@76: $this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array( Chris@76: 'id' => $row_board['id_board'], Chris@76: 'name' => $row_board['board_name'], Chris@76: 'description' => $row_board['description'], Chris@76: 'new' => empty($row_board['is_read']) && $row_board['poster_name'] != '', Chris@76: 'topics' => $row_board['num_topics'], Chris@76: 'posts' => $row_board['num_posts'], Chris@76: 'is_redirect' => $row_board['is_redirect'], Chris@76: 'unapproved_topics' => $row_board['unapproved_topics'], Chris@76: 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'], Chris@76: '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'])), Chris@76: 'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0', Chris@76: 'link' => '' . $row_board['board_name'] . '' Chris@76: ); Chris@76: Chris@76: // Counting child board posts is... slow :/. Chris@76: if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect']) Chris@76: { Chris@76: $this_category[$row_board['id_parent']]['posts'] += $row_board['num_posts']; Chris@76: $this_category[$row_board['id_parent']]['topics'] += $row_board['num_topics']; Chris@76: } Chris@76: Chris@76: // Does this board contain new boards? Chris@76: $this_category[$row_board['id_parent']]['children_new'] |= empty($row_board['is_read']); Chris@76: Chris@76: // This is easier to use in many cases for the theme.... Chris@76: $this_category[$row_board['id_parent']]['link_children'][] = &$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['link']; Chris@76: } Chris@76: // Child of a child... just add it on... Chris@76: elseif (!empty($boardIndexOptions['countChildPosts'])) Chris@76: { Chris@76: if (!isset($parent_map)) Chris@76: $parent_map = array(); Chris@76: Chris@76: if (!isset($parent_map[$row_board['id_parent']])) Chris@76: foreach ($this_category as $id => $board) Chris@76: { Chris@76: if (!isset($board['children'][$row_board['id_parent']])) Chris@76: continue; Chris@76: Chris@76: $parent_map[$row_board['id_parent']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]); Chris@76: $parent_map[$row_board['id_board']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]); Chris@76: Chris@76: break; Chris@76: } Chris@76: Chris@76: if (isset($parent_map[$row_board['id_parent']]) && !$row_board['is_redirect']) Chris@76: { Chris@76: $parent_map[$row_board['id_parent']][0]['posts'] += $row_board['num_posts']; Chris@76: $parent_map[$row_board['id_parent']][0]['topics'] += $row_board['num_topics']; Chris@76: $parent_map[$row_board['id_parent']][1]['posts'] += $row_board['num_posts']; Chris@76: $parent_map[$row_board['id_parent']][1]['topics'] += $row_board['num_topics']; Chris@76: Chris@76: continue; Chris@76: } Chris@76: Chris@76: continue; Chris@76: } Chris@76: // Found a child of a child - skip. Chris@76: else Chris@76: continue; Chris@76: Chris@76: // Prepare the subject, and make sure it's not too long. Chris@76: censorText($row_board['subject']); Chris@76: $row_board['short_subject'] = shorten_subject($row_board['subject'], 24); Chris@76: $this_last_post = array( Chris@76: 'id' => $row_board['id_msg'], Chris@76: 'time' => $row_board['poster_time'] > 0 ? timeformat($row_board['poster_time']) : $txt['not_applicable'], Chris@76: 'timestamp' => forum_time(true, $row_board['poster_time']), Chris@76: 'subject' => $row_board['short_subject'], Chris@76: 'member' => array( Chris@76: 'id' => $row_board['id_member'], Chris@76: 'username' => $row_board['poster_name'] != '' ? $row_board['poster_name'] : $txt['not_applicable'], Chris@76: 'name' => $row_board['real_name'], Chris@76: 'href' => $row_board['poster_name'] != '' && !empty($row_board['id_member']) ? $scripturl . '?action=profile;u=' . $row_board['id_member'] : '', Chris@76: 'link' => $row_board['poster_name'] != '' ? (!empty($row_board['id_member']) ? '' . $row_board['real_name'] . '' : $row_board['real_name']) : $txt['not_applicable'], Chris@76: ), Chris@76: 'start' => 'msg' . $row_board['new_from'], Chris@76: 'topic' => $row_board['id_topic'] Chris@76: ); Chris@76: Chris@76: // Provide the href and link. Chris@76: if ($row_board['subject'] != '') Chris@76: { Chris@76: $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'; Chris@76: $this_last_post['link'] = '' . $row_board['short_subject'] . ''; Chris@76: } Chris@76: else Chris@76: { Chris@76: $this_last_post['href'] = ''; Chris@76: $this_last_post['link'] = $txt['not_applicable']; Chris@76: } Chris@76: Chris@76: // Set the last post in the parent board. Chris@76: 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']))) Chris@76: $this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post; Chris@76: // Just in the child...? Chris@76: if ($isChild) Chris@76: { Chris@76: $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; Chris@76: Chris@76: // If there are no posts in this board, it really can't be new... Chris@76: $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != ''; Chris@76: } Chris@76: // No last post for this board? It's not new then, is it..? Chris@76: elseif ($row_board['poster_name'] == '') Chris@76: $this_category[$row_board['id_board']]['new'] = false; Chris@76: Chris@76: // Determine a global most recent topic. Chris@76: if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) Chris@76: $latest_post = array( Chris@76: 'timestamp' => $row_board['poster_time'], Chris@76: 'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'], Chris@76: ); Chris@76: } Chris@76: $smcFunc['db_free_result']($result_boards); Chris@76: Chris@76: // By now we should know the most recent post...if we wanna know it that is. Chris@76: if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) Chris@76: $context['latest_post'] = $latest_post['ref']; Chris@76: Chris@76: return $boardIndexOptions['include_categories'] ? $categories : $this_category; Chris@76: } Chris@76: Chris@76: ?>