Merge pull request #3200 from Hypolite/issue/#3195

Improve pagination on frio
This commit is contained in:
Michael Vogel 2017-03-14 06:05:42 +01:00 committed by GitHub
commit 199bba20d9
12 changed files with 103 additions and 46 deletions

View File

@ -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')) {
/**

View File

@ -2,7 +2,7 @@
{{if $pager}}
{{if $pager.prev}}<span class="pager_prev {{$pager.prev.class}}"><a href="{{$pager.prev.url}}">{{$pager.prev.text}}</a></span>{{/if}}
{{if $pager.first}}<span class="pager_first $pager.first.class"><a href="{{$pager.first.url}}">{{$pager.first.text}}</a></span>{{/if}}
{{if $pager.first}}<span class="pager_first {{$pager.first.class}}"><a href="{{$pager.first.url}}">{{$pager.first.text}}</a></span>{{/if}}
{{foreach $pager.pages as $p}}<span class="pager_{{$p.class}}"><a href="{{$p.url}}">{{$p.text}}</a></span>{{/foreach}}

View File

@ -1552,6 +1552,9 @@ blockquote.shared_content {
clear:left;
}
.pager .disabled {
display: none;
}
.pager_first,
.pager_last,

View File

@ -2508,6 +2508,24 @@ body .tread-wrapper .hovercard:hover .hover-card-content a {
color: $link_color !important;
}
/* 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;
}
/*
* some temporary workarounds until this will solved
* elsewhere (e.g. new templates)

View File

@ -0,0 +1,14 @@
{{* Pager template, uses output of paginate_data() in include/text.php *}}
{{if $pager}}
<div class="{{$pager.class}}">
{{if $pager.first}}<li class="pager_first {{$pager.first.class}}"><a href="{{$pager.first.url}}">{{$pager.first.text}}</a></li>{{/if}}
{{if $pager.prev}}<li class="pager_prev {{$pager.prev.class}}"><a href="{{$pager.prev.url}}">{{$pager.prev.text}}</a></li>{{/if}}
{{foreach $pager.pages as $p}}<li class="pager_{{$p.class}}"><a href="{{$p.url}}">{{$p.text}}</a></li>{{/foreach}}
{{if $pager.next}}<li class="pager_next {{$pager.next.class}}"><a href="{{$pager.next.url}}">{{$pager.next.text}}</a></li>{{/if}}
{{if $pager.last}}&nbsp;<li class="pager_last {{$pager.last.class}}"><a href="{{$pager.last.url}}">{{$pager.last.text}}</a></li>{{/if}}
</div>
{{/if}}

View File

@ -1909,6 +1909,9 @@ input#profile-jot-email {
-webkit-border-radius: 10px;
}
.pager .disabled {
display: none;
}
.pager_first,
.pager_last,

View File

@ -1866,6 +1866,9 @@ input#dfrn-url {
-webkit-border-radius: 10px;
}
.pager .disabled {
display: none;
}
.pager_first,
.pager_last,

View File

@ -2481,6 +2481,9 @@ footer {
margin-top: 25px;
clear: both;
}
.pager .disabled {
display: none;
}
/**
* ADMIN
*/

View File

@ -2481,6 +2481,9 @@ footer {
margin-top: 25px;
clear: both;
}
.pager .disabled {
display: none;
}
/**
* ADMIN
*/

View File

@ -1675,6 +1675,9 @@ footer { height: 100px; display: table-row; }
margin-top: 25px;
clear: both;
}
.pager .disabled {
display: none;
}
/**
* ADMIN

View File

@ -396,6 +396,10 @@ ul.menu-popup li a:hover {
margin: 4px;
}
.pager .disabled {
display: none;
}
.pager_current {
background-color: #1873a2;
color: #ffffff;

View File

@ -247,6 +247,10 @@ div.pager {
float: left;
}
.pager .disabled {
display: none;
}
.hide-comments-outer {
margin-left: 80px;
margin-bottom: 5px;