* email import
* code cleanups
* using mysql transactions if needed
+ * pagination
version 2.1alpha - Guardian of Fire - (2019-09-29)
# username and password see above
define("USE_PAGE_AUTH",false);
+# results per page
+define("RESULTS_PER_PAGE",10);
+
# settings for importing from e-mail
# SSL/TLS only
# imap
* @param bool | int $limit
* @return array
*/
- public function links($limit=false) {
+ public function links($limit=false,$offset=false) {
$ret = array();
$queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES."
WHERE `status` = 2
GROUP BY `hash`
ORDER BY `created` DESC";
+ if(!empty($limit)) {
+ $queryStr .= " LIMIT $limit";
+ if($offset !== false) {
+ $queryStr .= " OFFSET $offset";
+ }
+ }
$query = $this->DB->query($queryStr);
if(!empty($query) && $query->num_rows > 0) {
- $ret = $query->fetch_all(MYSQLI_ASSOC);
+ $ret['results'] = $query->fetch_all(MYSQLI_ASSOC);
+
+ $query = $this->DB->query("SELECT COUNT(DISTINCT(hash)) AS `amount`
+ FROM `".DB_PREFIX."_combined`
+ WHERE `status` = 2");
+ $result = $query->fetch_assoc();
+ $ret['amount'] = $result['amount'];
}
return $ret;
$_id = trim($_GET['id']);
$_id = Summoner::validate($_id,'digit') ? $_id : false;
}
+$_curPage = 1;
+if(isset($_GET['page']) && !empty($_GET['page'])) {
+ $_curPage = trim($_GET['page']);
+ $_curPage = Summoner::validate($_curPage,'digit') ? $_curPage : 1;
+}
$linkCollection = array();
$subHeadline = false;
$tagCollection = array();
$categoryCollection = array();
+$pagination = array('pages' => 0);
switch($_requestMode) {
case 'tag':
case 'all':
default:
# show all
- $linkCollection = $Management->links();
+ $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
+ if(!empty($linkCollection['amount'])) {
+ $pagination['pages'] = ceil($linkCollection['amount'] / RESULTS_PER_PAGE);
+ $pagination['curPage'] = $_curPage;
+ $pagination['m'] = $_requestMode;
+ }
+}
+
+if($pagination['pages'] > 11) {
+ # first pages
+ $pagination['visibleRange'] = range(1,3);
+ # last pages
+ foreach(range($pagination['pages']-2, $pagination['pages']) as $e) {
+ array_push($pagination['visibleRange'], $e);
+ }
+ # pages before and after current page
+ $cRange = range($pagination['curPage']-1, $pagination['curPage']+1);
+ foreach($cRange as $e) {
+ array_push($pagination['visibleRange'], $e);
+ }
+ $pagination['currentRangeStart'] = array_shift($cRange);
+ $pagination['currentRangeEnd'] = array_pop($cRange);
+}
+else {
+ $pagination['visibleRange'] = range(1,$pagination['pages']);
}
<?php } ?>
</div>
</div>
+
+ <?php if($pagination['pages'] > 0) { ?>
+ <nav class="pagination is-centered" role="navigation" aria-label="pagination">
+ <?php if($pagination['curPage'] > 1) {
+ echo '<a href="index.php?p=overview&m='.$pagination['m'].'&page='.($pagination['curPage']-1).'"
+ class="pagination-previous">Previous</a>';
+ }
+ if($pagination['curPage'] < $pagination['pages']) {
+ echo '<a href="index.php?p=overview&m='.$pagination['m'].'&page='.($pagination['curPage']+1).'"
+ class="pagination-next">Next</a>';
+ }
+ ?>
+ <ul class="pagination-list">
+ <?php
+ $ellipsisShown = 0;
+ for($i=1;$i<=$pagination['pages'];$i++) {
+ $active = '';
+ if($i == $pagination['curPage']) $active = 'is-current';
+
+ if(in_array($i,$pagination['visibleRange'])) {
+ echo '<li><a href="index.php?p=overview&m=' . $pagination['m'] . '&page=' . $i . '"
+ class="pagination-link ' . $active . '"
+ aria-label="Goto page ' . $i . '">' . $i . '</a></li>';
+ }
+ else {
+ if($i < $pagination['currentRangeStart'] && $ellipsisShown == 0) {
+ echo '<li><span class="pagination-ellipsis">…</span></li>';
+ $ellipsisShown = 1;
+ }
+ if($i > $pagination['currentRangeEnd'] && ($ellipsisShown == 0 || $ellipsisShown == 1)) {
+ echo '<li><span class="pagination-ellipsis">…</span></li>';
+ $ellipsisShown = 2;
+ }
+ }
+ }
+ ?>
+ </ul>
+ </nav>
+ <?php } ?>
</section>
<section class="section">
-<?php if(!empty($linkCollection)) { ?>
+<?php if(!empty($linkCollection['results'])) { ?>
<div class="columns is-multiline">
-<?php foreach ($linkCollection as $link) { ?>
+<?php foreach ($linkCollection['results'] as $link) { ?>
<div class="column is-one-quarter">
<div class="card">
<div class="card-image">