View Full Version : Edit Post based on Group ID
Noslo
02-28-2012, 06:29 PM
Hi there,
I'd like to make it so when a parcticular group posts a new thread or post that the background changes to a colour I.E gold.
I assume I'll be editing the postbit_legacy template and adding something like:
<if condition="is_member_of($bbuserinfo, 6)">style="background:gold;"</if>
But I'm not 100% sure of the correct coding or where that would go into which template.
Any help would be great thanks!
Sarteck
02-28-2012, 10:52 PM
Here's something I came up with.....
if (!function_exists('postbit_bg_injection')) {function postbit_bg_injection($subject)
{
global $bg_injection;
$bgcolor = "#000000";
$search = array('<div class="userinfo">','<div class="postbody">');
$replace = array(
'<div class="userinfo"\'.((is_member_of($post,array(6)))?\' style="background-color:'.$bgcolor.'"\':\'\').\'>',
'<div class="postbody"\'.((is_member_of($post,array(6)))?\' style="background-color:'.$bgcolor.'"\':\'\').\'>'
);
$bg_injection = true;
return str_replace($search,$replace,$subject);
}}
if (!$bg_injection) {$vbulletin->templatecache['postbit_legacy'] = postbit_bg_injection($vbulletin->templatecache['postbit_legacy']);}
There are several things you have to replace.
First, array(6) should be an array of groups you want to apply this to.
Second, $bgcolor should be changed.
This does not seem to get ALL areas of the postbit, but I gotta go to work in a few, so maybe you can find the last little bit. XD
P.S., I put this on the parse_templates hook, but it could probably go elsewhere.
(It's a shoddy job, but I JUST started learning this templatecache stuff.... and this actually showed me just how useful it can be to fiddle with it.)
Noslo
02-28-2012, 11:43 PM
Hi,
How would I edit this parse_templates hook? Where would I even find it?
Sarteck
02-28-2012, 11:47 PM
Oh, sorry.
Admin CP ==> Plugins & Products ==> Add New Plugin
That's where you add plugins. The "hook" is the specific place in the vB code where the Plugin code gets executed.
You can title it whatever you want, execution order of 5 is okay.
I'll be around in about six to eight hours to more-or-less "complete" it, but you could just use what I've got up there and see if that works for ya.
Noslo
02-28-2012, 11:54 PM
Oh I see, all I want is just the area where the message is to be a different colour :) But I will try and mess around with it.
If that's an easy fix or you know how please tell me, if not I'll wait for you to finish :P
--------------- Added 1330476950 at 1330476950 ---------------
EDIT:
I removed all the parts with user info and got what I wanted :) Thanks so much!!
Sarteck
02-28-2012, 11:57 PM
Oh, yes.
if (!function_exists('postbit_bg_injection')) {function postbit_bg_injection($subject)
{
global $bg_injection;
$bgcolor = "#000000";
$search = '<div class="postbody">';
$replace = '<div class="postbody"\'.((is_member_of($post,array(6)))?\' style="background-color:'.$bgcolor.'"\':\'\').\'>';
$bg_injection = true;
return str_replace($search,$replace,$subject);
}}
if (!$bg_injection) {$vbulletin->templatecache['postbit_legacy'] = postbit_bg_injection($vbulletin->templatecache['postbit_legacy']);} See, if that's the case, you only need the postbody to change. :> I thought you meant you wanted the UserInfo bit of the postbit to change as well.
Okays, time to get to work. If you have trouble or questions, post 'em and I'll help when I get back (unless someone else helps ya first).
--------------- Added 1330502363 at 1330502363 ---------------
I take the lack of response as heartening. :> You got it to work okay, I presume?
Noslo
02-29-2012, 10:05 AM
Quick question. I've got this working perfectly for the admin user group.
However I added a new plugin and changed the array to "5" for my super moderator code and it doesn't seem to work, I tried changing the execution array but I can't see what's going wrong.
Is it that you can't have two plugins that change parse_templates? If so how can I edit the original code to recognise more than one group with separate BG colours for each.
Thanks!
Sarteck
02-29-2012, 11:16 AM
Instead of adding a new plugin, try this:
Change array(6) to array(5,6)
And then add in more usergroups as you see fit. :3
Noslo
02-29-2012, 11:17 AM
But I want it to be different colours depending on which user group :)
--------------- Added 1330519221 at 1330519221 ---------------
EDIT:
I tried adding a new BG colour array and then adding a new line for group 5 but I got allot of errors :P
if (!function_exists('postbit_bg_injection')) {function postbit_bg_injection($subject)
{
global $bg_injection;
$bgcolorAdmin = "#D4AF37";
$bgcolorMod = "#17200d";
$search = array('<div class="postbody">');
$replace = array(
'<div class="postbody"\'.((is_member_of($post,array(6)))?\' style="background-color:'.$bgcolorAdmin.'"\':\'\').\'>'
'<div class="postbody"\'.((is_member_of($post,array(5)))?\' style="background-color:'.$bgcolorMod.'"\':\'\').\'>'
);
$bg_injection = true;
return str_replace($search,$replace,$subject);
}}
if (!$bg_injection) {$vbulletin->templatecache['postbit_legacy'] = postbit_bg_injection($vbulletin->templatecache['postbit_legacy']);}
Sarteck
02-29-2012, 11:52 AM
Oh, I see. Hmm. In that case, a little alteration is required:
if (!function_exists('postbit_bg_injection')) {function postbit_bg_injection($subject)
{
global $bg_injection;
$group_bg_color = array();
$group_bg_color[6] = "#000000"; // Admins
$group_bg_color[5] = "#232323"; // Mods
$search = '<div class="postbody">';
$replace = '<div class="postbody"\'';
foreach ($group_bg_color AS $groupid => $bgcolor)
{
$replace .= '.((is_member_of($post,'.$groupid.'))?\' style="background-color:'.$bgcolor.'"\':\'\')';
}
$replace .= '.\'>';
$bg_injection = true;
return str_replace($search,$replace,$subject);
}}
if (!$bg_injection) {$vbulletin->templatecache['postbit_legacy'] = postbit_bg_injection($vbulletin->templatecache['postbit_legacy']);}
Noslo
02-29-2012, 11:59 AM
How easy would it be to add more groups to that code then?
Sarteck
02-29-2012, 12:01 PM
Just add more lines as shown with that Admin and Mod examples with different indexes for the Group IDs and different values for the different colours.
Noslo
02-29-2012, 12:03 PM
Awesome. This is super helpful and it works perfectly. Thank you so much Sarteck!
Sarteck
02-29-2012, 12:04 PM
No prob, hope your forum likes. :3
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.