Vanilla commit.
[tinybbs.git] / replies.php
blob2ace972e729d0a79a8dd169038a303e270caa0b9
1 <?php
3 require('includes/header.php');
5 // Check if we're on a specific page.
6 if ( ! ctype_digit($_GET['p']) || $_GET['p'] < 2)
8 $current_page = 1;
9 $page_title = 'Latest replies';
11 update_activity('latest_replies');
13 else
15 $current_page = $_GET['p'];
16 $page_title = 'Replies, page #' . number_format($current_page);
18 update_activity('replies', $current_page);
21 // Print out the appropriate replies.
22 $items_per_page = ITEMS_PER_PAGE;
23 $start_listing_replies_at = $items_per_page * ($current_page - 1);
25 $stmt = $link->prepare('SELECT replies.id, replies.parent_id, replies.time, replies.body, topics.headline, topics.time FROM replies INNER JOIN topics ON replies.parent_id = topics.id ORDER BY id DESC LIMIT ?, ?');
26 $stmt->bind_param('ii', $start_listing_replies_at, $items_per_page);
27 $stmt->execute();
28 $stmt->bind_result($reply_id, $parent_id, $reply_time, $reply_body, $topic_headline, $topic_time);
30 $replies = new table();
31 $columns = array
33 'Snippet',
34 'Topic',
35 'Age ▼'
37 $replies->define_columns($columns, 'Topic');
38 $replies->add_td_class('Topic', 'topic_headline');
39 $replies->add_td_class('Snippet', 'snippet');
41 while($stmt->fetch())
43 $values = array
45 '<a href="/topic/' . $parent_id . '#reply_' . $reply_id . '">' . snippet($reply_body) . '</a>',
46 '<a href="/topic/' . $parent_id . '">' . htmlspecialchars($topic_headline) . '</a> <span class="help unimportant" title="' . format_date($topic_time) . '">(' . calculate_age($topic_time) . ' old)</span>',
47 '<span class="help" title="' . format_date($reply_time) . '">' . calculate_age($reply_time) . '</span>'
50 $replies->row($values);
52 $stmt->close();
53 $num_replies_fetched = $replies->num_rows_fetched;
54 echo $replies->output();
56 // Navigate backward or forward ...
57 page_navigation('replies', $current_page, $num_replies_fetched);
59 require('includes/footer.php');