Overriding sig content by secondary membergroup.

Started by Antechinus, June 07, 2012, 05:44:12 AM

Previous topic - Next topic

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:



$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>';



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:
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)';
}


Add it like so:
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)';
}


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:
function prepareDisplayContext($reset = false)
{
global $settings, $txt, $modSettings, $scripturl, $options, $user_info, $smcFunc;
global $memberContext, $context, $messages_request, $topic, $attachments, $topicinfo;


To:
function prepareDisplayContext($reset = false)
{
global $settings, $txt, $modSettings, $scripturl, $options, $user_info, $smcFunc;
global $memberContext, $context, $messages_request, $topic, $attachments, $topicinfo, $user_profile;


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:
$memberContext[$message['id_member']]['ip'] = $message['poster_ip'];

And after it:

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;
}



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:

// 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>';


Change to:

// 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>';


Not sure if there's a cleaner way of handling it. :)

Arantor


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

Arantor

Spoogs, IIRC, is taking care of it now, but making the edits does make it kind of complicated :/

Mind you, I got some great ideas for that these days... in particularly a disemvoweller ;)

Antechinus

#6
Well it wasn't exactly a simple mod anyway. I wont be playing with it soon. I've decided to skip 2.0.x and go straight to 2.1 beta as soon as we have one. Can't really see the point in 2.0.x at this stage, and a 2.1 beta should be pretty good.

Oh and I'll mark this as solved.

ETA: Had to tweak the code a bit for 1.1.x. If anyone wants the finished product, give this a bump and ask. :)

Antechinus

Bumpity. Had a brainwave to extend this thing a bit. It occurred to me that this would make a good official mod, properly packaged and with an admin interface. For my own use back then, I just edited the content directly into the template, but most admins would find it much easier if they could have a nice input in admin.

So, what I'm currently thinking of is a mod that would provide two content inputs: one to play havoc with the sig and one to play havoc with the avatar. This would be done on all pages that display either of these elements, apart from the account settings page in the user's profile, which would still display whatever they had tried to set themselves.

There would also need to be a third input, to take the membergroup ID. I'm not thinking of complicating things any more than this, so there would only be one membergroup affected and only one option for evil things done to all sigs and avs in that group.

Re this: "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."

Any tips on how I should approach the Sources side of it if wanting to extend the havoc to several templates?

margarett

The easiest way to do that is via $modSettings but the interface can be... Complicated :P to generate properly...
To create a sig, a raw textbox will do. But if you want a full editor with preview and whatnot, that's a totally different subject.
Group id, easy. But if you want a complete groups list to choose from, not that simple anymore...
And the avatar, the same. If you just want to give an URL, easy. But if you want to have the avatar selection stuff, it becomes a PITA (and I'm not even considering the possibility to upload it :P )

In a simple or complex presentation, then you would just need to extend Arantor's tips to make it work ;)

Another way to do it would be to create a dummy user and get its $memberContext at Display and Profile-View. Then, just swap the relevant details for the user you're targeting :)
Im just not sure if calling userContext wouldn't replace the information for the current user...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Antechinus

I'm just thinking basic inputs: for text or url for sig, url for av, ID number for targeted group. No silly business. If they can't make it work with that lot, they can't admin a forum anyway. It should only need to be set occasionally.

margarett

I've been looking at this... Question: do you want a MOD or do you want help coding to build a MOD?

I have a constraint in either case: it has to use this --> http://custom.simplemachines.org/mods/index.php?mod=3805
Because I already did the dirty work around additional membergroups :P
(and you can choose NOT to show the additional membergroups anyway, so only the "background tasks" are in place ;) )
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Antechinus

No I don't want someone to actually make it for me. I can do that bit. Just wanted to make sure I wasn't missing anything important. Back end code isn't my strong point. :)

IF, that means IF, I can make it work with your mod without it being a/ a PITA for me or b/ extra bloat and performance penalty for anyone who doesn't care about your mod then c/ I might do it. If a/ or b/ constraints are not met, c/ aint gonna happen. :P

margarett

#12
OK, some loose ends (that we need to put together in the end) ;)

1 - Create the Modification Settings
ManageSettings.php
Find:
// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
Add after:

array('text', 'irritate_groupid', '10'),
array('large_text', 'irritate_fakesig'),
array('text', 'irritate_fakeavatar', '30'),


Modifications.english.php

$txt['irritate_groupid'] = 'ID of the annoying users membergroup';
$txt['irritate_fakesig'] = 'Signature to irritate annoying users';
$txt['irritate_fakeavatar'] = 'URL to avatar to irritate annoying users';

This will create the settings. I need to write the rest and test it :)

2 - Replace poster details in Display.php
Find:
$memberContext[$message['id_member']]['ip'] = $message['poster_ip'];
Add after:
//Irritate this user?
if (!empty($modSettings['irritate_groupid']))
{
$groups = array();
if (!empty($memberContext[$message['id_member']]['group_id']))
$groups[] = $memberContext[$message['id_member']]['group_id'];
if (!empty($memberContext[$message['id_member']]['additional_groups_list']))
$groups = array_merge($groups, $memberContext[$message['id_member']]['additional_groups_list']);
//Finally, is the user affected by irritate? :)
$to_irritate = in_array($modSettings['irritate_groupid'], $groups);
}
// Fake signature?
if (!empty($to_irritate) && !empty($modSettings['irritate_fakesig']))
$memberContext[$message['id_member']]['signature'] = $modSettings['irritate_fakesig'];
//Fake avatar?
if (!empty($to_irritate) && !empty($modSettings['irritate_fakeavatar']))
{
$memberContext[$message['id_member']]['avatar']['name'] = $modSettings['irritate_fakeavatar'];
$memberContext[$message['id_member']]['avatar']['image'] = '<img src = "' . $modSettings['irritate_fakeavatar'] . '" />';
$memberContext[$message['id_member']]['avatar']['href'] = $modSettings['irritate_fakeavatar'];
$memberContext[$message['id_member']]['avatar']['url'] = $modSettings['irritate_fakeavatar'];
}


It works, I tested it :P

I'll leave the fun part in Profile-View.php for you now ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor


margarett

Ant suggested that long ago :P
Quote from: Antechinus on June 07, 2012, 05:34:49 PM
ETA: Might suggest this as an addition to Annoy User, if I can remember who is running that one now. :D
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

Yes but I hadn't taken it back at that point ;)

And frankly I'd rather build the more epic paid version now than do the free version. Paid one will be jaw-droppingly evil.

JBlaze

I can see extending Annoy User Pro into your gallery mod for some more evil goodness >:D
Jason Clemons
Former Team Member 2009 - 2012

Arantor

I hadn't plotted quite what I could do with that...

JBlaze

Quote from: Arantor on October 02, 2014, 09:10:19 PM
I hadn't plotted quite what I could do with that...

It opens up a whole new world of fun, what with image/video manipulation and whatnot :P
Jason Clemons
Former Team Member 2009 - 2012

Arantor

There's only so much I can meaningfully do without really screwing with gallery internals. The gallery code is mildly hardcore.

But I have a list of fun stuff - and it's the first thing I'm building after the gallery is done. Need something simple to unwind with.

Advertisement: