/
topic.php
executable file
·59 lines (44 loc) · 1.33 KB
/
topic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require('includes/header.php');
// Validate / fetch topic info.
if( ! ctype_digit($_GET['id']))
{
add_error('Invalid ID.', true);
}
$topic=new Topic(intval($_GET['id']));
$topic->Parse();
$topic->GetReplies();
Output::Assign('topic',$topic);
update_activity('topic', $_GET['id']);
$page_title = 'Topic: ' . htmlspecialchars($topic->Headline);
// Increment visit count.
if( ! isset($_SESSION['visited_topics'][$_GET['id']]) && isset($_COOKIE['SID']))
{
$_SESSION['visited_topics'][$_GET['id']] = 1;
DB::Execute('UPDATE {P}Topics SET visits = visits + 1 WHERE id = '.$_GET['id']);
}
// Set visited cookie...
$last_read_post = $User->Visited[$_GET['id']];
if($last_read_post !== $topic->Replies)
{
// Build cookie.
// Add the current topic:
$User->Visited = array( $_GET['id'] => $topic_replies) + $User->Visited;
// Readd old topics.
foreach($User->Visited as $cur_topic_id => $num_replies)
{
// If the cookie is getting too long (4kb), stop.
if(strlen($cookie_string) > 3900)
{
break;
}
$cookie_string .= 't' . $cur_topic_id . 'n' . $num_replies;
}
CreateCookie('topic_visits', $cookie_string);
}
Output::Assign('LastReadPost',$last_read_post);
// Output dummy form. (This is for JavaScript submissions to action.php.)
dummy_form();
echo Output::$tpl->Fetch('topic.tpl.php');
require('includes/footer.php');
?>