-
Notifications
You must be signed in to change notification settings - Fork 0
/
printthread.php
261 lines (226 loc) · 6.58 KB
/
printthread.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
define("IN_MYBB", 1);
define('THIS_SCRIPT', 'printthread.php');
$templatelist = "printthread,printthread_post,printthread_nav,forumdisplay_password_wrongpass,forumdisplay_password,printthread_multipage,printthread_multipage_page,printthread_multipage_page_current";
require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
// Load global language phrases
$lang->load("printthread");
$plugins->run_hooks("printthread_start");
$thread = get_thread($mybb->get_input('tid', MyBB::INPUT_INT));
if(!$thread || $thread['visible'] == -1)
{
error($lang->error_invalidthread);
}
$plugins->run_hooks("printthread_start");
$thread['threadprefix'] = $thread['displaystyle'] = '';
if($thread['prefix'])
{
$threadprefix = build_prefixes($thread['prefix']);
if(!empty($threadprefix))
{
$thread['threadprefix'] = $threadprefix['prefix'];
$thread['displaystyle'] = $threadprefix['displaystyle'];
}
}
$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
$fid = $thread['fid'];
$tid = $thread['tid'];
// Is the currently logged in user a moderator of this forum?
$ismod = is_moderator($fid);
// Make sure we are looking at a real thread here.
if(($thread['visible'] != 1 && $ismod == false) || ($thread['visible'] > 1 && $ismod == true))
{
error($lang->error_invalidthread);
}
// Get forum info
$forum = get_forum($fid);
if(!$forum)
{
error($lang->error_invalidforum);
}
$breadcrumb = makeprintablenav();
$parentsexp = explode(",", $forum['parentlist']);
$numparents = count($parentsexp);
$tdepth = "-";
for($i = 0; $i < $numparents; ++$i)
{
$tdepth .= "-";
}
$forumpermissions = forum_permissions($forum['fid']);
if($forum['type'] != "f")
{
error($lang->error_invalidforum);
}
if($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0 || (isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] != 0 && $thread['uid'] != $mybb->user['uid']))
{
error_no_permission();
}
// Check if this forum is password protected and we have a valid password
check_forum_password($forum['fid']);
$page = $mybb->get_input('page', MyBB::INPUT_INT);
// Paginate this thread
if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1)
{
$mybb->settings['postsperpage'] = 20;
}
$perpage = $mybb->settings['postsperpage'];
$postcount = (int)$thread['replies']+1;
$pages = ceil($postcount/$perpage);
if($page > $pages)
{
$page = 1;
}
if($page > 0)
{
$start = ($page-1) * $perpage;
}
else
{
$start = 0;
$page = 1;
}
if($postcount > $perpage)
{
$multipage = printthread_multipage($postcount, $perpage, $page, "printthread.php?tid={$tid}");
}
else
{
$multipage = '';
}
$thread['threadlink'] = get_thread_link($tid);
$postrows = '';
if(is_moderator($forum['fid'], "canviewunapprove"))
{
$visible = "AND (p.visible='0' OR p.visible='1')";
}
else
{
$visible = "AND p.visible='1'";
}
$query = $db->query("
SELECT u.*, u.username AS userusername, p.*
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
WHERE p.tid='$tid' {$visible}
ORDER BY p.dateline
LIMIT {$start}, {$perpage}
");
while($postrow = $db->fetch_array($query))
{
$parser_options = array(
"allow_html" => $forum['allowhtml'],
"allow_mycode" => $forum['allowmycode'],
"allow_smilies" => $forum['allowsmilies'],
"allow_imgcode" => $forum['allowimgcode'],
"allow_videocode" => $forum['allowvideocode'],
"me_username" => $postrow['username'],
"shorten_urls" => 0,
"filter_badwords" => 1
);
if($postrow['smilieoff'] == 1)
{
$parser_options['allow_smilies'] = 0;
}
if($mybb->user['showimages'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
{
$parser_options['allow_imgcode'] = 0;
}
if($mybb->user['showvideos'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0)
{
$parser_options['allow_videocode'] = 0;
}
if($postrow['userusername'])
{
$postrow['username'] = $postrow['userusername'];
}
$postrow['username'] = htmlspecialchars_uni($postrow['username']);
$postrow['subject'] = htmlspecialchars_uni($parser->parse_badwords($postrow['subject']));
$postrow['date'] = my_date($mybb->settings['dateformat'], $postrow['dateline'], null, 0);
$postrow['profilelink'] = build_profile_link($postrow['username'], $postrow['uid']);
$postrow['message'] = $parser->parse_message($postrow['message'], $parser_options);
$plugins->run_hooks("printthread_post");
eval("\$postrows .= \"".$templates->get("printthread_post")."\";");
}
$plugins->run_hooks("printthread_end");
eval("\$printable = \"".$templates->get("printthread")."\";");
output_page($printable);
/**
* @param int $pid
* @param string $depth
*
* @return string
*/
function makeprintablenav($pid=0, $depth="--")
{
global $mybb, $db, $pforumcache, $fid, $forum, $lang, $templates;
if(!is_array($pforumcache))
{
$parlist = build_parent_list($fid, "fid", "OR", $forum['parentlist']);
$query = $db->simple_select("forums", "name, fid, pid", "$parlist", array('order_by' => 'pid, disporder'));
while($forumnav = $db->fetch_array($query))
{
$pforumcache[$forumnav['pid']][$forumnav['fid']] = $forumnav;
}
unset($forumnav);
}
$forums = '';
if(is_array($pforumcache[$pid]))
{
foreach($pforumcache[$pid] as $key => $forumnav)
{
$forumnav['link'] = get_forum_link($forumnav['fid']);
eval("\$forums .= \"".$templates->get("printthread_nav")."\";");
if(!empty($pforumcache[$forumnav['fid']]))
{
$newdepth = $depth."-";
$forums .= makeprintablenav($forumnav['fid'], $newdepth);
}
}
}
return $forums;
}
/**
* Output multipage navigation.
*
* @param int $count The total number of items.
* @param int $perpage The items per page.
* @param int $current_page The current page.
* @param string $url The URL base.
*
* @return string
*/
function printthread_multipage($count, $perpage, $current_page, $url)
{
global $lang, $templates;
$multipage = "";
if($count > $perpage)
{
$pages = $count / $perpage;
$pages = ceil($pages);
$mppage = null;
for($page = 1; $page <= $pages; ++$page)
{
if($page == $current_page)
{
eval("\$mppage .= \"".$templates->get("printthread_multipage_page_current")."\";");
}
else
{
eval("\$mppage .= \"".$templates->get("printthread_multipage_page")."\";");
}
}
eval("\$multipage = \"".$templates->get("printthread_multipage")."\";");
}
return $multipage;
}