Browse Source

don't error when viewing an empty feed

pull/10/head
Aaron Parecki 9 years ago
parent
commit
534241ca23
2 changed files with 17 additions and 5 deletions
  1. +13
    -5
      controllers/controllers.php
  2. +4
    -0
      views/entries.php

+ 13
- 5
controllers/controllers.php View File

@ -264,18 +264,26 @@ $app->get('/:domain', function($domain) use($app) {
}
$entries = $entries->limit($per_page)->order_by_desc('published')->find_many();
$older = ORM::for_table('entries')->where('user_id', $user->id)
->where_lt('id', $entries[count($entries)-1]->id)->order_by_desc('published')->find_one();
if(count($entries) > 1) {
$older = ORM::for_table('entries')->where('user_id', $user->id)
->where_lt('id', $entries[count($entries)-1]->id)->order_by_desc('published')->find_one();
} else {
$older = null;
}
$newer = ORM::for_table('entries')->where('user_id', $user->id)
->where_gte('id', $entries[0]->id)->order_by_asc('published')->offset($per_page)->find_one();
if(count($entries) > 1) {
$newer = ORM::for_table('entries')->where('user_id', $user->id)
->where_gte('id', $entries[0]->id)->order_by_asc('published')->offset($per_page)->find_one();
} else {
$newer = null;
}
if(!$newer) {
// no new entry was found at the specific offset, so find the newest post to link to instead
$newer = ORM::for_table('entries')->where('user_id', $user->id)
->order_by_desc('published')->limit(1)->find_one();
if($newer->id == $entries[0]->id)
if($newer && $newer->id == $entries[0]->id)
$newer = false;
}

+ 4
- 0
views/entries.php View File

@ -8,6 +8,10 @@
<?php endforeach; ?>
</ul>
<?php if(count($this->entries) == 0): ?>
<div class="bs-callout bs-callout-warning">There are no entries yet!</div>
<?php endif; ?>
<nav class="site-navigation">
<? if($this->older) { ?>
<a class="prev" href="/<?= $this->user->url ?>?before=<?= $this->older ?>" rel="prev"><abbr>&larr;</abbr> <span>Older</span></a>

Loading…
Cancel
Save