Merge pull request #6426 from MrPetovan/bug/6425-fix-infinite-scroll-url
Fix infinite scroll base URL
This commit is contained in:
commit
cd3ab5ddc9
|
@ -4,6 +4,7 @@ namespace Friendica\Content;
|
||||||
|
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Renderer;
|
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.
|
* The Pager has two very different output, Minimal and Full, see renderMinimal() and renderFull() for more details.
|
||||||
|
@ -82,7 +83,7 @@ class Pager
|
||||||
*/
|
*/
|
||||||
public function getBaseQueryString()
|
public function getBaseQueryString()
|
||||||
{
|
{
|
||||||
return $this->baseQueryString;
|
return Strings::ensureQueryParameter($this->baseQueryString);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,21 +123,6 @@ class Pager
|
||||||
$this->baseQueryString = $stripped;
|
$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)
|
* @brief Minimal pager (newer/older)
|
||||||
*
|
*
|
||||||
|
@ -162,12 +148,12 @@ class Pager
|
||||||
$data = [
|
$data = [
|
||||||
'class' => 'pager',
|
'class' => 'pager',
|
||||||
'prev' => [
|
'prev' => [
|
||||||
'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
|
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
|
||||||
'text' => L10n::t('newer'),
|
'text' => L10n::t('newer'),
|
||||||
'class' => 'previous' . ($this->getPage() == 1 ? ' disabled' : '')
|
'class' => 'previous' . ($this->getPage() == 1 ? ' disabled' : '')
|
||||||
],
|
],
|
||||||
'next' => [
|
'next' => [
|
||||||
'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
|
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
|
||||||
'text' => L10n::t('older'),
|
'text' => L10n::t('older'),
|
||||||
'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '')
|
'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '')
|
||||||
]
|
]
|
||||||
|
@ -206,12 +192,12 @@ class Pager
|
||||||
$data['class'] = 'pagination';
|
$data['class'] = 'pagination';
|
||||||
if ($totalItemCount > $this->getItemsPerPage()) {
|
if ($totalItemCount > $this->getItemsPerPage()) {
|
||||||
$data['first'] = [
|
$data['first'] = [
|
||||||
'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=1'),
|
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=1'),
|
||||||
'text' => L10n::t('first'),
|
'text' => L10n::t('first'),
|
||||||
'class' => $this->getPage() == 1 ? 'disabled' : ''
|
'class' => $this->getPage() == 1 ? 'disabled' : ''
|
||||||
];
|
];
|
||||||
$data['prev'] = [
|
$data['prev'] = [
|
||||||
'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
|
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
|
||||||
'text' => L10n::t('prev'),
|
'text' => L10n::t('prev'),
|
||||||
'class' => $this->getPage() == 1 ? 'disabled' : ''
|
'class' => $this->getPage() == 1 ? 'disabled' : ''
|
||||||
];
|
];
|
||||||
|
@ -238,7 +224,7 @@ class Pager
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$pages[$i] = [
|
$pages[$i] = [
|
||||||
'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . $i),
|
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $i),
|
||||||
'text' => $i,
|
'text' => $i,
|
||||||
'class' => 'n'
|
'class' => 'n'
|
||||||
];
|
];
|
||||||
|
@ -254,7 +240,7 @@ class Pager
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$pages[$i] = [
|
$pages[$i] = [
|
||||||
'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . $i),
|
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $i),
|
||||||
'text' => $i,
|
'text' => $i,
|
||||||
'class' => 'n'
|
'class' => 'n'
|
||||||
];
|
];
|
||||||
|
@ -266,12 +252,12 @@ class Pager
|
||||||
$lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
|
$lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
|
||||||
|
|
||||||
$data['next'] = [
|
$data['next'] = [
|
||||||
'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
|
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
|
||||||
'text' => L10n::t('next'),
|
'text' => L10n::t('next'),
|
||||||
'class' => $this->getPage() == $lastpage ? 'disabled' : ''
|
'class' => $this->getPage() == $lastpage ? 'disabled' : ''
|
||||||
];
|
];
|
||||||
$data['last'] = [
|
$data['last'] = [
|
||||||
'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . $lastpage),
|
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $lastpage),
|
||||||
'text' => L10n::t('last'),
|
'text' => L10n::t('last'),
|
||||||
'class' => $this->getPage() == $lastpage ? 'disabled' : ''
|
'class' => $this->getPage() == $lastpage ? 'disabled' : ''
|
||||||
];
|
];
|
||||||
|
|
|
@ -312,4 +312,20 @@ class Strings
|
||||||
{
|
{
|
||||||
return (strcasecmp(self::normaliseLink($a), self::normaliseLink($b)) === 0);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue