Wednesday, December 7, 2005

Google Talk Version PHP Script

If you are a PHP programmer this script might be useful to you. It's a little script that fetches the latest Google Talk version number. If you have any questions on how it works, please leave a comment and I will try and help you out. Note that future changes to the system that Google uses to update Google Talk could break this script. This script is in no way supported by myself and certainly not by Google. Note that you can change the $file_name variable to the value "http://dl.google.com/googletalk/google-talk-versioncheck-testing.txt" if you want to see the version number of the latest Google Talk testing version.
<?
/**
 * @author Bradley Holt
 * @copyright Found Line
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
 */
class google_talk_version {
    var
$version;
    var
$major;
    var
$minor;
    var
$patch;
    var
$build;
    function
google_talk_version($file_name) {
        
$handle = fopen($file_name, "r");
        if (
$handle) {
            if (!
feof($handle)) {
                
$buffer = fgets($handle, 4096);
                
$pieces = explode(":", $buffer);
                
$this->version = trim($pieces[1]);
                
$pieces = explode(".", $this->version);
                
$this->major = $pieces[0];
                
$this->minor = $pieces[1];
                
$this->patch = $pieces[2];
                
$this->build = $pieces[3];
            }
            
fclose($handle);
        }
    }
}
//example usage
$file_name = "http://dl.google.com/googletalk/google-talk-versioncheck.txt";
$gtv = new google_talk_version($file_name);
echo
$gtv->version . "<br />";
echo
$gtv->major . "." . $gtv->minor . "." . $gtv->patch . "." . $gtv->build;
?>