Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 02-28-2012, 06:29 PM
Noslo Noslo is offline
 
Join Date: Dec 2011
Posts: 50
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Edit Post based on Group ID

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:

Code:
<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!
Reply With Quote
  #2  
Old 02-28-2012, 10:52 PM
Sarteck's Avatar
Sarteck Sarteck is offline
 
Join Date: Mar 2008
Posts: 304
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's something I came up with.....


PHP Code:
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.)
Reply With Quote
  #3  
Old 02-28-2012, 11:43 PM
Noslo Noslo is offline
 
Join Date: Dec 2011
Posts: 50
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi,

How would I edit this parse_templates hook? Where would I even find it?
Reply With Quote
  #4  
Old 02-28-2012, 11:47 PM
Sarteck's Avatar
Sarteck Sarteck is offline
 
Join Date: Mar 2008
Posts: 304
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 02-28-2012, 11:54 PM
Noslo Noslo is offline
 
Join Date: Dec 2011
Posts: 50
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 [DATE]1330476950[/DATE] at [TIME]1330476950[/TIME] ---------------

EDIT:

I removed all the parts with user info and got what I wanted Thanks so much!!
Reply With Quote
  #6  
Old 02-28-2012, 11:57 PM
Sarteck's Avatar
Sarteck Sarteck is offline
 
Join Date: Mar 2008
Posts: 304
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, yes.


PHP Code:
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 [DATE]1330502363[/DATE] at [TIME]1330502363[/TIME] ---------------

I take the lack of response as heartening. :> You got it to work okay, I presume?
Reply With Quote
  #7  
Old 02-29-2012, 10:05 AM
Noslo Noslo is offline
 
Join Date: Dec 2011
Posts: 50
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #8  
Old 02-29-2012, 11:16 AM
Sarteck's Avatar
Sarteck Sarteck is offline
 
Join Date: Mar 2008
Posts: 304
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #9  
Old 02-29-2012, 11:17 AM
Noslo Noslo is offline
 
Join Date: Dec 2011
Posts: 50
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

But I want it to be different colours depending on which user group

--------------- Added [DATE]1330519221[/DATE] at [TIME]1330519221[/TIME] ---------------

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

Code:
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']);}
Reply With Quote
  #10  
Old 02-29-2012, 11:52 AM
Sarteck's Avatar
Sarteck Sarteck is offline
 
Join Date: Mar 2008
Posts: 304
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, I see. Hmm. In that case, a little alteration is required:

PHP Code:
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']);} 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:47 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.15592 seconds
  • Memory Usage 2,273KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete