Merge pull request #3200 from Hypolite/issue/#3195
Improve pagination on frio
This commit is contained in:
commit
199bba20d9
12 changed files with 103 additions and 46 deletions
|
@ -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 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
|
* @return Array data for pagination template
|
||||||
*/
|
*/
|
||||||
function paginate_data(App $a, $count=null) {
|
function paginate_data(App $a, $count = null) {
|
||||||
$stripped = preg_replace('/([&?]page=[0-9]*)/','',$a->query_string);
|
$stripped = preg_replace('/([&?]page=[0-9]*)/', '', $a->query_string);
|
||||||
|
|
||||||
$stripped = str_replace('q=','',$stripped);
|
$stripped = str_replace('q=', '', $stripped);
|
||||||
$stripped = trim($stripped,'/');
|
$stripped = trim($stripped, '/');
|
||||||
$pagenum = $a->pager['page'];
|
$pagenum = $a->pager['page'];
|
||||||
|
|
||||||
if (($a->page_offset != "") AND !preg_match('/[?&].offset=/', $stripped))
|
if (($a->page_offset != '') AND !preg_match('/[?&].offset=/', $stripped)) {
|
||||||
$stripped .= "&offset=".urlencode($a->page_offset);
|
$stripped .= '&offset=' . urlencode($a->page_offset);
|
||||||
|
}
|
||||||
|
|
||||||
$url = $stripped;
|
$url = $stripped;
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
function _l(&$d, $name, $url, $text, $class="") {
|
function _l(&$d, $name, $url, $text, $class = '') {
|
||||||
if (!strpos($url, "?")) {
|
if (strpos($url, '?') === false && ($pos = strpos($url, '&')) !== false) {
|
||||||
if ($pos = strpos($url, "&"))
|
$url = substr($url, 0, $pos) . '?' . substr($url, $pos + 1);
|
||||||
$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)){
|
if (!is_null($count)) {
|
||||||
// alt pager
|
// minimal pager (newer / older)
|
||||||
if($a->pager['page']>1)
|
$data['class'] = 'pager';
|
||||||
_l($data, "prev", $url.'&page='.($a->pager['page'] - 1), t('newer'));
|
_l($data, 'prev', $url . '&page=' . ($a->pager['page'] - 1), t('newer'), 'previous' . ($a->pager['page'] == 1 ? ' disabled' : ''));
|
||||||
if($count>0)
|
_l($data, 'next', $url . '&page=' . ($a->pager['page'] + 1), t('older'), 'next' . ($count <= 0 ? ' disabled' : ''));
|
||||||
_l($data, "next", $url.'&page='.($a->pager['page'] + 1), t('older'));
|
|
||||||
} else {
|
} else {
|
||||||
// full pager
|
// full pager (first / prev / 1 / 2 / ... / 14 / 15 / next / last)
|
||||||
if($a->pager['total'] > $a->pager['itemspage']) {
|
$data['class'] = 'pagination';
|
||||||
if($a->pager['page'] != 1)
|
if ($a->pager['total'] > $a->pager['itemspage']) {
|
||||||
_l($data, "prev", $url.'&page='.($a->pager['page'] - 1), t('prev'));
|
_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' : '');
|
||||||
_l($data, "first", $url."&page=1", t('first'));
|
|
||||||
|
|
||||||
|
|
||||||
$numpages = $a->pager['total'] / $a->pager['itemspage'];
|
$numpages = $a->pager['total'] / $a->pager['itemspage'];
|
||||||
|
|
||||||
$numstart = 1;
|
$numstart = 1;
|
||||||
$numstop = $numpages;
|
$numstop = $numpages;
|
||||||
|
|
||||||
if($numpages > 14) {
|
if ($numpages > 14) {
|
||||||
$numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
|
$numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
|
||||||
$numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
|
$numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
|
||||||
}
|
}
|
||||||
|
|
||||||
$pages = array();
|
$pages = array();
|
||||||
|
|
||||||
for($i = $numstart; $i <= $numstop; $i++){
|
for ($i = $numstart; $i <= $numstop; $i++) {
|
||||||
if($i == $a->pager['page'])
|
if ($i == $a->pager['page']) {
|
||||||
_l($pages, $i, "#", $i, "current");
|
_l($pages, $i, '#', $i, 'current active');
|
||||||
else
|
} else {
|
||||||
_l($pages, $i, $url."&page=$i", $i, "n");
|
_l($pages, $i, $url . '&page='. $i, $i, 'n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
|
if (($a->pager['total'] % $a->pager['itemspage']) != 0) {
|
||||||
if($i == $a->pager['page'])
|
if ($i == $a->pager['page']) {
|
||||||
_l($pages, $i, "#", $i, "current");
|
_l($pages, $i, '#', $i, 'current active');
|
||||||
else
|
} else {
|
||||||
_l($pages, $i, $url."&page=$i", $i, "n");
|
_l($pages, $i, $url . '&page=' . $i, $i, 'n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['pages'] = $pages;
|
$data['pages'] = $pages;
|
||||||
|
|
||||||
$lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
|
$lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
|
||||||
_l($data, "last", $url."&page=$lastpage", t('last'));
|
_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' : '');
|
||||||
if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
|
|
||||||
_l($data, "next", $url."&page=".($a->pager['page'] + 1), t('next'));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
}
|
||||||
}}
|
|
||||||
|
|
||||||
if(! function_exists('paginate')) {
|
if(! function_exists('paginate')) {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{{if $pager}}
|
{{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.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}}
|
{{foreach $pager.pages as $p}}<span class="pager_{{$p.class}}"><a href="{{$p.url}}">{{$p.text}}</a></span>{{/foreach}}
|
||||||
|
|
||||||
|
|
|
@ -1552,6 +1552,9 @@ blockquote.shared_content {
|
||||||
clear:left;
|
clear:left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pager .disabled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.pager_first,
|
.pager_first,
|
||||||
.pager_last,
|
.pager_last,
|
||||||
|
|
|
@ -2508,6 +2508,24 @@ body .tread-wrapper .hovercard:hover .hover-card-content a {
|
||||||
color: $link_color !important;
|
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
|
* some temporary workarounds until this will solved
|
||||||
* elsewhere (e.g. new templates)
|
* elsewhere (e.g. new templates)
|
||||||
|
|
14
view/theme/frio/templates/paginate.tpl
Normal file
14
view/theme/frio/templates/paginate.tpl
Normal 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}} <li class="pager_last {{$pager.last.class}}"><a href="{{$pager.last.url}}">{{$pager.last.text}}</a></li>{{/if}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
|
@ -1909,6 +1909,9 @@ input#profile-jot-email {
|
||||||
-webkit-border-radius: 10px;
|
-webkit-border-radius: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pager .disabled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.pager_first,
|
.pager_first,
|
||||||
.pager_last,
|
.pager_last,
|
||||||
|
|
|
@ -1866,6 +1866,9 @@ input#dfrn-url {
|
||||||
-webkit-border-radius: 10px;
|
-webkit-border-radius: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pager .disabled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.pager_first,
|
.pager_first,
|
||||||
.pager_last,
|
.pager_last,
|
||||||
|
|
|
@ -2481,6 +2481,9 @@ footer {
|
||||||
margin-top: 25px;
|
margin-top: 25px;
|
||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
.pager .disabled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* ADMIN
|
* ADMIN
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2481,6 +2481,9 @@ footer {
|
||||||
margin-top: 25px;
|
margin-top: 25px;
|
||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
.pager .disabled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* ADMIN
|
* ADMIN
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1675,6 +1675,9 @@ footer { height: 100px; display: table-row; }
|
||||||
margin-top: 25px;
|
margin-top: 25px;
|
||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
.pager .disabled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADMIN
|
* ADMIN
|
||||||
|
|
|
@ -396,6 +396,10 @@ ul.menu-popup li a:hover {
|
||||||
margin: 4px;
|
margin: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pager .disabled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.pager_current {
|
.pager_current {
|
||||||
background-color: #1873a2;
|
background-color: #1873a2;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
|
|
|
@ -247,6 +247,10 @@ div.pager {
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pager .disabled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.hide-comments-outer {
|
.hide-comments-outer {
|
||||||
margin-left: 80px;
|
margin-left: 80px;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
|
|
Loading…
Reference in a new issue