aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/acp/acp_extensions.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/acp/acp_extensions.php')
-rw-r--r--phpBB/includes/acp/acp_extensions.php324
1 files changed, 262 insertions, 62 deletions
diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php
index 2ff479d824..9fbf2f20f1 100644
--- a/phpBB/includes/acp/acp_extensions.php
+++ b/phpBB/includes/acp/acp_extensions.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package acp
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
*
*/
@@ -15,9 +19,6 @@ if (!defined('IN_PHPBB'))
exit;
}
-/**
-* @package acp
-*/
class acp_extensions
{
var $u_action;
@@ -26,16 +27,22 @@ class acp_extensions
private $config;
private $template;
private $user;
+ private $cache;
+ private $log;
+ private $request;
function main()
{
// Start the page
- global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx;
+ global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpbb_log, $cache;
$this->db = $db;
$this->config = $config;
$this->template = $template;
$this->user = $user;
+ $this->cache = $cache;
+ $this->request = $request;
+ $this->log = $phpbb_log;
$user->add_lang(array('install', 'acp/extensions', 'migrator'));
@@ -69,21 +76,52 @@ class acp_extensions
{
$md_manager->get_metadata('all');
}
- catch(\phpbb\extension\exception $e)
+ catch (\phpbb\extension\exception $e)
{
- trigger_error($e, E_USER_WARNING);
+ $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
+ trigger_error($message, E_USER_WARNING);
}
}
// What are we doing?
switch ($action)
{
+ case 'set_config_version_check_force_unstable':
+ $force_unstable = $this->request->variable('force_unstable', false);
+
+ if ($force_unstable)
+ {
+ $s_hidden_fields = build_hidden_fields(array(
+ 'force_unstable' => $force_unstable,
+ ));
+
+ confirm_box(false, $user->lang('EXTENSION_FORCE_UNSTABLE_CONFIRM'), $s_hidden_fields);
+ }
+ else
+ {
+ $config->set('extension_force_unstable', false);
+ trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
+ }
+ break;
+
case 'list':
default:
+ if (confirm_box(true))
+ {
+ $config->set('extension_force_unstable', true);
+ trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
+ }
+
$this->list_enabled_exts($phpbb_extension_manager);
$this->list_disabled_exts($phpbb_extension_manager);
$this->list_available_exts($phpbb_extension_manager);
+ $this->template->assign_vars(array(
+ 'U_VERSIONCHECK_FORCE' => $this->u_action . '&amp;action=list&amp;versioncheck_force=1',
+ 'FORCE_UNSTABLE' => $config['extension_force_unstable'],
+ 'U_ACTION' => $this->u_action,
+ ));
+
$this->tpl_name = 'acp_ext_list';
break;
@@ -98,7 +136,13 @@ class acp_extensions
trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
}
- if ($phpbb_extension_manager->enabled($ext_name))
+ $extension = $phpbb_extension_manager->get_extension($ext_name);
+ if (!$extension->is_enableable())
+ {
+ trigger_error($user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
+ }
+
+ if ($phpbb_extension_manager->is_enabled($ext_name))
{
redirect($this->u_action);
}
@@ -123,6 +167,12 @@ class acp_extensions
trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
}
+ $extension = $phpbb_extension_manager->get_extension($ext_name);
+ if (!$extension->is_enableable())
+ {
+ trigger_error($user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
+ }
+
try
{
while ($phpbb_extension_manager->enable_step($ext_name))
@@ -135,6 +185,7 @@ class acp_extensions
meta_refresh(0, $this->u_action . '&amp;action=enable&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('enable.' . $ext_name));
}
}
+ $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_ENABLE', time(), array($ext_name));
}
catch (\phpbb\db\migration\exception $e)
{
@@ -149,7 +200,7 @@ class acp_extensions
break;
case 'disable_pre':
- if (!$phpbb_extension_manager->enabled($ext_name))
+ if (!$phpbb_extension_manager->is_enabled($ext_name))
{
redirect($this->u_action);
}
@@ -164,6 +215,11 @@ class acp_extensions
break;
case 'disable':
+ if (!$phpbb_extension_manager->is_enabled($ext_name))
+ {
+ redirect($this->u_action);
+ }
+
while ($phpbb_extension_manager->disable_step($ext_name))
{
// Are we approaching the time limit? If so we want to pause the update and continue after refreshing
@@ -174,6 +230,7 @@ class acp_extensions
meta_refresh(0, $this->u_action . '&amp;action=disable&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('disable.' . $ext_name));
}
}
+ $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_DISABLE', time(), array($ext_name));
$this->tpl_name = 'acp_ext_disable';
@@ -183,7 +240,7 @@ class acp_extensions
break;
case 'delete_data_pre':
- if ($phpbb_extension_manager->enabled($ext_name))
+ if ($phpbb_extension_manager->is_enabled($ext_name))
{
redirect($this->u_action);
}
@@ -197,6 +254,11 @@ class acp_extensions
break;
case 'delete_data':
+ if ($phpbb_extension_manager->is_enabled($ext_name))
+ {
+ redirect($this->u_action);
+ }
+
try
{
while ($phpbb_extension_manager->purge_step($ext_name))
@@ -209,6 +271,7 @@ class acp_extensions
meta_refresh(0, $this->u_action . '&amp;action=delete_data&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('delete_data.' . $ext_name));
}
}
+ $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_PURGE', time(), array($ext_name));
}
catch (\phpbb\db\migration\exception $e)
{
@@ -226,7 +289,33 @@ class acp_extensions
// Output it to the template
$md_manager->output_template_data();
- $template->assign_var('U_BACK', $this->u_action . '&amp;action=list');
+ try
+ {
+ $updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false));
+
+ $template->assign_vars(array(
+ 'S_UP_TO_DATE' => empty($updates_available),
+ 'S_VERSIONCHECK' => true,
+ 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')),
+ ));
+
+ foreach ($updates_available as $branch => $version_data)
+ {
+ $template->assign_block_vars('updates_available', $version_data);
+ }
+ }
+ catch (\RuntimeException $e)
+ {
+ $template->assign_vars(array(
+ 'S_VERSIONCHECK_STATUS' => $e->getCode(),
+ 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== $user->lang('VERSIONCHECK_FAIL')) ? $e->getMessage() : '',
+ ));
+ }
+
+ $template->assign_vars(array(
+ 'U_BACK' => $this->u_action . '&amp;action=list',
+ 'U_VERSIONCHECK_FORCE' => $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name')),
+ ));
$this->tpl_name = 'acp_ext_details';
break;
@@ -234,104 +323,179 @@ class acp_extensions
}
/**
- * Lists all the enabled extensions and dumps to the template
- *
- * @param $phpbb_extension_manager An instance of the extension manager
- * @return null
- */
+ * Lists all the enabled extensions and dumps to the template
+ *
+ * @param $phpbb_extension_manager An instance of the extension manager
+ * @return null
+ */
public function list_enabled_exts(\phpbb\extension\manager $phpbb_extension_manager)
{
+ $enabled_extension_meta_data = array();
+
foreach ($phpbb_extension_manager->all_enabled() as $name => $location)
{
$md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template);
try
{
- $this->template->assign_block_vars('enabled', array(
- 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
-
- 'U_DETAILS' => $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name),
- ));
-
- $this->output_actions('enabled', array(
- 'DISABLE' => $this->u_action . '&amp;action=disable_pre&amp;ext_name=' . urlencode($name),
- ));
+ $meta = $md_manager->get_metadata('all');
+ $enabled_extension_meta_data[$name] = array(
+ 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
+ 'META_VERSION' => $meta['version'],
+ );
+
+ $force_update = $this->request->variable('versioncheck_force', false);
+ $updates = $this->version_check($md_manager, $force_update, !$force_update);
+
+ $enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
+ $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
+ $enabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name'));
}
- catch(\phpbb\extension\exception $e)
+ catch (\phpbb\extension\exception $e)
{
+ $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
$this->template->assign_block_vars('disabled', array(
- 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e),
+ 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
+ 'S_VERSIONCHECK' => false,
));
}
+ catch (\RuntimeException $e)
+ {
+ $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
+ }
+ }
+
+ uasort($enabled_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
+
+ foreach ($enabled_extension_meta_data as $name => $block_vars)
+ {
+ $block_vars['NAME'] = $name;
+ $block_vars['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
+
+ $this->template->assign_block_vars('enabled', $block_vars);
+
+ $this->output_actions('enabled', array(
+ 'DISABLE' => $this->u_action . '&amp;action=disable_pre&amp;ext_name=' . urlencode($name),
+ ));
}
}
/**
- * Lists all the disabled extensions and dumps to the template
- *
- * @param $phpbb_extension_manager An instance of the extension manager
- * @return null
- */
+ * Lists all the disabled extensions and dumps to the template
+ *
+ * @param $phpbb_extension_manager An instance of the extension manager
+ * @return null
+ */
public function list_disabled_exts(\phpbb\extension\manager $phpbb_extension_manager)
{
+ $disabled_extension_meta_data = array();
+
foreach ($phpbb_extension_manager->all_disabled() as $name => $location)
{
$md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template);
try
{
- $this->template->assign_block_vars('disabled', array(
- 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
-
- 'U_DETAILS' => $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name),
- ));
-
- $this->output_actions('disabled', array(
- 'ENABLE' => $this->u_action . '&amp;action=enable_pre&amp;ext_name=' . urlencode($name),
- 'DELETE_DATA' => $this->u_action . '&amp;action=delete_data_pre&amp;ext_name=' . urlencode($name),
- ));
+ $meta = $md_manager->get_metadata('all');
+ $disabled_extension_meta_data[$name] = array(
+ 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
+ 'META_VERSION' => $meta['version'],
+ );
+
+ $force_update = $this->request->variable('versioncheck_force', false);
+ $updates = $this->version_check($md_manager, $force_update, !$force_update);
+
+ $disabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
+ $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
+ $disabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name'));
}
- catch(\phpbb\extension\exception $e)
+ catch (\phpbb\extension\exception $e)
{
+ $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
$this->template->assign_block_vars('disabled', array(
- 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e),
+ 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
+ 'S_VERSIONCHECK' => false,
));
}
+ catch (\RuntimeException $e)
+ {
+ $disabeld_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
+ }
+ }
+
+ uasort($disabled_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
+
+ foreach ($disabled_extension_meta_data as $name => $block_vars)
+ {
+ $block_vars['NAME'] = $name;
+ $block_vars['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
+
+ $this->template->assign_block_vars('disabled', $block_vars);
+
+ $this->output_actions('disabled', array(
+ 'ENABLE' => $this->u_action . '&amp;action=enable_pre&amp;ext_name=' . urlencode($name),
+ 'DELETE_DATA' => $this->u_action . '&amp;action=delete_data_pre&amp;ext_name=' . urlencode($name),
+ ));
}
}
/**
- * Lists all the available extensions and dumps to the template
- *
- * @param $phpbb_extension_manager An instance of the extension manager
- * @return null
- */
+ * Lists all the available extensions and dumps to the template
+ *
+ * @param $phpbb_extension_manager An instance of the extension manager
+ * @return null
+ */
public function list_available_exts(\phpbb\extension\manager $phpbb_extension_manager)
{
$uninstalled = array_diff_key($phpbb_extension_manager->all_available(), $phpbb_extension_manager->all_configured());
+ $available_extension_meta_data = array();
+
foreach ($uninstalled as $name => $location)
{
$md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template);
try
{
- $this->template->assign_block_vars('disabled', array(
- 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
-
- 'U_DETAILS' => $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name),
- ));
-
- $this->output_actions('disabled', array(
- 'ENABLE' => $this->u_action . '&amp;action=enable_pre&amp;ext_name=' . urlencode($name),
- ));
+ $meta = $md_manager->get_metadata('all');
+ $available_extension_meta_data[$name] = array(
+ 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
+ 'META_VERSION' => $meta['version'],
+ );
+
+ $force_update = $this->request->variable('versioncheck_force', false);
+ $updates = $this->version_check($md_manager, $force_update, !$force_update);
+
+ $available_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
+ $available_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
+ $available_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name'));
}
- catch(\phpbb\extension\exception $e)
+ catch (\phpbb\extension\exception $e)
{
+ $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
$this->template->assign_block_vars('disabled', array(
- 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e),
+ 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
+ 'S_VERSIONCHECK' => false,
));
}
+ catch (\RuntimeException $e)
+ {
+ $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
+ }
+ }
+
+ uasort($available_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
+
+ foreach ($available_extension_meta_data as $name => $block_vars)
+ {
+ $block_vars['NAME'] = $name;
+ $block_vars['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
+
+ $this->template->assign_block_vars('disabled', $block_vars);
+
+ $this->output_actions('disabled', array(
+ 'ENABLE' => $this->u_action . '&amp;action=enable_pre&amp;ext_name=' . urlencode($name),
+ ));
}
}
@@ -352,4 +516,40 @@ class acp_extensions
));
}
}
+
+ /**
+ * Check the version and return the available updates.
+ *
+ * @param \phpbb\extension\metadata_manager $md_manager The metadata manager for the version to check.
+ * @param bool $force_update Ignores cached data. Defaults to false.
+ * @param bool $force_cache Force the use of the cache. Override $force_update.
+ * @return string
+ * @throws RuntimeException
+ */
+ protected function version_check(\phpbb\extension\metadata_manager $md_manager, $force_update = false, $force_cache = false)
+ {
+ $meta = $md_manager->get_metadata('all');
+
+ if (!isset($meta['extra']['version-check']))
+ {
+ throw new \RuntimeException($this->user->lang('NO_VERSIONCHECK'), 1);
+ }
+
+ $version_check = $meta['extra']['version-check'];
+
+ $version_helper = new \phpbb\version_helper($this->cache, $this->config, new \phpbb\file_downloader(), $this->user);
+ $version_helper->set_current_version($meta['version']);
+ $version_helper->set_file_location($version_check['host'], $version_check['directory'], $version_check['filename'], isset($version_check['ssl']) ? $version_check['ssl'] : false);
+ $version_helper->force_stability($this->config['extension_force_unstable'] ? 'unstable' : null);
+
+ return $updates = $version_helper->get_suggested_updates($force_update, $force_cache);
+ }
+
+ /**
+ * Sort helper for the table containing the metadata about the extensions.
+ */
+ protected function sort_extension_meta_data_table($val1, $val2)
+ {
+ return strnatcasecmp($val1['META_DISPLAY_NAME'], $val2['META_DISPLAY_NAME']);
+ }
}