diff --git a/partials/base.php b/partials/base.php
index 75c7647..d3e4075 100644
--- a/partials/base.php
+++ b/partials/base.php
@@ -23,10 +23,6 @@ require_once 'libs/hash.php';
require_once 'libs/Parsedown.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";
// HACKED by sp@darch.dk
@@ -141,19 +137,6 @@ if (!empty($_GET['hash'])) {
$twts = array_reverse($twts, true);
}
-// Pagnation
-
-//$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);
-}
+// echo "Total twts before filtering: " . count($twts); // Pagnation (moved to pagnation.php)
$baseURL = str_replace("/index.php", "", $_SERVER['SCRIPT_NAME']);
diff --git a/partials/pagnation.php b/partials/pagnation.php
index 83501cb..b61b256 100644
--- a/partials/pagnation.php
+++ b/partials/pagnation.php
@@ -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 . ")
";
+ $paginateTwts = false;
+} else {
+ //echo "Over " . $twts_per_page . " so pagnation is needed.
";
+ $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 .= '> Next Page';
+}
+
+$totalTwts = count($twts);
+//echo "pagnation twts: " . $totalTwts;
+
+$totalPages = ceil($totalTwts / $twts_per_page);
+//echo "
total pages: " . $totalPages;
+
$page_url = $_SERVER['REQUEST_URI'];
//echo $page_url."