aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArno Richter <mail@arnorichter.de>2022-01-26 23:20:51 +0100
committerArno Richter <mail@arnorichter.de>2022-01-26 23:20:51 +0100
commit5922ced6820ea7349f627c9de83859c3fa340a4c (patch)
tree43f19afa249afa144386a44b18dd34a9b67c9db8
parent8925294b3e72386a870e8eb730cd7ce32bd62a91 (diff)
parentbc96650b4c09cb3d44b3cd33607d3e7f363ad8fb (diff)
downloadmicroblog-5922ced6820ea7349f627c9de83859c3fa340a4c.tar.gz
microblog-5922ced6820ea7349f627c9de83859c3fa340a4c.tar.bz2
microblog-5922ced6820ea7349f627c9de83859c3fa340a4c.zip
Merge branch 'pr/10'
-rw-r--r--functions.php12
-rw-r--r--microblog.css1
-rw-r--r--timeline.inc.php8
3 files changed, 16 insertions, 5 deletions
diff --git a/functions.php b/functions.php
index 94b9dc1..25ae5b2 100644
--- a/functions.php
+++ b/functions.php
@@ -51,6 +51,18 @@ function db_select_posts($from=NOW, $amount=10, $sort='desc', $page=1) {
return (!empty($rows)) ? $rows : false;
}
+function db_posts_count() {
+ global $config;
+ global $db;
+ if(empty($db)) return false;
+
+ $statement = $db->prepare('SELECT COUNT(*) AS posts_count FROM posts');
+ $statement->execute();
+ $row = $statement->fetch(PDO::FETCH_ASSOC);
+
+ return (int) $row['posts_count'];
+}
+
/* function that pings the official micro.blog endpoint for feed refreshes */
function ping_microblog() {
global $config;
diff --git a/microblog.css b/microblog.css
index 8f5df2c..eb9e382 100644
--- a/microblog.css
+++ b/microblog.css
@@ -71,7 +71,6 @@ nav li + li a {
font-weight: bold;
float: left;
}
-.timeline .pagination a.disabled { background-color: #b5b5af; }
.timeline .pagination .next { float: right; }
.wrap .post-timestamp {
diff --git a/timeline.inc.php b/timeline.inc.php
index c4f9d20..13a4d54 100644
--- a/timeline.inc.php
+++ b/timeline.inc.php
@@ -11,8 +11,8 @@
// pagination
$current_page = (path(0) == 'page' && is_numeric(path(1))) ? (int) path(1) : 1;
- $previous_page = ($current_page > 1) ? $current_page-1 : 1;
- $next_page = $current_page + 1;
+ $posts_count = db_posts_count();
+ $total_pages = ceil($posts_count / $config['posts_per_page']);
// get posts
$posts = db_select_posts(NOW, $config['posts_per_page'], 'desc', $current_page);
@@ -50,8 +50,8 @@
<p>No posts found.</p>
<?php endif; ?>
<div class="pagination">
- <a href="<?= $config['url'] ?>/page/<?= $previous_page ?>" class="previous<?= ($current_page == 1) ? ' disabled': '' ?>">newer updates</a>
- <a href="<?= $config['url'] ?>/page/<?= $next_page ?>" class="next">older updates</a>
+ <?php if ($current_page > 1): ?><a href="<?= $config['url'] ?>/page/<?= $current_page - 1 ?>" class="previous">newer updates</a><?php endif; ?>
+ <?php if ($current_page < $total_pages): ?><a href="<?= $config['url'] ?>/page/<?= $current_page + 1 ?>" class="next">older updates</a><?php endif; ?>
</div>
</div>
</body>