Adding this to /lib/functions.lib.php at the very bottom
- Code: Select all
function updateCheck()
{
global $addon;
global $roster;
$return = '';
//$updateCheck = Array ( 0 = WowRosterID, 1 = Update time, 2 = Version Retrieved)
$updateCheck = unserialize($addon['config']['updateCheck']);
$updateFrequency = 60*60*12; //12 Hours.
$updateTime = time() - ($updateCheck['1'] + $updateFrequency);
$wrnet_download_id = $updateCheck['0'];
$file_ver_latest = '';
if ($updateTime > 0)
{ // Check wowroster.net for versioning
$sh = @fsockopen('wowroster.net', 80, $errno, $error, 5);
if ( $sh )
{
@fputs($sh, "GET /rss/downloads.php?id=$wrnet_download_id HTTP/1.1\r\nHost: wowroster.net\r\nConnection: close\r\n\r\n");
while ( !@feof($sh) )
{
$content = @fgets($sh, 512);
if ( preg_match('#<version>(.+)</version>#i',$content,$version) )
{
$file_ver_latest = $version[1];
break;
}
}
}
@fclose($sh);
$updateCheck['1'] = time();
$updateCheck['2'] = $file_ver_latest;
$updateCheck = serialize ($updateCheck);
$roster->db->query ( "UPDATE `{$roster->db->prefix}addon_config` SET `config_value` = '{$updateCheck}' WHERE `addon_id` = '{$addon['addon_id']}' AND `config_name` = 'updateCheck' ");
}else{
$file_ver_latest = $updateCheck['2'];
}
if( $file_ver_latest == '' )
{
$return .= messagebox('Could not check version information','Version Check', 'sred');
}
elseif( version_compare($file_ver_latest, $addon['version'],'>') == true )
{
$return .= messagebox('There is a new version available! v' . $file_ver_latest . '; Current version v' .
$addon['version'],'Version Check','sgreen');
}
elseif( version_compare($file_ver_latest, $addon['version'],'<') == true )
{
$return .= messagebox('You are using a newer version then available. Use at your own risk.<br />
Using v' . $addon['version'] . '; Current v' . $file_ver_latest, 'Version Check','syellow');
}
return $return;
}
Then to call it, I put this in my topBox() in my addonname/admin/config.func.php .
- Code: Select all
$return .= updateCheck();
return $return;
The only catch to the whole thing, is it stores the value as a config option, so I added this to my addonname/inc/install.def.php; You can use any number for the menu option and the 117 is the download ID. This uses a serialized array to save it all, but doesnt show it in the rostercp.
- Code: Select all
$installer->add_config("'200','updateCheck','a:3:{i:0;i:117;i:1;i:0;i:2;s:9:\"0\";}','display','hidden_menu'");
Hopefully, this can all be added to roster to make life easier for all the addon developers.