Subversion Repositories Applications.papyrus

Rev

Details | 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','list');
20
 
21
include_once("./common.php");
22
include_once("./include/format_functions.php");
23
 
24
// set all our common URL's
25
phorum_build_common_urls();
26
 
27
if(!phorum_check_read_common()) {
28
  return;
29
}
30
 
31
 
32
if(empty($PHORUM["forum_id"])){
33
    $dest_url = phorum_get_url(PHORUM_INDEX_URL);
34
    phorum_redirect_by_url($dest_url);
35
    exit();
36
}
37
 
38
// somehow we got to a folder in list.php
39
if($PHORUM["folder_flag"]){
40
    $dest_url = phorum_get_url(PHORUM_INDEX_URL, $PHORUM["forum_id"]);
41
    phorum_redirect_by_url($dest_url);
42
    exit();
43
}
44
 
45
// check for markread
46
if (!empty($PHORUM["args"][1]) && $PHORUM["args"][1] == 'markread'){
47
    // setting all posts read
48
    unset($PHORUM['user']['newinfo']);
49
    phorum_db_newflag_allread();
50
 
51
    // redirect to a fresh list without markread in url
52
    $dest_url = phorum_get_url(PHORUM_LIST_URL);
53
    phorum_redirect_by_url($dest_url);
54
    exit();
55
 
56
}
57
 
58
if ($PHORUM["DATA"]["LOGGEDIN"]) { // reading newflags in
59
    $PHORUM['user']['newinfo']=phorum_db_newflag_get_flags();
60
}
61
 
62
// figure out what page we are on
63
if (empty($PHORUM["args"]["page"]) || !is_numeric($PHORUM["args"]["page"]) || $PHORUM["args"]["page"] < 0){
64
    $page=1;
65
} else {
66
    $page=intval($PHORUM["args"]["page"]);
67
}
68
$offset=$page-1;
69
 
70
// check the moderation-settings
71
$PHORUM["DATA"]["MODERATOR"] = phorum_user_access_allowed(PHORUM_USER_ALLOW_MODERATE_MESSAGES);
72
 
73
$build_move_url=false;
74
if($PHORUM["DATA"]["MODERATOR"]) {
75
    // find out how many forums this user can moderate
76
    $forums=phorum_db_get_forums(0,-1,$PHORUM['vroot']);
77
 
78
    $modforums=0;
79
    foreach($forums as $id=>$forum){
80
        if($forum["folder_flag"]==0 && phorum_user_moderate_allowed($id)){
81
            $modforums++;
82
        }
83
        if($modforums > 1) {
84
            $build_move_url=true;
85
            break;
86
        }
87
    }
88
}
89
// Get the threads
90
$rows = array();
91
 
92
// get the thread set started
93
$rows = phorum_db_get_thread_list($offset);
94
 
95
// redirect if invalid page
96
if(count($rows) < 1 && $offset > 0){
97
    $dest_url = phorum_get_url(PHORUM_LIST_URL);
98
    phorum_redirect_by_url($dest_url);
99
    exit();
100
}
101
 
102
if($PHORUM['threaded_list']) { // make it simpler :)
103
    $PHORUM["list_length"] = $PHORUM['list_length_threaded'];
104
} else {
105
    $PHORUM["list_length"] = $PHORUM['list_length_flat'];
106
}
107
 
108
// Figure out paging for threaded and flat mode. Sticky messages
109
// are in the thread_count, but because these are handled as a separate
110
// list (together with the announcements), they should not be included
111
// in the pages computation.
112
$pages=ceil(($PHORUM["thread_count"] - $PHORUM['sticky_count']) / $PHORUM["list_length"]);
113
 
114
// If we only have stickies and/of announcements, the number of pages
115
// will be zero. In that case, simply use one page.
116
if ($pages == 0) $pages = 1;
117
 
118
if($pages<=11){
119
    $page_start=1;
120
} elseif($pages-$page<5) {
121
    $page_start=$pages-10;
122
} elseif($pages>11 && $page>6){
123
    $page_start=$page-5;
124
} else {
125
    $page_start=1;
126
}
127
 
128
$pageno=1;
129
for($x=0;$x<11 && $x<$pages;$x++){
130
    $pageno=$x+$page_start;
131
    $PHORUM["DATA"]["PAGES"][] = array(
132
    "pageno"=>$pageno,
133
    "url"=>phorum_get_url(PHORUM_LIST_URL, $PHORUM["forum_id"], "page=$pageno")
134
    );
135
}
136
 
137
$PHORUM["DATA"]["CURRENTPAGE"]=$page;
138
$PHORUM["DATA"]["TOTALPAGES"]=$pages;
139
 
140
if($page_start>1){
141
    $PHORUM["DATA"]["URL"]["FIRSTPAGE"]=phorum_get_url(PHORUM_LIST_URL, $PHORUM["forum_id"], "page=1");
142
}
143
 
144
if($pageno<$pages){
145
    $PHORUM["DATA"]["URL"]["LASTPAGE"]=phorum_get_url(PHORUM_LIST_URL, $PHORUM["forum_id"], "page=$pages");
146
}
147
 
148
if($pages>$page){
149
    $nextpage=$page+1;
150
    $PHORUM["DATA"]["URL"]["NEXTPAGE"]=phorum_get_url(PHORUM_LIST_URL, $PHORUM["forum_id"], "page=$nextpage");
151
}
152
if($page>1){
153
    $prevpage=$page-1;
154
    $PHORUM["DATA"]["URL"]["PREVPAGE"]=phorum_get_url(PHORUM_LIST_URL, $PHORUM["forum_id"], "page=$prevpage");
155
}
156
 
157
$min_id=0;
158
if ($PHORUM["threaded_list"]){
159
 
160
    // loop through and read all the data in.
161
    foreach($rows as $key => $row){
162
 
163
        if($PHORUM["count_views"]) {  // show viewcount if enabled
164
              if($PHORUM["count_views"] == 2) { // viewcount as column
165
                  $PHORUM["DATA"]["VIEWCOUNT_COLUMN"]=true;
166
                  $rows[$key]["viewcount"]=$row['viewcount'];
167
              } else { // viewcount added to the subject
168
                  $rows[$key]["subject"]=$row["subject"]." ({$row['viewcount']} " . strtolower($PHORUM['DATA']['LANG']['Views']) . ")";
169
              }
170
        }
171
 
172
        $rows[$key]["datestamp"] = phorum_date($PHORUM["short_date"], $row["datestamp"]);
173
        $rows[$key]["lastpost"] = phorum_date($PHORUM["short_date"], $row["modifystamp"]);
174
        $rows[$key]["url"] = phorum_get_url(PHORUM_READ_URL, $row["thread"], $row["message_id"]);
175
 
176
        if($row["message_id"] == $row["thread"]){
177
            $rows[$key]["threadstart"] = true;
178
        }else{
179
            $rows[$key]["threadstart"] = false;
180
        }
181
 
182
        $rows[$key]["delete_url1"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_DELETE_MESSAGE, $row["message_id"]);
183
        $rows[$key]["delete_url2"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_DELETE_TREE, $row["message_id"]);
184
        if($build_move_url) {
185
                $rows[$key]["move_url"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_MOVE_THREAD, $row["message_id"]);
186
        }
187
        $rows[$key]["merge_url"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_MERGE_THREAD, $row["message_id"]);
188
 
189
        $rows[$key]["new"] = "";
190
        // recognizing moved threads
191
        if(isset($row['meta']['moved']) && $row['meta']['moved'] == 1) {
192
           $rows[$key]['moved']=1;
193
        } elseif ($PHORUM["DATA"]["LOGGEDIN"]){
194
 
195
            // newflag, if its NOT in newinfo AND newer (min than min_id,
196
            // then its a new message
197
 
198
            // newflag for collapsed special threads (sticky and announcement)
199
            if (($rows[$key]['sort'] == PHORUM_SORT_STICKY ||
200
                 $rows[$key]['sort'] == PHORUM_SORT_ANNOUNCEMENT) &&
201
                 isset($row['meta']['message_ids']) &&
202
                 is_array($row['meta']['message_ids'])) {
203
                foreach ($row['meta']['message_ids'] as $cur_id) {
204
                    if(!isset($PHORUM['user']['newinfo'][$cur_id]) && $cur_id > $PHORUM['user']['newinfo']['min_id'])
205
                        $rows[$key]["new"] = $PHORUM["DATA"]["LANG"]["newflag"];
206
                }
207
            }
208
            // newflag for regular messages
209
            else {
210
                if (!isset($PHORUM['user']['newinfo'][$row['message_id']]) && $row['message_id'] > $PHORUM['user']['newinfo']['min_id']) {
211
                    $rows[$key]["new"]=$PHORUM["DATA"]["LANG"]["newflag"];
212
                }
213
            }
214
        }
215
 
216
        if ($row["user_id"]){
217
            $url = phorum_get_url(PHORUM_PROFILE_URL, $row["user_id"]);
218
            $rows[$key]["profile_url"] = $url;
219
            $rows[$key]["linked_author"] = "<a href=\"$url\">".htmlspecialchars($row['author'])."</a>";
220
        }else{
221
            $rows[$key]["profile_url"] = "";
222
            if(!empty($row['email'])) {
223
                $email_url = phorum_html_encode("mailto:$row[email]");
224
                // we don't normally put HTML in this code, but this makes it easier on template builders
225
                $rows[$key]["linked_author"] = "<a href=\"".$email_url."\">".htmlspecialchars($row["author"])."</a>";
226
            } else {
227
                $rows[$key]["linked_author"] = htmlspecialchars($row["author"]);
228
            }
229
        }
230
        if($min_id == 0 || $min_id > $row['message_id'])
231
            $min_id = $row['message_id'];
232
    }
233
    // don't move this up.  We want it to be conditional.
234
    include_once("./include/thread_sort.php");
235
 
236
    $rows = phorum_sort_threads($rows);
237
 
238
}else{
239
 
240
    // loop through and read all the data in.
241
    foreach($rows as $key => $row){
242
 
243
        $rows[$key]["lastpost"] = phorum_date($PHORUM["short_date"], $row["modifystamp"]);
244
        $rows[$key]["datestamp"] = phorum_date($PHORUM["short_date"], $row["datestamp"]);
245
        $rows[$key]["url"] = phorum_get_url(PHORUM_READ_URL, $row["thread"]);
246
        $rows[$key]["newpost_url"] = phorum_get_url(PHORUM_READ_URL, $row["thread"],"gotonewpost");
247
 
248
        $rows[$key]["new"] = "";
249
 
250
        if($PHORUM["count_views"]) {  // show viewcount if enabled
251
              if($PHORUM["count_views"] == 2) { // viewcount as column
252
                  $PHORUM["DATA"]["VIEWCOUNT_COLUMN"]=true;
253
                  $rows[$key]["viewcount"]=$row['viewcount'];
254
              } else { // viewcount added to the subject
255
                  $rows[$key]["subject"]=$row["subject"]." ({$row['viewcount']} " . strtolower($PHORUM['DATA']['LANG']['Views']) . ")";
256
              }
257
        }
258
 
259
        // recognizing moved threads
260
        if(isset($row['meta']['moved']) && $row['meta']['moved'] == 1) {
261
           $rows[$key]['moved']=1;
262
        } else {
263
           $rows[$key]['moved']=0;
264
        }
265
 
266
        // default thread-count
267
        $thread_count=$row["thread_count"];
268
 
269
        if ($PHORUM["DATA"]["LOGGEDIN"]){
270
 
271
                    if($PHORUM["DATA"]["MODERATOR"]){
272
                        $rows[$key]["delete_url1"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_DELETE_MESSAGE, $row["message_id"]);
273
                        $rows[$key]["delete_url2"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_DELETE_TREE, $row["message_id"]);
274
                        if($build_move_url) {
275
                                $rows[$key]["move_url"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_MOVE_THREAD, $row["message_id"]);
276
                        }
277
                        $rows[$key]["merge_url"] = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_MERGE_THREAD, $row["message_id"]);
278
                        // count could be different with hidden or unapproved posts
279
                        if(!$PHORUM["threaded_read"] && isset($row["meta"]["message_ids_moderator"])) {
280
                                $thread_count=count($row["meta"]["message_ids_moderator"]);
281
                        }
282
                    }
283
 
284
                    if(!$rows[$key]['moved'] && isset($row['meta']['message_ids']) && is_array($row['meta']['message_ids'])) {
285
                        foreach ($row['meta']['message_ids'] as $cur_id) {
286
                            if(!isset($PHORUM['user']['newinfo'][$cur_id]) && $cur_id > $PHORUM['user']['newinfo']['min_id'])
287
                                $rows[$key]["new"] = $PHORUM["DATA"]["LANG"]["newflag"];
288
                        }
289
                    }
290
        }
291
 
292
        if ($row["user_id"]){
293
            $url = phorum_get_url(PHORUM_PROFILE_URL, $row["user_id"]);
294
            $rows[$key]["profile_url"] = $url;
295
            $rows[$key]["linked_author"] = "<a href=\"$url\">$row[author]</a>";
296
        }else{
297
            $rows[$key]["profile_url"] = "";
298
            if(!empty($row['email'])) {
299
                $email_url = phorum_html_encode("mailto:$row[email]");
300
                // we don't normally put HTML in this code, but this makes it easier on template builders
301
                $rows[$key]["linked_author"] = "<a href=\"".$email_url."\">".htmlspecialchars($row["author"])."</a>";
302
            } else {
303
                $rows[$key]["linked_author"] = $row["author"];
304
            }
305
        }
306
 
307
        $pages=1;
308
        // thread_count computed above in moderators-section
309
        if(!$PHORUM["threaded_read"] && $thread_count>$PHORUM["read_length"]){
310
 
311
            $pages=ceil($thread_count/$PHORUM["read_length"]);
312
 
313
            if($pages<=5){
314
                $page_links="";
315
                for($x=1;$x<=$pages;$x++){
316
                    $url=phorum_get_url(PHORUM_READ_URL, $row["thread"], "page=$x");
317
                    $page_links[]="<a href=\"$url\">$x</a>";
318
                }
319
                $rows[$key]["pages"]=implode(",&nbsp;", $page_links);
320
            } else {
321
                $url=phorum_get_url(PHORUM_READ_URL, $row["thread"], "page=1");
322
                $rows[$key]["pages"]="<a href=\"$url\">1</a>&nbsp;";
323
                $rows[$key]["pages"].="...&nbsp;";
324
                $pageno=$pages-2;
325
                $url=phorum_get_url(PHORUM_READ_URL, $row["thread"], "page=$pageno");
326
                $rows[$key]["pages"].="<a href=\"$url\">$pageno</a>,&nbsp;";
327
                $pageno=$pages-1;
328
                $url=phorum_get_url(PHORUM_READ_URL, $row["thread"], "page=$pageno");
329
                $rows[$key]["pages"].="<a href=\"$url\">$pageno</a>,&nbsp;";
330
                $pageno=$pages;
331
                $url=phorum_get_url(PHORUM_READ_URL, $row["thread"], "page=$pageno");
332
                $rows[$key]["pages"].="<a href=\"$url\">$pageno</a>&nbsp;";
333
            }
334
        }
335
        if(isset($row['meta']['recent_post'])) {
336
            if($pages>1){
337
                $rows[$key]["last_post_url"]=phorum_get_url(PHORUM_READ_URL, $row["thread"], $row["meta"]["recent_post"]["message_id"], "page=$pages");
338
            } else {
339
                $rows[$key]["last_post_url"]=phorum_get_url(PHORUM_READ_URL, $row["thread"], $row["meta"]["recent_post"]["message_id"]);
340
            }
341
 
342
            $row['meta']['recent_post']['author'] = htmlspecialchars($row['meta']['recent_post']['author']);
343
            if ($row["meta"]["recent_post"]["user_id"]){
344
                $url = phorum_get_url(PHORUM_PROFILE_URL, $row["meta"]["recent_post"]["user_id"]);
345
                $rows[$key]["last_post_profile_url"] = $url;
346
                $rows[$key]["last_post_by"] = "<a href=\"$url\">{$row['meta']['recent_post']['author']}</a>";
347
            }else{
348
                $rows[$key]["profile_url"] = "";
349
                $rows[$key]["last_post_by"] = $row["meta"]["recent_post"]["author"];
350
            }
351
        } else {
352
            $rows[$key]["last_post_by"] = "";
353
        }
354
 
355
        if($min_id == 0 || $min_id > $row['message_id'])
356
            $min_id = $row['message_id'];
357
    }
358
}
359
 
360
// run list mods
361
$rows = phorum_hook("list", $rows);
362
 
363
// if we retrieve the body too we need to setup some more variables for the messages
364
// to make it a little more similar to the view in read.php
365
if(isset($PHORUM['TMP']['bodies_in_list']) && $PHORUM['TMP']['bodies_in_list'] == 1) {
366
 
367
    foreach ($rows as $id => $row) {
368
 
369
        // is the message unapproved?
370
        $row["is_unapproved"] = ($row['status'] < 0) ? 1 : 0;
371
 
372
        // check if its the first message in the thread
373
        if($row["message_id"] == $row["thread"]) {
374
            $row["threadstart"] = true;
375
        } else{
376
            $row["threadstart"] = false;
377
        }
378
 
379
        // mask host if not a moderator
380
        if(empty($PHORUM["user"]["admin"]) && (empty($PHORUM["DATA"]["MODERATOR"]) || !PHORUM_MOD_IP_VIEW)){
381
            if($PHORUM["display_ip_address"]){
382
                if($row["moderator_post"]){
383
                    $row["ip"]=$PHORUM["DATA"]["LANG"]["Moderator"];
384
                } elseif(is_numeric(str_replace(".", "", $row["ip"]))){
385
                    $row["ip"]=substr($row["ip"],0,strrpos($row["ip"],'.')).'.---';
386
                } else {
387
                    $row["ip"]="---".strstr($row["ip"], ".");
388
                }
389
 
390
            } else {
391
                $row["ip"]=$PHORUM["DATA"]["LANG"]["IPLogged"];
392
            }
393
        }
394
 
395
        // add the edited-message to a post if its edited
396
        if(isset($row['meta']['edit_count']) && $row['meta']['edit_count'] > 0) {
397
            $editmessage = str_replace ("%count%", $row['meta']['edit_count'], $PHORUM["DATA"]["LANG"]["EditedMessage"]);
398
            $editmessage = str_replace ("%lastedit%", phorum_date($PHORUM["short_date"],$row['meta']['edit_date']),  $editmessage);
399
            $editmessage = str_replace ("%lastuser%", $row['meta']['edit_username'],  $editmessage);
400
            $row["body"].="\n\n\n\n$editmessage";
401
        }
402
 
403
 
404
        if($PHORUM["max_attachments"]>0 && isset($row["meta"]["attachments"])){
405
            $PHORUM["DATA"]["ATTACHMENTS"]=true;
406
            $row["attachments"]=$row["meta"]["attachments"];
407
            // unset($row["meta"]["attachments"]);
408
            foreach($row["attachments"] as $key=>$file){
409
                $row["attachments"][$key]["size"]=phorum_filesize($file["size"]);
410
                $row["attachments"][$key]["name"]=
411
                htmlentities($file['name'], ENT_COMPAT,
412
                $PHORUM["DATA"]["CHARSET"]);
413
                $row["attachments"][$key]["url"]=
414
                phorum_get_url(PHORUM_FILE_URL, "file={$file['file_id']}");
415
            }
416
        }
417
        $rows[$id] = $row;
418
    }
419
}
420
 
421
// format messages
422
$rows = phorum_format_messages($rows);
423
 
424
 
425
// set up the data
426
$PHORUM["DATA"]["ROWS"] = $rows;
427
 
428
$PHORUM["DATA"]["URL"]["MARKREAD"] = phorum_get_url(PHORUM_LIST_URL, $PHORUM["forum_id"], "markread");
429
if($PHORUM["DATA"]["MODERATOR"]) {
430
   $PHORUM["DATA"]["URL"]["UNAPPROVED"] = phorum_get_url(PHORUM_PREPOST_URL);
431
}
432
 
433
// updating new-info for first visit (last message on first page is first new)
434
if ($PHORUM["DATA"]["LOGGEDIN"] && $PHORUM['user']['newinfo']['min_id'] == 0 && !isset($PHORUM['user']['newinfo'][$min_id]) && $min_id != 0){
435
    // setting it as min-id
436
    phorum_db_newflag_add_read($min_id);
437
}
438
 
439
include phorum_get_template("header");
440
phorum_hook("after_header");
441
 
442
// include the correct template
443
if ($PHORUM["threaded_list"]){
444
    include phorum_get_template("list_threads");
445
}else{
446
    include phorum_get_template("list");
447
}
448
 
449
phorum_hook("before_footer");
450
include phorum_get_template("footer");
451
 
452
?>