Customizing SMF > SMF Coding Discussion
Overriding sig content by secondary membergroup.
Antechinus:
This is to wind up some irritating tossers on a 1.1.x site I run. :D
What I want to do is replace sig content when the poster has a certain group set as secondary. I don't want to do it by primary group. It has to be secondary.
This works for primary (if I changed the code to handle sig rather than karma stuff):
--- Quote from: Suki on November 14, 2010, 08:51:08 PM ---you should use $message['member']['group_id'] instead:
--- Code: ---
$groups = array(1,2,3,4); //where 1,2,3,4 are the membergroups's IDs
global $user_info, $modSettings;
// Is karma display enabled? Total or +/-?
if ($modSettings['karmaMode'] == '1' && isset($message['member']['group_id']) && in_array($message['member']['group_id'], $groups))
echo '
<li class="karma">111111111', $modSettings['karmaLabel'], ' ', $message['member']['karma']['good'] - $message['member']['karma']['bad'], '</li>';
elseif ($modSettings['karmaMode'] == '2' && isset($message['member']['group_id']) && in_array($message['member']['group_id'], $groups))
echo '
<li class="karma">', $modSettings['karmaLabel'], ' +', $message['member']['karma']['good'], '/-', $message['member']['karma']['bad'], '</li>';
--- End code ---
--- End quote ---
What I need is a modified version of that, so that it doesn't have to work off primary group. If someone can give me the basic conditional/array stuff, I can sort the rest. Might even make a handy mod. Hmm.
Arantor:
Therein lies the problem: additional member groups are not actually loaded in that page, only primary and post count group are.
Now, you can add it manually to the list of columns that are loaded in Load.php:
--- Code: --- if ($set == 'normal')
{
$select_columns = '
IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name,
mem.real_name, mem.email_address, mem.hide_email, mem.date_registered, mem.website_title, mem.website_url,
mem.birthdate, mem.member_ip, mem.member_ip2, mem.icq, mem.aim, mem.yim, mem.msn, mem.posts, mem.last_login,
mem.karma_good, mem.id_post_group, mem.karma_bad, mem.lngfile, mem.id_group, mem.time_offset, mem.show_online,
mem.buddy_list, mg.online_color AS member_group_color, IFNULL(mg.group_name, {string:blank_string}) AS member_group,
pg.online_color AS post_group_color, IFNULL(pg.group_name, {string:blank_string}) AS post_group, mem.is_activated, mem.warning,
CASE WHEN mem.id_group = 0 OR mg.stars = {string:blank_string} THEN pg.stars ELSE mg.stars END AS stars' . (!empty($modSettings['titlesEnable']) ? ',
mem.usertitle' : '');
$select_tables = '
LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)';
}
--- End code ---
Add it like so:
--- Code: --- if ($set == 'normal')
{
$select_columns = '
IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name,
mem.real_name, mem.email_address, mem.hide_email, mem.date_registered, mem.website_title, mem.website_url,
mem.birthdate, mem.member_ip, mem.member_ip2, mem.icq, mem.aim, mem.yim, mem.msn, mem.posts, mem.last_login,
mem.karma_good, mem.id_post_group, mem.additional_groups, mem.karma_bad, mem.lngfile, mem.id_group, mem.time_offset, mem.show_online,
mem.buddy_list, mg.online_color AS member_group_color, IFNULL(mg.group_name, {string:blank_string}) AS member_group,
pg.online_color AS post_group_color, IFNULL(pg.group_name, {string:blank_string}) AS post_group, mem.is_activated, mem.warning,
CASE WHEN mem.id_group = 0 OR mg.stars = {string:blank_string} THEN pg.stars ELSE mg.stars END AS stars' . (!empty($modSettings['titlesEnable']) ? ',
mem.usertitle' : '');
$select_tables = '
LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)';
}
--- End code ---
So now we have it available in PHP. I suppose were one doing this completely cleanly, we should extend $memberContext to have it, but since we don't need it anywhere else except the post view, let's do it only there.
Now, $memberContext contains a cleaned up version of the user data, but $user_profile contains the raw versions of everything.
As such we need to include it in the global declaration in the relevant function:
--- Code: ---function prepareDisplayContext($reset = false)
{
global $settings, $txt, $modSettings, $scripturl, $options, $user_info, $smcFunc;
global $memberContext, $context, $messages_request, $topic, $attachments, $topicinfo;
--- End code ---
To:
--- Code: ---function prepareDisplayContext($reset = false)
{
global $settings, $txt, $modSettings, $scripturl, $options, $user_info, $smcFunc;
global $memberContext, $context, $messages_request, $topic, $attachments, $topicinfo, $user_profile;
--- End code ---
Now we just need to do something with that information in Display.php, and because this is called once per post, let's see if we can't keep it lean in the process. Don't worry so much about how this works, just that it will. We'll add it to $memberContext here so it'll be kept between posts in a page, and that it'll be made available to the template cleanly.
So, we need to get the message and people details then figure out whether we need to do anything with the person.
The line to hit up is:
--- Code: --- $memberContext[$message['id_member']]['ip'] = $message['poster_ip'];
--- End code ---
And after it:
--- Code: ---if (!isset($memberContext[$message['id_member']]['user_is_a_pain'])
{
$groups = !empty($user_profile[$message['id_member']]) ? explode(',', $user_profile[$message['id_member']]['additional_groups']) : array();
$intersect = array_intersect($groups, array(1, 2, 3, 4)); // or whatever groups you want
$memberContext[$message['id_member']]['user_is_a_pain'] = count($intersect) > 0;
}
--- End code ---
Now all you need to do in the template is check against $message['member']['user_is_a_pain'] and if they are, do whatever in the template you need to do. There might be a cleaner way to do this if I knew what you were doing to that user's signature (since you might want to update their signature in the Display.php rather than in the template)
Antechinus:
Hmm. Well the only reason I want to do it as secondary is because it's sneakier and more evil. However, loads on this forum are low, so might as well have some fun. The staff and some of the members are looking forward to acting innocent when some sigs change by magic. :D
What I was thinking of doing with the sig content was something like the following:
Current code:
--- Code: --- // Show the member's signature?
if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
echo '
<div class="signature" style="clear: both; text-align: left;"><hr width="100%" size="1" class="hrcolor" />', $message['member']['signature'], '</div>';
--- End code ---
Change to:
--- Code: --- // Show the member's signature?
if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
echo '
<div class="signature" style="clear: both; text-align: left;"><hr width="100%" size="1" class="hrcolor" />';
if ($message['member']['user_is_a_pain'])
echo '
<img src="' . $settings['images_url'] . '/whatever.png" alt="" />';
else
echo '
', $message['member']['signature'];
echo '
</div>';
--- End code ---
Not sure if there's a cleaner way of handling it. :)
Arantor:
Hrm, I doubt it could be more cleanly then :)
Antechinus:
Righty o then, will just go ahead with being evil. Thanks for the help.
ETA: Might suggest this as an addition to Annoy User, if I can remember who is running that one now. :D
Navigation
[0] Message Index
[#] Next page
Go to full version