Browse Source

Fix detection of last version on sourceforge

Laurent Destailleur 9 years ago
parent
commit
e4f0b9ba15
1 changed files with 17 additions and 24 deletions
  1. 17 24
      htdocs/admin/tools/update.php

+ 17 - 24
htdocs/admin/tools/update.php

@@ -23,6 +23,7 @@
  */
 
 require '../../main.inc.php';
+include_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
 include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
 include_once DOL_DOCUMENT_ROOT . '/core/lib/geturl.lib.php';
 
@@ -172,30 +173,22 @@ $result = getURLContent('http://sourceforge.net/projects/dolibarr/rss');
 $sfurl = simplexml_load_string($result['content']);
 if ($sfurl)
 {
-    $title=$sfurl->channel[0]->item[0]->title;
-
-	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 = $title;
-	print $langs->trans("LastStableVersion").' : <b>'. word_limiter( $str ).'</b><br>';
+    $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++;
+    }
+	print $langs->trans("LastStableVersion").' : <b>'. ($version?$version:$langs->trans("Unknown")) .'</b><br>';
 }
 else
 {