diff options
author | Nathan Guse <nathaniel.guse@gmail.com> | 2014-03-10 21:26:46 -0500 |
---|---|---|
committer | Nathan Guse <nathaniel.guse@gmail.com> | 2014-03-10 21:26:46 -0500 |
commit | 00d86a4af1adc4d34955d0432ef514d8c25942c9 (patch) | |
tree | d40a4ea950dae2f5a99e557dc90906a9bee3c211 /phpBB/phpbb/version_helper.php | |
parent | 1f7c891da2590cd2d70f4e7278cf4d6119a820a5 (diff) | |
download | forums-00d86a4af1adc4d34955d0432ef514d8c25942c9.tar forums-00d86a4af1adc4d34955d0432ef514d8c25942c9.tar.gz forums-00d86a4af1adc4d34955d0432ef514d8c25942c9.tar.bz2 forums-00d86a4af1adc4d34955d0432ef514d8c25942c9.tar.xz forums-00d86a4af1adc4d34955d0432ef514d8c25942c9.zip |
[ticket/9871] Allow setting the host/file to load for the version class
PHPBB3-9871
Diffstat (limited to 'phpBB/phpbb/version_helper.php')
-rw-r--r-- | phpBB/phpbb/version_helper.php | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 6f2fd0c732..d7bc09182e 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -14,6 +14,21 @@ namespace phpbb; */ class version_helper { + /** + * @var string Host + */ + protected $host = 'version.phpbb.com'; + + /** + * @var string Path to file + */ + protected $path = '/phpbb'; + + /** + * @var string File name + */ + protected $file = 'versions.json'; + /** @var \phpbb\cache\service */ protected $cache; @@ -23,6 +38,13 @@ class version_helper /** @var \phpbb\user */ protected $user; + /** + * Constructor + * + * @param \phpbb\cache\service $cache + * @param \phpbb\config\config $config + * @param \phpbb\user $user + */ public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\user $user) { $this->cache = $cache; @@ -31,6 +53,23 @@ class version_helper } /** + * Set location to the file + * + * @param string $host Host (e.g. version.phpbb.com) + * @param string $path Path to file (e.g. /phpbb) + * @param string $file File name (Default: versions.json) + * @return version_helper + */ + public function set_file_location($host, $path, $file = 'versions.json') + { + $this->host = $host; + $this->path = $path; + $this->file = $file; + + return $this; + } + + /** * Wrapper for version_compare() that allows using uppercase A and B * for alpha and beta releases. * @@ -142,12 +181,14 @@ class version_helper */ public function get_versions($force_update = false) { - $info = $this->cache->get('versioncheck'); + $cache_file = 'versioncheck_' . $this->host . $this->path . $this->file; + + $info = $this->cache->get($cache_file); if ($info === false || $force_update) { $errstr = $errno = ''; - $info = get_remote_file('version.phpbb.com', '/phpbb', 'versions.json', $errstr, $errno); + $info = get_remote_file($this->host, $this->path, $this->file, $errstr, $errno); if (!empty($errstr)) { @@ -172,7 +213,7 @@ class version_helper } } - $this->cache->put('versioncheck', $info, 86400); // 24 hours + $this->cache->put($cache_file, $info, 86400); // 24 hours } return $info; |