From 944f9bf54e20fae7936c1349bd3fa3fa022099c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Mon, 24 Jul 2017 18:22:03 +0200 Subject: [PATCH 01/38] [ticket/15289] Add storage collection service PHPBB3-15289 --- phpBB/config/default/container/services_storage.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phpBB/config/default/container/services_storage.yml b/phpBB/config/default/container/services_storage.yml index 32b74687c9..3593b8264a 100644 --- a/phpBB/config/default/container/services_storage.yml +++ b/phpBB/config/default/container/services_storage.yml @@ -18,6 +18,13 @@ services: - '@storage.provider_collection' # Collections + storage.storage_collection: + class: phpbb\di\service_collection + arguments: + - '@service_container' + tags: + - { name: service_collection, tag: storage } + storage.adapter_collection: class: phpbb\di\service_collection arguments: From ba9f082bf40cf5ea6e390cf7bb3eef5ffcb952f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 25 Jul 2017 10:29:13 +0200 Subject: [PATCH 02/38] [ticket/15289] Add acp module PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 36 +++++++ phpBB/includes/acp/acp_storage.php | 132 ++++++++++++++++++++++++++ phpBB/install/schemas/schema_data.sql | 3 +- phpBB/language/en/acp/storage.php | 40 ++++++++ phpBB/phpbb/storage/storage.php | 15 +++ 5 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 phpBB/adm/style/acp_storage.html create mode 100644 phpBB/includes/acp/acp_storage.php create mode 100644 phpBB/language/en/acp/storage.php diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html new file mode 100644 index 0000000000..39125f25ae --- /dev/null +++ b/phpBB/adm/style/acp_storage.html @@ -0,0 +1,36 @@ + + + + +

{L_TITLE}

+ +

{L_TITLE_EXPLAIN}

+ +
+ + +
+ {storage.LEGEND} +
+

{storage.TITLE_EXPLAIN}
+
+
+
+ + +
+ {adapter.NAME} + {adapter.SETTINGS} +
+ + + +
+ {L_SUBMIT} +   + + {S_FORM_TOKEN} +
+
+ + diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php new file mode 100644 index 0000000000..cbf2a56bba --- /dev/null +++ b/phpBB/includes/acp/acp_storage.php @@ -0,0 +1,132 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @todo add cron intervals to server settings? (database_gc, queue_interval, session_gc, search_gc, cache_gc, warnings_gc) +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +class acp_storage +{ + /** @var \phpbb\config $config */ + protected $config; + + /** @var \phpbb\language\language $lang */ + protected $lang; + + /** @var \phpbb\request\request */ + protected $request; + + /** @var \phpbb\template\template */ + protected $template; + + /** @var \phpbb\user */ + protected $user; + + /** @var string */ + public $page_title; + + /** @var string */ + public $tpl_name; + + /** @var string */ + public $u_action; + + public function main($id, $mode) + { + global $phpbb_container; + + $this->config = $phpbb_container->get('config'); + $this->lang = $phpbb_container->get('language'); + $this->request = $phpbb_container->get('request'); + $this->template = $phpbb_container->get('template'); + $this->user = $phpbb_container->get('user'); + + // Add necesary language files + $this->user->add_lang(array('acp/storage')); + + switch($mode) + { + case 'settings': + $this->overview($id, $mode); + break; + } + } + + public function overview($id, $mode) + { + $form_name = 'acp_storage'; + add_form_key($form_name); + + global $phpbb_container; + $storage_collection = $phpbb_container->get('storage.storage_collection'); + $adapter_provider_collection = $phpbb_container->get('storage.provider_collection'); + + $storages = array(); + + foreach($storage_collection->getIterator() as $storage) + { + $this->template->assign_block_vars('storage', array( + 'LEGEND' => $storage->get_name(), + 'TITLE' => $storage->get_name(), + 'TITLE_EXPLAIN' => $storage->get_description(), + 'OPTIONS' => $this->generate_adapter_options(), + )); + + foreach($adapter_provider_collection as $provider) + { + if(!$provider->is_available()) + { + continue; + } + + $this->template->assign_block_vars('storage.adapter', array( + 'NAME' => get_class($provider), + 'SETTINGS' => print_r($provider->get_options(), 1), + )); + } + } + + // Template from adm/style + $this->tpl_name = 'acp_storage'; + + // Set page title + $this->page_title = 'STORAGE_TITLE'; + + $this->template->assign_vars(array( + )); + } + + protected function generate_adapter_options() + { + global $phpbb_container; + $adapter_provider_collection = $phpbb_container->get('storage.provider_collection'); + + $options = ''; + + foreach($adapter_provider_collection as $provider) + { + $class = get_class($provider); + $options .= ""; + } + + return $options; + } +} diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index fbe36bee05..b965d2e784 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -407,6 +407,7 @@ INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_reasons', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_roles', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_search', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_server', 1); +INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_storage', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_styles', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_switchperm', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_uauth', 1); @@ -522,7 +523,7 @@ INSERT INTO phpbb_ranks (rank_title, rank_min, rank_special, rank_image) VALUES # -- Roles data # Standard Admin (a_) -INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 1, auth_option_id, 1 FROM phpbb_acl_options WHERE auth_option LIKE 'a_%' AND auth_option NOT IN ('a_switchperm', 'a_jabber', 'a_phpinfo', 'a_server', 'a_backup', 'a_styles', 'a_clearlogs', 'a_modules', 'a_language', 'a_email', 'a_bots', 'a_search', 'a_aauth', 'a_roles'); +INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 1, auth_option_id, 1 FROM phpbb_acl_options WHERE auth_option LIKE 'a_%' AND auth_option NOT IN ('a_switchperm', 'a_jabber', 'a_phpinfo', 'a_server', 'a_backup', 'a_styles', 'a_clearlogs', 'a_modules', 'a_language', 'a_email', 'a_bots', 'a_search', 'a_storage', 'a_aauth', 'a_roles'); # Forum admin (a_) INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 2, auth_option_id, 1 FROM phpbb_acl_options WHERE auth_option LIKE 'a_%' AND auth_option IN ('a_', 'a_authgroups', 'a_authusers', 'a_fauth', 'a_forum', 'a_forumadd', 'a_forumdel', 'a_mauth', 'a_prune', 'a_uauth', 'a_viewauth', 'a_viewlogs'); diff --git a/phpBB/language/en/acp/storage.php b/phpBB/language/en/acp/storage.php new file mode 100644 index 0000000000..36c8641431 --- /dev/null +++ b/phpBB/language/en/acp/storage.php @@ -0,0 +1,40 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* DO NOT CHANGE +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +if (empty($lang) || !is_array($lang)) +{ + $lang = array(); +} + +// DEVELOPERS PLEASE NOTE +// +// All language files should use UTF-8 as their encoding and the files must not contain a BOM. +// +// Placeholders can now contain order information, e.g. instead of +// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows +// translators to re-order the output of data while ensuring it remains correct +// +// You do not need this where single placeholders are used, e.g. 'Message %d' is fine +// equally where a string contains only two placeholders which are used to wrap text +// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine + +$lang = array_merge($lang, array( +)); diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index 089ccce737..be5d813056 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -45,6 +45,21 @@ class storage $this->storage_name = $storage_name; } + public function get_id() + { + return $this->storage_name; + } + + public function get_name() + { + return strtoupper('STORAGE_' . $this->storage_name . '_NAME'); + } + + public function get_description() + { + return strtoupper('STORAGE_' . $this->storage_name . '_DESCRIPTION'); + } + /** * Returns an adapter instance * From 737a8f9f7d5566c830b9de9c2b997f8cb1fa44dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 27 Jul 2017 17:48:58 +0200 Subject: [PATCH 03/38] [ticket/15289] Update acp module PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 55 ++++++++++-------- phpBB/composer-ext.json | 0 phpBB/composer-ext.lock | 0 .../default/container/services_twig.yml | 1 + phpBB/includes/acp/acp_storage.php | 57 ++++--------------- phpBB/includes/acp/info/acp_storage.php | 34 +++++++++++ phpBB/language/en/acp/common.php | 3 + phpBB/language/en/acp/storage.php | 11 ++++ phpBB/phpbb/storage/provider/local.php | 12 +++- phpBB/phpbb/storage/storage.php | 17 ++---- 10 files changed, 109 insertions(+), 81 deletions(-) delete mode 100644 phpBB/composer-ext.json delete mode 100644 phpBB/composer-ext.lock create mode 100644 phpBB/includes/acp/info/acp_storage.php diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index 39125f25ae..7275b4ecfa 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -2,35 +2,44 @@ -

{L_TITLE}

+

{L_STORAGE_TITLE}

-

{L_TITLE_EXPLAIN}

+

{L_STORAGE_TITLE_EXPLAIN}

- -
- {storage.LEGEND} -
-

{storage.TITLE_EXPLAIN}
-
-
-
- - -
- {adapter.NAME} - {adapter.SETTINGS} + {% for storage in STORAGES %} +
+ {{ lang('STORAGE_' ~ storage.get_name | upper ~ '_TITLE') }} +
+

{L_STORAGE_SELECT_DESC}
+
+ +
+
- - -
- {L_SUBMIT} -   - - {S_FORM_TOKEN} -
+ {% for provider in PROVIDERS if provider.is_available %} +
+ {{ lang('STORAGE_' ~ storage.get_name | upper ~ '_TITLE') }} - {{ lang('STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_NAME') }} + provider.get_options +
+ {% endfor %} + + {% endfor %} + +
+ {L_SUBMIT} +   + + {S_FORM_TOKEN} +
diff --git a/phpBB/composer-ext.json b/phpBB/composer-ext.json deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/phpBB/composer-ext.lock b/phpBB/composer-ext.lock deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/phpBB/config/default/container/services_twig.yml b/phpBB/config/default/container/services_twig.yml index e9c0360436..c7ce82632a 100644 --- a/phpBB/config/default/container/services_twig.yml +++ b/phpBB/config/default/container/services_twig.yml @@ -15,6 +15,7 @@ services: - [] calls: - [setLexer, ['@template.twig.lexer']] + - [addGlobal, ['config', '@config']] template.twig.lexer: class: phpbb\template\twig\lexer diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index cbf2a56bba..29fc123f22 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -40,6 +40,12 @@ class acp_storage /** @var \phpbb\user */ protected $user; + /** @var \phpbb\di\service_collection */ + protected $provider_collection; + + /** @var \phpbb\di\service_collection */ + protected $storage_collection; + /** @var string */ public $page_title; @@ -58,9 +64,11 @@ class acp_storage $this->request = $phpbb_container->get('request'); $this->template = $phpbb_container->get('template'); $this->user = $phpbb_container->get('user'); + $this->provider_collection = $phpbb_container->get('storage.provider_collection'); + $this->storage_collection = $phpbb_container->get('storage.storage_collection'); // Add necesary language files - $this->user->add_lang(array('acp/storage')); + $this->lang->add_lang(array('acp/storage')); switch($mode) { @@ -75,35 +83,6 @@ class acp_storage $form_name = 'acp_storage'; add_form_key($form_name); - global $phpbb_container; - $storage_collection = $phpbb_container->get('storage.storage_collection'); - $adapter_provider_collection = $phpbb_container->get('storage.provider_collection'); - - $storages = array(); - - foreach($storage_collection->getIterator() as $storage) - { - $this->template->assign_block_vars('storage', array( - 'LEGEND' => $storage->get_name(), - 'TITLE' => $storage->get_name(), - 'TITLE_EXPLAIN' => $storage->get_description(), - 'OPTIONS' => $this->generate_adapter_options(), - )); - - foreach($adapter_provider_collection as $provider) - { - if(!$provider->is_available()) - { - continue; - } - - $this->template->assign_block_vars('storage.adapter', array( - 'NAME' => get_class($provider), - 'SETTINGS' => print_r($provider->get_options(), 1), - )); - } - } - // Template from adm/style $this->tpl_name = 'acp_storage'; @@ -111,22 +90,8 @@ class acp_storage $this->page_title = 'STORAGE_TITLE'; $this->template->assign_vars(array( + 'STORAGES' => $this->storage_collection, + 'PROVIDERS' => $this->provider_collection )); } - - protected function generate_adapter_options() - { - global $phpbb_container; - $adapter_provider_collection = $phpbb_container->get('storage.provider_collection'); - - $options = ''; - - foreach($adapter_provider_collection as $provider) - { - $class = get_class($provider); - $options .= ""; - } - - return $options; - } } diff --git a/phpBB/includes/acp/info/acp_storage.php b/phpBB/includes/acp/info/acp_storage.php new file mode 100644 index 0000000000..25807be91f --- /dev/null +++ b/phpBB/includes/acp/info/acp_storage.php @@ -0,0 +1,34 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class acp_storage_info +{ + function module() + { + return array( + 'filename' => 'acp_storage', + 'title' => 'ACP_STORAGE', + 'modes' => array( + 'settings' => array('title' => 'ACP_STORAGE_SETTINGS', 'auth' => 'acl_a_storage', 'cat' => array('ACP_SERVER_CONFIGURATION')), + ), + ); + } + + function install() + { + } + + function uninstall() + { + } +} diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 8cc87dd892..a371c27d8e 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -178,6 +178,9 @@ $lang = array_merge($lang, array( 'ACP_SERVER_SETTINGS' => 'Server settings', 'ACP_SIGNATURE_SETTINGS' => 'Signature settings', 'ACP_SMILIES' => 'Smilies', + + 'ACP_STORAGE_SETTINGS' => 'Storage settings', + 'ACP_STYLE_MANAGEMENT' => 'Style management', 'ACP_STYLES' => 'Styles', 'ACP_STYLES_CACHE' => 'Purge Cache', diff --git a/phpBB/language/en/acp/storage.php b/phpBB/language/en/acp/storage.php index 36c8641431..7025ce8a80 100644 --- a/phpBB/language/en/acp/storage.php +++ b/phpBB/language/en/acp/storage.php @@ -37,4 +37,15 @@ if (empty($lang) || !is_array($lang)) // in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine $lang = array_merge($lang, array( + 'STORAGE_TITLE' => 'Storage Settings', + 'STORAGE_TITLE_EXPLAIN' => 'Here you can change the storage.', + 'STORAGE_SELECT' => 'Select storage', + 'STORAGE_SELECT_DESC' => 'Select an storage from the list.', + + 'STORAGE_ATTACHMENT_TITLE' => 'Attachments storage', + 'STORAGE_AVATAR_TITLE' => 'Avatars storage', + 'STORAGE_BACKUP_TITLE' => 'Backup storage', + + 'STORAGE_ADAPTER_LOCAL_NAME' => 'Local', + )); diff --git a/phpBB/phpbb/storage/provider/local.php b/phpBB/phpbb/storage/provider/local.php index 370178cf47..32167d7d9c 100644 --- a/phpBB/phpbb/storage/provider/local.php +++ b/phpBB/phpbb/storage/provider/local.php @@ -15,6 +15,16 @@ namespace phpbb\storage\provider; class local implements provider_interface { + public function get_name() + { + return 'local'; + } + + public function get_class() + { + return get_class($this); + } + /** * {@inheritdoc} */ @@ -28,7 +38,7 @@ class local implements provider_interface */ public function get_options() { - return ['path']; + return ['path' => array('lang' => 'PATH', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => false)]; } /** diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index be5d813056..a380f93663 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -45,19 +45,14 @@ class storage $this->storage_name = $storage_name; } - public function get_id() - { - return $this->storage_name; - } - + /** + * Returns storage name + * + * @return string + */ public function get_name() { - return strtoupper('STORAGE_' . $this->storage_name . '_NAME'); - } - - public function get_description() - { - return strtoupper('STORAGE_' . $this->storage_name . '_DESCRIPTION'); + return $this->storage_name; } /** From 6cf97b947163cc4360f8e10de3af0f7f5a51ce9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 27 Jul 2017 18:02:53 +0200 Subject: [PATCH 04/38] [ticket/15289] Fix selected PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index 7275b4ecfa..3c0c6bfe54 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -16,7 +16,7 @@
{% for provider in PROVIDERS if provider.is_available %} - {% endfor %} From 19b99a0770bf0a7cb4dde8cefbad711e916e3054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Mon, 31 Jul 2017 22:58:29 +0200 Subject: [PATCH 06/38] [ticket/15289] Add twig extension to generate inputs from the template PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 30 ++++---- .../default/container/services_twig.yml | 6 ++ phpBB/language/en/acp/storage.php | 2 + phpBB/phpbb/storage/provider/local.php | 2 +- phpBB/phpbb/template/twig/extension/form.php | 71 +++++++++++++++++++ 5 files changed, 97 insertions(+), 14 deletions(-) create mode 100644 phpBB/phpbb/template/twig/extension/form.php diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index 3dcdf7e8c3..123036b45b 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -11,24 +11,28 @@ {% for storage in STORAGES %}
{{ lang('STORAGE_' ~ storage.get_name | upper ~ '_TITLE') }} -
-

{{ lang('STORAGE_SELECT_DESC') }}
-
- -
-
+
+

{{ lang('STORAGE_SELECT_DESC') }}
+
+ +
+
{% for provider in PROVIDERS if provider.is_available %}
{{ lang('STORAGE_' ~ storage.get_name | upper ~ '_TITLE') }} - {{ lang('STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_NAME') }} - provider.get_options + {% for name, options in provider.get_options %} + {% set lang_name = 'STORAGE_ADAPTER_' ~ storage.get_name | upper ~ '_OPTION_' ~ name | upper %} + {% set options = options|merge({'name': storage.get_name ~ '[' ~ name ~ ']'}) %} + {{ adm_block(lang(lang_name), '', input(options)) }} + {% endfor %}
{% endfor %} diff --git a/phpBB/config/default/container/services_twig.yml b/phpBB/config/default/container/services_twig.yml index c7ce82632a..11df56a21c 100644 --- a/phpBB/config/default/container/services_twig.yml +++ b/phpBB/config/default/container/services_twig.yml @@ -48,6 +48,12 @@ services: tags: - { name: twig.extension } + template.twig.extensions.form: + class: phpbb\template\twig\extension\form + arguments: + tags: + - { name: twig.extension } + template.twig.extensions.debug: class: Twig_Extension_Debug diff --git a/phpBB/language/en/acp/storage.php b/phpBB/language/en/acp/storage.php index 7025ce8a80..04bff12bfd 100644 --- a/phpBB/language/en/acp/storage.php +++ b/phpBB/language/en/acp/storage.php @@ -46,6 +46,8 @@ $lang = array_merge($lang, array( 'STORAGE_AVATAR_TITLE' => 'Avatars storage', 'STORAGE_BACKUP_TITLE' => 'Backup storage', + 'STORAGE_ADAPTER_LOCAL_OPTION_PATH' => 'Path', + 'STORAGE_ADAPTER_LOCAL_NAME' => 'Local', )); diff --git a/phpBB/phpbb/storage/provider/local.php b/phpBB/phpbb/storage/provider/local.php index 32167d7d9c..b7f315bfea 100644 --- a/phpBB/phpbb/storage/provider/local.php +++ b/phpBB/phpbb/storage/provider/local.php @@ -38,7 +38,7 @@ class local implements provider_interface */ public function get_options() { - return ['path' => array('lang' => 'PATH', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => false)]; + return ['path' => array('type' => 'text')]; } /** diff --git a/phpBB/phpbb/template/twig/extension/form.php b/phpBB/phpbb/template/twig/extension/form.php new file mode 100644 index 0000000000..00d3391f47 --- /dev/null +++ b/phpBB/phpbb/template/twig/extension/form.php @@ -0,0 +1,71 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\template\twig\extension; + +// I will use this to generate forms in twig until there is something better +class form extends \Twig_Extension +{ + + /** + * Constructor + */ + public function __construct() + { + } + + public function getFunctions() + { + return [ + new \Twig_SimpleFunction('input', '\\phpbb\\template\\twig\\extension\\form::generate_input'), + new \Twig_SimpleFunction('adm_block', '\\phpbb\\template\\twig\\extension\\form::generate_block'), + ]; + } + + public static function generate_input($options) + { + $input = ' $value) + { + if (in_array($key, ['lang'])) + continue; + + $input .= "$key=\"$value\" "; + } + break; + } + + $input .= '>'; + + return $input; + } + + public static function generate_block($name, $description = '', $content) + { + return << +

$description
+
+ $content +
+ +EOF; + } +} From 71f9babcf1b9972601828bcc2aa23f1ce79c7ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Mon, 31 Jul 2017 23:01:00 +0200 Subject: [PATCH 07/38] [ticket/15289] Fix language key PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index 123036b45b..ecbddc0e24 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -29,7 +29,7 @@
{{ lang('STORAGE_' ~ storage.get_name | upper ~ '_TITLE') }} - {{ lang('STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_NAME') }} {% for name, options in provider.get_options %} - {% set lang_name = 'STORAGE_ADAPTER_' ~ storage.get_name | upper ~ '_OPTION_' ~ name | upper %} + {% set lang_name = 'STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_OPTION_' ~ name | upper %} {% set options = options|merge({'name': storage.get_name ~ '[' ~ name ~ ']'}) %} {{ adm_block(lang(lang_name), '', input(options)) }} {% endfor %} From 6e739a1d0b79c30d998fee5279e48b09df0b6d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 1 Aug 2017 12:07:18 +0200 Subject: [PATCH 08/38] [ticket/15289] Fix adapter factory PHPBB3-15289 --- phpBB/phpbb/storage/adapter_factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/storage/adapter_factory.php b/phpBB/phpbb/storage/adapter_factory.php index 4b27269524..4f5547f433 100644 --- a/phpBB/phpbb/storage/adapter_factory.php +++ b/phpBB/phpbb/storage/adapter_factory.php @@ -83,7 +83,7 @@ class adapter_factory { $options = []; - foreach ($definitions as $def) + foreach (array_keys($definitions) as $def) { $options[$def] = $this->config['storage\\' . $storage_name . '\\config\\' . $def]; } From c3c8117f0a69728795035aec95da6d1558501dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 2 Aug 2017 15:08:34 +0200 Subject: [PATCH 09/38] [ticket/15289] Update acp to be able to save data in the database PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 2 +- phpBB/includes/acp/acp_storage.php | 59 +++++++++++++++++++- phpBB/phpbb/template/twig/extension/form.php | 4 +- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index ecbddc0e24..60b3540705 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -31,7 +31,7 @@ {% for name, options in provider.get_options %} {% set lang_name = 'STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_OPTION_' ~ name | upper %} {% set options = options|merge({'name': storage.get_name ~ '[' ~ name ~ ']'}) %} - {{ adm_block(lang(lang_name), '', input(options)) }} + {{ adm_block(lang(lang_name), '', input(options, attribute(CONFIG, 'storage\\' ~ storage.get_name ~ '\\config\\' ~ name))) }} {% endfor %}
{% endfor %} diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index 29fc123f22..4b368ffeea 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -78,6 +78,7 @@ class acp_storage } } + // TODO: Validate data public function overview($id, $mode) { $form_name = 'acp_storage'; @@ -89,9 +90,65 @@ class acp_storage // Set page title $this->page_title = 'STORAGE_TITLE'; + if ($this->request->is_set_post('submit')) + { + foreach ($this->storage_collection as $storage) + { + $modified = false; + $provider = $this->provider_collection->get_by_class($this->config['storage\\' . $storage->get_name() . '\\provider']); + + // Check if provider have been modified + if ($this->request->variable([$storage->get_name(), 'provider'], '') != $this->config['storage\\' . $storage->get_name() . '\\provider']) + { + $modified = true; + } + + // Check if options have been modified + if(!$modified) + { + foreach($provider->get_options() as $option => $params) + { + if ($this->request->variable([$storage->get_name(), $option], '') != $this->config['storage\\' . $storage->get_name() . '\\provider']) + { + $modified = true; + break; + } + } + } + + // Update storage + if($modified) + { + // TODO: Allow to move data to the new storage automatically + + // TODO: Validate data + + // Remove old straoge config + foreach (array_keys($provider->get_options()) as $def) + { + $this->config->delete('storage\\' . $storage->get_name() . '\\config\\' . $def); + } + + // Update provider + $this->config->set('storage\\' . $storage->get_name() . '\\provider', $this->request->variable([$storage->get_name(), 'provider'], '')); + + // Set new storage config + $new_provider = $this->provider_collection->get_by_class($this->config['storage\\' . $storage->get_name() . '\\provider']); + + foreach (array_keys($new_provider->get_options()) as $def) + { + $this->config->set('storage\\' . $storage->get_name() . '\\config\\' . $def, $this->request->variable([$storage->get_name(), $def], '')); + } + } + } + + // Updated succesfuly + } + $this->template->assign_vars(array( 'STORAGES' => $this->storage_collection, - 'PROVIDERS' => $this->provider_collection + 'PROVIDERS' => $this->provider_collection, + 'CONFIG' => $this->config // Maybe this should be added to \phpbb\templat\twig\extension )); } } diff --git a/phpBB/phpbb/template/twig/extension/form.php b/phpBB/phpbb/template/twig/extension/form.php index 00d3391f47..4cd39058f3 100644 --- a/phpBB/phpbb/template/twig/extension/form.php +++ b/phpBB/phpbb/template/twig/extension/form.php @@ -32,9 +32,9 @@ class form extends \Twig_Extension ]; } - public static function generate_input($options) + public static function generate_input($options, $value = '') { - $input = ' Date: Wed, 2 Aug 2017 15:41:05 +0200 Subject: [PATCH 10/38] [ticket/15289] Add event to add language PHPBB3-15289 --- phpBB/includes/acp/acp_storage.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index 4b368ffeea..91f0d8ae72 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -57,7 +57,7 @@ class acp_storage public function main($id, $mode) { - global $phpbb_container; + global $phpbb_container, $phpbb_dispatcher; $this->config = $phpbb_container->get('config'); $this->lang = $phpbb_container->get('language'); @@ -70,6 +70,17 @@ class acp_storage // Add necesary language files $this->lang->add_lang(array('acp/storage')); + /** + * Add language strings + * + * @event core.acp_storage_load + * @var array + * @since 3.3.0-a1 + */ + $vars = array( + ); + extract($phpbb_dispatcher->trigger_event('core.acp_storage_load', compact($vars))); + switch($mode) { case 'settings': From ebfb71604ded93a44598feffc94bb5828d0a3c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 2 Aug 2017 15:45:08 +0200 Subject: [PATCH 11/38] [ticket/15289] Use lang function in template PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index 60b3540705..b486223cfe 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -2,9 +2,9 @@ -

{L_STORAGE_TITLE}

+

{{ lang('STORAGE_TITLE') }}

-

{L_STORAGE_TITLE_EXPLAIN}

+

{{ lang('STORAGE_TITLE_EXPLAIN') }}

@@ -39,9 +39,9 @@ {% endfor %}
- {L_SUBMIT} -   - + {{ lang('SUBMIT') }} +   + {S_FORM_TOKEN}
From 7e0845f93036c683d1399256362115090e8e36fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 3 Aug 2017 14:01:59 +0200 Subject: [PATCH 12/38] [ticket/15289] Fix code style PHPBB3-15289 --- phpBB/includes/acp/acp_storage.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index 91f0d8ae72..aa7f45d981 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -77,8 +77,7 @@ class acp_storage * @var array * @since 3.3.0-a1 */ - $vars = array( - ); + $vars = array(); extract($phpbb_dispatcher->trigger_event('core.acp_storage_load', compact($vars))); switch($mode) From 04a34d9f4fbccc16cf0d6324d3c72056f81cf018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 3 Aug 2017 16:36:21 +0200 Subject: [PATCH 13/38] [ticket/15289] Use macros to generate form PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 12 ++-- phpBB/adm/style/forms.html | 28 ++++++++ .../default/container/services_twig.yml | 6 -- phpBB/phpbb/template/twig/extension/form.php | 71 ------------------- 4 files changed, 36 insertions(+), 81 deletions(-) create mode 100644 phpBB/adm/style/forms.html delete mode 100644 phpBB/phpbb/template/twig/extension/form.php diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index b486223cfe..4146d50d03 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -1,3 +1,4 @@ +{% import 'forms.html' as forms %} @@ -29,13 +30,16 @@
{{ lang('STORAGE_' ~ storage.get_name | upper ~ '_TITLE') }} - {{ lang('STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_NAME') }} {% for name, options in provider.get_options %} - {% set lang_name = 'STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_OPTION_' ~ name | upper %} - {% set options = options|merge({'name': storage.get_name ~ '[' ~ name ~ ']'}) %} - {{ adm_block(lang(lang_name), '', input(options, attribute(CONFIG, 'storage\\' ~ storage.get_name ~ '\\config\\' ~ name))) }} + {% set l_name = 'STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_OPTION_' ~ name | upper %} + {% set options = options|merge({'name': storage.get_name ~ '[' ~ name ~ ']'}) %} + {% set options = options|merge({'value': attribute(CONFIG, 'storage\\' ~ storage.get_name ~ '\\config\\' ~ name)}) %} + {{ forms.form_row( + forms.form_label(l_name), + forms.form_control(options) + ) }} {% endfor %}
{% endfor %} - {% endfor %}
diff --git a/phpBB/adm/style/forms.html b/phpBB/adm/style/forms.html new file mode 100644 index 0000000000..d3e10f563b --- /dev/null +++ b/phpBB/adm/style/forms.html @@ -0,0 +1,28 @@ +{% macro input(name, value, type, size) %} + +{% endmacro %} + +{% macro textarea(name, value, rows, cols) %} + +{% endmacro %} + +{% macro form_control(params) %} + {% if params['type'] == 'text' %} + {{ _self.input(params['name'], params['value'], params['type']) }} + {% endif %} +{% endmacro %} + +{% macro form_label(name, description = '') %} + {% if description is not empty %}
{{ lang(description) }}{% endif %} +{% endmacro %} + +{% macro form_row(left_content, right_content) %} +
+
+ {{ left_content }} +
+
+ {{ right_content}} +
+
+{% endmacro %} diff --git a/phpBB/config/default/container/services_twig.yml b/phpBB/config/default/container/services_twig.yml index 11df56a21c..c7ce82632a 100644 --- a/phpBB/config/default/container/services_twig.yml +++ b/phpBB/config/default/container/services_twig.yml @@ -48,12 +48,6 @@ services: tags: - { name: twig.extension } - template.twig.extensions.form: - class: phpbb\template\twig\extension\form - arguments: - tags: - - { name: twig.extension } - template.twig.extensions.debug: class: Twig_Extension_Debug diff --git a/phpBB/phpbb/template/twig/extension/form.php b/phpBB/phpbb/template/twig/extension/form.php deleted file mode 100644 index 4cd39058f3..0000000000 --- a/phpBB/phpbb/template/twig/extension/form.php +++ /dev/null @@ -1,71 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\template\twig\extension; - -// I will use this to generate forms in twig until there is something better -class form extends \Twig_Extension -{ - - /** - * Constructor - */ - public function __construct() - { - } - - public function getFunctions() - { - return [ - new \Twig_SimpleFunction('input', '\\phpbb\\template\\twig\\extension\\form::generate_input'), - new \Twig_SimpleFunction('adm_block', '\\phpbb\\template\\twig\\extension\\form::generate_block'), - ]; - } - - public static function generate_input($options, $value = '') - { - $input = ' $value) - { - if (in_array($key, ['lang'])) - continue; - - $input .= "$key=\"$value\" "; - } - break; - } - - $input .= '>'; - - return $input; - } - - public static function generate_block($name, $description = '', $content) - { - return << -

$description
-
- $content -
- -EOF; - } -} From 0b75f1e46a31c1b748ef807f75d20c9625bbe1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 3 Aug 2017 19:02:07 +0200 Subject: [PATCH 14/38] [ticket/15289] Update acp template PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 37 +++++++++++++++++++++++------- phpBB/adm/style/forms.html | 28 ---------------------- phpBB/includes/acp/acp_storage.php | 4 ---- 3 files changed, 29 insertions(+), 40 deletions(-) delete mode 100644 phpBB/adm/style/forms.html diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index 4146d50d03..d94d569c96 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -1,4 +1,3 @@ -{% import 'forms.html' as forms %} @@ -30,13 +29,35 @@
{{ lang('STORAGE_' ~ storage.get_name | upper ~ '_TITLE') }} - {{ lang('STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_NAME') }} {% for name, options in provider.get_options %} - {% set l_name = 'STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_OPTION_' ~ name | upper %} - {% set options = options|merge({'name': storage.get_name ~ '[' ~ name ~ ']'}) %} - {% set options = options|merge({'value': attribute(CONFIG, 'storage\\' ~ storage.get_name ~ '\\config\\' ~ name)}) %} - {{ forms.form_row( - forms.form_label(l_name), - forms.form_control(options) - ) }} +
+
+ {% if description is not empty %}
{{ lang(description) }}{% endif %} +
+
+ {% set input_type = options['type'] %} + {% set input_name = storage.get_name ~ '[' ~ name ~ ']' %} + {% set input_value = attribute(CONFIG, 'storage\\' ~ storage.get_name ~ '\\config\\' ~ name) %} + + {% if + input_type == 'text' or + input_type == 'password' or + input_type == 'email' %} + + {% elseif input_type == 'textarea' %} + + {% elseif input_type == 'radio' %} + {% for option_name, option_value in options['options'] %} + + {% endfor %} + {% elseif input_type == 'select' %} + + {% endif %} +
+
{% endfor %}
{% endfor %} diff --git a/phpBB/adm/style/forms.html b/phpBB/adm/style/forms.html deleted file mode 100644 index d3e10f563b..0000000000 --- a/phpBB/adm/style/forms.html +++ /dev/null @@ -1,28 +0,0 @@ -{% macro input(name, value, type, size) %} - -{% endmacro %} - -{% macro textarea(name, value, rows, cols) %} - -{% endmacro %} - -{% macro form_control(params) %} - {% if params['type'] == 'text' %} - {{ _self.input(params['name'], params['value'], params['type']) }} - {% endif %} -{% endmacro %} - -{% macro form_label(name, description = '') %} - {% if description is not empty %}
{{ lang(description) }}{% endif %} -{% endmacro %} - -{% macro form_row(left_content, right_content) %} -
-
- {{ left_content }} -
-
- {{ right_content}} -
-
-{% endmacro %} diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index aa7f45d981..a552be0f44 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -11,10 +11,6 @@ * */ -/** -* @todo add cron intervals to server settings? (database_gc, queue_interval, session_gc, search_gc, cache_gc, warnings_gc) -*/ - /** * @ignore */ From 7f4e47d26f374d9356bc286d66feccd55394449d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 3 Aug 2017 19:09:51 +0200 Subject: [PATCH 15/38] [ticket/15289] Update provider PHPBB3-15289 --- phpBB/phpbb/storage/provider/local.php | 8 +++----- phpBB/phpbb/storage/provider/provider_interface.php | 7 +++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/storage/provider/local.php b/phpBB/phpbb/storage/provider/local.php index b7f315bfea..7ec94d3d2e 100644 --- a/phpBB/phpbb/storage/provider/local.php +++ b/phpBB/phpbb/storage/provider/local.php @@ -15,16 +15,14 @@ namespace phpbb\storage\provider; class local implements provider_interface { + /** + * {@inheritdoc} + */ public function get_name() { return 'local'; } - public function get_class() - { - return get_class($this); - } - /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/storage/provider/provider_interface.php b/phpBB/phpbb/storage/provider/provider_interface.php index d2e78d907f..a61845bccc 100644 --- a/phpBB/phpbb/storage/provider/provider_interface.php +++ b/phpBB/phpbb/storage/provider/provider_interface.php @@ -15,6 +15,13 @@ namespace phpbb\storage\provider; interface provider_interface { + /** + * Gets adapter name. + * + * @return string + */ + public function get_name(); + /** * Gets adapter class. * From da32ecb30b8653aa943daab42c8bec84b5d52f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 3 Aug 2017 19:15:21 +0200 Subject: [PATCH 16/38] [ticket/15289] Remove comment PHPBB3-15289 --- phpBB/includes/acp/acp_storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index a552be0f44..1f842f1388 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -154,7 +154,7 @@ class acp_storage $this->template->assign_vars(array( 'STORAGES' => $this->storage_collection, 'PROVIDERS' => $this->provider_collection, - 'CONFIG' => $this->config // Maybe this should be added to \phpbb\templat\twig\extension + 'CONFIG' => $this->config )); } } From 5be42739dc632b2c626905ff92842c4807295432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 3 Aug 2017 19:26:00 +0200 Subject: [PATCH 17/38] [ticket/15289] Fix radio buttons PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 2 +- phpBB/includes/acp/acp_storage.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index d94d569c96..5ae39cea48 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -47,7 +47,7 @@ {% elseif input_type == 'radio' %} {% for option_name, option_value in options['options'] %} - + {% endfor %} {% elseif input_type == 'select' %} {% elseif input_type == 'textarea' %} From c5f3dec2f27a508384a1a9c2c0c8da3db1c4b291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sat, 5 Aug 2017 21:06:24 +0200 Subject: [PATCH 20/38] [ticket/15289] Update acp storage PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 2 +- phpBB/includes/acp/acp_storage.php | 165 +++++++++++++++++++----- phpBB/language/en/acp/storage.php | 16 ++- phpBB/phpbb/template/twig/extension.php | 21 ++- 4 files changed, 168 insertions(+), 36 deletions(-) diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index c43c327331..54c6d14079 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -16,7 +16,7 @@
+ {% elseif input_type == 'textarea' %} - + {% elseif input_type == 'radio' %} {% for option_name, option_value in options['options'] %} - + {{ lang(option_name) }} {% endfor %} {% elseif input_type == 'select' %} - {% for option_name, option_value in options['options'] %} {% endfor %} From 5420d660ba90689eee46ca5424c20968d8583cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 16:30:46 +0200 Subject: [PATCH 28/38] [ticket/15289] Use Twig includes PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index b4f40499b0..830ef1a663 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -1,4 +1,4 @@ - +{% include 'overall_header.html' %} @@ -70,4 +70,4 @@
- +{% include 'overall_footer.html' %} From 500404a921fed3e425080f34eb0ab7e881c728ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 16:31:24 +0200 Subject: [PATCH 29/38] [ticket/15289] Dont use short names PHPBB3-15289 --- phpBB/includes/acp/acp_storage.php | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index 7b366419b2..c93b503503 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -111,9 +111,9 @@ class acp_storage // Check if options have been modified if (!$modified) { - foreach (array_keys($options) as $def) + foreach (array_keys($options) as $definition) { - if ($this->get_new_def($storage_name, $def) != $this->get_current_def($storage_name, $def)) + if ($this->get_new_definition($storage_name, $definition) != $this->get_current_definition($storage_name, $definition)) { $modified = true; break; @@ -171,14 +171,14 @@ class acp_storage return $this->provider_collection->get_by_class($provider)->get_options(); } - protected function get_current_def($storage_name, $def) + protected function get_current_definition($storage_name, $definition) { - return $this->config['storage\\' . $storage_name . '\\config\\' . $def]; + return $this->config['storage\\' . $storage_name . '\\config\\' . $definition]; } - protected function get_new_def($storage_name, $def) + protected function get_new_definition($storage_name, $definition) { - return $this->request->variable([$storage_name, $def], ''); + return $this->request->variable([$storage_name, $definition], ''); } protected function validate_data($storage_name, &$messages) @@ -206,33 +206,33 @@ class acp_storage // Check options $new_options = $this->get_provider_options($this->get_new_provider($storage_name)); - foreach ($new_options as $def_k => $def_v) + foreach ($new_options as $definition_key => $definition_value) { $provider = $this->provider_collection->get_by_class($this->get_new_provider($storage_name)); - $def_title = $this->lang->lang('STORAGE_ADAPTER_' . strtoupper($provider->get_name()) . '_OPTION_' . strtoupper($def_k)); + $definition_title = $this->lang->lang('STORAGE_ADAPTER_' . strtoupper($provider->get_name()) . '_OPTION_' . strtoupper($definition_key)); - $value = $this->get_new_def($storage_name, $def_k); + $value = $this->get_new_definition($storage_name, $definition_key); - switch ($def_v['type']) + switch ($definition_value['type']) { case 'email': if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { - $messages[] = $this->lang->lang('STORAGE_FORM_TYPE_EMAIL_INCORRECT_FORMAT', $def_title, $storage_title); + $messages[] = $this->lang->lang('STORAGE_FORM_TYPE_EMAIL_INCORRECT_FORMAT', $definition_title, $storage_title); } case 'text': case 'password': - $maxlength = isset($def_v['maxlength']) ? $def_v['maxlength'] : 255; + $maxlength = isset($definition_value['maxlength']) ? $definition_value['maxlength'] : 255; if (strlen($value) > $maxlength) { - $messages[] = $this->lang->lang('STORAGE_FORM_TYPE_TEXT_TOO_LONG', $def_title, $storage_title); + $messages[] = $this->lang->lang('STORAGE_FORM_TYPE_TEXT_TOO_LONG', $definition_title, $storage_title); } break; case 'radio': case 'select': - if (!in_array($value, array_values($def_v['options']))) + if (!in_array($value, array_values($definition_value['options']))) { - $messages[] = $this->lang->lang('STORAGE_FORM_TYPE_SELECT_NOT_AVAILABLE', $def_title, $storage_title); + $messages[] = $this->lang->lang('STORAGE_FORM_TYPE_SELECT_NOT_AVAILABLE', $definition_title, $storage_title); } break; } @@ -244,9 +244,9 @@ class acp_storage $current_options = $this->get_provider_options($this->get_current_provider($storage_name)); // Remove old storage config - foreach (array_keys($current_options) as $def) + foreach (array_keys($current_options) as $definition) { - $this->config->delete('storage\\' . $storage_name . '\\config\\' . $def); + $this->config->delete('storage\\' . $storage_name . '\\config\\' . $definition); } // Update provider @@ -255,9 +255,9 @@ class acp_storage // Set new storage config $new_options = $this->get_provider_options($this->get_new_provider($storage_name)); - foreach (array_keys($new_options) as $def) + foreach (array_keys($new_options) as $definition) { - $this->config->set('storage\\' . $storage_name . '\\config\\' . $def, $this->get_new_def($storage_name, $def)); + $this->config->set('storage\\' . $storage_name . '\\config\\' . $definition, $this->get_new_definition($storage_name, $definition)); } } } From 7a0c5fcb18b2363dcfe60b423bec74fa2cf6971a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 16:37:15 +0200 Subject: [PATCH 30/38] [ticket/15289] Dont use short names PHPBB3-15289 --- phpBB/phpbb/storage/adapter_factory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/storage/adapter_factory.php b/phpBB/phpbb/storage/adapter_factory.php index 4f5547f433..6be702c0c8 100644 --- a/phpBB/phpbb/storage/adapter_factory.php +++ b/phpBB/phpbb/storage/adapter_factory.php @@ -83,9 +83,9 @@ class adapter_factory { $options = []; - foreach (array_keys($definitions) as $def) + foreach (array_keys($definitions) as $definition) { - $options[$def] = $this->config['storage\\' . $storage_name . '\\config\\' . $def]; + $options[$definition] = $this->config['storage\\' . $storage_name . '\\config\\' . $definition]; } return $options; From 557165ac2f49e94db6c6352d0363ca283d80673d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 8 Sep 2017 11:54:10 +0200 Subject: [PATCH 31/38] [ticket/15289] Use lang_defined() PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index 830ef1a663..64de18c648 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -37,7 +37,10 @@ {% set input_value = attribute(config, 'storage\\' ~ storage.get_name ~ '\\config\\' ~ name) %}
- {% if description != lang(description) %}
{{ lang(description) }}{% endif %} + + {% if lang_defined(description) %} +
{{ lang(description) }} + {% endif %}
{% if input_type in ['text', 'password', 'email'] %} From 367b84b462a77a334b2c739ae3ce1751b7dac745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 8 Sep 2017 16:19:44 +0200 Subject: [PATCH 32/38] [ticket/15289] Use twig syntax in variables PHPBB3-15289 --- phpBB/adm/style/acp_storage.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index 64de18c648..4689a7546d 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -6,7 +6,7 @@

{{ lang('STORAGE_TITLE_EXPLAIN') }}

-
+ {% for storage in STORAGES %}
@@ -69,7 +69,7 @@ {{ lang('SUBMIT') }}   - {S_FORM_TOKEN} + {{ S_FORM_TOKEN }}
From b1928d515e2d80c23b708b6e6ee6d9227bd93a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 8 Sep 2017 16:27:26 +0200 Subject: [PATCH 33/38] [ticket/15289] Add missing files PHPBB3-15289 --- phpBB/composer-ext.json | 0 phpBB/composer-ext.lock | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 phpBB/composer-ext.json create mode 100644 phpBB/composer-ext.lock diff --git a/phpBB/composer-ext.json b/phpBB/composer-ext.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/phpBB/composer-ext.lock b/phpBB/composer-ext.lock new file mode 100644 index 0000000000..e69de29bb2 From d7b1018110eb3718ad39173bfeb6aac7ed0ef44e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 8 Sep 2017 16:53:20 +0200 Subject: [PATCH 34/38] [ticket/15289] Language fixes PHPBB3-15289 --- phpBB/includes/acp/acp_storage.php | 3 +-- phpBB/language/en/acp/storage.php | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index c93b503503..30e2791134 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -64,8 +64,7 @@ class acp_storage $this->storage_collection = $phpbb_container->get('storage.storage_collection'); // Add necesary language files - $this->lang->add_lang(array('common')); - $this->lang->add_lang(array('acp/storage')); + $this->lang->add_lang(['common', 'acp/storage']); /** * Add language strings diff --git a/phpBB/language/en/acp/storage.php b/phpBB/language/en/acp/storage.php index 12e9069d3b..638df2177e 100644 --- a/phpBB/language/en/acp/storage.php +++ b/phpBB/language/en/acp/storage.php @@ -40,9 +40,9 @@ $lang = array_merge($lang, array( // Template 'STORAGE_TITLE' => 'Storage Settings', - 'STORAGE_TITLE_EXPLAIN' => 'Here you can change the storage.', + 'STORAGE_TITLE_EXPLAIN' => 'Change storage providers for the file storage types of phpBB. Choose local or remote providers to store files added to or created by phpBB.', 'STORAGE_SELECT' => 'Select storage', - 'STORAGE_SELECT_DESC' => 'Select an storage from the list.', + 'STORAGE_SELECT_DESC' => 'Select a storage from the list.', // Storage names 'STORAGE_ATTACHMENT_TITLE' => 'Attachments storage', @@ -54,9 +54,9 @@ $lang = array_merge($lang, array( 'STORAGE_ADAPTER_LOCAL_OPTION_PATH' => 'Path', // Form validation - 'STORAGE_UPDATE_SUCCESSFUL' => 'All storages were successfuly updated.', - 'STORAGE_NO_CHANGES' => 'No changes has been made.', - 'STORAGE_PROVIDER_NOT_EXISTS' => 'Provider selected for %s doesn\'t exist.', + 'STORAGE_UPDATE_SUCCESSFUL' => 'All storage types were successfully updated.', + 'STORAGE_NO_CHANGES' => 'No changes have been applied.', + 'STORAGE_PROVIDER_NOT_EXISTS' => 'Provider selected for %s doesn’t exist.', 'STORAGE_PROVIDER_NOT_AVAILABLE' => 'Provider selected for %s is not available.', 'STORAGE_FORM_TYPE_EMAIL_INCORRECT_FORMAT' => 'Incorrect email for %s of %s.', 'STORAGE_FORM_TYPE_TEXT_TOO_LONG' => 'Text is too long for %s of %s.', From 036ae01b8223fbfc4d8b8232c1ea11d0ee878457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 8 Sep 2017 16:54:11 +0200 Subject: [PATCH 35/38] [ticket/15289] Use empty instead of count PHPBB3-15289 --- phpBB/includes/acp/acp_storage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index 30e2791134..74cb64e76c 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -128,9 +128,9 @@ class acp_storage } } - if (count($modified_storages)) + if (!empty($modified_storages)) { - if (!count($messages)) + if (empty($messages)) { foreach ($modified_storages as $storage_name) { From 11f13e21ac9c3cdcbe8e059938fdbac832b9b441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 8 Sep 2017 17:01:13 +0200 Subject: [PATCH 36/38] [ticket/15289] Check form PHPBB3-15289 --- phpBB/includes/acp/acp_storage.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index 74cb64e76c..9998188a18 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -79,8 +79,8 @@ class acp_storage public function overview($id, $mode) { - $form_name = 'acp_storage'; - add_form_key($form_name); + $form_key = 'acp_storage'; + add_form_key($form_key); // Template from adm/style $this->tpl_name = 'acp_storage'; @@ -93,6 +93,11 @@ class acp_storage $modified_storages = []; $messages = []; + if (!check_form_key($form_key)) + { + $messages[] = $this->lang->lang('FORM_INVALID'); + } + foreach ($this->storage_collection as $storage) { $storage_name = $storage->get_name(); From c2f508eec6d3350f7e690f2ca8ad64a947b9c7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sat, 9 Sep 2017 14:01:08 +0200 Subject: [PATCH 37/38] [ticket/15289] Remove common language from acp module PHPBB3-15289 --- phpBB/includes/acp/acp_storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index 9998188a18..ef1494a029 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -64,7 +64,7 @@ class acp_storage $this->storage_collection = $phpbb_container->get('storage.storage_collection'); // Add necesary language files - $this->lang->add_lang(['common', 'acp/storage']); + $this->lang->add_lang(['acp/storage']); /** * Add language strings From 2b864f51d89a25598a7a394c466220caa545ffdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sat, 9 Sep 2017 15:21:06 +0200 Subject: [PATCH 38/38] [ticket/15289] Add phpdoc PHPBB3-15289 --- phpBB/includes/acp/acp_storage.php | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index ef1494a029..b2647843f1 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -51,6 +51,10 @@ class acp_storage /** @var string */ public $u_action; + /** + * @param string $id + * @param string $mode + */ public function main($id, $mode) { global $phpbb_container, $phpbb_dispatcher; @@ -77,6 +81,10 @@ class acp_storage $this->overview($id, $mode); } + /** + * @param string $id + * @param string $mode + */ public function overview($id, $mode) { $form_key = 'acp_storage'; @@ -160,31 +168,69 @@ class acp_storage )); } + /** + * Get the current provider from config + * + * @param string $key Storage name + * @return string The current provider + */ protected function get_current_provider($storage_name) { return $this->config['storage\\' . $storage_name . '\\provider']; } + /** + * Get the new provider from the request + * + * @param string $key Storage name + * @return string The new provider + */ protected function get_new_provider($storage_name) { return $this->request->variable([$storage_name, 'provider'], ''); } + /** + * Get adapter definitions from a provider + * + * @param string $provider Provider class + * @return array Adapter definitions + */ protected function get_provider_options($provider) { return $this->provider_collection->get_by_class($provider)->get_options(); } + /** + * Get the current value of the definition of a storage from config + * + * @param string $storage_name Storage name + * @param string $definition Definition + * @return string Definition value + */ protected function get_current_definition($storage_name, $definition) { return $this->config['storage\\' . $storage_name . '\\config\\' . $definition]; } + /** + * Get the new value of the definition of a storage from the request + * + * @param string $storage_name Storage name + * @param string $definition Definition + * @return string Definition value + */ protected function get_new_definition($storage_name, $definition) { return $this->request->variable([$storage_name, $definition], ''); } + /** + * Validates data + * + * @param string $storage_name Storage name + * @param array $messages Reference to messages array + */ protected function validate_data($storage_name, &$messages) { $storage_title = $this->lang->lang('STORAGE_' . strtoupper($storage_name) . '_TITLE'); @@ -243,6 +289,11 @@ class acp_storage } } + /** + * Updates an storage with the info provided in the form + * + * @param string $storage_name Storage name + */ protected function update_storage_config($storage_name) { $current_options = $this->get_provider_options($this->get_current_provider($storage_name));