From: Hypolite Petovan Date: Sun, 16 Feb 2020 18:04:26 +0000 (-0500) Subject: Add node-wide default items per page config X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e0d03615bcd3002871ad1e4e704db67890c041a0;p=friendica.git Add node-wide default items per page config --- diff --git a/mod/network.php b/mod/network.php index 31cafb5a86..6c63753d91 100644 --- a/mod/network.php +++ b/mod/network.php @@ -228,14 +228,12 @@ function networkPager(App $a, Pager $pager, $update) return ' LIMIT 100'; } - // check if we serve a mobile device and get the user settings - // accordingly if (DI::mode()->isMobile()) { - $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network'); - $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20); + $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', + DI::config()->get('system', 'itemspage_network_mobile')); } else { - $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network'); - $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40); + $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', + DI::config()->get('system', 'itemspage_network')); } // now that we have the user settings, see if the theme forces diff --git a/mod/notes.php b/mod/notes.php index 602514a54a..67f8fcab29 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -69,7 +69,15 @@ 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::l10n(), DI::args()->getQueryString(), 40); + if (DI::mode()->isMobile()) { + $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', + DI::config()->get('system', 'itemspage_network_mobile')); + } else { + $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', + DI::config()->get('system', 'itemspage_network')); + } + + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage); $params = ['order' => ['created' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; diff --git a/mod/settings.php b/mod/settings.php index 6fc8c8b1eb..94aed74ad4 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -356,11 +356,15 @@ function settings_post(App $a) } } - $itemspage_network = !empty($_POST['itemspage_network']) ? intval($_POST['itemspage_network']) : 40; + $itemspage_network = !empty($_POST['itemspage_network']) ? + intval($_POST['itemspage_network']) : + DI::config()->get('system', 'itemspage_network'); if ($itemspage_network > 100) { $itemspage_network = 100; } - $itemspage_mobile_network = !empty($_POST['itemspage_mobile_network']) ? intval($_POST['itemspage_mobile_network']) : 20; + $itemspage_mobile_network = !empty($_POST['itemspage_mobile_network']) ? + intval($_POST['itemspage_mobile_network']) : + DI::config()->get('system', 'itemspage_network_mobile'); if ($itemspage_mobile_network > 100) { $itemspage_mobile_network = 100; } @@ -938,9 +942,9 @@ function settings_content(App $a) } $itemspage_network = intval(DI::pConfig()->get(local_user(), 'system', 'itemspage_network')); - $itemspage_network = (($itemspage_network > 0 && $itemspage_network < 101) ? $itemspage_network : 40); // default if not set: 40 items + $itemspage_network = (($itemspage_network > 0 && $itemspage_network < 101) ? $itemspage_network : DI::config()->get('system', 'itemspage_network')); $itemspage_mobile_network = intval(DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network')); - $itemspage_mobile_network = (($itemspage_mobile_network > 0 && $itemspage_mobile_network < 101) ? $itemspage_mobile_network : 20); // default if not set: 20 items + $itemspage_mobile_network = (($itemspage_mobile_network > 0 && $itemspage_mobile_network < 101) ? $itemspage_mobile_network : DI::config()->get('system', 'itemspage_network_mobile')); $nosmile = DI::pConfig()->get(local_user(), 'system', 'no_smilies', 0); $first_day_of_week = DI::pConfig()->get(local_user(), 'system', 'first_day_of_week', 0); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index f1fec640a8..adc686f705 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1805,7 +1805,15 @@ class Contact $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()]; } - $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); + if (DI::mode()->isMobile()) { + $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', + DI::config()->get('system', 'itemspage_network_mobile')); + } else { + $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', + DI::config()->get('system', 'itemspage_network')); + } + + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage); $params = ['order' => ['received' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; diff --git a/src/Module/BaseSearch.php b/src/Module/BaseSearch.php index e1bb3ebb0a..e67d3c3c93 100644 --- a/src/Module/BaseSearch.php +++ b/src/Module/BaseSearch.php @@ -81,7 +81,15 @@ class BaseSearch extends BaseModule $header = DI::l10n()->t('Forum Search - %s', $search); } - $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); + if (DI::mode()->isMobile()) { + $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', + DI::config()->get('system', 'itemspage_network_mobile')); + } else { + $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', + DI::config()->get('system', 'itemspage_network')); + } + + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage); if ($localSearch && empty($results)) { $pager->setItemsPerPage(80); diff --git a/src/Module/Conversation/Community.php b/src/Module/Conversation/Community.php index a5f663139d..58af38eb16 100644 --- a/src/Module/Conversation/Community.php +++ b/src/Module/Conversation/Community.php @@ -195,11 +195,12 @@ class Community extends BaseModule } } - // check if we serve a mobile device and get the user settings accordingly if (DI::mode()->isMobile()) { - self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', 20); + self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', + DI::config()->get('system', 'itemspage_network_mobile')); } else { - self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', 40); + self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', + DI::config()->get('system', 'itemspage_network')); } // now that we have the user settings, see if the theme forces @@ -272,6 +273,7 @@ class Community extends BaseModule * @param $itemspage * @return array * @throws \Exception + * @TODO Move to repository/factory */ private static function selectItems($since_id, $max_id, $itemspage) { diff --git a/src/Module/Profile/Status.php b/src/Module/Profile/Status.php index bd2898fa63..abd5736c9a 100644 --- a/src/Module/Profile/Status.php +++ b/src/Module/Profile/Status.php @@ -166,12 +166,12 @@ class Status extends BaseProfile $sql_extra3 = ""; } - // check if we serve a mobile device and get the user settings - // accordingly if (DI::mode()->isMobile()) { - $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', 10); + $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', + DI::config()->get('system', 'itemspage_network_mobile')); } else { - $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', 20); + $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', + DI::config()->get('system', 'itemspage_network')); } // now that we have the user settings, see if the theme forces diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 2b7bb5c8a1..44407623e9 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -137,7 +137,15 @@ 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::l10n(), DI::args()->getQueryString()); + if (DI::mode()->isMobile()) { + $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', + DI::config()->get('system', 'itemspage_network_mobile')); + } else { + $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', + DI::config()->get('system', 'itemspage_network')); + } + + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage); if ($tag) { Logger::info('Start tag search.', ['q' => $search]); diff --git a/static/defaults.config.php b/static/defaults.config.php index f9eda841f2..ab47eef19c 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -227,6 +227,15 @@ return [ // If set true registration is only possible after a current member of the node has send an invitation. 'invitation_only' => false, + // itemspage_network (Integer) + // default number of items per page in stream pages (network, community, profile/contact statuses, search) + 'itemspage_network' => 40, + + // itemspage_network_mobile (Integer) + // default number of items per page in stream pages (network, community, profile/contact statuses, search) + // on detected mobile devices + 'itemspage_network_mobile' => 20, + // like_no_comment (Boolean) // Don't update the "commented" value of an item when it is liked. 'like_no_comment' => false,