|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees: online genealogy |
|
5
|
|
|
* Copyright (C) 2019 webtrees development team |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* You should have received a copy of the GNU General Public License |
|
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
declare(strict_types=1); |
|
19
|
|
|
|
|
20
|
|
|
namespace Fisharebest\Webtrees\Http\Controllers; |
|
21
|
|
|
|
|
22
|
|
|
use Fisharebest\Localization\Locale\LocaleInterface; |
|
23
|
|
|
use Fisharebest\Webtrees\FlashMessages; |
|
24
|
|
|
use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel; |
|
25
|
|
|
use Fisharebest\Webtrees\I18N; |
|
26
|
|
|
use Fisharebest\Webtrees\Module\ModuleThemeInterface; |
|
27
|
|
|
use Fisharebest\Webtrees\Services\EmailService; |
|
28
|
|
|
use Fisharebest\Webtrees\Services\ModuleService; |
|
29
|
|
|
use Fisharebest\Webtrees\Site; |
|
30
|
|
|
use Illuminate\Support\Collection; |
|
31
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
32
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
33
|
|
|
|
|
34
|
|
|
use function assert; |
|
35
|
|
|
use function filter_var; |
|
36
|
|
|
|
|
37
|
|
|
use const FILTER_VALIDATE_DOMAIN; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Controller for site administration. |
|
41
|
|
|
*/ |
|
42
|
|
|
class AdminSiteController extends AbstractBaseController |
|
43
|
|
|
{ |
|
44
|
|
|
/** @var string */ |
|
45
|
|
|
protected $layout = 'layouts/administration'; |
|
46
|
|
|
|
|
47
|
|
|
/** @var EmailService */ |
|
48
|
|
|
private $email_service; |
|
49
|
|
|
|
|
50
|
|
|
/** @var ModuleService */ |
|
51
|
|
|
private $module_service; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* AdminSiteController constructor. |
|
55
|
|
|
* |
|
56
|
|
|
* @param EmailService $email_service |
|
57
|
|
|
* @param ModuleService $module_service |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __construct(EmailService $email_service, ModuleService $module_service) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->email_service = $email_service; |
|
62
|
|
|
$this->module_service = $module_service; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param ServerRequestInterface $request |
|
67
|
|
|
* |
|
68
|
|
|
* @return ResponseInterface |
|
69
|
|
|
*/ |
|
70
|
|
|
public function preferencesForm(ServerRequestInterface $request): ResponseInterface |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
$all_themes = $this->themeOptions(); |
|
73
|
|
|
|
|
74
|
|
|
$title = I18N::translate('Website preferences'); |
|
75
|
|
|
|
|
76
|
|
|
return $this->viewResponse('admin/site-preferences', [ |
|
77
|
|
|
'all_themes' => $all_themes, |
|
78
|
|
|
'max_execution_time' => (int) get_cfg_var('max_execution_time'), |
|
79
|
|
|
'title' => $title, |
|
80
|
|
|
]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return Collection |
|
85
|
|
|
*/ |
|
86
|
|
|
private function themeOptions(): Collection |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->module_service |
|
89
|
|
|
->findByInterface(ModuleThemeInterface::class) |
|
90
|
|
|
->map($this->module_service->titleMapper()); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param ServerRequestInterface $request |
|
95
|
|
|
* |
|
96
|
|
|
* @return ResponseInterface |
|
97
|
|
|
*/ |
|
98
|
|
|
public function preferencesSave(ServerRequestInterface $request): ResponseInterface |
|
99
|
|
|
{ |
|
100
|
|
|
$params = $request->getParsedBody(); |
|
101
|
|
|
|
|
102
|
|
|
$INDEX_DIRECTORY = $params['INDEX_DIRECTORY']; |
|
103
|
|
|
if (substr($INDEX_DIRECTORY, -1) !== '/') { |
|
104
|
|
|
$INDEX_DIRECTORY .= '/'; |
|
105
|
|
|
} |
|
106
|
|
|
if (is_dir($INDEX_DIRECTORY)) { |
|
107
|
|
|
Site::setPreference('INDEX_DIRECTORY', $INDEX_DIRECTORY); |
|
108
|
|
|
} else { |
|
109
|
|
|
FlashMessages::addMessage(I18N::translate('The folder “%s” does not exist.', e($INDEX_DIRECTORY)), 'danger'); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
Site::setPreference('THEME_DIR', $params['THEME_DIR']); |
|
113
|
|
|
Site::setPreference('ALLOW_CHANGE_GEDCOM', $params['ALLOW_CHANGE_GEDCOM']); |
|
114
|
|
|
Site::setPreference('TIMEZONE', $params['TIMEZONE']); |
|
115
|
|
|
|
|
116
|
|
|
FlashMessages::addMessage(I18N::translate('The website preferences have been updated.'), 'success'); |
|
117
|
|
|
$url = route(ControlPanel::class); |
|
118
|
|
|
|
|
119
|
|
|
return redirect($url); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param ServerRequestInterface $request |
|
124
|
|
|
* |
|
125
|
|
|
* @return ResponseInterface |
|
126
|
|
|
*/ |
|
127
|
|
|
public function registrationForm(ServerRequestInterface $request): ResponseInterface |
|
128
|
|
|
{ |
|
129
|
|
|
$locale = $request->getAttribute('locale'); |
|
130
|
|
|
assert($locale instanceof LocaleInterface); |
|
131
|
|
|
|
|
132
|
|
|
$title = I18N::translate('Sign-in and registration'); |
|
133
|
|
|
|
|
134
|
|
|
$registration_text_options = $this->registrationTextOptions(); |
|
135
|
|
|
|
|
136
|
|
|
return $this->viewResponse('admin/site-registration', [ |
|
137
|
|
|
'language_tag' => $locale->languageTag(), |
|
138
|
|
|
'registration_text_options' => $registration_text_options, |
|
139
|
|
|
'title' => $title, |
|
140
|
|
|
]); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* A list of registration rules (e.g. for an edit control). |
|
145
|
|
|
* |
|
146
|
|
|
* @return string[] |
|
147
|
|
|
*/ |
|
148
|
|
|
private function registrationTextOptions(): array |
|
149
|
|
|
{ |
|
150
|
|
|
return [ |
|
151
|
|
|
0 => I18N::translate('No predefined text'), |
|
152
|
|
|
1 => I18N::translate('Predefined text that states all users can request a user account'), |
|
153
|
|
|
2 => I18N::translate('Predefined text that states admin will decide on each request for a user account'), |
|
154
|
|
|
3 => I18N::translate('Predefined text that states only family members can request a user account'), |
|
155
|
|
|
4 => I18N::translate('Choose user defined welcome text typed below'), |
|
156
|
|
|
]; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param ServerRequestInterface $request |
|
161
|
|
|
* |
|
162
|
|
|
* @return ResponseInterface |
|
163
|
|
|
*/ |
|
164
|
|
|
public function registrationSave(ServerRequestInterface $request): ResponseInterface |
|
165
|
|
|
{ |
|
166
|
|
|
$locale = $request->getAttribute('locale'); |
|
167
|
|
|
assert($locale instanceof LocaleInterface); |
|
168
|
|
|
|
|
169
|
|
|
$params = $request->getParsedBody(); |
|
170
|
|
|
|
|
171
|
|
|
Site::setPreference('WELCOME_TEXT_AUTH_MODE', $params['WELCOME_TEXT_AUTH_MODE']); |
|
172
|
|
|
Site::setPreference('WELCOME_TEXT_AUTH_MODE_' . $locale->languageTag(), $params['WELCOME_TEXT_AUTH_MODE_4']); |
|
173
|
|
|
Site::setPreference('USE_REGISTRATION_MODULE', $params['USE_REGISTRATION_MODULE']); |
|
174
|
|
|
Site::setPreference('SHOW_REGISTER_CAUTION', $params['SHOW_REGISTER_CAUTION']); |
|
175
|
|
|
|
|
176
|
|
|
FlashMessages::addMessage(I18N::translate('The website preferences have been updated.'), 'success'); |
|
177
|
|
|
$url = route(ControlPanel::class); |
|
178
|
|
|
|
|
179
|
|
|
return redirect($url); |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.