3 * @file src/Core/System.php
5 namespace Friendica\Core;
7 use Friendica\BaseObject;
8 use Friendica\Util\XML;
11 * @file include/Core/System.php
13 * @brief Contains the class with system relevant stuff
18 * @brief System methods
20 class System extends BaseObject
23 * @brief Retrieves the Friendica instance base URL
25 * @param bool $ssl Whether to append http or https under SSL_POLICY_SELFSIGN
26 * @return string Friendica server base URL
28 public static function baseUrl($ssl = false)
30 return self::getApp()->get_baseurl($ssl);
34 * @brief Removes the baseurl from an url. This avoids some mixed content problems.
36 * @param string $orig_url The url to be cleaned
38 * @return string The cleaned url
40 public static function removedBaseUrl($orig_url)
42 return self::getApp()->remove_baseurl($orig_url);
46 * @brief Returns a string with a callstack. Can be used for logging.
47 * @param integer $depth optional, default 4
50 public static function callstack($depth = 4)
52 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
54 // We remove the first two items from the list since they contain data that we don't need.
60 $previous = ['class' => '', 'function' => ''];
62 // The ignore list contains all functions that are only wrapper functions
63 $ignore = ['fetchUrl', 'call_user_func_array'];
65 while ($func = array_pop($trace)) {
66 if (!empty($func['class'])) {
67 // Don't show multiple calls from the "dba" class to show the essential parts of the callstack
68 if ((($previous['class'] != $func['class']) || ($func['class'] != 'dba')) && ($previous['function'] != 'q')) {
69 $classparts = explode("\\", $func['class']);
70 $callstack[] = array_pop($classparts).'::'.$func['function'];
73 } elseif (!in_array($func['function'], $ignore)) {
74 $callstack[] = $func['function'];
81 while ((count($callstack2) < $depth) && (count($callstack) > 0)) {
82 $callstack2[] = array_pop($callstack);
85 return implode(', ', $callstack2);
89 * @brief Called from db initialisation when db is dead.
91 static public function unavailable() {
94 <head><title>System Unavailable</title></head>
95 <body>Apologies but this site is unavailable at the moment. Please try again later.</body>
104 * Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable
105 * of $st and an optional text <message> of $message and terminates the current process.
107 public static function xmlExit($st, $message = '')
109 $result = ['status' => $st];
111 if ($message != '') {
112 $result['message'] = $message;
116 logger('xml_status returning non_zero: ' . $st . " message=" . $message);
119 header("Content-type: text/xml");
121 $xmldata = ["result" => $result];
123 echo XML::fromArray($xmldata, $xml);
129 * @brief Send HTTP status header and exit.
131 * @param integer $val HTTP status result value
132 * @param array $description optional message
133 * 'title' => header title
134 * 'description' => optional message
136 public static function httpExit($val, $description = [])
141 if (!isset($description["title"])) {
142 $description["title"] = $err." ".$val;
146 if ($val >= 200 && $val < 300) {
150 logger('http_status_exit ' . $val);
151 header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err);
153 if (isset($description["title"])) {
154 $tpl = get_markup_template('http_status.tpl');
158 '$title' => $description["title"],
159 '$description' => $description["description"]]
167 * @brief Encodes content to json.
169 * This function encodes an array to json format
170 * and adds an application/json HTTP header to the output.
171 * After finishing the process is getting killed.
173 * @param array $x The input content.
174 * @param string $content_type Type of the input (Default: 'application/json').
176 public static function jsonExit($x, $content_type = 'application/json') {
177 header("Content-type: $content_type");
178 echo json_encode($x);
182 /// @todo Move the following functions from boot.php
184 function get_guid($size = 16, $prefix = "")
187 function local_user()
188 function public_contact()
189 function remote_user()
192 function is_site_admin()
193 function random_digits($digits)
194 function get_server()
195 function get_temppath()
196 function get_cachefile($file, $writemode = true)
197 function get_itemcachepath()
198 function get_spoolpath()
199 function current_load()