Fix detection of last version on sourceforge

This commit is contained in:
Laurent Destailleur 2015-12-03 14:46:34 +01:00
parent 1658bee81c
commit e4f0b9ba15

View File

@ -23,6 +23,7 @@
*/ */
require '../../main.inc.php'; 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/files.lib.php';
include_once DOL_DOCUMENT_ROOT . '/core/lib/geturl.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']); $sfurl = simplexml_load_string($result['content']);
if ($sfurl) if ($sfurl)
{ {
$title=$sfurl->channel[0]->item[0]->title; $i=0;
$version='0.0';
function word_limiter($text, $limit = 30, $chars = '0123456789.') while (! empty($sfurl->channel[0]->item[$i]->title) && $i < 10000)
{ {
if (strlen( $text ) > $limit) $title=$sfurl->channel[0]->item[$i]->title;
{ if (preg_match('/([0-9]+\.([0-9\.]+))/', $title, $reg))
$words = str_word_count($text, 2, $chars); {
$words = array_reverse($words, TRUE); $newversion=$reg[1];
foreach($words as $length => $word) { $newversionarray=explode('.',$newversion);
if ($length + strlen( $word ) >= $limit) $versionarray=explode('.',$version);
{ //var_dump($newversionarray);var_dump($versionarray);
array_shift($words); if (versioncompare($newversionarray, $versionarray) > 0) $version=$newversion;
} else { }
break; $i++;
} }
} print $langs->trans("LastStableVersion").' : <b>'. ($version?$version:$langs->trans("Unknown")) .'</b><br>';
$words = array_reverse($words);
$text = implode(" ", $words) . '';
}
return $text;
}
$str = $title;
print $langs->trans("LastStableVersion").' : <b>'. word_limiter( $str ).'</b><br>';
} }
else else
{ {