Browse Source

! Rearrange the board index code somewhat - the chunks of content in the info center are now controlled via a list in $context, meaning a mod can (through hooks only) remove or add blocks or rearrange them at will. The chunk that was displayed in the info center in the case of the stats index being off - the PM bar - is now gone. More clean-up to come though.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 11 years ago
parent
commit
f0d6f997fe
2 changed files with 152 additions and 136 deletions
  1. 42 31
      Sources/BoardIndex.php
  2. 110 105
      Themes/default/BoardIndex.template.php

+ 42 - 31
Sources/BoardIndex.php

@@ -55,40 +55,24 @@ function BoardIndex()
 	);
 	$context['categories'] = getBoardIndex($boardIndexOptions);
 
-	// Get the user online list.
-	require_once($sourcedir . '/Subs-MembersOnline.php');
-	$membersOnlineOptions = array(
-		'show_hidden' => allowedTo('moderate_forum'),
-		'sort' => 'log_time',
-		'reverse_sort' => true,
-	);
-	$context += getMembersOnlineStats($membersOnlineOptions);
-
-	$context['show_buddies'] = !empty($user_info['buddies']);
-
-	// Are we showing all membergroups on the board index?
-	if (!empty($settings['show_group_key']))
-		$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
-
-	// Track most online statistics? (Subs-MembersOnline.php)
-	if (!empty($modSettings['trackStats']))
-		trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
+	// Now set up for the info center.
+	$context['info_center'] = array();
 
 	// Retrieve the latest posts if the theme settings require it.
-	if (isset($settings['number_recent_posts']) && $settings['number_recent_posts'] > 1)
+	if (!empty($settings['number_recent_posts']))
 	{
-		$latestPostOptions = array(
-			'number_posts' => $settings['number_recent_posts'],
-		);
-		$context['latest_posts'] = cache_quick_get('boardindex-latest_posts:' . md5($user_info['query_wanna_see_board'] . $user_info['language']), 'Subs-Recent.php', 'cache_getLastPosts', array($latestPostOptions));
+		if ($settings['number_recent_posts'] > 1)
+		{
+			$latestPostOptions = array(
+				'number_posts' => $settings['number_recent_posts'],
+			);
+			$context['latest_posts'] = cache_quick_get('boardindex-latest_posts:' . md5($user_info['query_wanna_see_board'] . $user_info['language']), 'Subs-Recent.php', 'cache_getLastPosts', array($latestPostOptions));
+		}
+
+		if (!empty($context['latest_posts']) || !empty($context['latest_post']))
+			$context['info_center'][] = 'recent';
 	}
 
-	$settings['display_recent_bar'] = !empty($settings['number_recent_posts']) ? $settings['number_recent_posts'] : 0;
-	$settings['show_member_bar'] &= allowedTo('view_mlist');
-	$context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);
-	$context['show_member_list'] = allowedTo('view_mlist');
-	$context['show_who'] = allowedTo('who_view') && !empty($modSettings['who_enabled']);
-
 	// Load the calendar?
 	if (!empty($modSettings['cal_enabled']) && allowedTo('calendar_view'))
 	{
@@ -106,10 +90,37 @@ function BoardIndex()
 
 		// This is used to show the "how-do-I-edit" help.
 		$context['calendar_can_edit'] = allowedTo('calendar_edit_any');
+
+		if ($context['show_calendar'])
+			$context['info_center'][] = 'calendar';
 	}
-	else
-		$context['show_calendar'] = false;
 
+	// And stats.
+	$context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);
+	if ($settings['show_stats_index'])
+		$context['info_center'][] = 'stats';
+
+	// Now the online stuff
+	require_once($sourcedir . '/Subs-MembersOnline.php');
+	$membersOnlineOptions = array(
+		'show_hidden' => allowedTo('moderate_forum'),
+		'sort' => 'log_time',
+		'reverse_sort' => true,
+	);
+	$context += getMembersOnlineStats($membersOnlineOptions);
+	$context['show_buddies'] = !empty($user_info['buddies']);
+	$context['show_who'] = allowedTo('who_view') && !empty($modSettings['who_enabled']);
+	$context['info_center'][] = 'online';
+
+	// Track most online statistics? (Subs-MembersOnline.php)
+	if (!empty($modSettings['trackStats']))
+		trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
+
+	// Are we showing all membergroups on the board index?
+	if (!empty($settings['show_group_key']))
+		$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
+
+	// And back to normality.
 	$context['page_title'] = sprintf($txt['forum_index'], $context['forum_name']);
 
 	// Mark read button

+ 110 - 105
Themes/default/BoardIndex.template.php

@@ -236,6 +236,9 @@ function template_info_center()
 {
 	global $context, $settings, $options, $txt, $scripturl, $modSettings;
 
+	if (empty($context['info_center']))
+		return;
+
 	// Here's where the "Info Center" starts...
 	echo '
 	<div class="roundframe" id="info_center">
@@ -247,10 +250,59 @@ function template_info_center()
 		</div>
 		<div id="upshrinkHeaderIC"', empty($options['collapse_header_ic']) ? '' : ' style="display: none;"', '>';
 
-	// This is the "Recent Posts" bar.
-	if (!empty($settings['number_recent_posts']) && (!empty($context['latest_posts']) || !empty($context['latest_post'])))
+	foreach ($context['info_center'] as $block)
 	{
-		echo '
+		$func = 'template_ic_block_' . $block;
+		$func();
+	}
+
+	echo '
+		</div>
+	</div>';
+
+	// Info center collapse object.
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var oInfoCenterToggle = new smc_Toggle({
+			bToggleEnabled: true,
+			bCurrentlyCollapsed: ', empty($options['collapse_header_ic']) ? 'false' : 'true', ',
+			aSwappableContainers: [
+				\'upshrinkHeaderIC\'
+			],
+			aSwapImages: [
+				{
+					sId: \'upshrink_ic\',
+					altExpanded: ', JavaScriptEscape($txt['hide']), ',
+					altCollapsed: ', JavaScriptEscape($txt['show']), '
+				}
+			],
+			aSwapLinks: [
+				{
+					sId: \'upshrink_link\',
+					msgExpanded: ', JavaScriptEscape(sprintf($txt['info_center_title'], $context['forum_name_html_safe'])), ',
+					msgCollapsed: ', JavaScriptEscape(sprintf($txt['info_center_title'], $context['forum_name_html_safe'])), '
+				}
+			],
+			oThemeOptions: {
+				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
+				sOptionName: \'collapse_header_ic\',
+				sSessionId: smf_session_id,
+				sSessionVar: smf_session_var,
+			},
+			oCookieOptions: {
+				bUseCookie: ', $context['user']['is_guest'] ? 'true' : 'false', ',
+				sCookieName: \'upshrinkIC\'
+			}
+		});
+	// ]]></script>';
+}
+
+function template_ic_block_recent()
+{
+	global $context, $scripturl, $settings, $txt;
+
+	// This is the "Recent Posts" bar.
+	echo '
 			<div class="title_barIC">
 				<h4 class="titlebg">
 					<a href="', $scripturl, '?action=recent"><img class="icon" src="', $settings['images_url'], '/post/xx.png" alt="" />', $txt['recent_posts'], '</a>
@@ -262,19 +314,19 @@ function template_info_center()
 					<a rel="feedurl" href="', $scripturl, '?action=.xml;type=webslice">', $txt['subscribe_webslice'], '</a>
 				</div>';
 
-		// Only show one post.
-		if ($settings['number_recent_posts'] == 1)
-		{
-			// latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
-			echo '
+	// Only show one post.
+	if ($settings['number_recent_posts'] == 1)
+	{
+		// latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
+		echo '
 				<p id="infocenter_onepost" class="inline">
 					<a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>&nbsp;&quot;', sprintf($txt['is_recent_updated'], '&quot;' . $context['latest_post']['link'], '&quot;'), ' (', $context['latest_post']['time'], ')<br />
 				</p>';
-		}
-		// Show lots of posts.
-		elseif (!empty($context['latest_posts']))
-		{
-			echo '
+	}
+	// Show lots of posts.
+	elseif (!empty($context['latest_posts']))
+	{
+		echo '
 				<table id="ic_recentposts">
 					<tr>
 						<th class="recentpost first_th">', $txt['message'], '</th>
@@ -283,74 +335,78 @@ function template_info_center()
 						<th class="recenttime last_th">', $txt['date'], '</th>
 					</tr>';
 
-			/* Each post in latest_posts has:
-					board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
-					subject, short_subject (shortened with...), time, link, and href. */
-			foreach ($context['latest_posts'] as $post)
-				echo '
+		/* Each post in latest_posts has:
+				board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
+				subject, short_subject (shortened with...), time, link, and href. */
+		foreach ($context['latest_posts'] as $post)
+			echo '
 					<tr>
 						<td class="recentpost"><strong>', $post['link'], '</strong></td>
 						<td class="recentposter">', $post['poster']['link'], '</td>
 						<td class="recentboard">', $post['board']['link'], '</td>
 						<td class="recenttime">', $post['time'], '</td>
 					</tr>';
-			echo '
-				</table>';
-		}
 		echo '
-			</div>';
+				</table>';
 	}
+	echo '
+			</div>';
+}
+
+function template_ic_block_calendar()
+{
+	global $context, $scripturl, $txt, $settings;
 
 	// Show information about events, birthdays, and holidays on the calendar.
-	if ($context['show_calendar'])
-	{
-		echo '
+	echo '
 			<div class="title_barIC">
 				<h4 class="titlebg">
 					<a href="', $scripturl, '?action=calendar' . '"><img class="icon" src="', $settings['images_url'], '/icons/calendar.png', '" alt="" />', $context['calendar_only_today'] ? $txt['calendar_today'] : $txt['calendar_upcoming'], '</a>
 				</h4>
 			</div>';
 
-		// Holidays like "Christmas", "Chanukah", and "We Love [Unknown] Day" :P.
-		if (!empty($context['calendar_holidays']))
-			echo '
+	// Holidays like "Christmas", "Chanukah", and "We Love [Unknown] Day" :P.
+	if (!empty($context['calendar_holidays']))
+		echo '
 				<p class="inline holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $context['calendar_holidays']), '</p>';
 
-		// People's birthdays. Like mine. And yours, I guess. Kidding.
-		if (!empty($context['calendar_birthdays']))
-		{
-			echo '
+	// People's birthdays. Like mine. And yours, I guess. Kidding.
+	if (!empty($context['calendar_birthdays']))
+	{
+		echo '
 				<p class="inline">
 					<span class="birthday">', $context['calendar_only_today'] ? $txt['birthdays'] : $txt['birthdays_upcoming'], '</span>';
-			// Each member in calendar_birthdays has: id, name (person), age (if they have one set?), is_last. (last in list?), and is_today (birthday is today?)
-			foreach ($context['calendar_birthdays'] as $member)
-				echo '
-					<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['is_today'] ? '<strong class="fix_rtl_names">' : '', $member['name'], $member['is_today'] ? '</strong>' : '', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] ? '' : ', ';
+		// Each member in calendar_birthdays has: id, name (person), age (if they have one set?), is_last. (last in list?), and is_today (birthday is today?)
+		foreach ($context['calendar_birthdays'] as $member)
 			echo '
+					<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['is_today'] ? '<strong class="fix_rtl_names">' : '', $member['name'], $member['is_today'] ? '</strong>' : '', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] ? '' : ', ';
+		echo '
 				</p>';
-		}
+	}
 
-		// Events like community get-togethers.
-		if (!empty($context['calendar_events']))
-		{
-			echo '
+	// Events like community get-togethers.
+	if (!empty($context['calendar_events']))
+	{
+		echo '
 				<p class="inline">
 					<span class="event">', $context['calendar_only_today'] ? $txt['events'] : $txt['events_upcoming'], '</span> ';
 
-			// Each event in calendar_events should have:
-			//		title, href, is_last, can_edit (are they allowed?), modify_href, and is_today.
-			foreach ($context['calendar_events'] as $event)
-				echo '
-					', $event['can_edit'] ? '<a href="' . $event['modify_href'] . '" title="' . $txt['calendar_edit'] . '"><img src="' . $settings['images_url'] . '/icons/calendar_modify.png" alt="*" class="centericon" /></a> ' : '', $event['href'] == '' ? '' : '<a href="' . $event['href'] . '">', $event['is_today'] ? '<strong>' . $event['title'] . '</strong>' : $event['title'], $event['href'] == '' ? '' : '</a>', $event['is_last'] ? '<br />' : ', ';
+		// Each event in calendar_events should have:
+		//		title, href, is_last, can_edit (are they allowed?), modify_href, and is_today.
+		foreach ($context['calendar_events'] as $event)
 			echo '
+					', $event['can_edit'] ? '<a href="' . $event['modify_href'] . '" title="' . $txt['calendar_edit'] . '"><img src="' . $settings['images_url'] . '/icons/calendar_modify.png" alt="*" class="centericon" /></a> ' : '', $event['href'] == '' ? '' : '<a href="' . $event['href'] . '">', $event['is_today'] ? '<strong>' . $event['title'] . '</strong>' : $event['title'], $event['href'] == '' ? '' : '</a>', $event['is_last'] ? '<br />' : ', ';
+		echo '
 				</p>';
-		}
 	}
+}
+
+function template_ic_block_stats()
+{
+	global $scripturl, $txt, $context, $settings;
 
 	// Show statistical style information...
-	if ($settings['show_stats_index'])
-	{
-		echo '
+	echo '
 			<div class="title_barIC">
 				<h4 class="titlebg">
 					<a href="', $scripturl, '?action=stats" title="', $txt['more_stats'], '"><span class="stats_icon boards"></span>', $txt['forum_stats'], '</a>
@@ -361,8 +417,11 @@ function template_info_center()
 				', (!empty($context['latest_post']) ? $txt['latest_post'] . ': <strong>&quot;' . $context['latest_post']['link'] . '&quot;</strong>  ( ' . $context['latest_post']['time'] . ' )<br />' : ''), '
 				<a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>
 			</p>';
-	}
+}
 
+function template_ic_block_online()
+{
+	global $context, $scripturl, $txt, $modSettings;
 	// "Users online" - in order of activity.
 	echo '
 			<div class="title_barIC">
@@ -404,59 +463,5 @@ function template_info_center()
 
 	echo '
 			</p>';
-
-	// If they are logged in, but statistical information is off... show a personal message bar.
-	if ($context['user']['is_logged'] && !$settings['show_stats_index'])
-	{
-		echo '
-			<div class="title_barIC">
-				<h4 class="titlebg">
-					', $context['allow_pm'] ? '<a href="' . $scripturl . '?action=pm">' : '', '<span class="pm_icons inbox icon"></span>', $txt['personal_message'], '', $context['allow_pm'] ? '</a>' : '', '
-				</h4>
-			</div>
-			<p class="pminfo">
-					', empty($context['user']['messages']) ? $txt['you_have_no_msg'] : ($context['user']['messages'] == 1 ? sprintf($txt['you_have_one_msg'], $scripturl . '?action=pm') : sprintf($txt['you_have_many_msgs'], $scripturl . '?action=pm', $context['user']['messages'])), '
-			</p>';
-	}
-
-	echo '
-		</div>
-	</div>';
-
-	// Info center collapse object.
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var oInfoCenterToggle = new smc_Toggle({
-			bToggleEnabled: true,
-			bCurrentlyCollapsed: ', empty($options['collapse_header_ic']) ? 'false' : 'true', ',
-			aSwappableContainers: [
-				\'upshrinkHeaderIC\'
-			],
-			aSwapImages: [
-				{
-					sId: \'upshrink_ic\',
-					altExpanded: ', JavaScriptEscape($txt['hide']), ',
-					altCollapsed: ', JavaScriptEscape($txt['show']), '
-				}
-			],
-			aSwapLinks: [
-				{
-					sId: \'upshrink_link\',
-					msgExpanded: ', JavaScriptEscape(sprintf($txt['info_center_title'], $context['forum_name_html_safe'])), ',
-					msgCollapsed: ', JavaScriptEscape(sprintf($txt['info_center_title'], $context['forum_name_html_safe'])), '
-				}
-			],
-			oThemeOptions: {
-				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
-				sOptionName: \'collapse_header_ic\',
-				sSessionId: smf_session_id,
-				sSessionVar: smf_session_var,
-			},
-			oCookieOptions: {
-				bUseCookie: ', $context['user']['is_guest'] ? 'true' : 'false', ',
-				sCookieName: \'upshrinkIC\'
-			}
-		});
-	// ]]></script>';
 }
 ?>