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