/** * Notify using src messenger * * @param int $notify_method Notify method for messenger (e.g. NOTIFY_IM) * @param string $template_dir_prefix Base directory to prepend to the email template name * * @return null */ protected function notify_using_messenger($notify_method, $template_dir_prefix = '') { if (empty($this->queue)) { return; } // Load all users we want to notify (we need their email address) $user_ids = $users = array(); foreach ($this->queue as $notification) { $user_ids[] = $notification->user_id; } // We do not send emails to banned users if (!function_exists('src_get_banned_user_ids')) { include $this->src_root_path . 'includes/functions_user.' . $this->php_ext; } $banned_users = src_get_banned_user_ids($user_ids); // Load all the users we need $this->user_loader->load_users($user_ids); // Load the messenger if (!class_exists('messenger')) { include $this->src_root_path . 'includes/functions_messenger.' . $this->php_ext; } $messenger = new \messenger(); $srcrd_url = generate_srcrd_url(); // Time to go through the queue and send emails foreach ($this->queue as $notification) { if ($notification->get_email_template() === false) { continue; } $user = $this->user_loader->get_user($notification->user_id); if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) { continue; } $messenger->template($template_dir_prefix . $notification->get_email_template(), $user['user_lang']); $messenger->set_addresses($user); $messenger->assign_vars(array_merge(array('USERNAME' => $user['username'], 'U_NOTIFICATION_SETTINGS' => generate_srcrd_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications'), $notification->get_email_template_variables())); $messenger->send($notify_method); } // Save the queue in the messenger class (has to be called or these emails could be lost?) $messenger->save_queue(); // We're done, empty the queue $this->empty_queue(); }
/** * For composing messages, handle list actions */ function handle_message_list_actions(&$address_list, &$error, $remove_u, $remove_g, $add_to, $add_bcc) { global $auth, $db, $user; global $request; // Delete User [TO/BCC] if ($remove_u && $request->variable('remove_u', array(0 => ''))) { $remove_user_id = array_keys($request->variable('remove_u', array(0 => ''))); if (isset($remove_user_id[0])) { unset($address_list['u'][(int) $remove_user_id[0]]); } } // Delete Group [TO/BCC] if ($remove_g && $request->variable('remove_g', array(0 => ''))) { $remove_group_id = array_keys($request->variable('remove_g', array(0 => ''))); if (isset($remove_group_id[0])) { unset($address_list['g'][(int) $remove_group_id[0]]); } } // Add Selected Groups $group_list = request_var('group_list', array(0)); // Build usernames to add $usernames = request_var('username', '', true); $usernames = empty($usernames) ? array() : array($usernames); $username_list = request_var('username_list', '', true); if ($username_list) { $usernames = array_merge($usernames, explode("\n", $username_list)); } // If add to or add bcc not pressed, users could still have usernames listed they want to add... if (!$add_to && !$add_bcc && (sizeof($group_list) || sizeof($usernames))) { $add_to = true; global $refresh, $submit, $preview; $refresh = true; $submit = false; // Preview is only true if there was also a message entered if (request_var('message', '')) { $preview = true; } } // Add User/Group [TO] if ($add_to || $add_bcc) { $type = $add_to ? 'to' : 'bcc'; if (sizeof($group_list)) { foreach ($group_list as $group_id) { $address_list['g'][$group_id] = $type; } } // User ID's to add... $user_id_ary = array(); // Reveal the correct user_ids if (sizeof($usernames)) { $user_id_ary = array(); user_get_id_name($user_id_ary, $usernames, array(USER_NORMAL, USER_FOUNDER, USER_INACTIVE)); // If there are users not existing, we will at least print a notice... if (!sizeof($user_id_ary)) { $error[] = $user->lang['PM_NO_USERS']; } } // Add Friends if specified $friend_list = array_keys($request->variable('add_' . $type, array(0))); $user_id_ary = array_merge($user_id_ary, $friend_list); foreach ($user_id_ary as $user_id) { if ($user_id == ANONYMOUS) { continue; } $address_list['u'][$user_id] = $type; } } // Check for disallowed recipients if (!empty($address_list['u'])) { $can_ignore_allow_pm = $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'); // Administrator deactivated users check and we need to check their // PM status (do they want to receive PM's?) // Only check PM status if not a moderator or admin, since they // are allowed to override this user setting $sql = 'SELECT user_id, user_allow_pm FROM ' . USERS_TABLE . ' WHERE ' . $db->sql_in_set('user_id', array_keys($address_list['u'])) . ' AND ( (user_type = ' . USER_INACTIVE . ' AND user_inactive_reason = ' . INACTIVE_MANUAL . ') ' . ($can_ignore_allow_pm ? '' : ' OR user_allow_pm = 0') . ' )'; $result = $db->sql_query($sql); $removed_no_pm = $removed_no_permission = false; while ($row = $db->sql_fetchrow($result)) { if (!$can_ignore_allow_pm && !$row['user_allow_pm']) { $removed_no_pm = true; } else { $removed_no_permission = true; } unset($address_list['u'][$row['user_id']]); } $db->sql_freeresult($result); // print a notice about users not being added who do not want to receive pms if ($removed_no_pm) { $error[] = $user->lang['PM_USERS_REMOVED_NO_PM']; } // print a notice about users not being added who do not have permission to receive PMs if ($removed_no_permission) { $error[] = $user->lang['PM_USERS_REMOVED_NO_PERMISSION']; } if (!sizeof(array_keys($address_list['u']))) { return; } // Check if users have permission to read PMs $can_read = $auth->acl_get_list(array_keys($address_list['u']), 'u_readpm'); $can_read = empty($can_read) || !isset($can_read[0]['u_readpm']) ? array() : $can_read[0]['u_readpm']; $cannot_read_list = array_diff(array_keys($address_list['u']), $can_read); if (!empty($cannot_read_list)) { foreach ($cannot_read_list as $cannot_read) { unset($address_list['u'][$cannot_read]); } $error[] = $user->lang['PM_USERS_REMOVED_NO_PERMISSION']; } // Check if users are banned $banned_user_list = src_get_banned_user_ids(array_keys($address_list['u']), false); if (!empty($banned_user_list)) { foreach ($banned_user_list as $banned_user) { unset($address_list['u'][$banned_user]); } $error[] = $user->lang['PM_USERS_REMOVED_NO_PERMISSION']; } } }
} else { if ($has_unapproved_attachments && !$topic_data['topic_attachment']) { // Topic has only unapproved attachments but we have the right to see and download them $topic_data['topic_attachment'] = 1; } } } } else { $display_notice = true; } } // Get the list of users who can receive private messages $can_receive_pm_list = $auth->acl_get_list(array_keys($user_cache), 'u_readpm'); $can_receive_pm_list = empty($can_receive_pm_list) || !isset($can_receive_pm_list[0]['u_readpm']) ? array() : $can_receive_pm_list[0]['u_readpm']; // Get the list of permanently banned users $permanently_banned_users = src_get_banned_user_ids(array_keys($user_cache), false); $i_total = sizeof($rowset) - 1; $prev_post_id = ''; $template->assign_vars(array('S_HAS_ATTACHMENTS' => $topic_data['topic_attachment'], 'S_NUM_POSTS' => sizeof($post_list))); /** * Event to modify the post, poster and attachment data before assigning the posts * * @event core.viewtopic_modify_post_data * @var int forum_id Forum ID * @var int topic_id Topic ID * @var array topic_data Array with topic data * @var array post_list Array with post_ids we are going to display * @var array rowset Array with post_id => post data * @var array user_cache Array with prepared user data * @var int start Pagination information * @var int sort_days Display posts of previous x days
/** * Prepare profile data */ function src_show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false, $check_can_receive_pm = true) { global $config, $auth, $user, $phpEx, $src_root_path, $src_dispatcher; $username = $data['username']; $user_id = $data['user_id']; $user_rank_data = src_get_user_rank($data, $user_id == ANONYMOUS ? false : $data['user_posts']); if (!empty($data['user_allow_viewemail']) && $auth->acl_get('u_sendemail') || $auth->acl_get('a_user')) { $email = $config['srcrd_email_form'] && $config['email_enable'] ? append_sid("{$src_root_path}memberlist.{$phpEx}", 'mode=email&u=' . $user_id) : ($config['srcrd_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 = src_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('src_get_banned_user_ids')) { include $src_root_path . 'includes/functions_user.' . $phpEx; } // Can this user receive a Private Message? $can_receive_pm = $check_can_receive_pm && ($data['user_type'] != USER_IGNORE && ($data['user_type'] != USER_INACTIVE || $data['user_inactive_reason'] != INACTIVE_MANUAL) && sizeof($auth->acl_get_list($user_id, 'u_readpm')) && !sizeof(src_get_banned_user_ids($user_id, false)) && ($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' => $user_rank_data['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' => src_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' => $user_rank_data['img'], 'RANK_IMG_SRC' => $user_rank_data['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("{$src_root_path}search.{$phpEx}", "author_id={$user_id}&sr=posts") : '', 'U_NOTES' => $user_notes_enabled && $auth->acl_getf_global('m_') ? append_sid("{$src_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("{$src_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("{$src_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("{$src_root_path}memberlist.{$phpEx}", 'mode=contact&action=jabber&u=' . $user_id) : '', 'USER_JABBER' => $config['jab_enable'] ? $data['user_jabber'] : '', 'USER_JABBER_IMG' => $config['jab_enable'] && $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($src_dispatcher->trigger_event('core.memberlist_prepare_profile_data', compact($vars))); return $template_data; }