author | Dan |
Tue, 13 Nov 2007 19:39:50 -0500 | |
changeset 6 | 3f66ec435f08 |
parent 4 | c31210950118 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/* |
|
3 |
* Decir |
|
4 |
* Version 0.1 |
|
5 |
* Copyright (C) 2007 Dan Fuhry |
|
6 |
* viewtopic.php - Shows individual posts |
|
7 |
* |
|
8 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
12 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
13 |
*/ |
|
6 | 14 |
|
0 | 15 |
require('common.php'); |
16 |
require('bbcode.php'); |
|
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
17 |
require('functions_viewtopic.php'); |
0 | 18 |
|
19 |
global $whos_online; |
|
20 |
||
21 |
if ( strtolower($paths->getParam(0)) == 'post' || isset($_GET['pid']) ) |
|
22 |
{ |
|
23 |
$pid = ( $n = $paths->getParam(1) ) ? $n : ( ( isset($_GET['pid']) ) ? $_GET['pid'] : 0 ); |
|
24 |
$pid = intval($pid); |
|
25 |
||
26 |
if(empty($pid)) |
|
27 |
{ |
|
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
28 |
$template->header(); |
0 | 29 |
echo '<p>Invalid topic ID</p>'; |
6 | 30 |
decir_show_footers(); |
31 |
$template->footer(); |
|
0 | 32 |
return; |
33 |
} |
|
34 |
||
35 |
$q = $db->sql_query('SELECT topic_id FROM '.table_prefix.'decir_posts WHERE post_id='.$pid.';'); |
|
36 |
if ( !$q ) |
|
37 |
$db->_die(); |
|
38 |
||
39 |
$row = $db->fetchrow(); |
|
1
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
40 |
$tid = intval($row['topic_id']); |
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
41 |
$db->free_result(); |
0 | 42 |
} |
43 |
else |
|
44 |
{ |
|
45 |
$tid = ( $n = $paths->getParam(1) ) ? $n : ( ( isset($_GET['tid']) ) ? $_GET['tid'] : 0 ); |
|
46 |
$tid = intval($tid); |
|
47 |
||
48 |
if(empty($tid)) |
|
49 |
{ |
|
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
50 |
$template->header(); |
0 | 51 |
echo '<p>Invalid topic ID</p>'; |
6 | 52 |
decir_show_footers(); |
53 |
$template->footer(); |
|
0 | 54 |
return; |
55 |
} |
|
56 |
} |
|
57 |
||
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
58 |
$q = $db->sql_query('SELECT t.forum_id, t.topic_title, f.forum_name, f.forum_id, t.topic_id, t.topic_deleted, t.topic_deletor, t.topic_delete_reason, u.username AS deletor FROM '.table_prefix.'decir_topics AS t |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
59 |
LEFT JOIN '.table_prefix.'users AS u |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
60 |
ON ( u.user_id = t.topic_deletor OR t.topic_deletor IS NULL ) |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
61 |
LEFT JOIN '.table_prefix.'decir_forums AS f |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
62 |
ON ( f.forum_id = t.forum_id ) |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
63 |
WHERE t.topic_id='.$tid.';'); |
0 | 64 |
|
65 |
if ( !$q ) |
|
66 |
$db->_die(); |
|
67 |
||
68 |
$topic_exists = true; |
|
69 |
||
70 |
if ( $db->numrows() > 0 ) |
|
71 |
{ |
|
72 |
$row = $db->fetchrow(); |
|
73 |
$forum_id = $row['forum_id']; |
|
74 |
$topic_id = $row['topic_id']; |
|
75 |
$topic_exists = true; |
|
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
76 |
// FIXME: This will be controlled by an ACL rule |
4
c31210950118
Some access controls implemented... we'll see how well this works
Dan
parents:
2
diff
changeset
|
77 |
if ( $row['topic_deleted'] == 1 && !$session->get_permissions('decir_see_deleted_topic_full') ) |
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
78 |
{ |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
79 |
$topic_exists = false; |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
80 |
} |
0 | 81 |
} |
82 |
else |
|
83 |
{ |
|
84 |
$topic_exists = false; |
|
85 |
} |
|
86 |
||
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
87 |
// Set page title |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
88 |
$template->tpl_strings['PAGE_NAME'] = htmlspecialchars($row['topic_title']) . ' « ' . htmlspecialchars($row['forum_name']) . ' « Forums'; |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
89 |
|
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
90 |
$template->header(); |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
91 |
|
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
92 |
// build breadcrumbs |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
93 |
echo '<div class="breadcrumbs">'; |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
94 |
echo '<a href="' . makeUrlNS('Special', 'Forum') . '">Forum index</a> » '; |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
95 |
echo '<a href="' . makeUrlNS('Special', 'Forum/ViewForum/' . $row['forum_id']) . '">' . htmlspecialchars($row['forum_name']) . '</a> » '; |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
96 |
echo htmlspecialchars($row['topic_title']); |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
97 |
echo '</div>'; |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
98 |
|
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
99 |
if ( $row['topic_deleted'] == 1 ) |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
100 |
{ |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
101 |
// User will at this point have permission to read the deleted topic (and thus restore it) |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
102 |
$restore_url = makeUrlNS('Special', 'Forum/RestoreTopic/' . $topic_id, false, true); |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
103 |
echo '<div class="usermessage">This topic was deleted by ' . htmlspecialchars($row['deletor']) . '. You can <a href="' . $restore_url . '">restore this topic</a>.<br /> |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
104 |
<i>Reason for deletion: ' . htmlspecialchars($row['topic_delete_reason']) . '</i></div>'; |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
105 |
} |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
106 |
|
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
107 |
if ( !$topic_exists ) |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
108 |
{ |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
109 |
die_friendly('Error', '<p>The topic you requested does not exist.</p>'); |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
110 |
} |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
111 |
|
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
112 |
$sql = 'SELECT COUNT(post_id) AS np FROM '.table_prefix."decir_posts WHERE topic_id=$tid;"; |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
113 |
$q = $db->sql_query($sql); |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
114 |
if ( !$q ) |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
115 |
$db->_die(); |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
116 |
list($num_posts) = $db->fetchrow_num(); |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
117 |
$db->free_result(); |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
118 |
|
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
119 |
$offset = 0; |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
120 |
if ( $p = $paths->getParam(2) ) |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
121 |
{ |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
122 |
if ( preg_match('/^start=([0-9]+)$/', $p, $m) ) |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
123 |
{ |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
124 |
$offset = intval($m[1]); |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
125 |
} |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
126 |
} |
0 | 127 |
|
1
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
128 |
$sql = 'SELECT p.post_id,p.poster_name,p.poster_id,u.username,p.timestamp,p.edit_count,p.last_edited_by,p.post_deleted,u2.username AS editor,p.edit_reason,u.user_level,u.reg_time,t.post_text,t.bbcode_uid FROM '.table_prefix.'decir_posts AS p |
0 | 129 |
LEFT JOIN '.table_prefix.'users AS u |
1
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
130 |
ON u.user_id=p.poster_id |
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
131 |
LEFT JOIN '.table_prefix.'users AS u2 |
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
132 |
ON (u2.user_id=p.last_edited_by OR p.last_edited_by IS NULL) |
0 | 133 |
LEFT JOIN '.table_prefix.'decir_posts_text AS t |
134 |
ON p.post_id=t.post_id |
|
135 |
WHERE p.topic_id='.$tid.' |
|
1
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
136 |
GROUP BY p.post_id |
0 | 137 |
ORDER BY p.timestamp ASC;'; |
138 |
||
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
139 |
$q = $db->sql_unbuffered_query($sql); |
0 | 140 |
if ( !$q ) |
141 |
$db->_die(); |
|
142 |
||
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
143 |
$formatter = new DecirPostbit(); |
0 | 144 |
|
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
145 |
$html = paginate( |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
146 |
$q, // MySQL result resource |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
147 |
'{post_id}', |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
148 |
$num_posts, |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
149 |
makeUrlNS('Special', 'Forum/Topic/' . $tid . '/start=%s', false, true), |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
150 |
$offset, |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
151 |
15, |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
152 |
array('post_id' => array($formatter, '_render')) |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
153 |
); |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
154 |
|
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
155 |
if ( $html ) |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
156 |
echo $html; |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
157 |
else |
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
158 |
die_friendly('Error', '<p>The topic you requested does not exist.</p>'); |
0 | 159 |
|
160 |
$db->free_result(); |
|
161 |
||
162 |
if ( $topic_exists ) |
|
163 |
{ |
|
164 |
$can_post_replies = false; |
|
165 |
$can_post_topics = false; |
|
166 |
||
1
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
167 |
$forum_perms = $session->fetch_page_acl($forum_id, 'DecirForum'); |
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
168 |
$topic_perms = $session->fetch_page_acl($topic_id, 'DecirTopic'); |
0 | 169 |
|
170 |
if ( $forum_perms->get_permissions('decir_post') ) |
|
171 |
$can_post_topics = true; |
|
172 |
||
173 |
if ( $topic_perms->get_permissions('decir_reply') ) |
|
174 |
$can_post_replies = true; |
|
175 |
||
176 |
echo '<p>'; |
|
177 |
if ( $can_post_topics ) |
|
178 |
{ |
|
179 |
echo '<a href="' . makeUrlNS('Special', 'Forum/New/Topic/' . $forum_id) . '">Post new topic</a>'; |
|
180 |
} |
|
181 |
if ( $can_post_topics && $can_post_replies ) |
|
182 |
{ |
|
183 |
echo ' | '; |
|
184 |
} |
|
185 |
if ( $can_post_replies ) |
|
186 |
{ |
|
187 |
echo '<a href="' . makeUrlNS('Special', 'Forum/New/Reply/' . $topic_id) . '">Add reply</a>'; |
|
188 |
} |
|
189 |
echo '</p>'; |
|
190 |
} |
|
191 |
||
1
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
192 |
// log the hit |
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
193 |
$time = time(); |
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
194 |
$q = $db->sql_query('INSERT INTO '.table_prefix."decir_hits(user_id, topic_id, timestamp) VALUES($session->user_id, $tid, $time);"); |
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
195 |
$q = $db->sql_query('UPDATE '.table_prefix."decir_topics SET num_views = num_views + 1 WHERE topic_id = $tid;"); |
1
6f8b7c6fac02
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
0
diff
changeset
|
196 |
|
6 | 197 |
decir_show_footers(); |
0 | 198 |
$template->footer(); |
199 |
||
2
253118325c65
Pagination on topics and a whole crapload of other stuff.
Dan
parents:
1
diff
changeset
|
200 |
?> |