diff --git a/admin/panels/maintain/admin.maintain.php b/admin/panels/maintain/admin.maintain.php index 8c46829..9422f15 100755 --- a/admin/panels/maintain/admin.maintain.php +++ b/admin/panels/maintain/admin.maintain.php @@ -77,9 +77,9 @@ 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 $sfweb = 'http://sourceforge.net/project/showfiles.php?group_id=157089'; + var $sfweb = 'http://sourceforge.net/projects/flatpress/files/'; function main() { $success = -1; @@ -88,21 +88,19 @@ 'unstable'=>'unknown', ); - $f = @fopen($this->web, 'r'); + $file = utils_geturl($this->web); + - if ($f) { - $file=''; - while(!feof($f)) { - $file .= fgets($f); - } - if ($file){ - $ver = utils_kexplode($file); - - if (strcmp($ver['stable'], SYSTEM_VER)>0) - $success = 1; - else - $success = 2; + if ($file) { + $ver = utils_kexplode($file['content']); + if (!isset($ver['stable'])) { $success = -1; } + elseif (system_ver_compare($ver['stable'], SYSTEM_VER)) { + $success = 1; + } else { + $success = 2; } + } else { + $success = -1; } diff --git a/fp-includes/core/core.system.php b/fp-includes/core/core.system.php index 130ad7d..a6e53ba 100755 --- a/fp-includes/core/core.system.php +++ b/fp-includes/core/core.system.php @@ -77,7 +77,28 @@ function 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) { return 'fp-'.dechex(crc32($string) ^ mt_rand()); } diff --git a/fp-includes/core/core.utils.php b/fp-includes/core/core.utils.php index 3febfc0..3ca8f2d 100644 --- a/fp-includes/core/core.utils.php +++ b/fp-includes/core/core.utils.php @@ -354,6 +354,50 @@ if (!function_exists('fnmatch')) { @ 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() {