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