From a20fa6a3a93475d6707f1a1aeedc4edc692935d9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 11 Jan 2019 19:27:56 -0500 Subject: [PATCH 1/4] Add ensureQueryParameter method to Util\Strings --- src/Util/Strings.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Util/Strings.php b/src/Util/Strings.php index 473774b71..a11ac2fd5 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -312,4 +312,20 @@ class Strings { return (strcasecmp(self::normaliseLink($a), self::normaliseLink($b)) === 0); } + + + /** + * Ensures the provided URI has its query string punctuation in order. + * + * @param string $uri + * @return string + */ + public static function ensureQueryParameter($uri) + { + if (strpos($uri, '?') === false && ($pos = strpos($uri, '&')) !== false) { + $uri = substr($uri, 0, $pos) . '?' . substr($uri, $pos + 1); + } + + return $uri; + } } From ec8b313c2d1fa818b976902c5a044a8425696ae4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 11 Jan 2019 19:29:39 -0500 Subject: [PATCH 2/4] Replace Pager->ensureQueryParameter by Strings::ensureQueryParameter --- src/Content/Pager.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Content/Pager.php b/src/Content/Pager.php index 0a1766fe5..fafb68084 100644 --- a/src/Content/Pager.php +++ b/src/Content/Pager.php @@ -4,6 +4,7 @@ namespace Friendica\Content; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\Util\Strings; /** * The Pager has two very different output, Minimal and Full, see renderMinimal() and renderFull() for more details. @@ -162,12 +163,12 @@ class Pager $data = [ 'class' => 'pager', 'prev' => [ - 'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)), + 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)), 'text' => L10n::t('newer'), 'class' => 'previous' . ($this->getPage() == 1 ? ' disabled' : '') ], 'next' => [ - 'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)), + 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)), 'text' => L10n::t('older'), 'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '') ] @@ -206,12 +207,12 @@ class Pager $data['class'] = 'pagination'; if ($totalItemCount > $this->getItemsPerPage()) { $data['first'] = [ - 'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=1'), + 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=1'), 'text' => L10n::t('first'), 'class' => $this->getPage() == 1 ? 'disabled' : '' ]; $data['prev'] = [ - 'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)), + 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)), 'text' => L10n::t('prev'), 'class' => $this->getPage() == 1 ? 'disabled' : '' ]; @@ -238,7 +239,7 @@ class Pager ]; } else { $pages[$i] = [ - 'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . $i), + 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $i), 'text' => $i, 'class' => 'n' ]; @@ -254,7 +255,7 @@ class Pager ]; } else { $pages[$i] = [ - 'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . $i), + 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $i), 'text' => $i, 'class' => 'n' ]; @@ -266,12 +267,12 @@ class Pager $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages); $data['next'] = [ - 'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)), + 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)), 'text' => L10n::t('next'), 'class' => $this->getPage() == $lastpage ? 'disabled' : '' ]; $data['last'] = [ - 'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . $lastpage), + 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $lastpage), 'text' => L10n::t('last'), 'class' => $this->getPage() == $lastpage ? 'disabled' : '' ]; From eaea24f98bfe31ac7d0df77948b5a0ff86d51eb0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 11 Jan 2019 19:29:55 -0500 Subject: [PATCH 3/4] Remove Pager->ensureQueryParameter --- src/Content/Pager.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/Content/Pager.php b/src/Content/Pager.php index fafb68084..064a7f90f 100644 --- a/src/Content/Pager.php +++ b/src/Content/Pager.php @@ -123,21 +123,6 @@ class Pager $this->baseQueryString = $stripped; } - /** - * Ensures the provided URI has its query string punctuation in order. - * - * @param string $uri - * @return string - */ - private function ensureQueryParameter($uri) - { - if (strpos($uri, '?') === false && ($pos = strpos($uri, '&')) !== false) { - $uri = substr($uri, 0, $pos) . '?' . substr($uri, $pos + 1); - } - - return $uri; - } - /** * @brief Minimal pager (newer/older) * From c5632a061fe3c712cb20bf4584a2292b8c2631ed Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 11 Jan 2019 19:30:33 -0500 Subject: [PATCH 4/4] Fix output of Pager->getBaseQueryString --- src/Content/Pager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Pager.php b/src/Content/Pager.php index 064a7f90f..4045ac844 100644 --- a/src/Content/Pager.php +++ b/src/Content/Pager.php @@ -83,7 +83,7 @@ class Pager */ public function getBaseQueryString() { - return $this->baseQueryString; + return Strings::ensureQueryParameter($this->baseQueryString); } /**