= time())
return;
if (!empty($modSettings['autoOptMaxOnline']))
{
$request = db_query("
SELECT COUNT(session)
FROM {$db_prefix}log_online", __FILE__, __LINE__);
list ($dont_do_it) = mysql_fetch_row($request);
mysql_free_result($request);
if ($dont_do_it > $modSettings['autoOptMaxOnline'])
return;
}
$request = db_query("
SHOW TABLES LIKE '" . str_replace('_', '\_', $db_prefix) . "%'", __FILE__, __LINE__);
$tables = array();
while ($row = mysql_fetch_row($request))
$tables[] = $row[0];
mysql_free_result($request);
updateSettings(array('autoOptLastOpt' => time()));
db_query("
OPTIMIZE TABLE `" . implode('`, `', $tables) . '`', __FILE__, __LINE__);
}
// Load all the important user information...
function loadUserSettings()
{
global $modSettings, $user_settings;
global $ID_MEMBER, $db_prefix, $cookiename, $user_info, $language;
// Check first the cookie, then the session.
if (isset($_COOKIE[$cookiename]))
{
$_COOKIE[$cookiename] = stripslashes($_COOKIE[$cookiename]);
// Fix a security hole in PHP 4.3.9 and below...
if (preg_match('~^a:3:\{i:0;(i:\d{1,6}|s:[1-6]:"\d{1,6}");i:1;s:(0|32):"([a-fA-F0-9]{32})?";i:2;i:\d{1,12};\}$~', $_COOKIE[$cookiename]) == 1)
{
list ($ID_MEMBER, $password) = @unserialize($_COOKIE[$cookiename]);
$ID_MEMBER = !empty($ID_MEMBER) ? (int) $ID_MEMBER : 0;
}
else
$ID_MEMBER = 0;
}
elseif (isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
{
list ($ID_MEMBER, $password, $login_span) = @unserialize(stripslashes($_SESSION['login_' . $cookiename]));
$ID_MEMBER = !empty($ID_MEMBER) && $login_span > time() ? (int) $ID_MEMBER : 0;
}
else
$ID_MEMBER = 0;
// Only load this stuff if the user isn't a guest.
if ($ID_MEMBER != 0)
{
$request = db_query("
SELECT mem.*, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH
FROM {$db_prefix}members AS mem
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = $ID_MEMBER)
WHERE mem.ID_MEMBER = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);
// Did we find 'im? If not, junk it.
if (mysql_num_rows($request) != 0)
{
// The base settings array.
$user_settings = mysql_fetch_assoc($request);
// Wrong password or not activated - either way, you're going nowhere.
$ID_MEMBER = md5_hmac($user_settings['passwd'], 'ys') != $password || empty($user_settings['is_activated']) ? 0 : $user_settings['ID_MEMBER'];
}
else
$ID_MEMBER = 0;
mysql_free_result($request);
}
// Found 'im, let's set up the variables.
if ($ID_MEMBER != 0)
{
if (empty($_SESSION['ID_MSG_LAST_VISIT']))
{
$_SESSION['ID_MSG_LAST_VISIT'] = $user_settings['ID_MSG_LAST_VISIT'];
unset($user_settings['ID_MSG_LAST_VISIT']);
updateMemberData($ID_MEMBER, array('ID_MSG_LAST_VISIT' => (int) $modSettings['maxMsgID'], 'lastLogin' => time(), 'memberIP' => '\'' . $_SERVER['REMOTE_ADDR'] . '\''));
$user_settings['lastLogin'] = time();
}
$username = $user_settings['memberName'];
if (empty($user_settings['additionalGroups']))
$user_info = array(
'groups' => array($user_settings['ID_GROUP'], $user_settings['ID_POST_GROUP'])
);
else
$user_info = array(
'groups' => array_merge(
array($user_settings['ID_GROUP'], $user_settings['ID_POST_GROUP']),
explode(',', $user_settings['additionalGroups'])
)
);
}
// If the user is a guest, initialize all the critial user settings.
else
{
// This is what a guest's variables should be.
$username = '';
$user_info = array('groups' => array(-1));
$user_settings = array();
if (isset($_COOKIE[$cookiename]))
$_COOKIE[$cookiename] = '';
}
// Set up the $user_info array.
$user_info += array(
'username' => $username,
'name' => isset($user_settings['realName']) ? $user_settings['realName'] : '',
'email' => isset($user_settings['emailAddress']) ? $user_settings['emailAddress'] : '',
'passwd' => isset($user_settings['passwd']) ? $user_settings['passwd'] : '',
'language' => empty($user_settings['lngfile']) || empty($modSettings['userLanguage']) ? $language : $user_settings['lngfile'],
'is_guest' => $ID_MEMBER == 0,
'is_admin' => in_array(1, $user_info['groups']),
'theme' => empty($user_settings['ID_THEME']) ? 0 : $user_settings['ID_THEME'],
'last_login' => empty($user_settings['lastLogin']) ? 0 : $user_settings['lastLogin'],
'ip' => $_SERVER['REMOTE_ADDR'],
'posts' => empty($user_settings['posts']) ? 0 : $user_settings['posts'],
'time_format' => empty($user_settings['timeFormat']) ? $modSettings['time_format'] : $user_settings['timeFormat'],
'time_offset' => empty($user_settings['timeOffset']) ? 0 : $user_settings['timeOffset'],
'avatar' => array(
'url' => isset($user_settings['avatar']) ? $user_settings['avatar'] : '',
'ID_ATTACH' => isset($user_settings['ID_ATTACH']) ? $user_settings['ID_ATTACH'] : 0
),
'smiley_set' => isset($user_settings['smileySet']) ? $user_settings['smileySet'] : '',
'messages' => empty($user_settings['instantMessages']) ? 0 : $user_settings['instantMessages'],
'unread_messages' => empty($user_settings['unreadMessages']) ? 0 : $user_settings['unreadMessages'],
'total_time_logged_in' => empty($user_settings['totalTimeLoggedIn']) ? 0 : $user_settings['totalTimeLoggedIn'],
'permissions' => array()
);
$user_info['groups'] = array_unique($user_info['groups']);
if (!empty($modSettings['userLanguage']) && !empty($_REQUEST['language']))
{
$user_info['language'] = strtr($_REQUEST['language'], './\\:', '____');
$_SESSION['language'] = $user_info['language'];
}
elseif (!empty($modSettings['userLanguage']) && !empty($_SESSION['language']))
$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
// Just build this here, it makes it easier to change/use.
if ($user_info['is_guest'])
$user_info['query_see_board'] = 'FIND_IN_SET(-1, b.memberGroups)';
// Administrators can see all boards.
elseif ($user_info['is_admin'])
$user_info['query_see_board'] = '1';
// Registered user.... just the groups in $user_info['groups'].
else
$user_info['query_see_board'] = '(FIND_IN_SET(' . implode(', b.memberGroups) OR FIND_IN_SET(', $user_info['groups']) . ', b.memberGroups))';
}
// MD5 Encryption used for passwords.
function md5_hmac($data, $key)
{
$key = str_pad(strlen($key) <= 64 ? $key : pack('H*', md5($key)), 64, chr(0x00));
return md5(($key ^ str_repeat(chr(0x5c), 64)) . pack('H*', md5(($key ^ str_repeat(chr(0x36), 64)). $data)));
}
// Check for moderators and see if they have access to the board.
function loadBoard()
{
global $txt, $db_prefix, $scripturl, $context;
global $board_info, $board, $topic, $ID_MEMBER, $user_info;
// Assume they are not a moderator.
$user_info['is_mod'] = false;
$context['user']['is_mod'] = &$user_info['is_mod'];
// Start the linktree off empty..
$context['linktree'] = array();
// Load this board only if the it is specified.
if (empty($board) && empty($topic))
{
$board_info = array('moderators' => array());
return;
}
$request = db_query("
SELECT
c.ID_CAT, b.name AS bname, b.description, b.numTopics, b.memberGroups,
b.ID_PARENT, c.name AS cname, IFNULL(mem.ID_MEMBER, 0) AS ID_MODERATOR,
mem.realName" . (!empty($topic) ? ", b.ID_BOARD" : '') . ", b.childLevel,
b.ID_THEME, b.override_theme, b.use_local_permissions
FROM {$db_prefix}boards AS b" . (!empty($topic) ? ", {$db_prefix}topics AS t" : '') . "
LEFT JOIN {$db_prefix}categories AS c ON (c.ID_CAT = b.ID_CAT)
LEFT JOIN {$db_prefix}moderators AS mods ON (mods.ID_BOARD = " . (empty($topic) ? $board : 't.ID_BOARD') . ")
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = mods.ID_MEMBER)
WHERE b.ID_BOARD = " . (empty($topic) ? $board : "t.ID_BOARD
AND t.ID_TOPIC = $topic"), __FILE__, __LINE__);
// If there aren't any, skip.
if (mysql_num_rows($request) > 0)
{
$row = mysql_fetch_assoc($request);
// Set the current board.
if (!empty($row['ID_BOARD']))
$board = $row['ID_BOARD'];
// Basic operating information. (globals... :/)
$board_info = array(
'moderators' => array(),
'cat' => array(
'id' => $row['ID_CAT'],
'name' => $row['cname']
),
'name' => $row['bname'],
'description' => $row['description'],
'num_topics' => $row['numTopics'],
'parent_boards' => getBoardParents($row['ID_PARENT']),
'parent' => $row['ID_PARENT'],
'child_level' => $row['childLevel'],
'theme' => $row['ID_THEME'],
'override_theme' => !empty($row['override_theme']),
'use_local_permissions' => $row['use_local_permissions'] == 1
);
// Load the membergroups allowed, and check permissions.
$board_info['groups'] = $row['memberGroups'] == '' ? array() : explode(',', $row['memberGroups']);
if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
$board_info['error'] = 'access';
do
{
if (!empty($row['ID_MODERATOR']))
$board_info['moderators'][$row['ID_MODERATOR']] = array(
'id' => $row['ID_MODERATOR'],
'name' => $row['realName'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MODERATOR'],
'link' => '' . $row['realName'] . ''
);
}
while ($row = mysql_fetch_assoc($request));
// Now check if the user is a moderator.
$user_info['is_mod'] = isset($board_info['moderators'][$ID_MEMBER]);
// Build up the linktree...
$context['linktree'] = array_merge(
$context['linktree'],
array(array(
'url' => $scripturl . '#' . $board_info['cat']['id'],
'name' => $board_info['cat']['name']
)),
array_reverse($board_info['parent_boards']),
array(array(
'url' => $scripturl . '?board=' . $board . '.0',
'name' => $board_info['name']
))
);
}
else
{
// Otherwise the topic is invalid, there are no moderators, etc.
$board_info = array(
'moderators' => array(),
'error' => 'exist'
);
$topic = null;
$board = 0;
}
mysql_free_result($request);
if (!empty($topic))
$_GET['board'] = (int) $board;
// Set the template contextual information.
$context['user']['is_mod'] = &$user_info['is_mod'];
$context['current_topic'] = $topic;
$context['current_board'] = $board;
// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
if (!empty($board_info['error']) && !($board_info['error'] == 'access' && $user_info['is_mod']))
{
// The permissions and theme need loading, just to make sure everything goes smoothly.
loadPermissions();
loadTheme();
fatal_lang_error('topic_gone', false);
}
if ($user_info['is_mod'])
$user_info['groups'][] = 3;
}
// Load this user's permissions.
function loadPermissions()
{
global $user_info, $db_prefix, $board, $board_info;
$user_info['permissions'] = array();
if ($user_info['is_admin'])
return;
$removals = array();
// Get the general permissions.
$request = db_query("
SELECT permission, addDeny
FROM {$db_prefix}permissions
WHERE ID_GROUP IN (" . implode(', ', $user_info['groups']) . ')', __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
if (empty($row['addDeny']))
$removals[] = $row['permission'];
else
$user_info['permissions'][] = $row['permission'];
}
mysql_free_result($request);
// Get the board permissions.
if (!empty($board))
{
// Make sure the board (if any) has been loaded by loadBoard().
if (!isset($board_info['use_local_permissions']))
fatal_lang_error('smf232');
$request = db_query("
SELECT permission, addDeny
FROM {$db_prefix}board_permissions
WHERE ID_GROUP IN (" . implode(', ', $user_info['groups']) . ")
AND ID_BOARD = " . ($board_info['use_local_permissions'] ? $board : '0'), __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
if (empty($row['addDeny']))
$removals[] = $row['permission'];
else
$user_info['permissions'][] = $row['permission'];
}
mysql_free_result($request);
}
// Remove all the permissions they shouldn't have ;).
$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
// Banned? Watch, don't touch..
banPermissions();
}
// Loads an array of users' data by ID or memberName.
function loadMemberData($users, $is_name = false, $set = 'normal')
{
global $user_profile, $db_prefix, $modSettings, $board_info;
// Can't just look for no users :P.
if (empty($users))
return false;
// Make sure it's an array.
$users = !is_array($users) ? array($users) : array_unique($users);
if ($set == 'normal')
{
// No need for moderator fixes if there are none or none among the requested users.
if (empty($board_info['moderators']) || (!$is_name && count(array_intersect($users, array_keys($board_info['moderators']))) == 0))
$moderator_fix = array('pg' => '', 'mg' => 'mem.ID_GROUP');
// Overwrite your primary group to moderator, if a user happens to be one.
else
$moderator_fix = array(
'pg' => 'AND mem.ID_MEMBER NOT IN (' . implode(', ', array_keys($board_info['moderators'])) . ')',
'mg' => 'IF(mem.ID_MEMBER IN (' . implode(', ', array_keys($board_info['moderators'])) . '), 3, mem.ID_GROUP)'
);
$select_columns = "
IFNULL(lo.logTime, 0) AS isOnline, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, mem.signature,
mem.personalText, mem.location, mem.gender, mem.avatar, mem.ID_MEMBER, mem.memberName, mem.realName,
mem.emailAddress, mem.hideEmail, mem.dateRegistered, mem.websiteTitle, mem.websiteUrl, mem.birthdate,
mem.memberIP, mem.location, mem.ICQ, mem.AIM, mem.YIM, mem.MSN, mem.posts, mem.lastLogin, mem.karmaGood,
mem.ID_POST_GROUP, mem.karmaBad, mem.lngfile, mem.ID_GROUP, mem.timeOffset, mem.showOnline,
mg.onlineColor AS member_group_color, IFNULL(mg.groupName, '') AS member_group,
pg.onlineColor AS post_group_color, IFNULL(pg.groupName, '') AS post_group,
IF((mem.ID_GROUP = 0 OR mg.stars = '')$moderator_fix[pg], pg.stars, mg.stars) AS stars" . (!empty($modSettings['titlesEnable']) ? ',
mem.usertitle' : '');
$select_tables = "
LEFT JOIN {$db_prefix}log_online AS lo ON (lo.ID_MEMBER = mem.ID_MEMBER)
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS pg ON (pg.ID_GROUP = mem.ID_POST_GROUP)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = $moderator_fix[mg])";
}
elseif ($set == 'profile')
{
$select_columns = "
IFNULL(lo.logTime, 0) AS isOnline, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, mem.signature,
mem.personalText, mem.location, mem.gender, mem.avatar, mem.ID_MEMBER, mem.memberName, mem.realName,
mem.emailAddress, mem.hideEmail, mem.dateRegistered, mem.websiteTitle, mem.websiteUrl, mem.birthdate,
mem.location, mem.ICQ, mem.AIM, mem.YIM, mem.MSN, mem.posts, mem.lastLogin, mem.karmaGood, mem.karmaBad,
mem.memberIP, mem.lngfile, mem.ID_GROUP, mem.ID_THEME, mem.im_ignore_list, mem.im_email_notify,
mem.timeOffset" . (!empty($modSettings['titlesEnable']) ? ', mem.usertitle' : '') . ", mem.timeFormat,
mem.secretQuestion, mem.is_activated, mem.additionalGroups, mem.smileySet, mem.showOnline,
mem.totalTimeLoggedIn, mem.ID_POST_GROUP, mem.notifyAnnouncements, mem.notifyOnce,
mg.onlineColor AS member_group_color, IFNULL(mg.groupName, '') AS member_group,
pg.onlineColor AS post_group_color, IFNULL(pg.groupName, '') AS post_group,
IF((mem.ID_GROUP = 0 OR mg.stars = ''), pg.stars, mg.stars) AS stars";
$select_tables = "
LEFT JOIN {$db_prefix}log_online AS lo ON (lo.ID_MEMBER = mem.ID_MEMBER)
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS pg ON (pg.ID_GROUP = mem.ID_POST_GROUP)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP)";
}
elseif ($set == 'minimal')
{
$select_columns = '
mem.ID_MEMBER, mem.memberName, mem.realName, mem.emailAddress, mem.hideEmail, mem.dateRegistered,
mem.posts, mem.lastLogin, mem.memberIP, mem.lngfile, mem.ID_GROUP';
$select_tables = '';
}
// Load the data.
$request = db_query("
SELECT$select_columns
FROM {$db_prefix}members AS mem$select_tables
WHERE mem." . ($is_name ? 'memberName' : 'ID_MEMBER') . (count($users) == 1 ? " = '" . current($users) . "'" : " IN ('" . implode("', '", $users) . "')"), __FILE__, __LINE__);
$loaded_ids = array();
while ($row = mysql_fetch_assoc($request))
{
$loaded_ids[] = $row['ID_MEMBER'];
$row['options'] = array();
$user_profile[$row['ID_MEMBER']] = $row;
}
mysql_free_result($request);
if (!empty($loaded_ids) && $set != 'minimal')
{
$request = db_query("
SELECT *
FROM {$db_prefix}themes
WHERE ID_MEMBER" . (count($loaded_ids) == 1 ? ' = ' . $loaded_ids[0] : ' IN (' . implode(', ', $loaded_ids) . ')'), __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
$user_profile[$row['ID_MEMBER']]['options'][$row['variable']] = $row['value'];
mysql_free_result($request);
}
return empty($loaded_ids) ? false : $loaded_ids;
}
// Loads the user's basic values... meant for template/theme usage.
function loadMemberContext($user)
{
global $themeUser, $user_profile, $txt, $scripturl, $user_info;
global $context, $modSettings, $ID_MEMBER;
global $board_info, $settings, $db_prefix;
static $dataLoaded = array();
// If this person's data is already loaded, skip it.
if (isset($dataLoaded[$user]))
return true;
// We can't load guests or members not loaded by loadMemberData()!
if ($user == 0 || !isset($user_profile[$user]))
return false;
// Well, it's loaded now anyhow.
$dataLoaded[$user] = true;
$profile = $user_profile[$user];
// Censor everything.
censorText($profile['signature']);
censorText($profile['personalText']);
censorText($profile['location']);
// Set things up to be used before hand.
$gendertxt = $profile['gender'] == 2 ? $txt[239] : ($profile['gender'] == 1 ? $txt[238] : '');
$profile['signature'] = str_replace(array("\n", "\r"), array('
', ''), $profile['signature']);
$profile['signature'] = doUBBC($profile['signature']);
$profile['is_online'] = (!empty($profile['showOnline']) || allowedTo('moderate_forum')) && $profile['isOnline'] > 0;
$profile['stars'] = empty($profile['stars']) ? array('', '') : explode('#', $profile['stars']);
if (stristr($profile['avatar'], 'http://') && !empty($modSettings['avatar_check_size']))
{
$sizes = url_image_size($profile['avatar']);
// Does your avatar still fit the maximum size?
if ($modSettings['avatar_action_too_large'] == 'option_refuse' && is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
{
// Fix it permanently!
$profile['avatar'] = '';
updateMemberData($profile['ID_MEMBER'], array('avatar' => '\'\''));
}
}
// What a monstrous array...
$themeUser[$user] = array(
'username' => &$profile['memberName'],
'name' => &$profile['realName'],
'id' => &$profile['ID_MEMBER'],
'is_guest' => $profile['ID_MEMBER'] == 0,
'title' => !empty($modSettings['titlesEnable']) ? $profile['usertitle'] : '',
'href' => $scripturl . '?action=profile;u=' . $profile['ID_MEMBER'],
'link' => '' . $profile['realName'] . '',
'email' => &$profile['emailAddress'],
'hide_email' => (!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']) || (!empty($profile['hideEmail']) && !empty($modSettings['allow_hideEmail']) && !allowedTo('moderate_forum')),
'email_public' => (empty($profile['hideEmail']) || empty($modSettings['allow_hideEmail'])) && (empty($modSettings['guest_hideContacts']) || !$user_info['is_guest']),
'registered' => empty($profile['dateRegistered']) ? $txt[470] : timeformat($profile['dateRegistered']),
'blurb' => &$profile['personalText'],
'gender' => array(
'name' => $gendertxt,
'image' => !empty($profile['gender']) ? '
' : ''
),
'website' => array(
'title' => &$profile['websiteTitle'],
'url' => &$profile['websiteUrl'],
),
'birth_date' => &$profile['birthdate'],
'signature' => &$profile['signature'],
'location' => &$profile['location'],
'icq' => $profile['ICQ'] != '' && (empty($modSettings['guest_hideContacts']) || !$user_info['is_guest']) ? array(
'name' => &$profile['ICQ'],
'href' => 'http://web.icq.com/whitepages/about_me/1,,,00.html?Uin=' . $profile['ICQ'],
'link' => '',
'link_text' => '' . $profile['ICQ'] . '',
) : array('name' => '', 'add' => '', 'href' => '', 'link' => '', 'link_text' => ''),
'aim' => $profile['AIM'] != '' && (empty($modSettings['guest_hideContacts']) || !$user_info['is_guest']) ? array(
'name' => &$profile['AIM'],
'href' => 'aim:goim?screenname=' . urlencode($profile['AIM']) . '&message=' . $txt['aim_default_message'],
'link' => '
',
'link_text' => '' . $profile['AIM'] . ''
) : array('name' => '', 'href' => '', 'link' => '', 'link_text' => ''),
'yim' => $profile['YIM'] != '' && (empty($modSettings['guest_hideContacts']) || !$user_info['is_guest']) ? array(
'name' => &$profile['YIM'],
'href' => 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($profile['YIM']),
'link' => '',
'link_text' => '' . $profile['YIM'] . ''
) : array('name' => '', 'href' => '', 'link' => '', 'link_text' => ''),
'msn' => $profile['MSN'] !='' && (empty($modSettings['guest_hideContacts']) || !$user_info['is_guest']) ? array(
'name' => &$profile['MSN'],
'href' => 'http://members.msn.com/' . $profile['MSN'],
'link' => '
',
'link_text' => '' . $profile['MSN'] . ''
) : array('name' => '', 'href' => '', 'link' => '', 'link_text' => ''),
'real_posts' => $profile['posts'],
'posts' => $profile['posts'] > 100000 ? $txt[683] : ($profile['posts'] == 1337 ? 'leet' : comma_format($profile['posts'])),
'avatar' => array(
'name' => &$profile['avatar'],
'image' => $profile['avatar'] == '' ? ($profile['ID_ATTACH'] > 0 && !empty($modSettings['avatar_allow_upload']) ? '' : '') : (stristr($profile['avatar'], 'http://') && !empty($modSettings['avatar_allow_external_url']) ? '
' : (!empty($modSettings['avatar_allow_server_stored']) ? '
' : '')),
'href' => $profile['avatar'] == '' ? ($profile['ID_ATTACH'] > 0 && !empty($modSettings['avatar_allow_upload']) ? $scripturl . '?action=dlattach;id=' . $profile['ID_ATTACH'] . ';type=avatar' : '') : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']),
'url' => $profile['avatar'] == '' ? '' : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'])
),
'last_login' => empty($profile['lastLogin']) ? $txt['never'] : timeformat($profile['lastLogin']),
'karma' => array(
'good' => &$profile['karmaGood'],
'bad' => &$profile['karmaBad'],
'allow' => !$user_info['is_guest'] && $user_info['posts'] >= $modSettings['karmaMinPosts'] && allowedTo('karma_edit') && !empty($modSettings['karmaMode']) && $ID_MEMBER != $user
),
'ip' => htmlspecialchars($profile['memberIP']),
'online' => array(
'is_online' => $profile['is_online'],
'text' => &$txt[$profile['is_online'] ? 'online2' : 'online3'],
'href' => $scripturl . '?action=pm;sa=send;u=' . $profile['ID_MEMBER'],
'link' => '' . $txt[$profile['is_online'] ? 'online2' : 'online3'] . '',
'image_href' => $settings['images_url'] . ($profile['is_online'] ? '/useron' : '/useroff') . '.gif',
'label' => &$txt[$profile['is_online'] ? 'online4' : 'online5']
),
'language' => ucfirst($profile['lngfile']),
'is_activated' => !empty($profile['is_activated']),
'options' => $profile['options'],
'is_guest' => false,
'group' => $profile['member_group'],
'group_color' => $profile['member_group_color'],
'group_id' => $profile['ID_GROUP'],
'post_group' => $profile['post_group'],
'post_group_color' => $profile['post_group_color'],
'group_stars' => str_repeat('
', empty($profile['stars'][0]) ? 0 : $profile['stars'][0]),
'local_time' => timeformat(time() + ($profile['timeOffset'] - $user_info['time_offset']) * 3600, false),
);
return true;
}
// Load a theme, by ID.
function loadTheme($ID_THEME = 0, $initialize = true)
{
global $ID_MEMBER, $user_info, $board_info, $sc;
global $db_prefix, $txt, $scripturl, $mbname, $modSettings;
global $context, $settings, $options;
// The theme was specified by parameter.
if (!empty($ID_THEME))
$ID_THEME = (int) $ID_THEME;
// Use the board's specific theme.
elseif (!empty($board_info['theme']) && $board_info['override_theme'])
$ID_THEME = $board_info['theme'];
// The theme was specified by REQUEST.
elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
{
$ID_THEME = (int) $_REQUEST['theme'];
$_SESSION['ID_THEME'] = $ID_THEME;
}
// The theme was specified by REQUEST... previously.
elseif (!empty($_SESSION['ID_THEME']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
$ID_THEME = (int) $_SESSION['ID_THEME'];
// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
$ID_THEME = $user_info['theme'];
// The theme was specified by the board.
elseif (!empty($board_info['theme']))
$ID_THEME = $board_info['theme'];
// The theme is the forum's default.
else
$ID_THEME = $modSettings['theme_guests'];
// Verify the ID_THEME... no foul play.
if (empty($modSettings['theme_default']) && $ID_THEME == 1 && !allowedTo('admin_forum'))
$ID_THEME = $modSettings['theme_guests'];
elseif (!empty($modSettings['knownThemes']) && !empty($modSettings['theme_allow']) && !allowedTo('admin_forum'))
{
$themes = explode(',', $modSettings['knownThemes']);
if (!in_array($ID_THEME, $themes))
$ID_THEME = $modSettings['theme_guests'];
else
$ID_THEME = (int) $ID_THEME;
}
else
$ID_THEME = (int) $ID_THEME;
$member = empty($ID_MEMBER) ? -1 : $ID_MEMBER;
// Load variables from the current or default theme, global or this user's.
$result = db_query("
SELECT variable, value, ID_MEMBER, ID_THEME
FROM {$db_prefix}themes
WHERE ID_MEMBER IN (0, $member)
AND ID_THEME" . ($ID_THEME == 1 ? ' = 1' : " IN ($ID_THEME, 1)"), __FILE__, __LINE__);
// Pick between $settings and $options depending on whose data it is.
$themeData = array(0 => array(), $member => array());
while ($row = mysql_fetch_assoc($result))
{
// If this is the theme_dir of the default theme, store it.
if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['ID_THEME'] == '1' && empty($row['ID_MEMBER']))
$themeData[0]['default_' . $row['variable']] = $row['value'];
// If this isn't set yet, is a theme option, or is not the default theme..
if (!isset($themeData[$row['ID_MEMBER']][$row['variable']]) || $row['ID_THEME'] != '1')
$themeData[$row['ID_MEMBER']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
}
mysql_free_result($result);
$settings = $themeData[0];
$options = $themeData[$member];
$settings['theme_id'] = $ID_THEME;
$settings['actual_theme_url'] = $settings['theme_url'];
$settings['actual_images_url'] = $settings['images_url'];
$settings['actual_theme_dir'] = $settings['theme_dir'];
if (!$initialize)
return;
// Set up the contextual user array.
$context['user'] = array(
'id' => &$ID_MEMBER,
'is_logged' => !$user_info['is_guest'],
'is_guest' => &$user_info['is_guest'],
'is_admin' => &$user_info['is_admin'],
'is_mod' => false,
'username' => &$user_info['username'],
'name' => $user_info['is_guest'] ? $txt[28] : $user_info['name'],
'language' => &$user_info['language'],
'email' => &$user_info['email']
);
// Determine the current smiley set.
$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
// Some basic information...
if (!isset($context['html_headers']))
$context['html_headers'] = '';
$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
$context['session_id'] = &$sc;
$context['forum_name'] = &$mbname;
// This determines the server... not used in many places, except for login fixing.
$context['server'] = array(
'is_iis' => strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false,
'is_apache' => strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false,
'is_cgi' => strpos(php_sapi_name(), 'cgi') !== false,
);
// A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
$context['server']['needs_login_fix'] = $context['server']['is_cgi'];
// The following determines the user agent. (browser)
$context['browser'] = array(
'is_opera' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false,
'is_opera6' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 6') !== false,
'is_ie4' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 4') !== false,
'is_safari' => strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false,
'is_mac_ie' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false
);
$context['browser']['is_gecko'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$context['browser']['is_safari'];
// Internet Explorer 5 and 6 are often "emulated".
$context['browser']['is_ie6'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'];
$context['browser']['is_ie5.5'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.5') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'];
$context['browser']['is_ie5'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.0') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'];
$context['browser']['is_ie'] = $context['browser']['is_ie4'] || $context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie6'];
$context['browser']['needs_size_fix'] = ($context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie4'] || $context['browser']['is_opera6']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') === false;
// Set the top level linktree up.
array_unshift($context['linktree'], array(
'url' => &$scripturl,
'name' => &$context['forum_name']
));
// Wireless mode? Load up the wireless stuff.
if (WIRELESS)
{
$context['template_layers'] = array(WIRELESS_PROTOCOL);
$templates = array('Wireless', 'index');
}
else
{
// Custom templates to load, or just default?
if (isset($settings['theme_templates']))
$templates = explode(',', $settings['theme_templates']);
else
$templates = array('index');
// Custom template layers?
if (isset($settings['theme_layers']))
$context['template_layers'] = explode(',', $settings['theme_layers']);
else
$context['template_layers'] = array('main');
}
$txt = array();
// Load each template.... and attempt to load its associated language file.
foreach ($templates as $template)
{
loadTemplate($template);
loadLanguage($template, '', false);
}
// Load the Modifications language file, always ;). (but don't sweat it if it doesn't exist.)
loadLanguage('Modifications', '', false);
// Initialize the theme.
loadSubTemplate('init', 'ignore');
if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'always')
{
$settings['theme_url'] = $settings['default_theme_url'];
$settings['images_url'] = $settings['default_images_url'];
$settings['theme_dir'] = $settings['default_theme_dir'];
}
// Set the character set from the template.
$context['character_set'] = $txt['lang_character_set'];
$context['right_to_left'] = !empty($txt['lang_rtl']);
// Fix font size with HTML 4.01, etc.
if (isset($settings['doctype']))
$context['browser']['needs_size_fix'] |= $settings['doctype'] == 'html' && $context['browser']['is_ie6'];
}
// Load a template - if the theme doesn't include it, use the default.
function loadTemplate($template_name)
{
global $context, $settings, $txt, $scripturl, $boarddir;
// Try the current theme's first.
if (file_exists($settings['theme_dir'] . '/' . $template_name . '.template.php'))
template_include($settings['theme_dir'] . '/' . $template_name . '.template.php', true);
elseif (file_exists($settings['default_theme_dir'] . '/' . $template_name . '.template.php'))
{
// Make it known that this template uses different directories...
$settings['default_template'] = true;
template_include($settings['default_theme_dir'] . '/' . $template_name . '.template.php', true);
}
// Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it?
elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
{
$settings['default_theme_dir'] = $boarddir . '/Themes/default';
if (!empty($context['user']['is_admin']) && !isset($_GET['id']))
{
loadLanguage('Errors');
echo '