Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-08-2015, 01:26 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Template Variable Hook

Hey all. I read this article: https://vborg.vbsupport.ru/showthread.php?t=228078 (You know, searching before posting) and I was still a bit confused. I want to do the following:

For each post, I want to set a variable to use in the postbit based on the user's usergroup.

I imagine I can use the last part of the article to pass the variable to the postbit_legacy template(?) but I don't know where I should place my hook or how to get the poster's info from that hook. Help appreciated!
Reply With Quote
  #2  
Old 04-08-2015, 03:14 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you want to add something to the postbit template, postbit_display_complete is probably a good hook to use. The template name you can use to preRegister is $this->template_prefix . $this->templatename.

I think the post author's usergroup info might already be in the $post array, so you might not need a plugin if you can do what you want to do using is_member_of() in a template conditional.
Reply With Quote
  #3  
Old 04-08-2015, 06:36 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'd prefer to use a hook because I will be doing multiple checks and there are multiple outcomes. I don't want to lengthen the template, so I'd rather just do all that in php and pass off the results.
Reply With Quote
  #4  
Old 04-15-2015, 01:59 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So after thinking awhile, I think this would be better to store in the $userdata array, but I don't want it to be premanent (drawn from the database) but rather dynamically generated when the userdata is retrieved. I think this will be easier than to do a check on every postbit, considering you may have the same poster multiple times. Is there a way to do that?
Reply With Quote
  #5  
Old 04-15-2015, 02:33 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think you can use the hook fetch_userinfo and look at the user info in $user, and add whatever you want to it. Then it should appear in $post in the postbit. (And it's cached for you).
Reply With Quote
  #6  
Old 04-15-2015, 07:48 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So I could essentially just add $user['blabla'] = xxx; to set that within the userinfo? After that wouldn't I still need a template hook to pass those variables, or does userdata work by allowing anything in that data set to be referenced?
Reply With Quote
  #7  
Old 04-15-2015, 08:34 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by KGodel View Post
So I could essentially just add $user['blabla'] = xxx; to set that within the userinfo? After that wouldn't I still need a template hook to pass those variables, or does userdata work by allowing anything in that data set to be referenced?
I'm not sure if I follow that, but when the postbit tremplate is being rendered, the userinfo is combined with the post info and registered to the template as 'post', so you should be able to use {vb:raw post.blabla} in the postbit (or postbit_legacy) template without doing anything else.
Reply With Quote
  #8  
Old 04-23-2015, 09:00 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So it doesn't seem to be working. Here is what I have at the hook "fetch_userinfo".

PHP Code:
$lrank $srank "";

switch (
$userinfo['usergroupid']) {
    
// Leadership Ranks
    
case 6:                // Clan Leader
        
if ($userinfo['userid'] == 1) {
            
$lrank "<img src='images/ranks/v10/cf.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Clan Founder' \>";
            
$srank "<img src='images/ranks/v9/cf.png' alt='Clan Founder' \>";
        } else {
            
$lrank "<img src='images/ranks/v10/cl.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Clan Leader' \>";
            
$srank "<img src='images/ranks/v9/cl.png' alt='Clan Leader' \>";
        }
        break;
    case 
5:                // Clan Officer
        
$lrank "<img src='images/ranks/v10/co.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Clan Officer' \>";
        
$srank "<img src='images/ranks/v9/co.png' alt='Clan Officer' \>";
        break;
    case 
24:               // Clan Coordinator
        
$lrank "<img src='images/ranks/v10/cc.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Clan Coordinator' \>";
        
$srank "<img src='images/ranks/v9/cc.png' alt='Clan Coordinator' \>";
        break;
    case 
17:               // Division Leader
        
$lrank "<img src='images/ranks/v10/dl.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Division Leader' \>";
        
$srank "<img src='images/ranks/v9/dl.png' alt='Division Leader' \>";
        break;
    case 
18:               // Division Officer
        
$lrank "<img src='images/ranks/v10/do.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Division Officer' \>";
        
$srank "<img src='images/ranks/v9/do.png' alt='Division Officer' \>";
        break;
    case 
62:               // Team Manager
        
$lrank "<img src='images/ranks/v10/tm.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Team Manager' \>";
        
$srank "<img src='images/ranks/v9/tm.png' alt='Team Manager' \>";
        break;
    case 
38:               // Leadership Trainee
        
$lrank "<img src='images/ranks/v10/lt.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Leadership Trainee' \>";
        
$srank "<img src='images/ranks/v9/lt.png' alt='Leadership Trainee' \>";
        break;
    
// Member Ranks
    
case 53:               // Visionary
        // Custom Rank Files
        
$ltagfile "images/ranks/v10/vis/" strtolower(str_replace(' '''$userinfo['username'])) . ".png";
        
$stagfile "images/ranks/v9/vis/" strtolower(str_replace(' '''$userinfo['username'])) . ".png";
        
        
// Default VM
        
$lrank "<img src='images/ranks/v10/vm.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Visionary Member' \>";
        
$srank "<img src='images/ranks/v9/vm.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Visionary Member' \>";
        
        
// Check for a Custom Ranks
        
if (file_exists($ltagfile)) { 
            
$lrank "<img src='" $ltagfile "' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Visionary Member' \>";
        }
        if (
file_exists($stagfile)) {
            
$srank "<img src='" $stagfile "' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Visionary Member' \>";
        }
        break;
    case 
52:               // Renowned
        
$lrank "<img src='images/ranks/v10/rm.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Renowned Member' \>";
        
$srank "<img src='images/ranks/v9/rm.png' alt='Renowned Member' \>";
    case 
51:               // Senior
        
$lrank "<img src='images/ranks/v10/srm.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Senior Member' \>";
        
$srank "<img src='images/ranks/v9/srm.png' alt='Senior Member' \>";
    case 
35:               // Steadfast
        
$lrank "<img src='images/ranks/v10/sm.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Steadfast Member' \>";
        
$srank "<img src='images/ranks/v9/sm.png' alt='Steadfast Member' \>";
    case 
2:                // Apprentice
        
$lrank "<img src='images/ranks/v10/ap.png' style='margin-left:auto; margin-right:auto; margin-top:-4px; display:block; overflow:visible; position:relative; z-index:10;' alt='Apprentice Member' \>";
        
$srank "<img src='images/ranks/v9/ap.png' alt='Apprentice Member' \>";
    
// Other Statuses
    
case 21:               // Missing in Action
        
$lrank "Missing in Action";
        
$srank "Missing in Action";
    case 
20:               // Extended Leave
        
$lrank "Extended Leave";
        
$srank "Extended Leave";
    case 
23:               // Resigned
        
$lrank "Resigned";
        
$srank "Resigned";
    case 
65:               // Inactive
        
$lrank "Inactive";
        
$srank "Inactive";
    case 
45:               // Guest Account
        
$lrank "Official Guest";
        
$srank "Official Guest";
    case 
8:                // Dismissed
        
$lrank "Dismissed";
        
$srank "Dismissed";
}

// Set the User Info
$userinfo['lrank'] = $lrank;
$userinfo['srank'] = $srank
Reply With Quote
  #9  
Old 04-23-2015, 09:26 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, using hook fetch_userinfo you'd want to use $user instead of $userinfo. You could try that, since it should be pretty quick to make that change, but looking at showthread.php I think I may have been wrong. Sorry about that, but it looks like showthread.php gets the userinfo as part of the query for posts in a thread, so I guess it doesn't call fetch_userinfo(). So it doesn't look like you can do much better than doing it in postbit_complete and using $post in place of $userinfo (although you should otherwise be able to use the same code, of course). And if you want to cache it, you'll have to build your own (just save arrays with lrank and srank in a global array with userid as index, and check that before executing your code). But you're not doing a db query or anything to get your answer, so if it were me I probably wouldn't bother.
Reply With Quote
  #10  
Old 04-23-2015, 09:50 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yea, after I thought about it I realized even if it did call fetch_userinfo, it would still be calling that on each individual post so I wouldn't really be saving any time code-wise. I just switched it to $post and moved to the postbit_display_complete hook and it works like a charm. Now just a bit more and it'll be doing what I want.
Reply With Quote
Благодарность от:
kh99
Reply


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 10:59 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.04358 seconds
  • Memory Usage 2,312KB
  • Queries Executed 13 (?)
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
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete