Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles

Reply
 
Thread Tools
[How-to] Add more tabs to the vB 3.7 profile pages
calorie
Join Date: May 2003
Posts: 2,804

 

Show Printable Version Email this Page Subscription
calorie calorie is offline 12-18-2007, 10:00 PM

If you want to add more tabs to the vB 3.7 profile pages, assuming JavaScript is enabled, or more blocks if JavaScript is off, then this tutorial is for you. If you like to learn in a trial by fire sort of way, create a new template titled memberinfo_block_mymodification with the following content:
Code:
<div class="alt1 block_row">
	<ul class="list_no_decoration">
		$block_data[mymodification]
	</ul>
</div>
Add a new plugin to the member_build_blocks_start hook with the following PHP code:
Code:
$blocklist = array_merge($blocklist, array(
	'mymodification' => array(
		'class' => 'MyModification',
		'title' => 'My Modification',
		'hook_location' => 'profile_left_last'
	)
));

class vB_ProfileBlock_MyModification extends vB_ProfileBlock
{
	var $template_name = 'memberinfo_block_mymodification';

	function confirm_empty_wrap()
	{
		return false;
	}

	function confirm_display()
	{
		return ($this->block_data['mymodification'] != '');
	}

	function prepare_output($id = '', $options = array())
	{
		$this->block_data['mymodification'] = 'Content to show in the tab.';
	}
}
Now visit your profile page to test it out. You should see a 'My Modification' tab that when clicked shows you the following text: Content to show in the tab. Exciting huh? Of course you need to add your own custom code for what to display, but this tutorial isn't about that, but rather to show you how to add tabs to the profile pages.

If you want to learn a bit more of the details, first consider this part:
Code:
$blocklist = array_merge($blocklist, array(
	'mymodification' => array(
		'class' => 'MyModification',
		'title' => 'My Modification',
		'hook_location' => 'profile_left_last'
	)
));
The $blocklist variable contains the default blocks. You merge to that another array where the key 'mymodification' references an array which sets a class to use, the title of the tab on the profile page, and the hook location. You can set whatever you want for title including the use of $vbphrase but in the example 'My Modification' is used. As for the hook location, you can use profile_left_first or profile_left_last depending on whether you want your new tab to be left or right of the current tabs, respectively.

Next consider the next part:
Code:
class vB_ProfileBlock_MyModification extends vB_ProfileBlock
{
	var $template_name = 'memberinfo_block_mymodification';

	function confirm_empty_wrap()
	{
		return false;
	}

	function confirm_display()
	{
		return ($this->block_data['mymodification'] != '');
	}

	function prepare_output($id = '', $options = array())
	{
		$this->block_data['mymodification'] = 'Content to show in the tab.';
	}
}
The class needs to be called vB_ProfileBlock_MyModification extends vB_ProfileBlock and note that part of the class name is vB_ProfileBlock_MyModification where MyModification comes from the class value set in your addition to the $blocklist variable. Inside the class, $template_name is set to the template to use, the confirm_empty_wrap function returns false to not create an empty block, the confirm_display function tests whether there is any content to display, and the prepare_output function is where you?d want to add your own custom code to fetch whatever you want to display, setting $this->block_data['mymodification'] to the content you want displayed. Remember variable scope when you add your own code, as you are inside a function that is inside a class.

Now there is the new template itself:
Code:
<div class="alt1 block_row">
	<ul class="list_no_decoration">
		$block_data[mymodification]
	</ul>
</div>
Note that $block_data[mymodification] contains whatever $this->block_data['mymodification'] contains in the prepare_output function inside the class, and because a hook location is set in your addition to the $blocklist variable, there are no manual template edits to make. Hooray! You should of course replace 'mymodification', 'MyModification', and 'My Modification' throughout this tutorial with something meaningful for your modification.

Finally there are other things that can be added to modifications such as options, and these can be seen in the vB class_profileblock.php and member.php files, though this tutorial should get you on your way to adding more content to the profile pages via additional tabs, but remember not to go overboard with queries, because even though you need to click the tab to see the content, whatever queries you run get run on page load, not tab click. Enjoy!

Fine print: tutorial based on vB 3.7.0 Beta 2, no redistribution without permission.
Reply With Quote
  #72  
Old 01-25-2009, 04:19 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Make $vbulletin global in the plugin.
Reply With Quote
  #73  
Old 02-03-2009, 01:53 PM
Cledus James Cledus James is offline
 
Join Date: Oct 2008
Posts: 79
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, this might have been answered before, but it seems I'm doing something wrong. I'm trying to add a new tab and display a custom profile field (field24) in it. Here's my plugin code:

Code:
$blocklist = array_merge($blocklist, array(
	'mymodification' => array(
		'class' => 'MyModification',
		'title' => 'My Modification',
		'hook_location' => 'profile_left_last'
	)
));

class vB_ProfileBlock_MyModification extends vB_ProfileBlock
{
	var $template_name = 'memberinfo_block_mymodification';

	function confirm_empty_wrap()
	{
		return false;
	}

	function confirm_display()
	{
		return ($this->block_data['mymodification'] != '');
	}

	function prepare_output($id = '', $options = array())
    {
 
        $this->block_data['mymodification'] = $this->profile->userinfo['field24'] : "Stuff: $this->profile->userinfo['field24']" ? "Nothing to see here";
    }
}
}
But when I add this I get an error on the website page:

Quote:
Parse error: parse error, unexpected ':' in /home/url/forums/member.php(464) : eval()'d code on line 26

Fatal error: Cannot instantiate non-existent class: vb_profileblock_myawards in /home/url/forums/includes/class_profileblock.php on line 64
When I ad just the original plugin code I don't get the error, but as soon as I try and replace the $this code it gives me the error. Wondering if anyone could be of any help. I'm a vBulletin newb. What am I doing wrong? Thanks.
Reply With Quote
  #74  
Old 02-05-2009, 07:32 PM
Dinatius Dinatius is offline
 
Join Date: Jan 2008
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Cledus: The ?: is in the wrong order. It should be:
Code:
$this->block_data['mymodification'] = $this->profile->userinfo['field24'] ? "Stuff: $this->profile->userinfo['field24']" : "Nothing to see here";

On another topic, for anyone interested, and to get some feedback on whether this is done properly:

I wanted to get mysql data on my new tab, and $db and $vbulletin->db didn't work - they aren't around when this code gets called. In the class_profileblock.php file, when it's building the static blocks such as user statistics and buddy list, it uses this:
Code:
$this->registry->db
It gets me the info, so it works, but is there a preferable way to do it?

Edit: $this->registry seems to be the same as $vbulletin elsewhere...
Reply With Quote
  #75  
Old 02-06-2009, 01:21 PM
Cledus James Cledus James is offline
 
Join Date: Oct 2008
Posts: 79
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dinatius View Post
Cledus: The ?: is in the wrong order. It should be:
Code:
$this->block_data['mymodification'] = $this->profile->userinfo['field24'] ? "Stuff: $this->profile->userinfo['field24']" : "Nothing to see here";

Ok, I updated it and it did fix the error, but it still didn't display the field. It displayed:

Quote:
Stuff: Object->userinfo['field24']
in the profile tab. What should I do to display the content of the my custom profile field 24.

So here's my plugin right now:

Code:
$blocklist = array_merge($blocklist, array(
	'mymodification' => array(
		'class' => 'MyModification',
		'title' => 'My Modification',
		'hook_location' => 'profile_left_last'
	)
));

class vB_ProfileBlock_MyModification extends vB_ProfileBlock
{
	var $template_name = 'memberinfo_block_mymodification';

	function confirm_empty_wrap()
	{
		return false;
	}

	function confirm_display()
	{
		return ($this->block_data['mymodification'] != '');
	}

	function prepare_output($id = '', $options = array())
    {
 
        $this->block_data['mymodification'] = $this->profile->userinfo['field24'] ? "Stuff: $this->profile->userinfo['field24']" : "Nothing to see here";
    }
}
By the way, thanks for the reply.
Reply With Quote
  #76  
Old 02-06-2009, 02:01 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried to see if your plugin is even working by doing something simple like:

PHP Code:
$this->block_data['mymodification'] = 'This is a test'
OR, see if the profile field is even available there:
PHP Code:
$this->block_data['mymodification'] = '$this->profile->userinfo['field24']'
Reply With Quote
  #77  
Old 02-06-2009, 04:19 PM
Dinatius Dinatius is offline
 
Join Date: Jan 2008
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oops, wasn't looking at the rest of the code. Array values need to be appended, can't be parsed inside quotes like a normal $variable:
Code:
$this->block_data['mymodification'] = $this->profile->userinfo['field24'] ? "Stuff: ".$this->profile->userinfo['field24'] : "Nothing to see here";
Alternately, you can put that array value in a variable and put that in quotes, although I'm not sure what that would do to the ?: selector. If it works, it makes things easier to read... Example:
Code:
$field24=$this->profile->userinfo['field24'];
$this->block_data['mymodification'] = $field24 ? "Stuff: $field24" : "Nothing to see here";
I'm only intermediate at PHP, too, so I'm not sure how that would affect performance (also depends how heavily the page is used)

(p.s. If people prefer I don't answer questions here, I'll move to PM)
Reply With Quote
  #78  
Old 02-09-2009, 04:13 PM
Cledus James Cledus James is offline
 
Join Date: Oct 2008
Posts: 79
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sent you a PM.
Reply With Quote
  #79  
Old 02-14-2009, 04:57 AM
Cledus James Cledus James is offline
 
Join Date: Oct 2008
Posts: 79
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, can someone help me just a bit more. Probably just an easy fix.

Now I added the last code posted to my plugin and it worked. It displayed the data from my custom profile field 18. In my above thread I said it was userfield24 but I had it wrong, it's userfield18. Now here's my plugin code:


Code:
$blocklist = array_merge($blocklist, array(
	'mymodification' => array(
		'class' => 'MyModification',
		'title' => 'My Modification',
		'hook_location' => 'profile_left_last'
	)
));

class vB_ProfileBlock_MyModification extends vB_ProfileBlock
{
	var $template_name = 'memberinfo_block_mymodification';

	function confirm_empty_wrap()
	{
		return false;
	}

	function confirm_display()
	{
		return ($this->block_data['mymodification'] != '');
	}

	function prepare_output($id = '', $options = array())
    {
 
        $this->block_data['mymodification'] = $this->profile->userinfo['field18'] ? "Stuff: ".$this->profile->userinfo['field18'] : "Nothing to see here";
    }
}
Like I said works fine with one small problem. Now the data I have stored in userfield18 is a list of information, like:

1. List Item 1
2. List Item 2
3. List Item 3
4. List Item 4
etc.

Now when its displayed in the new tab it all comes out on the same line like:

1. List Item 1 2. List Item 2 3. List Item 3 4. List Item 4

My question is, is there any way I can get it to be displayed in a list format? Like creating a new line for every list object? I tried adding a BR command in the field input itself without any luck. Anyone know how I can get it displayed like the way I input it into the field?

Thank you for any help anyone may offer.

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

Can anyone help?
Reply With Quote
  #80  
Old 02-14-2009, 04:21 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure, but I would take a look at exactly what is in that field and see what separates the items and perhaps do a search/replace on the separator with a <br />
Reply With Quote
  #81  
Old 02-15-2009, 01:10 AM
Cledus James Cledus James is offline
 
Join Date: Oct 2008
Posts: 79
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
I'm not sure, but I would take a look at exactly what is in that field and see what separates the items and perhaps do a search/replace on the separator with a <br />
Basically its just a list of info that is manually entered by admins into a custom field via admin cp. We have a ranking system of 1-22 on the website. The list just basically lets the users know how that got to what rank and what they've gotten credit for towards rank.

Anyway here's the url of my site profiles:

My Profile - Now what I'm trying to do is display that information in the Rank Information module on the right side under the Mini Stats into a new profile tab. I made the plugin active again so you can see the output under the My Modification tab. Basically want the rank info from the module inside the new tab in a list format. I'll rename the new tab and remove the info from th emodule when I get it working properly.

If for some reason you can not see the info I'm talking about on my site here's an example of some information (as listed in the custom field in the admin cp) thats in my custom field that I want displayed in list format.

Quote:
1. Website Owner
2. 6 month Member
3. 1 year Member
4. 100 Website Posts
5. 250 Website Posts
6. 500 Website Posts
7. 1000 Website Posts
8. Website staff
9. Clan Recruiting
10. Gears of War Roster
11. Rainbow Six Vegas Roster
12. Battlefield: Bad Company Roster
13. Call of Duty 4 Roster
14. Ghost Recon 2 Roster
15. Grand Theft Auto 4 Roster
16. Rainbow Six Vegas 2 Roster
17. Rock Band 2 Roster
18. Gears of War 2 Roster
19. Call of Duty 5 Roster
20. 3 Month Member
21. 50 Website Posts
22. 750 Website Posts
Again it comes out as:

Quote:
Stuff: 1. Website Owner 2. 6 month Member 3. 1 year Member 4. 100 Website Posts 5. 250 Website Posts 6. 500 Website Posts 7. 1000 Website Posts 8. Website staff 9. Clan Recruiting 10. Gears of War Roster 11. Rainbow Six Vegas Roster 12. Battlefield: Bad Company Roster 13. Call of Duty 4 Roster 14. Ghost Recon 2 Roster 15. Grand Theft Auto 4 Roster 16. Rainbow Six Vegas 2 Roster 17. Rock Band 2 Roster 18. Gears of War 2 Roster 19. Call of Duty 5 Roster 20. 3 Month Member 21. 50 Website Posts 22. 750 Website Posts
in the new profile tab.


Hope this helps you help me, lol. Thanks for your time.
Reply With Quote
Reply

Thread Tools

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 11:49 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.05215 seconds
  • Memory Usage 2,336KB
  • 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
  • (13)bbcode_code
  • (2)bbcode_php
  • (6)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
  • (1)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete