-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshowtopic.php
487 lines (427 loc) · 16 KB
/
showtopic.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
<?php
/*
Viscacha - A bulletin board solution for easily managing your content
Copyright (C) 2004-2009 The Viscacha Project
Author: Matthias Mohr (et al.)
Publisher: The Viscacha Project, http://www.viscacha.org
Start Date: May 22, 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
error_reporting(E_ALL);
define('SCRIPTNAME', 'showtopic');
define('VISCACHA_CORE', '1');
include ("data/config.inc.php");
include ("classes/function.viscacha_frontend.php");
($code = $plugins->load('showtopic_topic_query')) ? eval($code) : null;
$result = $db->query("SELECT id, topic, posts, sticky, status, last, board, vquestion, prefix FROM {$db->pre}topics WHERE id = '{$_GET['id']}' LIMIT 1");
$info = $gpc->prepare($db->fetch_assoc($result));
$my->p = $slog->Permissions($info['board']);
$my->mp = $slog->ModPermissions($info['board']);
$error = array();
if ($db->num_rows($result) < 1) {
$error[] = $lang->phrase('query_string_error');
}
if ($my->p['forum'] == 0) {
$error[] = $lang->phrase('not_allowed');
}
if (count($error) > 0) {
errorLogin($error,'forum.php'.SID2URL_1);
}
$catbid = $scache->load('cat_bid');
$fc = $catbid->get();
$last = $fc[$info['board']];
if ($last['topiczahl'] < 1) {
$last['topiczahl'] = $config['topiczahl'];
}
$q = urldecode($gpc->get('q', str));
if (strxlen($q) > 2) {
$qUrl = '&q='.urlencode($q);
$qUrl2 = '&q='.urlencode($q);
}
else {
$qUrl = $qUrl2 = '';
}
if ($_GET['action'] == 'firstnew' && $info['last'] >= $my->clv) {
$sql_order = iif($last['post_order'] == 1, '>', '<=');
$result = $db->query("SELECT COUNT(*) AS count FROM {$db->pre}replies WHERE topic_id = '{$info['id']}' AND date {$sql_order} '{$my->clv}'");
$old = $db->fetch_assoc($result);
if ($last['post_order'] != 1) {
$old['count']++; // Number of old post (with topic start post) + 1, to get the first new post, not the last old post
}
$pgs = ceil($old['count']/$last['topiczahl']);
if ($pgs < 1) {
$pgs = 1;
}
$db->close();
sendStatusCode(302, 'showtopic.php?id='.$info['id'].'&page='.$pgs.$qUrl.SID2URL_JS_x.'#firstnew');
exit;
}
elseif ($_GET['action'] == 'last') {
// Todo: Resourcen sparender w�re es in der Themenansicht einen Anker "last" zu setzen und diesen anzuspringen... damit w�re diese Query gespart
// For post_order = 1: Query could be saved, we can just jump to the first page, first post is the post we are looking for...
$result = $db->query("SELECT id FROM {$db->pre}replies WHERE topic_id = '{$info['id']}' ORDER BY date DESC LIMIT 1");
$new = $db->fetch_num($result);
if ($last['post_order'] == 1) {
$pgs = 1;
}
else {
$pgs = ceil(($info['posts']+1)/$last['topiczahl']);
}
$db->close();
sendStatusCode(302, 'showtopic.php?id='.$info['id'].'&page='.$pgs.$qUrl.SID2URL_JS_x.'#p'.$new[0]);
exit;
}
elseif ($_GET['action'] == 'mylast') {
$result = $db->query("SELECT date, id FROM {$db->pre}replies WHERE topic_id = '{$info['id']}' AND name = '{$my->id}' ORDER BY date DESC LIMIT 1");
$mylast = $db->fetch_num($result);
$sql_order = iif($last['post_order'] == 1, '>=', '<');
$result = $db->query("SELECT COUNT(*) AS count FROM {$db->pre}replies WHERE topic_id = '{$info['id']}' AND date {$sql_order} {$mylast[0]}");
$new = $db->fetch_assoc($result);
$tp = ($info['posts']+1) - $new['count'];
$pgs = ceil($tp/$last['topiczahl']);
if ($pgs < 1) {
$pgs = 1;
}
$db->close();
sendStatusCode(302, 'showtopic.php?id='.$info['id'].'&page='.$pgs.$qUrl.SID2URL_JS_x.'#p'.$mylast[1]);
exit;
}
elseif ($_GET['action'] == 'jumpto') {
$result = $db->query("SELECT date, id FROM {$db->pre}replies WHERE topic_id = '{$info['id']}' AND id = '{$_GET['topic_id']}'");
$mylast = $db->fetch_num($result);
$sql_order = iif($last['post_order'] == 1, '<', '>');
$result = $db->query("SELECT COUNT(*) AS count FROM {$db->pre}replies WHERE topic_id = '{$info['id']}' AND date {$sql_order} '{$mylast[0]}'");
$new = $db->fetch_assoc($result);
$tp = ($info['posts']+1) - $new['count'];
$pgs = ceil($tp/$last['topiczahl']);
if ($pgs < 1) {
$pgs = 1;
}
$db->close();
sendStatusCode(302, 'showtopic.php?id='.$info['id'].'&page='.$pgs.$qUrl.SID2URL_JS_x.'#p'.$mylast[1]);
exit;
}
($code = $plugins->load('showtopic_redirect')) ? eval($code) : null;
$prefix = '';
if ($info['prefix'] > 0) {
$prefix_obj = $scache->load('prefix');
$prefix_arr = $prefix_obj->get($info['board']);
if (isset($prefix_arr[$info['prefix']])) {
$prefix = $prefix_arr[$info['prefix']]['value'];
$prefix = $lang->phrase('showtopic_prefix_title');
}
}
$topforums = get_headboards($fc, $last, TRUE);
$breadcrumb->Add($last['name'], "showforum.php?id=".$last['id'].SID2URL_x);
$breadcrumb->Add($prefix.$info['topic']);
forum_opt($last);
// Some speed optimisation
$speeder = $info['posts']+1;
$start = $_GET['page']*$last['topiczahl'];
$start = $start-$last['topiczahl'];
$temp = pages($speeder, $last['topiczahl'], "showtopic.php?id=".$info['id'].$qUrl2."&", $_GET['page']);
define('LINK_PRINT_PAGE', "print.php?id={$info['id']}&page={$_GET['page']}".SID2URL_x);
echo $tpl->parse("header");
echo $tpl->parse("menu");
($code = $plugins->load('showtopic_start')) ? eval($code) : null;
$q = explode(' ', trim($q));
$memberdata_obj = $scache->load('memberdata');
$memberdata = $memberdata_obj->get();
$inner['index_bit'] = array();
$inner['vote_result'] = '';
$inner['related'] = '';
// Do we have a vote?
if (!empty($info['vquestion'])) {
// Yeah, we have - Create an empty array for the data
$vote = array(
'count' => 0, // Number of all votes
'question' => $info['vquestion'], // The question of the vote
'entries' => array(), // Each option (with title of the option, ...)
'voted' => 0, // The option (answer id) the requesting user has chosen (0 = no vote yet)
'results' => false, // Show the result page (true) or the form to chose the options (false)
'voter' => array(), // The voter for each option
'phrase' => null // Phrase to switch to the survey form (change/add)
);
if (!$my->vlogin || $my->p['voting'] == 0 || $_GET['temp'] == 1 || $info['status'] != 0) {
$vote['results'] = true;
}
// Get data: count of votes per option, option id, option text
$vresult = $db->query("
SELECT COUNT(r.id) as votes, v.id, v.answer
FROM {$db->pre}vote AS v
LEFT JOIN {$db->pre}votes AS r ON r.aid = v.id
WHERE v.tid = '{$info['id']}'
GROUP BY v.id
ORDER BY v.id
");
if ($db->num_rows($vresult) > 0) {
// Collect and cache data for a single query instead of multiple
while ($row = $db->fetch_assoc($vresult)) {
$vote['entries'][$row['id']] = $row;
$vote['voter'][$row['id']] = array();
$vote['count'] += $row['votes'];
}
// Now get more data (for what the users voted exactly)
$sql_aid_in = implode(',', array_keys($vote['entries']));
$vresult = $db->query("SELECT mid, aid FROM {$db->pre}votes WHERE aid IN({$sql_aid_in})");
while ($row = $db->fetch_assoc($vresult)) {
// Save the data for the member who is calling this page
if ($row['mid'] == $my->id) {
if ($config['vote_change'] != 1 || ($config['vote_change'] == 1 && $_GET['temp'] != 2)) {
$vote['results'] = true;
}
$vote['voted'] = $row['aid'];
}
// Create element in array with name (+ member id as key) at the selected answer
$vote['voter'][$row['aid']][$row['mid']] = $memberdata[$row['mid']];
}
if ($vote['results'] == false) {
// When we only show the form to submit/change a vote
($code = $plugins->load('showtopic_vote_prepared')) ? eval($code) : null;
$inner['vote_result'] = $tpl->parse("showtopic/vote");
}
else {
// Show the results
foreach ($vote['entries'] as $key => $row) {
if ($row['votes'] > 0) {
$row['percent'] = $row['votes'] / $vote['count'] * 100;
$row['percent_str'] = numbers($row['percent'], 1);
}
else {
$row['percent'] = 0;
$row['percent_str'] = "0";
}
$vote['entries'][$key] = $row;
// Make comma separated string from array of users
// Keys: (0 = Voter separated by comma, 1,2,3,... = Voter name with id as key)
if (count($vote['voter'][$row['id']]) > 0) {
$vote['voter'][$row['id']][0] = implode(', ', $vote['voter'][$row['id']]);
}
else {
$vote['voter'][$row['id']][0] = '-';
}
}
if ($my->vlogin && $my->p['voting'] == 1 && $info['status'] == 0) {
$vote['phrase'] = iif($vote['voted'] > 0, 'vote_change_option', 'vote_go_form');
}
($code = $plugins->load('showtopic_vote_result_prepared')) ? eval($code) : null;
$inner['vote_result'] = $tpl->parse("showtopic/vote_result");
}
}
}
if ($config['tpcallow'] == 1) {
$result = $db->query("SELECT id, tid, mid, file, source, hits FROM {$db->pre}uploads WHERE topic_id = '{$info['id']}'");
$uploads = array();
while ($row = $db->fetch_assoc($result)) {
$uploads[$row['tid']][] = $row;
}
if (count($uploads) > 0) {
$fileicons_obj = $scache->load('fileicons');
$fileicons = $fileicons_obj->get();
}
}
if ($config['postrating'] == 1) {
$result = $db->query("SELECT pid, mid, rating FROM {$db->pre}postratings WHERE tid = '{$info['id']}'");
$ratings = array();
while ($row = $db->fetch_assoc($result)) {
if (!isset($ratings[$row['pid']])) {
$ratings[$row['pid']] = array();
}
$ratings[$row['pid']][$row['mid']] = $row['rating'];
}
}
// Speed up the first pages with less than 10 posts
if ($speeder > $last['topiczahl']) {
$sql_limit = " LIMIT {$start},{$last['topiczahl']}";
}
else {
$sql_limit = " LIMIT {$speeder}";
}
$sql_select = iif($config['post_user_status'] == 1, ", IF (s.mid > 0, 1, 0) AS online");
$sql_join = iif($config['post_user_status'] == 1, "LEFT JOIN {$db->pre}session AS s ON s.mid = u.id");
$sql_order = iif($last['post_order'] == 1, 'DESC', 'ASC');
($code = $plugins->load('showtopic_query')) ? eval($code) : null;
$result = $db->query("
SELECT
r.id, r.edit, r.dosmileys, r.dowords, r.topic, r.comment, r.date, r.email as gmail, r.guest, r.name as gname, r.report, r.tstart,
u.id as mid, u.name as uname, u.mail, u.regdate, u.posts, u.fullname, u.hp, u.signature, u.location, u.gender, u.birthday, u.pic, u.lastvisit, u.jabber, u.skype, u.groups,
f.* {$sql_select}
FROM {$db->pre}replies AS r
LEFT JOIN {$db->pre}user AS u ON r.name = u.id AND r.guest = '0'
LEFT JOIN {$db->pre}userfields AS f ON u.id = f.ufid AND r.guest = '0'
{$sql_join}
WHERE r.topic_id = '{$info['id']}'
ORDER BY date {$sql_order}
{$sql_limit}
");
if ($last['post_order'] == 1) {
list($firstnew_id) = $db->fetch_num($db->query("SELECT id FROM {$db->pre}replies WHERE topic_id = '{$info['id']}' AND date > '{$my->clv}'"));
}
$firstnew = 0;
$firstnew_url = null;
if ($info['last'] >= $my->clv) {
$firstnew_url = 'showtopic.php?action=firstnew&id='.$info['id'].$qUrl2.SID2URL_x;
}
// Custom Profile Fields
include_once('classes/class.profilefields.php');
$pfields = new ProfileFieldViewer();
$rel_post_num = $start;
while ($row = $db->fetch_object($result)) {
$inner['upload_box'] = '';
$inner['image_box'] = '';
$row = $slog->cleanUserData($row);
$rel_post_num++;
$row->rel_post_num = $rel_post_num;
if ($row->guest == 0) {
$row->mail = '';
$row->name = $row->uname;
}
else {
$row->mail = $row->gmail;
$row->name = $row->gname;
$row->groups = GROUP_GUEST;
$row->mid = 0;
}
// Custom Profile Fields
$pfields->setUserId($row->mid);
$pfields->setUserData($row);
if ($firstnew > 0) {
$firstnew++;
}
if (($last['post_order'] == 0 && $row->date >= $my->clv && $firstnew == 0) ||
($last['post_order'] == 1 && !empty($firstnew_id) && $row->id == $firstnew_id)) {
$firstnew = 1;
$firstnew_url = "#firstnew";
}
$diff = time()-$row->date;
if ($config['edit_edit_time'] == 0) {
$edit_seconds = $diff;
}
else {
$edit_seconds = $config['edit_edit_time']*60;
}
$can_edit = ((($row->mid == $my->id && $row->guest == 0 && $edit_seconds >= $diff) || $my->mp[0] == 1) && $my->p['edit'] == 1 && $last['readonly'] == 0 && !($info['status'] != 0 && $my->mp[0] != 1));
$new = iif($row->date >= $my->clv, 'new', 'old');
BBProfile($bbcode);
$bbcode->setSmileys($row->dosmileys);
if ($config['wordstatus'] == 0) {
$row->dowords = 0;
}
$bbcode->setReplace($row->dowords);
$bbcode->setAuthor($row->mid);
if ($info['status'] == 2) {
$row->comment = $bbcode->ReplaceTextOnce($row->comment, 'moved');
}
$row->comment = $bbcode->parse($row->comment);
if ($my->opt_showsig == 1) {
BBProfile($bbcode, 'signature');
$row->signature = $bbcode->parse($row->signature);
}
if ($config['post_user_status'] == 1) {
$row->lang_online = $lang->phrase('profile_'.iif($row->online == 1, 'online', 'offline'));
}
$row->date = str_date($lang->phrase('dformat1'), times($row->date));
$row->regdate = gmdate($lang->phrase('dformat2'), times($row->regdate));
$row->level = $slog->getStatus($row->groups, ', ');
if (empty($row->location)) {
$row->location = $lang->phrase('showtopic_na');
}
if ((!empty($row->fullname) && $config['fullname_posts'] == 1) || (!empty($row->signature) && $my->opt_showsig == 1)) {
$bottom = true;
}
else {
$bottom = false;
}
if (isset($uploads[$row->id]) && $config['tpcallow'] == 1) {
foreach ($uploads[$row->id] as $file) {
$uppath = 'uploads/topics/'.$file['source'];
$imginfo = get_extension($uppath);
if (!isset($fileicons[$imginfo])) {
$icon = 'unknown';
}
else {
$icon = $fileicons[$imginfo];
}
// Dateigroesse
$fsize = filesize($uppath);
$fsize = formatFilesize($fsize);
$is_img = ($imginfo == 'gif' || $imginfo == 'jpg' || $imginfo == 'jpeg' || $imginfo == 'jpe' || $imginfo == 'png') ? true : false;
($code = $plugins->load('showtopic_attachments_prepared')) ? eval($code) : null;
if ($is_img == true) {
$imagesize = getimagesize($uppath);
$inner['image_box'] .= $tpl->parse("showtopic/image_box");
}
else {
$inner['upload_box'] .= $tpl->parse("showtopic/upload_box");
}
}
}
$edit = array();
if (!empty($row->edit)) {
preg_match_all('~^([^\t]+)\t(\d+)\t([^\t]*)\t([\d\.]+)$~m', $row->edit, $edits, PREG_SET_ORDER);
BBProfile($bbcode);
foreach ($edits as $e) {
$edit[] = array(
$e[1],
gmdate($lang->phrase('dformat1'), times($e[2])),
empty($e[3]) ? $lang->phrase('post_editinfo_na') : $bbcode->wordwrap($e[3]),
empty($e[4]) ? '-' : $e[4]
);
}
$anz = count($edit);
if ($anz == 0) {
$row->edit = null;
}
$lastdata = end($edit);
if ($lastdata != false) {
list(, $date, $why, ) = $lastdata;
}
}
// Ratings
$showrating = false;
$row->rating = 50;
$ratingcounter = 0;
if ($config['postrating'] == 1) {
if (!isset($ratings[$row->id])) {
$ratings[$row->id] = array();
}
if ($my->vlogin && $my->id != $row->mid && !isset($ratings[$row->id][$my->id])) {
$showrating = true;
}
$ratingcounter = count($ratings[$row->id]);
if (count($ratings[$row->id]) > 0) {
$row->rating = round(array_sum($ratings[$row->id])/$ratingcounter*50)+50;
}
}
($code = $plugins->load('showtopic_entry_prepared')) ? eval($code) : null;
$inner['index_bit'][] = $tpl->parse("showtopic/index_bit");
($code = $plugins->load('showtopic_entry_added')) ? eval($code) : null;
}
if ($my->vlogin && is_id($info['id'])) {
$result = $db->query("SELECT id, type FROM {$db->pre}abos WHERE mid = '{$my->id}' AND tid = '{$info['id']}'");
$abox = $db->fetch_assoc($result);
}
if (empty($abox)) {
$abox = array('id' => null, 'type' => null);
}
$inner['index_bit'] = implode('', $inner['index_bit']);
($code = $plugins->load('showtopic_prepared')) ? eval($code) : null;
echo $tpl->parse("showtopic/index");
$slog->setTopicRead($info['id'], $topforums);
($code = $plugins->load('showtopic_end')) ? eval($code) : null;
$slog->updatelogged();
$zeitmessung = t2();
echo $tpl->parse("footer");
$phpdoc->Out();
$db->close();
?>