aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2014-02-19 16:11:40 -0600
committerNathan Guse <nathaniel.guse@gmail.com>2014-02-19 16:13:23 -0600
commit6c8589775b8df2b6fbeffbe594d9279ae90e85ba (patch)
tree170b26bd86dce0eeb7d6c447115f6810ced34bc2 /phpBB/includes
parentbd8951cfbec799f685eb89f14a83933cee647112 (diff)
downloadforums-6c8589775b8df2b6fbeffbe594d9279ae90e85ba.tar
forums-6c8589775b8df2b6fbeffbe594d9279ae90e85ba.tar.gz
forums-6c8589775b8df2b6fbeffbe594d9279ae90e85ba.tar.bz2
forums-6c8589775b8df2b6fbeffbe594d9279ae90e85ba.tar.xz
forums-6c8589775b8df2b6fbeffbe594d9279ae90e85ba.zip
[ticket/9871] Update version check file to use json format
PHPBB3-9871
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/acp/acp_main.php18
-rw-r--r--phpBB/includes/acp/acp_update.php60
-rw-r--r--phpBB/includes/functions.php14
-rw-r--r--phpBB/includes/functions_admin.php105
-rw-r--r--phpBB/includes/functions_compatibility.php68
5 files changed, 101 insertions, 164 deletions
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php
index f01cba0bcc..579317d294 100644
--- a/phpBB/includes/acp/acp_main.php
+++ b/phpBB/includes/acp/acp_main.php
@@ -25,7 +25,7 @@ class acp_main
function main($id, $mode)
{
global $config, $db, $cache, $user, $auth, $template, $request;
- global $phpbb_root_path, $phpbb_admin_path, $phpEx;
+ global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container;
// Show restore permissions notice
if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm'))
@@ -432,17 +432,19 @@ class acp_main
));
}
- $latest_version_info = false;
- if (($latest_version_info = obtain_latest_version_info(request_var('versioncheck_force', false))) === false)
+ $version_helper = $phpbb_container->get('version_helper');
+ try
{
- $template->assign_var('S_VERSIONCHECK_FAIL', true);
+ $recheck = request_var('versioncheck_force', false);
+ $updates_available = $version_helper->get_suggested_updates($recheck);
+
+ $template->assign_var('S_VERSION_UP_TO_DATE', empty($updates_available));
}
- else
+ catch (\RuntimeException $e)
{
- $latest_version_info = explode("\n", $latest_version_info);
-
$template->assign_vars(array(
- 'S_VERSION_UP_TO_DATE' => phpbb_version_compare(trim($latest_version_info[0]), $config['version'], '<='),
+ 'S_VERSIONCHECK_FAIL' => true,
+ 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== $user->lang('VERSIONCHECK_FAIL')) ? $e->getMessage() : '',
));
}
diff --git a/phpBB/includes/acp/acp_update.php b/phpBB/includes/acp/acp_update.php
index 6b5407067d..e8f5c6f288 100644
--- a/phpBB/includes/acp/acp_update.php
+++ b/phpBB/includes/acp/acp_update.php
@@ -24,64 +24,42 @@ class acp_update
function main($id, $mode)
{
- global $config, $db, $user, $auth, $template, $cache;
- global $phpbb_root_path, $phpbb_admin_path, $phpEx;
+ global $config, $user, $template;
+ global $phpbb_root_path, $phpEx, $phpbb_container;
$user->add_lang('install');
$this->tpl_name = 'acp_update';
$this->page_title = 'ACP_VERSION_CHECK';
- // Get current and latest version
- $errstr = '';
- $errno = 0;
-
- $info = obtain_latest_version_info(request_var('versioncheck_force', false));
-
- if (empty($info))
+ $version_helper = $phpbb_container->get('version_helper');
+ try
{
- trigger_error('VERSIONCHECK_FAIL', E_USER_WARNING);
+ $recheck = request_var('versioncheck_force', false);
+ $updates_available = $version_helper->get_suggested_updates($recheck);
}
+ catch (\RuntimeException $e)
+ {
+ $template->assign_var('S_VERSIONCHECK_FAIL', true);
- $info = explode("\n", $info);
- $latest_version = trim($info[0]);
-
- $announcement_url = trim($info[1]);
- $announcement_url = (strpos($announcement_url, '&amp;') === false) ? str_replace('&', '&amp;', $announcement_url) : $announcement_url;
- $update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update');
+ $updates_available = array();
+ }
- // next feature release
- $next_feature_version = $next_feature_announcement_url = false;
- if (isset($info[2]) && trim($info[2]) !== '')
+ foreach ($updates_available as $branch => $version_data)
{
- $next_feature_version = trim($info[2]);
- $next_feature_announcement_url = trim($info[3]);
+ $template->assign_block_vars('updates_available', $version_data);
}
- // Determine automatic update...
- $sql = 'SELECT config_value
- FROM ' . CONFIG_TABLE . "
- WHERE config_name = 'version_update_from'";
- $result = $db->sql_query($sql);
- $version_update_from = (string) $db->sql_fetchfield('config_value');
- $db->sql_freeresult($result);
-
- $current_version = (!empty($version_update_from)) ? $version_update_from : $config['version'];
+ $update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update');
$template->assign_vars(array(
- 'S_UP_TO_DATE' => phpbb_version_compare($latest_version, $config['version'], '<='),
- 'S_UP_TO_DATE_AUTO' => phpbb_version_compare($latest_version, $current_version, '<='),
- 'S_VERSION_CHECK' => true,
- 'U_ACTION' => $this->u_action,
- 'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&amp;versioncheck_force=1'),
+ 'S_UP_TO_DATE' => empty($updates_available),
+ 'U_ACTION' => $this->u_action,
+ 'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&amp;versioncheck_force=1'),
- 'LATEST_VERSION' => $latest_version,
- 'CURRENT_VERSION' => $config['version'],
- 'AUTO_VERSION' => $version_update_from,
- 'NEXT_FEATURE_VERSION' => $next_feature_version,
+ 'CURRENT_VERSION' => $config['version'],
- 'UPDATE_INSTRUCTIONS' => sprintf($user->lang['UPDATE_INSTRUCTIONS'], $announcement_url, $update_link),
- 'UPGRADE_INSTRUCTIONS' => $next_feature_version ? $user->lang('UPGRADE_INSTRUCTIONS', $next_feature_version, $next_feature_announcement_url) : false,
+ 'UPDATE_INSTRUCTIONS' => sprintf($user->lang['UPDATE_INSTRUCTIONS'], $update_link),
));
}
}
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 689a682de3..97e35a930b 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -429,17 +429,11 @@ function phpbb_email_hash($email)
*/
function phpbb_version_compare($version1, $version2, $operator = null)
{
- $version1 = strtolower($version1);
- $version2 = strtolower($version2);
+ global $phpbb_container;
- if (is_null($operator))
- {
- return version_compare($version1, $version2);
- }
- else
- {
- return version_compare($version1, $version2, $operator);
- }
+ $version_helper = $phpbb_container->get('version_helper');
+
+ return $version_helper->compare($version1, $version2, $operator);
}
/**
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 722d3c9c67..7c4f589700 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -2925,72 +2925,6 @@ function get_database_size()
}
/**
-* Retrieve contents from remotely stored file
-*/
-function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port = 80, $timeout = 6)
-{
- global $user;
-
- if ($fsock = @fsockopen($host, $port, $errno, $errstr, $timeout))
- {
- @fputs($fsock, "GET $directory/$filename HTTP/1.0\r\n");
- @fputs($fsock, "HOST: $host\r\n");
- @fputs($fsock, "Connection: close\r\n\r\n");
-
- $timer_stop = time() + $timeout;
- stream_set_timeout($fsock, $timeout);
-
- $file_info = '';
- $get_info = false;
-
- while (!@feof($fsock))
- {
- if ($get_info)
- {
- $file_info .= @fread($fsock, 1024);
- }
- else
- {
- $line = @fgets($fsock, 1024);
- if ($line == "\r\n")
- {
- $get_info = true;
- }
- else if (stripos($line, '404 not found') !== false)
- {
- $errstr = $user->lang['FILE_NOT_FOUND'] . ': ' . $filename;
- return false;
- }
- }
-
- $stream_meta_data = stream_get_meta_data($fsock);
-
- if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop)
- {
- $errstr = $user->lang['FSOCK_TIMEOUT'];
- return false;
- }
- }
- @fclose($fsock);
- }
- else
- {
- if ($errstr)
- {
- $errstr = utf8_convert_message($errstr);
- return false;
- }
- else
- {
- $errstr = $user->lang['FSOCK_DISABLED'];
- return false;
- }
- }
-
- return $file_info;
-}
-
-/**
* Tidy Warnings
* Remove all warnings which have now expired from the database
* The duration of a warning can be defined by the administrator
@@ -3100,45 +3034,6 @@ function add_permission_language()
}
/**
- * Obtains the latest version information
- *
- * @param bool $force_update Ignores cached data. Defaults to false.
- * @param bool $warn_fail Trigger a warning if obtaining the latest version information fails. Defaults to false.
- * @param int $ttl Cache version information for $ttl seconds. Defaults to 86400 (24 hours).
- *
- * @return string | false Version info on success, false on failure.
- */
-function obtain_latest_version_info($force_update = false, $warn_fail = false, $ttl = 86400)
-{
- global $cache;
-
- $info = $cache->get('versioncheck');
-
- if ($info === false || $force_update)
- {
- $errstr = '';
- $errno = 0;
-
- $info = get_remote_file('version.phpbb.com', '/phpbb',
- ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno);
-
- if (empty($info))
- {
- $cache->destroy('versioncheck');
- if ($warn_fail)
- {
- trigger_error($errstr, E_USER_WARNING);
- }
- return false;
- }
-
- $cache->put('versioncheck', $info, $ttl);
- }
-
- return $info;
-}
-
-/**
* Enables a particular flag in a bitfield column of a given table.
*
* @param string $table_name The table to update
diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php
index 2197815087..2bd812efe0 100644
--- a/phpBB/includes/functions_compatibility.php
+++ b/phpBB/includes/functions_compatibility.php
@@ -48,3 +48,71 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $
return phpbb_get_avatar($row, $alt, $ignore_config);
}
+
+/**
+ * Retrieve contents from remotely stored file
+ *
+ * @deprecated 3.1.0-a4 (To be removed: 3.3.0)
+ */
+function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port = 80, $timeout = 6)
+{
+ global $user;
+
+ if ($fsock = @fsockopen($host, $port, $errno, $errstr, $timeout))
+ {
+ @fputs($fsock, "GET $directory/$filename HTTP/1.0\r\n");
+ @fputs($fsock, "HOST: $host\r\n");
+ @fputs($fsock, "Connection: close\r\n\r\n");
+
+ $timer_stop = time() + $timeout;
+ stream_set_timeout($fsock, $timeout);
+
+ $file_info = '';
+ $get_info = false;
+
+ while (!@feof($fsock))
+ {
+ if ($get_info)
+ {
+ $file_info .= @fread($fsock, 1024);
+ }
+ else
+ {
+ $line = @fgets($fsock, 1024);
+ if ($line == "\r\n")
+ {
+ $get_info = true;
+ }
+ else if (stripos($line, '404 not found') !== false)
+ {
+ $errstr = $user->lang['FILE_NOT_FOUND'] . ': ' . $filename;
+ return false;
+ }
+ }
+
+ $stream_meta_data = stream_get_meta_data($fsock);
+
+ if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop)
+ {
+ $errstr = $user->lang['FSOCK_TIMEOUT'];
+ return false;
+ }
+ }
+ @fclose($fsock);
+ }
+ else
+ {
+ if ($errstr)
+ {
+ $errstr = utf8_convert_message($errstr);
+ return false;
+ }
+ else
+ {
+ $errstr = $user->lang['FSOCK_DISABLED'];
+ return false;
+ }
+ }
+
+ return $file_info;
+}