]> git.mxchange.org Git - friendica.git/commitdiff
Refactor storage admin setting
authorPhilipp <admin@philipp.info>
Sun, 18 Jul 2021 20:36:06 +0000 (22:36 +0200)
committerPhilipp <admin@philipp.info>
Sat, 24 Jul 2021 17:00:58 +0000 (19:00 +0200)
src/Module/Admin/Storage.php
view/templates/admin/storage.tpl
view/theme/frio/templates/admin/storage.tpl [new file with mode: 0644]

index 1e1678b138b6bd62b0535a31ebfee786e6524be3..08d2df316b9e2725eca2bca3e7fff4dbcd0d3d96 100644 (file)
@@ -25,7 +25,6 @@ use Friendica\Core\Renderer;
 use Friendica\DI;
 use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
-use Psr\Log\LogLevel;
 
 class Storage extends BaseAdmin
 {
@@ -35,11 +34,11 @@ class Storage extends BaseAdmin
 
                self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage');
 
-               $storagebackend    = Strings::escapeTags(trim($_POST['storagebackend'] ?? ''));
+               $storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? ''));
 
                // save storage backend form
                if (DI::storageManager()->setBackend($storagebackend)) {
-                       $storage_opts     = DI::storage()->getOptions();
+                       $storage_opts        = DI::storage()->getOptions();
                        $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend);
                        $storage_opts_data   = [];
                        foreach ($storage_opts as $name => $info) {
@@ -75,8 +74,9 @@ class Storage extends BaseAdmin
        {
                parent::content($parameters);
 
-               $current_storage_backend = DI::storage();
+               $current_storage_backend    = DI::storage();
                $available_storage_backends = [];
+               $available_storage_forms    = [];
 
                // show legacy option only if it is the current backend:
                // once changed can't be selected anymore
@@ -86,14 +86,12 @@ class Storage extends BaseAdmin
 
                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);
+                       // 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) {
+                       $storage_form = [];
+                       foreach (DI::storageManager()->getByName($name)->getOptions() as $option => $info) {
                                $type = $info[0];
                                // Backward compatibilty with yesno field description
                                if ($type == 'yesno') {
@@ -102,24 +100,31 @@ class Storage extends BaseAdmin
                                        unset($info[4]);
                                }
 
-                               $info[0] = $storage_form_prefix . '_' . $name;
-                               $info['type'] = $type;
-                               $info['field'] = 'field_' . $type . '.tpl';
-                               $storage_form[$name] = $info;
+                               $info[0]               = $storage_form_prefix . '_' . $option;
+                               $info['type']          = $type;
+                               $info['field']         = 'field_' . $type . '.tpl';
+                               $storage_form[$option] = $info;
+                       }
+
+                       if (count($storage_form) > 0) {
+                               $available_storage_forms[] = [
+                                       'name' => $name,
+                                       'form' => $storage_form,
+                               ];
                        }
                }
 
                $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,
+                       '$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],
+                       '$availablestorageforms' => $available_storage_forms,
                ]);
        }
 }
index af4f1fbceda73073b2ca05364b1fa9eae07cfe89..760d97a6498f8cc4246077e57b112b03ce06e6d5 100644 (file)
@@ -4,10 +4,19 @@
        <form action="{{$baseurl}}/admin/storage" method="post">
                <input type='hidden' name='form_security_token' value="{{$form_security_token}}">
 
+               <h2>Storage Backend</h2>
+
                {{include file="field_select.tpl" field=$storagebackend}}
-               {{foreach from=$storageform item=$field}}
+               <div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div>
+
+               <h2>Storage Configuration</h2>
+
+               {{foreach from=$availablestorageforms item=$storage}}
+               <h3>{{$storage.name}}</h3>
+               {{foreach from=$storage.form item=$field}}
                {{include file=$field.field field=$field}}
                {{/foreach}}
+               {{/foreach}}
 
                <div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div>
 
diff --git a/view/theme/frio/templates/admin/storage.tpl b/view/theme/frio/templates/admin/storage.tpl
new file mode 100644 (file)
index 0000000..4174c07
--- /dev/null
@@ -0,0 +1,40 @@
+<link rel="stylesheet" href="view/theme/frio/css/mod_admin.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen"/>
+
+<div id="adminpage" class="adminpage generic-page-wrapper">
+       <h1>{{$title}} - {{$page}}</h1>
+
+       <form action="{{$baseurl}}/admin/storage" method="post">
+               <input type='hidden' name='form_security_token' value="{{$form_security_token}}">
+
+               <h2>Storage Backend</h2>
+
+               {{include file="field_select.tpl" field=$storagebackend}}
+               <input type="submit" name="page_site" class="btn btn-primary" value="{{$submit}}"/>
+
+               <h2>Storage Configuration</h2>
+
+               {{foreach from=$availablestorageforms item=$storage}}
+               <div class="panel">
+                       <div class="section-subtitle-wrapper panel-heading" role="tab" id="admin-settings-upload">
+                               <h3>
+                                       <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#admin-settings" href="#admin-settings-upload-collapse" aria-expanded="false" aria-controls="admin-settings-upload-collapse">
+                                               {{$storage.name}}
+                                       </a>
+                               </h3>
+                       </div>
+                       <div id="admin-settings-upload-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-upload">
+                               <div class="panel-body">
+                                       {{foreach from=$storage.form item=$field}}
+                                       {{include file=$field.field field=$field}}
+                                       {{/foreach}}
+                               </div>
+                               <div class="panel-footer">
+                                       <input type="submit" name="page_site" class="btn btn-primary" value="{{$submit}}"/>
+                               </div>
+                       </div>
+               </div>
+
+               {{/foreach}}
+
+       </form>
+</div>