General['enable_auto_update']; } /** * Check for a newer version * * @param bool $force Force check * @param int $interval Interval used for update checks */ public static function check($force = false, $interval = null) { if(!self::isAutoUpdateEnabled()) { return; } if ($interval === null) { $interval = self::CHECK_INTERVAL; } $lastTimeChecked = Option::get(self::LAST_TIME_CHECKED); if ($force || $lastTimeChecked === false || time() - $interval > $lastTimeChecked ) { // set the time checked first, so that parallel Piwik requests don't all trigger the http requests Option::set(self::LAST_TIME_CHECKED, time(), $autoLoad = 1); $parameters = array( 'piwik_version' => Version::VERSION, 'php_version' => PHP_VERSION, 'url' => Url::getCurrentUrlWithoutQueryString(), 'trigger' => Common::getRequestVar('module', '', 'string'), 'timezone' => API::getInstance()->getDefaultTimezone(), ); $url = Config::getInstance()->General['api_service_url'] . '/1.0/getLatestVersion/' . '?' . http_build_query($parameters, '', '&'); $timeout = self::SOCKET_TIMEOUT; if (@Config::getInstance()->Debug['allow_upgrades_to_beta']) { $url = 'http://builds.piwik.org/LATEST_BETA'; } try { $latestVersion = Http::sendHttpRequest($url, $timeout); if (!preg_match('~^[0-9][0-9a-zA-Z_.-]*$~D', $latestVersion)) { $latestVersion = ''; } } catch (Exception $e) { // e.g., disable_functions = fsockopen; allow_url_open = Off $latestVersion = ''; } Option::set(self::LATEST_VERSION, $latestVersion); } } /** * Returns version number of a newer Piwik release. * * @return string|bool false if current version is the latest available, * or the latest version number if a newest release is available */ public static function isNewestVersionAvailable() { $latestVersion = Option::get(self::LATEST_VERSION); if (!empty($latestVersion) && version_compare(Version::VERSION, $latestVersion) == -1 ) { return $latestVersion; } return false; } }