MyBB Community Forums

Full Version: Full UI Overhaul
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to do a full UI overhaul that can only be done by changing the source code of the index.php. I only want this to happen, however, when a user is using a particular theme. So I'm making a plugin that will do this. What I'm trying to do, is copy everything after the "index_start" hook, and putting it in a function to be run at the index_start hook. The only problem is well... Just view the attachment. That's what my index page looks like when the plugin is active. I set all this up on my local computer so that I could test it without affecting my actual website, by the way.

Here is the current contents of test.php (the plugin):
<?php
/*************************\
|*Copyright Nicholas Roge*|
\*************************/
 
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("index_start", "test");

function test_info()
{
	/**
	 * Array of information about the plugin.
	 * name: The name of the plugin
	 * description: Description of what the plugin does
	 * website: The website the plugin is maintained at (Optional)
	 * author: The name of the author of the plugin
	 * authorsite: The URL to the website of the author (Optional)
	 * version: The version number of the plugin
	 * guid: Unique ID issued by the MyBB Mods site for version checking
	 * compatibility: A CSV list of MyBB versions supported. Ex, "121,123", "12*". Wildcards supported.
	 */
	return array(
		"name"			=> "UI Overhaul",
		"description"	=> "Will completely alter the user interface of the index page.",
		"website"		=> "http://www.thedrp.org/",
		"author"		=> "Nicholas Roge",
		"authorsite"	=> "http://www.thedrp.org/",
		"version"		=> "1.0",
		"guid" 			=> "",
		"compatibility" => "*"
	);
}

function test()
{
	global $lang, $logoutlink, $loginform, $mybb, $templates, $db, $cache, $plugins, $user, $forumsread, $forums, $forum_list, $whosonline, $timesearch, $comma, $query, $forum_viewers, $membercount, $onlinemembers, $guestcount, $anoncount, $doneusers, $spiders, $botkey, $doneusers, $invisiblemark, $onlinebit, $memberbit, $anonbit, $guestbit, $bdays, $birthdays, $bdaycount, $bdayhidden, $bdaytime, $bdaydate, $year, $bdaycache, $hiddencount, $today_bdays, $bdayuser, $bday, $age, $stats, $newestmember, $mostonline, $time, $recordcount, $recorddate, $recordtime, $forumstats, $boardstats, $forumsread, $fcache, $moderatorcache, $excols, $permissioncache, $bgcolor, $showdepth, $index;
	
	// Load global language phrases
	$lang->load("index");
	
	$logoutlink = $loginform = '';
	if($mybb->user['uid'] != 0)
	{
		eval("\$logoutlink = \"".$templates->get("index_logoutlink")."\";");
	}
	else
	{
		//Checks to make sure the user can login; they haven't had too many tries at logging in.
		//Function call is not fatal
		if(login_attempt_check(false) !== false)
		{
			eval("\$loginform = \"".$templates->get("index_loginform")."\";");
		}
	}
	$whosonline = '';
	if($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0)
	{
		// Get the online users.
		$timesearch = TIME_NOW - $mybb->settings['wolcutoff'];
		$comma = '';
		$query = $db->query("
			SELECT s.sid, s.ip, s.uid, s.time, s.location, s.location1, u.username, u.invisible, u.usergroup, u.displaygroup
			FROM ".TABLE_PREFIX."sessions s
			LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
			WHERE s.time>'$timesearch'
			ORDER BY u.username ASC, s.time DESC
		");
	
		$forum_viewers = array();
		$membercount = 0;
		$onlinemembers = '';
		$guestcount = 0;
		$anoncount = 0;
		$doneusers = array();
	
		// Fetch spiders
		$spiders = $cache->read("spiders");
	
		// Loop through all users.
		while($user = $db->fetch_array($query))
		{
			// Create a key to test if this user is a search bot.
			$botkey = my_strtolower(str_replace("bot=", '', $user['sid']));
	
			// Decide what type of user we are dealing with.
			if($user['uid'] > 0)
			{
				// The user is registered.
				if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']])
				{
					// If the user is logged in anonymously, update the count for that.
					if($user['invisible'] == 1)
					{
						++$anoncount;
					}
					++$membercount;
					if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
					{
						// If this usergroup can see anonymously logged-in users, mark them.
						if($user['invisible'] == 1)
						{
							$invisiblemark = "*";
						}
						else
						{
							$invisiblemark = '';
						}
	
						// Properly format the username and assign the template.
						$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
						$user['profilelink'] = build_profile_link($user['username'], $user['uid']);
						eval("\$onlinemembers .= \"".$templates->get("index_whosonline_memberbit", 1, 0)."\";");
						$comma = ", ";
					}
					// This user has been handled.
					$doneusers[$user['uid']] = $user['time'];
				}
			}
			elseif(my_strpos($user['sid'], "bot=") !== false && $spiders[$botkey])
			{
				// The user is a search bot.
				$onlinemembers .= $comma.format_name($spiders[$botkey]['name'], $spiders[$botkey]['usergroup']);
				$comma = ", ";
				++$botcount;
			}
			else
			{
				// The user is a guest.
				++$guestcount;
			}
	
			if($user['location1'])
			{
				$forum_viewers[$user['location1']]++;
			}
		}
	
		// Build the who's online bit on the index page.
		$onlinecount = $membercount + $guestcount + $botcount;
		
		if($onlinecount != 1)
		{
			$onlinebit = $lang->online_online_plural;
		}
		else
		{
			$onlinebit = $lang->online_online_singular;
		}
		if($membercount != 1)
		{
			$memberbit = $lang->online_member_plural;
		}
		else
		{
			$memberbit = $lang->online_member_singular;
		}
		if($anoncount != 1)
		{
			$anonbit = $lang->online_anon_plural;
		}
		else
		{
			$anonbit = $lang->online_anon_singular;
		}
		if($guestcount != 1)
		{
			$guestbit = $lang->online_guest_plural;
		}
		else
		{
			$guestbit = $lang->online_guest_singular;
		}
		$lang->online_note = $lang->sprintf($lang->online_note, my_number_format($onlinecount), $onlinebit, $mybb->settings['wolcutoffmins'], my_number_format($membercount), $memberbit, my_number_format($anoncount), $anonbit, my_number_format($guestcount), $guestbit);
		eval("\$whosonline = \"".$templates->get("index_whosonline")."\";");
	}
	
	// Build the birthdays for to show on the index page.
	$bdays = $birthdays = '';
	if($mybb->settings['showbirthdays'] != 0)
	{
		// First, see what day this is.
		$bdaycount = 0; $bdayhidden = 0;
		$bdaytime = TIME_NOW;
		$bdaydate = my_date("j-n", $bdaytime, '', 0);
		$year = my_date("Y", $bdaytime, '', 0);
		
		$bdaycache = $cache->read("birthdays");
		
		if(!is_array($bdaycache))
		{
			$cache->update_birthdays();
			$bdaycache = $cache->read("birthdays");
		}
		
		$hiddencount = $bdaycache[$bdaydate]['hiddencount'];
		$today_bdays = $bdaycache[$bdaydate]['users'];
		
		$comma = '';
		if(!empty($today_bdays))
		{
			foreach($today_bdays as $bdayuser)
			{
				$bday = explode("-", $bdayuser['birthday']);
				if($year > $bday['2'] && $bday['2'] != '')
				{
					$age = " (".($year - $bday['2']).")";
				}
				else
				{
					$age = '';
				}
				$bdayuser['username'] = format_name($bdayuser['username'], $bdayuser['usergroup'], $bdayuser['displaygroup']);
				$bdayuser['profilelink'] = build_profile_link($bdayuser['username'], $bdayuser['uid']);
				eval("\$bdays .= \"".$templates->get("index_birthdays_birthday", 1, 0)."\";");
				++$bdaycount;
				$comma = ", ";
			}
		}
		
		if($hiddencount > 0)
		{
			if($bdaycount > 0)
			{
				$bdays .= " - ";
			}
			$bdays .= "{$hiddencount} {$lang->birthdayhidden}";
		}
		
		// If there are one or more birthdays, show them.
		if($bdaycount > 0 || $hiddencount > 0)
		{
			eval("\$birthdays = \"".$templates->get("index_birthdays")."\";");
		}
	}
	
	// Build the forum statistics to show on the index page.
	if($mybb->settings['showindexstats'] != 0)
	{
		// First, load the stats cache.
		$stats = $cache->read("stats");
	
		// Check who's the newest member.
		if(!$stats['lastusername'])
		{
			$newestmember = "no-one";
		}
		else
		{
			$newestmember = build_profile_link($stats['lastusername'], $stats['lastuid']);
		}
	
		// Format the stats language.
		$lang->stats_posts_threads = $lang->sprintf($lang->stats_posts_threads, my_number_format($stats['numposts']), my_number_format($stats['numthreads']));
		$lang->stats_numusers = $lang->sprintf($lang->stats_numusers, my_number_format($stats['numusers']));
		$lang->stats_newestuser = $lang->sprintf($lang->stats_newestuser, $newestmember);
	
		// Find out what the highest users online count is.
		$mostonline = $cache->read("mostonline");
		if($onlinecount > $mostonline['numusers'])
		{
			$time = TIME_NOW;
			$mostonline['numusers'] = $onlinecount;
			$mostonline['time'] = $time;
			$cache->update("mostonline", $mostonline);
		}
		$recordcount = $mostonline['numusers'];
		$recorddate = my_date($mybb->settings['dateformat'], $mostonline['time']);
		$recordtime = my_date($mybb->settings['timeformat'], $mostonline['time']);
	
		// Then format that language string.
		$lang->stats_mostonline = $lang->sprintf($lang->stats_mostonline, my_number_format($recordcount), $recorddate, $recordtime);
	
		eval("\$forumstats = \"".$templates->get("index_stats")."\";");
	}
	
	// Show the board statistics table only if one or more index statistics are enabled.
	if($mybb->settings['showwol'] != 0 || $mybb->settings['showindexstats'] != 0 || ($mybb->settings['showbirthdays'] != 0 && $bdaycount > 0))
	{
		if(!is_array($stats))
		{
			// Load the stats cache.
			$stats = $cache->read("stats");
		}
		
		eval("\$boardstats = \"".$templates->get("index_boardstats")."\";");
	}
	
	if($mybb->user['uid'] == 0)
	{
		// Build a forum cache.
		$query = $db->query("
			SELECT *
			FROM ".TABLE_PREFIX."forums
			WHERE active != 0
			ORDER BY pid, disporder
		");
		
		$forumsread = unserialize($mybb->cookies['mybb']['forumread']);
	}
	else
	{
		// Build a forum cache.
		$query = $db->query("
			SELECT f.*, fr.dateline AS lastread
			FROM ".TABLE_PREFIX."forums f
			LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
			WHERE f.active != 0
			ORDER BY pid, disporder
		");
	}
	while($forum = $db->fetch_array($query))
	{
		if($mybb->user['uid'] == 0)
		{
			if($forumsread[$forum['fid']])
			{
				$forum['lastread'] = $forumsread[$forum['fid']];
			}
		}
		$fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
	}
	$forumpermissions = forum_permissions();
	
	// Get the forum moderators if the setting is enabled.
	if($mybb->settings['modlist'] != "off")
	{	
		$moderatorcache = $cache->read("moderators");
	}
	
	$excols = "index";
	$permissioncache['-1'] = "1";
	$bgcolor = "trow1";
	
	// Decide if we're showing first-level subforums on the index page.
	if($mybb->settings['subforumsindex'] != 0)
	{
		$showdepth = 3;
	}
	else
	{
		$showdepth = 2;
	}
	$forum_list = build_forumbits();
	$forums = $forum_list['forum_list'];
	
	$plugins->run_hooks("index_end");
	
	eval("\$index = \"".$templates->get("index")."\";");
	output_page($index);
	
	exit;
}
?>

There must be something I'm not understand as to why it won't display correctly. By the way, I added that exit at the end to stop it from executing the rest of the index.php script after the index_start hook.
I don't see any theme elements in the global; $theme and $stylesheets would be a good start - $headerinclude and $footer would be needed too.
Thank you! That was the problem.
Mhmm.. May I ask: What is this for?

Thank you.
Well, instead of listing the each of the boards, I was going to put the boards in a tabbed format. For example (using mybboard's board), in stead of:
|---------------------------------------------------------|
|Anouncements                                             |
|---------------------------------------------------------|
|Subforums                                                |
|---------------------------------------------------------|

|---------------------------------------------------------|
|MyBB 1.4 Series                                          |
|---------------------------------------------------------|
|Subforums                                                |
|---------------------------------------------------------|

etc...

you would have something like:

|---------------------------------------------------------|
||Announcement||MyBB 1.4 Series||etc...|                  |
|---------------------------------------------------------|
|Subforums                                                |
|---------------------------------------------------------|
Ahh Great!
Will you release it to the public?
I don't see why not.
Great. I think I'll use it! Big Grin