fix version check

This commit is contained in:
real_nowhereman 2010-11-05 13:09:18 +00:00
parent 2b054364fe
commit 9503be02e2
3 changed files with 79 additions and 16 deletions

View File

@ -77,9 +77,9 @@
class admin_maintain_updates extends AdminPanelAction { class admin_maintain_updates extends AdminPanelAction {
var $web = 'http://www.flatpress.org/fp/VERSION'; var $web = 'http://flatpress.org/fp/VERSION';
var $fpweb = 'http://www.flatpress.org/home/blog.php'; var $fpweb = 'http://www.flatpress.org/home/blog.php';
var $sfweb = 'http://sourceforge.net/project/showfiles.php?group_id=157089'; var $sfweb = 'http://sourceforge.net/projects/flatpress/files/';
function main() { function main() {
$success = -1; $success = -1;
@ -88,21 +88,19 @@
'unstable'=>'unknown', 'unstable'=>'unknown',
); );
$f = @fopen($this->web, 'r'); $file = utils_geturl($this->web);
if ($f) { if ($file) {
$file=''; $ver = utils_kexplode($file['content']);
while(!feof($f)) { if (!isset($ver['stable'])) { $success = -1; }
$file .= fgets($f); elseif (system_ver_compare($ver['stable'], SYSTEM_VER)) {
} $success = 1;
if ($file){ } else {
$ver = utils_kexplode($file); $success = 2;
if (strcmp($ver['stable'], SYSTEM_VER)>0)
$success = 1;
else
$success = 2;
} }
} else {
$success = -1;
} }

View File

@ -77,7 +77,28 @@
function system_ver() { function system_ver() {
return 'fp-' . SYSTEM_VER; return 'fp-' . SYSTEM_VER;
} }
function system_ver_compare($newver, $oldver) {
$nv_arr = explode('.', $newver);
$ov_arr = explode('.', $oldver);
$cn = count($nv_arr);
$co = count($ov_arr);
$max = min($cn, $co);
// let's compare if one of the first version numbers differs
// from new version, being greater
for ($i=0; $i<$max; $i++) {
if ( $nv_arr[ $i ] > $ov_arr[ $i ] ) { return 1; }
if ( $nv_arr[ $i ] < $ov_arr[ $i ] ) { return 0; }
}
// if they equals, but still new version has more digits
// then old-version is still outdated
if ($cn > $co) return 1;
}
function system_generate_id($string) { function system_generate_id($string) {
return 'fp-'.dechex(crc32($string) ^ mt_rand()); return 'fp-'.dechex(crc32($string) ^ mt_rand());
} }

View File

@ -354,6 +354,50 @@ if (!function_exists('fnmatch')) {
@ header('Pragma: no-cache'); @ header('Pragma: no-cache');
} }
// from http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl
// code under OSI BSD
/**
* Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an
* array containing the HTTP server response header fields and content.
*/
function utils_geturl($url) {
/*
if (ini_get('allow_url_fopen')) {
return array('content' => io_load_file($url));
}
*/
if (!function_exists('curl_init')) {
trigger_error('curl extension is not installed');
return array();
}
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
function utils_checksmarty() { function utils_checksmarty() {