diff options
Diffstat (limited to 'phpBB/memberlist.php')
-rw-r--r-- | phpBB/memberlist.php | 443 |
1 files changed, 37 insertions, 406 deletions
diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 187b4b1cd9..63541dbee6 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -20,6 +20,14 @@ $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); include($phpbb_root_path . 'includes/functions_display.' . $phpEx); +$mode = request_var('mode', ''); + +if ($mode === 'contactadmin') +{ + define('SKIP_CHECK_BAN', true); + define('SKIP_CHECK_DISABLED', true); +} + // Start session management $user->session_begin(); $auth->acl($user->data); @@ -29,7 +37,6 @@ $user->setup(array('memberlist', 'groups')); $template->assign_var('S_IN_MEMBERLIST', true); // Grab data -$mode = request_var('mode', ''); $action = request_var('action', ''); $user_id = request_var('u', ANONYMOUS); $username = request_var('un', '', true); @@ -44,7 +51,7 @@ if ($mode == 'leaders') } // Check our mode... -if (!in_array($mode, array('', 'group', 'viewprofile', 'email', 'contact', 'searchuser', 'team', 'livesearch'))) +if (!in_array($mode, array('', 'group', 'viewprofile', 'email', 'contact', 'contactadmin', 'searchuser', 'team', 'livesearch'))) { trigger_error('NO_MODE'); } @@ -52,6 +59,7 @@ if (!in_array($mode, array('', 'group', 'viewprofile', 'email', 'contact', 'sear switch ($mode) { case 'email': + case 'contactadmin': break; case 'livesearch': @@ -386,7 +394,7 @@ switch ($mode) $messenger->set_addresses($row); $messenger->assign_vars(array( - 'BOARD_CONTACT' => $config['board_contact'], + 'BOARD_CONTACT' => phpbb_get_board_contact($config, $phpEx), 'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']), 'TO_USERNAME' => htmlspecialchars_decode($row['username']), 'MESSAGE' => htmlspecialchars_decode($message)) @@ -632,7 +640,7 @@ switch ($mode) ); extract($phpbb_dispatcher->trigger_event('core.memberlist_view_profile', compact($vars))); - $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled)); + $template->assign_vars(phpbb_show_profile($member, $user_notes_enabled, $warn_user_enabled)); // If the user has m_approve permission or a_user permission, then list then display unapproved posts if ($auth->acl_getf_global('m_approve') || $auth->acl_get('a_user')) @@ -660,6 +668,7 @@ switch ($mode) 'POSTS_IN_QUEUE'=> $member['posts_in_queue'], 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']), + 'L_SEND_EMAIL_USER' => $user->lang('SEND_EMAIL_USER', $member['username']), 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']), 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']), 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']), @@ -736,265 +745,50 @@ switch ($mode) break; + case 'contactadmin': case 'email': - - // Send an email - $page_title = $user->lang['SEND_EMAIL']; - $template_html = 'memberlist_email.html'; - - add_form_key('memberlist_email'); - - if (!$config['email_enable']) - { - trigger_error('EMAIL_DISABLED'); - } - - if (!$auth->acl_get('u_sendemail')) - { - trigger_error('NO_EMAIL'); - } - - // Are we trying to abuse the facility? - if (time() - $user->data['user_emailtime'] < $config['flood_interval']) + if (!class_exists('messenger')) { - trigger_error('FLOOD_EMAIL_LIMIT'); + include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); } - // Determine action... - $user_id = request_var('u', 0); - $topic_id = request_var('t', 0); + $user_id = request_var('u', 0); + $topic_id = request_var('t', 0); - // Send email to user... if ($user_id) { - if ($user_id == ANONYMOUS || !$config['board_email_form']) - { - trigger_error('NO_EMAIL'); - } - - // Get the appropriate username, etc. - $sql = 'SELECT username, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type - FROM ' . USERS_TABLE . " - WHERE user_id = $user_id - AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')'; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) - { - trigger_error('NO_USER'); - } - - // Can we send email to this user? - if (!$row['user_allow_viewemail'] && !$auth->acl_get('a_user')) - { - trigger_error('NO_EMAIL'); - } + $form_name = 'user'; } else if ($topic_id) { - // Send topic heads-up to email address - $sql = 'SELECT forum_id, topic_title - FROM ' . TOPICS_TABLE . " - WHERE topic_id = $topic_id"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) - { - trigger_error('NO_TOPIC'); - } - - if ($row['forum_id']) - { - if (!$auth->acl_get('f_read', $row['forum_id'])) - { - trigger_error('SORRY_AUTH_READ'); - } - - if (!$auth->acl_get('f_email', $row['forum_id'])) - { - trigger_error('NO_EMAIL'); - } - } - else - { - // If global announcement, we need to check if the user is able to at least read and email in one forum... - if (!$auth->acl_getf_global('f_read')) - { - trigger_error('SORRY_AUTH_READ'); - } - - if (!$auth->acl_getf_global('f_email')) - { - trigger_error('NO_EMAIL'); - } - } + $form_name = 'topic'; + } + else if ($mode === 'contactadmin') + { + $form_name = 'admin'; } else { trigger_error('NO_EMAIL'); } + $form = $phpbb_container->get('message.form.' . $form_name); - $error = array(); - - $name = utf8_normalize_nfc(request_var('name', '', true)); - $email = request_var('email', ''); - $email_lang = request_var('lang', $config['default_lang']); - $subject = utf8_normalize_nfc(request_var('subject', '', true)); - $message = utf8_normalize_nfc(request_var('message', '', true)); - $cc = (isset($_POST['cc_email'])) ? true : false; - $submit = (isset($_POST['submit'])) ? true : false; - - if ($submit) + $form->bind($request); + $error = $form->check_allow(); + if ($error) { - if (!check_form_key('memberlist_email')) - { - $error[] = 'FORM_INVALID'; - } - if ($user_id) - { - if (!$subject) - { - $error[] = $user->lang['EMPTY_SUBJECT_EMAIL']; - } - - if (!$message) - { - $error[] = $user->lang['EMPTY_MESSAGE_EMAIL']; - } - - $name = $row['username']; - $email_lang = $row['user_lang']; - $email = $row['user_email']; - } - else - { - if (!$email || !preg_match('/^' . get_preg_expression('email') . '$/i', $email)) - { - $error[] = $user->lang['EMPTY_ADDRESS_EMAIL']; - } - - if (!$name) - { - $error[] = $user->lang['EMPTY_NAME_EMAIL']; - } - } - - if (!sizeof($error)) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_emailtime = ' . time() . ' - WHERE user_id = ' . $user->data['user_id']; - $result = $db->sql_query($sql); - - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $messenger = new messenger(false); - $email_tpl = ($user_id) ? 'profile_send_email' : 'email_notify'; - - $mail_to_users = array(); - - $mail_to_users[] = array( - 'email_lang' => $email_lang, - 'email' => $email, - 'name' => $name, - 'username' => ($user_id) ? $row['username'] : '', - 'to_name' => $name, - 'user_jabber' => ($user_id) ? $row['user_jabber'] : '', - 'user_notify_type' => ($user_id) ? $row['user_notify_type'] : NOTIFY_EMAIL, - 'topic_title' => (!$user_id) ? $row['topic_title'] : '', - 'forum_id' => (!$user_id) ? $row['forum_id'] : 0, - ); - - // Ok, now the same email if CC specified, but without exposing the users email address - if ($cc) - { - $mail_to_users[] = array( - 'email_lang' => $user->data['user_lang'], - 'email' => $user->data['user_email'], - 'name' => $user->data['username'], - 'username' => $user->data['username'], - 'to_name' => $name, - 'user_jabber' => $user->data['user_jabber'], - 'user_notify_type' => ($user_id) ? $user->data['user_notify_type'] : NOTIFY_EMAIL, - 'topic_title' => (!$user_id) ? $row['topic_title'] : '', - 'forum_id' => (!$user_id) ? $row['forum_id'] : 0, - ); - } - - foreach ($mail_to_users as $row) - { - $messenger->template($email_tpl, $row['email_lang']); - $messenger->replyto($user->data['user_email']); - $messenger->to($row['email'], $row['name']); - - if ($user_id) - { - $messenger->subject(htmlspecialchars_decode($subject)); - $messenger->im($row['user_jabber'], $row['username']); - $notify_type = $row['user_notify_type']; - } - else - { - $notify_type = NOTIFY_EMAIL; - } - - $messenger->anti_abuse_headers($config, $user); - - $messenger->assign_vars(array( - 'BOARD_CONTACT' => $config['board_contact'], - 'TO_USERNAME' => htmlspecialchars_decode($row['to_name']), - 'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']), - 'MESSAGE' => htmlspecialchars_decode($message)) - ); - - if ($topic_id) - { - $messenger->assign_vars(array( - 'TOPIC_NAME' => htmlspecialchars_decode($row['topic_title']), - 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=" . $row['forum_id'] . "&t=$topic_id") - ); - } - - $messenger->send($notify_type); - } - - meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx")); - $message = ($user_id) ? sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>') : sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$row['forum_id']}&t=$topic_id") . '">', '</a>'); - trigger_error($user->lang['EMAIL_SENT'] . '<br /><br />' . $message); - } + trigger_error($error); } - if ($user_id) - { - $template->assign_vars(array( - 'S_SEND_USER' => true, - 'L_SEND_EMAIL_USER' => $user->lang('SEND_EMAIL_USER', $row['username']), - - 'L_EMAIL_BODY_EXPLAIN' => $user->lang['EMAIL_BODY_EXPLAIN'], - 'S_POST_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&u=' . $user_id)) - ); - } - else + if ($request->is_set_post('submit')) { - $template->assign_vars(array( - 'EMAIL' => $email, - 'NAME' => $name, - 'S_LANG_OPTIONS' => language_select($email_lang), - - 'L_EMAIL_BODY_EXPLAIN' => $user->lang['EMAIL_TOPIC_EXPLAIN'], - 'S_POST_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&t=' . $topic_id)) - ); + $messenger = new messenger(false); + $form->submit($messenger); } - $template->assign_vars(array( - 'ERROR_MESSAGE' => (sizeof($error)) ? implode('<br />', $error) : '', - 'SUBJECT' => $subject, - 'MESSAGE' => $message, - ) - ); + $page_title = $form->get_page_title(); + $template_html = $form->get_template_file(); + $form->render($template); break; @@ -1606,7 +1400,7 @@ switch ($mode) if ($sort_key == 'l') { // uasort($id_cache, create_function('$first, $second', "return (\$first['last_visit'] == \$second['last_visit']) ? 0 : ((\$first['last_visit'] < \$second['last_visit']) ? $lesser_than : ($lesser_than * -1));")); - usort($user_list, '_sort_last_active'); + usort($user_list, 'phpbb_sort_last_active'); } for ($i = 0, $end = sizeof($user_list); $i < $end; ++$i) @@ -1622,7 +1416,7 @@ switch ($mode) $cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template_data($profile_fields_cache[$user_id], false) : array(); } - $memberrow = array_merge(show_profile($row), array( + $memberrow = array_merge(phpbb_show_profile($row), array( 'ROW_NUMBER' => $i + ($start + 1), 'S_CUSTOM_PROFILE' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false, @@ -1691,166 +1485,3 @@ $template->set_filenames(array( make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx")); page_footer(); - -/** -* Prepare profile data -*/ -function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false) -{ - global $config, $auth, $template, $user, $phpEx, $phpbb_root_path, $phpbb_dispatcher; - - $username = $data['username']; - $user_id = $data['user_id']; - - $rank_title = $rank_img = $rank_img_src = ''; - get_user_rank($data['user_rank'], (($user_id == ANONYMOUS) ? false : $data['user_posts']), $rank_title, $rank_img, $rank_img_src); - - if ((!empty($data['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_user')) - { - $email = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&u=' . $user_id) : (($config['board_hide_emails'] && !$auth->acl_get('a_user')) ? '' : 'mailto:' . $data['user_email']); - } - else - { - $email = ''; - } - - if ($config['load_onlinetrack']) - { - $update_time = $config['load_online_time'] * 60; - $online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['session_viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false; - } - else - { - $online = false; - } - - if ($data['user_allow_viewonline'] || $auth->acl_get('u_viewonline')) - { - $last_active = (!empty($data['session_time'])) ? $data['session_time'] : $data['user_lastvisit']; - } - else - { - $last_active = ''; - } - - $age = ''; - - if ($config['allow_birthdays'] && $data['user_birthday']) - { - list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday'])); - - if ($bday_year) - { - $now = $user->create_datetime(); - $now = phpbb_gmgetdate($now->getTimestamp() + $now->getOffset()); - - $diff = $now['mon'] - $bday_month; - if ($diff == 0) - { - $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0; - } - else - { - $diff = ($diff < 0) ? 1 : 0; - } - - $age = max(0, (int) ($now['year'] - $bday_year - $diff)); - } - } - - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - } - - // Can this user receive a Private Message? - $can_receive_pm = ( - // They must be a "normal" user - $data['user_type'] != USER_IGNORE && - - // They must not be deactivated by the administrator - ($data['user_type'] != USER_INACTIVE || $data['user_inactive_reason'] != INACTIVE_MANUAL) && - - // They must be able to read PMs - sizeof($auth->acl_get_list($user_id, 'u_readpm')) && - - // They must not be permanently banned - !sizeof(phpbb_get_banned_user_ids($user_id, false)) && - - // They must allow users to contact via PM - (($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) || $data['user_allow_pm']) - ); - - // Dump it out to the template - $template_data = array( - 'AGE' => $age, - 'RANK_TITLE' => $rank_title, - 'JOINED' => $user->format_date($data['user_regdate']), - 'LAST_ACTIVE' => (empty($last_active)) ? ' - ' : $user->format_date($last_active), - 'POSTS' => ($data['user_posts']) ? $data['user_posts'] : 0, - 'WARNINGS' => isset($data['user_warnings']) ? $data['user_warnings'] : 0, - - 'USERNAME_FULL' => get_username_string('full', $user_id, $username, $data['user_colour']), - 'USERNAME' => get_username_string('username', $user_id, $username, $data['user_colour']), - 'USER_COLOR' => get_username_string('colour', $user_id, $username, $data['user_colour']), - 'U_VIEW_PROFILE' => get_username_string('profile', $user_id, $username, $data['user_colour']), - - 'A_USERNAME' => addslashes(get_username_string('username', $user_id, $username, $data['user_colour'])), - - 'AVATAR_IMG' => phpbb_get_user_avatar($data), - 'ONLINE_IMG' => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')), - 'S_ONLINE' => ($config['load_onlinetrack'] && $online) ? true : false, - 'RANK_IMG' => $rank_img, - 'RANK_IMG_SRC' => $rank_img_src, - 'S_JABBER_ENABLED' => ($config['jab_enable']) ? true : false, - - 'S_WARNINGS' => ($auth->acl_getf_global('m_') || $auth->acl_get('m_warn')) ? true : false, - - 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$user_id&sr=posts") : '', - 'U_NOTES' => ($user_notes_enabled && $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $user_id, true, $user->session_id) : '', - 'U_WARN' => ($warn_user_enabled && $auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $user_id, true, $user->session_id) : '', - 'U_PM' => ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && $can_receive_pm) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $user_id) : '', - 'U_EMAIL' => $email, - 'U_JABBER' => ($data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $user_id) : '', - - 'USER_JABBER' => $data['user_jabber'], - 'USER_JABBER_IMG' => ($data['user_jabber']) ? $user->img('icon_contact_jabber', $data['user_jabber']) : '', - - 'L_SEND_EMAIL_USER' => $user->lang('SEND_EMAIL_USER', $username), - 'L_CONTACT_USER' => $user->lang('CONTACT_USER', $username), - 'L_VIEWING_PROFILE' => $user->lang('VIEWING_PROFILE', $username), - ); - - /** - * Preparing a user's data before displaying it in profile and memberlist - * - * @event core.memberlist_prepare_profile_data - * @var array data Array with user's data - * @var array template_data Template array with user's data - * @since 3.1.0-a1 - */ - $vars = array('data', 'template_data'); - extract($phpbb_dispatcher->trigger_event('core.memberlist_prepare_profile_data', compact($vars))); - - return $template_data; -} - -function _sort_last_active($first, $second) -{ - global $id_cache, $sort_dir; - - $lesser_than = ($sort_dir === 'd') ? -1 : 1; - - if (isset($id_cache[$first]['group_leader']) && $id_cache[$first]['group_leader'] && (!isset($id_cache[$second]['group_leader']) || !$id_cache[$second]['group_leader'])) - { - return -1; - } - else if (isset($id_cache[$second]['group_leader']) && (!isset($id_cache[$first]['group_leader']) || !$id_cache[$first]['group_leader']) && $id_cache[$second]['group_leader']) - { - return 1; - } - else - { - return $lesser_than * (int) ($id_cache[$first]['last_visit'] - $id_cache[$second]['last_visit']); - } -} |