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