diff --git a/mod/common.php b/mod/common.php index 6e923fd19b..0ccad42387 100644 --- a/mod/common.php +++ b/mod/common.php @@ -107,7 +107,7 @@ function common_content(App $a) return $o; } - $pager = new Pager(DI::args()->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); if ($cid) { $common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage()); diff --git a/mod/message.php b/mod/message.php index e871e22e31..c62a15eb23 100644 --- a/mod/message.php +++ b/mod/message.php @@ -296,7 +296,7 @@ function message_content(App $a) $total = $r[0]['total']; } - $pager = new Pager(DI::args()->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); $r = get_messages(local_user(), $pager->getStart(), $pager->getItemsPerPage()); diff --git a/mod/network.php b/mod/network.php index 037a16ebfd..31cafb5a86 100644 --- a/mod/network.php +++ b/mod/network.php @@ -377,7 +377,7 @@ function networkFlatView(App $a, $update = 0) } } - $pager = new Pager(DI::args()->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); networkPager($a, $pager, $update); @@ -669,7 +669,7 @@ function networkThreadedView(App $a, $update, $parent) $sql_range = ''; } - $pager = new Pager(DI::args()->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); $pager_sql = networkPager($a, $pager, $update); diff --git a/mod/notes.php b/mod/notes.php index 34cf404ca8..602514a54a 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -69,7 +69,7 @@ function notes_content(App $a, $update = false) $condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => GRAVITY_PARENT, 'contact-id'=> $a->contact['id']]; - $pager = new Pager(DI::args()->getQueryString(), 40); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 40); $params = ['order' => ['created' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; diff --git a/mod/photos.php b/mod/photos.php index 5e5917452c..03b78e0e19 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1023,7 +1023,7 @@ function photos_content(App $a) $total = count($r); } - $pager = new Pager(DI::args()->getQueryString(), 20); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20); /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it? $order_field = $_GET['order'] ?? ''; @@ -1299,7 +1299,7 @@ function photos_content(App $a) $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']]; $total = DBA::count('item', $condition); - $pager = new Pager(DI::args()->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params); @@ -1565,7 +1565,7 @@ function photos_content(App $a) $total = count($r); } - $pager = new Pager(DI::args()->getQueryString(), 20); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20); $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`, diff --git a/mod/videos.php b/mod/videos.php index 3cb2b84bcd..49c64ef973 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -225,7 +225,7 @@ function videos_content(App $a) $total = count($r); } - $pager = new Pager(DI::args()->getQueryString(), 20); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20); $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype` diff --git a/src/Content/BoundariesPager.php b/src/Content/BoundariesPager.php index da296bd8cc..b8b7f67bba 100644 --- a/src/Content/BoundariesPager.php +++ b/src/Content/BoundariesPager.php @@ -21,17 +21,18 @@ namespace Friendica\Content; +use Friendica\Core\L10n; use Friendica\Core\Renderer; -use Friendica\DI; use Friendica\Util\Network; use Friendica\Util\Strings; /** - * This pager should be used by lists using the since_id/max_id parameters + * This pager should be used by lists using the since_id†/max_id† parameters * - * In this context, "id" refers to the value of the column that the list is ordered by. - * This pager automatically identifies if the sorting is done increasingly or decreasingly if the first item id - * and last item id are different. Otherwise it defaults to decreasingly like reverse chronological lists. + * This pager automatically identifies if the sorting is done increasingly or decreasingly if the first item id† + * and last item id† are different. Otherwise it defaults to decreasingly like reverse chronological lists. + * + * † In this context, "id" refers to the value of the column that the item list is ordered by. */ class BoundariesPager extends Pager { @@ -42,14 +43,15 @@ class BoundariesPager extends Pager /** * Instantiates a new Pager with the base parameters. * + * @param L10n $l10n * @param string $queryString The query string of the current page - * @param string $first_item_id The i - * @param string $last_item_id - * @param integer $itemsPerPage An optional number of items per page to override the default value + * @param string $first_item_id The id† of the first item in the displayed item list + * @param string $last_item_id The id† of the last item in the displayed item list + * @param integer $itemsPerPage An optional number of items per page to override the default value */ - public function __construct($queryString, $first_item_id = null, $last_item_id = null, $itemsPerPage = 50) + public function __construct(L10n $l10n, $queryString, $first_item_id = null, $last_item_id = null, $itemsPerPage = 50) { - parent::__construct($queryString, $itemsPerPage); + parent::__construct($l10n, $queryString, $itemsPerPage); $this->first_item_id = $first_item_id; $this->last_item_id = $last_item_id; @@ -111,7 +113,7 @@ class BoundariesPager extends Pager ($this->first_item_id >= $this->last_item_id ? '&since_id=' . $this->first_item_id : '&max_id=' . $this->first_item_id) ), - 'text' => DI::l10n()->t('newer'), + 'text' => $this->l10n->t('newer'), 'class' => 'previous' . ($this->first_page ? ' disabled' : '') ], 'next' => [ @@ -119,7 +121,7 @@ class BoundariesPager extends Pager ($this->first_item_id >= $this->last_item_id ? '&max_id=' . $this->last_item_id : '&since_id=' . $this->last_item_id) ), - 'text' => DI::l10n()->t('older'), + 'text' => $this->l10n->t('older'), 'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '') ] ]; diff --git a/src/Content/Pager.php b/src/Content/Pager.php index a7d7fe8f78..5b4345a4c8 100644 --- a/src/Content/Pager.php +++ b/src/Content/Pager.php @@ -21,8 +21,8 @@ namespace Friendica\Content; +use Friendica\Core\L10n; use Friendica\Core\Renderer; -use Friendica\DI; use Friendica\Util\Strings; /** @@ -30,30 +30,29 @@ use Friendica\Util\Strings; */ class Pager { - /** - * @var integer - */ + /** @var integer */ private $page = 1; - /** - * @var integer - */ + /** @var integer */ protected $itemsPerPage = 50; - - /** - * @var string - */ + /** @var string */ protected $baseQueryString = ''; + /** @var L10n */ + protected $l10n; + /** * Instantiates a new Pager with the base parameters. * * Guesses the page number from the GET parameter 'page'. * + * @param L10n $l10n * @param string $queryString The query string of the current page * @param integer $itemsPerPage An optional number of items per page to override the default value */ - public function __construct($queryString, $itemsPerPage = 50) + public function __construct(L10n $l10n, $queryString, $itemsPerPage = 50) { + $this->l10n = $l10n; + $this->setQueryString($queryString); $this->setItemsPerPage($itemsPerPage); $this->setPage(($_GET['page'] ?? 0) ?: 1); @@ -166,12 +165,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' : '') ] ]; @@ -211,12 +210,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' : '' ]; @@ -271,12 +270,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' : '' ]; } diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 789062403b..f1fec640a8 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1805,7 +1805,7 @@ class Contact $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()]; } - $pager = new Pager(DI::args()->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); $params = ['order' => ['received' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; diff --git a/src/Module/Admin/Blocklist/Contact.php b/src/Module/Admin/Blocklist/Contact.php index 5d87139df5..8893623234 100644 --- a/src/Module/Admin/Blocklist/Contact.php +++ b/src/Module/Admin/Blocklist/Contact.php @@ -68,7 +68,7 @@ class Contact extends BaseAdmin $total = DBA::count('contact', $condition); - $pager = new Pager(DI::args()->getQueryString(), 30); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30); $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]); diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index fbaab1ded2..b446a2c47c 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -194,7 +194,7 @@ class Users extends BaseAdmin /* get pending */ $pending = Register::getPending(); - $pager = new Pager(DI::args()->getQueryString(), 100); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 100); // @TODO Move below block to Model\User::getUsers($start, $count, $order = 'contact.name', $order_direction = '+') $valid_orders = [ diff --git a/src/Module/AllFriends.php b/src/Module/AllFriends.php index f916c16710..5d73f53cb5 100644 --- a/src/Module/AllFriends.php +++ b/src/Module/AllFriends.php @@ -67,7 +67,7 @@ class AllFriends extends BaseModule $total = Model\GContact::countAllFriends(local_user(), $cid); - $pager = new Pager(DI::args()->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); $friends = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage()); if (empty($friends)) { diff --git a/src/Module/BaseNotifications.php b/src/Module/BaseNotifications.php index 9e7b1cd979..4715641c2f 100644 --- a/src/Module/BaseNotifications.php +++ b/src/Module/BaseNotifications.php @@ -102,7 +102,7 @@ abstract class BaseNotifications extends BaseModule } // Set the pager - $pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), self::ITEMS_PER_PAGE); // Add additional informations (needed for json output) $notifications = [ @@ -132,7 +132,7 @@ abstract class BaseNotifications extends BaseModule $tabs = self::getTabs(); // Set the pager - $pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), self::ITEMS_PER_PAGE); $notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl'); return Renderer::replaceMacros($notif_tpl, [ diff --git a/src/Module/BaseSearch.php b/src/Module/BaseSearch.php index ca940ae4ea..e1bb3ebb0a 100644 --- a/src/Module/BaseSearch.php +++ b/src/Module/BaseSearch.php @@ -81,8 +81,7 @@ class BaseSearch extends BaseModule $header = DI::l10n()->t('Forum Search - %s', $search); } - $args = DI::args(); - $pager = new Pager($args->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); if ($localSearch && empty($results)) { $pager->setItemsPerPage(80); diff --git a/src/Module/Contact.php b/src/Module/Contact.php index be6f16a530..ee0ccce7ea 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -731,7 +731,7 @@ class Contact extends BaseModule } DBA::close($stmt); - $pager = new Pager(DI::args()->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); $sql_values[] = $pager->getStart(); $sql_values[] = $pager->getItemsPerPage(); diff --git a/src/Module/Conversation/Community.php b/src/Module/Conversation/Community.php index d149672838..ccd9554b8a 100644 --- a/src/Module/Conversation/Community.php +++ b/src/Module/Conversation/Community.php @@ -104,6 +104,7 @@ class Community extends BaseModule $o .= conversation(DI::app(), $items, 'community', false, false, 'commented', local_user()); $pager = new BoundariesPager( + DI::l10n(), DI::args()->getQueryString(), $items[0]['commented'], $items[count($items) - 1]['commented'], diff --git a/src/Module/Directory.php b/src/Module/Directory.php index 6bf246a370..0709aa3974 100644 --- a/src/Module/Directory.php +++ b/src/Module/Directory.php @@ -70,7 +70,7 @@ class Directory extends BaseModule $gDirPath = Profile::zrl($dirURL, true); } - $pager = new Pager(DI::args()->getQueryString(), 60); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 60); $profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search); diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php index 5ea3e0684c..3a42b0d311 100644 --- a/src/Module/Profile/Contacts.php +++ b/src/Module/Profile/Contacts.php @@ -85,7 +85,7 @@ class Contacts extends BaseProfile $total = DBA::count('contact', $condition); - $pager = new Pager(DI::args()->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; diff --git a/src/Module/Profile/Status.php b/src/Module/Profile/Status.php index 8da831405c..bd2898fa63 100644 --- a/src/Module/Profile/Status.php +++ b/src/Module/Profile/Status.php @@ -180,7 +180,7 @@ class Status extends BaseProfile $itemspage_network = $a->force_max_items; } - $pager = new Pager($args->getQueryString(), $itemspage_network); + $pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network); $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage()); diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 3e174c7905..2b7bb5c8a1 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -137,7 +137,7 @@ class Index extends BaseSearch // OR your own posts if you are a logged in member // No items will be shown if the member has a blocked profile wall. - $pager = new Pager(DI::args()->getQueryString()); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); if ($tag) { Logger::info('Start tag search.', ['q' => $search]);