function _privatemsg_parse_userstring in Privatemsg 6
Same name and namespace in other branches
- 6.2 privatemsg.module \_privatemsg_parse_userstring()
- 7.2 privatemsg.module \_privatemsg_parse_userstring()
- 7 privatemsg.module \_privatemsg_parse_userstring()
Extract the valid usernames of a string and loads them.
This function is used to parse a string supplied by a username autocomplete field and load all user objects.
Parameters
$string: A string in the form "usernameA, usernameB, ...".
Return value
Array, first element is an array of loaded user objects, second an array with invalid names.
3 calls to _privatemsg_parse_userstring()
- pm_send_validate in ./
privatemsg.module - privatemsg_filter_dropdown_submit in privatemsg_filter/
privatemsg_filter.module - privatemsg_filter_get_filter in privatemsg_filter/
privatemsg_filter.module
File
- ./
privatemsg.module, line 1058 - Allows users to send private messages to other users.
Code
function _privatemsg_parse_userstring($input) {
if (is_string($input)) {
$input = explode(',', $input);
}
// Start working through the input array.
$invalid = array();
$recipients = array();
foreach ($input as $string) {
$string = trim($string);
if (!empty($string)) {
// We don't care about white space names.
// First, check if another module is able to resolve the string into an
// user object.
foreach (module_implements('privatemsg_name_lookup') as $module) {
$function = $module . '_privatemsg_name_lookup';
if (($recipient = $function($string)) && is_object($recipient)) {
// If there is a match, continue with the next input string.
$recipients[$recipient->uid] = $recipient;
continue 2;
}
}
// Fall back to the default username lookup.
if (!($error = module_invoke('user', 'validate_name', $string))) {
// String is a valid username, look it up.
if ($recipient = user_load(array(
'name' => $string,
))) {
$recipients[$recipient->uid] = $recipient;
continue;
}
}
$invalid[$string] = $string;
}
}
return array(
$recipients,
$invalid,
);
}