X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FPager.php;h=f776249b1b5d7b1d1a72dcc280fe744aad02307e;hb=1f889b6086c5fe81a4ab694a55efa1134f8326b3;hp=badc8af4ec1498ead031fcace1b0ded3be2d02e3;hpb=0e05ff68686270d87447c570e28543a5bcc7e755;p=friendica.git diff --git a/src/Content/Pager.php b/src/Content/Pager.php index badc8af4ec..f776249b1b 100644 --- a/src/Content/Pager.php +++ b/src/Content/Pager.php @@ -1,6 +1,6 @@ l10n = $l10n; + $this->setQueryString($queryString); $this->setItemsPerPage($itemsPerPage); - $this->setPage(($_GET['page'] ?? 0) ?: 1); + $this->setPage((int)($_GET['page'] ?? 0) ?: 1); } /** * Returns the start offset for a LIMIT clause. Starts at 0. * - * @return integer + * @return int */ - public function getStart() + public function getStart(): int { return max(0, ($this->page * $this->itemsPerPage) - $this->itemsPerPage); } @@ -72,9 +74,9 @@ class Pager /** * Returns the number of items per page * - * @return integer + * @return int */ - public function getItemsPerPage() + public function getItemsPerPage(): int { return $this->itemsPerPage; } @@ -84,7 +86,7 @@ class Pager * * @return int */ - public function getPage() + public function getPage(): int { return $this->page; } @@ -106,9 +108,9 @@ class Pager /** * Sets the number of items per page, 1 minimum. * - * @param integer $itemsPerPage + * @param int $itemsPerPage */ - public function setItemsPerPage($itemsPerPage) + public function setItemsPerPage(int $itemsPerPage) { $this->itemsPerPage = max(1, intval($itemsPerPage)); } @@ -116,25 +118,24 @@ class Pager /** * Sets the current page number. Starts at 1. * - * @param integer $page + * @param int $page */ - public function setPage($page) + public function setPage(int $page) { - $this->page = max(1, intval($page)); + $this->page = max(1, $page); } /** * Sets the base query string from a full query string. * - * Strips the 'page' parameter, and remove the 'q=' string for some reason. + * Strips the 'page' parameter * * @param string $queryString */ - public function setQueryString($queryString) + public function setQueryString(string $queryString) { $stripped = preg_replace('/([&?]page=[0-9]*)/', '', $queryString); - $stripped = str_replace('q=', '', $stripped); $stripped = trim($stripped, '/'); $this->baseQueryString = $stripped; @@ -155,11 +156,11 @@ class Pager * * $html = $pager->renderMinimal(count($items)); * - * @param integer $itemCount The number of displayed items on the page + * @param int $itemCount The number of displayed items on the page * @return string HTML string of the pager - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \Exception */ - public function renderMinimal($itemCount) + public function renderMinimal(int $itemCount): string { $displayedItemCount = max(0, intval($itemCount)); @@ -167,12 +168,12 @@ class Pager 'class' => 'pager', 'prev' => [ 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)), - 'text' => DI::l10n()->t('newer'), + 'text' => $this->l10n->t('newer'), 'class' => 'previous' . ($this->getPage() == 1 ? ' disabled' : '') ], 'next' => [ 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)), - 'text' => DI::l10n()->t('older'), + 'text' => $this->l10n->t('older'), 'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '') ] ]; @@ -198,13 +199,13 @@ class Pager * * $html = $pager->renderFull(); * - * @param integer $itemCount The total number of items including those note displayed on the page + * @param int $itemCount The total number of items including those note displayed on the page * @return string HTML string of the pager * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function renderFull($itemCount) + public function renderFull(int $itemCount): string { - $totalItemCount = max(0, intval($itemCount)); + $totalItemCount = max(0, $itemCount); $data = []; @@ -212,12 +213,12 @@ class Pager if ($totalItemCount > $this->getItemsPerPage()) { $data['first'] = [ 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=1'), - 'text' => DI::l10n()->t('first'), + 'text' => $this->l10n->t('first'), 'class' => $this->getPage() == 1 ? 'disabled' : '' ]; $data['prev'] = [ 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)), - 'text' => DI::l10n()->t('prev'), + 'text' => $this->l10n->t('prev'), 'class' => $this->getPage() == 1 ? 'disabled' : '' ]; @@ -272,12 +273,12 @@ class Pager $data['next'] = [ 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)), - 'text' => DI::l10n()->t('next'), + 'text' => $this->l10n->t('next'), 'class' => $this->getPage() == $lastpage ? 'disabled' : '' ]; $data['last'] = [ 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $lastpage), - 'text' => DI::l10n()->t('last'), + 'text' => $this->l10n->t('last'), 'class' => $this->getPage() == $lastpage ? 'disabled' : '' ]; }