/** * Actually register the member. * @todo split this function in two functions: * - a function that handles action=register2, which needs no parameter; * - a function that processes the case of OpenID verification. * * @param bool $verifiedOpenID = false */ public function action_register2($verifiedOpenID = false) { global $txt, $modSettings, $context, $user_info; // Start collecting together any errors. $reg_errors = Error_Context::context('register', 0); // We can't validate the token and the session with OpenID enabled. if (!$verifiedOpenID) { checkSession(); if (!validateToken('register', 'post', true, false)) { $reg_errors->addError('token_verification'); } } // Did we save some open ID fields? if ($verifiedOpenID && !empty($context['openid_save_fields'])) { foreach ($context['openid_save_fields'] as $id => $value) { $_POST[$id] = $value; } } // You can't register if it's disabled. if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { fatal_lang_error('registration_disabled', false); } // If we're using an agreement checkbox, did they check it? if (!empty($modSettings['checkboxAgreement']) && !empty($_POST['checkbox_agreement'])) { $_SESSION['registration_agreed'] = true; } // Things we don't do for people who have already confirmed their OpenID allegances via register. if (!$verifiedOpenID) { // Well, if you don't agree, you can't register. if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { redirectexit(); } // Make sure they came from *somewhere*, have a session. if (!isset($_SESSION['old_url'])) { redirectexit('action=register'); } // If we don't require an agreement, we need a extra check for coppa. if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); } // Are they under age, and under age users are banned? if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) { loadLanguage('Login'); fatal_lang_error('under_age_registration_prohibited', false, array($modSettings['coppaAge'])); } // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { redirectexit('action=register'); } // Failing that, check the time limit for exessive speed. if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) { loadLanguage('Login'); $reg_errors->addError('too_quickly'); } // Check whether the visual verification code was entered correctly. if (!empty($modSettings['reg_verification'])) { require_once SUBSDIR . '/VerificationControls.class.php'; $verificationOptions = array('id' => 'register'); $context['visual_verification'] = create_control_verification($verificationOptions, true); if (is_array($context['visual_verification'])) { foreach ($context['visual_verification'] as $error) { $reg_errors->addError($error); } } } } foreach ($_POST as $key => $value) { if (!is_array($_POST[$key])) { $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); } } // Collect all extra registration fields someone might have filled in. $possible_strings = array('birthdate', 'time_format', 'buddy_list', 'pm_ignore_list', 'smiley_set', 'personal_text', 'avatar', 'lngfile', 'location', 'secret_question', 'secret_answer', 'website_url', 'website_title'); $possible_ints = array('pm_email_notify', 'notify_types', 'id_theme', 'gender'); $possible_floats = array('time_offset'); $possible_bools = array('notify_announcements', 'notify_regularity', 'notify_send_body', 'hide_email', 'show_online'); if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { $_POST['secret_answer'] = md5($_POST['secret_answer']); } // Needed for isReservedName() and registerMember(). require_once SUBSDIR . '/Members.subs.php'; // Validation... even if we're not a mall. if (isset($_POST['real_name']) && (!empty($modSettings['allow_editDisplayName']) || allowedTo('moderate_forum'))) { $_POST['real_name'] = trim(preg_replace('~[\\t\\n\\r \\x0B\\0\\x{A0}\\x{AD}\\x{2000}-\\x{200F}\\x{201F}\\x{202F}\\x{3000}\\x{FEFF}]+~u', ' ', $_POST['real_name'])); if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && Util::strlen($_POST['real_name']) < 60) { $possible_strings[] = 'real_name'; } } // Handle a string as a birthdate... if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); } elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); } // By default assume email is hidden, only show it if we tell it to. $_POST['hide_email'] = !empty($_POST['allow_email']) ? 0 : 1; // Validate the passed language file. if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) { // Do we have any languages? $context['languages'] = getLanguages(); // Did we find it? if (isset($context['languages'][$_POST['lngfile']])) { $_SESSION['language'] = $_POST['lngfile']; } else { unset($_POST['lngfile']); } } else { unset($_POST['lngfile']); } // Some of these fields we may not want. if (!empty($modSettings['registration_fields'])) { // But we might want some of them if the admin asks for them. $standard_fields = array('location', 'gender'); $reg_fields = explode(',', $modSettings['registration_fields']); $exclude_fields = array_diff($standard_fields, $reg_fields); // Website is a little different if (!in_array('website', $reg_fields)) { $exclude_fields = array_merge($exclude_fields, array('website_url', 'website_title')); } // We used to accept signature on registration but it's being abused by spammers these days, so no more. $exclude_fields[] = 'signature'; } else { $exclude_fields = array('signature', 'location', 'gender', 'website_url', 'website_title'); } $possible_strings = array_diff($possible_strings, $exclude_fields); $possible_ints = array_diff($possible_ints, $exclude_fields); $possible_floats = array_diff($possible_floats, $exclude_fields); $possible_bools = array_diff($possible_bools, $exclude_fields); // Set the options needed for registration. $regOptions = array('interface' => 'guest', 'username' => !empty($_POST['user']) ? $_POST['user'] : '', 'email' => !empty($_POST['email']) ? $_POST['email'] : '', 'password' => !empty($_POST['passwrd1']) ? $_POST['passwrd1'] : '', 'password_check' => !empty($_POST['passwrd2']) ? $_POST['passwrd2'] : '', 'openid' => !empty($_POST['openid_identifier']) ? $_POST['openid_identifier'] : '', 'auth_method' => !empty($_POST['authenticate']) ? $_POST['authenticate'] : '', 'check_reserved_name' => true, 'check_password_strength' => true, 'check_email_ban' => true, 'send_welcome_email' => !empty($modSettings['send_welcomeEmail']), 'require' => !empty($modSettings['coppaAge']) && !$verifiedOpenID && empty($_SESSION['skip_coppa']) ? 'coppa' : (empty($modSettings['registration_method']) ? 'nothing' : ($modSettings['registration_method'] == 1 ? 'activation' : 'approval')), 'extra_register_vars' => array(), 'theme_vars' => array()); // Include the additional options that might have been filled in. foreach ($possible_strings as $var) { if (isset($_POST[$var])) { $regOptions['extra_register_vars'][$var] = Util::htmlspecialchars($_POST[$var], ENT_QUOTES); } } foreach ($possible_ints as $var) { if (isset($_POST[$var])) { $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; } } foreach ($possible_floats as $var) { if (isset($_POST[$var])) { $regOptions['extra_register_vars'][$var] = (double) $_POST[$var]; } } foreach ($possible_bools as $var) { if (isset($_POST[$var])) { $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; } } // Registration options are always default options... if (isset($_POST['default_options'])) { $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; } $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); // Make sure they are clean, dammit! $regOptions['theme_vars'] = htmlspecialchars__recursive($regOptions['theme_vars']); // Check whether we have fields that simply MUST be displayed? require_once SUBSDIR . '/Profile.subs.php'; loadCustomFields(0, 'register'); foreach ($context['custom_fields'] as $row) { // Don't allow overriding of the theme variables. if (isset($regOptions['theme_vars'][$row['colname']])) { unset($regOptions['theme_vars'][$row['colname']]); } // Prepare the value! $value = isset($_POST['customfield'][$row['colname']]) ? trim($_POST['customfield'][$row['colname']]) : ''; // We only care for text fields as the others are valid to be empty. if (!in_array($row['type'], array('check', 'select', 'radio'))) { // Is it too long? if ($row['field_length'] && $row['field_length'] < Util::strlen($value)) { $reg_errors->addError(array('custom_field_too_long', array($row['name'], $row['field_length']))); } // Any masks to apply? if ($row['type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') { // @todo We never error on this - just ignore it at the moment... if ($row['mask'] == 'email' && !isValidEmail($value)) { $reg_errors->addError(array('custom_field_invalid_email', array($row['name']))); } elseif ($row['mask'] == 'number' && preg_match('~[^\\d]~', $value)) { $reg_errors->addError(array('custom_field_not_number', array($row['name']))); } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) !== '' && preg_match(substr($row['mask'], 5), $value) === 0) { $reg_errors->addError(array('custom_field_inproper_format', array($row['name']))); } } } // Is this required but not there? if (trim($value) == '' && $row['show_reg'] > 1) { $reg_errors->addError(array('custom_field_empty', array($row['name']))); } } // Lets check for other errors before trying to register the member. if ($reg_errors->hasErrors()) { $_REQUEST['step'] = 2; // If they've filled in some details but made an error then they need less time to finish $_SESSION['register']['limit'] = 4; return $this->action_register(); } // If they're wanting to use OpenID we need to validate them first. if (empty($_SESSION['openid']['verified']) && !empty($_POST['authenticate']) && $_POST['authenticate'] == 'openid') { // What do we need to save? $save_variables = array(); foreach ($_POST as $k => $v) { if (!in_array($k, array('sc', 'sesc', $context['session_var'], 'passwrd1', 'passwrd2', 'regSubmit'))) { $save_variables[$k] = $v; } } require_once SUBSDIR . '/OpenID.subs.php'; $openID = new OpenID(); $openID->validate($_POST['openid_identifier'], false, $save_variables); } elseif ($verifiedOpenID || (!empty($_POST['openid_identifier']) || !empty($_SESSION['openid']['openid_uri'])) && $_POST['authenticate'] == 'openid') { $regOptions['username'] = !empty($_POST['user']) && trim($_POST['user']) != '' ? $_POST['user'] : $_SESSION['openid']['nickname']; $regOptions['email'] = !empty($_POST['email']) && trim($_POST['email']) != '' ? $_POST['email'] : $_SESSION['openid']['email']; $regOptions['auth_method'] = 'openid'; $regOptions['openid'] = !empty($_SESSION['openid']['openid_uri']) ? $_SESSION['openid']['openid_uri'] : (!empty($_POST['openid_identifier']) ? $_POST['openid_identifier'] : ''); } // Registration needs to know your IP $req = request(); $regOptions['ip'] = $user_info['ip']; $regOptions['ip2'] = $req->ban_ip(); $memberID = registerMember($regOptions, 'register'); // If there are "important" errors and you are not an admin: log the first error // Otherwise grab all of them and don't log anything if ($reg_errors->hasErrors(1) && !$user_info['is_admin']) { foreach ($reg_errors->prepareErrors(1) as $error) { fatal_error($error, 'general'); } } // Was there actually an error of some kind dear boy? if ($reg_errors->hasErrors()) { $_REQUEST['step'] = 2; return $this->action_register(); } // Do our spam protection now. spamProtection('register'); // We'll do custom fields after as then we get to use the helper function! if (!empty($_POST['customfield'])) { require_once SUBSDIR . '/Profile.subs.php'; makeCustomFieldChanges($memberID, 'register'); } // If COPPA has been selected then things get complicated, setup the template. if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { redirectexit('action=coppa;member=' . $memberID); } elseif (!empty($modSettings['registration_method'])) { loadTemplate('Register'); $context += array('page_title' => $txt['register'], 'title' => $txt['registration_successful'], 'sub_template' => 'after', 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration']); } else { call_integration_hook('integrate_activate', array($regOptions['username'])); setLoginCookie(60 * $modSettings['cookieTime'], $memberID, hash('sha256', Util::strtolower($regOptions['username']) . $regOptions['password'] . $regOptions['register_vars']['password_salt'])); redirectexit('action=auth;sa=check;member=' . $memberID, $context['server']['needs_login_fix']); } }
function summary($memID) { global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $sourcedir, $scripturl, $smcFunc; // Attempt to load the member's profile data. if (!loadMemberContext($memID) || !isset($memberContext[$memID])) { fatal_lang_error('not_a_user', false); } // Set up the stuff and load the user. $context += array('page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']), 'can_send_pm' => allowedTo('pm_send'), 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']), 'can_issue_warning' => in_array('w', $context['admin_features']) && allowedTo('issue_warning') && $modSettings['warning_settings'][0] == 1); $context['member'] =& $memberContext[$memID]; $context['can_view_warning'] = in_array('w', $context['admin_features']) && (allowedTo('issue_warning') && !$context['user']['is_owner']) || !empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $context['user']['is_owner']); // Set a canonical URL for this page. $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID; // Are there things we don't show? $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); // See if they have broken any warning levels... list($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']); if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) { $context['warning_status'] = $txt['profile_warning_is_muted']; } elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) { $context['warning_status'] = $txt['profile_warning_is_moderation']; } elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) { $context['warning_status'] = $txt['profile_warning_is_watch']; } // They haven't even been registered for a full day!? $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24)); if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) { $context['member']['posts_per_day'] = $txt['not_applicable']; } else { $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); } // Set the age... if (empty($context['member']['birth_date'])) { $context['member'] += array('age' => $txt['not_applicable'], 'today_is_birthday' => false); } else { list($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d'); $datearray = getdate(forum_time()); $context['member'] += array('age' => $birth_year <= 4 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - ($datearray['mon'] > $birth_month || $datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day ? 0 : 1), 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day); } if (allowedTo('moderate_forum')) { // Make sure it's a valid ip address; otherwise, don't bother... if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) { $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); } else { $context['member']['hostname'] = ''; } $context['can_see_ip'] = true; } else { $context['can_see_ip'] = false; } if (!empty($modSettings['who_enabled'])) { include_once $sourcedir . '/Who.php'; $action = determineActions($user_profile[$memID]['url']); if ($action !== false) { $context['member']['action'] = $action; } } // If the user is awaiting activation, and the viewer has permission - setup some activation context messages. if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum')) { $context['activate_type'] = $context['member']['is_activated']; // What should the link text be? $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate']; // Should we show a custom message? $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated']; } // Is the signature even enabled on this forum? $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1; // How about, are they banned? $context['member']['bans'] = array(); if (allowedTo('moderate_forum')) { // Can they edit the ban? $context['can_edit_ban'] = allowedTo('manage_bans'); $ban_query = array(); $ban_query_vars = array('time' => time()); $ban_query[] = 'id_member = ' . $context['member']['id']; // Valid IP? if (preg_match('/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/', $memberContext[$memID]['ip'], $ip_parts) == 1) { $ban_query[] = '((' . $ip_parts[1] . ' BETWEEN bi.ip_low1 AND bi.ip_high1) AND (' . $ip_parts[2] . ' BETWEEN bi.ip_low2 AND bi.ip_high2) AND (' . $ip_parts[3] . ' BETWEEN bi.ip_low3 AND bi.ip_high3) AND (' . $ip_parts[4] . ' BETWEEN bi.ip_low4 AND bi.ip_high4))'; // Do we have a hostname already? if (!empty($context['member']['hostname'])) { $ban_query[] = '({string:hostname} LIKE hostname)'; $ban_query_vars['hostname'] = $context['member']['hostname']; } } elseif ($memberContext[$memID]['ip'] == 'unknown') { $ban_query[] = '(bi.ip_low1 = 255 AND bi.ip_high1 = 255 AND bi.ip_low2 = 255 AND bi.ip_high2 = 255 AND bi.ip_low3 = 255 AND bi.ip_high3 = 255 AND bi.ip_low4 = 255 AND bi.ip_high4 = 255)'; } // Check their email as well... if (strlen($context['member']['email']) != 0) { $ban_query[] = '({string:email} LIKE bi.email_address)'; $ban_query_vars['email'] = $context['member']['email']; } // So... are they banned? Dying to know! $request = $smcFunc['db_query']('', ' SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post, bg.cannot_register, bg.cannot_login, bg.reason FROM {db_prefix}ban_items AS bi INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time})) WHERE (' . implode(' OR ', $ban_query) . ')', $ban_query_vars); while ($row = $smcFunc['db_fetch_assoc']($request)) { // Work out what restrictions we actually have. $ban_restrictions = array(); foreach (array('access', 'register', 'login', 'post') as $type) { if ($row['cannot_' . $type]) { $ban_restrictions[] = $txt['ban_type_' . $type]; } } // No actual ban in place? if (empty($ban_restrictions)) { continue; } // Prepare the link for context. $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>'); $context['member']['bans'][$row['id_ban_group']] = array('reason' => empty($row['reason']) ? '' : '<br /><br /><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'], 'cannot' => array('access' => !empty($row['cannot_access']), 'register' => !empty($row['cannot_register']), 'post' => !empty($row['cannot_post']), 'login' => !empty($row['cannot_login'])), 'explanation' => $ban_explanation); } $smcFunc['db_free_result']($request); } loadCustomFields($memID); }
function Register($reg_errors = array()) { global $txt, $boarddir, $context, $modSettings, $user_info; global $language, $scripturl, $sourcedir, $cur_profile; // Is this an incoming AJAX check? if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { return RegisterCheckUsername(); } // Check if the administrator has it disabled. if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { fatal_lang_error('registration_disabled', false); } // If this user is an admin - redirect them to the admin registration page. if (allowedTo('moderate_forum') && !$user_info['is_guest']) { redirectexit('action=admin;area=regcenter;sa=register'); } elseif (empty($user_info['is_guest'])) { redirectexit(); } loadLanguage('Login'); EoS_Smarty::loadTemplate('register/base'); // Do we need them to agree to the registration agreement, first? $context['require_agreement'] = !empty($modSettings['requireAgreement']); $context['registration_passed_agreement'] = !empty($_SESSION['registration_agreed']); $context['show_coppa'] = !empty($modSettings['coppaAge']); // Under age restrictions? if ($context['show_coppa']) { $context['skip_coppa'] = false; $context['coppa_agree_above'] = sprintf($txt['agreement_agree_coppa_above'], $modSettings['coppaAge']); $context['coppa_agree_below'] = sprintf($txt['agreement_agree_coppa_below'], $modSettings['coppaAge']); } // What step are we at? $current_step = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : ($context['require_agreement'] ? 1 : 2); // Does this user agree to the registation agreement? if ($current_step == 1 && (isset($_POST['accept_agreement']) || isset($_POST['accept_agreement_coppa']))) { $context['registration_passed_agreement'] = $_SESSION['registration_agreed'] = true; $current_step = 2; // Skip the coppa procedure if the user says he's old enough. if ($context['show_coppa']) { $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); // Are they saying they're under age, while under age registration is disabled? if (empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) { loadLanguage('Login'); fatal_lang_error('under_age_registration_prohibited', false, array($modSettings['coppaAge'])); } } } elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { $current_step = 1; } // Show the user the right form. EoS_Smarty::getConfigInstance()->registerHookTemplate('register_content_area', $current_step == 1 ? 'register/agreement' : 'register/form'); //$context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; // Add the register chain to the link tree. $context['linktree'][] = array('url' => $scripturl . '?action=register', 'name' => $txt['register']); // If you have to agree to the agreement, it needs to be fetched from the file. if ($context['require_agreement']) { // Have we got a localized one? if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); } elseif (file_exists($boarddir . '/agreement.txt')) { $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); } else { $context['agreement'] = ''; } } if (!empty($modSettings['userLanguage'])) { $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; // Do we have any languages? if (empty($context['languages'])) { getLanguages(); } // Try to find our selected language. foreach ($context['languages'] as $key => $lang) { $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); // Found it! if ($selectedLanguage == $lang['filename']) { $context['languages'][$key]['selected'] = true; } } } // Any custom fields we want filled in? require_once $sourcedir . '/Profile.php'; loadCustomFields(0, 'register'); // Or any standard ones? if (!empty($modSettings['registration_fields'])) { require_once $sourcedir . '/Profile-Modify.php'; // Setup some important context. loadLanguage('Profile'); $context['user']['is_owner'] = true; // Here, and here only, emulate the permissions the user would have to do this. $user_info['permissions'] = array_merge($user_info['permissions'], array('profile_account_own', 'profile_extra_own')); $reg_fields = explode(',', $modSettings['registration_fields']); // We might have had some submissions on this front - go check. foreach ($reg_fields as $field) { if (isset($_POST[$field])) { $cur_profile[$field] = commonAPI::htmlspecialchars($_POST[$field]); } } // Load all the fields in question. setupProfileContext($reg_fields); } // Generate a visual verification code to make sure the user is no bot. if (!empty($modSettings['reg_verification'])) { require_once $sourcedir . '/lib/Subs-Editor.php'; $verificationOptions = array('id' => 'register'); $context['visual_verification'] = create_control_verification($verificationOptions); $context['visual_verification_id'] = $verificationOptions['id']; } else { $context['visual_verification'] = false; } // Are they coming from an OpenID login attempt? if (!empty($_SESSION['openid']['verified']) && !empty($_SESSION['openid']['openid_uri'])) { $context['openid'] = $_SESSION['openid']['openid_uri']; $context['username'] = commonAPI::htmlspecialchars(!empty($_POST['user']) ? $_POST['user'] : $_SESSION['openid']['nickname']); $context['email'] = commonAPI::htmlspecialchars(!empty($_POST['email']) ? $_POST['email'] : $_SESSION['openid']['email']); } else { $context += array('openid' => isset($_POST['openid_identifier']) ? $_POST['openid_identifier'] : '', 'username' => isset($_POST['user']) ? commonAPI::htmlspecialchars($_POST['user']) : '', 'email' => isset($_POST['email']) ? commonAPI::htmlspecialchars($_POST['email']) : ''); } // !!! Why isn't this a simple set operation? // Were there any errors? $context['registration_errors'] = array(); if (!empty($reg_errors)) { foreach ($reg_errors as $error) { $context['registration_errors'][] = $error; } } HookAPI::callHook('register_before'); }
} if ($tags_names_index > 0) { wp_set_object_terms($id, explode(",", $data[$tags_names_index]), 'product_tag'); } $import_count++; } $n++; } fclose($handle); } //WE NEED TO RELOAD ATTRIBUTES BECUSE WE MIGHT CREATED SOME NEW ONES $attributes = array(); $attributes_asoc = array(); loadAttributes($attributes, $attributes_asoc); $custom_fileds = array(); loadCustomFields($plem_settings, $custom_fileds); //////////////////////////////////////////////////////////////////// } } $categories = array(); $cat_asoc = array(); $shipping_classes = array(); $shippclass_asoc = array(); $args = array('number' => 99999, 'orderby' => 'slug', 'order' => 'ASC', 'hide_empty' => false, 'include' => ''); $woo_categories = get_terms('product_cat', $args); foreach ($woo_categories as $category) { $cat = new stdClass(); $cat->category_id = $category->term_id; $cat->category_name = $category->name; $cat->category_slug = urldecode($category->slug); $cat->category_parent = $category->parent;
function shd_profile_theme_wrapper($memID) { global $txt, $context, $user_profile, $modSettings, $settings, $user_info, $smcFunc, $sourcedir, $profile_fields; loadTemplate('Profile'); loadTemplate('sd_template/SimpleDesk-Profile'); $lang_strings = array('current_time', 'theme_info', 'date_format', 'return_to_post', 'timeformat_default', 'theme_forum_default', 'theme_forum_default_desc'); // Replace the standard profile strings with SD specific ones. foreach ($lang_strings as $str) { $txt[$str] = $txt['shd_' . $str]; } loadThemeOptions($memID); if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) { loadCustomFields($memID, 'theme'); } $context['sub_template'] = 'edit_options'; $context['page_desc'] = $txt['theme_info']; $opts = array('id_theme', 'smiley_set', 'hr', 'time_format', 'time_offset', 'hr', 'theme_settings'); if (!empty($modSettings['shd_display_avatar'])) { $opts = array_merge(array('avatar_choice', 'hr'), $opts); } setupProfileContext($opts); $context['profile_fields']['theme_settings']['callback_func'] = 'shd_theme_settings'; }
function theme($memID) { global $txt, $context, $user_profile, $modSettings, $settings, $user_info, $smcFunc; loadThemeOptions($memID); if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) { loadCustomFields($memID, 'theme'); } $context['sub_template'] = 'edit_options'; $context['page_desc'] = $txt['theme_info']; setupProfileContext(array('id_theme', 'smiley_set', 'hr', 'time_format', 'time_offset', 'hr', 'theme_settings')); }
public static function fb_do_custom() { global $context, $sourcedir, $fb_hook_object, $user_info, $smcFunc; if (!empty($fb_hook_object->modSettings['fb_app_enablecp'])) { require_once $sourcedir . '/Profile.php'; loadCustomFields(0, 'register'); if (!empty($fb_hook_object->modSettings['registration_fields'])) { require_once $sourcedir . '/Profile-Modify.php'; loadLanguage('Profile'); loadTemplate('Profile'); $context['user']['is_owner'] = true; $user_info['permissions'] = array_merge($user_info['permissions'], array('profile_account_own', 'profile_extra_own')); $reg_fields = explode(',', $fb_hook_object->modSettings['registration_fields']); foreach ($reg_fields as $field) { if (isset($_POST[$field])) { $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); } } setupProfileContext($reg_fields); } } }
function theme($memID) { global $txt, $context; loadThemeOptions($memID); if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) { loadCustomFields($memID, 'theme'); } EoS_Smarty::loadTemplate('profile/profile_base'); EoS_Smarty::getConfigInstance()->registerHookTemplate('profile_content_area', 'profile/edit_options'); //$context['sub_template'] = 'edit_options'; $context['page_desc'] = $txt['theme_info']; setupProfileContext(array('id_theme', 'smiley_set', 'hr', 'time_format', 'time_offset', 'hr', 'theme_settings')); }
/** * View the user profile summary. * * @uses ProfileInfo template */ public function action_summary() { global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $scripturl, $settings; $memID = currentMemberID(); // Attempt to load the member's profile data. if (!loadMemberContext($memID) || !isset($memberContext[$memID])) { fatal_lang_error('not_a_user', false); } loadTemplate('ProfileInfo'); // Set up the stuff and load the user. $context += array('page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']), 'can_send_pm' => allowedTo('pm_send'), 'can_send_email' => allowedTo('send_email_to_members'), 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']), 'can_issue_warning' => in_array('w', $context['admin_features']) && allowedTo('issue_warning') && !empty($modSettings['warning_enable'])); $context['member'] =& $memberContext[$memID]; $context['can_view_warning'] = in_array('w', $context['admin_features']) && (allowedTo('issue_warning') && !$context['user']['is_owner']) || !empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $context['user']['is_owner']); // Set a canonical URL for this page. $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID; // Are there things we don't show? $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); // Menu tab $context[$context['profile_menu_name']]['tab_data'] = array(); // Tab information for use in the summary page // Each tab template defines a div, the value of which are the template(s) to load in that div // Templates are named template_profile_block_YOURNAME $context['summarytabs'] = array('summary' => array('name' => $txt['summary'], 'templates' => array(array('summary', 'user_info'), array('contact', 'other_info'), array('user_customprofileinfo', 'moderation')), 'active' => true), 'recent' => array('name' => $txt['profile_recent_activity'], 'templates' => array('posts', 'topics', 'attachments'), 'active' => true), 'buddies' => array('name' => $txt['buddies'], 'templates' => array('buddies'), 'active' => !empty($modSettings['enable_buddylist']) && $context['user']['is_owner'])); // Let addons add or remove to the tabs array call_integration_hook('integrate_profile_summary', array($memID)); // Go forward with whats left $summary_areas = ''; foreach ($context['summarytabs'] as $id => $tab) { // If the tab is active we add it if ($tab['active'] !== true) { unset($context['summarytabs'][$id]); } else { // All the active templates, used to prevent processing data we don't need foreach ($tab['templates'] as $template) { $summary_areas .= is_array($template) ? implode(',', $template) : ',' . $template; } } } $summary_areas = explode(',', $summary_areas); // See if they have broken any warning levels... if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) { $context['warning_status'] = $txt['profile_warning_is_muted']; } elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) { $context['warning_status'] = $txt['profile_warning_is_moderation']; } elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) { $context['warning_status'] = $txt['profile_warning_is_watch']; } // They haven't even been registered for a full day!? $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24)); if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) { $context['member']['posts_per_day'] = $txt['not_applicable']; } else { $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); } // Set the age... if (empty($context['member']['birth_date'])) { $context['member'] += array('age' => $txt['not_applicable'], 'today_is_birthday' => false); } else { list($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d'); $datearray = getdate(forum_time()); $context['member'] += array('age' => $birth_year <= 4 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - ($datearray['mon'] > $birth_month || $datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day ? 0 : 1), 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day); } if (allowedTo('moderate_forum')) { // Make sure it's a valid ip address; otherwise, don't bother... if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) { $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); } else { $context['member']['hostname'] = ''; } $context['can_see_ip'] = true; } else { $context['can_see_ip'] = false; } if (!empty($modSettings['who_enabled']) && $context['member']['online']['is_online']) { include_once SUBSDIR . '/Who.subs.php'; $action = determineActions($user_profile[$memID]['url']); loadLanguage('index'); if ($action !== false) { $context['member']['action'] = $action; } } // If the user is awaiting activation, and the viewer has permission - setup some activation context messages. if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum')) { $context['activate_type'] = $context['member']['is_activated']; // What should the link text be? $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate']; // Should we show a custom message? $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated']; $context['activate_url'] = $scripturl . '?action=profile;save;area=activateaccount;u=' . $memID . ';' . $context['session_var'] . '=' . $context['session_id'] . ';' . $context['profile-aa' . $memID . '_token_var'] . '=' . $context['profile-aa' . $memID . '_token']; } // Is the signature even enabled on this forum? $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1; // How about, are they banned? if (allowedTo('moderate_forum')) { require_once SUBSDIR . '/Bans.subs.php'; $hostname = !empty($context['member']['hostname']) ? $context['member']['hostname'] : ''; $email = !empty($context['member']['email']) ? $context['member']['email'] : ''; $context['member']['bans'] = BanCheckUser($memID, $hostname, $email); // Can they edit the ban? $context['can_edit_ban'] = allowedTo('manage_bans'); } // Load up the most recent attachments for this user for use in profile views etc. $context['thumbs'] = array(); if (!empty($modSettings['attachmentEnable']) && !empty($settings['attachments_on_summary']) && in_array('attachments', $summary_areas)) { $boardsAllowed = boardsAllowedTo('view_attachments'); if (empty($boardsAllowed)) { $boardsAllowed = array(-1); } $attachments = $this->list_getAttachments(0, $settings['attachments_on_summary'], 'm.poster_time DESC', $boardsAllowed, $memID); // Some generic images for mime types $mime_images_url = $settings['default_images_url'] . '/mime_images/'; $mime_path = $settings['default_theme_dir'] . '/images/mime_images/'; // Load them in to $context for use in the template for ($i = 0, $count = count($attachments); $i < $count; $i++) { $context['thumbs'][$i] = array('url' => $scripturl . '?action=dlattach;topic=' . $attachments[$i]['topic'] . '.0;attach=' . $attachments[$i]['id'], 'img' => '', 'filename' => $attachments[$i]['filename'], 'downloads' => $attachments[$i]['downloads'], 'subject' => $attachments[$i]['subject'], 'id' => $attachments[$i]['id']); // Show a thumbnail image as well? if ($attachments[$i]['is_image'] && !empty($modSettings['attachmentShowImages']) && !empty($modSettings['attachmentThumbnails'])) { if (!empty($attachments[$i]['id_thumb'])) { $context['thumbs'][$i]['img'] = '<img id="thumb_' . $attachments[$i]['id'] . '" src="' . $scripturl . '?action=dlattach;topic=' . $attachments[$i]['topic'] . '.0;attach=' . $attachments[$i]['id_thumb'] . ';image" title="" alt="" />'; } else { // No thumbnail available ... use html instead if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight'])) { if ($attachments[$i]['width'] > $modSettings['attachmentThumbWidth'] || $attachments[$i]['height'] > $modSettings['attachmentThumbHeight']) { $context['thumbs'][$i]['img'] = '<img id="thumb_' . $attachments[$i]['id'] . '" src="' . $scripturl . '?action=dlattach;topic=' . $attachments[$i]['topic'] . '.0;attach=' . $attachments[$i]['id'] . '" title="" alt="" width="' . $modSettings['attachmentThumbWidth'] . '" height="' . $modSettings['attachmentThumbHeight'] . '" />'; } else { $context['thumbs'][$i]['img'] = '<img id="thumb_' . $attachments[$i]['id'] . '" src="' . $scripturl . '?action=dlattach;topic=' . $attachments[$i]['topic'] . '.0;attach=' . $attachments[$i]['id'] . '" title="" alt="" width="' . $attachments[$i]['width'] . '" height="' . $attachments[$i]['height'] . '" />'; } } } } else { if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && (128 > $modSettings['attachmentThumbWidth'] || 128 > $modSettings['attachmentThumbHeight'])) { $context['thumbs'][$i]['img'] = '<img src="' . $mime_images_url . (!file_exists($mime_path . $attachments[$i]['fileext'] . '.png') ? 'default' : $attachments[$i]['fileext']) . '.png" title="" alt="" width="' . $modSettings['attachmentThumbWidth'] . '" height="' . $modSettings['attachmentThumbHeight'] . '" />'; } else { $context['thumbs'][$i]['img'] = '<img src="' . $mime_images_url . (!file_exists($mime_path . $attachments[$i]['fileext'] . '.png') ? 'default' : $attachments[$i]['fileext']) . '.png" title="" alt="" />'; } } } } // Would you be mine? Could you be mine? Be my buddy :D if (!empty($modSettings['enable_buddylist']) && $context['user']['is_owner'] && !empty($user_info['buddies']) && in_array('buddies', $summary_areas)) { $context['buddies'] = array(); loadMemberData($user_info['buddies'], false, 'profile'); // Get the info for this buddy foreach ($user_info['buddies'] as $buddy) { loadMemberContext($buddy, true); $context['buddies'][$buddy] = $memberContext[$buddy]; } } // How about thier most recent posts? if (in_array('posts', $summary_areas)) { // Is the load average too high just now, then let them know if (!empty($modSettings['loadavg_show_posts']) && $modSettings['current_load'] >= $modSettings['loadavg_show_posts']) { $context['loadaverage'] = true; } else { // Set up to get the last 10 psots of this member $msgCount = count_user_posts($memID); $range_limit = ''; $maxIndex = 10; $start = (int) $_REQUEST['start']; // If they are a frequent poster, we guess the range to help minimize what the query work if ($msgCount > 1000) { list($min_msg_member, $max_msg_member) = findMinMaxUserMessage($memID); $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + 0.1 * ($max_msg_member - $min_msg_member)); $range_limit = 'm.id_msg > ' . ($max_msg_member - $margin); } // Find this user's most recent posts $rows = load_user_posts($memID, 0, $maxIndex, $range_limit); $context['posts'] = array(); foreach ($rows as $row) { // Censor.... censorText($row['body']); censorText($row['subject']); // Do the code. $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); $preview = strip_tags(strtr($row['body'], array('<br />' => ' '))); $preview = Util::shorten_text($preview, !empty($modSettings['ssi_preview_length']) ? $modSettings['ssi_preview_length'] : 128); $short_subject = Util::shorten_text($row['subject'], !empty($modSettings['ssi_subject_length']) ? $modSettings['ssi_subject_length'] : 24); // And the array... $context['posts'][] = array('body' => $preview, 'board' => array('name' => $row['bname'], 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'), 'subject' => $row['subject'], 'short_subject' => $short_subject, 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $short_subject . '</a>'); } } } // How about the most recent topics that they started? if (in_array('topics', $summary_areas)) { // Is the load average still too high? if (!empty($modSettings['loadavg_show_posts']) && $modSettings['current_load'] >= $modSettings['loadavg_show_posts']) { $context['loadaverage'] = true; } else { // Set up to get the last 10 topics of this member $topicCount = count_user_topics($memID); $range_limit = ''; $maxIndex = 10; // If they are a frequent topic starter we guess the range to help the query if ($topicCount > 1000) { list($min_topic_member, $max_topic_member) = findMinMaxUserTopic($memID); $margin = floor(($max_topic_member - $min_topic_member) * (($start + $modSettings['defaultMaxMessages']) / $topicCount) + 0.1 * ($max_topic_member - $min_topic_member)); $margin *= 5; $range_limit = 't.id_first_msg > ' . ($max_topic_member - $margin); } // Find this user's most recent topics $rows = load_user_topics($memID, 0, $maxIndex, $range_limit); $context['topics'] = array(); foreach ($rows as $row) { // Censor.... censorText($row['body']); censorText($row['subject']); // Do the code. $short_subject = Util::shorten_text($row['subject'], !empty($modSettings['ssi_subject_length']) ? $modSettings['ssi_subject_length'] : 24); // And the array... $context['topics'][] = array('board' => array('name' => $row['bname'], 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'), 'subject' => $row['subject'], 'short_subject' => $short_subject, 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $short_subject . '</a>'); } } } // To finish this off, custom profile fields. require_once SUBSDIR . '/Profile.subs.php'; loadCustomFields($memID); // To make tabs work, we need jQueryUI $modSettings['jquery_include_ui'] = true; addInlineJavascript(' $(function() {$( "#tabs" ).tabs();});', true); }
/** * Allow the user to pick a theme. * */ public function action_themepick() { global $txt, $context; $memID = currentMemberID(); loadThemeOptions($memID); if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) { loadCustomFields($memID, 'theme'); } loadTemplate('ProfileOptions'); $context['sub_template'] = 'edit_options'; $context['page_desc'] = $txt['theme_info']; setupProfileContext(array('id_theme', 'smiley_set', 'hr', 'time_format', 'time_offset', 'hr', 'theme_settings'), 'themepick'); }