]> git.mxchange.org Git - friendica.git/blob - src/Core/System.php
Merge pull request #4060 from annando/system-unavailable
[friendica.git] / src / Core / System.php
1 <?php
2 /**
3  * @file src/Core/System.php
4  */
5 namespace Friendica\Core;
6
7 use Friendica\App;
8
9 /**
10  * @file include/Core/System.php
11  *
12  * @brief Contains the class with system relevant stuff
13  */
14
15
16 /**
17  * @brief System methods
18  */
19 class System
20 {
21         private static $a;
22
23         /**
24          * @brief Initializes the static class variable
25          * @return void
26          */
27         private static function init()
28         {
29                 global $a;
30
31                 if (!is_object(self::$a)) {
32                         self::$a = $a;
33                 }
34         }
35
36         /**
37          * @brief Retrieves the Friendica instance base URL
38          *
39          * @param bool $ssl Whether to append http or https under SSL_POLICY_SELFSIGN
40          * @return string Friendica server base URL
41          */
42         public static function baseUrl($ssl = false)
43         {
44                 self::init();
45                 return self::$a->get_baseurl($ssl);
46         }
47
48         /**
49          * @brief Removes the baseurl from an url. This avoids some mixed content problems.
50          *
51          * @param string $orig_url The url to be cleaned
52          *
53          * @return string The cleaned url
54          */
55         public static function removedBaseUrl($orig_url)
56         {
57                 self::init();
58                 return self::$a->remove_baseurl($orig_url);
59         }
60
61         /**
62          * @brief Returns a string with a callstack. Can be used for logging.
63          * @param integer $depth optional, default 4
64          * @return string
65          */
66         public static function callstack($depth = 4)
67         {
68                 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
69
70                 // We remove the first two items from the list since they contain data that we don't need.
71                 array_shift($trace);
72                 array_shift($trace);
73
74                 $callstack = array();
75                 $counter = 0;
76                 $previous = array('class' => '', 'function' => '');
77
78                 // The ignore list contains all functions that are only wrapper functions
79                 $ignore = array('get_config', 'get_pconfig', 'set_config', 'set_pconfig', 'fetch_url', 'probe_url');
80
81                 while ($func = array_pop($trace)) {
82                         if (!empty($func['class'])) {
83                                 // Don't show multiple calls from the same function (mostly used for "dba" class)
84                                 if (($previous['class'] != $func['class']) && ($previous['function'] != 'q')) {
85                                         $classparts = explode("\\", $func['class']);
86                                         $callstack[] = array_pop($classparts).'::'.$func['function'];
87                                         $previous = $func;
88                                 }
89                         } elseif (!in_array($func['function'], $ignore)) {
90                                 $callstack[] = $func['function'];
91                                 $previous = $func;
92                         }
93                 }
94
95                 $callstack2 = array();
96                 while ((count($callstack2) < $depth) && (count($callstack) > 0)) {
97                         $callstack2[] = array_pop($callstack);
98                 }
99
100                 return implode(', ', $callstack2);
101         }
102
103         /**
104          * @brief Called from db initialisation when db is dead.
105          */
106         static public function unavailable() {
107 echo <<< EOT
108 <html>
109         <head><title>System Unavailable</title></head>
110         <body>Apologies but this site is unavailable at the moment. Please try again later.</body>
111 </html>
112 EOT;
113
114                 killme();
115         }
116
117         /// @todo Move the following functions from boot.php
118         /*
119         function get_guid($size = 16, $prefix = "")
120         function killme()
121         function goaway($s)
122         function local_user()
123         function public_contact()
124         function remote_user()
125         function notice($s)
126         function info($s)
127         function is_site_admin()
128         function random_digits($digits)
129         function get_server()
130         function get_temppath()
131         function get_cachefile($file, $writemode = true)
132         function get_itemcachepath()
133         function get_spoolpath()
134         function current_load()
135         */
136 }