7 use Friendica\Core\Cache;
8 use Friendica\Core\Config;
9 use Friendica\Core\L10n;
10 use Friendica\Core\PConfig;
11 use Friendica\Core\System;
13 use Detection\MobileDetect;
17 require_once 'boot.php';
18 require_once 'include/text.php';
24 * @brief Our main application structure for the life of this page.
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.
35 public $module_loaded = false;
36 public $module_class = null;
50 public $error = false;
61 public $interactive = true;
63 public $addons_admin = [];
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;
75 // Allow themes to control internal parameters
76 // by changing App values in theme.php
78 public $sourcename = '';
79 public $videowidth = 425;
80 public $videoheight = 350;
81 public $force_max_items = 0;
82 public $theme_events_in_profile = true;
85 * @brief An array for all theme-controllable parameters
87 * Mostly unimplemented yet. Only options 'template_engine' and
94 'force_max_items' => 0,
96 'template_engine' => 'smarty3',
100 * @brief An array of registered template engines ('name'=>'class name')
102 public $template_engines = [];
105 * @brief An array of instanced template engines ('name'=>'instance')
107 public $template_engine_instance = [];
121 private $curl_content_type;
122 private $curl_headers;
126 * @brief App constructor.
128 * @param string $basepath Path to the app base folder
130 public function __construct($basepath)
132 global $default_timezone;
134 if (!static::directory_usable($basepath, false)) {
135 throw new Exception('Basepath ' . $basepath . ' isn\'t usable.');
138 $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);
140 if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php')) {
141 include $this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php';
144 $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
146 date_default_timezone_set($this->timezone);
148 $this->performance['start'] = microtime(true);
149 $this->performance['database'] = 0;
150 $this->performance['database_write'] = 0;
151 $this->performance['cache'] = 0;
152 $this->performance['cache_write'] = 0;
153 $this->performance['network'] = 0;
154 $this->performance['file'] = 0;
155 $this->performance['rendering'] = 0;
156 $this->performance['parser'] = 0;
157 $this->performance['marktime'] = 0;
158 $this->performance['markstart'] = microtime(true);
160 $this->callstack['database'] = [];
161 $this->callstack['database_write'] = [];
162 $this->callstack['cache'] = [];
163 $this->callstack['cache_write'] = [];
164 $this->callstack['network'] = [];
165 $this->callstack['file'] = [];
166 $this->callstack['rendering'] = [];
167 $this->callstack['parser'] = [];
173 $this->query_string = '';
175 $this->process_id = uniqid('log', true);
179 $this->scheme = 'http';
181 if ((x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) ||
182 (x($_SERVER, 'HTTP_FORWARDED') && preg_match('/proto=https/', $_SERVER['HTTP_FORWARDED'])) ||
183 (x($_SERVER, 'HTTP_X_FORWARDED_PROTO') && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ||
184 (x($_SERVER, 'HTTP_X_FORWARDED_SSL') && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') ||
185 (x($_SERVER, 'FRONT_END_HTTPS') && $_SERVER['FRONT_END_HTTPS'] == 'on') ||
186 (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much?
188 $this->scheme = 'https';
191 if (x($_SERVER, 'SERVER_NAME')) {
192 $this->hostname = $_SERVER['SERVER_NAME'];
194 if (x($_SERVER, 'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
195 $this->hostname .= ':' . $_SERVER['SERVER_PORT'];
198 * Figure out if we are running at the top of a domain
199 * or in a sub-directory and adjust accordingly
202 /// @TODO This kind of escaping breaks syntax-highlightning on CoolEdit (Midnight Commander)
203 $path = trim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
204 if (isset($path) && strlen($path) && ($path != $this->path)) {
210 get_include_path() . PATH_SEPARATOR
211 . $this->basepath . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR
212 . $this->basepath . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
215 if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 9) === 'pagename=') {
216 $this->query_string = substr($_SERVER['QUERY_STRING'], 9);
218 // removing trailing / - maybe a nginx problem
219 $this->query_string = ltrim($this->query_string, '/');
220 } elseif ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === 'q=') {
221 $this->query_string = substr($_SERVER['QUERY_STRING'], 2);
223 // removing trailing / - maybe a nginx problem
224 $this->query_string = ltrim($this->query_string, '/');
227 if (x($_GET, 'pagename')) {
228 $this->cmd = trim($_GET['pagename'], '/\\');
229 } elseif (x($_GET, 'q')) {
230 $this->cmd = trim($_GET['q'], '/\\');
234 $this->query_string = str_replace($this->cmd . '&', $this->cmd . '?', $this->query_string);
236 // unix style "homedir"
237 if (substr($this->cmd, 0, 1) === '~') {
238 $this->cmd = 'profile/' . substr($this->cmd, 1);
241 // Diaspora style profile url
242 if (substr($this->cmd, 0, 2) === 'u/') {
243 $this->cmd = 'profile/' . substr($this->cmd, 2);
247 * Break the URL path into C style argc/argv style arguments for our
248 * modules. Given "http://example.com/module/arg1/arg2", $this->argc
249 * will be 3 (integer) and $this->argv will contain:
255 * There will always be one argument. If provided a naked domain
256 * URL, $this->argv[0] is set to "home".
259 $this->argv = explode('/', $this->cmd);
260 $this->argc = count($this->argv);
261 if ((array_key_exists('0', $this->argv)) && strlen($this->argv[0])) {
262 $this->module = str_replace('.', '_', $this->argv[0]);
263 $this->module = str_replace('-', '_', $this->module);
266 $this->argv = ['home'];
267 $this->module = 'home';
270 // See if there is any page number information, and initialise pagination
271 $this->pager['page'] = ((x($_GET, 'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
272 $this->pager['itemspage'] = 50;
273 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
275 if ($this->pager['start'] < 0) {
276 $this->pager['start'] = 0;
278 $this->pager['total'] = 0;
280 // Detect mobile devices
281 $mobile_detect = new MobileDetect();
282 $this->is_mobile = $mobile_detect->isMobile();
283 $this->is_tablet = $mobile_detect->isTablet();
286 $this->is_friendica_app = ($_SERVER['HTTP_USER_AGENT'] == 'Apache-HttpClient/UNAVAILABLE (java 1.4)');
288 // Register template engines
289 $this->register_template_engine('Friendica\Render\FriendicaSmartyEngine');
295 * @brief Returns the base filesystem path of the App
297 * It first checks for the internal variable, then for DOCUMENT_ROOT and
302 public function get_basepath()
304 $basepath = $this->basepath;
307 $basepath = Config::get('system', 'basepath');
310 if (!$basepath && x($_SERVER, 'DOCUMENT_ROOT')) {
311 $basepath = $_SERVER['DOCUMENT_ROOT'];
314 if (!$basepath && x($_SERVER, 'PWD')) {
315 $basepath = $_SERVER['PWD'];
318 return self::realpath($basepath);
322 * @brief Returns a normalized file path
324 * This is a wrapper for the "realpath" function.
325 * That function cannot detect the real path when some folders aren't readable.
326 * Since this could happen with some hosters we need to handle this.
328 * @param string $path The path that is about to be normalized
329 * @return string normalized path - when possible
331 public static function realpath($path)
333 $normalized = realpath($path);
335 if (!is_bool($normalized)) {
342 public function get_scheme()
344 return $this->scheme;
348 * @brief Retrieves the Friendica instance base URL
350 * This function assembles the base URL from multiple parts:
351 * - Protocol is determined either by the request or a combination of
352 * system.ssl_policy and the $ssl parameter.
353 * - Host name is determined either by system.hostname or inferred from request
354 * - Path is inferred from SCRIPT_NAME
356 * Note: $ssl parameter value doesn't directly correlate with the resulting protocol
358 * @param bool $ssl Whether to append http or https under SSL_POLICY_SELFSIGN
359 * @return string Friendica server base URL
361 public function get_baseurl($ssl = false)
363 $scheme = $this->scheme;
365 if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {
369 // Basically, we have $ssl = true on any links which can only be seen by a logged in user
370 // (and also the login link). Anything seen by an outsider will have it turned off.
372 if (Config::get('system', 'ssl_policy') == SSL_POLICY_SELFSIGN) {
380 if (Config::get('config', 'hostname') != '') {
381 $this->hostname = Config::get('config', 'hostname');
384 return $scheme . '://' . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
388 * @brief Initializes the baseurl components
390 * Clears the baseurl cache to prevent inconsistencies
394 public function set_baseurl($url)
396 $parsed = @parse_url($url);
399 $this->scheme = $parsed['scheme'];
401 $hostname = $parsed['host'];
402 if (x($parsed, 'port')) {
403 $hostname .= ':' . $parsed['port'];
405 if (x($parsed, 'path')) {
406 $this->path = trim($parsed['path'], '\\/');
409 if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php')) {
410 include $this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php';
413 if (Config::get('config', 'hostname') != '') {
414 $this->hostname = Config::get('config', 'hostname');
417 if (!isset($this->hostname) || ( $this->hostname == '')) {
418 $this->hostname = $hostname;
423 public function get_hostname()
425 if (Config::get('config', 'hostname') != '') {
426 $this->hostname = Config::get('config', 'hostname');
429 return $this->hostname;
432 public function get_path()
437 public function set_pager_total($n)
439 $this->pager['total'] = intval($n);
442 public function set_pager_itemspage($n)
444 $this->pager['itemspage'] = ((intval($n) > 0) ? intval($n) : 0);
445 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
448 public function set_pager_page($n)
450 $this->pager['page'] = $n;
451 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
454 public function init_pagehead()
456 $interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000);
458 // If the update is 'deactivated' set it to the highest integer number (~24 days)
460 $interval = 2147483647;
463 if ($interval < 10000) {
467 // compose the page title from the sitename and the
468 // current module called
469 if (!$this->module == '') {
470 $this->page['title'] = $this->config['sitename'] . ' (' . $this->module . ')';
472 $this->page['title'] = $this->config['sitename'];
475 /* put the head template at the beginning of page['htmlhead']
476 * since the code added by the modules frequently depends on it
479 if (!isset($this->page['htmlhead'])) {
480 $this->page['htmlhead'] = '';
483 // If we're using Smarty, then doing replace_macros() will replace
484 // any unrecognized variables with a blank string. Since we delay
485 // replacing $stylesheet until later, we need to replace it now
486 // with another variable name
487 if ($this->theme['template_engine'] === 'smarty3') {
488 $stylesheet = $this->get_template_ldelim('smarty3') . '$stylesheet' . $this->get_template_rdelim('smarty3');
490 $stylesheet = '$stylesheet';
493 $shortcut_icon = Config::get('system', 'shortcut_icon');
494 if ($shortcut_icon == '') {
495 $shortcut_icon = 'images/friendica-32.png';
498 $touch_icon = Config::get('system', 'touch_icon');
499 if ($touch_icon == '') {
500 $touch_icon = 'images/friendica-128.png';
503 // get data wich is needed for infinite scroll on the network page
504 $invinite_scroll = infinite_scroll_data($this->module);
506 $tpl = get_markup_template('head.tpl');
507 $this->page['htmlhead'] = replace_macros($tpl, [
508 '$baseurl' => $this->get_baseurl(),
509 '$local_user' => local_user(),
510 '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION,
511 '$delitem' => L10n::t('Delete this item?'),
512 '$showmore' => L10n::t('show more'),
513 '$showfewer' => L10n::t('show fewer'),
514 '$update_interval' => $interval,
515 '$shortcut_icon' => $shortcut_icon,
516 '$touch_icon' => $touch_icon,
517 '$stylesheet' => $stylesheet,
518 '$infinite_scroll' => $invinite_scroll,
519 ]) . $this->page['htmlhead'];
522 public function init_page_end()
524 if (!isset($this->page['end'])) {
525 $this->page['end'] = '';
527 $tpl = get_markup_template('end.tpl');
528 $this->page['end'] = replace_macros($tpl, [
529 '$baseurl' => $this->get_baseurl()
530 ]) . $this->page['end'];
533 public function set_curl_code($code)
535 $this->curl_code = $code;
538 public function get_curl_code()
540 return $this->curl_code;
543 public function set_curl_content_type($content_type)
545 $this->curl_content_type = $content_type;
548 public function get_curl_content_type()
550 return $this->curl_content_type;
553 public function set_curl_headers($headers)
555 $this->curl_headers = $headers;
558 public function get_curl_headers()
560 return $this->curl_headers;
564 * @brief Removes the base url from an url. This avoids some mixed content problems.
566 * @param string $orig_url
568 * @return string The cleaned url
570 public function remove_baseurl($orig_url)
572 // Remove the hostname from the url if it is an internal link
573 $nurl = normalise_link($orig_url);
574 $base = normalise_link($this->get_baseurl());
575 $url = str_replace($base . '/', '', $nurl);
577 // if it is an external link return the orignal value
578 if ($url == normalise_link($orig_url)) {
586 * @brief Register template engine class
588 * @param string $class
590 private function register_template_engine($class)
592 $v = get_class_vars($class);
595 $this->template_engines[$name] = $class;
597 echo "template engine <tt>$class</tt> cannot be registered without a name.\n";
603 * @brief Return template engine instance.
605 * If $name is not defined, return engine defined by theme,
608 * @return object Template Engine instance
610 public function template_engine()
612 $template_engine = 'smarty3';
613 if (x($this->theme, 'template_engine')) {
614 $template_engine = $this->theme['template_engine'];
617 if (isset($this->template_engines[$template_engine])) {
618 if (isset($this->template_engine_instance[$template_engine])) {
619 return $this->template_engine_instance[$template_engine];
621 $class = $this->template_engines[$template_engine];
623 $this->template_engine_instance[$template_engine] = $obj;
628 echo "template engine <tt>$template_engine</tt> is not registered!\n";
633 * @brief Returns the active template engine.
637 public function get_template_engine()
639 return $this->theme['template_engine'];
642 public function set_template_engine($engine = 'smarty3')
644 $this->theme['template_engine'] = $engine;
647 public function get_template_ldelim($engine = 'smarty3')
649 return $this->ldelim[$engine];
652 public function get_template_rdelim($engine = 'smarty3')
654 return $this->rdelim[$engine];
657 public function save_timestamp($stamp, $value)
659 if (!isset($this->config['system']['profiler']) || !$this->config['system']['profiler']) {
663 $duration = (float) (microtime(true) - $stamp);
665 if (!isset($this->performance[$value])) {
666 // Prevent ugly E_NOTICE
667 $this->performance[$value] = 0;
670 $this->performance[$value] += (float) $duration;
671 $this->performance['marktime'] += (float) $duration;
673 $callstack = System::callstack();
675 if (!isset($this->callstack[$value][$callstack])) {
676 // Prevent ugly E_NOTICE
677 $this->callstack[$value][$callstack] = 0;
680 $this->callstack[$value][$callstack] += (float) $duration;
683 public function get_useragent()
686 FRIENDICA_PLATFORM . " '" .
687 FRIENDICA_CODENAME . "' " .
688 FRIENDICA_VERSION . '-' .
689 DB_UPDATE_VERSION . '; ' .
690 $this->get_baseurl();
693 public function is_friendica_app()
695 return $this->is_friendica_app;
699 * @brief Checks if the site is called via a backend process
701 * This isn't a perfect solution. But we need this check very early.
702 * So we cannot wait until the modules are loaded.
704 * @return bool Is it a known backend?
706 public function is_backend()
730 // Check if current module is in backend or backend flag is set
731 return (in_array($this->module, $backends) || $this->backend);
735 * @brief Checks if the maximum number of database processes is reached
737 * @return bool Is the limit reached?
739 public function max_processes_reached()
741 // Deactivated, needs more investigating if this check really makes sense
745 * Commented out to suppress static analyzer issues
747 if ($this->is_backend()) {
748 $process = 'backend';
749 $max_processes = Config::get('system', 'max_processes_backend');
750 if (intval($max_processes) == 0) {
754 $process = 'frontend';
755 $max_processes = Config::get('system', 'max_processes_frontend');
756 if (intval($max_processes) == 0) {
761 $processlist = DBM::processlist();
762 if ($processlist['list'] != '') {
763 logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
765 if ($processlist['amount'] > $max_processes) {
766 logger('Processcheck: Maximum number of processes for ' . $process . ' tasks (' . $max_processes . ') reached.', LOGGER_DEBUG);
775 * @brief Checks if the minimal memory is reached
777 * @return bool Is the memory limit reached?
779 public function min_memory_reached()
781 $min_memory = Config::get('system', 'min_memory', 0);
782 if ($min_memory == 0) {
786 if (!is_readable('/proc/meminfo')) {
790 $memdata = explode("\n", file_get_contents('/proc/meminfo'));
793 foreach ($memdata as $line) {
794 list($key, $val) = explode(':', $line);
795 $meminfo[$key] = (int) trim(str_replace('kB', '', $val));
796 $meminfo[$key] = (int) ($meminfo[$key] / 1024);
799 if (!isset($meminfo['MemAvailable']) || !isset($meminfo['MemFree'])) {
803 $free = $meminfo['MemAvailable'] + $meminfo['MemFree'];
805 $reached = ($free < $min_memory);
808 logger('Minimal memory reached: ' . $free . '/' . $meminfo['MemTotal'] . ' - limit ' . $min_memory, LOGGER_DEBUG);
815 * @brief Checks if the maximum load is reached
817 * @return bool Is the load reached?
819 public function maxload_reached()
821 if ($this->is_backend()) {
822 $process = 'backend';
823 $maxsysload = intval(Config::get('system', 'maxloadavg'));
824 if ($maxsysload < 1) {
828 $process = 'frontend';
829 $maxsysload = intval(Config::get('system', 'maxloadavg_frontend'));
830 if ($maxsysload < 1) {
835 $load = current_load();
837 if (intval($load) > $maxsysload) {
838 logger('system: load ' . $load . ' for ' . $process . ' tasks (' . $maxsysload . ') too high.');
845 public function proc_run($args)
847 if (!function_exists('proc_open')) {
851 // If the last worker fork was less than 2 seconds before then don't fork another one.
852 // This should prevent the forking of masses of workers.
853 $cachekey = 'app:proc_run:started';
854 $result = Cache::get($cachekey);
856 if (!is_null($result) && ( time() - $result) < 2) {
860 // Set the timestamp of the last proc_run
861 Cache::set($cachekey, time(), CACHE_MINUTE);
863 array_unshift($args, ((x($this->config, 'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'));
865 for ($x = 0; $x < count($args); $x ++) {
866 $args[$x] = escapeshellarg($args[$x]);
869 $cmdline = implode(' ', $args);
871 if ($this->min_memory_reached()) {
875 if (Config::get('system', 'proc_windows')) {
876 $resource = proc_open('cmd /c start /b ' . $cmdline, [], $foo, $this->get_basepath());
878 $resource = proc_open($cmdline . ' &', [], $foo, $this->get_basepath());
880 if (!is_resource($resource)) {
881 logger('We got no resource for command ' . $cmdline, LOGGER_DEBUG);
884 proc_close($resource);
888 * @brief Returns the system user that is executing the script
890 * This mostly returns something like "www-data".
892 * @return string system username
894 private static function systemuser()
896 if (!function_exists('posix_getpwuid') || !function_exists('posix_geteuid')) {
900 $processUser = posix_getpwuid(posix_geteuid());
901 return $processUser['name'];
905 * @brief Checks if a given directory is usable for the system
907 * @return boolean the directory is usable
909 public static function directory_usable($directory, $check_writable = true)
911 if ($directory == '') {
912 logger('Directory is empty. This shouldn\'t happen.', LOGGER_DEBUG);
916 if (!file_exists($directory)) {
917 logger('Path "' . $directory . '" does not exist for user ' . self::systemuser(), LOGGER_DEBUG);
921 if (is_file($directory)) {
922 logger('Path "' . $directory . '" is a file for user ' . self::systemuser(), LOGGER_DEBUG);
926 if (!is_dir($directory)) {
927 logger('Path "' . $directory . '" is not a directory for user ' . self::systemuser(), LOGGER_DEBUG);
931 if ($check_writable && !is_writable($directory)) {
932 logger('Path "' . $directory . '" is not writable for user ' . self::systemuser(), LOGGER_DEBUG);
940 * @param string $cat Config category
941 * @param string $k Config key
942 * @param mixed $default Default value if it isn't set
944 public function getConfigValue($cat, $k, $default = null)
948 if ($cat === 'config') {
949 if (isset($this->config[$k])) {
950 $return = $this->config[$k];
953 if (isset($this->config[$cat][$k])) {
954 $return = $this->config[$cat][$k];
962 * Sets a value in the config cache. Accepts raw output from the config table
964 * @param string $cat Config category
965 * @param string $k Config key
966 * @param mixed $v Value to set
968 public function setConfigValue($cat, $k, $v)
970 // Only arrays are serialized in database, so we have to unserialize sparingly
971 $value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v;
973 if ($cat === 'config') {
974 $this->config[$k] = $value;
976 $this->config[$cat][$k] = $value;
981 * Deletes a value from the config cache
983 * @param string $cat Config category
984 * @param string $k Config key
986 public function deleteConfigValue($cat, $k)
988 if ($cat === 'config') {
989 if (isset($this->config[$k])) {
990 unset($this->config[$k]);
993 if (isset($this->config[$cat][$k])) {
994 unset($this->config[$cat][$k]);
1001 * Retrieves a value from the user config cache
1003 * @param int $uid User Id
1004 * @param string $cat Config category
1005 * @param string $k Config key
1006 * @param mixed $default Default value if key isn't set
1008 public function getPConfigValue($uid, $cat, $k, $default = null)
1012 if (isset($this->config[$uid][$cat][$k])) {
1013 $return = $this->config[$uid][$cat][$k];
1020 * Sets a value in the user config cache
1022 * Accepts raw output from the pconfig table
1024 * @param int $uid User Id
1025 * @param string $cat Config category
1026 * @param string $k Config key
1027 * @param mixed $v Value to set
1029 public function setPConfigValue($uid, $cat, $k, $v)
1031 // Only arrays are serialized in database, so we have to unserialize sparingly
1032 $value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v;
1034 $this->config[$uid][$cat][$k] = $value;
1038 * Deletes a value from the user config cache
1040 * @param int $uid User Id
1041 * @param string $cat Config category
1042 * @param string $k Config key
1044 public function deletePConfigValue($uid, $cat, $k)
1046 if (isset($this->config[$uid][$cat][$k])) {
1047 unset($this->config[$uid][$cat][$k]);
1052 * Generates the site's default sender email address
1056 public function getSenderEmailAddress()
1058 $sender_email = Config::get('config', 'sender_email');
1059 if (empty($sender_email)) {
1060 $hostname = $this->get_hostname();
1061 if (strpos($hostname, ':')) {
1062 $hostname = substr($hostname, 0, strpos($hostname, ':'));
1065 $sender_email = 'noreply@' . $hostname;
1068 return $sender_email;