]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #3200 from Hypolite/issue/#3195
authorMichael Vogel <icarus@dabo.de>
Tue, 14 Mar 2017 05:05:42 +0000 (06:05 +0100)
committerGitHub <noreply@github.com>
Tue, 14 Mar 2017 05:05:42 +0000 (06:05 +0100)
Improve pagination on frio

12 files changed:
include/text.php
view/templates/paginate.tpl
view/theme/duepuntozero/style.css
view/theme/frio/css/style.css
view/theme/frio/templates/paginate.tpl [new file with mode: 0644]
view/theme/frost-mobile/style.css
view/theme/frost/style.css
view/theme/quattro/green/style.css
view/theme/quattro/lilac/style.css
view/theme/quattro/quattro.less
view/theme/smoothly/style.css
view/theme/vier/style.css

index 11248902ba0c7a6840a18485b20adc85e2af8df2..580bd95fc75c81343dd3e8466cc09bba9574fd35 100644 (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')) {
 /**
index 21d56509aabe83de3d1e3266f1a4cd7979b9ff11..fcd580b0715aede0b680bb4aa8062e8cdcfa53f8 100644 (file)
@@ -2,7 +2,7 @@
        {{if $pager}}\r
        {{if $pager.prev}}<span class="pager_prev {{$pager.prev.class}}"><a href="{{$pager.prev.url}}">{{$pager.prev.text}}</a></span>{{/if}}\r
 \r
-       {{if $pager.first}}<span class="pager_first $pager.first.class"><a href="{{$pager.first.url}}">{{$pager.first.text}}</a></span>{{/if}}\r
+       {{if $pager.first}}<span class="pager_first {{$pager.first.class}}"><a href="{{$pager.first.url}}">{{$pager.first.text}}</a></span>{{/if}}\r
 \r
        {{foreach $pager.pages as $p}}<span class="pager_{{$p.class}}"><a href="{{$p.url}}">{{$p.text}}</a></span>{{/foreach}}\r
 \r
index c1e8067443a3f35af95c939b74ad119669ba9bad..8e2c5d44780129bbe25c8345b9932403f5f310ba 100644 (file)
@@ -1552,6 +1552,9 @@ blockquote.shared_content {
   clear:left;
 }
 
+.pager .disabled {
+       display: none;
+}
 
 .pager_first,
 .pager_last,
index df9585d07026f5440341e034e72440120c22bcfb..34bcb833dbf21e50af43b8d735047d6201f6cebd 100644 (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)
diff --git a/view/theme/frio/templates/paginate.tpl b/view/theme/frio/templates/paginate.tpl
new file mode 100644 (file)
index 0000000..ab65cdd
--- /dev/null
@@ -0,0 +1,14 @@
+{{* Pager template, uses output of paginate_data() in include/text.php *}}\r
+{{if $pager}}\r
+<div class="{{$pager.class}}">\r
+       {{if $pager.first}}<li class="pager_first {{$pager.first.class}}"><a href="{{$pager.first.url}}">{{$pager.first.text}}</a></li>{{/if}}\r
+\r
+       {{if $pager.prev}}<li class="pager_prev {{$pager.prev.class}}"><a href="{{$pager.prev.url}}">{{$pager.prev.text}}</a></li>{{/if}}\r
+\r
+       {{foreach $pager.pages as $p}}<li class="pager_{{$p.class}}"><a href="{{$p.url}}">{{$p.text}}</a></li>{{/foreach}}\r
+\r
+       {{if $pager.next}}<li class="pager_next {{$pager.next.class}}"><a href="{{$pager.next.url}}">{{$pager.next.text}}</a></li>{{/if}}\r
+\r
+       {{if $pager.last}}&nbsp;<li class="pager_last {{$pager.last.class}}"><a href="{{$pager.last.url}}">{{$pager.last.text}}</a></li>{{/if}}\r
+</div>\r
+{{/if}}\r
index c005e838f163e44b56290cf891de8d7dc848c1c3..7c5d2c7609d09f26a2a1beb943fecf24debd44a1 100644 (file)
@@ -1909,6 +1909,9 @@ input#profile-jot-email {
        -webkit-border-radius: 10px;\r
 }\r
 \r
+.pager .disabled {\r
+       display: none;\r
+}\r
 \r
 .pager_first,\r
 .pager_last,\r
index 46eb650ec1db93278ff68c9b1955acd2f18cf26c..9b65da9c8c81251e0d10aad3f933f21699448088 100644 (file)
@@ -1866,6 +1866,9 @@ input#dfrn-url {
        -webkit-border-radius: 10px;
 }
 
+.pager .disabled {
+       display: none;
+}
 
 .pager_first,
 .pager_last,
index 8eba0e4cf723a861698407ebd018eeee5044c7ab..af5cfcedf0bc175ae156c35044d487ba6de0c6d6 100644 (file)
@@ -2481,6 +2481,9 @@ footer {
   margin-top: 25px;
   clear: both;
 }
+.pager .disabled {
+       display: none;
+}
 /**
  * ADMIN
  */
index b424534206328ead1dd3e9fc28e44d97c7c5f452..0c17b00331d1651159d8a6d298bdea3827186e1a 100644 (file)
@@ -2481,6 +2481,9 @@ footer {
   margin-top: 25px;
   clear: both;
 }
+.pager .disabled {
+       display: none;
+}
 /**
  * ADMIN
  */
index 6c019868889f80ff684d10e853d9a67e76150108..53bb7e38a6d9d5bb97458a7f1dcf3c4b70acea5a 100644 (file)
@@ -1675,6 +1675,9 @@ footer { height: 100px; display: table-row; }
         margin-top: 25px;
         clear: both;
 }
+.pager .disabled {
+       display: none;
+}
 
 /**
  * ADMIN
index e91eccfe174e5e3af54d5de4c915968e7b6ab802..ec52277bddf6d6ace4076d2f0442c4758a73d182 100644 (file)
@@ -396,6 +396,10 @@ ul.menu-popup li a:hover {
        margin: 4px;
 }
 
+.pager .disabled {
+       display: none;
+}
+
 .pager_current {
        background-color: #1873a2;
        color: #ffffff;
index 8454c7e0ae610c46fb3987f825ace15afafc7ea7..32617867cb391d7d2d790c09ffdf127db4dd6e11 100644 (file)
@@ -247,6 +247,10 @@ div.pager {
   float: left;
 }
 
+.pager .disabled {
+       display: none;
+}
+
 .hide-comments-outer {
   margin-left: 80px;
   margin-bottom: 5px;