Subversion Repositories Applications.papyrus

Rev

Rev 1688 | 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
 
20
// Check that this file is not loaded directly.
21
if ( basename( __FILE__ ) == basename( $_SERVER["PHP_SELF"] ) ) exit();
22
 
23
// all other constants in ./include/constants.php
24
define( "PHORUM", "5.1.10" );
25
 
26
// our internal version in format of year-month-day-serial
27
define( "PHORUMINTERNAL", "2005120400" );
28
 
29
define( "DEBUG", 0 );
30
 
31
include_once( "./include/constants.php" );
32
 
33
// setup the PHORUM var
34
$PHORUM = array();
35
 
36
// temp member to hold arrays and such in templates
37
$PHORUM["TMP"] = array();
38
 
39
// The data member is the data the templates can access
40
$PHORUM["DATA"] = array();
41
$PHORUM["DATA"]["GET_VARS"] = array();
42
$PHORUM["DATA"]["POST_VARS"] = "";
43
 
44
// get the forum id if set with a post
45
if ( isset( $_REQUEST["forum_id"] ) && is_numeric( $_REQUEST["forum_id"] ) ) {
46
    $PHORUM["forum_id"] = $_REQUEST["forum_id"];
47
}
48
 
49
// strip the slashes off of POST data if magic_quotes is on
50
if ( get_magic_quotes_gpc() && count( $_REQUEST ) ) {
51
    foreach( $_POST as $key => $value ) {
52
        if ( !is_array( $value ) )
53
            $_POST[$key] = stripslashes( $value );
54
        else
55
            $_POST[$key] = phorum_recursive_stripslashes( $value );
56
    }
57
    foreach( $_GET as $key => $value ) {
58
        if ( !is_array( $value ) )
59
            $_GET[$key] = stripslashes( $value );
60
        else
61
            $_GET[$key] = phorum_recursive_stripslashes( $value );
62
    }
63
}
64
 
65
// look for and parse the QUERY_STRING
66
// this only applies to urls that we create.
67
// scrips using urls from forms (search) should use $_GET or $_POST
68
if ( !defined( "PHORUM_ADMIN" ) ) {
69
    if ( isset( $_SERVER["QUERY_STRING"] ) || isset( $PHORUM["CUSTOM_QUERY_STRING"] ) ) {
70
        $Q_STR = empty( $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"] ) ? $_SERVER["QUERY_STRING"]: $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"];
71
 
72
        // ignore stuff past a #
73
        if ( strstr( $Q_STR, "#" ) ) list( $Q_STR, $other ) = explode( "#", $Q_STR );
74
 
75
        // explode it on comma
76
        $PHORUM["args"] = explode( ",", $Q_STR );
77
 
78
        // check for any assigned values
79
        if ( strstr( $Q_STR, "=" ) ) {
80
            foreach( $PHORUM["args"] as $key => $arg ) {
81
 
82
                // if an arg has an = create an element in args
83
                // with left part as key and right part as value
84
                if ( strstr( $arg, "=" ) ) {
85
                    list( $var, $value ) = explode( "=", $arg );
86
                    $PHORUM["args"][$var] = urldecode( $value );
87
                    // get rid of the numbered arg, it is useless.
88
                    unset( $PHORUM["args"][$key] );
89
                }
90
            }
91
        }
92
 
93
        // set forum_id if not set already by
94
        if ( empty( $PHORUM["forum_id"] ) && isset( $PHORUM["args"][0] ) ) {
95
            $PHORUM["forum_id"] = ( int )$PHORUM["args"][0];
96
        }
97
    }
98
}
99
 
100
// set the forum_id to 0 if not set by now.
101
if ( empty( $PHORUM["forum_id"] ) ) $PHORUM["forum_id"] = 0;
102
 
103
// Get the database settings.
104
if ( empty( $GLOBALS["PHORUM_ALT_DBCONFIG"] ) || $GLOBALS["PHORUM_ALT_DBCONFIG"]==$_REQUEST["PHORUM_ALT_DBCONFIG"] || !defined("PHORUM_WRAPPER") ) {
105
    // Backup display_errors setting.
106
    $orig = ini_get("display_errors");
107
    ini_set("display_errors", 0);
108
 
109
    // Load configuration.
110
    if (! include_once( "./include/db/config.php" )) {
111
        print '<html><head><title>Phorum error</title></head><body>';
112
        print '<h2>Phorum database configuration error</h2>';
113
 
114
        // No database configuration found.
115
        if (!file_exists("./include/db/config.php")) { ?>
116
            Phorum has been installed on this server, but the configuration<br/>
117
            for the database connection has not yet been made. Please read<br/>
118
            <a href="docs/install.txt">docs/install.txt</a> for installation instructions. <?php
119
        } else {
120
            $fp = fopen("./include/db/config.php", "r");
121
            // Unable to read the configuration file.
122
            if (!$fp) { ?>
123
                A database configuration file was found in ./include/db/config.php,<br/>
124
                but Phorum was unable to read it. Please check the file permissions<br/>
125
                for this file. <?php
126
            // Unknown error.
127
            } else {
128
                fclose($fp); ?>
129
                A database configuration file was found in ./include/dbconfig.php,<br/>
130
                but it could not be loaded. It possibly contains one or more errors.<br/>
131
                Please check your configuration file. <?php
132
            }
133
        }
134
 
135
        print '</body></html>';
136
        exit(1);
137
    }
138
 
139
    // Restore original display_errors setting.
140
    ini_set("display_errors", $orig);
141
} else {
142
    $PHORUM["DBCONFIG"] = $GLOBALS["PHORUM_ALT_DBCONFIG"];
143
}
144
 
145
// Load the database layer.
146
include_once( "./include/db/{$PHORUM['DBCONFIG']['type']}.php" );
147
 
148
if(!phorum_db_check_connection()){
149
    if(isset($PHORUM["DBCONFIG"]["down_page"])){
150
        header("Location: ".$PHORUM["DBCONFIG"]["down_page"]);
151
        exit();
152
    } else {
153
        echo "The database connection failed. Please check your database configuration in include/db/config.php. If the configuration is okay, check if the database server is running.";
154
        exit();
155
    }
156
}
157
 
158
// get the Phorum settings
159
phorum_db_load_settings();
160
 
161
// a hook for rewriting vars at the beginning of common.php,
162
//right after loading the settings from the database
163
phorum_hook( "common_pre", "" );
164
 
165
include_once( "./include/cache.php" );
166
 
167
// stick some stuff from the settings into the DATA member
168
$PHORUM["DATA"]["TITLE"] = ( isset( $PHORUM["title"] ) ) ? $PHORUM["title"] : "";
169
$PHORUM["DATA"]["HTML_TITLE"] = ( !empty( $PHORUM["html_title"] ) ) ? $PHORUM["html_title"] : $PHORUM["DATA"]["TITLE"];
170
$PHORUM["DATA"]["HEAD_TAGS"] = ( isset( $PHORUM["head_tags"] ) ) ? $PHORUM["head_tags"] : "";
171
$PHORUM["DATA"]["FORUM_ID"] = $PHORUM["forum_id"];
172
 
173
////////////////////////////////////////////////////////////
174
// only do this stuff if we are not in the admin
175
 
176
if ( !defined( "PHORUM_ADMIN" ) ) {
177
 
178
    // if the Phorum is disabled, display a message.
179
    if(isset($PHORUM["status"]) && $PHORUM["status"]=="disabled"){
180
        if(!empty($PHORUM["disabled_url"])){
181
            header("Location: ".$PHORUM["disabled_url"]);
182
            exit();
183
        } else {
184
            echo "This Phorum is currently disabled.  Please contact the web site owner at ".$PHORUM['system_email_from_address']." for more information.\n";
185
            exit();
186
        }
187
    }
188
 
189
    // checking for upgrade or new install
190
    if ( !isset( $PHORUM['internal_version'] ) ) {
191
        echo "<html><head><title>Phorum error</title></head><body>No Phorum settings were found. Either this is a brand new installation of Phorum or there is an error with your database server. If this is a new install, please <a href=\"admin.php\">go to the admin page</a> to complete the installation. If not, check your database server.</body></html>";
192
        exit();
193
    } elseif ( $PHORUM['internal_version'] < PHORUMINTERNAL ) {
194
        echo "<html><head><title>Error</title></head><body>Looks like you have installed a new version. Go to the admin to complete the upgrade!</body></html>";
195
        exit();
196
    }
197
 
198
    // load the forum's settings
199
    if ( !empty( $PHORUM["forum_id"] ) ) {
200
        $forum_settings = phorum_db_get_forums( $PHORUM["forum_id"] );
201
        if ( empty( $forum_settings[$PHORUM["forum_id"]] ) ) {
202
            phorum_hook( "common_no_forum", "" );
203
            phorum_redirect_by_url( phorum_get_url( PHORUM_INDEX_URL ) );
204
            exit();
205
        }
206
        $PHORUM = array_merge( $PHORUM, $forum_settings[$PHORUM["forum_id"]] );
207
    } else {
208
        // some defaults we might need if no forum is set (i.e. on the index-page)
209
        $PHORUM['vroot']=0;
210
        $PHORUM['parent_id']=0;
211
        $PHORUM['active']=1;
212
        $PHORUM['folder_flag']=1;
213
    }
214
 
215
    // stick some stuff from the settings into the DATA member
216
    $PHORUM["DATA"]["NAME"] = ( isset( $PHORUM["name"] ) ) ? $PHORUM["name"] : "";
217
    $PHORUM["DATA"]["DESCRIPTION"] = ( isset( $PHORUM["description"] ) ) ? $PHORUM["description"] : "";
218
    $PHORUM["DATA"]["ENABLE_PM"] = ( isset( $PHORUM["enable_pm"] ) ) ? $PHORUM["enable_pm"] : "";
219
    if ( !empty( $PHORUM["DATA"]["HTML_TITLE"] ) && !empty( $PHORUM["DATA"]["NAME"] ) ) {
220
        $PHORUM["DATA"]["HTML_TITLE"] .= PHORUM_SEPARATOR;
221
    }
222
    $PHORUM["DATA"]["HTML_TITLE"] .= $PHORUM["DATA"]["NAME"];
223
 
224
    // check the user session
225
    include_once( "./include/users.php" );
226
    if ( phorum_user_check_session() ) {
227
        $PHORUM["DATA"]["LOGGEDIN"] = true;
228
 
229
        if(!$PHORUM["tight_security"] || phorum_user_check_session( PHORUM_SESSION_SHORT_TERM )){
230
            $PHORUM["DATA"]["FULLY_LOGGEDIN"] = true;
231
        } else {
232
            $PHORUM["DATA"]["FULLY_LOGGEDIN"] = false;
233
        }
234
 
235
        // Let the templates know whether we have new private messages.
236
        $PHORUM["DATA"]["NEW_PRIVATE_MESSAGES"] = 0;
237
        if ( $PHORUM["enable_pm"] && isset($PHORUM["user"]["new_private_messages"]) ) {
238
             $PHORUM["DATA"]["NEW_PRIVATE_MESSAGES"] = $PHORUM["user"]["new_private_messages"];
239
        }
240
 
241
        $PHORUM["DATA"]["notice_messages"] = false;
242
        $PHORUM["DATA"]["notice_users"] = false;
243
        $PHORUM["DATA"]["notice_groups"] = false;
244
 
245
        // if moderator notifications are on and the person is a mod, lets find out if anything is new
246
        if ( $PHORUM["enable_moderator_notifications"] ) {
247
            $forummodlist = phorum_user_access_list( PHORUM_USER_ALLOW_MODERATE_MESSAGES );
248
            if ( count( $forummodlist ) > 0 ) {
249
                $PHORUM["DATA"]["notice_messages"] = ( count( phorum_db_get_unapproved_list( $forummodlist, true ) ) > 0 );
250
                $PHORUM["DATA"]["notice_messages_url"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_UNAPPROVED );
251
            }
252
            if ( phorum_user_access_allowed( PHORUM_USER_ALLOW_MODERATE_USERS ) ) {
253
                $PHORUM["DATA"]["notice_users"] = ( count( phorum_db_user_get_unapproved() ) > 0 );
254
                $PHORUM["DATA"]["notice_users_url"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_USERS );
255
            }
256
            if ( phorum_user_allow_moderate_group() ) {
257
                $groups = phorum_user_get_moderator_groups();
258
                if ( count( $groups ) > 0 ) {
259
                    $PHORUM["DATA"]["notice_groups"] = count( phorum_db_get_group_members( array_keys( $groups ), PHORUM_USER_GROUP_UNAPPROVED ) );
260
                    $PHORUM["DATA"]["notice_groups_url"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_GROUP_MODERATION );
261
                }
262
            }
263
        }
264
 
265
        $PHORUM["DATA"]["notice_all"] = ( $PHORUM["enable_pm"] && phorum_page!="pm" && $PHORUM["DATA"]["NEW_PRIVATE_MESSAGES"] ) || $PHORUM["DATA"]["notice_messages"] || $PHORUM["DATA"]["notice_users"] || $PHORUM["DATA"]["notice_groups"];
266
 
267
        // if the user has overridden thread settings, change it here.
268
        if ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) {
269
            if ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_ON ) {
270
                $PHORUM["threaded_list"] = true;
271
            } elseif ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_OFF ) {
272
                $PHORUM["threaded_list"] = false;
273
            }
274
            if ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_ON ) {
275
                $PHORUM["threaded_read"] = true;
276
            } elseif ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_OFF ) {
277
                $PHORUM["threaded_read"] = false;
278
            }
279
        }
280
    }
281
 
282
    // set up the blank user if not logged in
283
    if ( empty( $PHORUM["user"] ) ) {
284
        $PHORUM["user"] = array( "user_id" => 0, "username" => "", "admin" => false, "newinfo" => array() );
285
        $PHORUM["DATA"]["LOGGEDIN"] = false;
286
    }
287
 
288
 
289
    // a hook for rewriting vars in common.php after loading the user
290
    phorum_hook( "common_post_user", "" );
291
 
292
 
293
    // set up the template
294
 
295
    // check for a template being passed on the url
296
    // only use valid template names
297
    if ( !empty( $PHORUM["args"]["template"] ) ) {
298
        $template = basename( $PHORUM["args"]["template"] );
299
        if ($template != '..') {
300
            $PHORUM["template"] = $template;
301
        }
302
    }
303
 
304
    // user output buffering so we don't get header errors
305
    // not loaded if we are running an external or scheduled script
306
    if (! defined('PHORUM_SCRIPT')) {
307
        ob_start();
308
        include_once( phorum_get_template( "settings" ) );
309
        ob_end_clean();
310
    }
311
 
312
    // get the language file
313
    if ( ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) && isset( $PHORUM['user']['user_language'] ) && !empty($PHORUM['user']['user_language']) )
314
        $PHORUM['language'] = $PHORUM['user']['user_language'];
315
 
316
    if ( !isset( $PHORUM["language"] ) || empty( $PHORUM["language"] ) || !file_exists( "./include/lang/$PHORUM[language].php" ) )
317
        $PHORUM["language"] = $PHORUM["default_language"];
318
 
319
    if ( file_exists( "./include/lang/$PHORUM[language].php" ) ) {
320
        include_once( "./include/lang/$PHORUM[language].php" );
321
    }
322
    // load languages for localized modules
323
    if ( isset( $PHORUM["hooks"]["lang"] ) && is_array($PHORUM["hooks"]["lang"]) ) {
324
        foreach( $PHORUM["hooks"]["lang"]["mods"] as $mod ) {
325
            // load mods for this hook
326
            if ( file_exists( "./mods/$mod/lang/$PHORUM[language].php" ) ) {
327
                include_once "./mods/$mod/lang/$PHORUM[language].php";
328
            }
329
            elseif ( file_exists( "./mods/$mod/lang/english.php" ) ) {
330
                include_once "./mods/$mod/lang/english.php";
331
            }
332
        }
333
    }
334
 
335
    // HTML titles can't contain HTML code, so we strip HTML tags
336
    // and HTML escape the title.
337
$PHORUM["DATA"]["HTML_TITLE"] = htmlentities(strip_tags($PHORUM["DATA"]["HTML_TITLE"]), ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
338
 
339
    // if the Phorum is disabled, display a message.
340
    if(isset($PHORUM["status"]) && $PHORUM["status"]=="admin-only" && !$PHORUM["user"]["admin"]){
341
        // set all our URL's
342
        phorum_build_common_urls();
343
 
344
        $PHORUM["DATA"]["MESSAGE"]=$PHORUM["DATA"]["LANG"]["AdminOnlyMessage"];
345
        include phorum_get_template("header");
346
        phorum_hook("after_header");
347
        include phorum_get_template("message");
348
        phorum_hook("before_footer");
349
        include phorum_get_template("footer");
350
        exit();
351
 
352
    }
353
 
354
 
355
    // a hook for rewriting vars at the end of common.php
356
    phorum_hook( "common", "" );
357
 
358
    $PHORUM['DATA']['USERINFO'] = $PHORUM['user'];
359
    $PHORUM['DATA']['PHORUM_PAGE'] = phorum_page;
360
    $PHORUM['DATA']['USERTRACK'] = $PHORUM['track_user_activity'];
361
}
362
 
363
 
364
//////////////////////////////////////////////////////////
365
// functions
366
 
367
/**
368
 * A common function to check that a user is logged in
369
 */
370
function phorum_require_login()
371
{
372
    $PHORUM = $GLOBALS['PHORUM'];
373
    if ( !$PHORUM["user"]["user_id"] ) {
374
        $url = phorum_get_url( PHORUM_LOGIN_URL, "redir=" . urlencode( $PHORUM["http_path"] . "/" . basename( $_SERVER["PHP_SELF"] ) . "?" . $_SERVER["QUERY_STRING"] ) );
375
        phorum_redirect_by_url( $url );
376
        exit();
377
    }
378
}
379
 
380
/**
381
 * A common function for checking the read-permissions for a forum-page
382
 * returns false if access is not allowed and an error page-was output
383
 */
384
function phorum_check_read_common()
385
{
386
    $PHORUM = $GLOBALS['PHORUM'];
387
 
388
    $retval = true;
389
 
390
    if ( $PHORUM["forum_id"] > 0 && !$PHORUM["folder_flag"] && !phorum_user_access_allowed( PHORUM_USER_ALLOW_READ ) ) {
391
        if ( $PHORUM["DATA"]["LOGGEDIN"] ) {
392
            // if they are logged in and not allowed, they don't have rights
393
            $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["NoRead"];
394
        } else {
395
            // check if they could read if logged in.
396
            // if so, let them know to log in.
397
            if ( ( empty( $PHORUM["DATA"]["POST"]["parentid"] ) && $PHORUM["reg_perms"] &PHORUM_USER_ALLOW_READ ) ) {
398
                $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["PleaseLoginRead"];
399
            } else {
400
                $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["NoRead"];
401
            }
402
        }
403
 
404
        phorum_build_common_urls();
405
 
406
        include phorum_get_template( "header" );
407
        phorum_hook( "after_header" );
408
        include phorum_get_template( "message" );
409
        phorum_hook( "before_footer" );
410
        include phorum_get_template( "footer" );
411
 
412
        $retval = false;
413
    }
414
 
415
    return $retval;
416
}
417
 
418
// used for all url creation.
419
function phorum_get_url()
420
{
421
    $PHORUM = $GLOBALS["PHORUM"];
422
 
423
    $args = "";
424
    $url = "";
425
    $suffix = "";
426
    $add_forum_id = false;
427
    $add_get_vars = true;
428
 
429
    $argv = func_get_args();
430
    $type = array_shift( $argv );
431
 
432
    switch ( $type ) {
433
        case PHORUM_LIST_URL:
434
            $page = "list";
435
            if ( empty( $argv ) ) $add_forum_id = true;
436
            break;
437
        case PHORUM_READ_URL:
438
            $page = "read";
439
            $add_forum_id = true;
440
            if ( !empty( $argv[1] ) && is_numeric( $argv[1] ) ) $suffix = "#msg-$argv[1]";
441
            break;
442
        case PHORUM_FOREIGN_READ_URL:
443
            $page = "read";
444
            if ( !empty( $argv[2] ) && is_numeric( $argv[2] ) ) $suffix = "#msg-$argv[2]";
445
            break;
446
        case PHORUM_REPLY_URL:
447
            if(isset($PHORUM["reply_on_read_page"]) && $PHORUM["reply_on_read_page"]){
448
                $page = "read";
449
                $suffix = "#REPLY";
450
            } else {
451
                $page = "posting";
452
                // For reply on a separate page, we call posting.php on its own.
453
                // In that case argv[0] is the editor mode we want to use
454
                // (reply in this case). Currently, the thread id is in argv[0],
455
                // but we don't need that one for posting.php. So we simply
456
                // replace argv[0] with the correct argument.
457
                $argv[0] = "reply";
458
            }
459
            $add_forum_id = true;
460
            break;
461
        case PHORUM_POSTING_URL:
462
            $page = "posting";
463
            $add_forum_id = true;
464
            break;
465
        case PHORUM_REDIRECT_URL:
466
            $page = "redirect";
467
            $add_forum_id = false;
468
            break;
469
        case PHORUM_SEARCH_URL:
470
            $page = "search";
471
            $add_forum_id = true;
472
            break;
473
        case PHORUM_SEARCH_ACTION_URL:
474
            $page = "search";
475
            $add_get_vars = true;
476
            break;
477
        case PHORUM_DOWN_URL:
478
            $page = "down";
479
            $add_forum_id = true;
480
            break;
481
        case PHORUM_VIOLATION_URL:
482
            $page = "violation";
483
            $add_forum_id = true;
484
            break;
485
        case PHORUM_INDEX_URL:
486
            $page = "index";
487
            break;
488
        case PHORUM_LOGIN_URL:
489
            $page = "login";
490
            $add_forum_id = true;
491
            break;
492
        case PHORUM_LOGIN_ACTION_URL:
493
            $page = "login";
494
            break;
495
        case PHORUM_REGISTER_URL:
496
            $page = "register";
497
            $add_forum_id = true;
498
            break;
499
        case PHORUM_REGISTER_ACTION_URL:
500
            $page = "register";
501
            break;
502
        case PHORUM_PROFILE_URL:
503
            $page = "profile";
504
            $add_forum_id = true;
505
            break;
506
        case PHORUM_SUBSCRIBE_URL:
507
            $page = "subscribe";
508
            $add_forum_id = true;
509
            break;
510
        case PHORUM_MODERATION_URL:
511
            $page = "moderation";
512
            $add_forum_id = true;
513
            break;
514
        case PHORUM_MODERATION_ACTION_URL:
515
            $page = "moderation";
516
            $add_get_vars = false;
517
            break;
518
        case PHORUM_PREPOST_URL:
519
            $page = "control";
520
            $argv[] = "panel=messages";
521
            $add_forum_id = true;
522
            break;
523
        case PHORUM_CONTROLCENTER_URL:
524
            $page = "control";
525
            $add_forum_id = true;
526
            break;
527
        case PHORUM_CONTROLCENTER_ACTION_URL:
528
            $page = "control";
529
            break;
530
        case PHORUM_PM_URL:
531
            $page = "pm";
532
            $add_forum_id = true;
533
            break;
534
        case PHORUM_PM_ACTION_URL:
535
            $page = "pm";
536
            break;
537
        case PHORUM_FILE_URL:
538
            $page = "file";
539
            $add_forum_id = true;
540
            break;
541
        case PHORUM_FOLLOW_URL:
542
            $page = "follow";
543
            $add_forum_id = true;
544
            break;
545
        case PHORUM_FOLLOW_ACTION_URL:
546
            $page = "follow";
547
            $add_forum_id = false;
548
            break;
549
        case PHORUM_REPORT_URL:
550
            $page = "report";
551
            $add_forum_id = true;
552
            break;
553
        case PHORUM_RSS_URL:
554
            switch(phorum_page){
555
                case "list":
556
                    $add_forum_id = true;
557
                    break;
558
                case "read":
559
                    $add_forum_id = true;
560
                    array_push($argv, $PHORUM["args"]["1"]);
561
                    break;
562
            }
563
            $page = "rss";
564
            break;
565
        // this is for adding own generic urls
566
        case PHORUM_CUSTOM_URL:
567
            $page = array_shift($argv); // first arg is our page
568
            $add_forum_id_tmp=array_shift($argv); // second determining if we should add the forum_id
569
            $add_forum_id = $add_forum_id_tmp?true:false;
570
            break;
571
 
572
        case PHORUM_BASE_URL:
573
            // only to flag phorum_custom_get_url() that base url is requested
574
            $page = '';
575
            break;
576
 
577
        default:
578
            trigger_error( "Unhandled page type.", E_USER_WARNING );
579
            break;
580
    }
581
 
582
    // build the query string
583
    $query_items = array();
584
 
585
    if ( $add_forum_id ) {
586
        $query_items[] = ( int )$PHORUM["forum_id"];
587
    }
588
 
589
    if ( count( $argv ) > 0 ) {
590
        $query_items = array_merge( $query_items, $argv );
591
    }
592
 
593
    if ( !empty( $PHORUM["DATA"]["GET_VARS"] ) && $add_get_vars ) {
594
        $query_items = array_merge( $query_items, $PHORUM["DATA"]["GET_VARS"] );
595
    }
596
    // build the url
597
    if ( !function_exists( "phorum_custom_get_url" ) ) {
598
        if ($type == PHORUM_BASE_URL) return $PHORUM["http_path"] . '/';
599
 
600
        $url = "$PHORUM[http_path]/$page." . PHORUM_FILE_EXTENSION;
601
 
602
        if ( count( $query_items ) ) $url .= "?" . implode( ",", $query_items );
603
 
604
        if ( !empty( $suffix ) ) $url .= $suffix;
605
    } else {
606
        $url = phorum_custom_get_url( $page, $query_items, $suffix );
607
    }
608
 
609
    return $url;
610
}
611
 
612
// retrieve the appropriate template file name
613
function phorum_get_template( $page, $is_include = false )
614
{
615
    $PHORUM = $GLOBALS["PHORUM"];
616
 
617
    if ( ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) && isset( $PHORUM['user']['user_template'] ) && !empty($PHORUM['user']['user_template'])) {
618
        $PHORUM['template'] = $PHORUM['user']['user_template'];
619
    }
620
 
621
    // If no user template is set or if the template folder cannot be found,
622
    // fallback to the default template.
623
    if (empty($PHORUM["template"]) || !file_exists("./templates/{$PHORUM['template']}")) {
624
        $PHORUM["template"] = $PHORUM["default_template"];
625
    }
626
 
627
    $tpl = "./templates/$PHORUM[template]/$page";
628
    // check for straight PHP file
629
    if ( file_exists( "$tpl.php" ) ) {
630
        $phpfile = "$tpl.php";
631
    } else {
632
        // not there, look for a template
633
        $tplfile = "$tpl.tpl";
634
        $safetemplate = str_replace("-", "_", $PHORUM["template"]);
635
        $safepage = str_replace("-", "_", $page);
636
        $phpfile = "$PHORUM[cache]/tpl-$safetemplate-$safepage-" .
637
               ($is_include ? "include" : "toplevel") . "-" .
638
               md5( dirname( __FILE__ ) ) . ".php";
639
 
640
        if ( $is_include || !file_exists( $phpfile ) ) {
641
            include_once "./include/templates.php";
642
            phorum_import_template( $tplfile, $phpfile );
643
        }
644
    }
645
 
646
    return $phpfile;
647
}
648
 
649
// creates URLs used on most pages
650
function phorum_build_common_urls()
651
{
652
    $PHORUM=$GLOBALS['PHORUM'];
653
 
654
    // those links are only needed in forums, not in folders
655
    if(isset($PHORUM['folder_flag']) && !$PHORUM['folder_flag']) {
656
        $GLOBALS["PHORUM"]["DATA"]["URL"]["TOP"] = phorum_get_url( PHORUM_LIST_URL );
657
        $GLOBALS["PHORUM"]["DATA"]["URL"]["MARKREAD"] = phorum_get_url( PHORUM_LIST_URL, "markread=1" );
658
        $GLOBALS["PHORUM"]["DATA"]["URL"]["POST"] = phorum_get_url( PHORUM_POSTING_URL );
659
        $GLOBALS["PHORUM"]["DATA"]["URL"]["SUBSCRIBE"] = phorum_get_url( PHORUM_SUBSCRIBE_URL );
660
    }
661
 
662
    // those are general urls, needed nearly everywhere
663
    $GLOBALS["PHORUM"]["DATA"]["URL"]["SEARCH"] = phorum_get_url( PHORUM_SEARCH_URL );
664
 
665
    // RSS-Url only makes sense on a couple of pages
666
    if(isset($PHORUM['use_rss']) && $PHORUM['use_rss']
667
        && (phorum_page=="index" || phorum_page=="list" || phorum_page=="read")){
668
        $GLOBALS["PHORUM"]["DATA"]["URL"]["RSS"] = phorum_get_url( PHORUM_RSS_URL );
669
    }
670
 
671
    $index_id=-1;
672
    // in a folder
673
 
674
    if( $PHORUM['folder_flag'] && phorum_page != 'index'
675
    && ($PHORUM['forum_id'] == 0 || $PHORUM['vroot'] == $PHORUM['forum_id'])) {
676
        // folder where we usually don't show the index-link but on
677
        // additional pages like search and login its shown
678
        $index_id=$PHORUM['forum_id'];
679
 
680
    } elseif( ( $PHORUM['folder_flag'] &&
681
    ($PHORUM['forum_id'] != 0 && $PHORUM['vroot'] != $PHORUM['forum_id'])) ||
682
    (!$PHORUM['folder_flag'] && $PHORUM['active'])) {
683
        // either a folder where the link should be shown (not vroot or root)
684
        // or an active forum where the link should be shown
685
 
686
        if(isset($PHORUM["use_new_folder_style"]) && $PHORUM["use_new_folder_style"] ) {
687
            // go to root or vroot
688
            $index_id=$PHORUM["vroot"]; // vroot is either 0 (root) or another id
689
 
690
        } else {
691
            // go to parent
692
            $index_id=$PHORUM["parent_id"]; // parent_id is always set now
693
 
694
        }
695
 
696
    }
697
    if($index_id > -1) {
698
        // check if its the full root, avoid adding an id in this case (SE-optimized ;))
699
        if (!empty($index_id))
700
            $GLOBALS["PHORUM"]["DATA"]["URL"]["INDEX"] = phorum_get_url( PHORUM_INDEX_URL, $index_id );
701
        else
702
            $GLOBALS["PHORUM"]["DATA"]["URL"]["INDEX"] = phorum_get_url( PHORUM_INDEX_URL );
703
    }
704
 
705
    // these urls depend on the login-status of a user
706
    if ( $GLOBALS["PHORUM"]["DATA"]["LOGGEDIN"] ) {
707
        $GLOBALS["PHORUM"]["DATA"]["URL"]["LOGINOUT"] = phorum_get_url( PHORUM_LOGIN_URL, "logout=1" );
708
        $GLOBALS["PHORUM"]["DATA"]["URL"]["REGISTERPROFILE"] = phorum_get_url( PHORUM_CONTROLCENTER_URL );
709
        $GLOBALS["PHORUM"]["DATA"]["URL"]["PM"] = phorum_get_url( PHORUM_PM_URL );
710
    } else {
711
        $GLOBALS["PHORUM"]["DATA"]["URL"]["LOGINOUT"] = phorum_get_url( PHORUM_LOGIN_URL );
712
        $GLOBALS["PHORUM"]["DATA"]["URL"]["REGISTERPROFILE"] = phorum_get_url( PHORUM_REGISTER_URL );
713
    }
714
}
715
 
716
// calls phorum mod functions
717
function phorum_hook( $hook, $arg = "" )
718
{
719
    $PHORUM = $GLOBALS["PHORUM"];
720
 
721
    if ( isset( $PHORUM["hooks"][$hook] ) && is_array($PHORUM["hooks"][$hook])) {
722
 
723
        foreach( $PHORUM["hooks"][$hook]["mods"] as $mod ) {
724
            // load mods for this hook
725
            if ( file_exists( "./mods/$mod/$mod.php" ) ) {
726
                include_once "./mods/$mod/$mod.php";
727
            } elseif ( file_exists( "./mods/$mod.php" ) ) {
728
                include_once "./mods/$mod.php";
729
            }
730
        }
731
 
732
        foreach( $PHORUM["hooks"][$hook]["funcs"] as $func ) {
733
            // call functions for this hook
734
            if ( function_exists( $func ) ) {
735
                $arg = call_user_func( $func, $arg );
736
            }
737
        }
738
    }
739
 
740
    return $arg;
741
}
742
 
743
// HTML encodes a string
744
function phorum_html_encode( $string )
745
{
746
    $ret_string = "";
747
    $len = strlen( $string );
748
    for( $x = 0;$x < $len;$x++ ) {
749
        $ord = ord( $string[$x] );
750
        $ret_string .= "&#$ord;";
751
    }
752
    return $ret_string;
753
}
754
 
755
// removes slashes from all array-entries
756
function phorum_recursive_stripslashes( $array )
757
{
758
    if ( !is_array( $array ) ) {
759
        return $array;
760
    } else {
761
        foreach( $array as $key => $value ) {
762
            if ( !is_array( $value ) )
763
                $array[$key] = stripslashes( $value );
764
            else
765
                $array[$key] = phorum_recursive_stripslashes( $value );
766
        }
767
    }
768
    return $array;
769
}
770
 
771
// returns the available templates as an array
772
function phorum_get_template_info()
773
{
774
    $tpls = array();
775
 
776
    $d = dir( "./templates" );
777
    while ( false !== ( $entry = $d->read() ) ) {
778
        if ( $entry != "." && $entry != ".." && file_exists( "./templates/$entry/info.php" ) ) {
779
            include "./templates/$entry/info.php";
780
            if ( !isset( $template_hide ) || empty( $template_hide ) || defined( "PHORUM_ADMIN" ) ) {
781
                $tpls[$entry] = "$name $version";
782
            } else {
783
                unset( $template_hide );
784
            }
785
        }
786
    }
787
 
788
    return $tpls;
789
}
790
 
791
// returns the available languages as an array
792
function phorum_get_language_info()
793
{
794
    $langs = array();
795
 
796
    $d = dir( "./include/lang" );
797
    while ( false !== ( $entry = $d->read() ) ) {
798
        if ( substr( $entry, -4 ) == ".php" && is_file( "./include/lang/$entry" ) ) {
799
            @include "./include/lang/$entry";
800
            if ( !isset( $language_hide ) || empty( $language_hide ) || defined( "PHORUM_ADMIN" ) ) {
801
                $langs[str_replace( ".php", "", $entry )] = $language;
802
            } else {
803
                unset( $language_hide );
804
            }
805
        }
806
    }
807
 
808
    return $langs;
809
}
810
 
811
function phorum_redirect_by_url( $redir_url )
812
{
813
    if ( stristr( $_SERVER['SERVER_SOFTWARE'], "Microsoft-IIS" ) ) {
814
        // the ugly IIS-hack to avoid crashing IIS
815
        print "<html><head>\n<title>Redirecting ...</title>\n";
816
        print "<meta http-equiv=\"refresh\" content=\"0; URL=$redir_url\">";
817
        print "</head>\n";
818
        print "<body><a href=\"$redir_url\">Redirecting ...</a></body>\n";
819
        print "</html>";
820
    } else {
821
        // our standard-way
822
        header( "Location: $redir_url" );
823
    }
824
    exit(0);
825
}
826
 
827
// might remove these, might not.  Need it for debugging.
828
function print_var( $var )
829
{
830
    echo "<xmp>";
831
    print_r( $var );
832
    echo "</xmp>";
833
}
834
 
835
?>