How to get PM recipients ID or name?

Started by Adrek, April 28, 2016, 02:57:51 PM

Previous topic - Next topic

Adrek

Hi, I'm trying to make a mod that displays warning to PM author if one of the recipients was user in specified member group.
Would it be possible to catch recipients IDs/names using function in integrate_load_theme?

I looked at PersonalMessage.php and tried to get something from $_POST but every time it came back empty..
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Pipke

ok here you have a go what you want to achieve i guess ;)

the code for inside your function for integrate_load_theme.


global $sourcedir, $smcFunc;

require_once($sourcedir . '/Subs-Auth.php');

$_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];
$_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];

// Route the input from the 'u' parameter to the 'to'-list.
if (!empty($_POST['u']))
$_POST['recipient_to'] = explode(',', $_POST['u']);

// Construct the list of recipients.
$recipientList = array();
$namedRecipientList = array();
$namesNotFound = array();
foreach (array('to', 'bcc') as $recipientType)
{
// First, let's see if there's user ID's given.
$recipientList[$recipientType] = array();
if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))
{
foreach ($_POST['recipient_' . $recipientType] as $recipient)
$recipientList[$recipientType][] = (int) $recipient;
}

// Are there also literal names set?
if (!empty($_REQUEST[$recipientType]))
{
// We're going to take out the "s anyway ;).
$recipientString = strtr($_REQUEST[$recipientType], array('\\"' => '"'));

preg_match_all('~"([^"]+)"~', $recipientString, $matches);
$namedRecipientList[$recipientType] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $recipientString))));

foreach ($namedRecipientList[$recipientType] as $index => $recipient)
{
if (strlen(trim($recipient)) > 0)
$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
else
unset($namedRecipientList[$recipientType][$index]);
}

if (!empty($namedRecipientList[$recipientType]))
{
$foundMembers = findMembers($namedRecipientList[$recipientType]);

// Assume all are not found, until proven otherwise.
$namesNotFound[$recipientType] = $namedRecipientList[$recipientType];

foreach ($foundMembers as $member)
{
$testNames = array(
$smcFunc['strtolower']($member['username']),
$smcFunc['strtolower']($member['name']),
$smcFunc['strtolower']($member['email']),
);

if (count(array_intersect($testNames, $namedRecipientList[$recipientType])) !== 0)
{
$recipientList[$recipientType][] = $member['id'];

// Get rid of this username, since we found it.
$namesNotFound[$recipientType] = array_diff($namesNotFound[$recipientType], $testNames);
}
}
}
}

// Selected a recipient to be deleted? Remove them now.
if (!empty($_POST['delete_recipient']))
$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));

// Make sure we don't include the same name twice
$recipientList[$recipientType] = array_unique($recipientList[$recipientType]);

// find 'recipients' groups
foreach ($recipientList[$recipientType] as $key => $value)
{
$request = $smcFunc['db_query']('','
SELECT
id_group, additional_groups, id_post_group, id_member
FROM {db_prefix}members
WHERE id_member = {int:id}',
array(
'id' => $value,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$recipients_group[$row['id_member']] = array(
'id_group' => $row['id_group'],
'additional_groups' => $row['additional_groups'],
'id_post_group' => $row['id_post_group'],
);
}
$smcFunc['db_free_result']($request);
}


}
echo'<pre>';
print_r($recipients_group);  // is the output array
echo'</pre>';


$recipients_group = the array (with the recipients users ids and the groups the user recipient is in) you see on top on the screenshot i attached
with this array you can do a check on the user group if they are in it and then print the warning, have fun with it.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Adrek

exactly what I needed :) Thank you.

One more question related to this: can this array be available afer user is redirected to inbox after sending message (?action=pm;f=inbox;l=-1;done=sent)?
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Pipke

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

qc

(Not only) just for fun: you could also do this with pure CSS as long as you know the IDs of the members you want to be warned about:



CSS:
#to_item_list_container input[name="recipient_to[]"][value="<REPLACE WITH USER-ID>"] + a::before {
    content: "WARNING";
    color: #F00;
    margin-right: 4px;
    font-size: 10px;
}
Playing quizduell? Having quizduell questions? Our german quizduell forum quizcommunity.de is looking for quiz freaks to come and play quizduell with us :)

Adrek

after message is sent array is empty

--------

Nice trick with CSS :)
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Advertisement: