How does MyBB check plugin versions?
#1
Ok, so MyBB's ACP can check if any of your plugins are out of date. How does it "talk" to mods.mybb.com? I assume its GUID based? Any clues?
Reply
#2
This user has been denied support. This user has been denied support.
Yes, its GUID and it identifies the plugin with GUID and caches its latest version from the mods.mybb.com Smile
Reply
#3
I think it sends off the GUIDs of the plugins you have, gets the versions for those plugins, and then loops through and checks them.
MyReactions - All Plugins

Can you still feel the butterflies?

Free never tasted like pudding.
Reply
#4
(2011-10-04, 06:41 PM)MattRogowski Wrote: I think it sends off the GUIDs of the plugins you have, gets the versions for those plugins, and then loops through and checks them.

This is pretty much correct.

Relevant Code:
if($mybb->input['action'] == "check")
{	
	$plugins_list = get_plugins_list();
	
	$plugins->run_hooks("admin_config_plugins_check");
	
	$info = array();
	
	if($plugins_list)
	{
		$active_hooks = $plugins->hooks;
		foreach($plugins_list as $plugin_file)
		{
			require_once MYBB_ROOT."inc/plugins/".$plugin_file;
			$codename = str_replace(".php", "", $plugin_file);
			$infofunc = $codename."_info";
			if(!function_exists($infofunc))
			{
				continue;
			}
			$plugininfo = $infofunc();
			$plugininfo['guid'] = trim($plugininfo['guid']);
			
			if($plugininfo['guid'] != "")
			{
				$info[] = $plugininfo['guid'];
				$names[$plugininfo['guid']] = array('name' => $plugininfo['name'], 'version' => $plugininfo['version']);
			}
		}
		$plugins->hooks = $active_hooks;
	}
	
	if(empty($info))
	{
		flash_message($lang->error_vcheck_no_supported_plugins, 'error');
		admin_redirect("index.php?module=config-plugins");
	}
	
	$url = "http://mods.mybb.com/version_check.php?";
	foreach($info as $guid)
	{
		$url .= "info[]=".urlencode($guid)."&";
	}
	$url = substr($url, 0, -1);
	
	require_once MYBB_ROOT."inc/class_xml.php";
	$contents = fetch_remote_file($url);
	
	if(!$contents)
	{
		flash_message($lang->error_vcheck_communications_problem, 'error');
		admin_redirect("index.php?module=config-plugins");
	}
	
	$parser = new XMLParser($contents);
	$tree = $parser->get_tree();
	
	if(array_key_exists('error', $tree['plugins']))
	{
		switch($tree['plugins'][0]['error'])
		{
			case "1":
				$error_msg = $lang->error_no_input;
				break;
			case "2":
				$error_msg = $lang->error_no_pids;
				break;
			default:
				$error_msg = "";
		}
		
		flash_message($lang->error_communication_problem.$error_msg, 'error');
		admin_redirect("index.php?module=config-plugins");
	}
	
	$table = new Table;
	$table->construct_header($lang->plugin);
	$table->construct_header($lang->your_version, array("class" => "align_center", 'width' => 125));
	$table->construct_header($lang->latest_version, array("class" => "align_center", 'width' => 125));
	$table->construct_header($lang->controls, array("class" => "align_center", 'width' => 125));
	
	if(!is_array($tree['plugins']['plugin']))
	{
		flash_message($lang->success_plugins_up_to_date, 'success');
		admin_redirect("index.php?module=config-plugins");
	}
	
	if(array_key_exists("tag", $tree['plugins']['plugin']))
	{
		$only_plugin = $tree['plugins']['plugin'];
		unset($tree['plugins']['plugin']);
		$tree['plugins']['plugin'][0] = $only_plugin;
	}
	
	foreach($tree['plugins']['plugin'] as $plugin)
	{
		if(version_compare($names[$plugin['attributes']['guid']]['version'], $plugin['version']['value'], "<"))
		{
			$table->construct_cell("<strong>{$names[$plugin['attributes']['guid']]['name']}</strong>");
			$table->construct_cell("{$names[$plugin['attributes']['guid']]['version']}", array("class" => "align_center"));
			$table->construct_cell("<strong><span style=\"color: #C00\">{$plugin['version']['value']}</span></strong>", array("class" => "align_center"));
			$table->construct_cell("<strong><a href=\"http://mods.mybb.com/view/{$plugin['download_url']['value']}\" target=\"_blank\">{$lang->download}</a></strong>", array("class" => "align_center"));
			$table->construct_row();
		}
	}
	
	if($table->num_rows() == 0)
	{
		flash_message($lang->success_plugins_up_to_date, 'success');
		admin_redirect("index.php?module=config-plugins");
	}
	
	$page->add_breadcrumb_item($lang->plugin_updates);
	
	$page->output_header($lang->plugin_updates);
	
	$sub_tabs['plugins'] = array(
		'title' => $lang->plugins,
		'link' => "index.php?module=config-plugins",
	);
	
	$sub_tabs['update_plugins'] = array(
		'title' => $lang->plugin_updates,
		'link' => "index.php?module=config-plugins&amp;action=check",
		'description' => $lang->plugin_updates_desc
	);
	
	$sub_tabs['browse_plugins'] = array(
		'title' => $lang->browse_plugins,
		'link' => "index.php?module=config-plugins&amp;action=browse",
		'description' => $lang->browse_plugins_desc
	);
	
	$page->output_nav_tabs($sub_tabs, 'update_plugins');
	
	$table->output($lang->plugin_updates);
	
	$page->output_footer();
}
Reply
#5
This user has been denied support. This user has been denied support.
Cool, requires pretty much code.
Reply
#6
This is what I was looking for:
http://mods.mybb.com/version_check.php?guid=x

Smile thanks
Reply
#7
Be aware that this block of code will be greatly changed in one of the upcoming releases when I have the time to finish out this ticket: [issue]1544[/issues] which will greatly help Plugin Authors who release on their own sites have users kept up to date.
Reply
#8
Yeah, I'm making a new MyBB service that alerts new users by email to when new plugin versions are out Smile so it'd be nice if I could check external author plugins too Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)