Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->version_check, "index.php?module=home-version_check");
$plugins->run_hooks("admin_home_version_check_begin");
if(!$mybb->input['action'])
{
	$plugins->run_hooks("admin_home_version_check_start");
	
	$page->output_header($lang->version_check);
	
	$sub_tabs['version_check'] = array(
		'title' => $lang->version_check,
		'link' => "index.php?module=home-version_check",
		'description' => $lang->version_check_description
	);
	
	$sub_tabs['download_mybb'] = array(
		'title' => $lang->dl_the_latest_mybb,
		'link' => "http://mybb.com/downloads",
		'link_target' => '_blank'
	);
	
	$sub_tabs['check_plugins'] = array(
		'title' => $lang->check_plugin_versions,
		'link' => "index.php?module=config-plugins&action=check",
	);
	
	$page->output_nav_tabs($sub_tabs, 'version_check');	
	
	$current_version = rawurlencode($mybb->version_code);
	$updated_cache = array(
		"last_check" => TIME_NOW
	);
	require_once MYBB_ROOT."inc/class_xml.php";
	$contents = fetch_remote_file("http://www.mybb.com/version_check.php");
	if(!$contents)
	{
		$page->output_inline_error($lang->error_communication);
		$page->output_footer();
		exit;
	}
	
	// We do this because there is some weird symbols that show up in the xml file for unknown reasons
	$pos = strpos($contents, "<");
	if($pos > 1)
	{
		$contents = substr($contents, $pos);
	}
	
	$pos = strpos(strrev($contents), ">");
	if($pos > 1)
	{
		$contents = substr($contents, 0, (-1) * ($pos-1));
	}
	$parser = new XMLParser($contents);
	$tree = $parser->get_tree();
	if(!is_array($tree) || !isset($tree['mybb']))
	{
		$page->output_inline_error($lang->error_communication);
		$page->output_footer();
		exit;
	}
	$latest_code = $tree['mybb']['version_code']['value'];
	$latest_version = "".$tree['mybb']['latest_version']['value']." (".$latest_code.")";
	if($latest_code > $mybb->version_code)
	{
		$latest_version = "".$latest_version."";
		$version_warn = 1;
		$updated_cache['latest_version'] = $latest_version;
		$updated_cache['latest_version_code'] = $latest_code;
	}
	else
	{
		$version_warn = 0;
		$latest_version = "".$latest_version."";
	}
	
	$cache->update("update_check", $updated_cache);
	require_once MYBB_ROOT."inc/class_feedparser.php";
	$feed_parser = new FeedParser();
	$feed_parser->parse_feed("http://feeds.feedburner.com/MyBBDevelopmentBlog");
	
	$table = new Table;
	$table->construct_header($lang->your_version);
	$table->construct_header($lang->latest_version);
	
	$table->construct_cell("".$mybb->version." (".$mybb->version_code.")");
	$table->construct_cell($latest_version);
	$table->construct_row();
	
	$table->output($lang->version_check);
	
	if($version_warn)
	{
		$page->output_error("{$lang->error_out_of_date} {$lang->update_forum}
");
	}
	else
	{
		$page->output_success("{$lang->success_up_to_date}
");
	}
	
	if($feed_parser->error == '')
	{
		foreach($feed_parser->items as $item)
		{
			if($item['date_timestamp'])
			{
				$stamp = my_date($mybb->settings['dateformat'], $item['date_timestamp']).", ".my_date($mybb->settings['timeformat'], $item['date_timestamp']);
			}
			else
			{
				$stamp = '';
			}
			if($item['content'])
			{
				$content = $item['content'];
			}
			else
			{
				$content = $item['description'];
			}
			$table->construct_cell("".$item['title']."
{$content}{$stamp}
» {$lang->read_more}");
			$table->construct_row();
		}
	}
	else
	{
		$table->construct_cell("{$lang->error_fetch_news} ");
		$table->construct_row();
	}
	
	$table->output($lang->latest_mybb_announcements);
	
	$page->output_footer();
}
?>