From b786c8836f0576d4feb1543471950c5d24bc7939 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 21 Mar 2017 20:08:40 +0100 Subject: Set Shaarli's version only in shaarli_version.php file --- application/ApplicationUtils.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'application/ApplicationUtils.php') diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php index 94c49040..85dcbeeb 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php @@ -4,9 +4,13 @@ */ class ApplicationUtils { + /** + * @var string File containing the current version + */ + public static $VERSION_FILE = 'shaarli_version.php'; + private static $GIT_URL = 'https://raw.githubusercontent.com/shaarli/Shaarli'; private static $GIT_BRANCHES = array('latest', 'stable'); - private static $VERSION_FILE = 'shaarli_version.php'; private static $VERSION_START_TAG = ''; @@ -29,6 +33,30 @@ class ApplicationUtils return false; } + return $data; + } + + /** + * Retrieve the version from a remote URL or a file. + * + * @param string $remote URL or file to fetch. + * @param int $timeout For URLs fetching. + * + * @return bool|string The version or false if it couldn't be retrieved. + */ + public static function getVersion($remote, $timeout = 2) + { + if (startsWith($remote, 'http')) { + if (($data = static::getLatestGitVersionCode($remote, $timeout)) === false) { + return false; + } + } else { + if (! is_file($remote)) { + return false; + } + $data = file_get_contents($remote); + } + return str_replace( array(self::$VERSION_START_TAG, self::$VERSION_END_TAG, PHP_EOL), array('', '', ''), @@ -90,7 +118,7 @@ class ApplicationUtils // Late Static Binding allows overriding within tests // See http://php.net/manual/en/language.oop5.late-static-bindings.php - $latestVersion = static::getLatestGitVersionCode( + $latestVersion = static::getVersion( self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE ); -- cgit v1.2.3