From 6be9a04a5648d5bd1f7a4d221cae423660e963db Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 3 Dec 2015 14:52:13 +0100 Subject: [PATCH] Fix detection of last version on sourceforge --- htdocs/admin/system/about.php | 60 +++++++++++++++++------------------ htdocs/admin/tools/update.php | 4 ++- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/htdocs/admin/system/about.php b/htdocs/admin/system/about.php index e9d3f96ad55..3b2492fad65 100644 --- a/htdocs/admin/system/about.php +++ b/htdocs/admin/system/about.php @@ -59,39 +59,39 @@ $result = getURLContent('http://sourceforge.net/projects/dolibarr/rss'); $sfurl = simplexml_load_string($result['content']); if ($sfurl) { - $title=$sfurl->channel[0]->item[0]->title; + $i=0; + $version='0.0'; + while (! empty($sfurl->channel[0]->item[$i]->title) && $i < 10000) + { + $title=$sfurl->channel[0]->item[$i]->title; + if (preg_match('/([0-9]+\.([0-9\.]+))/', $title, $reg)) + { + $newversion=$reg[1]; + $newversionarray=explode('.',$newversion); + $versionarray=explode('.',$version); + //var_dump($newversionarray);var_dump($versionarray); + if (versioncompare($newversionarray, $versionarray) > 0) $version=$newversion; + } + $i++; + } - function word_limiter($text, $limit = 30, $chars = '0123456789.') - { - if (strlen( $text ) > $limit) - { - $words = str_word_count($text, 2, $chars); - $words = array_reverse($words, TRUE); - foreach($words as $length => $word) { - if ($length + strlen( $word ) >= $limit) - { - array_shift($words); - } else { - break; - } - } - $words = array_reverse($words); - $text = implode(" ", $words) . ''; - } - return $text; - } - - $str = word_limiter($title); - $str = preg_replace('/[^0-9\.]/', '', $str); - print ' ('.$langs->trans("LastStableVersion").': '.$str.''; - if (DOL_VERSION == $str) - { - $youuselaststable=1; - print $langs->trans("YouUseLastStableVersion"); - } - print ')'; + // Show version + if ($version != '0.0') + { + print ' ('.$langs->trans("LastStableVersion").': '.$version.''; + if (DOL_VERSION == $version) + { + $youuselaststable=1; + print $langs->trans("YouUseLastStableVersion"); + } + print ')'; + } print ' / GNU-GPL v3+'; } +else +{ + print $langs->trans("LastStableVersion").' : ' .$langs->trans("UpdateServerOffline").'
'; +} print ''; diff --git a/htdocs/admin/tools/update.php b/htdocs/admin/tools/update.php index f524508e708..cb4890f77f1 100644 --- a/htdocs/admin/tools/update.php +++ b/htdocs/admin/tools/update.php @@ -188,7 +188,9 @@ if ($sfurl) } $i++; } - print $langs->trans("LastStableVersion").' : '. ($version?$version:$langs->trans("Unknown")) .'
'; + + // Show version + print $langs->trans("LastStableVersion").' : '. (($version != '0.0')?$version:$langs->trans("Unknown")) .'
'; } else {