From a3cd804ff12e4cca5e2adc2b750378007bca4146 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 1 Mar 2017 23:23:14 -0500 Subject: [PATCH 1/5] Fix default paginate.tpl Adding missing curly braces --- view/templates/paginate.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/templates/paginate.tpl b/view/templates/paginate.tpl index 21d56509aa..fcd580b071 100644 --- a/view/templates/paginate.tpl +++ b/view/templates/paginate.tpl @@ -2,7 +2,7 @@ {{if $pager}} {{if $pager.prev}}{{$pager.prev.text}}{{/if}} - {{if $pager.first}}{{$pager.first.text}}{{/if}} + {{if $pager.first}}{{$pager.first.text}}{{/if}} {{foreach $pager.pages as $p}}{{$p.text}}{{/foreach}} From 07aefe61bfeab5046f74a7f7940963011c81baf5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 1 Mar 2017 23:26:49 -0500 Subject: [PATCH 2/5] Update paginate_data() - Formatting: Normalize quotes, spaces, braces - Add "disabled" CSS class to links previously ommitted - Add "previous" and "next" CSS classes to minimal pager links - Add main pager CSS class depending on type --- include/text.php | 89 ++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/include/text.php b/include/text.php index 11248902ba..580bd95fc7 100644 --- a/include/text.php +++ b/include/text.php @@ -268,90 +268,89 @@ function hex2bin($s) { }} -if(! function_exists('paginate_data')) { /** - * Automatica pagination data. + * @brief Paginator function. Pushes relevant links in a pager array structure. + * + * Links are generated depending on the current page and the total number of items. + * Inactive links (like "first" and "prev" on page 1) are given the "disabled" class. + * Current page link is given the "active" CSS class * * @param App $a App instance - * @param int $count [optional] item count (used with alt pager) + * @param int $count [optional] item count (used with minimal pager) * @return Array data for pagination template */ -function paginate_data(App $a, $count=null) { - $stripped = preg_replace('/([&?]page=[0-9]*)/','',$a->query_string); +function paginate_data(App $a, $count = null) { + $stripped = preg_replace('/([&?]page=[0-9]*)/', '', $a->query_string); - $stripped = str_replace('q=','',$stripped); - $stripped = trim($stripped,'/'); + $stripped = str_replace('q=', '', $stripped); + $stripped = trim($stripped, '/'); $pagenum = $a->pager['page']; - if (($a->page_offset != "") AND !preg_match('/[?&].offset=/', $stripped)) - $stripped .= "&offset=".urlencode($a->page_offset); + if (($a->page_offset != '') AND !preg_match('/[?&].offset=/', $stripped)) { + $stripped .= '&offset=' . urlencode($a->page_offset); + } $url = $stripped; $data = array(); - function _l(&$d, $name, $url, $text, $class="") { - if (!strpos($url, "?")) { - if ($pos = strpos($url, "&")) - $url = substr($url, 0, $pos)."?".substr($url, $pos + 1); + function _l(&$d, $name, $url, $text, $class = '') { + if (strpos($url, '?') === false && ($pos = strpos($url, '&')) !== false) { + $url = substr($url, 0, $pos) . '?' . substr($url, $pos + 1); } - $d[$name] = array('url'=>$url, 'text'=>$text, 'class'=>$class); + $d[$name] = array('url' => $url, 'text' => $text, 'class' => $class); } - if (!is_null($count)){ - // alt pager - if($a->pager['page']>1) - _l($data, "prev", $url.'&page='.($a->pager['page'] - 1), t('newer')); - if($count>0) - _l($data, "next", $url.'&page='.($a->pager['page'] + 1), t('older')); + if (!is_null($count)) { + // minimal pager (newer / older) + $data['class'] = 'pager'; + _l($data, 'prev', $url . '&page=' . ($a->pager['page'] - 1), t('newer'), 'previous' . ($a->pager['page'] == 1 ? ' disabled' : '')); + _l($data, 'next', $url . '&page=' . ($a->pager['page'] + 1), t('older'), 'next' . ($count <= 0 ? ' disabled' : '')); } else { - // full pager - if($a->pager['total'] > $a->pager['itemspage']) { - if($a->pager['page'] != 1) - _l($data, "prev", $url.'&page='.($a->pager['page'] - 1), t('prev')); - - _l($data, "first", $url."&page=1", t('first')); - + // full pager (first / prev / 1 / 2 / ... / 14 / 15 / next / last) + $data['class'] = 'pagination'; + if ($a->pager['total'] > $a->pager['itemspage']) { + _l($data, 'first', $url . '&page=1', t('first'), $a->pager['page'] == 1 ? 'disabled' : ''); + _l($data, 'prev', $url . '&page=' . ($a->pager['page'] - 1), t('prev'), $a->pager['page'] == 1 ? 'disabled' : ''); $numpages = $a->pager['total'] / $a->pager['itemspage']; $numstart = 1; $numstop = $numpages; - if($numpages > 14) { + if ($numpages > 14) { $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1); $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14)); } $pages = array(); - for($i = $numstart; $i <= $numstop; $i++){ - if($i == $a->pager['page']) - _l($pages, $i, "#", $i, "current"); - else - _l($pages, $i, $url."&page=$i", $i, "n"); + for ($i = $numstart; $i <= $numstop; $i++) { + if ($i == $a->pager['page']) { + _l($pages, $i, '#', $i, 'current active'); + } else { + _l($pages, $i, $url . '&page='. $i, $i, 'n'); + } } - if(($a->pager['total'] % $a->pager['itemspage']) != 0) { - if($i == $a->pager['page']) - _l($pages, $i, "#", $i, "current"); - else - _l($pages, $i, $url."&page=$i", $i, "n"); + if (($a->pager['total'] % $a->pager['itemspage']) != 0) { + if ($i == $a->pager['page']) { + _l($pages, $i, '#', $i, 'current active'); + } else { + _l($pages, $i, $url . '&page=' . $i, $i, 'n'); + } } $data['pages'] = $pages; $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages); - _l($data, "last", $url."&page=$lastpage", t('last')); - - if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0) - _l($data, "next", $url."&page=".($a->pager['page'] + 1), t('next')); - + _l($data, 'next', $url . '&page=' . ($a->pager['page'] + 1), t('next'), $a->pager['page'] == $lastpage ? 'disabled' : ''); + _l($data, 'last', $url . '&page=' . $lastpage, t('last'), $a->pager['page'] == $lastpage ? 'disabled' : ''); } } - return $data; -}} + return $data; +} if(! function_exists('paginate')) { /** From 21cad46d19f4a049b9d4d69a0a569e023c652b6d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 1 Mar 2017 23:40:34 -0500 Subject: [PATCH 3/5] Backward compatibility for theme other than frio - Add .pager .disabled CSS rule --- view/theme/duepuntozero/style.css | 3 +++ view/theme/frost-mobile/style.css | 3 +++ view/theme/frost/style.css | 3 +++ view/theme/quattro/green/style.css | 3 +++ view/theme/quattro/lilac/style.css | 3 +++ view/theme/quattro/quattro.less | 3 +++ view/theme/smoothly/style.css | 4 ++++ view/theme/vier/style.css | 4 ++++ 8 files changed, 26 insertions(+) diff --git a/view/theme/duepuntozero/style.css b/view/theme/duepuntozero/style.css index c1e8067443..8e2c5d4478 100644 --- a/view/theme/duepuntozero/style.css +++ b/view/theme/duepuntozero/style.css @@ -1552,6 +1552,9 @@ blockquote.shared_content { clear:left; } +.pager .disabled { + display: none; +} .pager_first, .pager_last, diff --git a/view/theme/frost-mobile/style.css b/view/theme/frost-mobile/style.css index c005e838f1..7c5d2c7609 100644 --- a/view/theme/frost-mobile/style.css +++ b/view/theme/frost-mobile/style.css @@ -1909,6 +1909,9 @@ input#profile-jot-email { -webkit-border-radius: 10px; } +.pager .disabled { + display: none; +} .pager_first, .pager_last, diff --git a/view/theme/frost/style.css b/view/theme/frost/style.css index 46eb650ec1..9b65da9c8c 100644 --- a/view/theme/frost/style.css +++ b/view/theme/frost/style.css @@ -1866,6 +1866,9 @@ input#dfrn-url { -webkit-border-radius: 10px; } +.pager .disabled { + display: none; +} .pager_first, .pager_last, diff --git a/view/theme/quattro/green/style.css b/view/theme/quattro/green/style.css index 8eba0e4cf7..af5cfcedf0 100644 --- a/view/theme/quattro/green/style.css +++ b/view/theme/quattro/green/style.css @@ -2481,6 +2481,9 @@ footer { margin-top: 25px; clear: both; } +.pager .disabled { + display: none; +} /** * ADMIN */ diff --git a/view/theme/quattro/lilac/style.css b/view/theme/quattro/lilac/style.css index b424534206..0c17b00331 100644 --- a/view/theme/quattro/lilac/style.css +++ b/view/theme/quattro/lilac/style.css @@ -2481,6 +2481,9 @@ footer { margin-top: 25px; clear: both; } +.pager .disabled { + display: none; +} /** * ADMIN */ diff --git a/view/theme/quattro/quattro.less b/view/theme/quattro/quattro.less index 6c01986888..53bb7e38a6 100644 --- a/view/theme/quattro/quattro.less +++ b/view/theme/quattro/quattro.less @@ -1675,6 +1675,9 @@ footer { height: 100px; display: table-row; } margin-top: 25px; clear: both; } +.pager .disabled { + display: none; +} /** * ADMIN diff --git a/view/theme/smoothly/style.css b/view/theme/smoothly/style.css index e91eccfe17..ec52277bdd 100644 --- a/view/theme/smoothly/style.css +++ b/view/theme/smoothly/style.css @@ -396,6 +396,10 @@ ul.menu-popup li a:hover { margin: 4px; } +.pager .disabled { + display: none; +} + .pager_current { background-color: #1873a2; color: #ffffff; diff --git a/view/theme/vier/style.css b/view/theme/vier/style.css index 8454c7e0ae..32617867cb 100644 --- a/view/theme/vier/style.css +++ b/view/theme/vier/style.css @@ -247,6 +247,10 @@ div.pager { float: left; } +.pager .disabled { + display: none; +} + .hide-comments-outer { margin-left: 80px; margin-bottom: 5px; From 57ce6cf5daaff5d1d4433b9a8059f5dea7b68bf5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 1 Mar 2017 23:41:54 -0500 Subject: [PATCH 4/5] Improve pagination on frio theme - Add pager class discrimination - Change links order to first / prev / 1 / ... / 10 / next / last - Enable dynamic pagination coloring - Prevent click on disabled links --- view/theme/frio/css/style.css | 20 ++++++++++++++++++++ view/theme/frio/templates/paginate.tpl | 13 +++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 view/theme/frio/templates/paginate.tpl diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index df9585d070..ea4db0d532 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -2515,3 +2515,23 @@ body .tread-wrapper .hovercard:hover .hover-card-content a { section .profile-match-wrapper { float: left; } + +/* Pagination improvements */ + +.pagination > li > a, +.pagination > li > span { + color: $link_color; +} +.pagination>.active>a, +.pagination>.active>a:focus, +.pagination>.active>a:hover, +.pagination>.active>span, +.pagination>.active>span:focus, +.pagination>.active>span:hover { + background-color: $link_color; + border-color: $link_color; +} + +.disabled > a { + pointer-events: none; +} \ No newline at end of file diff --git a/view/theme/frio/templates/paginate.tpl b/view/theme/frio/templates/paginate.tpl new file mode 100644 index 0000000000..a9c3ae480d --- /dev/null +++ b/view/theme/frio/templates/paginate.tpl @@ -0,0 +1,13 @@ +{{if $pager}} +
+ {{if $pager.first}}
  • {{$pager.first.text}}
  • {{/if}} + + {{if $pager.prev}}
  • {{$pager.prev.text}}
  • {{/if}} + + {{foreach $pager.pages as $p}}
  • {{$p.text}}
  • {{/foreach}} + + {{if $pager.next}}
  • {{$pager.next.text}}
  • {{/if}} + + {{if $pager.last}} 
  • {{$pager.last.text}}
  • {{/if}} +
    +{{/if}} From ebdc9667f796de83c6b4da2247d11f8658725a1b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 2 Mar 2017 11:30:41 -0500 Subject: [PATCH 5/5] Improve readability - Move CSS block above the temporary block - Add template description --- view/theme/frio/css/style.css | 20 +++++++++----------- view/theme/frio/templates/paginate.tpl | 1 + 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index ea4db0d532..34bcb833db 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -2508,16 +2508,7 @@ body .tread-wrapper .hovercard:hover .hover-card-content a { color: $link_color !important; } -/* - * some temporary workarounds until this will solved - * elsewhere (e.g. new templates) - */ -section .profile-match-wrapper { - float: left; -} - /* Pagination improvements */ - .pagination > li > a, .pagination > li > span { color: $link_color; @@ -2531,7 +2522,14 @@ section .profile-match-wrapper { background-color: $link_color; border-color: $link_color; } - .disabled > a { pointer-events: none; -} \ No newline at end of file +} + +/* + * some temporary workarounds until this will solved + * elsewhere (e.g. new templates) + */ +section .profile-match-wrapper { + float: left; +} diff --git a/view/theme/frio/templates/paginate.tpl b/view/theme/frio/templates/paginate.tpl index a9c3ae480d..ab65cdd406 100644 --- a/view/theme/frio/templates/paginate.tpl +++ b/view/theme/frio/templates/paginate.tpl @@ -1,3 +1,4 @@ +{{* Pager template, uses output of paginate_data() in include/text.php *}} {{if $pager}}
    {{if $pager.first}}
  • {{$pager.first.text}}
  • {{/if}}