mirror of
https://github.com/sorenpeter/timeline.git
synced 2025-12-15 10:57:01 +00:00
Pagnations done
This commit is contained in:
parent
b65c496c0d
commit
6e46dd04ae
4 changed files with 54 additions and 84 deletions
|
|
@ -1,83 +1,52 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|
||||
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;
|
||||
$maxTwts = $config['twts_per_page'] ?? 50; // Fallback number if twts_per_page not set in config.ini
|
||||
|
||||
$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>";
|
||||
if ( ($maxTwts >= $totalTwts) || ($paginateTwts == false) ) {
|
||||
// echo "Only " . $totalTwts . " so no need for pagnation. (max: ". $maxTwts . ")<br>";
|
||||
$paginateTwts = false;
|
||||
|
||||
} else {
|
||||
//echo "Over " . $twts_per_page . " so pagnation is needed.<br>";
|
||||
$paginateTwts = true;
|
||||
}
|
||||
// echo "Over " . $maxTwts . " so pagnation is needed.<br>";
|
||||
$paginateTwts = true; // for showing pagnation navigation below timeline
|
||||
|
||||
$page = 1;
|
||||
if (!empty($_GET['page'])) {
|
||||
$page = intval($_GET['page']);
|
||||
}
|
||||
$totalPages = ceil($totalTwts / $maxTwts);
|
||||
|
||||
// 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>';
|
||||
}
|
||||
// Split up twts into pages
|
||||
$startingTwt = (($currentPage - 1) * $maxTwts);
|
||||
$twts = array_slice($twts, $startingTwt, $maxTwts);
|
||||
|
||||
$totalTwts = count($twts);
|
||||
//echo "pagnation twts: " . $totalTwts;
|
||||
|
||||
$totalPages = ceil($totalTwts / $twts_per_page);
|
||||
//echo "<br>total pages: " . $totalPages;
|
||||
|
||||
$page_url = $_SERVER['REQUEST_URI'];
|
||||
//echo $page_url."<hr>";
|
||||
// Fingure out base URL for prev/next links
|
||||
$pageURL = $_SERVER['REQUEST_URI'];
|
||||
//echo $pageURL."<hr>";
|
||||
|
||||
if (!empty($_GET['page'])) {
|
||||
|
||||
if (preg_match('/\?page=/', $page_url)) {
|
||||
if (preg_match('/\?page=/', $pageURL)) {
|
||||
//echo "cotains ?page= so reuse that <hr>";
|
||||
$page_url = preg_replace('/\?page=\d*/', "", $page_url) . '?page=';
|
||||
$pageURL = preg_replace('/\?page=\d*/', "", $pageURL) . '?page=';
|
||||
}
|
||||
|
||||
if (preg_match('/&page=/', $page_url)) {
|
||||
if (preg_match('/&page=/', $pageURL)) {
|
||||
//echo "cotains &page= so reuse that <hr>";
|
||||
$page_url = preg_replace('/&page=\d*/', "", $page_url) . '&page=';
|
||||
$pageURL = preg_replace('/&page=\d*/', "", $pageURL) . '&page=';
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (!preg_match('/(\?|&)/', $page_url)) {
|
||||
if (!preg_match('/(\?|&)/', $pageURL)) {
|
||||
//echo "No param, so use ?page <hr>";
|
||||
$page_url = $page_url . '?page=';
|
||||
$pageURL = $pageURL . '?page=';
|
||||
}
|
||||
|
||||
if (!preg_match('/(\?|&)page/', $page_url)) {
|
||||
if (!preg_match('/(\?|&)page/', $pageURL)) {
|
||||
//echo "other param than _page, so use &page <hr>";
|
||||
$page_url = $page_url . '&page=';
|
||||
$pageURL = $pageURL . '&page=';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
<?php }?>
|
||||
-->
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
include_once 'partials/search.php';
|
||||
|
|
@ -60,19 +59,21 @@ 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 if ($currentPage> 1) { ?>
|
||||
<a href="<?= $pageURL . $currentPage- 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>
|
||||
<strong> <?= $currentPage /* . " / " . $totalPages */ ?> </strong>
|
||||
<?php if ($currentPage < $totalPages) { ?>
|
||||
<a href="<?= $pageURL . $currentPage+1 ?>">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a>
|
||||
<?php } else { ?>
|
||||
<span style="color: var(--disabled);">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></span>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php }
|
||||
|
||||
require_once 'libs/session.php';
|
||||
|
||||
if (!hasValidSession()) {
|
||||
echo '<center><a href="mailto:' . $config['email'] . '?subject=RE: ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '" class="button">Comment via email</a></center>';
|
||||
if (!hasValidSession() && isset($config['email']) ) {
|
||||
echo '<center><a href="mailto:' . $config['email'] . '?subject=RE: ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '" class="button">Reply via email</a></center>';
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
//$paginateTwts = true;
|
||||
$paginateTwts = true;
|
||||
|
||||
if (!empty($_GET['url'])) { // Show twts for some user (Profile view)
|
||||
$twtsURL = $_GET['url'];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
//$paginateTwts = true;
|
||||
$paginateTwts = true;
|
||||
|
||||
if (!empty($_GET['url'])) { // Show twts for some user (Profile view)
|
||||
$twtsURL = $_GET['url'];
|
||||
|
|
|
|||
Loading…
Reference in a new issue