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