2001-04-19 13:18:57 +00:00
|
|
|
<?php
|
|
|
|
/***************************************************************************
|
|
|
|
* functions.php
|
|
|
|
* -------------------
|
|
|
|
* begin : Saturday, Feb 13, 2001
|
|
|
|
* copyright : (C) 2001 The phpBB Group
|
|
|
|
* email : support@phpbb.com
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2001-04-19 15:05:39 +00:00
|
|
|
function get_db_stat($mode)
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2001-04-19 15:05:39 +00:00
|
|
|
global $db;
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
switch( $mode )
|
2001-07-08 20:24:15 +00:00
|
|
|
{
|
2001-04-19 13:18:57 +00:00
|
|
|
case 'usercount':
|
2001-06-11 00:22:35 +00:00
|
|
|
$sql = "SELECT COUNT(user_id) AS total
|
2001-10-25 23:21:12 +00:00
|
|
|
FROM " . USERS_TABLE . "
|
2001-07-08 20:24:15 +00:00
|
|
|
WHERE user_id <> " . ANONYMOUS;
|
|
|
|
break;
|
2001-04-19 13:18:57 +00:00
|
|
|
|
|
|
|
case 'newestuser':
|
2001-05-13 12:12:44 +00:00
|
|
|
$sql = "SELECT user_id, username
|
2001-10-25 23:21:12 +00:00
|
|
|
FROM " . USERS_TABLE . "
|
2001-07-08 20:24:15 +00:00
|
|
|
WHERE user_id <> " . ANONYMOUS . "
|
|
|
|
ORDER BY user_id DESC
|
|
|
|
LIMIT 1";
|
|
|
|
break;
|
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
case 'postcount':
|
2001-06-13 08:32:32 +00:00
|
|
|
case 'topiccount':
|
2002-02-08 01:33:36 +00:00
|
|
|
$sql = "SELECT SUM(forum_topics) AS topic_total, SUM(forum_posts) AS post_total
|
2001-10-25 23:21:12 +00:00
|
|
|
FROM " . FORUMS_TABLE;
|
2001-07-08 20:24:15 +00:00
|
|
|
break;
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
if ( !($result = $db->sql_query($sql)) )
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
return false;
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
2002-02-08 01:33:36 +00:00
|
|
|
|
|
|
|
$row = $db->sql_fetchrow($result);
|
|
|
|
|
|
|
|
switch ( $mode )
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
case 'usercount':
|
|
|
|
return $row['total'];
|
|
|
|
break;
|
|
|
|
case 'newestuser':
|
|
|
|
return $row;
|
|
|
|
break;
|
|
|
|
case 'postcount':
|
|
|
|
return $row['post_total'];
|
|
|
|
break;
|
|
|
|
case 'topiccount':
|
|
|
|
return $row['topic_total'];
|
|
|
|
break;
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
2002-02-08 01:33:36 +00:00
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
return false;
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
|
|
|
|
2002-02-12 17:14:39 +00:00
|
|
|
function get_userdata($user)
|
2001-05-30 20:21:42 +00:00
|
|
|
{
|
|
|
|
global $db;
|
|
|
|
|
2001-06-11 00:58:08 +00:00
|
|
|
$sql = "SELECT *
|
2002-02-12 17:14:39 +00:00
|
|
|
FROM " . USERS_TABLE . "
|
|
|
|
WHERE ";
|
|
|
|
$sql .= ( ( is_integer($user) ) ? "user_id = $user" : "username = '" . str_replace("\'", "''", $user) . "'" ) . " AND user_id <> " . ANONYMOUS;
|
2002-02-08 01:33:36 +00:00
|
|
|
if ( !($result = $db->sql_query($sql)) )
|
2001-05-30 20:21:42 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql);
|
2001-05-30 20:21:42 +00:00
|
|
|
}
|
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
return ( $row = $db->sql_fetchrow($result) ) ? $row : false;
|
2001-05-30 20:21:42 +00:00
|
|
|
}
|
2001-04-19 13:18:57 +00:00
|
|
|
|
2002-03-31 00:06:34 +00:00
|
|
|
function make_jumpbox($action, $match_forum_id = 0)
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2002-03-31 00:06:34 +00:00
|
|
|
global $template, $lang, $db, $SID, $nav_links, $phpEx;
|
2001-04-19 13:18:57 +00:00
|
|
|
|
2001-05-13 12:12:44 +00:00
|
|
|
$sql = "SELECT c.cat_id, c.cat_title, c.cat_order
|
2001-07-08 20:24:15 +00:00
|
|
|
FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f
|
2001-04-19 13:18:57 +00:00
|
|
|
WHERE f.cat_id = c.cat_id
|
|
|
|
GROUP BY c.cat_id, c.cat_title, c.cat_order
|
|
|
|
ORDER BY c.cat_order";
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( !($result = $db->sql_query($sql)) )
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2001-07-08 20:24:15 +00:00
|
|
|
message_die(GENERAL_ERROR, "Couldn't obtain category list.", "", __LINE__, __FILE__, $sql);
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
2002-02-12 17:14:39 +00:00
|
|
|
|
|
|
|
$category_rows = array();
|
|
|
|
while ( $row = $db->sql_fetchrow($result) )
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2002-02-12 17:14:39 +00:00
|
|
|
$category_rows[] = $row;
|
|
|
|
}
|
2001-04-19 13:18:57 +00:00
|
|
|
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( $total_categories = count($category_rows) )
|
|
|
|
{
|
2001-04-19 13:18:57 +00:00
|
|
|
$sql = "SELECT *
|
2001-07-31 18:37:25 +00:00
|
|
|
FROM " . FORUMS_TABLE . "
|
2001-04-19 13:18:57 +00:00
|
|
|
ORDER BY cat_id, forum_order";
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( !($result = $db->sql_query($sql)) )
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
2001-10-01 23:22:18 +00:00
|
|
|
|
2001-10-06 17:21:10 +00:00
|
|
|
$boxstring = '<select name="' . POST_FORUM_URL . '" onChange="if(this.options[this.selectedIndex].value != -1){ forms[\'jumpbox\'].submit() }"><option value="-1">' . $lang['Select_forum'] . '</option>';
|
2001-04-19 13:18:57 +00:00
|
|
|
|
2002-02-12 17:14:39 +00:00
|
|
|
$forum_rows = array();
|
|
|
|
while ( $row = $db->sql_fetchrow($result) )
|
|
|
|
{
|
|
|
|
$forum_rows[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $total_forums = count($forum_rows) )
|
2001-12-05 00:50:12 +00:00
|
|
|
{
|
|
|
|
for($i = 0; $i < $total_categories; $i++)
|
2002-02-12 17:14:39 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
$boxstring_forums = '';
|
2001-10-01 23:22:18 +00:00
|
|
|
for($j = 0; $j < $total_forums; $j++)
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( $forum_rows[$j]['cat_id'] == $category_rows[$i]['cat_id'] && $forum_rows[$j]['auth_view'] <= AUTH_REG )
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2002-02-12 17:14:39 +00:00
|
|
|
$selected = ( $forum_rows[$j]['forum_id'] == $match_forum_id ) ? 'selected="selected"' : '';
|
2001-12-05 00:50:12 +00:00
|
|
|
$boxstring_forums .= '<option value="' . $forum_rows[$j]['forum_id'] . '"' . $selected . '>' . $forum_rows[$j]['forum_name'] . '</option>';
|
2001-11-26 12:09:37 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Add an array to $nav_links for the Mozilla navigation bar.
|
|
|
|
// 'chapter' and 'forum' can create multiple items, therefore we are using a nested array.
|
|
|
|
//
|
|
|
|
$nav_links['chapter forum'][$forum_rows[$j]['forum_id']] = array (
|
2002-02-08 01:33:36 +00:00
|
|
|
'url' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=" . $forum_rows[$j]['forum_id']),
|
2001-11-26 12:09:37 +00:00
|
|
|
'title' => $forum_rows[$j]['forum_name']
|
|
|
|
);
|
|
|
|
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-05 00:50:12 +00:00
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $boxstring_forums != '' )
|
2001-12-05 00:50:12 +00:00
|
|
|
{
|
|
|
|
$boxstring .= '<option value="-1"> </option>';
|
|
|
|
$boxstring .= '<option value="-1">' . $category_rows[$i]['cat_title'] . '</option>';
|
|
|
|
$boxstring .= '<option value="-1">----------------</option>';
|
|
|
|
$boxstring .= $boxstring_forums;
|
|
|
|
}
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-05 00:50:12 +00:00
|
|
|
|
2001-09-07 12:32:47 +00:00
|
|
|
$boxstring .= '</select>';
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-11-16 17:31:49 +00:00
|
|
|
$boxstring .= '<select name="' . POST_FORUM_URL . '" onChange="if(this.options[this.selectedIndex].value != -1){ forms[\'jumpbox\'].submit() }"></select>';
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
|
|
|
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( isset($SID) )
|
2001-10-14 15:48:38 +00:00
|
|
|
{
|
2002-01-27 03:10:40 +00:00
|
|
|
$boxstring .= '<input type="hidden" name="sid" value="' . $SID . '" />';
|
2001-10-14 15:48:38 +00:00
|
|
|
}
|
|
|
|
|
2002-03-31 00:06:34 +00:00
|
|
|
$template->set_filenames(array(
|
|
|
|
'jumpbox' => 'jumpbox.tpl')
|
|
|
|
);
|
|
|
|
$template->assign_vars(array(
|
|
|
|
'L_GO' => $lang['Go'],
|
|
|
|
'L_JUMP_TO' => $lang['Jump_to'],
|
|
|
|
'L_SELECT_FORUM' => $lang['Select_forum'],
|
|
|
|
|
|
|
|
'S_JUMPBOX_SELECT' => $boxstring,
|
|
|
|
'S_JUMPBOX_ACTION' => append_sid($action))
|
|
|
|
);
|
|
|
|
$template->assign_var_from_handle('JUMPBOX', 'jumpbox');
|
|
|
|
|
|
|
|
return;
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialise user settings on page load
|
|
|
|
function init_userprefs($userdata)
|
|
|
|
{
|
2001-10-25 23:21:12 +00:00
|
|
|
global $board_config, $theme, $images;
|
|
|
|
global $template, $lang, $phpEx, $phpbb_root_path;
|
2001-05-02 00:42:33 +00:00
|
|
|
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( $userdata['user_id'] != ANONYMOUS )
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( !empty($userdata['user_lang']))
|
2001-06-11 12:53:35 +00:00
|
|
|
{
|
|
|
|
$board_config['default_lang'] = $userdata['user_lang'];
|
|
|
|
}
|
2001-07-08 20:24:15 +00:00
|
|
|
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( !empty($userdata['user_dateformat']) )
|
2001-06-11 12:53:35 +00:00
|
|
|
{
|
|
|
|
$board_config['default_dateformat'] = $userdata['user_dateformat'];
|
|
|
|
}
|
2001-07-08 20:24:15 +00:00
|
|
|
|
2002-03-23 23:12:31 +00:00
|
|
|
if ( isset($userdata['user_timezone']) )
|
2001-06-11 12:53:35 +00:00
|
|
|
{
|
2001-09-08 18:24:34 +00:00
|
|
|
$board_config['board_timezone'] = $userdata['user_timezone'];
|
2001-06-11 12:53:35 +00:00
|
|
|
}
|
2001-07-14 17:30:21 +00:00
|
|
|
}
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( !file_exists($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.'.$phpEx) )
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
$board_config['default_lang'] = 'english';
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
2001-05-03 22:10:23 +00:00
|
|
|
|
2001-12-14 02:41:33 +00:00
|
|
|
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx);
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( defined('IN_ADMIN') )
|
2001-11-16 17:31:49 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
if( !file_exists($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.'.$phpEx) )
|
2001-11-16 17:31:49 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
$board_config['default_lang'] = 'english';
|
2001-11-16 17:31:49 +00:00
|
|
|
}
|
2001-12-14 02:41:33 +00:00
|
|
|
|
|
|
|
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx);
|
|
|
|
}
|
|
|
|
|
2002-02-04 18:31:22 +00:00
|
|
|
//
|
|
|
|
// Set up style
|
|
|
|
//
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( !$board_config['override_user_style'] )
|
2001-12-14 02:41:33 +00:00
|
|
|
{
|
2002-02-14 16:09:36 +00:00
|
|
|
if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
|
2002-02-04 18:31:22 +00:00
|
|
|
{
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( $theme = setup_style($userdata['user_style']) )
|
2002-02-04 18:31:22 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
return;
|
2002-02-04 18:31:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-11-16 17:31:49 +00:00
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
$theme = setup_style($board_config['default_style']);
|
|
|
|
|
2001-04-19 13:18:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-05-01 19:10:09 +00:00
|
|
|
|
2001-09-25 18:18:47 +00:00
|
|
|
function setup_style($style)
|
2001-04-19 13:18:57 +00:00
|
|
|
{
|
2001-09-25 18:18:47 +00:00
|
|
|
global $db, $board_config, $template, $images, $phpbb_root_path;
|
2001-05-03 22:10:23 +00:00
|
|
|
|
2001-05-27 03:11:27 +00:00
|
|
|
$sql = "SELECT *
|
2001-07-08 20:24:15 +00:00
|
|
|
FROM " . THEMES_TABLE . "
|
2001-09-25 18:18:47 +00:00
|
|
|
WHERE themes_id = $style";
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( !($result = $db->sql_query($sql)) )
|
2001-05-01 19:10:09 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
message_die(CRITICAL_ERROR, 'Could not query database for theme info');
|
2001-05-01 19:10:09 +00:00
|
|
|
}
|
2001-09-25 18:18:47 +00:00
|
|
|
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( !($row = $db->sql_fetchrow($result)) )
|
2001-05-01 19:10:09 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]");
|
2001-05-01 19:10:09 +00:00
|
|
|
}
|
2001-09-25 18:18:47 +00:00
|
|
|
|
2001-09-27 17:15:59 +00:00
|
|
|
$template_path = 'templates/' ;
|
2001-09-25 18:18:47 +00:00
|
|
|
$template_name = $row['template_name'] ;
|
|
|
|
|
2001-12-21 16:00:41 +00:00
|
|
|
$template = new Template($phpbb_root_path . $template_path . $template_name, $board_config, $db);
|
2001-09-25 18:18:47 +00:00
|
|
|
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( $template )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2001-12-14 02:41:33 +00:00
|
|
|
$current_template_path = $template_path . $template_name;
|
2001-09-27 17:15:59 +00:00
|
|
|
@include($phpbb_root_path . $template_path . $template_name . '/' . $template_name . '.cfg');
|
2001-09-25 18:18:47 +00:00
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( !defined('TEMPLATE_CONFIG') )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
message_die(CRITICAL_ERROR, "Could not open $template_name template config file", '', __LINE__, __FILE__);
|
2001-09-25 18:18:47 +00:00
|
|
|
}
|
|
|
|
|
2002-02-25 14:59:01 +00:00
|
|
|
$img_lang = ( file_exists($current_template_path . '/images/lang_' . $board_config['default_lang']) ) ? $board_config['default_lang'] : 'english';
|
|
|
|
|
|
|
|
while( list($key, $value) = @each($images) )
|
2002-02-04 18:31:22 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( !is_array($value) )
|
|
|
|
{
|
|
|
|
$images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value);
|
|
|
|
}
|
2002-02-04 18:31:22 +00:00
|
|
|
}
|
2001-09-25 18:18:47 +00:00
|
|
|
}
|
|
|
|
|
2002-02-04 18:31:22 +00:00
|
|
|
return $row;
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create date/time from format and timezone
|
|
|
|
//
|
|
|
|
function create_date($format, $gmepoch, $tz)
|
|
|
|
{
|
2002-03-06 00:40:31 +00:00
|
|
|
global $board_config, $lang;
|
2002-03-18 13:35:23 +00:00
|
|
|
static $translate;
|
2002-03-06 00:40:31 +00:00
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( empty($translate) && $board_config['default_lang'] != 'english' )
|
2002-03-06 00:40:31 +00:00
|
|
|
{
|
|
|
|
@reset($lang['datetime']);
|
|
|
|
while ( list($match, $replace) = @each($lang['datetime']) )
|
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
$translate[$match] = $replace;
|
2002-03-06 00:40:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : @gmdate($format, $gmepoch + (3600 * $tz));
|
2001-04-19 13:18:57 +00:00
|
|
|
}
|
2001-05-06 16:16:22 +00:00
|
|
|
|
2001-05-07 23:04:16 +00:00
|
|
|
//
|
|
|
|
// Pagination routine, generates
|
|
|
|
// page number sequence
|
|
|
|
//
|
|
|
|
function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE)
|
|
|
|
{
|
2001-06-11 00:22:35 +00:00
|
|
|
global $lang;
|
2001-05-27 03:11:27 +00:00
|
|
|
|
2001-05-07 23:04:16 +00:00
|
|
|
$total_pages = ceil($num_items/$per_page);
|
2001-10-25 23:21:12 +00:00
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
if ( $total_pages == 1 )
|
2001-05-07 23:04:16 +00:00
|
|
|
{
|
2002-04-02 14:04:18 +00:00
|
|
|
return '';
|
2001-05-07 23:04:16 +00:00
|
|
|
}
|
|
|
|
|
2001-10-25 23:21:12 +00:00
|
|
|
$on_page = floor($start_item / $per_page) + 1;
|
2001-05-07 23:04:16 +00:00
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
$page_string = '';
|
2002-02-08 01:33:36 +00:00
|
|
|
if ( $total_pages > 10 )
|
2001-05-07 23:04:16 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
$init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
|
2001-10-25 23:21:12 +00:00
|
|
|
|
|
|
|
for($i = 1; $i < $init_page_max + 1; $i++)
|
2001-05-07 23:04:16 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
|
|
|
|
if ( $i < $init_page_max )
|
2001-10-25 23:21:12 +00:00
|
|
|
{
|
|
|
|
$page_string .= ", ";
|
|
|
|
}
|
2001-05-07 23:04:16 +00:00
|
|
|
}
|
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
if ( $total_pages > 3 )
|
2001-05-07 23:04:16 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
if ( $on_page > 1 && $on_page < $total_pages )
|
2001-10-25 23:21:12 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string .= ( $on_page > 5 ) ? ' ... ' : ', ';
|
2001-05-27 03:11:27 +00:00
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
$init_page_min = ( $on_page > 4 ) ? $on_page : 5;
|
|
|
|
$init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
|
2001-05-07 23:04:16 +00:00
|
|
|
|
2001-10-25 23:21:12 +00:00
|
|
|
for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++)
|
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
|
|
|
|
if ( $i < $init_page_max + 1 )
|
2001-10-25 23:21:12 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string .= ', ';
|
2001-10-25 23:21:12 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-09 21:09:00 +00:00
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : ', ';
|
2001-10-25 23:21:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string .= ' ... ';
|
2001-10-25 23:21:12 +00:00
|
|
|
}
|
2001-06-09 21:09:00 +00:00
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
for($i = $total_pages - 2; $i < $total_pages + 1; $i++)
|
2001-05-07 23:04:16 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
|
2001-10-25 23:21:12 +00:00
|
|
|
if( $i < $total_pages )
|
2001-06-09 21:09:00 +00:00
|
|
|
{
|
2001-10-25 23:21:12 +00:00
|
|
|
$page_string .= ", ";
|
2001-06-09 21:09:00 +00:00
|
|
|
}
|
2001-05-07 23:04:16 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-25 23:21:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for($i = 1; $i < $total_pages + 1; $i++)
|
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
|
|
|
|
if ( $i < $total_pages )
|
2001-10-25 23:21:12 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string .= ', ';
|
2001-10-25 23:21:12 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-07 23:04:16 +00:00
|
|
|
}
|
2001-05-27 03:11:27 +00:00
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
if ( $add_prevnext_text )
|
2001-05-07 23:04:16 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
if ( $on_page > 1 )
|
2001-05-07 23:04:16 +00:00
|
|
|
{
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string = ' <a href="' . append_sid($base_url . "&start=" . ( ( $on_page - 2 ) * $per_page ) ) . '">' . $lang['Previous'] . '</a> ' . $page_string;
|
2001-05-07 23:04:16 +00:00
|
|
|
}
|
2001-10-25 23:21:12 +00:00
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
if ( $on_page < $total_pages )
|
2001-05-07 23:04:16 +00:00
|
|
|
{
|
2002-02-08 20:54:21 +00:00
|
|
|
$page_string .= ' <a href="' . append_sid($base_url . "&start=" . ( $on_page * $per_page ) ) . '">' . $lang['Next'] . '</a>';
|
2001-05-07 23:04:16 +00:00
|
|
|
}
|
2001-06-11 00:22:35 +00:00
|
|
|
|
2001-05-07 23:04:16 +00:00
|
|
|
}
|
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
$page_string = $lang['Goto_page'] . ' ' . $page_string;
|
2001-10-25 23:21:12 +00:00
|
|
|
|
2001-05-07 23:04:16 +00:00
|
|
|
return $page_string;
|
|
|
|
}
|
|
|
|
|
2002-03-25 12:41:41 +00:00
|
|
|
//
|
|
|
|
// This does exactly what preg_quote() does in PHP 4-ish
|
|
|
|
// If you just need the 1-parameter preg_quote call, then don't bother using this.
|
|
|
|
//
|
|
|
|
function phpbb_preg_quote($str, $delimiter)
|
|
|
|
{
|
|
|
|
$text = preg_quote($str);
|
2002-04-02 14:04:18 +00:00
|
|
|
$text = str_replace($delimiter, '\\' . $delimiter, $text);
|
2002-03-25 12:41:41 +00:00
|
|
|
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2001-09-02 22:08:01 +00:00
|
|
|
//
|
2001-09-09 23:22:29 +00:00
|
|
|
// Obtain list of naughty words and build preg style replacement arrays for use by the
|
|
|
|
// calling script, note that the vars are passed as references this just makes it easier
|
|
|
|
// to return both sets of arrays
|
2001-09-02 22:08:01 +00:00
|
|
|
//
|
|
|
|
function obtain_word_list(&$orig_word, &$replacement_word)
|
|
|
|
{
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Define censored word matches
|
|
|
|
//
|
|
|
|
$sql = "SELECT word, replacement
|
|
|
|
FROM " . WORDS_TABLE;
|
2002-02-08 01:44:27 +00:00
|
|
|
if( !($result = $db->sql_query($sql)) )
|
2001-09-02 22:08:01 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
message_die(GENERAL_ERROR, 'Could not get censored words from database', '', __LINE__, __FILE__, $sql);
|
2001-09-02 22:08:01 +00:00
|
|
|
}
|
2002-02-08 01:44:27 +00:00
|
|
|
|
|
|
|
if ( $row = $db->sql_fetchrow($result) )
|
2001-09-02 22:08:01 +00:00
|
|
|
{
|
2002-02-08 01:44:27 +00:00
|
|
|
do
|
2001-09-02 22:08:01 +00:00
|
|
|
{
|
2002-04-02 14:04:18 +00:00
|
|
|
$orig_word[] = '#\b(' . str_replace('\*', '\w*?', phpbb_preg_quote($row['word'], '#')) . ')\b#i';
|
2002-03-25 12:39:17 +00:00
|
|
|
$replacement_word[] = $row['replacement'];
|
2001-09-02 22:08:01 +00:00
|
|
|
}
|
2002-02-08 01:44:27 +00:00
|
|
|
while ( $row = $db->sql_fetchrow($result) );
|
2001-09-02 22:08:01 +00:00
|
|
|
}
|
|
|
|
|
2002-02-08 01:33:36 +00:00
|
|
|
return true;
|
2001-09-02 22:08:01 +00:00
|
|
|
}
|
|
|
|
|
2001-09-25 18:18:47 +00:00
|
|
|
//
|
2002-03-18 13:35:23 +00:00
|
|
|
// This is general replacement for die(), allows templated
|
|
|
|
// output in users (or default) language, etc.
|
2001-09-25 18:18:47 +00:00
|
|
|
//
|
2002-03-18 13:35:23 +00:00
|
|
|
// $msg_code can be one of these constants:
|
2001-09-25 18:18:47 +00:00
|
|
|
//
|
2002-03-18 13:35:23 +00:00
|
|
|
// GENERAL_MESSAGE : Use for any simple text message, eg. results
|
|
|
|
// of an operation, authorisation failures, etc.
|
2001-09-25 18:18:47 +00:00
|
|
|
//
|
2002-03-18 13:35:23 +00:00
|
|
|
// GENERAL ERROR : Use for any error which occurs _AFTER_ the
|
|
|
|
// common.php include and session code, ie. most errors in
|
|
|
|
// pages/functions
|
2001-09-25 18:18:47 +00:00
|
|
|
//
|
2002-03-18 13:35:23 +00:00
|
|
|
// CRITICAL_MESSAGE : Used when basic config data is available but
|
|
|
|
// a session may not exist, eg. banned users
|
2001-09-25 18:18:47 +00:00
|
|
|
//
|
2002-03-18 13:35:23 +00:00
|
|
|
// CRITICAL_ERROR : Used when config data cannot be obtained, eg
|
|
|
|
// no database connection. Should _not_ be used in 99.5% of cases
|
2001-09-25 18:18:47 +00:00
|
|
|
//
|
2002-03-18 13:35:23 +00:00
|
|
|
function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '')
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2002-04-20 00:22:29 +00:00
|
|
|
global $db, $template, $board_config, $theme, $lang, $phpEx, $phpbb_root_path, $nav_links, $gen_simple_header;
|
2001-09-25 18:18:47 +00:00
|
|
|
global $userdata, $user_ip, $session_length;
|
|
|
|
global $starttime;
|
|
|
|
|
|
|
|
$sql_store = $sql;
|
2002-01-22 18:13:59 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get SQL error if we are debugging. Do this as soon as possible to prevent
|
|
|
|
// subsequent queries from overwriting the status of sql_error()
|
|
|
|
//
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) )
|
2002-01-22 18:13:59 +00:00
|
|
|
{
|
|
|
|
$sql_error = $db->sql_error();
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
$debug_text = '';
|
2002-01-22 18:13:59 +00:00
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $sql_error['message'] != '' )
|
2002-01-22 18:13:59 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
$debug_text .= '<br /><br />SQL Error : ' . $sql_error['code'] . ' ' . $sql_error['message'];
|
2002-01-22 18:13:59 +00:00
|
|
|
}
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $sql_store != '' )
|
2002-01-22 18:13:59 +00:00
|
|
|
{
|
|
|
|
$debug_text .= "<br /><br />$sql_store";
|
|
|
|
}
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $err_line != '' && $err_file != '' )
|
2002-01-22 18:13:59 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
$debug_text .= '</br /><br />Line : ' . $err_line . '<br />File : ' . $err_file;
|
2002-01-22 18:13:59 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-25 18:18:47 +00:00
|
|
|
|
|
|
|
if( empty($userdata) && ( $msg_code == GENERAL_MESSAGE || $msg_code == GENERAL_ERROR ) )
|
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
$userdata = session_pagestart($user_ip, PAGE_INDEX);
|
2001-09-25 18:18:47 +00:00
|
|
|
init_userprefs($userdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the header hasn't been output then do it
|
|
|
|
//
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( !defined('HEADER_INC') && $msg_code != CRITICAL_ERROR )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( empty($lang) )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( !empty($board_config['default_lang']) )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2001-10-11 12:18:37 +00:00
|
|
|
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.'.$phpEx);
|
2001-09-25 18:18:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-10-11 12:18:37 +00:00
|
|
|
include($phpbb_root_path . 'language/lang_english/lang_main.'.$phpEx);
|
2001-09-25 18:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( empty($template) )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
$template = new Template($phpbb_root_path . 'templates/' . $board_config['board_template']);
|
2001-09-25 18:18:47 +00:00
|
|
|
}
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( empty($theme) )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2001-12-16 01:27:16 +00:00
|
|
|
$theme = setup_style($board_config['default_style']);
|
2001-09-25 18:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Load the Page Header
|
|
|
|
//
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( !defined('IN_ADMIN') )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
|
|
|
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
include($phpbb_root_path . 'admin/page_header_admin.'.$phpEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch($msg_code)
|
|
|
|
{
|
|
|
|
case GENERAL_MESSAGE:
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $msg_title == '' )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
|
|
|
$msg_title = $lang['Information'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CRITICAL_MESSAGE:
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $msg_title == '' )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
|
|
|
$msg_title = $lang['Critical_Information'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GENERAL_ERROR:
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $msg_text == '' )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
|
|
|
$msg_text = $lang['An_error_occured'];
|
|
|
|
}
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $msg_title == '' )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
|
|
|
$msg_title = $lang['General_Error'];
|
|
|
|
}
|
|
|
|
|
|
|
|
case CRITICAL_ERROR:
|
|
|
|
//
|
|
|
|
// Critical errors mean we cannot rely on _ANY_ DB information being
|
|
|
|
// available so we're going to dump out a simple echo'd statement
|
|
|
|
//
|
2001-10-11 12:18:37 +00:00
|
|
|
include($phpbb_root_path . 'language/lang_english/lang_main.'.$phpEx);
|
2001-09-25 18:18:47 +00:00
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $msg_text == '' )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
|
|
|
$msg_text = $lang['A_critical_error'];
|
|
|
|
}
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $msg_title == '' )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
$msg_title = 'phpBB : <b>' . $lang['Critical_Error'] . '</b>';
|
2001-09-25 18:18:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Add on DEBUG info if we've enabled debug mode and this is an error. This
|
|
|
|
// prevents debug info being output for general messages should DEBUG be
|
|
|
|
// set TRUE by accident (preventing confusion for the end user!)
|
|
|
|
//
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( $debug_text != '' )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2002-03-18 13:35:23 +00:00
|
|
|
$msg_text = $msg_text . '<br /><br /><b><u>DEBUG MODE</u></b>' . $debug_text;
|
2001-09-25 18:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( $msg_code != CRITICAL_ERROR )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
2002-02-12 17:14:39 +00:00
|
|
|
if ( !empty($lang[$msg_text]) )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
|
|
|
$msg_text = $lang[$msg_text];
|
|
|
|
}
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( !defined('IN_ADMIN') )
|
2001-10-14 15:48:38 +00:00
|
|
|
{
|
|
|
|
$template->set_filenames(array(
|
2002-03-18 13:35:23 +00:00
|
|
|
'message_body' => 'message_body.tpl')
|
2001-10-14 15:48:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$template->set_filenames(array(
|
2002-03-18 13:35:23 +00:00
|
|
|
'message_body' => 'admin/admin_message_body.tpl')
|
2001-10-14 15:48:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2001-09-25 18:18:47 +00:00
|
|
|
$template->assign_vars(array(
|
2002-03-18 13:35:23 +00:00
|
|
|
'MESSAGE_TITLE' => $msg_title,
|
|
|
|
'MESSAGE_TEXT' => $msg_text)
|
2001-09-25 18:18:47 +00:00
|
|
|
);
|
2002-03-18 13:35:23 +00:00
|
|
|
$template->pparse('message_body');
|
2001-09-25 18:18:47 +00:00
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
if ( !defined('IN_ADMIN') )
|
2001-09-25 18:18:47 +00:00
|
|
|
{
|
|
|
|
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
include($phpbb_root_path . 'admin/page_footer_admin.'.$phpEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo "<html>\n<body>\n" . $msg_title . "\n<br /><br />\n" . $msg_text . "</body>\n</html>";
|
|
|
|
}
|
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2002-03-18 13:35:23 +00:00
|
|
|
?>
|