diff options
author | mattpiwik <matthieu.aubry@gmail.com> | 2009-02-19 05:04:32 +0300 |
---|---|---|
committer | mattpiwik <matthieu.aubry@gmail.com> | 2009-02-19 05:04:32 +0300 |
commit | 3dbb5f95f0619db038a9611df252cedbf5778202 (patch) | |
tree | a186e0026d009665e3e950c74dc9043617159185 /core/UpdateCheck.php | |
parent | e68e02876949a88d5bcaec201716d47c723a448a (diff) |
- adding an update check mechanism: once a day, piwik will check against api.piwik.org to check if a new piwik release is available. If a new release is available, the top right orange message will display: "Piwik 0.2.30 is available! Please update now (see changes)." with link to piwik.org/docs/update and piwik.org/changelog
- adding helper function to send http request with enforced timeout (to make sure that the piwik UI doesn't hang for 30 seconds when checking for a new release once a day, if piwik.org down)
- adding some installation strings that weren't in the translation file already
- adding two checkboxes during installation: register to piwik major & security releases newsletter, register for general piwik newsletter.
git-svn-id: http://dev.piwik.org/svn/trunk@909 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core/UpdateCheck.php')
-rw-r--r-- | core/UpdateCheck.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/core/UpdateCheck.php b/core/UpdateCheck.php new file mode 100644 index 0000000000..fe43bfc573 --- /dev/null +++ b/core/UpdateCheck.php @@ -0,0 +1,49 @@ +<?php + +class Piwik_UpdateCheck +{ + const CHECK_INTERVAL = 86400; + const LAST_TIME_CHECKED = 'UpdateCheck_LastTimeChecked'; + const LATEST_VERSION = 'UpdateCheck_LatestVersion'; + const PIWIK_HOST = 'http://api.piwik.org/1.0/getLatestVersion/'; + const SOCKET_TIMEOUT = 2; + + public static function check() + { + $lastTimeChecked = Piwik_GetOption(self::LAST_TIME_CHECKED); + if($lastTimeChecked === false + || time() - self::CHECK_INTERVAL > $lastTimeChecked ) + { + $parameters = array( + 'piwik_version' => Piwik_Version::VERSION, + 'php_version' => phpversion(), + 'url' => Piwik_Url::getCurrentUrlWithoutQueryString(), + 'trigger' => Piwik_Common::getRequestVar('module','','string'), + ); + + $url = self::PIWIK_HOST . "?" . http_build_query($parameters, '', '&'); + $timeout = self::SOCKET_TIMEOUT; + $latestVersion = Piwik::sendHttpRequest($url, $timeout); + Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoload = 1); + Piwik_SetOption(self::LATEST_VERSION, $latestVersion); + } + } + + /** + * @return string|false false if current version is the latest available, + * or the latest version number if a newest release is available + */ + public static function isNewestVersionAvailable() + { + $latestVersion = Piwik_GetOption(self::LATEST_VERSION); + if(!empty($latestVersion) + && version_compare(Piwik_Version::VERSION, $latestVersion) == -1) + { + return $latestVersion; + } + else + { + return false; + } + } +} |