mirror of
https://github.com/sorenpeter/timeline.git
synced 2026-03-11 12:42:17 +00:00
pagnation for profiles and only if needed
This commit is contained in:
parent
0c91c9434e
commit
b65c496c0d
3 changed files with 69 additions and 34 deletions
|
|
@ -23,10 +23,6 @@ require_once 'libs/hash.php';
|
||||||
require_once 'libs/Parsedown.php';
|
require_once 'libs/Parsedown.php';
|
||||||
require_once 'libs/load_timezone.php';
|
require_once 'libs/load_timezone.php';
|
||||||
|
|
||||||
// TODO: Move twts per page to config.ini
|
|
||||||
// Add a fallback if the number is invalid (it should be between 1 and 999)
|
|
||||||
const TWTS_PER_PAGE = 50;
|
|
||||||
|
|
||||||
$title = $config['site_title'] ?? "Timeline";
|
$title = $config['site_title'] ?? "Timeline";
|
||||||
|
|
||||||
// HACKED by sp@darch.dk
|
// HACKED by sp@darch.dk
|
||||||
|
|
@ -141,19 +137,6 @@ if (!empty($_GET['hash'])) {
|
||||||
$twts = array_reverse($twts, true);
|
$twts = array_reverse($twts, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pagnation
|
// echo "Total twts before filtering: " . count($twts); // Pagnation (moved to pagnation.php)
|
||||||
|
|
||||||
//$twts_per_page = $config['twts_per_page'];
|
|
||||||
|
|
||||||
$page = 1;
|
|
||||||
if (!empty($_GET['page'])) {
|
|
||||||
$page = intval($_GET['page']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we should paginate our twts list
|
|
||||||
if (!empty($paginateTwts)) {
|
|
||||||
$startingTwt = (($page - 1) * TWTS_PER_PAGE);
|
|
||||||
$twts = array_slice($twts, $startingTwt, TWTS_PER_PAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
$baseURL = str_replace("/index.php", "", $_SERVER['SCRIPT_NAME']);
|
$baseURL = str_replace("/index.php", "", $_SERVER['SCRIPT_NAME']);
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,56 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
TODO: Make pagnation work with profile views
|
TODO:
|
||||||
|
+ Test if $twts are bigger/lowe than max to detemen if pagnations is needed
|
||||||
|
+ Make pagnation work with profile views
|
||||||
|
- Move twts per page to config.ini
|
||||||
|
- Add a fallback if the number is invalid (it should be between 1 and 999)
|
||||||
|
//$twts_per_page = $config['twts_per_page'];
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const TWTS_PER_PAGE = 20;
|
||||||
|
$twts_per_page = TWTS_PER_PAGE;
|
||||||
|
|
||||||
|
$totalTwts = count($twts);
|
||||||
|
|
||||||
|
// Test if pagnation is needed and set stat
|
||||||
|
// TODO: consider how to have /conv alway show all twts
|
||||||
|
|
||||||
|
if ( $twts_per_page >= $totalTwts ) {
|
||||||
|
//echo "Only " . $totalTwts . " so no need for pagnation. (max: ". $twts_per_page . ")<br>";
|
||||||
|
$paginateTwts = false;
|
||||||
|
} else {
|
||||||
|
//echo "Over " . $twts_per_page . " so pagnation is needed.<br>";
|
||||||
|
$paginateTwts = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$page = 1;
|
||||||
|
if (!empty($_GET['page'])) {
|
||||||
|
$page = intval($_GET['page']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we should paginate our twts list
|
||||||
|
if (!empty($paginateTwts)) {
|
||||||
|
$startingTwt = (($page - 1) * TWTS_PER_PAGE);
|
||||||
|
$twts = array_slice($twts, $startingTwt, TWTS_PER_PAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Approach 2: Ignore invalid page numbers, and adjust the number between 1 and the last page
|
||||||
|
$currentPage = max(1, min($_GET["page"], $totalPages));
|
||||||
|
|
||||||
|
# And then in the HTML template only show the next page link if we are NOT on the last one
|
||||||
|
if ($currentPage < $totalPages) {
|
||||||
|
$output .= '<a href="?page=' . ($currentPage + 1) . '">> Next Page</a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalTwts = count($twts);
|
||||||
|
//echo "pagnation twts: " . $totalTwts;
|
||||||
|
|
||||||
|
$totalPages = ceil($totalTwts / $twts_per_page);
|
||||||
|
//echo "<br>total pages: " . $totalPages;
|
||||||
|
|
||||||
$page_url = $_SERVER['REQUEST_URI'];
|
$page_url = $_SERVER['REQUEST_URI'];
|
||||||
//echo $page_url."<hr>";
|
//echo $page_url."<hr>";
|
||||||
|
|
||||||
|
|
@ -35,13 +81,3 @@ if (!empty($_GET['page'])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="pagnation">
|
|
||||||
<?php if ($page > 1) { ?>
|
|
||||||
<a href="<?= $page_url . $page-1 ?>"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>
|
|
||||||
<?php } else { ?>
|
|
||||||
<span style="color: var(--disabled);"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</span>
|
|
||||||
<?php } ?>
|
|
||||||
<strong> <?= $page ?> </strong>
|
|
||||||
<a href="<?= $page_url . $page+1 ?>">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a>
|
|
||||||
</div>
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,13 @@
|
||||||
<?php }?>
|
<?php }?>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<?php // echo "count: " . count($twts); ?>
|
|
||||||
|
|
||||||
<?php include_once 'partials/search.php'; ?>
|
<?php
|
||||||
|
|
||||||
|
include_once 'partials/search.php';
|
||||||
|
include_once 'partials/pagnation.php';
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
<?php foreach ($twts as $twt) { ?>
|
<?php foreach ($twts as $twt) { ?>
|
||||||
<article class="post-entry" id="<?=$twt->hash?>">
|
<article class="post-entry" id="<?=$twt->hash?>">
|
||||||
|
|
@ -51,9 +55,21 @@
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
<?php }
|
<?php }
|
||||||
|
|
||||||
include_once 'partials/pagnation.php';
|
if ($paginateTwts) { ?>
|
||||||
|
|
||||||
|
<div class="pagnation">
|
||||||
|
<?php if ($page > 1) { ?>
|
||||||
|
<a href="<?= $page_url . $page-1 ?>"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>
|
||||||
|
<?php } else { ?>
|
||||||
|
<span style="color: var(--disabled);"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</span>
|
||||||
|
<?php } ?>
|
||||||
|
<strong> <?= $page ?> </strong>
|
||||||
|
<a href="<?= $page_url . $page+1 ?>">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php }
|
||||||
|
|
||||||
require_once 'libs/session.php';
|
require_once 'libs/session.php';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue