]> git.mxchange.org Git - friendica.git/commitdiff
Extract Storage admin section to own page
authorPhilipp <admin@philipp.info>
Sun, 18 Jul 2021 20:09:11 +0000 (22:09 +0200)
committerPhilipp <admin@philipp.info>
Sat, 24 Jul 2021 17:00:58 +0000 (19:00 +0200)
src/Module/Admin/Site.php
src/Module/Admin/Storage.php [new file with mode: 0644]
src/Module/BaseAdmin.php
static/routes.config.php
view/templates/admin/site.tpl
view/templates/admin/storage.tpl [new file with mode: 0644]
view/theme/frio/templates/admin/site.tpl

index 068b013269b4d2db9f42e2cc7e86c8447d6cdb4e..9d0e9c9dad3a329f148411683ab007cfe283d1b6 100644 (file)
@@ -212,39 +212,6 @@ class Site extends BaseAdmin
                $relay_user_tags   = !empty($_POST['relay_user_tags']);
                $active_panel      = (!empty($_POST['active_panel'])      ? "#" . Strings::escapeTags(trim($_POST['active_panel'])) : '');
 
-               $storagebackend    = Strings::escapeTags(trim($_POST['storagebackend'] ?? ''));
-
-               // save storage backend form
-               if (DI::storageManager()->setBackend($storagebackend)) {
-                       $storage_opts     = DI::storage()->getOptions();
-                       $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend);
-                       $storage_opts_data   = [];
-                       foreach ($storage_opts as $name => $info) {
-                               $fieldname = $storage_form_prefix . '_' . $name;
-                               switch ($info[0]) { // type
-                                       case 'checkbox':
-                                       case 'yesno':
-                                               $value = !empty($_POST[$fieldname]);
-                                               break;
-                                       default:
-                                               $value = $_POST[$fieldname] ?? '';
-                               }
-                               $storage_opts_data[$name] = $value;
-                       }
-                       unset($name);
-                       unset($info);
-
-                       $storage_form_errors = DI::storage()->saveOptions($storage_opts_data);
-                       if (count($storage_form_errors)) {
-                               foreach ($storage_form_errors as $name => $err) {
-                                       notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err);
-                               }
-                               DI::baseUrl()->redirect('admin/site' . $active_panel);
-                       }
-               } elseif (!empty($storagebackend)) {
-                       notice(DI::l10n()->t('Invalid storage backend setting value.'));
-               }
-
                // Has the directory url changed? If yes, then resubmit the existing profiles there
                if ($global_directory != DI::config()->get('system', 'directory') && ($global_directory != '')) {
                        DI::config()->set('system', 'directory', $global_directory);
@@ -526,40 +493,6 @@ class Site extends BaseAdmin
 
                $diaspora_able = (DI::baseUrl()->getUrlPath() == '');
 
-               $current_storage_backend = DI::storage();
-               $available_storage_backends = [];
-
-               // show legacy option only if it is the current backend:
-               // once changed can't be selected anymore
-               if ($current_storage_backend == null) {
-                       $available_storage_backends[''] = DI::l10n()->t('Database (legacy)');
-               }
-
-               foreach (DI::storageManager()->listBackends() as $name => $class) {
-                       $available_storage_backends[$name] = $name;
-               }
-
-               // build storage config form,
-               $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|' ,'', $current_storage_backend);
-
-               $storage_form = [];
-               if (!is_null($current_storage_backend) && $current_storage_backend != '') {
-                       foreach ($current_storage_backend->getOptions() as $name => $info) {
-                               $type = $info[0];
-                               // Backward compatibilty with yesno field description
-                               if ($type == 'yesno') {
-                                       $type = 'checkbox';
-                                       // Remove translated labels Yes No from field info
-                                       unset($info[4]);
-                               }
-
-                               $info[0] = $storage_form_prefix . '_' . $name;
-                               $info['type'] = $type;
-                               $info['field'] = 'field_' . $type . '.tpl';
-                               $storage_form[$name] = $info;
-                       }
-               }
-
                $t = Renderer::getMarkupTemplate('admin/site.tpl');
                return Renderer::replaceMacros($t, [
                        '$title'             => DI::l10n()->t('Administration'),
@@ -600,8 +533,6 @@ class Site extends BaseAdmin
                        '$hide_help'        => ['hide_help', DI::l10n()->t('Hide help entry from navigation menu'), DI::config()->get('system', 'hide_help'), DI::l10n()->t('Hides the menu entry for the Help pages from the navigation menu. You can still access it calling /help directly.')],
                        '$singleuser'       => ['singleuser', DI::l10n()->t('Single user instance'), DI::config()->get('system', 'singleuser', '---'), DI::l10n()->t('Make this instance multi-user or single-user for the named user'), $user_names],
 
-                       '$storagebackend'   => ['storagebackend', DI::l10n()->t('File storage backend'), $current_storage_backend, DI::l10n()->t('The backend used to store uploaded data. If you change the storage backend, you can manually move the existing files. If you do not do so, the files uploaded before the change will still be available at the old backend. Please see <a href="/help/Settings#1_2_3_1">the settings documentation</a> for more information about the choices and the moving procedure.'), $available_storage_backends],
-                       '$storageform'      => $storage_form,
                        '$maximagesize'     => ['maximagesize', DI::l10n()->t('Maximum image size'), DI::config()->get('system', 'maximagesize'), DI::l10n()->t('Maximum size in bytes of uploaded images. Default is 0, which means no limits.')],
                        '$maximagelength'   => ['maximagelength', DI::l10n()->t('Maximum image length'), DI::config()->get('system', 'max_image_length'), DI::l10n()->t('Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.')],
                        '$jpegimagequality' => ['jpegimagequality', DI::l10n()->t('JPEG image quality'), DI::config()->get('system', 'jpeg_quality'), DI::l10n()->t('Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.')],
diff --git a/src/Module/Admin/Storage.php b/src/Module/Admin/Storage.php
new file mode 100644 (file)
index 0000000..1e1678b
--- /dev/null
@@ -0,0 +1,125 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Admin;
+
+use Friendica\Core\Renderer;
+use Friendica\DI;
+use Friendica\Module\BaseAdmin;
+use Friendica\Util\Strings;
+use Psr\Log\LogLevel;
+
+class Storage extends BaseAdmin
+{
+       public static function post(array $parameters = [])
+       {
+               self::checkAdminAccess();
+
+               self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage');
+
+               $storagebackend    = Strings::escapeTags(trim($_POST['storagebackend'] ?? ''));
+
+               // save storage backend form
+               if (DI::storageManager()->setBackend($storagebackend)) {
+                       $storage_opts     = DI::storage()->getOptions();
+                       $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend);
+                       $storage_opts_data   = [];
+                       foreach ($storage_opts as $name => $info) {
+                               $fieldname = $storage_form_prefix . '_' . $name;
+                               switch ($info[0]) { // type
+                                       case 'checkbox':
+                                       case 'yesno':
+                                               $value = !empty($_POST[$fieldname]);
+                                               break;
+                                       default:
+                                               $value = $_POST[$fieldname] ?? '';
+                               }
+                               $storage_opts_data[$name] = $value;
+                       }
+                       unset($name);
+                       unset($info);
+
+                       $storage_form_errors = DI::storage()->saveOptions($storage_opts_data);
+                       if (count($storage_form_errors)) {
+                               foreach ($storage_form_errors as $name => $err) {
+                                       notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err);
+                               }
+                               DI::baseUrl()->redirect('admin/storage');
+                       }
+               } elseif (!empty($storagebackend)) {
+                       notice(DI::l10n()->t('Invalid storage backend setting value.'));
+               }
+
+               DI::baseUrl()->redirect('admin/storage');
+       }
+
+       public static function content(array $parameters = [])
+       {
+               parent::content($parameters);
+
+               $current_storage_backend = DI::storage();
+               $available_storage_backends = [];
+
+               // show legacy option only if it is the current backend:
+               // once changed can't be selected anymore
+               if ($current_storage_backend == null) {
+                       $available_storage_backends[''] = DI::l10n()->t('Database (legacy)');
+               }
+
+               foreach (DI::storageManager()->listBackends() as $name => $class) {
+                       $available_storage_backends[$name] = $name;
+               }
+
+               // build storage config form,
+               $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|' ,'', $current_storage_backend);
+
+               $storage_form = [];
+               if (!is_null($current_storage_backend) && $current_storage_backend != '') {
+                       foreach ($current_storage_backend->getOptions() as $name => $info) {
+                               $type = $info[0];
+                               // Backward compatibilty with yesno field description
+                               if ($type == 'yesno') {
+                                       $type = 'checkbox';
+                                       // Remove translated labels Yes No from field info
+                                       unset($info[4]);
+                               }
+
+                               $info[0] = $storage_form_prefix . '_' . $name;
+                               $info['type'] = $type;
+                               $info['field'] = 'field_' . $type . '.tpl';
+                               $storage_form[$name] = $info;
+                       }
+               }
+
+               $t = Renderer::getMarkupTemplate('admin/storage.tpl');
+
+               return Renderer::replaceMacros($t, [
+                       '$title' => DI::l10n()->t('Administration'),
+                       '$page' => DI::l10n()->t('Storage'),
+                       '$submit' => DI::l10n()->t('Save Settings'),
+                       '$clear' => DI::l10n()->t('Clear'),
+                       '$baseurl' => DI::baseUrl()->get(true),
+                       '$form_security_token' => self::getFormSecurityToken("admin_storage"),
+                       '$storagebackend'   => ['storagebackend', DI::l10n()->t('File storage backend'), $current_storage_backend, DI::l10n()->t('The backend used to store uploaded data. If you change the storage backend, you can manually move the existing files. If you do not do so, the files uploaded before the change will still be available at the old backend. Please see <a href="/help/Settings#1_2_3_1">the settings documentation</a> for more information about the choices and the moving procedure.'), $available_storage_backends],
+                       '$storageform'      => $storage_form,
+               ]);
+       }
+}
index 90b246e432f0640cea9aa080207afbf456d2690b..5d5841f994662aea0b1b15c68d0f9219f6615eea 100644 (file)
@@ -88,6 +88,7 @@ abstract class BaseAdmin extends BaseModule
                        ]],
                        'configuration' => [DI::l10n()->t('Configuration'), [
                                'site'         => ['admin/site'        , DI::l10n()->t('Site')                    , 'site'],
+                               'storage'      => ['admin/storage'     , DI::l10n()->t('Storage')                 , 'storage'],
                                'users'        => ['admin/users'       , DI::l10n()->t('Users')                   , 'users'],
                                'addons'       => ['admin/addons'      , DI::l10n()->t('Addons')                  , 'addons'],
                                'themes'       => ['admin/themes'      , DI::l10n()->t('Themes')                  , 'themes'],
index 9780bf3cbee098e25aceb86c4d937951cb80003c..05e266ff1023efad588e5da77a4b98a41085f371 100644 (file)
@@ -198,6 +198,8 @@ return [
 
                '/site' => [Module\Admin\Site::class, [R::GET, R::POST]],
 
+               '/storage' => [Module\Admin\Storage::class, [R::GET, R::POST]],
+
                '/themes'               => [Module\Admin\Themes\Index::class,   [R::GET, R::POST]],
                '/themes/{theme}'       => [Module\Admin\Themes\Details::class, [R::GET, R::POST]],
                '/themes/{theme}/embed' => [Module\Admin\Themes\Embed::class,   [R::GET, R::POST]],
index 64d49d3a31a93ab2d66d2a3d5f1411d4c3ee9bea..493abef61ec4150697a5016c13622e70b9f49de7 100644 (file)
                <div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
 
                <h2>{{$upload}}</h2>
-               {{include file="field_select.tpl" field=$storagebackend}}
-               {{foreach from=$storageform item=$field}}
-                       {{include file=$field.field field=$field}}
-               {{/foreach}}
-               <hr>
                {{include file="field_input.tpl" field=$maximagesize}}
                {{include file="field_input.tpl" field=$maximagelength}}
                {{include file="field_input.tpl" field=$jpegimagequality}}
diff --git a/view/templates/admin/storage.tpl b/view/templates/admin/storage.tpl
new file mode 100644 (file)
index 0000000..af4f1fb
--- /dev/null
@@ -0,0 +1,15 @@
+<div id='adminpage'>
+       <h1>{{$title}} - {{$page}}</h1>
+
+       <form action="{{$baseurl}}/admin/storage" method="post">
+               <input type='hidden' name='form_security_token' value="{{$form_security_token}}">
+
+               {{include file="field_select.tpl" field=$storagebackend}}
+               {{foreach from=$storageform item=$field}}
+               {{include file=$field.field field=$field}}
+               {{/foreach}}
+
+               <div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div>
+
+       </form>
+</div>
index ad8715177711f93826bfe266b0a30f0d801e38be..ef8ef9786dbe43134c9a52f99710ee87602258de 100644 (file)
                                </div>
                                <div id="admin-settings-upload-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-upload">
                                        <div class="panel-body">
-                                               {{include file="field_select.tpl" field=$storagebackend}}
-                                               {{foreach from=$storageform item=$field}}
-                                                       {{include file=$field.field field=$field}}
-                                               {{/foreach}}
-                                               <hr>
                                                {{include file="field_input.tpl" field=$maximagesize}}
                                                {{include file="field_input.tpl" field=$maximagelength}}
                                                {{include file="field_input.tpl" field=$jpegimagequality}}