Update Check

Posts from previous Beta sessions

Update Check

Postby boyo » Mon Oct 15, 2007 4:56 pm

With needing a way to check if the script is running the most current version, I borrowed most of this from Zanix and made it to where it's built into roster.

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$error5);
        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($sh512);
                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.
boyo
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 103
Joined: Wed Jan 24, 2007 7:37 am

Update Check

Postby zanix » Mon Oct 15, 2007 10:17 pm

Yes, I plan to add this...someday
Read the Forum Rules, the WiKi, and Search before posting!
WoWRoster v2.1 - SigGen v0.3.3.523 - WoWRosterDF
User avatar
zanix
Admin
Admin
WoWRoster.net Dev Team
WoWRoster.net Dev Team
UA/UU Developer
UA/UU Developer
 
Posts: 5546
Joined: Mon Jul 03, 2006 8:29 am
Location: Idaho Falls, Idaho
Realm: Doomhammer (PvE) - US

Update Check

Postby zanix » Sun Oct 21, 2007 7:31 am

Added svn[1407]
Read the Forum Rules, the WiKi, and Search before posting!
WoWRoster v2.1 - SigGen v0.3.3.523 - WoWRosterDF
User avatar
zanix
Admin
Admin
WoWRoster.net Dev Team
WoWRoster.net Dev Team
UA/UU Developer
UA/UU Developer
 
Posts: 5546
Joined: Mon Jul 03, 2006 8:29 am
Location: Idaho Falls, Idaho
Realm: Doomhammer (PvE) - US

Update Check

Postby boyo » Sun Oct 21, 2007 1:57 pm

Looks awesome, and I thought that it had to be manually called from the addon but was incorrect, it will show on the main cp page and manage addons page i noticed when installing.

Just by setting the var $wrnet_id = '###'; it works perfect.

I did notice one small bug in the link though, the link is coming out as " http://localhost/roster20/ <br />http://www.wowroster.net/ "

At first I thought it was because I didn't have the homepage set on my download, so I set it, and it's still not working correctly.

Here is a screenshot hovering over HERE
Image

Edit: Oh and I just noticed the release date in that screenshot is wrong too.
Last edited by boyo on Sun Oct 21, 2007 2:05 pm, edited 1 time in total.
boyo
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 103
Joined: Wed Jan 24, 2007 7:37 am

Update Check

Postby zanix » Sun Oct 21, 2007 2:12 pm

Oh, nice catches
I didn't exactly test this but I wasn't gonna have it released before it was tested

There are three <link> in the rss feed, one for the site url, one for the main image link, and one for the addon url
The preg_match had to be adjusted to account for this

Fixed svn[1409]
Read the Forum Rules, the WiKi, and Search before posting!
WoWRoster v2.1 - SigGen v0.3.3.523 - WoWRosterDF
User avatar
zanix
Admin
Admin
WoWRoster.net Dev Team
WoWRoster.net Dev Team
UA/UU Developer
UA/UU Developer
 
Posts: 5546
Joined: Mon Jul 03, 2006 8:29 am
Location: Idaho Falls, Idaho
Realm: Doomhammer (PvE) - US

Update Check

Postby boyo » Sun Oct 21, 2007 2:17 pm

Ok, here is what the RSS returns..

It looks like it's pulling the first <link></link> in the function, which would explain partially the above problem.

Also function is checking for <info></info>. I don't see that anywhere in the feed; is it supposed to be <description></description> ?

Does <pubDate></pubDate> change when updates are uploaded, or does that stay permanent? Which would explain why <updated></updated> is used instead. I did notice for <updated></updated> that it uses a unix timestamp instead of the format that is in <pubDate></pubDate>

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
   <title>WoWRoster.net</title>
   <link>http://www.wowroster.net/</link>
   <description>WoWRoster.net</description>
   <language>en-us</language>
   <pubDate>Sat, 13 Oct 2007 23:48:05 GMT</pubDate>
   <ttl>1440</ttl>
   <generator>CPG-Nuke Dragonfly</generator>
   <copyright>WoWRoster.net</copyright>
   <category>Downloads</category>
   <docs>http://backend.userland.com/rss</docs>
   <image>
      <url>http://www.wowroster.net/images/logo.jpg</url>
      <title>WoWRoster.net</title>
      <link>http://www.wowroster.net/</link>
   </image>

   <item>
      <title>SMFSync</title>
      <version>1.9.9.271</version>
      <link>http://www.wowroster.net/Downloads/details/id=117.html</link>
      <description>SMFSync will allow you to synchronize your members with your SMF forum.</description>
      <pubDate>Sat, 13 Oct 2007 23:48:05 GMT</pubDate>
      <updated>0</updated>
   </item>

</channel>
</rss>


Edit: Heh, I was typing this while you replied.
Last edited by boyo on Sun Oct 21, 2007 2:18 pm, edited 1 time in total.
boyo
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 103
Joined: Wed Jan 24, 2007 7:37 am


Return to Archived

Who is online

Users browsing this forum: No registered users and 1 guest

cron