X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FApp.php;h=97c193b3b7f4937ec68fe62fc390dd1787ba04d2;hb=9239ecc5e0207eb5e62bea36f6ee200e4581932c;hp=fcde77846e172aa04315f76798748d9c480c1e0f;hpb=3d04562c87140a5d026e8405b6d1213b181ffc0d;p=friendica.git diff --git a/src/App.php b/src/App.php index fcde77846e..97c193b3b7 100644 --- a/src/App.php +++ b/src/App.php @@ -86,7 +86,7 @@ class App private $mode; /** - * @var string The App basepath + * @var string The App base path */ private $basePath; @@ -110,6 +110,11 @@ class App */ private $currentTheme; + /** + * @var bool check if request was an AJAX (xmlhttprequest) request + */ + private $isAjax; + /** * Register a stylesheet file path to be included in the tag of every page. * Inclusion is done in App->initHead(). @@ -322,6 +327,8 @@ class App $this->is_mobile = $mobile_detect->isMobile(); $this->is_tablet = $mobile_detect->isTablet(); + $this->isAjax = strtolower(defaults($_SERVER, 'HTTP_X_REQUESTED_WITH', '')) == 'xmlhttprequest'; + // Register template engines $this->registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); } @@ -522,20 +529,29 @@ class App */ private function determineURLPath() { + /* Relative script path to the web server root + * Not all of those $_SERVER properties can be present, so we do by inverse priority order + */ + $relative_script_path = ''; + $relative_script_path = defaults($_SERVER, 'REDIRECT_URL' , $relative_script_path); + $relative_script_path = defaults($_SERVER, 'REDIRECT_URI' , $relative_script_path); + $relative_script_path = defaults($_SERVER, 'REDIRECT_SCRIPT_URL', $relative_script_path); + $relative_script_path = defaults($_SERVER, 'SCRIPT_URL' , $relative_script_path); + $this->urlPath = $this->getConfigValue('system', 'urlpath'); - /* SCRIPT_URL gives /path/to/friendica/module/parameter + /* $relative_script_path gives /relative/path/to/friendica/module/parameter * QUERY_STRING gives pagename=module/parameter * - * To get /path/to/friendica we perform dirname() for as many levels as there are slashes in the QUERY_STRING + * To get /relative/path/to/friendica we perform dirname() for as many levels as there are slashes in the QUERY_STRING */ - if (!empty($_SERVER['SCRIPT_URL'])) { + if (!empty($relative_script_path)) { // Module if (!empty($_SERVER['QUERY_STRING'])) { - $path = trim(dirname($_SERVER['SCRIPT_URL'], substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/'); + $path = trim(dirname($relative_script_path, substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/'); } else { // Root page - $path = trim($_SERVER['SCRIPT_URL'], '/'); + $path = trim($relative_script_path, '/'); } if ($path && $path != $this->urlPath) { @@ -1212,7 +1228,7 @@ class App } } - $load = current_load(); + $load = System::currentLoad(); if ($load) { if (intval($load) > $maxsysload) { logger('system: load ' . $load . ' for ' . $process . ' tasks (' . $maxsysload . ') too high.'); @@ -1563,4 +1579,32 @@ class App { return Core\Theme::getStylesheetPath($this->getCurrentTheme()); } + + /** + * Check if request was an AJAX (xmlhttprequest) request. + * + * @return boolean true if it was an AJAX request + */ + public function isAjax() + { + return $this->isAjax; + } + + /** + * Returns the value of a argv key + * TODO there are a lot of $a->argv usages in combination with defaults() which can be replaced with this method + * + * @param int $position the position of the argument + * @param mixed $default the default value if not found + * + * @return mixed returns the value of the argument + */ + public function getArgumentValue($position, $default = '') + { + if (array_key_exists($position, $this->argv)) { + return $this->argv[$position]; + } + + return $default; + } }