CC-2950: Tell users if they are running an out-of-date version or not

- added error checking to curl call
- added regex validation when storing link to latest version
This commit is contained in:
Yuchen Wang 2011-11-17 15:33:29 -05:00
parent eae90862b1
commit 52052bd573
2 changed files with 18 additions and 5 deletions

View file

@ -530,15 +530,20 @@ class Application_Model_Preference
public static function GetLatestLink(){ public static function GetLatestLink(){
$link = self::GetValue("latest_link"); $link = self::GetValue("latest_link");
if($link == null || strlen($link) == 0) { if($link == null || strlen($link) == 0) {
return ""; return "http://www.sourcefabric.org/en/airtime/download/";
} else { } else {
return $link; return $link;
} }
} }
public static function SetLatestLink($link){ public static function SetLatestLink($link){
$pattern = "#^(http|https|ftp)://" .
"([a-zA-Z0-9]+\.)*[a-zA-Z0-9]+" .
"(/[a-zA-Z0-9\-\.\_\~\:\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=]+)*/?$#";
if(preg_match($pattern, $link)) {
self::SetValue("latest_link", $link); self::SetValue("latest_link", $link);
} }
}
public static function SetUploadToSoundcloudOption($upload) { public static function SetUploadToSoundcloudOption($upload) {
self::SetValue("soundcloud_upload_option", $upload); self::SetValue("soundcloud_upload_option", $upload);

View file

@ -72,6 +72,8 @@ if(Application_Model_Preference::GetSupportFeedback() == '1'){
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataArray); curl_setopt($ch, CURLOPT_POSTFIELDS, $dataArray);
$result = curl_exec($ch); $result = curl_exec($ch);
curl_close($ch);
} }
// Get latest version from stat server and store to db // Get latest version from stat server and store to db
@ -82,10 +84,16 @@ if(Application_Model_Preference::GetPlanLevel() == 'disabled'){
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch); $result = curl_exec($ch);
$resultArray = explode("\n", $result);
if(curl_errno($ch)) {
echo "curl error: " . curl_error($ch) . "\n";
} else {
$resultArray = explode("\n", $result);
Application_Model_Preference::SetLatestVersion($resultArray[0]); Application_Model_Preference::SetLatestVersion($resultArray[0]);
Application_Model_Preference::SetLatestLink($resultArray[1]); Application_Model_Preference::SetLatestLink($resultArray[1]);
}
curl_close($ch);
} }
/** /**