]> git.mxchange.org Git - friendica.git/blob - src/App.php
Register Friendica stylesheet using App->registerStylesheet()
[friendica.git] / src / App.php
1 <?php
2 /**
3  * @file src/App.php
4  */
5 namespace Friendica;
6
7 use Detection\MobileDetect;
8 use Exception;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\PConfig;
12 use Friendica\Core\System;
13 use Friendica\Database\DBA;
14
15 require_once 'boot.php';
16 require_once 'include/dba.php';
17 require_once 'include/text.php';
18
19 /**
20  *
21  * class: App
22  *
23  * @brief Our main application structure for the life of this page.
24  *
25  * Primarily deals with the URL that got us here
26  * and tries to make some sense of it, and
27  * stores our page contents and config storage
28  * and anything else that might need to be passed around
29  * before we spit the page out.
30  *
31  */
32 class App
33 {
34         const MODE_LOCALCONFIGPRESENT = 1;
35         const MODE_DBAVAILABLE = 2;
36         const MODE_DBCONFIGAVAILABLE = 4;
37         const MODE_MAINTENANCEDISABLED = 8;
38
39         /**
40          * @deprecated since version 2008.08 Use App->isInstallMode() instead to check for install mode.
41          */
42         const MODE_INSTALL = 0;
43
44         /**
45          * @deprecated since version 2008.08 Use the precise mode constant to check for a specific capability instead.
46          */
47         const MODE_NORMAL = App::MODE_LOCALCONFIGPRESENT | App::MODE_DBAVAILABLE | App::MODE_DBCONFIGAVAILABLE | App::MODE_MAINTENANCEDISABLED;
48
49         public $module_loaded = false;
50         public $module_class = null;
51         public $query_string = '';
52         public $config = [];
53         public $page = [];
54         public $pager = [];
55         public $page_offset;
56         public $profile;
57         public $profile_uid;
58         public $user;
59         public $cid;
60         public $contact;
61         public $contacts;
62         public $page_contact;
63         public $content;
64         public $data = [];
65         public $error = false;
66         public $cmd = '';
67         public $argv;
68         public $argc;
69         public $module;
70         public $mode = App::MODE_INSTALL;
71         public $strings;
72         public $basepath;
73         public $urlpath;
74         public $hooks = [];
75         public $timezone;
76         public $interactive = true;
77         public $addons;
78         public $addons_admin = [];
79         public $apps = [];
80         public $identities;
81         public $is_mobile = false;
82         public $is_tablet = false;
83         public $is_friendica_app;
84         public $performance = [];
85         public $callstack = [];
86         public $theme_info = [];
87         public $backend = true;
88         public $nav_sel;
89         public $category;
90         // Allow themes to control internal parameters
91         // by changing App values in theme.php
92
93         public $sourcename = '';
94         public $videowidth = 425;
95         public $videoheight = 350;
96         public $force_max_items = 0;
97         public $theme_events_in_profile = true;
98
99         public $stylesheets = [];
100         public $footerScripts = [];
101
102         public function registerStylesheet($path)
103         {
104                 $url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
105
106                 $this->stylesheets[] = trim($url, '/');
107         }
108
109         public function registerFooterScript($path)
110         {
111                 $url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
112
113                 $this->footerScripts[] = trim($url, '/');
114         }
115
116         /**
117          * @brief An array for all theme-controllable parameters
118          *
119          * Mostly unimplemented yet. Only options 'template_engine' and
120          * beyond are used.
121          */
122         public $theme = [
123                 'sourcename' => '',
124                 'videowidth' => 425,
125                 'videoheight' => 350,
126                 'force_max_items' => 0,
127                 'stylesheet' => '',
128                 'template_engine' => 'smarty3',
129         ];
130
131         /**
132          * @brief An array of registered template engines ('name'=>'class name')
133          */
134         public $template_engines = [];
135
136         /**
137          * @brief An array of instanced template engines ('name'=>'instance')
138          */
139         public $template_engine_instance = [];
140         public $process_id;
141         public $queue;
142         private $ldelim = [
143                 'internal' => '',
144                 'smarty3' => '{{'
145         ];
146         private $rdelim = [
147                 'internal' => '',
148                 'smarty3' => '}}'
149         ];
150         private $scheme;
151         private $hostname;
152         private $curl_code;
153         private $curl_content_type;
154         private $curl_headers;
155
156         /**
157          * @brief App constructor.
158          *
159          * @param string $basepath Path to the app base folder
160          *
161          * @throws Exception if the Basepath is not usable
162          */
163         public function __construct($basepath)
164         {
165                 if (!static::directory_usable($basepath, false)) {
166                         throw new Exception('Basepath ' . $basepath . ' isn\'t usable.');
167                 }
168
169                 BaseObject::setApp($this);
170
171                 $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);
172
173                 $this->performance['start'] = microtime(true);
174                 $this->performance['database'] = 0;
175                 $this->performance['database_write'] = 0;
176                 $this->performance['cache'] = 0;
177                 $this->performance['cache_write'] = 0;
178                 $this->performance['network'] = 0;
179                 $this->performance['file'] = 0;
180                 $this->performance['rendering'] = 0;
181                 $this->performance['parser'] = 0;
182                 $this->performance['marktime'] = 0;
183                 $this->performance['markstart'] = microtime(true);
184
185                 $this->callstack['database'] = [];
186                 $this->callstack['database_write'] = [];
187                 $this->callstack['cache'] = [];
188                 $this->callstack['cache_write'] = [];
189                 $this->callstack['network'] = [];
190                 $this->callstack['file'] = [];
191                 $this->callstack['rendering'] = [];
192                 $this->callstack['parser'] = [];
193
194                 $this->reload();
195
196                 set_time_limit(0);
197
198                 // This has to be quite large to deal with embedded private photos
199                 ini_set('pcre.backtrack_limit', 500000);
200
201                 $this->scheme = 'http';
202
203                 if ((x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) ||
204                         (x($_SERVER, 'HTTP_FORWARDED') && preg_match('/proto=https/', $_SERVER['HTTP_FORWARDED'])) ||
205                         (x($_SERVER, 'HTTP_X_FORWARDED_PROTO') && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ||
206                         (x($_SERVER, 'HTTP_X_FORWARDED_SSL') && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') ||
207                         (x($_SERVER, 'FRONT_END_HTTPS') && $_SERVER['FRONT_END_HTTPS'] == 'on') ||
208                         (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much?
209                 ) {
210                         $this->scheme = 'https';
211                 }
212
213                 if (x($_SERVER, 'SERVER_NAME')) {
214                         $this->hostname = $_SERVER['SERVER_NAME'];
215
216                         if (x($_SERVER, 'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
217                                 $this->hostname .= ':' . $_SERVER['SERVER_PORT'];
218                         }
219                 }
220
221                 set_include_path(
222                         get_include_path() . PATH_SEPARATOR
223                         . $this->basepath . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR
224                         . $this->basepath . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
225                         . $this->basepath);
226
227                 if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 9) === 'pagename=') {
228                         $this->query_string = substr($_SERVER['QUERY_STRING'], 9);
229                 } elseif ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === 'q=') {
230                         $this->query_string = substr($_SERVER['QUERY_STRING'], 2);
231                 }
232
233                 // removing trailing / - maybe a nginx problem
234                 $this->query_string = ltrim($this->query_string, '/');
235
236                 if (!empty($_GET['pagename'])) {
237                         $this->cmd = trim($_GET['pagename'], '/\\');
238                 } elseif (!empty($_GET['q'])) {
239                         $this->cmd = trim($_GET['q'], '/\\');
240                 }
241
242                 // fix query_string
243                 $this->query_string = str_replace($this->cmd . '&', $this->cmd . '?', $this->query_string);
244
245                 // unix style "homedir"
246                 if (substr($this->cmd, 0, 1) === '~') {
247                         $this->cmd = 'profile/' . substr($this->cmd, 1);
248                 }
249
250                 // Diaspora style profile url
251                 if (substr($this->cmd, 0, 2) === 'u/') {
252                         $this->cmd = 'profile/' . substr($this->cmd, 2);
253                 }
254
255                 /*
256                  * Break the URL path into C style argc/argv style arguments for our
257                  * modules. Given "http://example.com/module/arg1/arg2", $this->argc
258                  * will be 3 (integer) and $this->argv will contain:
259                  *   [0] => 'module'
260                  *   [1] => 'arg1'
261                  *   [2] => 'arg2'
262                  *
263                  *
264                  * There will always be one argument. If provided a naked domain
265                  * URL, $this->argv[0] is set to "home".
266                  */
267
268                 $this->argv = explode('/', $this->cmd);
269                 $this->argc = count($this->argv);
270                 if ((array_key_exists('0', $this->argv)) && strlen($this->argv[0])) {
271                         $this->module = str_replace('.', '_', $this->argv[0]);
272                         $this->module = str_replace('-', '_', $this->module);
273                 } else {
274                         $this->argc = 1;
275                         $this->argv = ['home'];
276                         $this->module = 'home';
277                 }
278
279                 // See if there is any page number information, and initialise pagination
280                 $this->pager['page'] = ((x($_GET, 'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
281                 $this->pager['itemspage'] = 50;
282                 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
283
284                 if ($this->pager['start'] < 0) {
285                         $this->pager['start'] = 0;
286                 }
287                 $this->pager['total'] = 0;
288
289                 // Detect mobile devices
290                 $mobile_detect = new MobileDetect();
291                 $this->is_mobile = $mobile_detect->isMobile();
292                 $this->is_tablet = $mobile_detect->isTablet();
293
294                 // Friendica-Client
295                 $this->is_friendica_app = isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] == 'Apache-HttpClient/UNAVAILABLE (java 1.4)';
296
297                 // Register template engines
298                 $this->register_template_engine('Friendica\Render\FriendicaSmartyEngine');
299         }
300
301         /**
302          * Reloads the whole app instance
303          */
304         public function reload()
305         {
306                 // The order of the following calls is important to ensure proper initialization
307                 $this->loadConfigFiles();
308
309                 $this->loadDatabase();
310
311                 $this->determineMode();
312
313                 $this->determineUrlPath();
314
315                 Config::load();
316
317                 if ($this->mode & self::MODE_DBAVAILABLE) {
318                         Core\Addon::loadHooks();
319
320                         $this->loadAddonConfig();
321                 }
322
323                 $this->loadDefaultTimezone();
324
325                 $this->page = [
326                         'aside' => '',
327                         'bottom' => '',
328                         'content' => '',
329                         'footer' => '',
330                         'htmlhead' => '',
331                         'nav' => '',
332                         'page_title' => '',
333                         'right_aside' => '',
334                         'template' => '',
335                         'title' => ''
336                 ];
337
338                 $this->process_id = System::processID('log');
339         }
340
341         /**
342          * Load the configuration files
343          *
344          * First loads the default value for all the configuration keys, then the legacy configuration files, then the
345          * expected local.ini.php
346          */
347         private function loadConfigFiles()
348         {
349                 $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.ini.php');
350                 $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'settings.ini.php');
351
352                 // Legacy .htconfig.php support
353                 if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php')) {
354                         $a = $this;
355                         include $this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php';
356                 }
357
358                 // Legacy .htconfig.php support
359                 if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) {
360                         $a = $this;
361
362                         include $this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php';
363
364                         $this->setConfigValue('database', 'hostname', $db_host);
365                         $this->setConfigValue('database', 'username', $db_user);
366                         $this->setConfigValue('database', 'password', $db_pass);
367                         $this->setConfigValue('database', 'database', $db_data);
368                         if (isset($a->config['system']['db_charset'])) {
369                                 $this->setConfigValue('database', 'charset', $a->config['system']['db_charset']);
370                         }
371
372                         unset($db_host, $db_user, $db_pass, $db_data);
373
374                         if (isset($default_timezone)) {
375                                 $this->setConfigValue('system', 'default_timezone', $default_timezone);
376                                 unset($default_timezone);
377                         }
378
379                         if (isset($pidfile)) {
380                                 $this->setConfigValue('system', 'pidfile', $pidfile);
381                                 unset($pidfile);
382                         }
383
384                         if (isset($lang)) {
385                                 $this->setConfigValue('system', 'language', $lang);
386                                 unset($lang);
387                         }
388                 }
389
390                 if (file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) {
391                         $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php');
392                 }
393         }
394
395         /**
396          * Tries to load the specified configuration file into the App->config array.
397          * Overwrites previously set values.
398          *
399          * The config format is INI and the template for configuration files is the following:
400          *
401          * <?php return <<<INI
402          *
403          * [section]
404          * key = value
405          *
406          * INI;
407          * // Keep this line
408          *
409          * @param type $filepath
410          * @throws Exception
411          */
412         public function loadConfigFile($filepath)
413         {
414                 if (!file_exists($filepath)) {
415                         throw new Exception('Error parsing non-existent config file ' . $filepath);
416                 }
417
418                 $contents = include($filepath);
419
420                 $config = parse_ini_string($contents, true, INI_SCANNER_TYPED);
421
422                 if ($config === false) {
423                         throw new Exception('Error parsing config file ' . $filepath);
424                 }
425
426                 foreach ($config as $category => $values) {
427                         foreach ($values as $key => $value) {
428                                 $this->setConfigValue($category, $key, $value);
429                         }
430                 }
431         }
432
433         /**
434          * Loads addons configuration files
435          *
436          * First loads all activated addons default configuration throught the load_config hook, then load the local.ini.php
437          * again to overwrite potential local addon configuration.
438          */
439         private function loadAddonConfig()
440         {
441                 // Loads addons default config
442                 Core\Addon::callHooks('load_config');
443
444                 // Load the local addon config file to overwritten default addon config values
445                 if (file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php')) {
446                         $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php');
447                 }
448         }
449
450         /**
451          * Loads the default timezone
452          *
453          * Include support for legacy $default_timezone
454          *
455          * @global string $default_timezone
456          */
457         private function loadDefaultTimezone()
458         {
459                 if ($this->getConfigValue('system', 'default_timezone')) {
460                         $this->timezone = $this->getConfigValue('system', 'default_timezone');
461                 } else {
462                         global $default_timezone;
463                         $this->timezone = !empty($default_timezone) ? $default_timezone : 'UTC';
464                 }
465
466                 if ($this->timezone) {
467                         date_default_timezone_set($this->timezone);
468                 }
469         }
470
471         /**
472          * Figure out if we are running at the top of a domain or in a sub-directory and adjust accordingly
473          */
474         private function determineUrlPath()
475         {
476                 $this->urlpath = $this->getConfigValue('system', 'urlpath');
477
478                 /* SCRIPT_URL gives /path/to/friendica/module/parameter
479                  * QUERY_STRING gives pagename=module/parameter
480                  *
481                  * To get /path/to/friendica we perform dirname() for as many levels as there are slashes in the QUERY_STRING
482                  */
483                 if (!empty($_SERVER['SCRIPT_URL'])) {
484                         // Module
485                         if (!empty($_SERVER['QUERY_STRING'])) {
486                                 $path = trim(dirname($_SERVER['SCRIPT_URL'], substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/');
487                         } else {
488                                 // Root page
489                                 $path = trim($_SERVER['SCRIPT_URL'], '/');
490                         }
491
492                         if ($path && $path != $this->urlpath) {
493                                 $this->urlpath = $path;
494                         }
495                 }
496         }
497
498         /**
499          * Sets the App mode
500          *
501          * - App::MODE_INSTALL    : Either the database connection can't be established or the config table doesn't exist
502          * - App::MODE_MAINTENANCE: The maintenance mode has been set
503          * - App::MODE_NORMAL     : Normal run with all features enabled
504          *
505          * @return type
506          */
507         private function determineMode()
508         {
509                 $this->mode = 0;
510
511                 if (!file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')
512                         && !file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) {
513                         return;
514                 }
515
516                 $this->mode |= App::MODE_LOCALCONFIGPRESENT;
517
518                 if (!DBA::connected()) {
519                         return;
520                 }
521
522                 $this->mode |= App::MODE_DBAVAILABLE;
523
524                 if (DBA::fetchFirst("SHOW TABLES LIKE 'config'") === false) {
525                         return;
526                 }
527
528                 $this->mode |= App::MODE_DBCONFIGAVAILABLE;
529
530                 if (Config::get('system', 'maintenance')) {
531                         return;
532                 }
533
534                 $this->mode |= App::MODE_MAINTENANCEDISABLED;
535         }
536
537         public function loadDatabase()
538         {
539                 if (DBA::connected()) {
540                         return;
541                 }
542
543                 $db_host = $this->getConfigValue('database', 'hostname');
544                 $db_user = $this->getConfigValue('database', 'username');
545                 $db_pass = $this->getConfigValue('database', 'password');
546                 $db_data = $this->getConfigValue('database', 'database');
547                 $charset = $this->getConfigValue('database', 'charset');
548
549                 // Use environment variables for mysql if they are set beforehand
550                 if (!empty(getenv('MYSQL_HOST'))
551                         && (!empty(getenv('MYSQL_USERNAME')) || !empty(getenv('MYSQL_USER')))
552                         && getenv('MYSQL_PASSWORD') !== false
553                         && !empty(getenv('MYSQL_DATABASE')))
554                 {
555                         $db_host = getenv('MYSQL_HOST');
556                         if (!empty(getenv('MYSQL_PORT'))) {
557                                 $db_host .= ':' . getenv('MYSQL_PORT');
558                         }
559                         if (!empty(getenv('MYSQL_USERNAME'))) {
560                                 $db_user = getenv('MYSQL_USERNAME');
561                         } else {
562                                 $db_user = getenv('MYSQL_USER');
563                         }
564                         $db_pass = (string) getenv('MYSQL_PASSWORD');
565                         $db_data = getenv('MYSQL_DATABASE');
566                 }
567
568                 $stamp1 = microtime(true);
569
570                 DBA::connect($db_host, $db_user, $db_pass, $db_data, $charset);
571                 unset($db_host, $db_user, $db_pass, $db_data, $charset);
572
573                 $this->save_timestamp($stamp1, 'network');
574         }
575
576         /**
577          * Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
578          *
579          * @return bool
580          */
581         public function isInstallMode()
582         {
583                 return !($this->mode & App::MODE_LOCALCONFIGPRESENT) || !($this->mode & App::MODE_DBCONFIGAVAILABLE);
584         }
585
586         /**
587          * @brief Returns the base filesystem path of the App
588          *
589          * It first checks for the internal variable, then for DOCUMENT_ROOT and
590          * finally for PWD
591          *
592          * @return string
593          */
594         public function get_basepath()
595         {
596                 $basepath = $this->basepath;
597
598                 if (!$basepath) {
599                         $basepath = Config::get('system', 'basepath');
600                 }
601
602                 if (!$basepath && x($_SERVER, 'DOCUMENT_ROOT')) {
603                         $basepath = $_SERVER['DOCUMENT_ROOT'];
604                 }
605
606                 if (!$basepath && x($_SERVER, 'PWD')) {
607                         $basepath = $_SERVER['PWD'];
608                 }
609
610                 return self::realpath($basepath);
611         }
612
613         /**
614          * @brief Returns a normalized file path
615          *
616          * This is a wrapper for the "realpath" function.
617          * That function cannot detect the real path when some folders aren't readable.
618          * Since this could happen with some hosters we need to handle this.
619          *
620          * @param string $path The path that is about to be normalized
621          * @return string normalized path - when possible
622          */
623         public static function realpath($path)
624         {
625                 $normalized = realpath($path);
626
627                 if (!is_bool($normalized)) {
628                         return $normalized;
629                 } else {
630                         return $path;
631                 }
632         }
633
634         public function get_scheme()
635         {
636                 return $this->scheme;
637         }
638
639         /**
640          * @brief Retrieves the Friendica instance base URL
641          *
642          * This function assembles the base URL from multiple parts:
643          * - Protocol is determined either by the request or a combination of
644          * system.ssl_policy and the $ssl parameter.
645          * - Host name is determined either by system.hostname or inferred from request
646          * - Path is inferred from SCRIPT_NAME
647          *
648          * Note: $ssl parameter value doesn't directly correlate with the resulting protocol
649          *
650          * @param bool $ssl Whether to append http or https under SSL_POLICY_SELFSIGN
651          * @return string Friendica server base URL
652          */
653         public function get_baseurl($ssl = false)
654         {
655                 $scheme = $this->scheme;
656
657                 if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {
658                         $scheme = 'https';
659                 }
660
661                 //      Basically, we have $ssl = true on any links which can only be seen by a logged in user
662                 //      (and also the login link). Anything seen by an outsider will have it turned off.
663
664                 if (Config::get('system', 'ssl_policy') == SSL_POLICY_SELFSIGN) {
665                         if ($ssl) {
666                                 $scheme = 'https';
667                         } else {
668                                 $scheme = 'http';
669                         }
670                 }
671
672                 if (Config::get('config', 'hostname') != '') {
673                         $this->hostname = Config::get('config', 'hostname');
674                 }
675
676                 return $scheme . '://' . $this->hostname . (!empty($this->urlpath) ? '/' . $this->urlpath : '' );
677         }
678
679         /**
680          * @brief Initializes the baseurl components
681          *
682          * Clears the baseurl cache to prevent inconsistencies
683          *
684          * @param string $url
685          */
686         public function set_baseurl($url)
687         {
688                 $parsed = @parse_url($url);
689                 $hostname = '';
690
691                 if (x($parsed)) {
692                         if (!empty($parsed['scheme'])) {
693                                 $this->scheme = $parsed['scheme'];
694                         }
695
696                         if (!empty($parsed['host'])) {
697                                 $hostname = $parsed['host'];
698                         }
699
700                         if (x($parsed, 'port')) {
701                                 $hostname .= ':' . $parsed['port'];
702                         }
703                         if (x($parsed, 'path')) {
704                                 $this->urlpath = trim($parsed['path'], '\\/');
705                         }
706
707                         if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php')) {
708                                 include $this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php';
709                         }
710
711                         if (Config::get('config', 'hostname') != '') {
712                                 $this->hostname = Config::get('config', 'hostname');
713                         }
714
715                         if (!isset($this->hostname) || ($this->hostname == '')) {
716                                 $this->hostname = $hostname;
717                         }
718                 }
719         }
720
721         public function get_hostname()
722         {
723                 if (Config::get('config', 'hostname') != '') {
724                         $this->hostname = Config::get('config', 'hostname');
725                 }
726
727                 return $this->hostname;
728         }
729
730         public function get_path()
731         {
732                 return $this->urlpath;
733         }
734
735         public function set_pager_total($n)
736         {
737                 $this->pager['total'] = intval($n);
738         }
739
740         public function set_pager_itemspage($n)
741         {
742                 $this->pager['itemspage'] = ((intval($n) > 0) ? intval($n) : 0);
743                 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
744         }
745
746         public function set_pager_page($n)
747         {
748                 $this->pager['page'] = $n;
749                 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
750         }
751
752         public function initHead()
753         {
754                 $interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000);
755
756                 // If the update is 'deactivated' set it to the highest integer number (~24 days)
757                 if ($interval < 0) {
758                         $interval = 2147483647;
759                 }
760
761                 if ($interval < 10000) {
762                         $interval = 40000;
763                 }
764
765                 // compose the page title from the sitename and the
766                 // current module called
767                 if (!$this->module == '') {
768                         $this->page['title'] = $this->config['sitename'] . ' (' . $this->module . ')';
769                 } else {
770                         $this->page['title'] = $this->config['sitename'];
771                 }
772
773                 if (!empty($this->theme['stylesheet'])) {
774                         $stylesheet = $this->theme['stylesheet'];
775                 } else {
776                         $stylesheet = $this->getCurrentThemeStylesheetPath();
777                 }
778
779                 $this->registerStylesheet($stylesheet);
780
781                 $shortcut_icon = Config::get('system', 'shortcut_icon');
782                 if ($shortcut_icon == '') {
783                         $shortcut_icon = 'images/friendica-32.png';
784                 }
785
786                 $touch_icon = Config::get('system', 'touch_icon');
787                 if ($touch_icon == '') {
788                         $touch_icon = 'images/friendica-128.png';
789                 }
790
791                 // get data wich is needed for infinite scroll on the network page
792                 $infinite_scroll = infinite_scroll_data($this->module);
793
794                 Core\Addon::callHooks('head', $this->page['htmlhead']);
795
796                 $tpl = get_markup_template('head.tpl');
797                 /* put the head template at the beginning of page['htmlhead']
798                  * since the code added by the modules frequently depends on it
799                  * being first
800                  */
801                 $this->page['htmlhead'] = replace_macros($tpl, [
802                         '$baseurl'         => $this->get_baseurl(),
803                         '$local_user'      => local_user(),
804                         '$generator'       => 'Friendica' . ' ' . FRIENDICA_VERSION,
805                         '$delitem'         => L10n::t('Delete this item?'),
806                         '$showmore'        => L10n::t('show more'),
807                         '$showfewer'       => L10n::t('show fewer'),
808                         '$update_interval' => $interval,
809                         '$shortcut_icon'   => $shortcut_icon,
810                         '$touch_icon'      => $touch_icon,
811                         '$infinite_scroll' => $infinite_scroll,
812                         '$block_public'    => intval(Config::get('system', 'block_public')),
813                         '$stylesheets'     => $this->stylesheets,
814                 ]) . $this->page['htmlhead'];
815         }
816
817         public function initFooter()
818         {
819                 // If you're just visiting, let javascript take you home
820                 if (!empty($_SESSION['visitor_home'])) {
821                         $homebase = $_SESSION['visitor_home'];
822                 } elseif (local_user()) {
823                         $homebase = 'profile/' . $a->user['nickname'];
824                 }
825
826                 if (isset($homebase)) {
827                         $this->page['footer'] .= '<script>var homebase="' . $homebase . '";</script>' . "\n";
828                 }
829
830                 /*
831                  * Add a "toggle mobile" link if we're using a mobile device
832                  */
833                 if ($this->is_mobile || $this->is_tablet) {
834                         if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
835                                 $link = 'toggle_mobile?address=' . curPageURL();
836                         } else {
837                                 $link = 'toggle_mobile?off=1&address=' . curPageURL();
838                         }
839                         $this->page['footer'] .= replace_macros(get_markup_template("toggle_mobile_footer.tpl"), [
840                                 '$toggle_link' => $link,
841                                 '$toggle_text' => Core\L10n::t('toggle mobile')
842                         ]);
843                 }
844
845                 Core\Addon::callHooks('footer', $this->page['footer']);
846
847                 $tpl = get_markup_template('footer.tpl');
848                 $this->page['footer'] = replace_macros($tpl, [
849                         '$baseurl' => $this->get_baseurl(),
850                         '$footerScripts' => $this->footerScripts,
851                 ]) . $this->page['footer'];
852         }
853
854         public function set_curl_code($code)
855         {
856                 $this->curl_code = $code;
857         }
858
859         public function get_curl_code()
860         {
861                 return $this->curl_code;
862         }
863
864         public function set_curl_content_type($content_type)
865         {
866                 $this->curl_content_type = $content_type;
867         }
868
869         public function get_curl_content_type()
870         {
871                 return $this->curl_content_type;
872         }
873
874         public function set_curl_headers($headers)
875         {
876                 $this->curl_headers = $headers;
877         }
878
879         public function get_curl_headers()
880         {
881                 return $this->curl_headers;
882         }
883
884         /**
885          * @brief Removes the base url from an url. This avoids some mixed content problems.
886          *
887          * @param string $orig_url
888          *
889          * @return string The cleaned url
890          */
891         public function remove_baseurl($orig_url)
892         {
893                 // Remove the hostname from the url if it is an internal link
894                 $nurl = normalise_link($orig_url);
895                 $base = normalise_link($this->get_baseurl());
896                 $url = str_replace($base . '/', '', $nurl);
897
898                 // if it is an external link return the orignal value
899                 if ($url == normalise_link($orig_url)) {
900                         return $orig_url;
901                 } else {
902                         return $url;
903                 }
904         }
905
906         /**
907          * @brief Register template engine class
908          *
909          * @param string $class
910          */
911         private function register_template_engine($class)
912         {
913                 $v = get_class_vars($class);
914                 if (x($v, 'name')) {
915                         $name = $v['name'];
916                         $this->template_engines[$name] = $class;
917                 } else {
918                         echo "template engine <tt>$class</tt> cannot be registered without a name.\n";
919                         die();
920                 }
921         }
922
923         /**
924          * @brief Return template engine instance.
925          *
926          * If $name is not defined, return engine defined by theme,
927          * or default
928          *
929          * @return object Template Engine instance
930          */
931         public function template_engine()
932         {
933                 $template_engine = 'smarty3';
934                 if (x($this->theme, 'template_engine')) {
935                         $template_engine = $this->theme['template_engine'];
936                 }
937
938                 if (isset($this->template_engines[$template_engine])) {
939                         if (isset($this->template_engine_instance[$template_engine])) {
940                                 return $this->template_engine_instance[$template_engine];
941                         } else {
942                                 $class = $this->template_engines[$template_engine];
943                                 $obj = new $class;
944                                 $this->template_engine_instance[$template_engine] = $obj;
945                                 return $obj;
946                         }
947                 }
948
949                 echo "template engine <tt>$template_engine</tt> is not registered!\n";
950                 killme();
951         }
952
953         /**
954          * @brief Returns the active template engine.
955          *
956          * @return string
957          */
958         public function get_template_engine()
959         {
960                 return $this->theme['template_engine'];
961         }
962
963         public function set_template_engine($engine = 'smarty3')
964         {
965                 $this->theme['template_engine'] = $engine;
966         }
967
968         public function get_template_ldelim($engine = 'smarty3')
969         {
970                 return $this->ldelim[$engine];
971         }
972
973         public function get_template_rdelim($engine = 'smarty3')
974         {
975                 return $this->rdelim[$engine];
976         }
977
978         public function save_timestamp($stamp, $value)
979         {
980                 if (!isset($this->config['system']['profiler']) || !$this->config['system']['profiler']) {
981                         return;
982                 }
983
984                 $duration = (float) (microtime(true) - $stamp);
985
986                 if (!isset($this->performance[$value])) {
987                         // Prevent ugly E_NOTICE
988                         $this->performance[$value] = 0;
989                 }
990
991                 $this->performance[$value] += (float) $duration;
992                 $this->performance['marktime'] += (float) $duration;
993
994                 $callstack = System::callstack();
995
996                 if (!isset($this->callstack[$value][$callstack])) {
997                         // Prevent ugly E_NOTICE
998                         $this->callstack[$value][$callstack] = 0;
999                 }
1000
1001                 $this->callstack[$value][$callstack] += (float) $duration;
1002         }
1003
1004         public function get_useragent()
1005         {
1006                 return
1007                         FRIENDICA_PLATFORM . " '" .
1008                         FRIENDICA_CODENAME . "' " .
1009                         FRIENDICA_VERSION . '-' .
1010                         DB_UPDATE_VERSION . '; ' .
1011                         $this->get_baseurl();
1012         }
1013
1014         public function is_friendica_app()
1015         {
1016                 return $this->is_friendica_app;
1017         }
1018
1019         /**
1020          * @brief Checks if the site is called via a backend process
1021          *
1022          * This isn't a perfect solution. But we need this check very early.
1023          * So we cannot wait until the modules are loaded.
1024          *
1025          * @return bool Is it a known backend?
1026          */
1027         public function is_backend()
1028         {
1029                 static $backends = [
1030                         '_well_known',
1031                         'api',
1032                         'dfrn_notify',
1033                         'fetch',
1034                         'hcard',
1035                         'hostxrd',
1036                         'nodeinfo',
1037                         'noscrape',
1038                         'p',
1039                         'poco',
1040                         'post',
1041                         'proxy',
1042                         'pubsub',
1043                         'pubsubhubbub',
1044                         'receive',
1045                         'rsd_xml',
1046                         'salmon',
1047                         'statistics_json',
1048                         'xrd',
1049                 ];
1050
1051                 // Check if current module is in backend or backend flag is set
1052                 return (in_array($this->module, $backends) || $this->backend);
1053         }
1054
1055         /**
1056          * @brief Checks if the maximum number of database processes is reached
1057          *
1058          * @return bool Is the limit reached?
1059          */
1060         public function isMaxProcessesReached()
1061         {
1062                 // Deactivated, needs more investigating if this check really makes sense
1063                 return false;
1064
1065                 /*
1066                  * Commented out to suppress static analyzer issues
1067                  *
1068                 if ($this->is_backend()) {
1069                         $process = 'backend';
1070                         $max_processes = Config::get('system', 'max_processes_backend');
1071                         if (intval($max_processes) == 0) {
1072                                 $max_processes = 5;
1073                         }
1074                 } else {
1075                         $process = 'frontend';
1076                         $max_processes = Config::get('system', 'max_processes_frontend');
1077                         if (intval($max_processes) == 0) {
1078                                 $max_processes = 20;
1079                         }
1080                 }
1081
1082                 $processlist = DBA::processlist();
1083                 if ($processlist['list'] != '') {
1084                         logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
1085
1086                         if ($processlist['amount'] > $max_processes) {
1087                                 logger('Processcheck: Maximum number of processes for ' . $process . ' tasks (' . $max_processes . ') reached.', LOGGER_DEBUG);
1088                                 return true;
1089                         }
1090                 }
1091                 return false;
1092                  */
1093         }
1094
1095         /**
1096          * @brief Checks if the minimal memory is reached
1097          *
1098          * @return bool Is the memory limit reached?
1099          */
1100         public function min_memory_reached()
1101         {
1102                 $min_memory = Config::get('system', 'min_memory', 0);
1103                 if ($min_memory == 0) {
1104                         return false;
1105                 }
1106
1107                 if (!is_readable('/proc/meminfo')) {
1108                         return false;
1109                 }
1110
1111                 $memdata = explode("\n", file_get_contents('/proc/meminfo'));
1112
1113                 $meminfo = [];
1114                 foreach ($memdata as $line) {
1115                         list($key, $val) = explode(':', $line);
1116                         $meminfo[$key] = (int) trim(str_replace('kB', '', $val));
1117                         $meminfo[$key] = (int) ($meminfo[$key] / 1024);
1118                 }
1119
1120                 if (!isset($meminfo['MemAvailable']) || !isset($meminfo['MemFree'])) {
1121                         return false;
1122                 }
1123
1124                 $free = $meminfo['MemAvailable'] + $meminfo['MemFree'];
1125
1126                 $reached = ($free < $min_memory);
1127
1128                 if ($reached) {
1129                         logger('Minimal memory reached: ' . $free . '/' . $meminfo['MemTotal'] . ' - limit ' . $min_memory, LOGGER_DEBUG);
1130                 }
1131
1132                 return $reached;
1133         }
1134
1135         /**
1136          * @brief Checks if the maximum load is reached
1137          *
1138          * @return bool Is the load reached?
1139          */
1140         public function isMaxLoadReached()
1141         {
1142                 if ($this->is_backend()) {
1143                         $process = 'backend';
1144                         $maxsysload = intval(Config::get('system', 'maxloadavg'));
1145                         if ($maxsysload < 1) {
1146                                 $maxsysload = 50;
1147                         }
1148                 } else {
1149                         $process = 'frontend';
1150                         $maxsysload = intval(Config::get('system', 'maxloadavg_frontend'));
1151                         if ($maxsysload < 1) {
1152                                 $maxsysload = 50;
1153                         }
1154                 }
1155
1156                 $load = current_load();
1157                 if ($load) {
1158                         if (intval($load) > $maxsysload) {
1159                                 logger('system: load ' . $load . ' for ' . $process . ' tasks (' . $maxsysload . ') too high.');
1160                                 return true;
1161                         }
1162                 }
1163                 return false;
1164         }
1165
1166         /**
1167          * Executes a child process with 'proc_open'
1168          *
1169          * @param string $command The command to execute
1170          * @param array  $args    Arguments to pass to the command ( [ 'key' => value, 'key2' => value2, ... ]
1171          */
1172         public function proc_run($command, $args)
1173         {
1174                 if (!function_exists('proc_open')) {
1175                         return;
1176                 }
1177
1178                 $cmdline = $this->getConfigValue('config', 'php_path', 'php') . ' ' . escapeshellarg($command);
1179
1180                 foreach ($args as $key => $value) {
1181                         if (!is_null($value) && is_bool($value) && !$value) {
1182                                 continue;
1183                         }
1184
1185                         $cmdline .= ' --' . $key;
1186                         if (!is_null($value) && !is_bool($value)) {
1187                                 $cmdline .= ' ' . $value;
1188                         }
1189                 }
1190
1191                 if ($this->min_memory_reached()) {
1192                         return;
1193                 }
1194
1195                 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
1196                         $resource = proc_open('cmd /c start /b ' . $cmdline, [], $foo, $this->get_basepath());
1197                 } else {
1198                         $resource = proc_open($cmdline . ' &', [], $foo, $this->get_basepath());
1199                 }
1200                 if (!is_resource($resource)) {
1201                         logger('We got no resource for command ' . $cmdline, LOGGER_DEBUG);
1202                         return;
1203                 }
1204                 proc_close($resource);
1205         }
1206
1207         /**
1208          * @brief Returns the system user that is executing the script
1209          *
1210          * This mostly returns something like "www-data".
1211          *
1212          * @return string system username
1213          */
1214         private static function systemuser()
1215         {
1216                 if (!function_exists('posix_getpwuid') || !function_exists('posix_geteuid')) {
1217                         return '';
1218                 }
1219
1220                 $processUser = posix_getpwuid(posix_geteuid());
1221                 return $processUser['name'];
1222         }
1223
1224         /**
1225          * @brief Checks if a given directory is usable for the system
1226          *
1227          * @return boolean the directory is usable
1228          */
1229         public static function directory_usable($directory, $check_writable = true)
1230         {
1231                 if ($directory == '') {
1232                         logger('Directory is empty. This shouldn\'t happen.', LOGGER_DEBUG);
1233                         return false;
1234                 }
1235
1236                 if (!file_exists($directory)) {
1237                         logger('Path "' . $directory . '" does not exist for user ' . self::systemuser(), LOGGER_DEBUG);
1238                         return false;
1239                 }
1240
1241                 if (is_file($directory)) {
1242                         logger('Path "' . $directory . '" is a file for user ' . self::systemuser(), LOGGER_DEBUG);
1243                         return false;
1244                 }
1245
1246                 if (!is_dir($directory)) {
1247                         logger('Path "' . $directory . '" is not a directory for user ' . self::systemuser(), LOGGER_DEBUG);
1248                         return false;
1249                 }
1250
1251                 if ($check_writable && !is_writable($directory)) {
1252                         logger('Path "' . $directory . '" is not writable for user ' . self::systemuser(), LOGGER_DEBUG);
1253                         return false;
1254                 }
1255
1256                 return true;
1257         }
1258
1259         /**
1260          * @param string $cat     Config category
1261          * @param string $k       Config key
1262          * @param mixed  $default Default value if it isn't set
1263          */
1264         public function getConfigValue($cat, $k, $default = null)
1265         {
1266                 $return = $default;
1267
1268                 if ($cat === 'config') {
1269                         if (isset($this->config[$k])) {
1270                                 $return = $this->config[$k];
1271                         }
1272                 } else {
1273                         if (isset($this->config[$cat][$k])) {
1274                                 $return = $this->config[$cat][$k];
1275                         }
1276                 }
1277
1278                 return $return;
1279         }
1280
1281         /**
1282          * Sets a value in the config cache. Accepts raw output from the config table
1283          *
1284          * @param string $cat Config category
1285          * @param string $k   Config key
1286          * @param mixed  $v   Value to set
1287          */
1288         public function setConfigValue($cat, $k, $v)
1289         {
1290                 // Only arrays are serialized in database, so we have to unserialize sparingly
1291                 $value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v;
1292
1293                 if ($cat === 'config') {
1294                         $this->config[$k] = $value;
1295                 } else {
1296                         if (!isset($this->config[$cat])) {
1297                                 $this->config[$cat] = [];
1298                         }
1299
1300                         $this->config[$cat][$k] = $value;
1301                 }
1302         }
1303
1304         /**
1305          * Deletes a value from the config cache
1306          *
1307          * @param string $cat Config category
1308          * @param string $k   Config key
1309          */
1310         public function deleteConfigValue($cat, $k)
1311         {
1312                 if ($cat === 'config') {
1313                         if (isset($this->config[$k])) {
1314                                 unset($this->config[$k]);
1315                         }
1316                 } else {
1317                         if (isset($this->config[$cat][$k])) {
1318                                 unset($this->config[$cat][$k]);
1319                         }
1320                 }
1321         }
1322
1323
1324         /**
1325          * Retrieves a value from the user config cache
1326          *
1327          * @param int    $uid     User Id
1328          * @param string $cat     Config category
1329          * @param string $k       Config key
1330          * @param mixed  $default Default value if key isn't set
1331          */
1332         public function getPConfigValue($uid, $cat, $k, $default = null)
1333         {
1334                 $return = $default;
1335
1336                 if (isset($this->config[$uid][$cat][$k])) {
1337                         $return = $this->config[$uid][$cat][$k];
1338                 }
1339
1340                 return $return;
1341         }
1342
1343         /**
1344          * Sets a value in the user config cache
1345          *
1346          * Accepts raw output from the pconfig table
1347          *
1348          * @param int    $uid User Id
1349          * @param string $cat Config category
1350          * @param string $k   Config key
1351          * @param mixed  $v   Value to set
1352          */
1353         public function setPConfigValue($uid, $cat, $k, $v)
1354         {
1355                 // Only arrays are serialized in database, so we have to unserialize sparingly
1356                 $value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v;
1357
1358                 if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) {
1359                         $this->config[$uid] = [];
1360                 }
1361
1362                 if (!isset($this->config[$uid][$cat]) || !is_array($this->config[$uid][$cat])) {
1363                         $this->config[$uid][$cat] = [];
1364                 }
1365
1366                 $this->config[$uid][$cat][$k] = $value;
1367         }
1368
1369         /**
1370          * Deletes a value from the user config cache
1371          *
1372          * @param int    $uid User Id
1373          * @param string $cat Config category
1374          * @param string $k   Config key
1375          */
1376         public function deletePConfigValue($uid, $cat, $k)
1377         {
1378                 if (isset($this->config[$uid][$cat][$k])) {
1379                         unset($this->config[$uid][$cat][$k]);
1380                 }
1381         }
1382
1383         /**
1384          * Generates the site's default sender email address
1385          *
1386          * @return string
1387          */
1388         public function getSenderEmailAddress()
1389         {
1390                 $sender_email = Config::get('config', 'sender_email');
1391                 if (empty($sender_email)) {
1392                         $hostname = $this->get_hostname();
1393                         if (strpos($hostname, ':')) {
1394                                 $hostname = substr($hostname, 0, strpos($hostname, ':'));
1395                         }
1396
1397                         $sender_email = 'noreply@' . $hostname;
1398                 }
1399
1400                 return $sender_email;
1401         }
1402
1403         /**
1404          * Returns the current theme name.
1405          *
1406          * @return string
1407          */
1408         public function getCurrentTheme()
1409         {
1410                 if ($this->isInstallMode()) {
1411                         return '';
1412                 }
1413
1414                 //// @TODO Compute the current theme only once (this behavior has
1415                 /// already been implemented, but it didn't work well -
1416                 /// https://github.com/friendica/friendica/issues/5092)
1417                 $this->computeCurrentTheme();
1418
1419                 return $this->current_theme;
1420         }
1421
1422         /**
1423          * Computes the current theme name based on the node settings, the user settings and the device type
1424          *
1425          * @throws Exception
1426          */
1427         private function computeCurrentTheme()
1428         {
1429                 $system_theme = Config::get('system', 'theme');
1430                 if (!$system_theme) {
1431                         throw new Exception(L10n::t('No system theme config value set.'));
1432                 }
1433
1434                 // Sane default
1435                 $this->current_theme = $system_theme;
1436
1437                 $allowed_themes = explode(',', Config::get('system', 'allowed_themes', $system_theme));
1438
1439                 $page_theme = null;
1440                 // Find the theme that belongs to the user whose stuff we are looking at
1441                 if ($this->profile_uid && ($this->profile_uid != local_user())) {
1442                         // Allow folks to override user themes and always use their own on their own site.
1443                         // This works only if the user is on the same server
1444                         $user = DBA::selectFirst('user', ['theme'], ['uid' => $this->profile_uid]);
1445                         if (DBA::isResult($user) && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
1446                                 $page_theme = $user['theme'];
1447                         }
1448                 }
1449
1450                 $user_theme = Core\Session::get('theme', $system_theme);
1451
1452                 // Specific mobile theme override
1453                 if (($this->is_mobile || $this->is_tablet) && Core\Session::get('show-mobile', true)) {
1454                         $system_mobile_theme = Config::get('system', 'mobile-theme');
1455                         $user_mobile_theme = Core\Session::get('mobile-theme', $system_mobile_theme);
1456
1457                         // --- means same mobile theme as desktop
1458                         if (!empty($user_mobile_theme) && $user_mobile_theme !== '---') {
1459                                 $user_theme = $user_mobile_theme;
1460                         }
1461                 }
1462
1463                 if ($page_theme) {
1464                         $theme_name = $page_theme;
1465                 } else {
1466                         $theme_name = $user_theme;
1467                 }
1468
1469                 if ($theme_name
1470                         && in_array($theme_name, $allowed_themes)
1471                         && (file_exists('view/theme/' . $theme_name . '/style.css')
1472                         || file_exists('view/theme/' . $theme_name . '/style.php'))
1473                 ) {
1474                         $this->current_theme = $theme_name;
1475                 }
1476         }
1477
1478         /**
1479          * @brief Return full URL to theme which is currently in effect.
1480          *
1481          * Provide a sane default if nothing is chosen or the specified theme does not exist.
1482          *
1483          * @return string
1484          */
1485         public function getCurrentThemeStylesheetPath()
1486         {
1487                 return Core\Theme::getStylesheetPath($this->getCurrentTheme());
1488         }
1489 }