Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

123 lines
2.8 KiB

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