Chris@76: 999)
Chris@76: $modSettings['defaultMaxTopics'] = 20;
Chris@76: if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
Chris@76: $modSettings['defaultMaxMessages'] = 15;
Chris@76: if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
Chris@76: $modSettings['defaultMaxMembers'] = 30;
Chris@76:
Chris@76: if (!empty($modSettings['cache_enable']))
Chris@76: cache_put_data('modSettings', $modSettings, 90);
Chris@76: }
Chris@76:
Chris@76: // UTF-8 in regular expressions is unsupported on PHP(win) versions < 4.2.3.
Chris@76: $utf8 = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || @version_compare(PHP_VERSION, '4.2.3') != -1);
Chris@76:
Chris@76: // Set a list of common functions.
Chris@76: $ent_list = empty($modSettings['disableEntityCheck']) ? '&(#\d{1,7}|quot|amp|lt|gt|nbsp);' : '&(#021|quot|amp|lt|gt|nbsp);';
Chris@76: $ent_check = empty($modSettings['disableEntityCheck']) ? array('preg_replace(\'~((\d{1,7}|x[0-9a-fA-F]{1,6});)~e\', \'$smcFunc[\\\'entity_fix\\\'](\\\'\\2\\\')\', ', ')') : array('', '');
Chris@76:
Chris@76: // Preg_replace can handle complex characters only for higher PHP versions.
Chris@76: $space_chars = $utf8 ? (@version_compare(PHP_VERSION, '4.3.3') != -1 ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : "\xC2\xA0\xC2\xAD\xE2\x80\x80-\xE2\x80\x8F\xE2\x80\x9F\xE2\x80\xAF\xE2\x80\x9F\xE3\x80\x80\xEF\xBB\xBF") : '\x00-\x08\x0B\x0C\x0E-\x19\xA0';
Chris@76:
Chris@76: $smcFunc += array(
Chris@76: 'entity_fix' => create_function('$string', '
Chris@76: $num = substr($string, 0, 1) === \'x\' ? hexdec(substr($string, 1)) : (int) $string;
Chris@76: return $num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202E || $num === 0x202D ? \'\' : \'\' . $num . \';\';'),
Chris@76: 'htmlspecialchars' => create_function('$string, $quote_style = ENT_COMPAT, $charset = \'ISO-8859-1\'', '
Chris@76: global $smcFunc;
Chris@76: return ' . strtr($ent_check[0], array('&' => '&')) . 'htmlspecialchars($string, $quote_style, ' . ($utf8 ? '\'UTF-8\'' : '$charset') . ')' . $ent_check[1] . ';'),
Chris@76: 'htmltrim' => create_function('$string', '
Chris@76: global $smcFunc;
Chris@76: return preg_replace(\'~^(?:[ \t\n\r\x0B\x00' . $space_chars . ']| )+|(?:[ \t\n\r\x0B\x00' . $space_chars . ']| )+$~' . ($utf8 ? 'u' : '') . '\', \'\', ' . implode('$string', $ent_check) . ');'),
Chris@76: 'strlen' => create_function('$string', '
Chris@76: global $smcFunc;
Chris@76: return strlen(preg_replace(\'~' . $ent_list . ($utf8 ? '|.~u' : '~') . '\', \'_\', ' . implode('$string', $ent_check) . '));'),
Chris@76: 'strpos' => create_function('$haystack, $needle, $offset = 0', '
Chris@76: global $smcFunc;
Chris@76: $haystack_arr = preg_split(\'~(' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '\', ' . implode('$haystack', $ent_check) . ', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
Chris@76: $haystack_size = count($haystack_arr);
Chris@76: if (strlen($needle) === 1)
Chris@76: {
Chris@76: $result = array_search($needle, array_slice($haystack_arr, $offset));
Chris@76: return is_int($result) ? $result + $offset : false;
Chris@76: }
Chris@76: else
Chris@76: {
Chris@76: $needle_arr = preg_split(\'~(' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '\', ' . implode('$needle', $ent_check) . ', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
Chris@76: $needle_size = count($needle_arr);
Chris@76:
Chris@76: $result = array_search($needle_arr[0], array_slice($haystack_arr, $offset));
Chris@76: while (is_int($result))
Chris@76: {
Chris@76: $offset += $result;
Chris@76: if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
Chris@76: return $offset;
Chris@76: $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
Chris@76: }
Chris@76: return false;
Chris@76: }'),
Chris@76: 'substr' => create_function('$string, $start, $length = null', '
Chris@76: global $smcFunc;
Chris@76: $ent_arr = preg_split(\'~(' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '\', ' . implode('$string', $ent_check) . ', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
Chris@76: return $length === null ? implode(\'\', array_slice($ent_arr, $start)) : implode(\'\', array_slice($ent_arr, $start, $length));'),
Chris@76: 'strtolower' => $utf8 ? (function_exists('mb_strtolower') ? create_function('$string', '
Chris@76: return mb_strtolower($string, \'UTF-8\');') : create_function('$string', '
Chris@76: global $sourcedir;
Chris@76: require_once($sourcedir . \'/Subs-Charset.php\');
Chris@76: return utf8_strtolower($string);')) : 'strtolower',
Chris@76: 'strtoupper' => $utf8 ? (function_exists('mb_strtoupper') ? create_function('$string', '
Chris@76: return mb_strtoupper($string, \'UTF-8\');') : create_function('$string', '
Chris@76: global $sourcedir;
Chris@76: require_once($sourcedir . \'/Subs-Charset.php\');
Chris@76: return utf8_strtoupper($string);')) : 'strtoupper',
Chris@76: 'truncate' => create_function('$string, $length', (empty($modSettings['disableEntityCheck']) ? '
Chris@76: global $smcFunc;
Chris@76: $string = ' . implode('$string', $ent_check) . ';' : '') . '
Chris@76: preg_match(\'~^(' . $ent_list . '|.){\' . $smcFunc[\'strlen\'](substr($string, 0, $length)) . \'}~'. ($utf8 ? 'u' : '') . '\', $string, $matches);
Chris@76: $string = $matches[0];
Chris@76: while (strlen($string) > $length)
Chris@76: $string = preg_replace(\'~(?:' . $ent_list . '|.)$~'. ($utf8 ? 'u' : '') . '\', \'\', $string);
Chris@76: return $string;'),
Chris@76: 'ucfirst' => $utf8 ? create_function('$string', '
Chris@76: global $smcFunc;
Chris@76: return $smcFunc[\'strtoupper\']($smcFunc[\'substr\']($string, 0, 1)) . $smcFunc[\'substr\']($string, 1);') : 'ucfirst',
Chris@76: 'ucwords' => $utf8 ? create_function('$string', '
Chris@76: global $smcFunc;
Chris@76: $words = preg_split(\'~([\s\r\n\t]+)~\', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
Chris@76: for ($i = 0, $n = count($words); $i < $n; $i += 2)
Chris@76: $words[$i] = $smcFunc[\'ucfirst\']($words[$i]);
Chris@76: return implode(\'\', $words);') : 'ucwords',
Chris@76: );
Chris@76:
Chris@76: // Setting the timezone is a requirement for some functions in PHP >= 5.1.
Chris@76: if (isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
Chris@76: date_default_timezone_set($modSettings['default_timezone']);
Chris@76:
Chris@76: // Check the load averages?
Chris@76: if (!empty($modSettings['loadavg_enable']))
Chris@76: {
Chris@76: if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
Chris@76: {
Chris@76: $modSettings['load_average'] = @file_get_contents('/proc/loadavg');
Chris@76: if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
Chris@76: $modSettings['load_average'] = (float) $matches[1];
Chris@76: elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
Chris@76: $modSettings['load_average'] = (float) $matches[1];
Chris@76: else
Chris@76: unset($modSettings['load_average']);
Chris@76:
Chris@76: if (!empty($modSettings['load_average']))
Chris@76: cache_put_data('loadavg', $modSettings['load_average'], 90);
Chris@76: }
Chris@76:
Chris@76: if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
Chris@76: db_fatal_error(true);
Chris@76: }
Chris@76:
Chris@76: // Is post moderation alive and well?
Chris@76: $modSettings['postmod_active'] = isset($modSettings['admin_features']) ? in_array('pm', explode(',', $modSettings['admin_features'])) : true;
Chris@76:
Chris@76: // Integration is cool.
Chris@76: if (defined('SMF_INTEGRATION_SETTINGS'))
Chris@76: {
Chris@76: $integration_settings = unserialize(SMF_INTEGRATION_SETTINGS);
Chris@76: foreach ($integration_settings as $hook => $function)
Chris@76: add_integration_function($hook, $function, false);
Chris@76: }
Chris@76:
Chris@76: // Any files to pre include?
Chris@76: if (!empty($modSettings['integrate_pre_include']))
Chris@76: {
Chris@76: $pre_includes = explode(',', $modSettings['integrate_pre_include']);
Chris@76: foreach ($pre_includes as $include)
Chris@76: {
Chris@76: $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
Chris@76: if (file_exists($include))
Chris@76: require_once($include);
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Call pre load integration functions.
Chris@76: call_integration_hook('integrate_pre_load');
Chris@76: }
Chris@76:
Chris@76: // Load all the important user information...
Chris@76: function loadUserSettings()
Chris@76: {
Chris@76: global $modSettings, $user_settings, $sourcedir, $smcFunc;
Chris@76: global $cookiename, $user_info, $language;
Chris@76:
Chris@76: // Check first the integration, then the cookie, and last the session.
Chris@76: if (count($integration_ids = call_integration_hook('integrate_verify_user')) > 0)
Chris@76: {
Chris@76: $id_member = 0;
Chris@76: foreach ($integration_ids as $integration_id)
Chris@76: {
Chris@76: $integration_id = (int) $integration_id;
Chris@76: if ($integration_id > 0)
Chris@76: {
Chris@76: $id_member = $integration_id;
Chris@76: $already_verified = true;
Chris@76: break;
Chris@76: }
Chris@76: }
Chris@76: }
Chris@76: else
Chris@76: $id_member = 0;
Chris@76:
Chris@76: if (empty($id_member) && isset($_COOKIE[$cookiename]))
Chris@76: {
Chris@76: // Fix a security hole in PHP 4.3.9 and below...
Chris@76: if (preg_match('~^a:[34]:\{i:0;(i:\d{1,6}|s:[1-8]:"\d{1,8}");i:1;s:(0|40):"([a-fA-F0-9]{40})?";i:2;[id]:\d{1,14};(i:3;i:\d;)?\}$~i', $_COOKIE[$cookiename]) == 1)
Chris@76: {
Chris@76: list ($id_member, $password) = @unserialize($_COOKIE[$cookiename]);
Chris@76: $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
Chris@76: }
Chris@76: else
Chris@76: $id_member = 0;
Chris@76: }
Chris@76: elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
Chris@76: {
Chris@76: // !!! Perhaps we can do some more checking on this, such as on the first octet of the IP?
Chris@76: list ($id_member, $password, $login_span) = @unserialize($_SESSION['login_' . $cookiename]);
Chris@76: $id_member = !empty($id_member) && strlen($password) == 40 && $login_span > time() ? (int) $id_member : 0;
Chris@76: }
Chris@76:
Chris@76: // Only load this stuff if the user isn't a guest.
Chris@76: if ($id_member != 0)
Chris@76: {
Chris@76: // Is the member data cached?
Chris@76: if (empty($modSettings['cache_enable']) || $modSettings['cache_enable'] < 2 || ($user_settings = cache_get_data('user_settings-' . $id_member, 60)) == null)
Chris@76: {
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT mem.*, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type
Chris@76: FROM {db_prefix}members AS mem
Chris@76: LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = {int:id_member})
Chris@76: WHERE mem.id_member = {int:id_member}
Chris@76: LIMIT 1',
Chris@76: array(
Chris@76: 'id_member' => $id_member,
Chris@76: )
Chris@76: );
Chris@76: $user_settings = $smcFunc['db_fetch_assoc']($request);
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
Chris@76: cache_put_data('user_settings-' . $id_member, $user_settings, 60);
Chris@76: }
Chris@76:
Chris@76: // Did we find 'im? If not, junk it.
Chris@76: if (!empty($user_settings))
Chris@76: {
Chris@76: // As much as the password should be right, we can assume the integration set things up.
Chris@76: if (!empty($already_verified) && $already_verified === true)
Chris@76: $check = true;
Chris@76: // SHA-1 passwords should be 40 characters long.
Chris@76: elseif (strlen($password) == 40)
Chris@76: $check = sha1($user_settings['passwd'] . $user_settings['password_salt']) == $password;
Chris@76: else
Chris@76: $check = false;
Chris@76:
Chris@76: // Wrong password or not activated - either way, you're going nowhere.
Chris@76: $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? $user_settings['id_member'] : 0;
Chris@76: }
Chris@76: else
Chris@76: $id_member = 0;
Chris@76:
Chris@76: // If we no longer have the member maybe they're being all hackey, stop brute force!
Chris@76: if (!$id_member)
Chris@76: {
Chris@76: require_once($sourcedir . '/LogInOut.php');
Chris@76: validatePasswordFlood(!empty($user_settings['id_member']) ? $user_settings['id_member'] : $id_member, !empty($user_settings['passwd_flood']) ? $user_settings['passwd_flood'] : false, $id_member != 0);
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Found 'im, let's set up the variables.
Chris@76: if ($id_member != 0)
Chris@76: {
Chris@76: // Let's not update the last visit time in these cases...
Chris@76: // 1. SSI doesn't count as visiting the forum.
Chris@76: // 2. RSS feeds and XMLHTTP requests don't count either.
Chris@76: // 3. If it was set within this session, no need to set it again.
Chris@76: // 4. New session, yet updated < five hours ago? Maybe cache can help.
Chris@76: if (SMF != 'SSI' && !isset($_REQUEST['xml']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != '.xml') && empty($_SESSION['id_msg_last_visit']) && (empty($modSettings['cache_enable']) || ($_SESSION['id_msg_last_visit'] = cache_get_data('user_last_visit-' . $id_member, 5 * 3600)) === null))
Chris@76: {
Chris@76: // Do a quick query to make sure this isn't a mistake.
Chris@76: $result = $smcFunc['db_query']('', '
Chris@76: SELECT poster_time
Chris@76: FROM {db_prefix}messages
Chris@76: WHERE id_msg = {int:id_msg}
Chris@76: LIMIT 1',
Chris@76: array(
Chris@76: 'id_msg' => $user_settings['id_msg_last_visit'],
Chris@76: )
Chris@76: );
Chris@76: list ($visitTime) = $smcFunc['db_fetch_row']($result);
Chris@76: $smcFunc['db_free_result']($result);
Chris@76:
Chris@76: $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
Chris@76:
Chris@76: // If it was *at least* five hours ago...
Chris@76: if ($visitTime < time() - 5 * 3600)
Chris@76: {
Chris@76: updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
Chris@76: $user_settings['last_login'] = time();
Chris@76:
Chris@76: if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
Chris@76: cache_put_data('user_settings-' . $id_member, $user_settings, 60);
Chris@76:
Chris@76: if (!empty($modSettings['cache_enable']))
Chris@76: cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
Chris@76: }
Chris@76: }
Chris@76: elseif (empty($_SESSION['id_msg_last_visit']))
Chris@76: $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
Chris@76:
Chris@76: $username = $user_settings['member_name'];
Chris@76:
Chris@76: if (empty($user_settings['additional_groups']))
Chris@76: $user_info = array(
Chris@76: 'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
Chris@76: );
Chris@76: else
Chris@76: $user_info = array(
Chris@76: 'groups' => array_merge(
Chris@76: array($user_settings['id_group'], $user_settings['id_post_group']),
Chris@76: explode(',', $user_settings['additional_groups'])
Chris@76: )
Chris@76: );
Chris@76:
Chris@76: // Because history has proven that it is possible for groups to go bad - clean up in case.
Chris@76: foreach ($user_info['groups'] as $k => $v)
Chris@76: $user_info['groups'][$k] = (int) $v;
Chris@76:
Chris@76: // This is a logged in user, so definitely not a spider.
Chris@76: $user_info['possibly_robot'] = false;
Chris@76: }
Chris@76: // If the user is a guest, initialize all the critical user settings.
Chris@76: else
Chris@76: {
Chris@76: // This is what a guest's variables should be.
Chris@76: $username = '';
Chris@76: $user_info = array('groups' => array(-1));
Chris@76: $user_settings = array();
Chris@76:
Chris@76: if (isset($_COOKIE[$cookiename]))
Chris@76: $_COOKIE[$cookiename] = '';
Chris@76:
Chris@76: // Do we perhaps think this is a search robot? Check every five minutes just in case...
Chris@76: if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
Chris@76: {
Chris@76: require_once($sourcedir . '/ManageSearchEngines.php');
Chris@76: $user_info['possibly_robot'] = SpiderCheck();
Chris@76: }
Chris@76: elseif (!empty($modSettings['spider_mode']))
Chris@76: $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
Chris@76: // If we haven't turned on proper spider hunts then have a guess!
Chris@76: else
Chris@76: {
Chris@76: $ci_user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
Chris@76: $user_info['possibly_robot'] = (strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla') === false && strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') === false) || strpos($ci_user_agent, 'googlebot') !== false || strpos($ci_user_agent, 'slurp') !== false || strpos($ci_user_agent, 'crawl') !== false;
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Set up the $user_info array.
Chris@76: $user_info += array(
Chris@76: 'id' => $id_member,
Chris@76: 'username' => $username,
Chris@76: 'name' => isset($user_settings['real_name']) ? $user_settings['real_name'] : '',
Chris@76: 'email' => isset($user_settings['email_address']) ? $user_settings['email_address'] : '',
Chris@76: 'passwd' => isset($user_settings['passwd']) ? $user_settings['passwd'] : '',
Chris@76: 'language' => empty($user_settings['lngfile']) || empty($modSettings['userLanguage']) ? $language : $user_settings['lngfile'],
Chris@76: 'is_guest' => $id_member == 0,
Chris@76: 'is_admin' => in_array(1, $user_info['groups']),
Chris@76: 'theme' => empty($user_settings['id_theme']) ? 0 : $user_settings['id_theme'],
Chris@76: 'last_login' => empty($user_settings['last_login']) ? 0 : $user_settings['last_login'],
Chris@76: 'ip' => $_SERVER['REMOTE_ADDR'],
Chris@76: 'ip2' => $_SERVER['BAN_CHECK_IP'],
Chris@76: 'posts' => empty($user_settings['posts']) ? 0 : $user_settings['posts'],
Chris@76: 'time_format' => empty($user_settings['time_format']) ? $modSettings['time_format'] : $user_settings['time_format'],
Chris@76: 'time_offset' => empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'],
Chris@76: 'avatar' => array(
Chris@76: 'url' => isset($user_settings['avatar']) ? $user_settings['avatar'] : '',
Chris@76: 'filename' => empty($user_settings['filename']) ? '' : $user_settings['filename'],
Chris@76: 'custom_dir' => !empty($user_settings['attachment_type']) && $user_settings['attachment_type'] == 1,
Chris@76: 'id_attach' => isset($user_settings['id_attach']) ? $user_settings['id_attach'] : 0
Chris@76: ),
Chris@76: 'smiley_set' => isset($user_settings['smiley_set']) ? $user_settings['smiley_set'] : '',
Chris@76: 'messages' => empty($user_settings['instant_messages']) ? 0 : $user_settings['instant_messages'],
Chris@76: 'unread_messages' => empty($user_settings['unread_messages']) ? 0 : $user_settings['unread_messages'],
Chris@76: 'total_time_logged_in' => empty($user_settings['total_time_logged_in']) ? 0 : $user_settings['total_time_logged_in'],
Chris@76: 'buddies' => !empty($modSettings['enable_buddylist']) && !empty($user_settings['buddy_list']) ? explode(',', $user_settings['buddy_list']) : array(),
Chris@76: 'ignoreboards' => !empty($user_settings['ignore_boards']) && !empty($modSettings['allow_ignore_boards']) ? explode(',', $user_settings['ignore_boards']) : array(),
Chris@76: 'ignoreusers' => !empty($user_settings['pm_ignore_list']) ? explode(',', $user_settings['pm_ignore_list']) : array(),
Chris@76: 'warning' => isset($user_settings['warning']) ? $user_settings['warning'] : 0,
Chris@76: 'permissions' => array(),
Chris@76: );
Chris@76: $user_info['groups'] = array_unique($user_info['groups']);
Chris@76: // Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
Chris@76: if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
Chris@76: unset($user_info['ignoreboards'][$tmp]);
Chris@76:
Chris@76: // Do we have any languages to validate this?
Chris@76: if (!empty($modSettings['userLanguage']) && (!empty($_GET['language']) || !empty($_SESSION['language'])))
Chris@76: $languages = getLanguages();
Chris@76:
Chris@76: // Allow the user to change their language if its valid.
Chris@76: if (!empty($modSettings['userLanguage']) && !empty($_GET['language']) && isset($languages[strtr($_GET['language'], './\\:', '____')]))
Chris@76: {
Chris@76: $user_info['language'] = strtr($_GET['language'], './\\:', '____');
Chris@76: $_SESSION['language'] = $user_info['language'];
Chris@76: }
Chris@76: elseif (!empty($modSettings['userLanguage']) && !empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
Chris@76: $user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
Chris@76:
Chris@76: // Just build this here, it makes it easier to change/use - administrators can see all boards.
Chris@76: if ($user_info['is_admin'])
Chris@76: $user_info['query_see_board'] = '1=1';
Chris@76: // Otherwise just the groups in $user_info['groups'].
Chris@76: else
Chris@76: $user_info['query_see_board'] = '(FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0' . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
Chris@76:
Chris@76: // Build the list of boards they WANT to see.
Chris@76: // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
Chris@76:
Chris@76: // If they aren't ignoring any boards then they want to see all the boards they can see
Chris@76: if (empty($user_info['ignoreboards']))
Chris@76: $user_info['query_wanna_see_board'] = $user_info['query_see_board'];
Chris@76: // Ok I guess they don't want to see all the boards
Chris@76: else
Chris@76: $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
Chris@76: }
Chris@76:
Chris@76: // Check for moderators and see if they have access to the board.
Chris@76: function loadBoard()
Chris@76: {
Chris@76: global $txt, $scripturl, $context, $modSettings;
Chris@76: global $board_info, $board, $topic, $user_info, $smcFunc;
Chris@76:
Chris@76: // Assume they are not a moderator.
Chris@76: $user_info['is_mod'] = false;
Chris@76: $context['user']['is_mod'] = &$user_info['is_mod'];
Chris@76:
Chris@76: // Start the linktree off empty..
Chris@76: $context['linktree'] = array();
Chris@76:
Chris@76: // Have they by chance specified a message id but nothing else?
Chris@76: if (empty($_REQUEST['action']) && empty($topic) && empty($board) && !empty($_REQUEST['msg']))
Chris@76: {
Chris@76: // Make sure the message id is really an int.
Chris@76: $_REQUEST['msg'] = (int) $_REQUEST['msg'];
Chris@76:
Chris@76: // Looking through the message table can be slow, so try using the cache first.
Chris@76: if (($topic = cache_get_data('msg_topic-' . $_REQUEST['msg'], 120)) === NULL)
Chris@76: {
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT id_topic
Chris@76: FROM {db_prefix}messages
Chris@76: WHERE id_msg = {int:id_msg}
Chris@76: LIMIT 1',
Chris@76: array(
Chris@76: 'id_msg' => $_REQUEST['msg'],
Chris@76: )
Chris@76: );
Chris@76:
Chris@76: // So did it find anything?
Chris@76: if ($smcFunc['db_num_rows']($request))
Chris@76: {
Chris@76: list ($topic) = $smcFunc['db_fetch_row']($request);
Chris@76: $smcFunc['db_free_result']($request);
Chris@76: // Save save save.
Chris@76: cache_put_data('msg_topic-' . $_REQUEST['msg'], $topic, 120);
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Remember redirection is the key to avoiding fallout from your bosses.
Chris@76: if (!empty($topic))
Chris@76: redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
Chris@76: else
Chris@76: {
Chris@76: loadPermissions();
Chris@76: loadTheme();
Chris@76: fatal_lang_error('topic_gone', false);
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Load this board only if it is specified.
Chris@76: if (empty($board) && empty($topic))
Chris@76: {
Chris@76: $board_info = array('moderators' => array());
Chris@76: return;
Chris@76: }
Chris@76:
Chris@76: if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
Chris@76: {
Chris@76: // !!! SLOW?
Chris@76: if (!empty($topic))
Chris@76: $temp = cache_get_data('topic_board-' . $topic, 120);
Chris@76: else
Chris@76: $temp = cache_get_data('board-' . $board, 120);
Chris@76:
Chris@76: if (!empty($temp))
Chris@76: {
Chris@76: $board_info = $temp;
Chris@76: $board = $board_info['id'];
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: if (empty($temp))
Chris@76: {
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT
Chris@76: c.id_cat, b.name AS bname, b.description, b.num_topics, b.member_groups,
Chris@76: b.id_parent, c.name AS cname, IFNULL(mem.id_member, 0) AS id_moderator,
Chris@76: mem.real_name' . (!empty($topic) ? ', b.id_board' : '') . ', b.child_level,
Chris@76: b.id_theme, b.override_theme, b.count_posts, b.id_profile, b.redirect,
Chris@76: b.unapproved_topics, b.unapproved_posts' . (!empty($topic) ? ', t.approved, t.id_member_started' : '') . '
Chris@76: FROM {db_prefix}boards AS b' . (!empty($topic) ? '
Chris@76: INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})' : '') . '
Chris@76: LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
Chris@76: LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = {raw:board_link})
Chris@76: LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)
Chris@76: WHERE b.id_board = {raw:board_link}',
Chris@76: array(
Chris@76: 'current_topic' => $topic,
Chris@76: 'board_link' => empty($topic) ? $smcFunc['db_quote']('{int:current_board}', array('current_board' => $board)) : 't.id_board',
Chris@76: )
Chris@76: );
Chris@76: // If there aren't any, skip.
Chris@76: if ($smcFunc['db_num_rows']($request) > 0)
Chris@76: {
Chris@76: $row = $smcFunc['db_fetch_assoc']($request);
Chris@76:
Chris@76: // Set the current board.
Chris@76: if (!empty($row['id_board']))
Chris@76: $board = $row['id_board'];
Chris@76:
Chris@76: // Basic operating information. (globals... :/)
Chris@76: $board_info = array(
Chris@76: 'id' => $board,
Chris@76: 'moderators' => array(),
Chris@76: 'cat' => array(
Chris@76: 'id' => $row['id_cat'],
Chris@76: 'name' => $row['cname']
Chris@76: ),
Chris@76: 'name' => $row['bname'],
Chris@76: 'description' => $row['description'],
Chris@76: 'num_topics' => $row['num_topics'],
Chris@76: 'unapproved_topics' => $row['unapproved_topics'],
Chris@76: 'unapproved_posts' => $row['unapproved_posts'],
Chris@76: 'unapproved_user_topics' => 0,
Chris@76: 'parent_boards' => getBoardParents($row['id_parent']),
Chris@76: 'parent' => $row['id_parent'],
Chris@76: 'child_level' => $row['child_level'],
Chris@76: 'theme' => $row['id_theme'],
Chris@76: 'override_theme' => !empty($row['override_theme']),
Chris@76: 'profile' => $row['id_profile'],
Chris@76: 'redirect' => $row['redirect'],
Chris@76: 'posts_count' => empty($row['count_posts']),
Chris@76: 'cur_topic_approved' => empty($topic) || $row['approved'],
Chris@76: 'cur_topic_starter' => empty($topic) ? 0 : $row['id_member_started'],
Chris@76: );
Chris@76:
Chris@76: // Load the membergroups allowed, and check permissions.
Chris@76: $board_info['groups'] = $row['member_groups'] == '' ? array() : explode(',', $row['member_groups']);
Chris@76:
Chris@76: do
Chris@76: {
Chris@76: if (!empty($row['id_moderator']))
Chris@76: $board_info['moderators'][$row['id_moderator']] = array(
Chris@76: 'id' => $row['id_moderator'],
Chris@76: 'name' => $row['real_name'],
Chris@76: 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
Chris@76: 'link' => '' . $row['real_name'] . ''
Chris@76: );
Chris@76: }
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request));
Chris@76:
Chris@76: // If the board only contains unapproved posts and the user isn't an approver then they can't see any topics.
Chris@76: // If that is the case do an additional check to see if they have any topics waiting to be approved.
Chris@76: if ($board_info['num_topics'] == 0 && $modSettings['postmod_active'] && !allowedTo('approve_posts'))
Chris@76: {
Chris@76: $smcFunc['db_free_result']($request); // Free the previous result
Chris@76:
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT COUNT(id_topic)
Chris@76: FROM {db_prefix}topics
Chris@76: WHERE id_member_started={int:id_member}
Chris@76: AND approved = {int:unapproved}
Chris@76: AND id_board = {int:board}',
Chris@76: array(
Chris@76: 'id_member' => $user_info['id'],
Chris@76: 'unapproved' => 0,
Chris@76: 'board' => $board,
Chris@76: )
Chris@76: );
Chris@76:
Chris@76: list ($board_info['unapproved_user_topics']) = $smcFunc['db_fetch_row']($request);
Chris@76: }
Chris@76:
Chris@76: if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
Chris@76: {
Chris@76: // !!! SLOW?
Chris@76: if (!empty($topic))
Chris@76: cache_put_data('topic_board-' . $topic, $board_info, 120);
Chris@76: cache_put_data('board-' . $board, $board_info, 120);
Chris@76: }
Chris@76: }
Chris@76: else
Chris@76: {
Chris@76: // Otherwise the topic is invalid, there are no moderators, etc.
Chris@76: $board_info = array(
Chris@76: 'moderators' => array(),
Chris@76: 'error' => 'exist'
Chris@76: );
Chris@76: $topic = null;
Chris@76: $board = 0;
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76: }
Chris@76:
Chris@76: if (!empty($topic))
Chris@76: $_GET['board'] = (int) $board;
Chris@76:
Chris@76: if (!empty($board))
Chris@76: {
Chris@76: // Now check if the user is a moderator.
Chris@76: $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]);
Chris@76:
Chris@76: if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
Chris@76: $board_info['error'] = 'access';
Chris@76:
Chris@76: // Build up the linktree.
Chris@76: $context['linktree'] = array_merge(
Chris@76: $context['linktree'],
Chris@76: array(array(
Chris@76: 'url' => $scripturl . '#c' . $board_info['cat']['id'],
Chris@76: 'name' => $board_info['cat']['name']
Chris@76: )),
Chris@76: array_reverse($board_info['parent_boards']),
Chris@76: array(array(
Chris@76: 'url' => $scripturl . '?board=' . $board . '.0',
Chris@76: 'name' => $board_info['name']
Chris@76: ))
Chris@76: );
Chris@76: }
Chris@76:
Chris@76: // Set the template contextual information.
Chris@76: $context['user']['is_mod'] = &$user_info['is_mod'];
Chris@76: $context['current_topic'] = $topic;
Chris@76: $context['current_board'] = $board;
Chris@76:
Chris@76: // Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
Chris@76: if (!empty($board_info['error']) && ($board_info['error'] != 'access' || !$user_info['is_mod']))
Chris@76: {
Chris@76: // The permissions and theme need loading, just to make sure everything goes smoothly.
Chris@76: loadPermissions();
Chris@76: loadTheme();
Chris@76:
Chris@76: $_GET['board'] = '';
Chris@76: $_GET['topic'] = '';
Chris@76:
Chris@76: // The linktree should not give the game away mate!
Chris@76: $context['linktree'] = array(
Chris@76: array(
Chris@76: 'url' => $scripturl,
Chris@76: 'name' => $context['forum_name_html_safe']
Chris@76: )
Chris@76: );
Chris@76:
Chris@76: // If it's a prefetching agent or we're requesting an attachment.
Chris@76: if ((isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') || (!empty($_REQUEST['action']) && $_REQUEST['action'] === 'dlattach'))
Chris@76: {
Chris@76: ob_end_clean();
Chris@76: header('HTTP/1.1 403 Forbidden');
Chris@76: die;
Chris@76: }
Chris@76: elseif ($user_info['is_guest'])
Chris@76: {
Chris@76: loadLanguage('Errors');
Chris@76: is_not_guest($txt['topic_gone']);
Chris@76: }
Chris@76: else
Chris@76: fatal_lang_error('topic_gone', false);
Chris@76: }
Chris@76:
Chris@76: if ($user_info['is_mod'])
Chris@76: $user_info['groups'][] = 3;
Chris@76: }
Chris@76:
Chris@76: // Load this user's permissions.
Chris@76: function loadPermissions()
Chris@76: {
Chris@76: global $user_info, $board, $board_info, $modSettings, $smcFunc, $sourcedir;
Chris@76:
Chris@76: if ($user_info['is_admin'])
Chris@76: {
Chris@76: banPermissions();
Chris@76: return;
Chris@76: }
Chris@76:
Chris@76: if (!empty($modSettings['cache_enable']))
Chris@76: {
Chris@76: $cache_groups = $user_info['groups'];
Chris@76: asort($cache_groups);
Chris@76: $cache_groups = implode(',', $cache_groups);
Chris@76: // If it's a spider then cache it different.
Chris@76: if ($user_info['possibly_robot'])
Chris@76: $cache_groups .= '-spider';
Chris@76:
Chris@76: if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
Chris@76: {
Chris@76: list ($user_info['permissions']) = $temp;
Chris@76: banPermissions();
Chris@76:
Chris@76: return;
Chris@76: }
Chris@76: elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
Chris@76: list ($user_info['permissions'], $removals) = $temp;
Chris@76: }
Chris@76:
Chris@76: // If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
Chris@76: $spider_restrict = $user_info['possibly_robot'] && !empty($modSettings['spider_group']) ? ' OR (id_group = {int:spider_group} AND add_deny = 0)' : '';
Chris@76:
Chris@76: if (empty($user_info['permissions']))
Chris@76: {
Chris@76: // Get the general permissions.
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT permission, add_deny
Chris@76: FROM {db_prefix}permissions
Chris@76: WHERE id_group IN ({array_int:member_groups})
Chris@76: ' . $spider_restrict,
Chris@76: array(
Chris@76: 'member_groups' => $user_info['groups'],
Chris@76: 'spider_group' => !empty($modSettings['spider_group']) ? $modSettings['spider_group'] : 0,
Chris@76: )
Chris@76: );
Chris@76: $removals = array();
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: {
Chris@76: if (empty($row['add_deny']))
Chris@76: $removals[] = $row['permission'];
Chris@76: else
Chris@76: $user_info['permissions'][] = $row['permission'];
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: if (isset($cache_groups))
Chris@76: cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
Chris@76: }
Chris@76:
Chris@76: // Get the board permissions.
Chris@76: if (!empty($board))
Chris@76: {
Chris@76: // Make sure the board (if any) has been loaded by loadBoard().
Chris@76: if (!isset($board_info['profile']))
Chris@76: fatal_lang_error('no_board');
Chris@76:
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT permission, add_deny
Chris@76: FROM {db_prefix}board_permissions
Chris@76: WHERE (id_group IN ({array_int:member_groups})
Chris@76: ' . $spider_restrict . ')
Chris@76: AND id_profile = {int:id_profile}',
Chris@76: array(
Chris@76: 'member_groups' => $user_info['groups'],
Chris@76: 'id_profile' => $board_info['profile'],
Chris@76: 'spider_group' => !empty($modSettings['spider_group']) ? $modSettings['spider_group'] : 0,
Chris@76: )
Chris@76: );
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: {
Chris@76: if (empty($row['add_deny']))
Chris@76: $removals[] = $row['permission'];
Chris@76: else
Chris@76: $user_info['permissions'][] = $row['permission'];
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76: }
Chris@76:
Chris@76: // Remove all the permissions they shouldn't have ;).
Chris@76: if (!empty($modSettings['permission_enable_deny']))
Chris@76: $user_info['permissions'] = array_diff($user_info['permissions'], $removals);
Chris@76:
Chris@76: if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
Chris@76: cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
Chris@76:
Chris@76: // Banned? Watch, don't touch..
Chris@76: banPermissions();
Chris@76:
Chris@76: // Load the mod cache so we can know what additional boards they should see, but no sense in doing it for guests
Chris@76: if (!$user_info['is_guest'])
Chris@76: {
Chris@76: if (!isset($_SESSION['mc']) || $_SESSION['mc']['time'] <= $modSettings['settings_updated'])
Chris@76: {
Chris@76: require_once($sourcedir . '/Subs-Auth.php');
Chris@76: rebuildModCache();
Chris@76: }
Chris@76: else
Chris@76: $user_info['mod_cache'] = $_SESSION['mc'];
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Loads an array of users' data by ID or member_name.
Chris@76: function loadMemberData($users, $is_name = false, $set = 'normal')
Chris@76: {
Chris@76: global $user_profile, $modSettings, $board_info, $smcFunc;
Chris@76:
Chris@76: // Can't just look for no users :P.
Chris@76: if (empty($users))
Chris@76: return false;
Chris@76:
Chris@76: // Make sure it's an array.
Chris@76: $users = !is_array($users) ? array($users) : array_unique($users);
Chris@76: $loaded_ids = array();
Chris@76:
Chris@76: if (!$is_name && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
Chris@76: {
Chris@76: $users = array_values($users);
Chris@76: for ($i = 0, $n = count($users); $i < $n; $i++)
Chris@76: {
Chris@76: $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
Chris@76: if ($data == null)
Chris@76: continue;
Chris@76:
Chris@76: $loaded_ids[] = $data['id_member'];
Chris@76: $user_profile[$data['id_member']] = $data;
Chris@76: unset($users[$i]);
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: if ($set == 'normal')
Chris@76: {
Chris@76: $select_columns = '
Chris@76: IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
Chris@76: mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name,
Chris@76: mem.real_name, mem.email_address, mem.hide_email, mem.date_registered, mem.website_title, mem.website_url,
Chris@76: mem.birthdate, mem.member_ip, mem.member_ip2, mem.icq, mem.aim, mem.yim, mem.msn, mem.posts, mem.last_login,
Chris@76: mem.karma_good, mem.id_post_group, mem.karma_bad, mem.lngfile, mem.id_group, mem.time_offset, mem.show_online,
Chris@76: mem.buddy_list, mg.online_color AS member_group_color, IFNULL(mg.group_name, {string:blank_string}) AS member_group,
Chris@76: pg.online_color AS post_group_color, IFNULL(pg.group_name, {string:blank_string}) AS post_group, mem.is_activated, mem.warning,
Chris@76: CASE WHEN mem.id_group = 0 OR mg.stars = {string:blank_string} THEN pg.stars ELSE mg.stars END AS stars' . (!empty($modSettings['titlesEnable']) ? ',
Chris@76: mem.usertitle' : '');
Chris@76: $select_tables = '
Chris@76: LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
Chris@76: LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
Chris@76: LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)
Chris@76: LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)';
Chris@76: }
Chris@76: elseif ($set == 'profile')
Chris@76: {
Chris@76: $select_columns = '
Chris@76: IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
Chris@76: mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name,
Chris@76: mem.real_name, mem.email_address, mem.hide_email, mem.date_registered, mem.website_title, mem.website_url,
Chris@76: mem.openid_uri, mem.birthdate, mem.icq, mem.aim, mem.yim, mem.msn, mem.posts, mem.last_login, mem.karma_good,
Chris@76: mem.karma_bad, mem.member_ip, mem.member_ip2, mem.lngfile, mem.id_group, mem.id_theme, mem.buddy_list,
Chris@76: mem.pm_ignore_list, mem.pm_email_notify, mem.pm_receive_from, mem.time_offset' . (!empty($modSettings['titlesEnable']) ? ', mem.usertitle' : '') . ',
Chris@76: mem.time_format, mem.secret_question, mem.is_activated, mem.additional_groups, mem.smiley_set, mem.show_online,
Chris@76: mem.total_time_logged_in, mem.id_post_group, mem.notify_announcements, mem.notify_regularity, mem.notify_send_body,
Chris@76: mem.notify_types, lo.url, mg.online_color AS member_group_color, IFNULL(mg.group_name, {string:blank_string}) AS member_group,
Chris@76: pg.online_color AS post_group_color, IFNULL(pg.group_name, {string:blank_string}) AS post_group, mem.ignore_boards, mem.warning,
Chris@76: CASE WHEN mem.id_group = 0 OR mg.stars = {string:blank_string} THEN pg.stars ELSE mg.stars END AS stars, mem.password_salt, mem.pm_prefs';
Chris@76: $select_tables = '
Chris@76: LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
Chris@76: LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
Chris@76: LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)
Chris@76: LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)';
Chris@76: }
Chris@76: elseif ($set == 'minimal')
Chris@76: {
Chris@76: $select_columns = '
Chris@76: mem.id_member, mem.member_name, mem.real_name, mem.email_address, mem.hide_email, mem.date_registered,
Chris@76: mem.posts, mem.last_login, mem.member_ip, mem.member_ip2, mem.lngfile, mem.id_group';
Chris@76: $select_tables = '';
Chris@76: }
Chris@76: else
Chris@76: trigger_error('loadMemberData(): Invalid member data set \'' . $set . '\'', E_USER_WARNING);
Chris@76:
Chris@76: if (!empty($users))
Chris@76: {
Chris@76: // Load the member's data.
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT' . $select_columns . '
Chris@76: FROM {db_prefix}members AS mem' . $select_tables . '
Chris@76: WHERE mem.' . ($is_name ? 'member_name' : 'id_member') . (count($users) == 1 ? ' = {' . ($is_name ? 'string' : 'int') . ':users}' : ' IN ({' . ($is_name ? 'array_string' : 'array_int') . ':users})'),
Chris@76: array(
Chris@76: 'blank_string' => '',
Chris@76: 'users' => count($users) == 1 ? current($users) : $users,
Chris@76: )
Chris@76: );
Chris@76: $new_loaded_ids = array();
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: {
Chris@76: $new_loaded_ids[] = $row['id_member'];
Chris@76: $loaded_ids[] = $row['id_member'];
Chris@76: $row['options'] = array();
Chris@76: $user_profile[$row['id_member']] = $row;
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76: }
Chris@76:
Chris@76: if (!empty($new_loaded_ids) && $set !== 'minimal')
Chris@76: {
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT *
Chris@76: FROM {db_prefix}themes
Chris@76: WHERE id_member' . (count($new_loaded_ids) == 1 ? ' = {int:loaded_ids}' : ' IN ({array_int:loaded_ids})'),
Chris@76: array(
Chris@76: 'loaded_ids' => count($new_loaded_ids) == 1 ? $new_loaded_ids[0] : $new_loaded_ids,
Chris@76: )
Chris@76: );
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
Chris@76: $smcFunc['db_free_result']($request);
Chris@76: }
Chris@76:
Chris@76: if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
Chris@76: {
Chris@76: for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
Chris@76: cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
Chris@76: }
Chris@76:
Chris@76: // Are we loading any moderators? If so, fix their group data...
Chris@76: if (!empty($loaded_ids) && !empty($board_info['moderators']) && $set === 'normal' && count($temp_mods = array_intersect($loaded_ids, array_keys($board_info['moderators']))) !== 0)
Chris@76: {
Chris@76: if (($row = cache_get_data('moderator_group_info', 480)) == null)
Chris@76: {
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT group_name AS member_group, online_color AS member_group_color, stars
Chris@76: FROM {db_prefix}membergroups
Chris@76: WHERE id_group = {int:moderator_group}
Chris@76: LIMIT 1',
Chris@76: array(
Chris@76: 'moderator_group' => 3,
Chris@76: )
Chris@76: );
Chris@76: $row = $smcFunc['db_fetch_assoc']($request);
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: cache_put_data('moderator_group_info', $row, 480);
Chris@76: }
Chris@76:
Chris@76: foreach ($temp_mods as $id)
Chris@76: {
Chris@76: // By popular demand, don't show admins or global moderators as moderators.
Chris@76: if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
Chris@76: $user_profile[$id]['member_group'] = $row['member_group'];
Chris@76:
Chris@76: // If the Moderator group has no color or stars, but their group does... don't overwrite.
Chris@76: if (!empty($row['stars']))
Chris@76: $user_profile[$id]['stars'] = $row['stars'];
Chris@76: if (!empty($row['member_group_color']))
Chris@76: $user_profile[$id]['member_group_color'] = $row['member_group_color'];
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: return empty($loaded_ids) ? false : $loaded_ids;
Chris@76: }
Chris@76:
Chris@76: // Loads the user's basic values... meant for template/theme usage.
Chris@76: function loadMemberContext($user, $display_custom_fields = false)
Chris@76: {
Chris@76: global $memberContext, $user_profile, $txt, $scripturl, $user_info;
Chris@76: global $context, $modSettings, $board_info, $settings;
Chris@76: global $smcFunc;
Chris@76: static $dataLoaded = array();
Chris@76:
Chris@76: // If this person's data is already loaded, skip it.
Chris@76: if (isset($dataLoaded[$user]))
Chris@76: return true;
Chris@76:
Chris@76: // We can't load guests or members not loaded by loadMemberData()!
Chris@76: if ($user == 0)
Chris@76: return false;
Chris@76: if (!isset($user_profile[$user]))
Chris@76: {
Chris@76: trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
Chris@76: return false;
Chris@76: }
Chris@76:
Chris@76: // Well, it's loaded now anyhow.
Chris@76: $dataLoaded[$user] = true;
Chris@76: $profile = $user_profile[$user];
Chris@76:
Chris@76: // Censor everything.
Chris@76: censorText($profile['signature']);
Chris@76: censorText($profile['personal_text']);
Chris@76: censorText($profile['location']);
Chris@76:
Chris@76: // Set things up to be used before hand.
Chris@76: $gendertxt = $profile['gender'] == 2 ? $txt['female'] : ($profile['gender'] == 1 ? $txt['male'] : '');
Chris@76: $profile['signature'] = str_replace(array("\n", "\r"), array('
', ''), $profile['signature']);
Chris@76: $profile['signature'] = parse_bbc($profile['signature'], true, 'sig' . $profile['id_member']);
Chris@76:
Chris@76: $profile['is_online'] = (!empty($profile['show_online']) || allowedTo('moderate_forum')) && $profile['is_online'] > 0;
Chris@76: $profile['stars'] = empty($profile['stars']) ? array('', '') : explode('#', $profile['stars']);
Chris@76: // Setup the buddy status here (One whole in_array call saved :P)
Chris@76: $profile['buddy'] = in_array($profile['id_member'], $user_info['buddies']);
Chris@76: $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
Chris@76:
Chris@76: // If we're always html resizing, assume it's too large.
Chris@76: if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
Chris@76: {
Chris@76: $avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
Chris@76: $avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
Chris@76: }
Chris@76: else
Chris@76: {
Chris@76: $avatar_width = '';
Chris@76: $avatar_height = '';
Chris@76: }
Chris@76:
Chris@76: // What a monstrous array...
Chris@76: $memberContext[$user] = array(
Chris@76: 'username' => $profile['member_name'],
Chris@76: 'name' => $profile['real_name'],
Chris@76: 'id' => $profile['id_member'],
Chris@76: 'is_buddy' => $profile['buddy'],
Chris@76: 'is_reverse_buddy' => in_array($user_info['id'], $buddy_list),
Chris@76: 'buddies' => $buddy_list,
Chris@76: 'title' => !empty($modSettings['titlesEnable']) ? $profile['usertitle'] : '',
Chris@76: 'href' => $scripturl . '?action=profile;u=' . $profile['id_member'],
Chris@76: 'link' => '' . $profile['real_name'] . '',
Chris@76: 'email' => $profile['email_address'],
Chris@76: 'show_email' => showEmailAddress(!empty($profile['hide_email']), $profile['id_member']),
Chris@76: 'registered' => empty($profile['date_registered']) ? $txt['not_applicable'] : timeformat($profile['date_registered']),
Chris@76: 'registered_timestamp' => empty($profile['date_registered']) ? 0 : forum_time(true, $profile['date_registered']),
Chris@76: 'blurb' => $profile['personal_text'],
Chris@76: 'gender' => array(
Chris@76: 'name' => $gendertxt,
Chris@76: 'image' => !empty($profile['gender']) ? '' : ''
Chris@76: ),
Chris@76: 'website' => array(
Chris@76: 'title' => $profile['website_title'],
Chris@76: 'url' => $profile['website_url'],
Chris@76: ),
Chris@76: 'birth_date' => empty($profile['birthdate']) || $profile['birthdate'] === '0001-01-01' ? '0000-00-00' : (substr($profile['birthdate'], 0, 4) === '0004' ? '0000' . substr($profile['birthdate'], 4) : $profile['birthdate']),
Chris@76: 'signature' => $profile['signature'],
Chris@76: 'location' => $profile['location'],
Chris@76: 'icq' => $profile['icq'] != '' && (empty($modSettings['guest_hideContacts']) || !$user_info['is_guest']) ? array(
Chris@76: 'name' => $profile['icq'],
Chris@76: 'href' => 'http://www.icq.com/whitepages/about_me.php?uin=' . $profile['icq'],
Chris@76: 'link' => '
',
Chris@76: 'link_text' => '' . $profile['icq'] . '',
Chris@76: ) : array('name' => '', 'add' => '', 'href' => '', 'link' => '', 'link_text' => ''),
Chris@76: 'aim' => $profile['aim'] != '' && (empty($modSettings['guest_hideContacts']) || !$user_info['is_guest']) ? array(
Chris@76: 'name' => $profile['aim'],
Chris@76: 'href' => 'aim:goim?screenname=' . urlencode(strtr($profile['aim'], array(' ' => '%20'))) . '&message=' . $txt['aim_default_message'],
Chris@76: 'link' => '
',
Chris@76: 'link_text' => '' . $profile['aim'] . ''
Chris@76: ) : array('name' => '', 'href' => '', 'link' => '', 'link_text' => ''),
Chris@76: 'yim' => $profile['yim'] != '' && (empty($modSettings['guest_hideContacts']) || !$user_info['is_guest']) ? array(
Chris@76: 'name' => $profile['yim'],
Chris@76: 'href' => 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($profile['yim']),
Chris@76: 'link' => '
',
Chris@76: 'link_text' => '' . $profile['yim'] . ''
Chris@76: ) : array('name' => '', 'href' => '', 'link' => '', 'link_text' => ''),
Chris@76: 'msn' => $profile['msn'] !='' && (empty($modSettings['guest_hideContacts']) || !$user_info['is_guest']) ? array(
Chris@76: 'name' => $profile['msn'],
Chris@76: 'href' => 'http://members.msn.com/' . $profile['msn'],
Chris@76: 'link' => '
',
Chris@76: 'link_text' => '' . $profile['msn'] . ''
Chris@76: ) : array('name' => '', 'href' => '', 'link' => '', 'link_text' => ''),
Chris@76: 'real_posts' => $profile['posts'],
Chris@76: 'posts' => $profile['posts'] > 500000 ? $txt['geek'] : comma_format($profile['posts']),
Chris@76: 'avatar' => array(
Chris@76: 'name' => $profile['avatar'],
Chris@76: 'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '
' : '') : (stristr($profile['avatar'], 'http://') ? '
' : '
'),
Chris@76: 'href' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) : '') : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']),
Chris@76: 'url' => $profile['avatar'] == '' ? '' : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'])
Chris@76: ),
Chris@76: 'last_login' => empty($profile['last_login']) ? $txt['never'] : timeformat($profile['last_login']),
Chris@76: 'last_login_timestamp' => empty($profile['last_login']) ? 0 : forum_time(0, $profile['last_login']),
Chris@76: 'karma' => array(
Chris@76: 'good' => $profile['karma_good'],
Chris@76: 'bad' => $profile['karma_bad'],
Chris@76: 'allow' => !$user_info['is_guest'] && !empty($modSettings['karmaMode']) && $user_info['id'] != $user && allowedTo('karma_edit') &&
Chris@76: ($user_info['posts'] >= $modSettings['karmaMinPosts'] || $user_info['is_admin']),
Chris@76: ),
Chris@76: 'ip' => htmlspecialchars($profile['member_ip']),
Chris@76: 'ip2' => htmlspecialchars($profile['member_ip2']),
Chris@76: 'online' => array(
Chris@76: 'is_online' => $profile['is_online'],
Chris@76: 'text' => $txt[$profile['is_online'] ? 'online' : 'offline'],
Chris@76: 'href' => $scripturl . '?action=pm;sa=send;u=' . $profile['id_member'],
Chris@76: 'link' => '' . $txt[$profile['is_online'] ? 'online' : 'offline'] . '',
Chris@76: 'image_href' => $settings['images_url'] . '/' . ($profile['buddy'] ? 'buddy_' : '') . ($profile['is_online'] ? 'useron' : 'useroff') . '.gif',
Chris@76: 'label' => $txt[$profile['is_online'] ? 'online' : 'offline']
Chris@76: ),
Chris@76: 'language' => $smcFunc['ucwords'](strtr($profile['lngfile'], array('_' => ' ', '-utf8' => ''))),
Chris@76: 'is_activated' => isset($profile['is_activated']) ? $profile['is_activated'] : 1,
Chris@76: 'is_banned' => isset($profile['is_activated']) ? $profile['is_activated'] >= 10 : 0,
Chris@76: 'options' => $profile['options'],
Chris@76: 'is_guest' => false,
Chris@76: 'group' => $profile['member_group'],
Chris@76: 'group_color' => $profile['member_group_color'],
Chris@76: 'group_id' => $profile['id_group'],
Chris@76: 'post_group' => $profile['post_group'],
Chris@76: 'post_group_color' => $profile['post_group_color'],
Chris@76: 'group_stars' => str_repeat('
', empty($profile['stars'][0]) || empty($profile['stars'][1]) ? 0 : $profile['stars'][0]),
Chris@76: 'warning' => $profile['warning'],
Chris@76: 'warning_status' => !empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $profile['warning'] ? 'mute' : (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $profile['warning'] ? 'moderate' : (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $profile['warning'] ? 'watch' : (''))),
Chris@76: 'local_time' => timeformat(time() + ($profile['time_offset'] - $user_info['time_offset']) * 3600, false),
Chris@76: );
Chris@76:
Chris@76: // First do a quick run through to make sure there is something to be shown.
Chris@76: $memberContext[$user]['has_messenger'] = false;
Chris@76: foreach (array('icq', 'msn', 'aim', 'yim') as $messenger)
Chris@76: {
Chris@76: if (!isset($context['disabled_fields'][$messenger]) && !empty($memberContext[$user][$messenger]['link']))
Chris@76: {
Chris@76: $memberContext[$user]['has_messenger'] = true;
Chris@76: break;
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Are we also loading the members custom fields into context?
Chris@76: if ($display_custom_fields && !empty($modSettings['displayFields']))
Chris@76: {
Chris@76: $memberContext[$user]['custom_fields'] = array();
Chris@76: if (!isset($context['display_fields']))
Chris@76: $context['display_fields'] = unserialize($modSettings['displayFields']);
Chris@76:
Chris@76: foreach ($context['display_fields'] as $custom)
Chris@76: {
Chris@76: if (empty($custom['title']) || empty($profile['options'][$custom['colname']]))
Chris@76: continue;
Chris@76:
Chris@76: $value = $profile['options'][$custom['colname']];
Chris@76:
Chris@76: // BBC?
Chris@76: if ($custom['bbc'])
Chris@76: $value = parse_bbc($value);
Chris@76: // ... or checkbox?
Chris@76: elseif (isset($custom['type']) && $custom['type'] == 'check')
Chris@76: $value = $value ? $txt['yes'] : $txt['no'];
Chris@76:
Chris@76: // Enclosing the user input within some other text?
Chris@76: if (!empty($custom['enclose']))
Chris@76: $value = strtr($custom['enclose'], array(
Chris@76: '{SCRIPTURL}' => $scripturl,
Chris@76: '{IMAGES_URL}' => $settings['images_url'],
Chris@76: '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
Chris@76: '{INPUT}' => $value,
Chris@76: ));
Chris@76:
Chris@76: $memberContext[$user]['custom_fields'][] = array(
Chris@76: 'title' => $custom['title'],
Chris@76: 'colname' => $custom['colname'],
Chris@76: 'value' => $value,
Chris@76: 'placement' => !empty($custom['placement']) ? $custom['placement'] : 0,
Chris@76: );
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: return true;
Chris@76: }
Chris@76:
Chris@76: function detectBrowser()
Chris@76: {
Chris@76: global $context, $user_info;
Chris@76:
Chris@76: // The following determines the user agent (browser) as best it can.
Chris@76: $context['browser'] = array(
Chris@76: 'is_opera' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false,
Chris@76: 'is_opera6' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 6') !== false,
Chris@76: 'is_opera7' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 7') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera/7') !== false,
Chris@76: 'is_opera8' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 8') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera/8') !== false,
Chris@76: 'is_opera9' => preg_match('~Opera[ /]9(?!\\.[89])~', $_SERVER['HTTP_USER_AGENT']) === 1,
Chris@76: 'is_opera10' => preg_match('~Opera[ /]10\\.~', $_SERVER['HTTP_USER_AGENT']) === 1 || (preg_match('~Opera[ /]9\\.[89]~', $_SERVER['HTTP_USER_AGENT']) === 1 && preg_match('~Version/1[0-9]\\.~', $_SERVER['HTTP_USER_AGENT']) === 1),
Chris@76: 'is_ie4' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 4') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') === false,
Chris@76: 'is_webkit' => strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') !== false,
Chris@76: 'is_mac_ie' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false,
Chris@76: 'is_web_tv' => strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') !== false,
Chris@76: 'is_konqueror' => strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false,
Chris@76: 'is_firefox' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/~', $_SERVER['HTTP_USER_AGENT']) === 1,
Chris@76: 'is_firefox1' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/1\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
Chris@76: 'is_firefox2' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/2\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
Chris@76: 'is_firefox3' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)/3\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
Chris@76: 'is_iphone' => strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== false,
Chris@76: 'is_android' => strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false,
Chris@76: );
Chris@76:
Chris@76: $context['browser']['is_chrome'] = $context['browser']['is_webkit'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false;
Chris@76: $context['browser']['is_safari'] = !$context['browser']['is_chrome'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false;
Chris@76: $context['browser']['is_gecko'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$context['browser']['is_webkit'] && !$context['browser']['is_konqueror'];
Chris@76:
Chris@76: // Internet Explorer 5 and 6 are often "emulated".
Chris@76: $context['browser']['is_ie8'] = !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'] && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8') !== false;
Chris@76: $context['browser']['is_ie7'] = !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'] && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false && !$context['browser']['is_ie8'];
Chris@76: $context['browser']['is_ie6'] = !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'] && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && !$context['browser']['is_ie8'] && !$context['browser']['is_ie7'];
Chris@76: $context['browser']['is_ie5.5'] = !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'] && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.5') !== false;
Chris@76: $context['browser']['is_ie5'] = !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'] && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.0') !== false;
Chris@76:
Chris@76: $context['browser']['is_ie'] = $context['browser']['is_ie4'] || $context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie6'] || $context['browser']['is_ie7'] || $context['browser']['is_ie8'];
Chris@76: // Before IE8 we need to fix IE... lots!
Chris@76: $context['browser']['ie_standards_fix'] = !$context['browser']['is_ie8'];
Chris@76:
Chris@76: $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;
Chris@76:
Chris@76: // This isn't meant to be reliable, it's just meant to catch most bots to prevent PHPSESSID from showing up.
Chris@76: $context['browser']['possibly_robot'] = !empty($user_info['possibly_robot']);
Chris@76:
Chris@76: // Robots shouldn't be logging in or registering. So, they aren't a bot. Better to be wrong than sorry (or people won't be able to log in!), anyway.
Chris@76: if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register'))) || !$user_info['is_guest'])
Chris@76: $context['browser']['possibly_robot'] = false;
Chris@76: }
Chris@76:
Chris@76: // Load a theme, by ID.
Chris@76: function loadTheme($id_theme = 0, $initialize = true)
Chris@76: {
Chris@76: global $user_info, $user_settings, $board_info, $sc, $boarddir;
Chris@76: global $txt, $boardurl, $scripturl, $mbname, $modSettings, $language;
Chris@76: global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc;
Chris@76:
Chris@76: // The theme was specified by parameter.
Chris@76: if (!empty($id_theme))
Chris@76: $id_theme = (int) $id_theme;
Chris@76: // The theme was specified by REQUEST.
Chris@76: elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
Chris@76: {
Chris@76: $id_theme = (int) $_REQUEST['theme'];
Chris@76: $_SESSION['id_theme'] = $id_theme;
Chris@76: }
Chris@76: // The theme was specified by REQUEST... previously.
Chris@76: elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
Chris@76: $id_theme = (int) $_SESSION['id_theme'];
Chris@76: // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
Chris@76: elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
Chris@76: $id_theme = $user_info['theme'];
Chris@76: // The theme was specified by the board.
Chris@76: elseif (!empty($board_info['theme']))
Chris@76: $id_theme = $board_info['theme'];
Chris@76: // The theme is the forum's default.
Chris@76: else
Chris@76: $id_theme = $modSettings['theme_guests'];
Chris@76:
Chris@76: // Verify the id_theme... no foul play.
Chris@76: // Always allow the board specific theme, if they are overriding.
Chris@76: if (!empty($board_info['theme']) && $board_info['override_theme'])
Chris@76: $id_theme = $board_info['theme'];
Chris@76: // If they have specified a particular theme to use with SSI allow it to be used.
Chris@76: elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
Chris@76: $id_theme = (int) $id_theme;
Chris@76: elseif (!empty($modSettings['knownThemes']) && !allowedTo('admin_forum'))
Chris@76: {
Chris@76: $themes = explode(',', $modSettings['knownThemes']);
Chris@76: if (!in_array($id_theme, $themes))
Chris@76: $id_theme = $modSettings['theme_guests'];
Chris@76: else
Chris@76: $id_theme = (int) $id_theme;
Chris@76: }
Chris@76: else
Chris@76: $id_theme = (int) $id_theme;
Chris@76:
Chris@76: $member = empty($user_info['id']) ? -1 : $user_info['id'];
Chris@76:
Chris@76: if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
Chris@76: {
Chris@76: $themeData = $temp;
Chris@76: $flag = true;
Chris@76: }
Chris@76: elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
Chris@76: $themeData = $temp + array($member => array());
Chris@76: else
Chris@76: $themeData = array(-1 => array(), 0 => array(), $member => array());
Chris@76:
Chris@76: if (empty($flag))
Chris@76: {
Chris@76: // Load variables from the current or default theme, global or this user's.
Chris@76: $result = $smcFunc['db_query']('', '
Chris@76: SELECT variable, value, id_member, id_theme
Chris@76: FROM {db_prefix}themes
Chris@76: WHERE id_member' . (empty($themeData[0]) ? ' IN (-1, 0, {int:id_member})' : ' = {int:id_member}') . '
Chris@76: AND id_theme' . ($id_theme == 1 ? ' = {int:id_theme}' : ' IN ({int:id_theme}, 1)'),
Chris@76: array(
Chris@76: 'id_theme' => $id_theme,
Chris@76: 'id_member' => $member,
Chris@76: )
Chris@76: );
Chris@76: // Pick between $settings and $options depending on whose data it is.
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($result))
Chris@76: {
Chris@76: // There are just things we shouldn't be able to change as members.
Chris@76: if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
Chris@76: continue;
Chris@76:
Chris@76: // If this is the theme_dir of the default theme, store it.
Chris@76: if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
Chris@76: $themeData[0]['default_' . $row['variable']] = $row['value'];
Chris@76:
Chris@76: // If this isn't set yet, is a theme option, or is not the default theme..
Chris@76: if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
Chris@76: $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
Chris@76: }
Chris@76: $smcFunc['db_free_result']($result);
Chris@76:
Chris@76: if (!empty($themeData[-1]))
Chris@76: foreach ($themeData[-1] as $k => $v)
Chris@76: {
Chris@76: if (!isset($themeData[$member][$k]))
Chris@76: $themeData[$member][$k] = $v;
Chris@76: }
Chris@76:
Chris@76: if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
Chris@76: cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
Chris@76: // Only if we didn't already load that part of the cache...
Chris@76: elseif (!isset($temp))
Chris@76: cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
Chris@76: }
Chris@76:
Chris@76: $settings = $themeData[0];
Chris@76: $options = $themeData[$member];
Chris@76:
Chris@76: $settings['theme_id'] = $id_theme;
Chris@76:
Chris@76: $settings['actual_theme_url'] = $settings['theme_url'];
Chris@76: $settings['actual_images_url'] = $settings['images_url'];
Chris@76: $settings['actual_theme_dir'] = $settings['theme_dir'];
Chris@76:
Chris@76: $settings['template_dirs'] = array();
Chris@76: // This theme first.
Chris@76: $settings['template_dirs'][] = $settings['theme_dir'];
Chris@76:
Chris@76: // Based on theme (if there is one).
Chris@76: if (!empty($settings['base_theme_dir']))
Chris@76: $settings['template_dirs'][] = $settings['base_theme_dir'];
Chris@76:
Chris@76: // Lastly the default theme.
Chris@76: if ($settings['theme_dir'] != $settings['default_theme_dir'])
Chris@76: $settings['template_dirs'][] = $settings['default_theme_dir'];
Chris@76:
Chris@76: if (!$initialize)
Chris@76: return;
Chris@76:
Chris@76: // Check to see if they're accessing it from the wrong place.
Chris@76: if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
Chris@76: {
Chris@76: $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
Chris@76: $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
Chris@76: $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
Chris@76: if ($temp != '/')
Chris@76: $detected_url .= $temp;
Chris@76: }
Chris@76: if (isset($detected_url) && $detected_url != $boardurl)
Chris@76: {
Chris@76: // Try #1 - check if it's in a list of alias addresses.
Chris@76: if (!empty($modSettings['forum_alias_urls']))
Chris@76: {
Chris@76: $aliases = explode(',', $modSettings['forum_alias_urls']);
Chris@76:
Chris@76: foreach ($aliases as $alias)
Chris@76: {
Chris@76: // Rip off all the boring parts, spaces, etc.
Chris@76: if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
Chris@76: $do_fix = true;
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Hmm... check #2 - is it just different by a www? Send them to the correct place!!
Chris@76: if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
Chris@76: {
Chris@76: // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
Chris@76: if (empty($_GET))
Chris@76: redirectexit('wwwRedirect');
Chris@76: else
Chris@76: {
Chris@76: list ($k, $v) = each($_GET);
Chris@76:
Chris@76: if ($k != 'wwwRedirect')
Chris@76: redirectexit('wwwRedirect;' . $k . '=' . $v);
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // #3 is just a check for SSL...
Chris@76: if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
Chris@76: $do_fix = true;
Chris@76:
Chris@76: // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...)
Chris@76: if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
Chris@76: {
Chris@76: // Caching is good ;).
Chris@76: $oldurl = $boardurl;
Chris@76:
Chris@76: // Fix $boardurl and $scripturl.
Chris@76: $boardurl = $detected_url;
Chris@76: $scripturl = strtr($scripturl, array($oldurl => $boardurl));
Chris@76: $_SERVER['REQUEST_URL'] = strtr($_SERVER['REQUEST_URL'], array($oldurl => $boardurl));
Chris@76:
Chris@76: // Fix the theme urls...
Chris@76: $settings['theme_url'] = strtr($settings['theme_url'], array($oldurl => $boardurl));
Chris@76: $settings['default_theme_url'] = strtr($settings['default_theme_url'], array($oldurl => $boardurl));
Chris@76: $settings['actual_theme_url'] = strtr($settings['actual_theme_url'], array($oldurl => $boardurl));
Chris@76: $settings['images_url'] = strtr($settings['images_url'], array($oldurl => $boardurl));
Chris@76: $settings['default_images_url'] = strtr($settings['default_images_url'], array($oldurl => $boardurl));
Chris@76: $settings['actual_images_url'] = strtr($settings['actual_images_url'], array($oldurl => $boardurl));
Chris@76:
Chris@76: // And just a few mod settings :).
Chris@76: $modSettings['smileys_url'] = strtr($modSettings['smileys_url'], array($oldurl => $boardurl));
Chris@76: $modSettings['avatar_url'] = strtr($modSettings['avatar_url'], array($oldurl => $boardurl));
Chris@76:
Chris@76: // Clean up after loadBoard().
Chris@76: if (isset($board_info['moderators']))
Chris@76: {
Chris@76: foreach ($board_info['moderators'] as $k => $dummy)
Chris@76: {
Chris@76: $board_info['moderators'][$k]['href'] = strtr($dummy['href'], array($oldurl => $boardurl));
Chris@76: $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
Chris@76: }
Chris@76: }
Chris@76: foreach ($context['linktree'] as $k => $dummy)
Chris@76: $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
Chris@76: }
Chris@76: }
Chris@76: // Set up the contextual user array.
Chris@76: $context['user'] = array(
Chris@76: 'id' => $user_info['id'],
Chris@76: 'is_logged' => !$user_info['is_guest'],
Chris@76: 'is_guest' => &$user_info['is_guest'],
Chris@76: 'is_admin' => &$user_info['is_admin'],
Chris@76: 'is_mod' => &$user_info['is_mod'],
Chris@76: // A user can mod if they have permission to see the mod center, or they are a board/group/approval moderator.
Chris@76: 'can_mod' => allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])))),
Chris@76: 'username' => $user_info['username'],
Chris@76: 'language' => $user_info['language'],
Chris@76: 'email' => $user_info['email'],
Chris@76: 'ignoreusers' => $user_info['ignoreusers'],
Chris@76: );
Chris@76: if (!$context['user']['is_guest'])
Chris@76: $context['user']['name'] = $user_info['name'];
Chris@76: elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
Chris@76: $context['user']['name'] = $txt['guest_title'];
Chris@76:
Chris@76: // Determine the current smiley set.
Chris@76: $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'];
Chris@76: $context['user']['smiley_set'] = $user_info['smiley_set'];
Chris@76:
Chris@76: // Some basic information...
Chris@76: if (!isset($context['html_headers']))
Chris@76: $context['html_headers'] = '';
Chris@76:
Chris@76: $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
Chris@76: $context['session_var'] = $_SESSION['session_var'];
Chris@76: $context['session_id'] = $_SESSION['session_value'];
Chris@76: $context['forum_name'] = $mbname;
Chris@76: $context['forum_name_html_safe'] = $smcFunc['htmlspecialchars']($context['forum_name']);
Chris@76: $context['header_logo_url_html_safe'] = empty($settings['header_logo_url']) ? '' : $smcFunc['htmlspecialchars']($settings['header_logo_url']);
Chris@76: $context['current_action'] = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
Chris@76: $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
Chris@76: if (isset($modSettings['load_average']))
Chris@76: $context['load_average'] = $modSettings['load_average'];
Chris@76:
Chris@76: // Set some permission related settings.
Chris@76: $context['show_login_bar'] = $user_info['is_guest'] && !empty($modSettings['enableVBStyleLogin']);
Chris@76:
Chris@76: // This determines the server... not used in many places, except for login fixing.
Chris@76: $context['server'] = array(
Chris@76: 'is_iis' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false,
Chris@76: 'is_apache' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false,
Chris@76: 'is_lighttpd' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false,
Chris@76: 'is_nginx' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false,
Chris@76: 'is_cgi' => isset($_SERVER['SERVER_SOFTWARE']) && strpos(php_sapi_name(), 'cgi') !== false,
Chris@76: 'is_windows' => strpos(PHP_OS, 'WIN') === 0,
Chris@76: 'iso_case_folding' => ord(strtolower(chr(138))) === 154,
Chris@76: 'complex_preg_chars' => @version_compare(PHP_VERSION, '4.3.3') != -1,
Chris@76: );
Chris@76: // A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
Chris@76: $context['server']['needs_login_fix'] = $context['server']['is_cgi'] && $context['server']['is_iis'];
Chris@76:
Chris@76: // Detect the browser. This is separated out because it's also used in attachment downloads
Chris@76: detectBrowser();
Chris@76:
Chris@76: // Set the top level linktree up.
Chris@76: array_unshift($context['linktree'], array(
Chris@76: 'url' => $scripturl,
Chris@76: 'name' => $context['forum_name_html_safe']
Chris@76: ));
Chris@76:
Chris@76: // This allows sticking some HTML on the page output - useful for controls.
Chris@76: $context['insert_after_template'] = '';
Chris@76:
Chris@76: if (!isset($txt))
Chris@76: $txt = array();
Chris@76: $simpleActions = array(
Chris@76: 'findmember',
Chris@76: 'helpadmin',
Chris@76: 'printpage',
Chris@76: 'quotefast',
Chris@76: 'spellcheck',
Chris@76: );
Chris@76:
Chris@76: // Wireless mode? Load up the wireless stuff.
Chris@76: if (WIRELESS)
Chris@76: {
Chris@76: $context['template_layers'] = array(WIRELESS_PROTOCOL);
Chris@76: loadTemplate('Wireless');
Chris@76: loadLanguage('Wireless+index+Modifications');
Chris@76: }
Chris@76: // Output is fully XML, so no need for the index template.
Chris@76: elseif (isset($_REQUEST['xml']))
Chris@76: {
Chris@76: loadLanguage('index+Modifications');
Chris@76: loadTemplate('Xml');
Chris@76: $context['template_layers'] = array();
Chris@76: }
Chris@76: // These actions don't require the index template at all.
Chris@76: elseif (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], $simpleActions))
Chris@76: {
Chris@76: loadLanguage('index+Modifications');
Chris@76: $context['template_layers'] = array();
Chris@76: }
Chris@76: else
Chris@76: {
Chris@76: // Custom templates to load, or just default?
Chris@76: if (isset($settings['theme_templates']))
Chris@76: $templates = explode(',', $settings['theme_templates']);
Chris@76: else
Chris@76: $templates = array('index');
Chris@76:
Chris@76: // Load each template...
Chris@76: foreach ($templates as $template)
Chris@76: loadTemplate($template);
Chris@76:
Chris@76: // ...and attempt to load their associated language files.
Chris@76: $required_files = implode('+', array_merge($templates, array('Modifications')));
Chris@76: loadLanguage($required_files, '', false);
Chris@76:
Chris@76: // Custom template layers?
Chris@76: if (isset($settings['theme_layers']))
Chris@76: $context['template_layers'] = explode(',', $settings['theme_layers']);
Chris@76: else
Chris@76: $context['template_layers'] = array('html', 'body');
Chris@76: }
Chris@76:
Chris@76: // Initialize the theme.
Chris@76: loadSubTemplate('init', 'ignore');
Chris@76:
Chris@76: // Load the compatibility stylesheet if the theme hasn't been updated for 2.0 RC2 (yet).
Chris@76: if (isset($settings['theme_version']) && (version_compare($settings['theme_version'], '2.0 RC2', '<') || strpos($settings['theme_version'], '2.0 Beta') !== false))
Chris@76: loadTemplate(false, 'compat');
Chris@76:
Chris@76: // Guests may still need a name.
Chris@76: if ($context['user']['is_guest'] && empty($context['user']['name']))
Chris@76: $context['user']['name'] = $txt['guest_title'];
Chris@76:
Chris@76: // Any theme-related strings that need to be loaded?
Chris@76: if (!empty($settings['require_theme_strings']))
Chris@76: loadLanguage('ThemeStrings', '', false);
Chris@76:
Chris@76: // We allow theme variants, because we're cool.
Chris@76: $context['theme_variant'] = '';
Chris@76: $context['theme_variant_url'] = '';
Chris@76: if (!empty($settings['theme_variants']))
Chris@76: {
Chris@76: // Overriding - for previews and that ilk.
Chris@76: if (!empty($_REQUEST['variant']))
Chris@76: $_SESSION['id_variant'] = $_REQUEST['variant'];
Chris@76: // User selection?
Chris@76: if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
Chris@76: $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
Chris@76: // If not a user variant, select the default.
Chris@76: if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
Chris@76: $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
Chris@76:
Chris@76: // Do this to keep things easier in the templates.
Chris@76: $context['theme_variant'] = '_' . $context['theme_variant'];
Chris@76: $context['theme_variant_url'] = $context['theme_variant'] . '/';
Chris@76: }
Chris@76:
Chris@76: // Let's be compatible with old themes!
Chris@76: if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
Chris@76: $context['template_layers'] = array('main');
Chris@76:
Chris@76: // Allow overriding the board wide time/number formats.
Chris@76: if (empty($user_settings['time_format']) && !empty($txt['time_format']))
Chris@76: $user_info['time_format'] = $txt['time_format'];
Chris@76: $txt['number_format'] = empty($txt['number_format']) ? empty($modSettings['number_format']) ? '' : $modSettings['number_format'] : $txt['number_format'];
Chris@76:
Chris@76: if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'always')
Chris@76: {
Chris@76: $settings['theme_url'] = $settings['default_theme_url'];
Chris@76: $settings['images_url'] = $settings['default_images_url'];
Chris@76: $settings['theme_dir'] = $settings['default_theme_dir'];
Chris@76: }
Chris@76: // Make a special URL for the language.
Chris@76: $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
Chris@76:
Chris@76: // Set the character set from the template.
Chris@76: $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
Chris@76: $context['utf8'] = $context['character_set'] === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || @version_compare(PHP_VERSION, '4.2.3') != -1);
Chris@76: $context['right_to_left'] = !empty($txt['lang_rtl']);
Chris@76:
Chris@76: $context['tabindex'] = 1;
Chris@76:
Chris@76: // Fix font size with HTML 4.01, etc.
Chris@76: if (isset($settings['doctype']))
Chris@76: $context['browser']['needs_size_fix'] |= $settings['doctype'] == 'html' && $context['browser']['is_ie6'];
Chris@76:
Chris@76: // Compatibility.
Chris@76: if (!isset($settings['theme_version']))
Chris@76: $modSettings['memberCount'] = $modSettings['totalMembers'];
Chris@76:
Chris@76: // This allows us to change the way things look for the admin.
Chris@76: $context['admin_features'] = isset($modSettings['admin_features']) ? explode(',', $modSettings['admin_features']) : array('cd,cp,k,w,rg,ml,pm');
Chris@76:
Chris@76: // If we think we have mail to send, let's offer up some possibilities... robots get pain (Now with scheduled task support!)
Chris@76: if ((!empty($modSettings['mail_next_send']) && $modSettings['mail_next_send'] < time() && empty($modSettings['mail_queue_use_cron'])) || empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
Chris@76: {
Chris@76: if ($context['browser']['possibly_robot'])
Chris@76: {
Chris@76: //!!! Maybe move this somewhere better?!
Chris@76: require_once($sourcedir . '/ScheduledTasks.php');
Chris@76:
Chris@76: // What to do, what to do?!
Chris@76: if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
Chris@76: AutoTask();
Chris@76: else
Chris@76: ReduceMailQueue();
Chris@76: }
Chris@76: else
Chris@76: {
Chris@76: $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
Chris@76: $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
Chris@76:
Chris@76: $context['html_headers'] .= '
Chris@76: ';
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Any files to include at this point?
Chris@76: if (!empty($modSettings['integrate_theme_include']))
Chris@76: {
Chris@76: $theme_includes = explode(',', $modSettings['integrate_theme_include']);
Chris@76: foreach ($theme_includes as $include)
Chris@76: {
Chris@76: $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
Chris@76: if (file_exists($include))
Chris@76: require_once($include);
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Call load theme integration functions.
Chris@76: call_integration_hook('integrate_load_theme');
Chris@76:
Chris@76: // We are ready to go.
Chris@76: $context['theme_loaded'] = true;
Chris@76: }
Chris@76:
Chris@76: // Load a template - if the theme doesn't include it, use the default.
Chris@76: function loadTemplate($template_name, $style_sheets = array(), $fatal = true)
Chris@76: {
Chris@76: global $context, $settings, $txt, $scripturl, $boarddir, $db_show_debug;
Chris@76:
Chris@76: // Do any style sheets first, cause we're easy with those.
Chris@76: if (!empty($style_sheets))
Chris@76: {
Chris@76: if (!is_array($style_sheets))
Chris@76: $style_sheets = array($style_sheets);
Chris@76:
Chris@76: foreach ($style_sheets as $sheet)
Chris@76: {
Chris@76: // Prevent the style sheet from being included twice.
Chris@76: if (strpos($context['html_headers'], 'id="' . $sheet . '_css"') !== false)
Chris@76: continue;
Chris@76:
Chris@76: $sheet_path = file_exists($settings['theme_dir']. '/css/' . $sheet . '.css') ? 'theme_url' : (file_exists($settings['default_theme_dir']. '/css/' . $sheet . '.css') ? 'default_theme_url' : '');
Chris@76: if ($sheet_path)
Chris@76: {
Chris@76: $context['html_headers'] .= "\n\t" . '';
Chris@76: if ($db_show_debug === true)
Chris@76: $context['debug']['sheets'][] = $sheet . ' (' . basename($settings[$sheet_path]) . ')';
Chris@76: }
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // No template to load?
Chris@76: if ($template_name === false)
Chris@76: return true;
Chris@76:
Chris@76: $loaded = false;
Chris@76: foreach ($settings['template_dirs'] as $template_dir)
Chris@76: {
Chris@76: if (file_exists($template_dir . '/' . $template_name . '.template.php'))
Chris@76: {
Chris@76: $loaded = true;
Chris@76: template_include($template_dir . '/' . $template_name . '.template.php', true);
Chris@76: break;
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: if ($loaded)
Chris@76: {
Chris@76: // For compatibility reasons, if this is the index template without new functions, include compatible stuff.
Chris@76: if (substr($template_name, 0, 5) == 'index' && !function_exists('template_button_strip'))
Chris@76: loadTemplate('Compat');
Chris@76:
Chris@76: if ($db_show_debug === true)
Chris@76: $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
Chris@76:
Chris@76: // If they have specified an initialization function for this template, go ahead and call it now.
Chris@76: if (function_exists('template_' . $template_name . '_init'))
Chris@76: call_user_func('template_' . $template_name . '_init');
Chris@76: }
Chris@76: // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it?
Chris@76: elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
Chris@76: {
Chris@76: $settings['default_theme_dir'] = $boarddir . '/Themes/default';
Chris@76: $settings['template_dirs'][] = $settings['default_theme_dir'];
Chris@76:
Chris@76: if (!empty($context['user']['is_admin']) && !isset($_GET['th']))
Chris@76: {
Chris@76: loadLanguage('Errors');
Chris@76: echo '
Chris@76: