Vanilla commit.
[tinybbs.git] / topic_trivia.php
blobe114de84839c40e65eeaa64c1b645319cd982536
1 <?php
3 require('includes/header.php');
5 if( ! ctype_digit($_GET['id']))
7 add_error('Invalid ID.', true);
10 $stmt = $link->prepare('SELECT headline, visits, replies, author FROM topics WHERE id = ?');
11 $stmt->bind_param('i', $_GET['id']);
13 $stmt->execute();
15 $stmt->store_result();
16 if($stmt->num_rows < 1)
18 $page_title = 'Non-existent topic';
19 add_error('There is no such topic. It may have been deleted.', true);
22 $stmt->bind_result($topic_headline, $topic_visits, $topic_replies, $topic_author);
23 $stmt->fetch();
24 $stmt->close();
26 update_activity('topic_trivia', $_GET['id']);
28 $page_title = 'Trivia for topic: <a href="/topic/' . $_GET['id'] . '">' . htmlspecialchars($topic_headline) . '</a>';
30 $statistics = array();
32 $query = "SELECT count(*) FROM watchlists WHERE topic_id = '" . $link->real_escape_string($_GET['id']) . "';";
33 $query .= "SELECT count(*) FROM activity WHERE action_name = 'topic' AND action_id = '" . $link->real_escape_string($_GET['id']) . "';";
34 $query .= "SELECT count(*) FROM activity WHERE action_name = 'replying' AND action_id = '" . $link->real_escape_string($_GET['id']) . "';";
35 $query .= "SELECT count(DISTINCT author) FROM replies WHERE parent_id = '" . $link->real_escape_string($_GET['id']) . "' AND author != '" . $link->real_escape_string($topic_author) . "';"; // Alternatively, we could select the most recent poster_number. I'm not sure which method would be fastest.
37 $link->multi_query($query);
38 do
40 $result = $link->store_result();
41 while ($row = $result->fetch_row())
43 $statistics[] = $row[0];
45 $result->free();
46 } while ($link->next_result());
48 $topic_watchers = $statistics[0];
49 $topic_readers = $statistics[1];
50 $topic_writers = $statistics[2];
51 $topic_participants = $statistics[3] + 1; // include topic author
55 <table>
56 <tr>
57 <th class="minimal">Total visits</th>
58 <td><?php echo format_number($topic_visits) ?></td>
59 </tr>
61 <tr class="odd">
62 <th class="minimal">Watchers</th>
63 <td><?php echo format_number($topic_watchers) ?></td>
64 </tr>
66 <tr>
67 <th class="minimal">Participants</th>
68 <td><?php echo ($topic_participants === 1) ? '(Just the creator.)' : format_number($topic_participants) ?></td>
69 </tr>
71 <tr class="odd">
72 <th class="minimal">Replies</th>
73 <td><?php echo format_number($topic_replies) ?></td>
74 </tr>
76 <tr>
77 <th class="minimal">Current readers</th>
78 <td><?php echo format_number($topic_readers) ?></td>
79 </tr>
81 <tr class="odd">
82 <th class="minimal">Current reply writers</th>
83 <td><?php echo format_number($topic_writers) ?></td>
84 </tr>
86 </table>
88 <?php
90 require('includes/footer.php');