Subversion Repositories Applications.papyrus

Rev

Rev 1371 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 1
<?php
2
 
3
////////////////////////////////////////////////////////////////////////////////
4
//                                                                            //
5
//   Copyright (C) 2006  Phorum Development Team                              //
6
//   http://www.phorum.org                                                    //
7
//                                                                            //
8
//   This program is free software. You can redistribute it and/or modify     //
9
//   it under the terms of either the current Phorum License (viewable at     //
10
//   phorum.org) or the Phorum License that was distributed with this file    //
11
//                                                                            //
12
//   This program is distributed in the hope that it will be useful,          //
13
//   but WITHOUT ANY WARRANTY, without even the implied warranty of           //
14
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     //
15
//                                                                            //
16
//   You should have received a copy of the Phorum License                    //
17
//   along with this program.                                                 //
18
////////////////////////////////////////////////////////////////////////////////
19
define('phorum_page','read');
20
 
21
include_once("./common.php");
22
include_once("./include/email_functions.php");
23
include_once("./include/format_functions.php");
24
 
25
 
26
// set all our URL's ... we need these earlier
27
phorum_build_common_urls();
28
 
29
// checking read-permissions
30
if(!phorum_check_read_common()) {
31
  return;
32
}
33
 
34
// somehow we got to a folder
35
if(empty($PHORUM["forum_id"]) || $PHORUM["folder_flag"]){
36
    $dest_url = phorum_get_url(PHORUM_INDEX_URL, $PHORUM["forum_id"]);
37
    phorum_redirect_by_url($dest_url);
38
    exit();
39
}
40
 
41
if ($PHORUM["DATA"]["LOGGEDIN"]) { // reading newflags in
42
    $PHORUM['user']['newinfo']=phorum_db_newflag_get_flags();
43
}
44
 
45
$PHORUM["DATA"]["MODERATOR"] = phorum_user_access_allowed(PHORUM_USER_ALLOW_MODERATE_MESSAGES);
46
 
47
if($PHORUM["DATA"]["MODERATOR"]) {
48
        // find out how many forums this user can moderate
49
        $forums=phorum_db_get_forums(0,-1,$PHORUM['vroot']);
50
 
51
        $modforums=0;
52
        foreach($forums as $id=>$forum){
53
                if($forum["folder_flag"]==0 && phorum_user_moderate_allowed($id)){
54
                   $modforums++;
55
                }
56
        }
57
        if($modforums > 1) {
58
                $build_move_url=true;
59
        } else {
60
                $build_move_url=false;
61
        }
62
}
63
 
64
// setup some stuff based on the url passed
65
if(empty($PHORUM["args"][1])) {
66
    phorum_redirect_by_url(phorum_get_url(PHORUM_LIST_URL));
67
    exit();
68
} elseif(empty($PHORUM["args"][2])) {
69
    $thread = (int)$PHORUM["args"][1];
70
    $message_id = (int)$PHORUM["args"][1];
71
} else{
72
    if(!is_numeric($PHORUM["args"][2])) {
73
        $dest_url="";
74
        $newervar=(int)$PHORUM["args"][1];
75
 
76
        switch($PHORUM["args"][2]) {
77
            case "newer":
78
                $thread = phorum_db_get_newer_thread($newervar);
79
                break;
80
            case "older":
81
                $thread = phorum_db_get_older_thread($newervar);
82
                break;
83
            case "markthreadread":
84
                // thread needs to be in $thread for the redirection
85
                $thread = (int)$PHORUM["args"][1];
86
                $thread_message=phorum_db_get_message($thread,'message_id');
87
 
88
                $mids=array();
89
                foreach($thread_message['meta']['message_ids'] as $mid) {
90
                    if(!isset($PHORUM['user']['newinfo'][$mid]) && $mid > $PHORUM['user']['newinfo']['min_id']) {
91
                        $mids[]=$mid;
92
                    }
93
                }
94
 
95
                $msg_count=count($mids);
96
 
97
                // any messages left to update newinfo with?
98
                if($msg_count > 0){
99
                    phorum_db_newflag_add_read($mids);
100
                    unset($mids);
101
                }
102
                break;
103
            case "gotonewpost":
104
                // thread needs to be in $thread for the redirection
105
                $thread = (int)$PHORUM["args"][1];
106
                $thread_message=phorum_db_get_message($thread,'message_id');
107
                $message_ids=$thread_message['meta']['message_ids'];
108
 
109
                foreach($message_ids as $mkey => $mid) {
110
                	// if already read, remove it from message-array
111
                	if(isset($PHORUM['user']['newinfo'][$mid]) || $mid <= $PHORUM['user']['newinfo']['min_id']) {
112
                		unset($message_ids[$mkey]);
113
                	}
114
 
115
                }
116
 
117
                // it could happen that they are all read
118
                if(count($message_ids)) {
119
                    asort($message_ids,SORT_NUMERIC); // make sure they are sorted
120
 
121
 
122
                    $new_message=array_shift($message_ids); // get the first element
123
 
124
                    if(!$PHORUM['threaded_read']) { // get new page
125
                        $new_page=ceil(phorum_db_get_message_index($thread,$new_message)/$PHORUM['read_length']);
126
                        $dest_url=phorum_get_url(PHORUM_READ_URL,$thread,$new_message,"page=$new_page");
127
                    } else { // for threaded
128
                        $dest_url=phorum_get_url(PHORUM_READ_URL,$thread,$new_message);
129
                    }
130
                } else {
131
                    // lets go back to the index if they are all read
132
                    $dest_url=phorum_get_url(PHORUM_LIST_URL);
133
                }
134
 
135
                break;
136
 
137
 
138
        }
139
 
140
        if(empty($dest_url)) {
141
            if($thread > 0) {
142
                $dest_url = phorum_get_url(PHORUM_READ_URL, $thread);
143
            } else{
144
                // we are either at the top or the bottom, go back to the list.
145
                $dest_url = phorum_get_url(PHORUM_LIST_URL);
146
            }
147
        }
148
 
149
        phorum_redirect_by_url($dest_url);
150
        exit();
151
    }
152
 
153
    $thread = (int)$PHORUM["args"][1];
154
    $message_id = (int)$PHORUM["args"][2];
155
}
156
 
157
// determining the page if page isn't given and message_id != thread
158
$page=0;
159
if(!$PHORUM["threaded_read"]) {
160
    if(isset($PHORUM['args']['page']) && is_numeric($PHORUM["args"]["page"]) && $PHORUM["args"]["page"] > 0) {
161
                $page=(int)$PHORUM["args"]["page"];
162
    } elseif($message_id != $thread) {
163
                $page=ceil(phorum_db_get_message_index($thread,$message_id)/$PHORUM['read_length']);
164
    } else {
165
                $page=1;
166
    }
167
    if(empty($page)) {
168
        $page=1;
169
    }
170
}
171
 
172
// Get the thread
173
$data = phorum_db_get_messages($thread,$page);
174
 
175
 
176
if(!empty($data) && isset($data[$thread]) && isset($data[$message_id])) {
177
 
178
    $fetch_user_ids = $data['users'];
179
    unset($data['users']);
180
 
181
    // remove the unneeded message bodies in threaded view
182
    // to avoid unnecessary formatting of bodies
183
    if ($PHORUM["threaded_read"] &&
184
        !(isset($PHORUM['TMP']['all_bodies_in_threaded_read']) &&
185
         !empty($PHORUM['TMP']['all_bodies_in_threaded_read']) ) ) {
186
 
187
            $remove_threaded_bodies=1;
188
            // the flag is used in the foreach-loop later on
189
    } else {
190
            $remove_threaded_bodies=0;
191
    }
192
 
193
    // build URL's that apply only here.
194
    if($PHORUM["float_to_top"]) {
195
        $PHORUM["DATA"]["URL"]["OLDERTHREAD"] = phorum_get_url(PHORUM_READ_URL, $data[$thread]["modifystamp"], "older");
196
        $PHORUM["DATA"]["URL"]["NEWERTHREAD"] = phorum_get_url(PHORUM_READ_URL, $data[$thread]["modifystamp"], "newer");
197
    } else{
198
        $PHORUM["DATA"]["URL"]["OLDERTHREAD"] = phorum_get_url(PHORUM_READ_URL, $thread, "older");
199
        $PHORUM["DATA"]["URL"]["NEWERTHREAD"] = phorum_get_url(PHORUM_READ_URL, $thread, "newer");
200
    }
201
 
202
    $PHORUM["DATA"]["URL"]["MARKTHREADREAD"] = phorum_get_url(PHORUM_READ_URL, $thread, "markthreadread");
203
    $PHORUM["DATA"]["POST"]["thread"] = $thread;
204
    $PHORUM["DATA"]["POST"]["parentid"] = $message_id;
205
    $PHORUM["DATA"]["POST"]["subject"] = $data[$message_id]["subject"];
206
 
207
    $thread_is_closed = (bool)$data[$thread]["closed"];
208
    $thread_is_announcement = ($data[$thread]["sort"]==PHORUM_SORT_ANNOUNCEMENT)?1:0;
209
 
210
    // we might have more messages for mods
211
    if($PHORUM["DATA"]["MODERATOR"] && isset($data[$thread]["meta"]["message_ids_moderator"])) {
212
        $threadnum=count($data[$thread]['meta']['message_ids_moderator']);
213
    } else {
214
        $threadnum=$data[$thread]['thread_count'];
215
    }
216
 
217
    if(!$PHORUM["threaded_read"] && $threadnum > $PHORUM["read_length"]){
218
        $pages=ceil($threadnum/$PHORUM["read_length"]);
219
 
220
        if($pages<=11){
221
            $page_start=1;
222
        } elseif($pages-$page<5) {
223
            $page_start=$pages-10;
224
        } elseif($pages>11 && $page>6){
225
            $page_start=$page-5;
226
        } else {
227
            $page_start=1;
228
        }
229
 
230
        for($x=0;$x<11 && $x<$pages;$x++){
231
            $pageno=$x+$page_start;
232
            $PHORUM["DATA"]["PAGES"][] = array(
233
            "pageno"=>$pageno,
234
            "url"=>phorum_get_url(PHORUM_READ_URL, $thread, "page=$pageno")
235
            );
236
        }
237
 
238
        $PHORUM["DATA"]["CURRENTPAGE"]=$page;
239
        $PHORUM["DATA"]["TOTALPAGES"]=$pages;
240
 
241
        if($page_start>1){
242
            $PHORUM["DATA"]["URL"]["FIRSTPAGE"]=phorum_get_url(PHORUM_READ_URL, $thread, "page=1");
243
        }
244
 
245
        if($pageno<$pages){
246
            $PHORUM["DATA"]["URL"]["LASTPAGE"]=phorum_get_url(PHORUM_READ_URL, $thread, "page=$pages");
247
        }
248
 
249
        if($pages>$page){
250
            $nextpage=$page+1;
251
            $PHORUM["DATA"]["URL"]["NEXTPAGE"]=phorum_get_url(PHORUM_READ_URL, $thread, "page=$nextpage");
252
        }
253
        if($page>1){
254
            $prevpage=$page-1;
255
            $PHORUM["DATA"]["URL"]["PREVPAGE"]=phorum_get_url(PHORUM_READ_URL, $thread, "page=$prevpage");
256
        }
257
    }
258
 
259
    // fetch_user_ids filled from phorum_db_get_messages
260
    if(isset($fetch_user_ids) && count($fetch_user_ids)){
261
        $user_info=phorum_user_get($fetch_user_ids, false);
262
        // hook to modify user info
263
        $user_info = phorum_hook("read_user_info", $user_info);
264
    }
265
 
266
    // URLS which are common for the thread
267
    if($PHORUM["DATA"]["MODERATOR"]) {
268
        if($build_move_url) {
269
                $URLS["move_url"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_MOVE_THREAD, $thread);
270
        }
271
        $URLS["merge_url"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_MERGE_THREAD, $thread);
272
        $URLS["close_url"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_CLOSE_THREAD, $thread);
273
        $URLS["reopen_url"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_REOPEN_THREAD, $thread);
274
    }
275
 
276
 
277
 
278
 
279
    // main loop for template setup
280
    $read_messages=array(); // needed for newinfo
281
    foreach($data as $key => $row) {
282
 
283
        // should we remove the bodies in threaded view
284
        if($remove_threaded_bodies) {
285
            if ($row["message_id"] != $message_id) {
286
                unset($row["body"]); // strip body
287
            }
288
        }
289
 
290
        // assign user data to the row
291
        if($row["user_id"] && isset($user_info[$row["user_id"]])){
292
            $row["user"]=$user_info[$row["user_id"]];
293
            unset($row["user"]["password"]);
294
            unset($row["user"]["password_tmp"]);
295
        }
296
        if(!$PHORUM["threaded_read"] && $PHORUM["DATA"]["LOGGEDIN"] && $row['message_id'] > $PHORUM['user']['newinfo']['min_id'] && !isset($PHORUM['user']['newinfo'][$row['message_id']])) { // set this message as read
297
            $read_messages[] = array("id"=>$row['message_id'],"forum"=>$row['forum_id']);
298
        }
299
        // is the message unapproved?
300
        $row["is_unapproved"] = ($row['status'] < 0) ? 1 : 0;
301
 
302
        // all stuff that makes only sense for moderators or admin
303
        if($PHORUM["DATA"]["MODERATOR"]) {
304
 
305
            $row["delete_url1"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_DELETE_MESSAGE, $row["message_id"]);
306
            $row["delete_url2"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_DELETE_TREE, $row["message_id"]);
307
            $row["edit_url"]=phorum_get_url(PHORUM_POSTING_URL, "moderation", $row["message_id"]);
308
            $row["split_url"]=phorum_get_url(PHORUM_MODERATION_URL, PHORUM_SPLIT_THREAD, $row["message_id"]);
309
            if($row['is_unapproved']) {
310
              $row["approve_url"]=phorum_get_url(PHORUM_MODERATION_URL, PHORUM_APPROVE_MESSAGE, $row["message_id"]);
311
            } else {
312
              $row["hide_url"]=phorum_get_url(PHORUM_MODERATION_URL, PHORUM_HIDE_POST, $row["message_id"]);
313
            }
314
            if($build_move_url) {
315
                $row["move_url"] = $URLS["move_url"];
316
            }
317
            $row["merge_url"] = $URLS["merge_url"];
318
            $row["close_url"] = $URLS["close_url"];
319
            $row["reopen_url"] = $URLS["reopen_url"];
320
        }
321
 
322
        // allow editing only if logged in, allowed for forum, the thread is open,
323
        // its the same user, and its within the time restriction
324
        if($PHORUM["user"]["user_id"]==$row["user_id"] && phorum_user_access_allowed(PHORUM_USER_ALLOW_EDIT) &&
325
            !$thread_is_closed &&($PHORUM["user_edit_timelimit"] == 0 || $row["datestamp"] + ($PHORUM["user_edit_timelimit"] * 60) >= time())) {
326
            $row["edit"]=1;
327
            if($PHORUM["DATA"]["MODERATOR"]) {
328
                $row["edituser_url"]=$row["edit_url"];
329
            } else {
330
                $row["edituser_url"]=phorum_get_url(PHORUM_POSTING_URL, "edit", $row["message_id"]);
331
            }
332
        }
333
 
334
        // this stuff is used in threaded and non threaded.
335
        $row["short_datestamp"] = phorum_date($PHORUM["short_date"], $row["datestamp"]);
336
        $row["datestamp"] = phorum_date($PHORUM["long_date"], $row["datestamp"]);
337
        $row["url"] = phorum_get_url(PHORUM_READ_URL, $row["thread"], $row["message_id"]);
338
        $row["reply_url"] = phorum_get_url(PHORUM_REPLY_URL, $row["thread"], $row["message_id"]);
339
        $row["quote_url"] = phorum_get_url(PHORUM_REPLY_URL, $row["thread"], $row["message_id"], "quote=1");
340
        $row["report_url"] = phorum_get_url(PHORUM_REPORT_URL, $row["message_id"]);
341
        $row["follow_url"] = phorum_get_url(PHORUM_FOLLOW_URL, $row["thread"]);
342
 
343
        // can only send private replies if the author is a registered user
344
        if ($PHORUM["enable_pm"] && $row["user_id"]) {
345
            $row["private_reply_url"] = phorum_get_url(PHORUM_PM_URL, "page=send", "message_id=".$row["message_id"]);
346
        } else {
347
            $row["private_reply_url"] = false;
348
        }
349
 
350
        // check if its the first message in the thread
351
        if($row["message_id"] == $row["thread"]) {
352
            $row["threadstart"] = true;
353
        } else{
354
            $row["threadstart"] = false;
355
        }
356
 
357
        // should we show the signature?
358
        if(isset($row['body'])) {
359
            if(isset($row["user"]["signature"])
360
               && isset($row['meta']['show_signature']) && $row['meta']['show_signature']==1){
361
 
362
                   $phorum_sig=trim($row["user"]["signature"]);
363
                   if(!empty($phorum_sig)){
364
                       $row["body"].="\n\n$phorum_sig";
365
                   }
366
            }
367
 
368
            // add the edited-message to a post if its edited
369
            if(isset($row['meta']['edit_count']) && $row['meta']['edit_count'] > 0) {
370
                $editmessage = str_replace ("%count%", $row['meta']['edit_count'], $PHORUM["DATA"]["LANG"]["EditedMessage"]);
371
                $editmessage = str_replace ("%lastedit%", phorum_date($PHORUM["short_date"],$row['meta']['edit_date']),  $editmessage);
372
                $editmessage = str_replace ("%lastuser%", $row['meta']['edit_username'],  $editmessage);
373
                $row["body"].="\n\n\n\n$editmessage";
374
            }
375
        }
376
 
377
 
378
        if(!empty($row["user_id"])) {
379
            $row["profile_url"] = phorum_get_url(PHORUM_PROFILE_URL, $row["user_id"]);
380
            // we don't normally put HTML in this code, but this makes it easier on template builders
381
            $row["linked_author"] = "<a href=\"".$row["profile_url"]."\">$row[author]</a>";
382
        } elseif(!empty($row["email"])) {
383
            $row["email_url"] = phorum_html_encode("mailto:$row[email]");
384
            // we don't normally put HTML in this code, but this makes it easier on template builders
385
            $row["linked_author"] = "<a href=\"".$row["email_url"]."\">".htmlspecialchars($row["author"])."</a>";
386
        } else {
387
            $row["linked_author"] = htmlspecialchars($row["author"]);
388
        }
389
 
390
        // mask host if not a moderator
391
        if(empty($PHORUM["user"]["admin"]) && (empty($PHORUM["DATA"]["MODERATOR"]) || !PHORUM_MOD_IP_VIEW)){
392
            if($PHORUM["display_ip_address"]){
393
                if($row["moderator_post"]){
394
                    $row["ip"]=$PHORUM["DATA"]["LANG"]["Moderator"];
395
                } elseif(is_numeric(str_replace(".", "", $row["ip"]))){
396
                    $row["ip"]=substr($row["ip"],0,strrpos($row["ip"],'.')).'.---';
397
                } else {
398
                    $row["ip"]="---".strstr($row["ip"], ".");
399
                }
400
 
401
            } else {
402
                $row["ip"]=$PHORUM["DATA"]["LANG"]["IPLogged"];
403
            }
404
        }
405
 
406
        if($PHORUM["max_attachments"]>0 && isset($row["meta"]["attachments"])){
407
            $PHORUM["DATA"]["ATTACHMENTS"]=true;
408
            $row["attachments"]=$row["meta"]["attachments"];
409
            // unset($row["meta"]["attachments"]);
410
            foreach($row["attachments"] as $key=>$file){
411
                $row["attachments"][$key]["size"]=phorum_filesize($file["size"]);
412
                $row["attachments"][$key]["name"]=htmlentities($file['name'], ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]); // clear all special chars from name to avoid XSS
413
                $row["attachments"][$key]["url"]=phorum_get_url(PHORUM_FILE_URL, "file={$file['file_id']}");
414
            }
415
        }
416
 
417
        // newflag, if its NOT in newinfo AND newer than min_id, then its a new message
418
        $row["new"]="";
419
        if ($PHORUM["DATA"]["LOGGEDIN"]){
420
            if (!isset($PHORUM['user']['newinfo'][$row['message_id']]) && $row['message_id'] > $PHORUM['user']['newinfo']['min_id']) {
421
                $row["new"]= $PHORUM["DATA"]["LANG"]["newflag"];
422
            }
423
        }
424
 
425
        $messages[$row["message_id"]]=$row;
426
    }
427
 
428
    if($PHORUM["threaded_read"]) {
429
        // don't move this up.  We want it to be conditional.
430
        include_once("./include/thread_sort.php");
431
 
432
        // run read-threads mods
433
        $messages = phorum_hook("readthreads", $messages);
434
 
435
        $messages = phorum_sort_threads($messages);
436
 
437
        if($PHORUM["DATA"]["LOGGEDIN"] && !isset($PHORUM['user']['newinfo'][$message_id]) && $message_id > $PHORUM['user']['newinfo']['min_id']) {
438
            $read_messages[] = array("id"=>$message_id,"forum"=>$messages[$message_id]['forum_id']);
439
        }
440
 
441
        // we have to loop again and create the urls for the Next and Previous links.
442
        foreach($messages as $key => $row) {
443
 
444
            if($PHORUM["count_views"]) {  // show viewcount if enabled
445
                  if($PHORUM["count_views"] == 2) { // viewcount as column
446
                      $PHORUM["DATA"]["VIEWCOUNT_COLUMN"]=true;
447
                      $messages[$key]["viewcount"]=$row['viewcount'];
448
                  } else { // viewcount added to the subject
449
                      $messages[$key]["subject"]=$row["subject"]." ({$row['viewcount']} {$PHORUM['DATA']['LANG']['Views']})";
450
                  }
451
            }
452
 
453
 
454
            $messages[$key]["next_url"] = $PHORUM["DATA"]["URL"]["NEWERTHREAD"];
455
            if(empty($last_key)) {
456
                $messages[$key]["prev_url"] = $PHORUM["DATA"]["URL"]["OLDERTHREAD"];
457
            } else{
458
                $messages[$key]["prev_url"] = phorum_get_url(PHORUM_READ_URL, $row["thread"], $last_key);
459
                $messages[$last_key]["next_url"] = phorum_get_url(PHORUM_READ_URL, $row["thread"], $row["message_id"]);
460
            }
461
 
462
            $last_key = $key;
463
        }
464
    }
465
 
466
    // run read mods
467
    $messages = phorum_hook("read", $messages);
468
 
469
    // increment viewcount if enabled
470
    if($PHORUM['count_views']) {
471
        phorum_db_viewcount_inc($message_id);
472
    }
473
 
474
    // format messages
475
    $messages = phorum_format_messages($messages);
476
 
477
    // set up the data
478
    $PHORUM["DATA"]["MESSAGE"] = $messages[$message_id];
479
 
480
    // we need to remove the thread-starter from the data if we are not on the first page
481
    $threadsubject = $messages[$thread]["subject"];
482
    if($page > 1)
483
        unset($messages[$thread]);
484
 
485
    $PHORUM["DATA"]["MESSAGES"] = $messages;
486
 
487
 
488
    // alter the HTML_TITLE
489
    if(!empty($PHORUM["DATA"]["HTML_TITLE"])){
490
        $PHORUM["DATA"]["HTML_TITLE"].=htmlentities(PHORUM_SEPARATOR, ENT_COMPAT, $PHORUM["DATA"]["CHARSET"] );;
491
    }
492
    // No htmlentities() needed. The subject is already escaped.
493
    // Strip HTML tags from the HTML title. There might be HTML in
494
    // here, because of modules adding images and formatting.
495
    $PHORUM["DATA"]["HTML_TITLE"] .= trim(strip_tags($PHORUM["threaded_read"] ? $PHORUM["DATA"]["MESSAGE"]["subject"] : $threadsubject));
496
 
497
    // include the correct template
498
 
499
    include phorum_get_template("header");
500
    phorum_hook("after_header");
501
 
502
    if($PHORUM["threaded_read"]) {
503
        include phorum_get_template("read_threads");
504
    } else{
505
        include phorum_get_template("read");
506
    }
507
    if($PHORUM["DATA"]["LOGGEDIN"]) { // setting read messages really read
508
        phorum_db_newflag_add_read($read_messages);
509
    }
510
 
511
    // An anchor so clicking on a reply button can let the browser
512
    // jump to the editor or the closed thread message.
513
    if(isset($PHORUM["reply_on_read_page"]) && $PHORUM["reply_on_read_page"]) {
514
        print '<a name="REPLY"></a>';
515
    }
516
 
517
    // Never show the reply box if the message is closed.
518
    if($thread_is_closed) {
519
 
520
        // Closed announcements have their own specific message.
521
        $key = $thread_is_announcement ? "ThreadAnnouncement" : "ThreadClosed";
522
        $PHORUM["DATA"]["MESSAGE"]=$PHORUM["DATA"]["LANG"][$key];
523
        include phorum_get_template("message");
524
 
525
    } elseif (isset($PHORUM["reply_on_read_page"]) && $PHORUM["reply_on_read_page"]) {
526
 
527
        // Prepare the arguments for the posting.php script.
528
        $goto_mode = "reply";
529
        if (isset($PHORUM["args"]["quote"]) && $PHORUM["args"]["quote"]) {
530
            $goto_mode = "quote";
531
        }
532
 
533
        $PHORUM["postingargs"] = array(
534
            1 => $goto_mode,
535
            2 => $message_id,
536
            "as_include" => true
537
        );
538
 
539
        include("./posting.php");
540
    }
541
 
542
    phorum_hook("before_footer");
543
    include phorum_get_template("footer");
544
 
545
 
546
} elseif($toforum=phorum_check_moved_message($thread)) { // is it a moved thread?
547
 
548
    $PHORUM["DATA"]["MESSAGE"]=$PHORUM["DATA"]["LANG"]["MovedMessage"];
549
    $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_FOREIGN_READ_URL, $toforum, $thread);
550
    $PHORUM['DATA']["BACKMSG"]=$PHORUM["DATA"]["LANG"]["MovedMessageTo"];
551
 
552
    $PHORUM["DATA"]["HTML_TITLE"] = htmlentities( $PHORUM["DATA"]["HTML_TITLE"], ENT_COMPAT, $PHORUM["DATA"]["CHARSET"] );
553
    // have to include the header here for the Redirect
554
    include phorum_get_template("header");
555
    phorum_hook("after_header");
556
    include phorum_get_template("message");
557
    phorum_hook("before_footer");
558
    include phorum_get_template("footer");
559
 
560
} else { // message not found
561
    $PHORUM["DATA"]["ERROR"]=$PHORUM["DATA"]["LANG"]["MessageNotFound"];
562
    $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
563
    $PHORUM['DATA']["BACKMSG"]=$PHORUM["DATA"]["LANG"]["BackToList"];
564
 
565
    $PHORUM["DATA"]["HTML_TITLE"] = htmlentities( $PHORUM["DATA"]["HTML_TITLE"], ENT_COMPAT, $PHORUM["DATA"]["CHARSET"] );
566
    // have to include the header here for the Redirect
567
    include phorum_get_template("header");
568
    phorum_hook("after_header");
569
    include phorum_get_template("message");
570
    phorum_hook("before_footer");
571
    include phorum_get_template("footer");
572
}
573
 
574
// find out if the given thread has been moved to another forum
575
function phorum_check_moved_message($thread) {
576
    $forum_id=$GLOBALS['PHORUM']['forum_id'];
577
    $message=phorum_db_get_message($thread,'message_id',true);
578
 
579
    if(!empty($message) && $message['forum_id'] != $forum_id) {
580
        $ret=$message['forum_id'];
581
    } else {
582
        $ret=false;
583
    }
584
    return $ret;
585
}
586
 
587
?>