]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Pager.php
Remove deprecated code
[friendica.git] / src / Content / Pager.php
index 0a1766fe593ad225caa0d6555d202572d8650291..800aa760e6d92d57e342aca68843811739613ca3 100644 (file)
@@ -2,8 +2,9 @@
 
 namespace Friendica\Content;
 
-use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
+use Friendica\DI;
+use Friendica\Util\Strings;
 
 /**
  * The Pager has two very different output, Minimal and Full, see renderMinimal() and renderFull() for more details.
@@ -38,7 +39,7 @@ class Pager
        {
                $this->setQueryString($queryString);
                $this->setItemsPerPage($itemsPerPage);
-               $this->setPage(defaults($_GET, 'page', 1));
+               $this->setPage(($_GET['page'] ?? 0) ?: 1);
        }
 
        /**
@@ -64,7 +65,7 @@ class Pager
        /**
         * Returns the current page number
         *
-        * @return type
+        * @return int
         */
        public function getPage()
        {
@@ -82,7 +83,7 @@ class Pager
         */
        public function getBaseQueryString()
        {
-               return $this->baseQueryString;
+               return Strings::ensureQueryParameter($this->baseQueryString);
        }
 
        /**
@@ -123,22 +124,7 @@ class Pager
        }
 
        /**
-        * 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)
+        * Minimal pager (newer/older)
         *
         * This mode is intended for reverse chronological pages and presents only two links, newer (previous) and older (next).
         * The itemCount is the number of displayed items. If no items are displayed, the older button is disabled.
@@ -154,6 +140,7 @@ class Pager
         *
         * @param integer $itemCount The number of displayed items on the page
         * @return string HTML string of the pager
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public function renderMinimal($itemCount)
        {
@@ -162,13 +149,13 @@ class Pager
                $data = [
                        'class' => 'pager',
                        'prev'  => [
-                               'url'   => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
-                               'text'  => L10n::t('newer'),
+                               'url'   => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
+                               'text'  => DI::l10n()->t('newer'),
                                'class' => 'previous' . ($this->getPage() == 1 ? ' disabled' : '')
                        ],
                        'next'  => [
-                               'url'   => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
-                               'text'  => L10n::t('older'),
+                               'url'   => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
+                               'text'  => DI::l10n()->t('older'),
                                'class' =>  'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '')
                        ]
                ];
@@ -178,7 +165,7 @@ class Pager
        }
 
        /**
-        * @brief Full pager (first / prev / 1 / 2 / ... / 14 / 15 / next / last)
+        * Full pager (first / prev / 1 / 2 / ... / 14 / 15 / next / last)
         *
         * This mode presents page numbers as well as first, previous, next and last links.
         * The itemCount is the total number of items including those not displayed.
@@ -196,6 +183,7 @@ class Pager
         *
         * @param integer $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)
        {
@@ -206,13 +194,13 @@ class Pager
                $data['class'] = 'pagination';
                if ($totalItemCount > $this->getItemsPerPage()) {
                        $data['first'] = [
-                               'url'   => $this->ensureQueryParameter($this->baseQueryString . '&page=1'),
-                               'text'  => L10n::t('first'),
+                               'url'   => Strings::ensureQueryParameter($this->baseQueryString . '&page=1'),
+                               'text'  => DI::l10n()->t('first'),
                                'class' => $this->getPage() == 1 ? 'disabled' : ''
                        ];
                        $data['prev'] = [
-                               'url'   => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
-                               'text'  => L10n::t('prev'),
+                               'url'   => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
+                               'text'  => DI::l10n()->t('prev'),
                                'class' => $this->getPage() == 1 ? 'disabled' : ''
                        ];
 
@@ -238,7 +226,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 +242,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,13 +254,13 @@ class Pager
                        $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
 
                        $data['next'] = [
-                               'url'   => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
-                               'text'  => L10n::t('next'),
+                               'url'   => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
+                               'text'  => DI::l10n()->t('next'),
                                'class' => $this->getPage() == $lastpage ? 'disabled' : ''
                        ];
                        $data['last'] = [
-                               'url'   => $this->ensureQueryParameter($this->baseQueryString . '&page=' . $lastpage),
-                               'text'  => L10n::t('last'),
+                               'url'   => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $lastpage),
+                               'text'  => DI::l10n()->t('last'),
                                'class' => $this->getPage() == $lastpage ? 'disabled' : ''
                        ];
                }