diff options
author | Michal Čihař <mcihar@suse.cz> | 2013-07-12 12:21:17 +0400 |
---|---|---|
committer | Michal Čihař <mcihar@suse.cz> | 2013-07-12 12:21:17 +0400 |
commit | dcd8d12cf6c4a3459a67b151cf5978f916b41d91 (patch) | |
tree | a6c9ba87e4cc05fb0724e1063a9e2ed3ea74f8b4 /version_check.php | |
parent | 20a0cbba6294762dfc0be43c34ee1cf955299e87 (diff) |
Move version gathering into function and test it
Diffstat (limited to 'version_check.php')
-rw-r--r-- | version_check.php | 67 |
1 files changed, 7 insertions, 60 deletions
diff --git a/version_check.php b/version_check.php index eac1fd2c44..d4ad963802 100644 --- a/version_check.php +++ b/version_check.php @@ -9,69 +9,16 @@ // Sets up the session define('PMA_MINIMUM_COMMON', true); require_once 'libraries/common.inc.php'; - -// Get response text from phpmyadmin.net or from the session -// Update cache every 6 hours -if (isset($_SESSION['cache']['version_check']) - && time() < $_SESSION['cache']['version_check']['timestamp'] + 3600 * 6 -) { - $save = false; - $response = $_SESSION['cache']['version_check']['response']; -} else { - $save = true; - $file = 'http://www.phpmyadmin.net/home_page/version.json'; - if (ini_get('allow_url_fopen')) { - if (strlen($cfg['VersionCheckProxyUrl'])) { - $context = array( - 'http' => array( - 'proxy' => $cfg['VersionCheckProxyUrl'], - 'request_fulluri' => true - ) - ); - if (strlen($cfg['VersionCheckProxyUser'])) { - $auth = base64_encode( - $cfg['VersionCheckProxyUser'] . ':' . $cfg['VersionCheckProxyPass'] - ); - $context['http']['header'] = 'Proxy-Authorization: Basic ' . $auth; - } - $response = file_get_contents( - $file, - false, - stream_context_create($context) - ); - } else { - $response = file_get_contents($file); - } - } else if (function_exists('curl_init')) { - $curl_handle = curl_init($file); - if (strlen($cfg['VersionCheckProxyUrl'])) { - curl_setopt($curl_handle, CURLOPT_PROXY, $cfg['VersionCheckProxyUrl']); - if (strlen($cfg['VersionCheckProxyUser'])) { - curl_setopt( - $curl_handle, - CURLOPT_PROXYUSERPWD, - $cfg['VersionCheckProxyUser'] . ':' . $cfg['VersionCheckProxyPass'] - ); - } - } - curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); - $response = curl_exec($curl_handle); - } -} +require_once 'libraries/Util.class.php'; // Always send the correct headers header('Content-type: application/json; charset=UTF-8'); -// Save and forward the response only if in valid format -$data = json_decode($response); -if (is_object($data) && strlen($data->version) && strlen($data->date)) { - if ($save) { - $_SESSION['cache']['version_check'] = array( - 'response' => $response, - 'timestamp' => time() - ); - } - echo $response; -} +$version = PMA_Util::getLatestVersion(); + +echo json_encode(array( + 'version' => $version->version, + 'date' => $version->date, +)); ?> |