]> git.mxchange.org Git - friendica.git/blob - src/App.php
Merge remote-tracking branch 'upstream/develop' into share-rework
[friendica.git] / src / App.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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;
23
24 use Exception;
25 use Friendica\App\Arguments;
26 use Friendica\App\BaseURL;
27 use Friendica\Capabilities\ICanCreateResponses;
28 use Friendica\Core\Config\Factory\Config;
29 use Friendica\Core\Session\Capability\IHandleSessions;
30 use Friendica\Core\Session\Capability\IHandleUserSessions;
31 use Friendica\Module\Maintenance;
32 use Friendica\Security\Authentication;
33 use Friendica\Core\Config\ValueObject\Cache;
34 use Friendica\Core\Config\Capability\IManageConfigValues;
35 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
36 use Friendica\Core\L10n;
37 use Friendica\Core\System;
38 use Friendica\Core\Theme;
39 use Friendica\Database\Database;
40 use Friendica\Model\Contact;
41 use Friendica\Model\Profile;
42 use Friendica\Module\Special\HTTPException as ModuleHTTPException;
43 use Friendica\Network\HTTPException;
44 use Friendica\Util\DateTimeFormat;
45 use Friendica\Util\HTTPInputData;
46 use Friendica\Util\HTTPSignature;
47 use Friendica\Util\Profiler;
48 use Friendica\Util\Strings;
49 use Psr\Log\LoggerInterface;
50
51 /**
52  * Our main application structure for the life of this page.
53  *
54  * Primarily deals with the URL that got us here
55  * and tries to make some sense of it, and
56  * stores our page contents and config storage
57  * and anything else that might need to be passed around
58  * before we spit the page out.
59  *
60  */
61 class App
62 {
63         const PLATFORM = 'Friendica';
64         const CODENAME = 'Giant Rhubarb';
65         const VERSION  = '2022.12-dev';
66
67         // Allow themes to control internal parameters
68         // by changing App values in theme.php
69         private $theme_info = [
70                 'videowidth'        => 425,
71                 'videoheight'       => 350,
72                 'events_in_profile' => true
73         ];
74
75         private $user_id       = 0;
76         private $nickname      = '';
77         private $timezone      = '';
78         private $profile_owner = 0;
79         private $contact_id    = 0;
80         private $queue         = [];
81
82         /**
83          * @var App\Mode The Mode of the Application
84          */
85         private $mode;
86
87         /**
88          * @var BaseURL
89          */
90         private $baseURL;
91
92         /** @var string The name of the current theme */
93         private $currentTheme;
94         /** @var string The name of the current mobile theme */
95         private $currentMobileTheme;
96
97         /**
98          * @var IManageConfigValues The config
99          */
100         private $config;
101
102         /**
103          * @var LoggerInterface The logger
104          */
105         private $logger;
106
107         /**
108          * @var Profiler The profiler of this app
109          */
110         private $profiler;
111
112         /**
113          * @var Database The Friendica database connection
114          */
115         private $database;
116
117         /**
118          * @var L10n The translator
119          */
120         private $l10n;
121
122         /**
123          * @var App\Arguments
124          */
125         private $args;
126
127         /**
128          * @var IManagePersonalConfigValues
129          */
130         private $pConfig;
131
132         /**
133          * @var IHandleSessions
134          */
135         private $session;
136
137         /**
138          * @var IHandleUserSessions
139          */
140         private $userSession;
141
142         /**
143          * Set the user ID
144          *
145          * @param int $user_id
146          * @return void
147          */
148         public function setLoggedInUserId(int $user_id)
149         {
150                 $this->user_id = $user_id;
151         }
152
153         /**
154          * Set the nickname
155          *
156          * @param int $user_id
157          * @return void
158          */
159         public function setLoggedInUserNickname(string $nickname)
160         {
161                 $this->nickname = $nickname;
162         }
163
164         public function isLoggedIn(): bool
165         {
166                 return $this->userSession->getLocalUserId() && $this->user_id && ($this->user_id == $this->userSession->getLocalUserId());
167         }
168
169         /**
170          * Check if current user has admin role.
171          *
172          * @return bool true if user is an admin
173          */
174         public function isSiteAdmin(): bool
175         {
176                 $admin_email = $this->config->get('config', 'admin_email');
177
178                 $adminlist = explode(',', str_replace(' ', '', $admin_email));
179
180                 return $this->userSession->getLocalUserId() && $admin_email && $this->database->exists('user', ['uid' => $this->getLoggedInUserId(), 'email' => $adminlist]);
181         }
182
183         /**
184          * Fetch the user id
185          * @return int User id
186          */
187         public function getLoggedInUserId(): int
188         {
189                 return $this->user_id;
190         }
191
192         /**
193          * Fetch the user nick name
194          * @return string User's nickname
195          */
196         public function getLoggedInUserNickname(): string
197         {
198                 return $this->nickname;
199         }
200
201         /**
202          * Set the profile owner ID
203          *
204          * @param int $owner_id
205          * @return void
206          */
207         public function setProfileOwner(int $owner_id)
208         {
209                 $this->profile_owner = $owner_id;
210         }
211
212         /**
213          * Get the profile owner ID
214          *
215          * @return int
216          */
217         public function getProfileOwner(): int
218         {
219                 return $this->profile_owner;
220         }
221
222         /**
223          * Set the contact ID
224          *
225          * @param int $contact_id
226          * @return void
227          */
228         public function setContactId(int $contact_id)
229         {
230                 $this->contact_id = $contact_id;
231         }
232
233         /**
234          * Get the contact ID
235          *
236          * @return int
237          */
238         public function getContactId(): int
239         {
240                 return $this->contact_id;
241         }
242
243         /**
244          * Set the timezone
245          *
246          * @param string $timezone A valid time zone identifier, see https://www.php.net/manual/en/timezones.php
247          * @return void
248          */
249         public function setTimeZone(string $timezone)
250         {
251                 $this->timezone = (new \DateTimeZone($timezone))->getName();
252                 DateTimeFormat::setLocalTimeZone($this->timezone);
253         }
254
255         /**
256          * Get the timezone
257          *
258          * @return int
259          */
260         public function getTimeZone(): string
261         {
262                 return $this->timezone;
263         }
264
265         /**
266          * Set workerqueue information
267          *
268          * @param array $queue 
269          * @return void 
270          */
271         public function setQueue(array $queue)
272         {
273                 $this->queue = $queue;
274         }
275
276         /**
277          * Fetch workerqueue information
278          *
279          * @return array Worker queue
280          */
281         public function getQueue(): array
282         {
283                 return $this->queue ?? [];
284         }
285
286         /**
287          * Fetch a specific workerqueue field
288          *
289          * @param string $index Work queue record to fetch
290          * @return mixed Work queue item or NULL if not found
291          */
292         public function getQueueValue(string $index)
293         {
294                 return $this->queue[$index] ?? null;
295         }
296
297         public function setThemeInfoValue(string $index, $value)
298         {
299                 $this->theme_info[$index] = $value;
300         }
301
302         public function getThemeInfo()
303         {
304                 return $this->theme_info;
305         }
306
307         public function getThemeInfoValue(string $index, $default = null)
308         {
309                 return $this->theme_info[$index] ?? $default;
310         }
311
312         /**
313          * Returns the current config cache of this node
314          *
315          * @return Cache
316          */
317         public function getConfigCache()
318         {
319                 return $this->config->getCache();
320         }
321
322         /**
323          * The basepath of this app
324          *
325          * @return string Base path from configuration
326          */
327         public function getBasePath(): string
328         {
329                 // Don't use the basepath of the config table for basepath (it should always be the config-file one)
330                 return $this->config->getCache()->get('system', 'basepath');
331         }
332
333         /**
334          * @param Database                    $database The Friendica Database
335          * @param IManageConfigValues         $config   The Configuration
336          * @param App\Mode                    $mode     The mode of this Friendica app
337          * @param BaseURL                     $baseURL  The full base URL of this Friendica app
338          * @param LoggerInterface             $logger   The current app logger
339          * @param Profiler                    $profiler The profiler of this application
340          * @param L10n                        $l10n     The translator instance
341          * @param App\Arguments               $args     The Friendica Arguments of the call
342          * @param IManagePersonalConfigValues $pConfig  Personal configuration
343          * @param IHandleSessions             $session  The Session handler
344          */
345         public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, IManagePersonalConfigValues $pConfig, IHandleSessions $session, IHandleUserSessions $userSession)
346         {
347                 $this->database    = $database;
348                 $this->config      = $config;
349                 $this->mode        = $mode;
350                 $this->baseURL     = $baseURL;
351                 $this->profiler    = $profiler;
352                 $this->logger      = $logger;
353                 $this->l10n        = $l10n;
354                 $this->args        = $args;
355                 $this->pConfig     = $pConfig;
356                 $this->session     = $session;
357                 $this->userSession = $userSession;
358
359                 $this->load();
360         }
361
362         /**
363          * Load the whole app instance
364          */
365         public function load()
366         {
367                 set_time_limit(0);
368
369                 // Normally this constant is defined - but not if "pcntl" isn't installed
370                 if (!defined('SIGTERM')) {
371                         define('SIGTERM', 15);
372                 }
373
374                 // Ensure that all "strtotime" operations do run timezone independent
375                 date_default_timezone_set('UTC');
376
377                 // This has to be quite large to deal with embedded private photos
378                 ini_set('pcre.backtrack_limit', 500000);
379
380                 set_include_path(
381                         get_include_path() . PATH_SEPARATOR
382                         . $this->getBasePath() . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR
383                         . $this->getBasePath() . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
384                         . $this->getBasePath());
385
386                 $this->profiler->reset();
387
388                 if ($this->mode->has(App\Mode::DBAVAILABLE)) {
389                         $this->profiler->update($this->config);
390
391                         Core\Hook::loadHooks();
392                         $loader = (new Config())->createConfigFileLoader($this->getBasePath(), $_SERVER);
393                         Core\Hook::callAll('load_config', $loader);
394                 }
395
396                 $this->loadDefaultTimezone();
397                 // Register template engines
398                 Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine');
399         }
400
401         /**
402          * Loads the default timezone
403          *
404          * Include support for legacy $default_timezone
405          *
406          * @global string $default_timezone
407          */
408         private function loadDefaultTimezone()
409         {
410                 if ($this->config->get('system', 'default_timezone')) {
411                         $timezone = $this->config->get('system', 'default_timezone', 'UTC');
412                 } else {
413                         global $default_timezone;
414                         $timezone = $default_timezone ?? '' ?: 'UTC';
415                 }
416
417                 $this->setTimeZone($timezone);
418         }
419
420         /**
421          * Returns the current theme name. May be overriden by the mobile theme name.
422          *
423          * @return string Current theme name or empty string in installation phase
424          * @throws Exception
425          */
426         public function getCurrentTheme(): string
427         {
428                 if ($this->mode->isInstall()) {
429                         return '';
430                 }
431
432                 // Specific mobile theme override
433                 if (($this->mode->isMobile() || $this->mode->isTablet()) && $this->session->get('show-mobile', true)) {
434                         $user_mobile_theme = $this->getCurrentMobileTheme();
435
436                         // --- means same mobile theme as desktop
437                         if (!empty($user_mobile_theme) && $user_mobile_theme !== '---') {
438                                 return $user_mobile_theme;
439                         }
440                 }
441
442                 if (!$this->currentTheme) {
443                         $this->computeCurrentTheme();
444                 }
445
446                 return $this->currentTheme;
447         }
448
449         /**
450          * Returns the current mobile theme name.
451          *
452          * @return string Mobile theme name or empty string if installer
453          * @throws Exception
454          */
455         public function getCurrentMobileTheme(): string
456         {
457                 if ($this->mode->isInstall()) {
458                         return '';
459                 }
460
461                 if (is_null($this->currentMobileTheme)) {
462                         $this->computeCurrentMobileTheme();
463                 }
464
465                 return $this->currentMobileTheme;
466         }
467
468         /**
469          * Setter for current theme name
470          *
471          * @param string $theme Name of current theme
472          */
473         public function setCurrentTheme(string $theme)
474         {
475                 $this->currentTheme = $theme;
476         }
477
478         /**
479          * Setter for current mobile theme name
480          *
481          * @param string $theme Name of current mobile theme
482          */
483         public function setCurrentMobileTheme(string $theme)
484         {
485                 $this->currentMobileTheme = $theme;
486         }
487
488         /**
489          * Computes the current theme name based on the node settings, the page owner settings and the user settings
490          *
491          * @throws Exception
492          */
493         private function computeCurrentTheme()
494         {
495                 $system_theme = $this->config->get('system', 'theme');
496                 if (!$system_theme) {
497                         throw new Exception($this->l10n->t('No system theme config value set.'));
498                 }
499
500                 // Sane default
501                 $this->setCurrentTheme($system_theme);
502
503                 $page_theme = null;
504                 // Find the theme that belongs to the user whose stuff we are looking at
505                 if (!empty($this->profile_owner) && ($this->profile_owner != $this->userSession->getLocalUserId())) {
506                         // Allow folks to override user themes and always use their own on their own site.
507                         // This works only if the user is on the same server
508                         $user = $this->database->selectFirst('user', ['theme'], ['uid' => $this->profile_owner]);
509                         if ($this->database->isResult($user) && !$this->userSession->getLocalUserId()) {
510                                 $page_theme = $user['theme'];
511                         }
512                 }
513
514                 $theme_name = $page_theme ?: $this->session->get('theme', $system_theme);
515
516                 $theme_name = Strings::sanitizeFilePathItem($theme_name);
517                 if ($theme_name
518                     && in_array($theme_name, Theme::getAllowedList())
519                     && (file_exists('view/theme/' . $theme_name . '/style.css')
520                         || file_exists('view/theme/' . $theme_name . '/style.php'))
521                 ) {
522                         $this->setCurrentTheme($theme_name);
523                 }
524         }
525
526         /**
527          * Computes the current mobile theme name based on the node settings, the page owner settings and the user settings
528          */
529         private function computeCurrentMobileTheme()
530         {
531                 $system_mobile_theme = $this->config->get('system', 'mobile-theme', '');
532
533                 // Sane default
534                 $this->setCurrentMobileTheme($system_mobile_theme);
535
536                 $page_mobile_theme = null;
537                 // Find the theme that belongs to the user whose stuff we are looking at
538                 if (!empty($this->profile_owner) && ($this->profile_owner != $this->userSession->getLocalUserId())) {
539                         // Allow folks to override user themes and always use their own on their own site.
540                         // This works only if the user is on the same server
541                         if (!$this->userSession->getLocalUserId()) {
542                                 $page_mobile_theme = $this->pConfig->get($this->profile_owner, 'system', 'mobile-theme');
543                         }
544                 }
545
546                 $mobile_theme_name = $page_mobile_theme ?: $this->session->get('mobile-theme', $system_mobile_theme);
547
548                 $mobile_theme_name = Strings::sanitizeFilePathItem($mobile_theme_name);
549                 if ($mobile_theme_name == '---'
550                         ||
551                         in_array($mobile_theme_name, Theme::getAllowedList())
552                         && (file_exists('view/theme/' . $mobile_theme_name . '/style.css')
553                                 || file_exists('view/theme/' . $mobile_theme_name . '/style.php'))
554                 ) {
555                         $this->setCurrentMobileTheme($mobile_theme_name);
556                 }
557         }
558
559         /**
560          * Provide a sane default if nothing is chosen or the specified theme does not exist.
561          *
562          * @return string Current theme's stylsheet path
563          * @throws Exception
564          */
565         public function getCurrentThemeStylesheetPath(): string
566         {
567                 return Core\Theme::getStylesheetPath($this->getCurrentTheme());
568         }
569
570         /**
571          * Sets the base url for use in cmdline programs which don't have
572          * $_SERVER variables
573          */
574         public function checkURL()
575         {
576                 $url = $this->config->get('system', 'url');
577
578                 // if the url isn't set or the stored url is radically different
579                 // than the currently visited url, store the current value accordingly.
580                 // "Radically different" ignores common variations such as http vs https
581                 // and www.example.com vs example.com.
582                 // We will only change the url to an ip address if there is no existing setting
583
584                 if (empty($url) || (!Util\Strings::compareLink($url, $this->baseURL->get())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->baseURL->getHostname()))) {
585                         $this->config->set('system', 'url', $this->baseURL->get());
586                 }
587         }
588
589         /**
590          * Frontend App script
591          *
592          * The App object behaves like a container and a dispatcher at the same time, including a representation of the
593          * request and a representation of the response.
594          *
595          * This probably should change to limit the size of this monster method.
596          *
597          * @param App\Router                  $router
598          * @param IManagePersonalConfigValues $pconfig
599          * @param Authentication              $auth       The Authentication backend of the node
600          * @param App\Page                    $page       The Friendica page printing container
601          * @param HTTPInputData               $httpInput  A library for processing PHP input streams
602          * @param float                       $start_time The start time of the overall script execution
603          *
604          * @throws HTTPException\InternalServerErrorException
605          * @throws \ImagickException
606          */
607         public function runFrontend(App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, HTTPInputData $httpInput, float $start_time)
608         {
609                 $this->profiler->set($start_time, 'start');
610                 $this->profiler->set(microtime(true), 'classinit');
611
612                 $moduleName = $this->args->getModuleName();
613                 $page->setLogging($this->args->getMethod(), $this->args->getModuleName(), $this->args->getCommand());
614
615                 try {
616                         // Missing DB connection: ERROR
617                         if ($this->mode->has(App\Mode::LOCALCONFIGPRESENT) && !$this->mode->has(App\Mode::DBAVAILABLE)) {
618                                 throw new HTTPException\InternalServerErrorException($this->l10n->t('Apologies but the website is unavailable at the moment.'));
619                         }
620
621                         if (!$this->mode->isInstall()) {
622                                 // Force SSL redirection
623                                 if ($this->baseURL->checkRedirectHttps()) {
624                                         System::externalRedirect($this->baseURL->get() . '/' . $this->args->getQueryString());
625                                 }
626
627                                 Core\Hook::callAll('init_1');
628                         }
629
630                         if ($this->mode->isNormal() && !$this->mode->isBackend()) {
631                                 $requester = HTTPSignature::getSigner('', $_SERVER);
632                                 if (!empty($requester)) {
633                                         Profile::addVisitorCookieForHandle($requester);
634                                 }
635                         }
636
637                         // ZRL
638                         if (!empty($_GET['zrl']) && $this->mode->isNormal() && !$this->mode->isBackend() && !$this->userSession->getLocalUserId()) {
639                                 // Only continue when the given profile link seems valid
640                                 // Valid profile links contain a path with "/profile/" and no query parameters
641                                 if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == '') &&
642                                         strstr(parse_url($_GET['zrl'], PHP_URL_PATH), '/profile/')) {
643                                         if ($this->session->get('visitor_home') != $_GET['zrl']) {
644                                                 $this->session->set('my_url', $_GET['zrl']);
645                                                 $this->session->set('authenticated', 0);
646
647                                                 $remote_contact = Contact::getByURL($_GET['zrl'], false, ['subscribe']);
648                                                 if (!empty($remote_contact['subscribe'])) {
649                                                         $_SESSION['remote_comment'] = $remote_contact['subscribe'];
650                                                 }
651                                         }
652
653                                         Model\Profile::zrlInit($this);
654                                 } else {
655                                         // Someone came with an invalid parameter, maybe as a DDoS attempt
656                                         // We simply stop processing here
657                                         $this->logger->debug('Invalid ZRL parameter.', ['zrl' => $_GET['zrl']]);
658                                         throw new HTTPException\ForbiddenException();
659                                 }
660                         }
661
662                         if (!empty($_GET['owt']) && $this->mode->isNormal()) {
663                                 $token = $_GET['owt'];
664                                 Model\Profile::openWebAuthInit($token);
665                         }
666
667                         if (!$this->mode->isBackend()) {
668                                 $auth->withSession($this);
669                         }
670
671                         if (empty($_SESSION['authenticated'])) {
672                                 header('X-Account-Management-Status: none');
673                         }
674
675                         /*
676                          * check_config() is responsible for running update scripts. These automatically
677                          * update the DB schema whenever we push a new one out. It also checks to see if
678                          * any addons have been added or removed and reacts accordingly.
679                          */
680
681                         // in install mode, any url loads install module
682                         // but we need "view" module for stylesheet
683                         if ($this->mode->isInstall() && $moduleName !== 'install') {
684                                 $this->baseURL->redirect('install');
685                         } else {
686                                 $this->checkURL();
687                                 Core\Update::check($this->getBasePath(), false, $this->mode);
688                                 Core\Addon::loadAddons();
689                                 Core\Hook::loadHooks();
690                         }
691
692                         // Compatibility with the Android Diaspora client
693                         if ($moduleName == 'stream') {
694                                 $this->baseURL->redirect('network?order=post');
695                         }
696
697                         if ($moduleName == 'conversations') {
698                                 $this->baseURL->redirect('message');
699                         }
700
701                         if ($moduleName == 'commented') {
702                                 $this->baseURL->redirect('network?order=comment');
703                         }
704
705                         if ($moduleName == 'liked') {
706                                 $this->baseURL->redirect('network?order=comment');
707                         }
708
709                         if ($moduleName == 'activity') {
710                                 $this->baseURL->redirect('network?conv=1');
711                         }
712
713                         if (($moduleName == 'status_messages') && ($this->args->getCommand() == 'status_messages/new')) {
714                                 $this->baseURL->redirect('bookmarklet');
715                         }
716
717                         if (($moduleName == 'user') && ($this->args->getCommand() == 'user/edit')) {
718                                 $this->baseURL->redirect('settings');
719                         }
720
721                         if (($moduleName == 'tag_followings') && ($this->args->getCommand() == 'tag_followings/manage')) {
722                                 $this->baseURL->redirect('search');
723                         }
724
725                         // Initialize module that can set the current theme in the init() method, either directly or via App->setProfileOwner
726                         $page['page_title'] = $moduleName;
727
728                         // The "view" module is required to show the theme CSS
729                         if (!$this->mode->isInstall() && !$this->mode->has(App\Mode::MAINTENANCEDISABLED) && $moduleName !== 'view') {
730                                 $module = $router->getModule(Maintenance::class);
731                         } else {
732                                 // determine the module class and save it to the module instance
733                                 // @todo there's an implicit dependency due SESSION::start(), so it has to be called here (yet)
734                                 $module = $router->getModule();
735                         }
736
737                         // Processes data from GET requests
738                         $httpinput = $httpInput->process();
739                         $input     = array_merge($httpinput['variables'], $httpinput['files'], $request ?? $_REQUEST);
740
741                         // Let the module run it's internal process (init, get, post, ...)
742                         $timestamp = microtime(true);
743                         $response = $module->run($input);
744                         $this->profiler->set(microtime(true) - $timestamp, 'content');
745                         if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) {
746                                 $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $this->userSession->getLocalUserId());
747                         } else {
748                                 $page->exit($response);
749                         }
750                 } catch (HTTPException $e) {
751                         (new ModuleHTTPException())->rawContent($e);
752                 }
753                 $page->logRuntime($this->config, 'runFrontend');
754         }
755
756         /**
757          * Automatically redirects to relative or absolute URL
758          * Should only be used if it isn't clear if the URL is either internal or external
759          *
760          * @param string $toUrl The target URL
761          *
762          * @throws HTTPException\InternalServerErrorException
763          */
764         public function redirect(string $toUrl)
765         {
766                 if (!empty(parse_url($toUrl, PHP_URL_SCHEME))) {
767                         Core\System::externalRedirect($toUrl);
768                 } else {
769                         $this->baseURL->redirect($toUrl);
770                 }
771         }
772 }