Please make sure IN_MYBB is defined.");
}
$plugins->run_hooks("admin_home_index_begin");
$sub_tabs['dashboard'] = array(
'title' => $lang->dashboard,
'link' => "index.php",
'description' => $lang->dashboard_description
);
$sub_tabs['version_check'] = array(
'title' => $lang->version_check,
'link' => "index.php?module=home&action=version_check",
'description' => $lang->version_check_description
);
if($mybb->input['action'] == "version_check")
{
$plugins->run_hooks("admin_home_version_check_start");
$current_version = rawurlencode($mybb->version_code);
$updated_cache = array(
"last_check" => TIME_NOW
);
$contents = fetch_remote_file("https://mybb.com/version_check.php");
if(!$contents)
{
flash_message($lang->error_communication, 'error');
admin_redirect('index.php');
}
$plugins->run_hooks("admin_home_version_check");
$page->add_breadcrumb_item($lang->version_check, "index.php?module=home-version_check");
$page->output_header($lang->version_check);
$page->output_nav_tabs($sub_tabs, 'version_check');
$contents = trim($contents);
$parser = create_xml_parser($contents);
$tree = $parser->get_tree();
$latest_code = (int)$tree['mybb']['version_code']['value'];
$latest_version = "".htmlspecialchars_uni($tree['mybb']['latest_version']['value'])." (".$latest_code.")";
if($latest_code > $mybb->version_code)
{
$latest_version = "".$latest_version."";
$updated_cache['latest_version'] = $latest_version;
$updated_cache['latest_version_code'] = $latest_code;
$page->output_error("{$lang->error_out_of_date} {$lang->update_forum}
");
}
else
{
$latest_version = "".$latest_version."";
$page->output_success("{$lang->success_up_to_date}
");
}
$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);
require_once MYBB_ROOT."inc/class_feedparser.php";
$feed_parser = new FeedParser();
$feed_parser->parse_feed("http://feeds.feedburner.com/MyBBDevelopmentBlog");
$updated_cache['news'] = array();
if($feed_parser->error == '')
{
require_once MYBB_ROOT . '/inc/class_parser.php';
$post_parser = new postParser();
foreach($feed_parser->items as $item)
{
if(!isset($updated_cache['news'][2]))
{
$updated_cache['news'][] = array(
'title' => $item['title'],
'description' => $item['description'],
'link' => $item['link'],
'author' => $item['author'],
'dateline' => $item['date_timestamp'],
);
}
$stamp = '';
if($item['date_timestamp'])
{
$stamp = my_date('relative', (int)$item['date_timestamp']);
}
$link = htmlspecialchars_uni($item['link']);
$title = htmlspecialchars_uni($item['title']);
$description = htmlspecialchars_uni(strip_tags($item['description']));
$table->construct_cell("{$title}
{$description}{$stamp}
» {$lang->read_more}");
$table->construct_row();
}
}
else
{
$table->construct_cell("{$lang->error_fetch_news} ");
$table->construct_row();
}
$cache->update("update_check", $updated_cache);
$table->output($lang->latest_mybb_announcements);
$page->output_footer();
}
elseif(!$mybb->input['action'])
{
$plugins->run_hooks("admin_home_index_start");
if($mybb->request_method == "post" && isset($mybb->input['adminnotes']))
{
// Update Admin Notes cache
$update_cache = array(
"adminmessage" => $mybb->input['adminnotes']
);
$cache->update("adminnotes", $update_cache);
$plugins->run_hooks("admin_home_index_start_begin");
flash_message($lang->success_notes_updated, 'success');
admin_redirect("index.php");
}
$page->add_breadcrumb_item($lang->dashboard);
$page->output_header($lang->dashboard);
$sub_tabs['dashboard'] = array(
'title' => $lang->dashboard,
'link' => "index.php",
'description' => $lang->dashboard_description
);
$page->output_nav_tabs($sub_tabs, 'dashboard');
// Load stats cache
$stats = $cache->read("stats");
$serverload = get_server_load();
// Get the number of users
$query = $db->simple_select("users", "COUNT(uid) AS numusers");
$users = my_number_format($db->fetch_field($query, "numusers"));
// Get the number of users awaiting validation
$awaitingusers = $cache->read('awaitingactivation');
if(!empty($awaitingusers['users']))
{
$awaitingusers = (int)$awaitingusers['users'];
}
else
{
$awaitingusers = 0;
}
if($awaitingusers < 1)
{
$awaitingusers = 0;
}
else
{
$awaitingusers = my_number_format($awaitingusers);
}
// Get the number of new users for today
$timecut = TIME_NOW - 86400;
$query = $db->simple_select("users", "COUNT(uid) AS newusers", "regdate > '$timecut'");
$newusers = my_number_format($db->fetch_field($query, "newusers"));
// Get the number of active users today
$query = $db->simple_select("users", "COUNT(uid) AS activeusers", "lastvisit > '$timecut'");
$activeusers = my_number_format($db->fetch_field($query, "activeusers"));
// Get the number of threads
$threads = my_number_format($stats['numthreads']);
// Get the number of unapproved threads
$unapproved_threads = my_number_format($stats['numunapprovedthreads']);
// Get the number of new threads for today
$query = $db->simple_select("threads", "COUNT(*) AS newthreads", "dateline > '$timecut' AND visible='1' AND closed NOT LIKE 'moved|%'");
$newthreads = my_number_format($db->fetch_field($query, "newthreads"));
// Get the number of posts
$posts = my_number_format($stats['numposts']);
// Get the number of unapproved posts
if($stats['numunapprovedposts'] < 0)
{
$stats['numunapprovedposts'] = 0;
}
$unapproved_posts = my_number_format($stats['numunapprovedposts']);
// Get the number of new posts for today
$query = $db->simple_select("posts", "COUNT(*) AS newposts", "dateline > '$timecut' AND visible='1'");
$newposts = my_number_format($db->fetch_field($query, "newposts"));
// Get the number of reported post
$query = $db->simple_select("reportedcontent", "COUNT(*) AS reported_posts", "type = 'post' OR type = ''");
$reported_posts = my_number_format($db->fetch_field($query, "reported_posts"));
// Get the number of reported posts that haven't been marked as read yet
$query = $db->simple_select("reportedcontent", "COUNT(*) AS new_reported_posts", "reportstatus='0' AND (type = 'post' OR type = '')");
$new_reported_posts = my_number_format($db->fetch_field($query, "new_reported_posts"));
// Get the number and total file size of attachments
$query = $db->simple_select("attachments", "COUNT(*) AS numattachs, SUM(filesize) as spaceused", "visible='1' AND pid > '0'");
$attachs = $db->fetch_array($query);
$attachs['spaceused'] = get_friendly_size($attachs['spaceused']);
$approved_attachs = my_number_format($attachs['numattachs']);
// Get the number of unapproved attachments
$query = $db->simple_select("attachments", "COUNT(*) AS numattachs", "visible='0' AND pid > '0'");
$unapproved_attachs = my_number_format($db->fetch_field($query, "numattachs"));
// Fetch the last time an update check was run
$update_check = $cache->read("update_check");
// If last update check was greater than two weeks ago (14 days) show an alert
if(isset($update_check['last_check']) && $update_check['last_check'] <= TIME_NOW-60*60*24*14)
{
$lang->last_update_check_two_weeks = $lang->sprintf($lang->last_update_check_two_weeks, "index.php?module=home&action=version_check");
$page->output_error("{$lang->last_update_check_two_weeks}
");
}
// If the update check contains information about a newer version, show an alert
if(isset($update_check['latest_version_code']) && $update_check['latest_version_code'] > $mybb->version_code)
{
$lang->new_version_available = $lang->sprintf($lang->new_version_available, "MyBB {$mybb->version}", "MyBB {$update_check['latest_version']}");
$page->output_error("{$lang->new_version_available}
");
}
$plugins->run_hooks("admin_home_index_output_message");
$adminmessage = $cache->read("adminnotes");
if($adminmessage === false)
{
$adminmessage = array(
'adminmessage' => '',
);
}
$table = new Table;
$table->construct_header($lang->mybb_server_stats, array("colspan" => 2));
$table->construct_header($lang->forum_stats, array("colspan" => 2));
$table->construct_cell("{$lang->mybb_version}", array('width' => '25%'));
$table->construct_cell($mybb->version, array('width' => '25%'));
$table->construct_cell("{$lang->threads}", array('width' => '25%'));
$table->construct_cell("{$threads} {$lang->threads}
{$newthreads} {$lang->new_today}
{$unapproved_threads} {$lang->unapproved}", array('width' => '25%'));
$table->construct_row();
$table->construct_cell("{$lang->php_version}", array('width' => '25%'));
$table->construct_cell(PHP_VERSION, array('width' => '25%'));
$table->construct_cell("{$lang->posts}", array('width' => '25%'));
$table->construct_cell("{$posts} {$lang->posts}
{$newposts} {$lang->new_today}
{$unapproved_posts} {$lang->unapproved}
{$reported_posts} {$lang->reported_posts}
{$new_reported_posts} {$lang->unread_reports}", array('width' => '25%'));
$table->construct_row();
$table->construct_cell("{$lang->sql_engine}", array('width' => '25%'));
$table->construct_cell($db->short_title." ".$db->get_version(), array('width' => '25%'));
$table->construct_cell("{$lang->users}", array('width' => '25%'));
$table->construct_cell("{$users} {$lang->registered_users}
{$activeusers} {$lang->active_users}
{$newusers} {$lang->registrations_today}
{$awaitingusers} {$lang->awaiting_activation}", array('width' => '25%'));
$table->construct_row();
$table->construct_cell("{$lang->server_load}", array('width' => '25%'));
$table->construct_cell($serverload, array('width' => '25%'));
$table->construct_cell("{$lang->attachments}", array('width' => '25%'));
$table->construct_cell("{$approved_attachs} {$lang->attachments}
{$unapproved_attachs} {$lang->unapproved}
{$attachs['spaceused']} {$lang->used}", array('width' => '25%'));
$table->construct_row();
$table->output($lang->dashboard);
echo '
';
$table = new Table;
$table->construct_header($lang->admin_notes_public);
$form = new Form("index.php", "post");
$table->construct_cell($form->generate_text_area("adminnotes", $adminmessage['adminmessage'], array('style' => 'width: 99%; height: 200px;')));
$table->construct_row();
$table->output($lang->admin_notes);
$buttons[] = $form->generate_submit_button($lang->save_notes);
$form->output_submit_wrapper($buttons);
$form->end();
echo '
';
// Latest news widget
$table = new Table;
$table->construct_header($lang->news_description);
if(!empty($update_check['news']) && is_array($update_check['news']))
{
foreach($update_check['news'] as $news_item)
{
$posted = my_date('relative', (int)$news_item['dateline']);
$link = htmlspecialchars_uni($news_item['link']);
$title = htmlspecialchars_uni($news_item['title']);
$description = htmlspecialchars_uni(strip_tags($news_item['description']));
$table->construct_cell("
{$title}{$posted}");
$table->construct_row();
$table->construct_cell($description);
$table->construct_row();
}
}
else
{
$table->construct_cell($lang->no_announcements);
$table->construct_row();
}
$table->output($lang->latest_mybb_announcements);
echo '
';
$page->output_footer();
}