Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Using your User Profile Fields in your postbit templates (w/ all plugin method)
Lynne's Avatar
Lynne
Join Date: Sep 2004
Posts: 41,180

 

California/Idaho
Show Printable Version Email this Page Subscription
Lynne Lynne is offline 09-12-2010, 10:00 PM

This article is written with the assumption that you have already created your own User Profile Fields in the User Profile Field Manager. If you need help with this, you may read about it in the manual here - http://www.vbulletin.com/docs/html/profile

For the Purposes of this article, I will be referring to "fieldx" as the name of your profile field. Your real name will be found in the User Profile Manager in the "Name" column - field1, field2, etc.

Adding the Profile Field to your postbit (or postbit_legacy) template

For Single-Line Text Box, Multiple-Line Text Box, Single-Selection Radio Buttons, and Single-Selection Menu

Method 1
- Modifying the Template
Open the postbit or postbit_legacy template and find the area you want to add it to. For instance, to add it right after the user post count, find this:
Code:
<dt>{vb:rawphrase 'posts'}</dt> <dd>{vb:raw post.posts}</dd>
And then, add this underneath:
Code:
<vb:if condition="$post['fieldx']"><dt>My FieldX</dt> <dd>{vb:raw post.fieldx}</dd></vb:if>
Change "fieldx" to your actual field name and the green field to whatever you want. Notice the html I used is similar to the html used for the text above me new field.
Method 2 - Using a template_hook
I have always found it easier to just use the existing $template_hooks in the template and write a plugin to add these. In this case, there is a $template_hook right where we want it, after the user post count:
Code:
{vb:raw template_hook.postbit_userinfo_right_after_posts}
So, we would create a plugin with these specifications:
? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates
? Plugin is Active - Yes
? Plugin PHP Code -
Code:
if ($post['fieldx'])
{
    $template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' .$post[fieldx]. '</dd>';
}
Change "fieldx" to your actual field name and the green field to whatever you want. Again, notice the html I used is similar to the html used for the text above me new field. Whichever template_hook you use, you should look at the template to see what sort of html is being used around the hook so that you may use similar, proper html also.
For Multiple-Selection Menu and Multiple-Selection Checkbox

It is a bit more complicated for these two types of selections since the options selected are stored as a binary number. If you just display the field using the method above, you will get a number, not a list of options selected. So, in order to use these types of fields, you will have to use the method below. Here is a thead that will explain the binary scheme - http://www.vbulletin.com/forum/showt...To-The-Postbit

Method 1
- Modifying the Template
Open the template and find the area you want to add it to. For instance, to add it right after the user post count, find this:
Code:
<dt>{vb:rawphrase 'posts'}</dt> <dd>{vb:raw  post.posts}</dd>
And then add this underneath (this is assuming the field has 5 options):
Code:
<vb:if condition="$post['fieldx']"><dt>My FieldX</dt><dd>
<vb:if condition="$post['fieldx'] & 1">Your 1rst option</vb:if>
<vb:if condition="$post['fieldx'] & 2">Your 2nd option</vb:if>
<vb:if condition="$post['fieldx'] & 4">Your 3rd option</vb:if>
<vb:if condition="$post['fieldx'] & 8">Your 4th option</vb:if>
<vb:if condition="$post['fieldx'] & 16">Your 5th option</vb:if>
</dd>
</vb:if>
Change "fieldx" to your actual field name and the green field to whatever you want. Notice the html I used is similar to the html used for the text above me new field.
Method 2 - Using a template_hook
Find the template_hook you want to use. In this case, there is a $template_hook right where we want it, after the user post count:
Code:
{vb:raw template_hook.postbit_userinfo_right_after_posts}
So, we would create a plugin with these specifications:
? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates
? Plugin is Active - Yes
? Plugin PHP Code -
Code:
if ($post['fieldx'])
{
    $template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>';
    
    if ($post['fieldx'] & 1)  $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 1rst option';
    if ($post['fieldx'] & 2)  $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 2nd option';
    if ($post['fieldx'] & 4)  $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 3rd option';
    if ($post['fieldx'] & 8)  $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 4th option';
    if ($post['fieldx'] & 16)  $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 5th option';
    
    $template_hook['postbit_userinfo_right_after_posts'] .= '</dd>';
}
Change "fieldx" to your actual field name and the green field to whatever you want. Again, notice the html I used is similar to the html used for the text above me new field. Whichever template_hook you use, you should look at the template to see what sort of html is being used around the hook so that you may use similar, proper html also.
More Advanced

If you like everything to be 'automatic' - meaning you don't have to supply any text at all, just use everything already stored in the database - then you can use a few of plugins to do the work for you.

Plugin 1
- This plugin is used to get the phrasegroup "cprofilefield" added for use in the page so that you may use $vbphrase[fieldx_title] to get the Profile Field Title you entered in the User Profile Field Manager.
? hook location - init_startup
? Title - Add User Profile Fields to Postbit Templates - 1
? Plugin is Active - Yes
? Plugin PHP Code -
Code:
if (THIS_SCRIPT == 'showthread') $GLOBALS['phrasegroups'][] = 'cprofilefield';
Plugin 2 - This plugin is used to get the fields you defined for the profile in the User Profile Field Manager.
? hook location - showthread_postbit_create
? Title - Add User Profile Fields to Postbit Templates - 2
? Plugin is Active - Yes
? Plugin PHP Code -
Code:
if (THIS_SCRIPT == 'showthread') {
    $profilefieldx =  $vbulletin->db->query_first("SELECT profilefieldid, data, type  FROM " . TABLE_PREFIX . "profilefield WHERE profilefieldid = x");
    $post['profilefieldx'] = $profilefieldx;
}
Plugin 3 - This plugin simply spits the data out into the postbit using the template_hook and using the phrase for the Title and the Options are all spit out with commas between them (if needed) into the postbit.
? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates - 3
? Plugin is Active - Yes
? Plugin PHP Code -
Code:
// for single-line fields - using fieldy
if ($post['fieldy']) {
     $template_hook['postbit_userinfo_right_after_posts'] .= '<dt>' .$vbphrase[fieldy_title]. '</dt> <dd>' .$post[fieldy]. '</dd>';
 }

// for multiple-selection fields - using filedx
if ($post['fieldx'])
{
    $fieldarrayx = $post['profilefieldx'];
    fetch_profilefield_display($fieldarrayx, $post['fieldx']);
    $template_hook['postbit_userinfo_right_after_posts'] .= '<dt>' .$vbphrase[fieldx_title]. '</dt> <dd>' .$fieldarrayx['value']. '</dd>'; 
}
Change "fieldx" to your actual field name and the orange, purple, and brown fields should 'match-up' and have the same names.
Reply With Quote
  #22  
Old 01-11-2011, 02:53 AM
stl7997 stl7997 is offline
 
Join Date: Nov 2009
Location: Germany
Posts: 61
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you so much for this article! I was wondering where I need to add a break (see picture) to the code in the template. I would like a break to be done after the 'AE Assignments:' so that everything appears on the line below it.

Thanks in advance!
Attached Images
File Type: jpg Capture.JPG (13.5 KB, 0 views)
Reply With Quote
  #23  
Old 01-11-2011, 03:02 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by stl7997 View Post
Thank you so much for this article! I was wondering where I need to add a break (see picture) to the code in the template. I would like a break to be done after the 'AE Assignments:' so that everything appears on the line below it.

Thanks in advance!
Can't you just add a <br /> where you want a break?
Reply With Quote
  #24  
Old 01-11-2011, 09:32 AM
stl7997 stl7997 is offline
 
Join Date: Nov 2009
Location: Germany
Posts: 61
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
Can't you just add a <br /> where you want a break?
Yes that is exactly what I want to do, however I'm a complete noob to PHP. I've tried adding the <br /> in different places to the code but cannot get the desired results.

Where would I add the <br /> in this code? Or is this even the right place to place it?

Sorry for such rookie questions

PHP Code:
// for single-line fields - using fieldy
if ($post['fieldy']) {
     
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>' .$vbphrase[fieldy_title]. '</dt> <dd>' .$post[fieldy]. '</dd>';
 }

// for multiple-selection fields - using filedx
if ($post['fieldx'])
{
    
$fieldarrayx $post['profilefieldx'];
    
fetch_profilefield_display($fieldarrayx$post['fieldx']);
    
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>' .$vbphrase[fieldx_title]. '</dt> <dd>' .$fieldarrayx['value']. '</dd>'

Reply With Quote
  #25  
Old 01-11-2011, 08:16 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Put it right after the </dt> and before the <dd> for the field you are adding.
Reply With Quote
  #26  
Old 01-12-2011, 02:20 AM
stl7997 stl7997 is offline
 
Join Date: Nov 2009
Location: Germany
Posts: 61
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
Put it right after the </dt> and before the <dd> for the field you are adding.
:up:

Thanks Lynne!
Reply With Quote
  #27  
Old 01-20-2011, 01:28 AM
Sarcoth Sarcoth is offline
 
Join Date: Mar 2006
Location: Huntsville
Posts: 521
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can we set this up so only certain users can see postbit addon?
PHP Code:
if (is_member_of($vbulletin->userinfo567))
{
    if (
$post['fieldx'])
    {
        
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' .$post[fieldx]. '</dd>';
    }

I can't seem to get that part to work. Thanks.
Reply With Quote
  #28  
Old 01-20-2011, 03:36 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It could be you need to globalize $vbulletin if you are using that variable.
Reply With Quote
  #29  
Old 01-20-2011, 03:59 AM
Sarcoth Sarcoth is offline
 
Join Date: Mar 2006
Location: Huntsville
Posts: 521
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Sarcoth View Post
Can we set this up so only certain users can see postbit addon?
PHP Code:
if (is_member_of($vbulletin->userinfo567))
{
    if (
$post['fieldx'])
    {
        
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' .$post[fieldx]. '</dd>';
    }

I can't seem to get that part to work. Thanks.
Quote:
Originally Posted by Lynne View Post
It could be you need to globalize $vbulletin if you are using that variable.
Thanks Lynne. I know I had tried that earlier and thought it did not work. Going over my notes I see I used "$global $vbulletin;". I needed to leave out the first $ to fix the problem.

I thought globalizing it could be a security risk in some cases. Is there a problem doing that in this plugin?

Thank you again for the help on that. Now I can go to sleep.
Reply With Quote
  #30  
Old 03-13-2011, 08:55 PM
Special Pages Special Pages is offline
 
Join Date: Nov 2010
Location: www.TheDiscussionCafe.com
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Very good Lynne. Keep up the good work!
Reply With Quote
  #31  
Old 03-18-2011, 04:28 PM
mikem164 mikem164 is offline
 
Join Date: Jan 2009
Posts: 152
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just did this and it turned out phenomenal! A big THANKS!
Reply With Quote
Благодарность от:
Crrrazzzy
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 03:55 AM.


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.04687 seconds
  • Memory Usage 2,372KB
  • Queries Executed 26 (?)
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
  • (11)bbcode_code
  • (3)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (8)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (11)postbit_onlinestatus
  • (11)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • 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
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete