]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/includes/functions.php
Baseline
[www.vanrenterghem.biz.git] / phpBB2_old / includes / functions.php
1 <?php
2 /***************************************************************************
3  *                               functions.php
4  *                            -------------------
5  *   begin                : Saturday, Feb 13, 2001
6  *   copyright            : (C) 2001 The phpBB Group
7  *   email                : support@phpbb.com
8  *
9  *   $Id: functions.php,v 1.133.2.33 2004/11/18 17:49:42 acydburn Exp $
10  *
11  *
12  ***************************************************************************/
14 /***************************************************************************
15  *
16  *   This program is free software; you can redistribute it and/or modify
17  *   it under the terms of the GNU General Public License as published by
18  *   the Free Software Foundation; either version 2 of the License, or
19  *   (at your option) any later version.
20  *
21  *
22  ***************************************************************************/
24 function get_db_stat($mode)
25 {
26         global $db;
28         switch( $mode )
29         {
30                 case 'usercount':
31                         $sql = "SELECT COUNT(user_id) AS total
32                                 FROM " . USERS_TABLE . "
33                                 WHERE user_id <> " . ANONYMOUS;
34                         break;
36                 case 'newestuser':
37                         $sql = "SELECT user_id, username
38                                 FROM " . USERS_TABLE . "
39                                 WHERE user_id <> " . ANONYMOUS . "
40                                 ORDER BY user_id DESC
41                                 LIMIT 1";
42                         break;
44                 case 'postcount':
45                 case 'topiccount':
46                         $sql = "SELECT SUM(forum_topics) AS topic_total, SUM(forum_posts) AS post_total
47                                 FROM " . FORUMS_TABLE;
48                         break;
49         }
51         if ( !($result = $db->sql_query($sql)) )
52         {
53                 return false;
54         }
56         $row = $db->sql_fetchrow($result);
58         switch ( $mode )
59         {
60                 case 'usercount':
61                         return $row['total'];
62                         break;
63                 case 'newestuser':
64                         return $row;
65                         break;
66                 case 'postcount':
67                         return $row['post_total'];
68                         break;
69                 case 'topiccount':
70                         return $row['topic_total'];
71                         break;
72         }
74         return false;
75 }
77 // added at phpBB 2.0.11 to properly format the username
78 function phpbb_clean_username($username)
79 {
80         $username = htmlspecialchars(rtrim(trim($username), "\\"));
81         $username = substr(str_replace("\\'", "'", $username), 0, 25);
82         $username = str_replace("'", "\\'", $username);
84         return $username;
85 }
87 //
88 // Get Userdata, $user can be username or user_id. If force_str is true, the username will be forced.
89 //
90 function get_userdata($user, $force_str = false)
91 {
92         global $db;
94         if (intval($user) == 0 || $force_str)
95         {
96                 $user = phpbb_clean_username($user);
97         }
98         else
99         {
100                 $user = intval($user);
101         }
103         $sql = "SELECT *
104                 FROM " . USERS_TABLE . " 
105                 WHERE ";
106         $sql .= ( ( is_integer($user) ) ? "user_id = $user" : "username = '" .  $user . "'" ) . " AND user_id <> " . ANONYMOUS;
107         if ( !($result = $db->sql_query($sql)) )
108         {
109                 message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql);
110         }
112         return ( $row = $db->sql_fetchrow($result) ) ? $row : false;
115 function make_jumpbox($action, $match_forum_id = 0)
117         global $template, $userdata, $lang, $db, $nav_links, $phpEx, $SID;
119 //      $is_auth = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata);
121         $sql = "SELECT c.cat_id, c.cat_title, c.cat_order
122                 FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f
123                 WHERE f.cat_id = c.cat_id
124                 GROUP BY c.cat_id, c.cat_title, c.cat_order
125                 ORDER BY c.cat_order";
126         if ( !($result = $db->sql_query($sql)) )
127         {
128                 message_die(GENERAL_ERROR, "Couldn't obtain category list.", "", __LINE__, __FILE__, $sql);
129         }
130         
131         $category_rows = array();
132         while ( $row = $db->sql_fetchrow($result) )
133         {
134                 $category_rows[] = $row;
135         }
137         if ( $total_categories = count($category_rows) )
138         {
139                 $sql = "SELECT *
140                         FROM " . FORUMS_TABLE . "
141                         ORDER BY cat_id, forum_order";
142                 if ( !($result = $db->sql_query($sql)) )
143                 {
144                         message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
145                 }
147                 $boxstring = '<select name="' . POST_FORUM_URL . '" onchange="if(this.options[this.selectedIndex].value != -1){ forms[\'jumpbox\'].submit() }"><option value="-1">' . $lang['Select_forum'] . '</option>';
149                 $forum_rows = array();
150                 while ( $row = $db->sql_fetchrow($result) )
151                 {
152                         $forum_rows[] = $row;
153                 }
155                 if ( $total_forums = count($forum_rows) )
156                 {
157                         for($i = 0; $i < $total_categories; $i++)
158                         {
159                                 $boxstring_forums = '';
160                                 for($j = 0; $j < $total_forums; $j++)
161                                 {
162                                         if ( $forum_rows[$j]['cat_id'] == $category_rows[$i]['cat_id'] && $forum_rows[$j]['auth_view'] <= AUTH_REG )
163                                         {
165 //                                      if ( $forum_rows[$j]['cat_id'] == $category_rows[$i]['cat_id'] && $is_auth[$forum_rows[$j]['forum_id']]['auth_view'] )
166 //                                      {
167                                                 $selected = ( $forum_rows[$j]['forum_id'] == $match_forum_id ) ? 'selected="selected"' : '';
168                                                 $boxstring_forums .=  '<option value="' . $forum_rows[$j]['forum_id'] . '"' . $selected . '>' . $forum_rows[$j]['forum_name'] . '</option>';
170                                                 //
171                                                 // Add an array to $nav_links for the Mozilla navigation bar.
172                                                 // 'chapter' and 'forum' can create multiple items, therefore we are using a nested array.
173                                                 //
174                                                 $nav_links['chapter forum'][$forum_rows[$j]['forum_id']] = array (
175                                                         'url' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=" . $forum_rows[$j]['forum_id']),
176                                                         'title' => $forum_rows[$j]['forum_name']
177                                                 );
178                                                                 
179                                         }
180                                 }
182                                 if ( $boxstring_forums != '' )
183                                 {
184                                         $boxstring .= '<option value="-1">&nbsp;</option>';
185                                         $boxstring .= '<option value="-1">' . $category_rows[$i]['cat_title'] . '</option>';
186                                         $boxstring .= '<option value="-1">----------------</option>';
187                                         $boxstring .= $boxstring_forums;
188                                 }
189                         }
190                 }
192                 $boxstring .= '</select>';
193         }
194         else
195         {
196                 $boxstring .= '<select name="' . POST_FORUM_URL . '" onchange="if(this.options[this.selectedIndex].value != -1){ forms[\'jumpbox\'].submit() }"></select>';
197         }
199         // Let the jumpbox work again in sites having additional session id checks.
200 //      if ( !empty($SID) )
201 //      {
202                 $boxstring .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';
203 //      }
205         $template->set_filenames(array(
206                 'jumpbox' => 'jumpbox.tpl')
207         );
208         $template->assign_vars(array(
209                 'L_GO' => $lang['Go'],
210                 'L_JUMP_TO' => $lang['Jump_to'],
211                 'L_SELECT_FORUM' => $lang['Select_forum'],
213                 'S_JUMPBOX_SELECT' => $boxstring,
214                 'S_JUMPBOX_ACTION' => append_sid($action))
215         );
216         $template->assign_var_from_handle('JUMPBOX', 'jumpbox');
218         return;
221 //
222 // Initialise user settings on page load
223 function init_userprefs($userdata)
225         global $board_config, $theme, $images;
226         global $template, $lang, $phpEx, $phpbb_root_path;
227         global $nav_links;
229         if ( $userdata['user_id'] != ANONYMOUS )
230         {
231                 if ( !empty($userdata['user_lang']))
232                 {
233                         $board_config['default_lang'] = $userdata['user_lang'];
234                 }
236                 if ( !empty($userdata['user_dateformat']) )
237                 {
238                         $board_config['default_dateformat'] = $userdata['user_dateformat'];
239                 }
241                 if ( isset($userdata['user_timezone']) )
242                 {
243                         $board_config['board_timezone'] = $userdata['user_timezone'];
244                 }
245         }
247         if ( !file_exists(@phpbb_realpath($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.'.$phpEx)) )
248         {
249                 $board_config['default_lang'] = 'english';
250         }
252         include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx);
254         if ( defined('IN_ADMIN') )
255         {
256                 if( !file_exists(@phpbb_realpath($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.'.$phpEx)) )
257                 {
258                         $board_config['default_lang'] = 'english';
259                 }
261                 include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx);
262         }
264         //
265         // Set up style
266         //
267         if ( !$board_config['override_user_style'] )
268         {
269                 if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
270                 {
271                         if ( $theme = setup_style($userdata['user_style']) )
272                         {
273                                 return;
274                         }
275                 }
276         }
278         $theme = setup_style($board_config['default_style']);
280         //
281         // Mozilla navigation bar
282         // Default items that should be valid on all pages.
283         // Defined here to correctly assign the Language Variables
284         // and be able to change the variables within code.
285         //
286         $nav_links['top'] = array ( 
287                 'url' => append_sid($phpbb_root_path . 'index.' . $phpEx),
288                 'title' => sprintf($lang['Forum_Index'], $board_config['sitename'])
289         );
290         $nav_links['search'] = array ( 
291                 'url' => append_sid($phpbb_root_path . 'search.' . $phpEx),
292                 'title' => $lang['Search']
293         );
294         $nav_links['help'] = array ( 
295                 'url' => append_sid($phpbb_root_path . 'faq.' . $phpEx),
296                 'title' => $lang['FAQ']
297         );
298         $nav_links['author'] = array ( 
299                 'url' => append_sid($phpbb_root_path . 'memberlist.' . $phpEx),
300                 'title' => $lang['Memberlist']
301         );
303         return;
306 function setup_style($style)
308         global $db, $board_config, $template, $images, $phpbb_root_path;
310         $sql = "SELECT *
311                 FROM " . THEMES_TABLE . "
312                 WHERE themes_id = $style";
313         if ( !($result = $db->sql_query($sql)) )
314         {
315                 message_die(CRITICAL_ERROR, 'Could not query database for theme info');
316         }
318         if ( !($row = $db->sql_fetchrow($result)) )
319         {
320                 message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]");
321         }
323         $template_path = 'templates/' ;
324         $template_name = $row['template_name'] ;
326         $template = new Template($phpbb_root_path . $template_path . $template_name);
328         if ( $template )
329         {
330                 $current_template_path = $template_path . $template_name;
331                 @include($phpbb_root_path . $template_path . $template_name . '/' . $template_name . '.cfg');
333                 if ( !defined('TEMPLATE_CONFIG') )
334                 {
335                         message_die(CRITICAL_ERROR, "Could not open $template_name template config file", '', __LINE__, __FILE__);
336                 }
338                 $img_lang = ( file_exists(@phpbb_realpath($phpbb_root_path . $current_template_path . '/images/lang_' . $board_config['default_lang'])) ) ? $board_config['default_lang'] : 'english';
340                 while( list($key, $value) = @each($images) )
341                 {
342                         if ( !is_array($value) )
343                         {
344                                 $images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value);
345                         }
346                 }
347         }
349         return $row;
352 function encode_ip($dotquad_ip)
354         $ip_sep = explode('.', $dotquad_ip);
355         return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
358 function decode_ip($int_ip)
360         $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
361         return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
364 //
365 // Create date/time from format and timezone
366 //
367 function create_date($format, $gmepoch, $tz)
369         global $board_config, $lang;
370         static $translate;
372         if ( empty($translate) && $board_config['default_lang'] != 'english' )
373         {
374                 @reset($lang['datetime']);
375                 while ( list($match, $replace) = @each($lang['datetime']) )
376                 {
377                         $translate[$match] = $replace;
378                 }
379         }
381         return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : @gmdate($format, $gmepoch + (3600 * $tz));
384 //
385 // Pagination routine, generates
386 // page number sequence
387 //
388 function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE)
390         global $lang;
392         $total_pages = ceil($num_items/$per_page);
394         if ( $total_pages == 1 )
395         {
396                 return '';
397         }
399         $on_page = floor($start_item / $per_page) + 1;
401         $page_string = '';
402         if ( $total_pages > 10 )
403         {
404                 $init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
406                 for($i = 1; $i < $init_page_max + 1; $i++)
407                 {
408                         $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&amp;start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
409                         if ( $i <  $init_page_max )
410                         {
411                                 $page_string .= ", ";
412                         }
413                 }
415                 if ( $total_pages > 3 )
416                 {
417                         if ( $on_page > 1  && $on_page < $total_pages )
418                         {
419                                 $page_string .= ( $on_page > 5 ) ? ' ... ' : ', ';
421                                 $init_page_min = ( $on_page > 4 ) ? $on_page : 5;
422                                 $init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
424                                 for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++)
425                                 {
426                                         $page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&amp;start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
427                                         if ( $i <  $init_page_max + 1 )
428                                         {
429                                                 $page_string .= ', ';
430                                         }
431                                 }
433                                 $page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : ', ';
434                         }
435                         else
436                         {
437                                 $page_string .= ' ... ';
438                         }
440                         for($i = $total_pages - 2; $i < $total_pages + 1; $i++)
441                         {
442                                 $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>'  : '<a href="' . append_sid($base_url . "&amp;start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
443                                 if( $i <  $total_pages )
444                                 {
445                                         $page_string .= ", ";
446                                 }
447                         }
448                 }
449         }
450         else
451         {
452                 for($i = 1; $i < $total_pages + 1; $i++)
453                 {
454                         $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&amp;start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
455                         if ( $i <  $total_pages )
456                         {
457                                 $page_string .= ', ';
458                         }
459                 }
460         }
462         if ( $add_prevnext_text )
463         {
464                 if ( $on_page > 1 )
465                 {
466                         $page_string = ' <a href="' . append_sid($base_url . "&amp;start=" . ( ( $on_page - 2 ) * $per_page ) ) . '">' . $lang['Previous'] . '</a>&nbsp;&nbsp;' . $page_string;
467                 }
469                 if ( $on_page < $total_pages )
470                 {
471                         $page_string .= '&nbsp;&nbsp;<a href="' . append_sid($base_url . "&amp;start=" . ( $on_page * $per_page ) ) . '">' . $lang['Next'] . '</a>';
472                 }
474         }
476         $page_string = $lang['Goto_page'] . ' ' . $page_string;
478         return $page_string;
481 //
482 // This does exactly what preg_quote() does in PHP 4-ish
483 // If you just need the 1-parameter preg_quote call, then don't bother using this.
484 //
485 function phpbb_preg_quote($str, $delimiter)
487         $text = preg_quote($str);
488         $text = str_replace($delimiter, '\\' . $delimiter, $text);
489         
490         return $text;
493 //
494 // Obtain list of naughty words and build preg style replacement arrays for use by the
495 // calling script, note that the vars are passed as references this just makes it easier
496 // to return both sets of arrays
497 //
498 function obtain_word_list(&$orig_word, &$replacement_word)
500         global $db;
502         //
503         // Define censored word matches
504         //
505         $sql = "SELECT word, replacement
506                 FROM  " . WORDS_TABLE;
507         if( !($result = $db->sql_query($sql)) )
508         {
509                 message_die(GENERAL_ERROR, 'Could not get censored words from database', '', __LINE__, __FILE__, $sql);
510         }
512         if ( $row = $db->sql_fetchrow($result) )
513         {
514                 do 
515                 {
516                         $orig_word[] = '#\b(' . str_replace('\*', '\w*?', phpbb_preg_quote($row['word'], '#')) . ')\b#i';
517                         $replacement_word[] = $row['replacement'];
518                 }
519                 while ( $row = $db->sql_fetchrow($result) );
520         }
522         return true;
525 //
526 // This is general replacement for die(), allows templated
527 // output in users (or default) language, etc.
528 //
529 // $msg_code can be one of these constants:
530 //
531 // GENERAL_MESSAGE : Use for any simple text message, eg. results 
532 // of an operation, authorisation failures, etc.
533 //
534 // GENERAL ERROR : Use for any error which occurs _AFTER_ the 
535 // common.php include and session code, ie. most errors in 
536 // pages/functions
537 //
538 // CRITICAL_MESSAGE : Used when basic config data is available but 
539 // a session may not exist, eg. banned users
540 //
541 // CRITICAL_ERROR : Used when config data cannot be obtained, eg
542 // no database connection. Should _not_ be used in 99.5% of cases
543 //
544 function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '')
546         global $db, $template, $board_config, $theme, $lang, $phpEx, $phpbb_root_path, $nav_links, $gen_simple_header, $images;
547         global $userdata, $user_ip, $session_length;
548         global $starttime;
550         if(defined('HAS_DIED'))
551         {
552                 die("message_die() was called multiple times. This isn't supposed to happen. Was message_die() used in page_tail.php?");
553         }
554         
555         define(HAS_DIED, 1);
556         
558         $sql_store = $sql;
559         
560         //
561         // Get SQL error if we are debugging. Do this as soon as possible to prevent 
562         // subsequent queries from overwriting the status of sql_error()
563         //
564         if ( DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) )
565         {
566                 $sql_error = $db->sql_error();
568                 $debug_text = '';
570                 if ( $sql_error['message'] != '' )
571                 {
572                         $debug_text .= '<br /><br />SQL Error : ' . $sql_error['code'] . ' ' . $sql_error['message'];
573                 }
575                 if ( $sql_store != '' )
576                 {
577                         $debug_text .= "<br /><br />$sql_store";
578                 }
580                 if ( $err_line != '' && $err_file != '' )
581                 {
582                         $debug_text .= '</br /><br />Line : ' . $err_line . '<br />File : ' . $err_file;
583                 }
584         }
586         if( empty($userdata) && ( $msg_code == GENERAL_MESSAGE || $msg_code == GENERAL_ERROR ) )
587         {
588                 $userdata = session_pagestart($user_ip, PAGE_INDEX);
589                 init_userprefs($userdata);
590         }
592         //
593         // If the header hasn't been output then do it
594         //
595         if ( !defined('HEADER_INC') && $msg_code != CRITICAL_ERROR )
596         {
597                 if ( empty($lang) )
598                 {
599                         if ( !empty($board_config['default_lang']) )
600                         {
601                                 include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.'.$phpEx);
602                         }
603                         else
604                         {
605                                 include($phpbb_root_path . 'language/lang_english/lang_main.'.$phpEx);
606                         }
607                 }
609                 if ( empty($template) )
610                 {
611                         $template = new Template($phpbb_root_path . 'templates/' . $board_config['board_template']);
612                 }
613                 if ( empty($theme) )
614                 {
615                         $theme = setup_style($board_config['default_style']);
616                 }
618                 //
619                 // Load the Page Header
620                 //
621                 if ( !defined('IN_ADMIN') )
622                 {
623                         include($phpbb_root_path . 'includes/page_header.'.$phpEx);
624                 }
625                 else
626                 {
627                         include($phpbb_root_path . 'admin/page_header_admin.'.$phpEx);
628                 }
629         }
631         switch($msg_code)
632         {
633                 case GENERAL_MESSAGE:
634                         if ( $msg_title == '' )
635                         {
636                                 $msg_title = $lang['Information'];
637                         }
638                         break;
640                 case CRITICAL_MESSAGE:
641                         if ( $msg_title == '' )
642                         {
643                                 $msg_title = $lang['Critical_Information'];
644                         }
645                         break;
647                 case GENERAL_ERROR:
648                         if ( $msg_text == '' )
649                         {
650                                 $msg_text = $lang['An_error_occured'];
651                         }
653                         if ( $msg_title == '' )
654                         {
655                                 $msg_title = $lang['General_Error'];
656                         }
657                         break;
659                 case CRITICAL_ERROR:
660                         //
661                         // Critical errors mean we cannot rely on _ANY_ DB information being
662                         // available so we're going to dump out a simple echo'd statement
663                         //
664                         include($phpbb_root_path . 'language/lang_english/lang_main.'.$phpEx);
666                         if ( $msg_text == '' )
667                         {
668                                 $msg_text = $lang['A_critical_error'];
669                         }
671                         if ( $msg_title == '' )
672                         {
673                                 $msg_title = 'phpBB : <b>' . $lang['Critical_Error'] . '</b>';
674                         }
675                         break;
676         }
678         //
679         // Add on DEBUG info if we've enabled debug mode and this is an error. This
680         // prevents debug info being output for general messages should DEBUG be
681         // set TRUE by accident (preventing confusion for the end user!)
682         //
683         if ( DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) )
684         {
685                 if ( $debug_text != '' )
686                 {
687                         $msg_text = $msg_text . '<br /><br /><b><u>DEBUG MODE</u></b>' . $debug_text;
688                 }
689         }
691         if ( $msg_code != CRITICAL_ERROR )
692         {
693                 if ( !empty($lang[$msg_text]) )
694                 {
695                         $msg_text = $lang[$msg_text];
696                 }
698                 if ( !defined('IN_ADMIN') )
699                 {
700                         $template->set_filenames(array(
701                                 'message_body' => 'message_body.tpl')
702                         );
703                 }
704                 else
705                 {
706                         $template->set_filenames(array(
707                                 'message_body' => 'admin/admin_message_body.tpl')
708                         );
709                 }
711                 $template->assign_vars(array(
712                         'MESSAGE_TITLE' => $msg_title,
713                         'MESSAGE_TEXT' => $msg_text)
714                 );
715                 $template->pparse('message_body');
717                 if ( !defined('IN_ADMIN') )
718                 {
719                         include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
720                 }
721                 else
722                 {
723                         include($phpbb_root_path . 'admin/page_footer_admin.'.$phpEx);
724                 }
725         }
726         else
727         {
728                 echo "<html>\n<body>\n" . $msg_title . "\n<br /><br />\n" . $msg_text . "</body>\n</html>";
729         }
731         exit;
734 //
735 // This function is for compatibility with PHP 4.x's realpath()
736 // function.  In later versions of PHP, it needs to be called
737 // to do checks with some functions.  Older versions of PHP don't
738 // seem to need this, so we'll just return the original value.
739 // dougk_ff7 <October 5, 2002>
740 function phpbb_realpath($path)
742         global $phpbb_root_path, $phpEx;
744         return (!@function_exists('realpath') || !@realpath($phpbb_root_path . 'includes/functions.'.$phpEx)) ? $path : @realpath($path);
747 function redirect($url)
749         global $db, $board_config;
751         if (!empty($db))
752         {
753                 $db->sql_close();
754         }
756         if (strstr(urldecode($url), "\n") || strstr(urldecode($url), "\r"))
757         {
758                 message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
759         }
761         $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://';
762         $server_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['server_name']));
763         $server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) : '';
764         $script_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['script_path']));
765         $script_name = ($script_name == '') ? $script_name : '/' . $script_name;
766         $url = preg_replace('#^\/?(.*?)\/?$#', '/\1', trim($url));
768         // Redirect via an HTML form for PITA webservers
769         if (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')))
770         {
771                 header('Refresh: 0; URL=' . $server_protocol . $server_name . $server_port . $script_name . $url);
772                 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="0; url=' . $server_protocol . $server_name . $server_port . $script_name . $url . '"><title>Redirect</title></head><body><div align="center">If your browser does not support meta redirection please click <a href="' . $server_protocol . $server_name . $server_port . $script_name . $url . '">HERE</a> to be redirected</div></body></html>';
773                 exit;
774         }
776         // Behave as per HTTP/1.1 spec for others
777         header('Location: ' . $server_protocol . $server_name . $server_port . $script_name . $url);
778         exit;
781 ?>