]> git.mxchange.org Git - friendica.git/blob - src/Core/Storage/Type/FilesystemConfig.php
Merge pull request #11015 from MrPetovan/task/10979-frio-time-tooltip
[friendica.git] / src / Core / Storage / Type / FilesystemConfig.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Core\Storage\Type;
23
24 use Friendica\Core\Config\Capability\IManageConfigValues;
25 use Friendica\Core\L10n;
26 use Friendica\Core\Storage\Capability\ICanConfigureStorage;
27
28 /**
29  * Filesystem based storage backend configuration
30  */
31 class FilesystemConfig implements ICanConfigureStorage
32 {
33         // Default base folder
34         const DEFAULT_BASE_FOLDER = 'storage';
35
36         /** @var IManageConfigValues */
37         private $config;
38
39         /** @var string */
40         private $storagePath;
41
42         /** @var L10n */
43         private $l10n;
44
45         /**
46          * Returns the current storage path
47          *
48          * @return string
49          */
50         public function getStoragePath(): string
51         {
52                 return $this->storagePath;
53         }
54
55         /**
56          * Filesystem constructor.
57          *
58          * @param IManageConfigValues $config
59          * @param L10n                $l10n
60          */
61         public function __construct(IManageConfigValues $config, L10n $l10n)
62         {
63                 $this->config = $config;
64                 $this->l10n   = $l10n;
65
66                 $path              = $this->config->get('storage', 'filesystem_path', self::DEFAULT_BASE_FOLDER);
67                 $this->storagePath = rtrim($path, '/');
68         }
69
70         /**
71          * @inheritDoc
72          */
73         public function getOptions(): array
74         {
75                 return [
76                         'storagepath' => [
77                                 'input',
78                                 $this->l10n->t('Storage base path'),
79                                 $this->storagePath,
80                                 $this->l10n->t('Folder where uploaded files are saved. For maximum security, This should be a path outside web server folder tree')
81                         ]
82                 ];
83         }
84
85         /**
86          * @inheritDoc
87          */
88         public function saveOptions(array $data): array
89         {
90                 $storagePath = $data['storagepath'] ?? '';
91                 if ($storagePath === '' || !is_dir($storagePath)) {
92                         return [
93                                 'storagepath' => $this->l10n->t('Enter a valid existing folder')
94                         ];
95                 };
96                 $this->config->set('storage', 'filesystem_path', $storagePath);
97                 $this->storagePath = $storagePath;
98                 return [];
99         }
100 }