X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FApp%2FArguments.php;h=ae6c64a4f39715db1577e29a04d7ec7e294f659a;hb=f00792d370cfbf1d52b37e3eed7e80e682df9d8a;hp=8047186a0762d3dec2cb89893331e0268a93fad2;hpb=2c5ba7fc15b96016684f6c9e047144e10e8d7c46;p=friendica.git diff --git a/src/App/Arguments.php b/src/App/Arguments.php index 8047186a07..ae6c64a4f3 100644 --- a/src/App/Arguments.php +++ b/src/App/Arguments.php @@ -1,4 +1,23 @@ . + * + */ namespace Friendica\App; @@ -28,7 +47,7 @@ class Arguments */ private $argc; - public function __construct(string $queryString = '', string $command = '', array $argv = [Module::DEFAULT], int $argc = 1) + public function __construct(string $queryString = '', string $command = '', array $argv = [], int $argc = 0) { $this->queryString = $queryString; $this->command = $command; @@ -37,7 +56,7 @@ class Arguments } /** - * @return string The whole query string of this call + * @return string The whole query string of this call with url-encoded query parameters */ public function getQueryString() { @@ -68,9 +87,20 @@ class Arguments return $this->argc; } + public function setArgv(array $argv) + { + $this->argv = $argv; + $this->argc = count($argv); + } + + public function setArgc(int $argc) + { + $this->argc = $argc; + } + /** * 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 + * @todo there are a lot of $a->argv usages in combination with ?? which can be replaced with this method * * @param int $position the position of the argument * @param mixed $default the default value if not found @@ -102,50 +132,27 @@ class Arguments */ public function determine(array $server, array $get) { - $queryString = ''; + // removing leading / - maybe a nginx problem + $server['QUERY_STRING'] = ltrim($server['QUERY_STRING'] ?? '', '/'); - if (!empty($server['QUERY_STRING']) && strpos($server['QUERY_STRING'], 'pagename=') === 0) { - $queryString = substr($server['QUERY_STRING'], 9); - } elseif (!empty($server['QUERY_STRING']) && strpos($server['QUERY_STRING'], 'q=') === 0) { - $queryString = substr($server['QUERY_STRING'], 2); - } - - // eventually strip ZRL - $queryString = $this->stripZRLs($queryString); - - // eventually strip OWT - $queryString = $this->stripQueryParam($queryString, 'owt'); - - // removing trailing / - maybe a nginx problem - $queryString = ltrim($queryString, '/'); + $queryParameters = []; + parse_str($server['QUERY_STRING'], $queryParameters); if (!empty($get['pagename'])) { $command = trim($get['pagename'], '/\\'); + } elseif (!empty($queryParameters['pagename'])) { + $command = trim($queryParameters['pagename'], '/\\'); } elseif (!empty($get['q'])) { + // Legacy page name parameter, now conflicts with the search query parameter $command = trim($get['q'], '/\\'); } else { - $command = Module::DEFAULT; - } - - - // fix query_string - if (!empty($command)) { - $queryString = str_replace( - $command . '&', - $command . '?', - $queryString - ); - } - - // unix style "homedir" - if (substr($command, 0, 1) === '~') { - $command = 'profile/' . substr($command, 1); + $command = ''; } - // Diaspora style profile url - if (substr($command, 0, 2) === 'u/') { - $command = 'profile/' . substr($command, 2); - } + // Remove generated and one-time use parameters + unset($queryParameters['pagename']); + unset($queryParameters['zrl']); + unset($queryParameters['owt']); /* * Break the URL path into C style argc/argv style arguments for our @@ -154,41 +161,17 @@ class Arguments * [0] => 'module' * [1] => 'arg1' * [2] => 'arg2' - * - * - * There will always be one argument. If provided a naked domain - * URL, $this->argv[0] is set to "home". */ + if ($command) { + $argv = explode('/', $command); + } else { + $argv = []; + } - $argv = explode('/', $command); $argc = count($argv); + $queryString = $command . ($queryParameters ? '?' . http_build_query($queryParameters) : ''); return new Arguments($queryString, $command, $argv, $argc); } - - /** - * Strip zrl parameter from a string. - * - * @param string $queryString The input string. - * - * @return string The zrl. - */ - public function stripZRLs(string $queryString) - { - return preg_replace('/[?&]zrl=(.*?)(&|$)/ism', '$2', $queryString); - } - - /** - * Strip query parameter from a string. - * - * @param string $queryString The input string. - * @param string $param - * - * @return string The query parameter. - */ - public function stripQueryParam(string $queryString, string $param) - { - return preg_replace('/[?&]' . $param . '=(.*?)(&|$)/ism', '$2', $queryString); - } -} \ No newline at end of file +}