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

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
  #92  
Old 04-24-2009, 02:47 AM
Chadi's Avatar
Chadi Chadi is offline
 
Join Date: May 2004
Location: USA
Posts: 2,043
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

NOTE: I'm creating a new mode for Shelfari called "My Shelfari Bookshelf". I reserve this idea, so please don't steal my idea

Having a hard time applying this for a new tab called "Shelfari" (shelfari.com)

The template is:

memberinfo_block_shelfari

Code:
<div class="alt1 block_row">
    <ul class="list_no_decoration">
        $block_data[shelfari]
    </ul>
</div>
The plugin is:
Code:
$blocklist = array_merge($blocklist, array(
    'mymodification' => array(
        'class' => 'Shelfari',
        'title' => 'My Shelfari Bookshelf',
        'hook_location' => 'profile_left_last'
    )
));

class vB_ProfileBlock_Shelfari extends vB_ProfileBlock
{
    var $template_name = 'memberinfo_block_shelfari';

    function confirm_empty_wrap()
    {
        return false;
    }

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

    function prepare_output($id = '', $options = array())
    {
        $this->block_data['shelfari'] = '<embed width="500" height="500" src="http://www.shelfari.com/ws/shelf.swf" wmode="transparent" FlashVars="UserName=chadi&ShelfType=list&verE=s1.5&ListType=isowned&booksize=large&Alpha=0&BGColor=FFFFFF"></embed>';
    }
}
Note, "chadi" in that Shelfari embed code I pasted at the end of the plugin is my actual Shelfari username. However, I created a user profile field called "My Shelfari Bookshelf", which is field44.

I tried replacing chadi with $userinfo[field44] and it did not pull correctly.

What is the actual proper replacement code to pull whatever content from the user's field44 profile field to replace my actual username?

Can some also please explain how to properly create a plugin file for this, so I can share it as a mod?
Reply With Quote
  #93  
Old 04-24-2009, 02:55 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 Chadi View Post
What is the actual proper replacement code to pull whatever content from the user's field44 profile field to replace my actual username?
Try $this->profile->userinfo['field44']
Reply With Quote
  #94  
Old 04-24-2009, 03:02 AM
Chadi's Avatar
Chadi Chadi is offline
 
Join Date: May 2004
Location: USA
Posts: 2,043
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, but the tab doesn't show up now.

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

class vB_ProfileBlock_Shelfari extends vB_ProfileBlock
{
    var $template_name = 'memberinfo_block_shelfari';

    function confirm_empty_wrap()
    {
        return false;
    }

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

    function prepare_output($id = '', $options = array())
    {
        $this->block_data['shelfari'] = '<embed width="700" height="700" src="http://www.shelfari.com/ws/shelf.swf" wmode="transparent" FlashVars="UserName=$this->profile->userinfo['field44']&ShelfType=list&verE=s1.5&ListType=isowned&booksize=large&AmazonAssociate=taljes-20&Alpha=0&BGColor=FFFFFF"></embed>';
    }
}
Reply With Quote
  #95  
Old 04-24-2009, 03:08 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try assigning it to a variable and then use the variable in that line of code:
PHP Code:
$var $this->profile->userinfo['field44'];
   
$this->block_data['shelfari'] = '..... UserName=' $var '&Shel....'
Something like that. You'll probably have to play with it a bit.
Reply With Quote
  #96  
Old 04-24-2009, 03:15 AM
Chadi's Avatar
Chadi Chadi is offline
 
Join Date: May 2004
Location: USA
Posts: 2,043
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, but I really don't know what you're telling me here. I'm not a coder

Can you give me a hint by pasting what the entire plugin code should look like? It'll be easier for me to dissect it carefully from there.

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

Ok, I tried this:

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

class vB_ProfileBlock_Shelfari extends vB_ProfileBlock
{
    var $template_name = 'memberinfo_block_shelfari';

    function confirm_empty_wrap()
    {
        return false;
    }

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

    function prepare_output($id = '', $options = array())
    {
$var = $this->profile->userinfo['field44'];
        $this->block_data['shelfari'] = '<embed width="700" height="700" src="http://www.shelfari.com/ws/shelf.swf" wmode="transparent" FlashVars="UserName' . $var . '&ShelfType=list&verE=s1.5&ListType=isowned&booksize=large&AmazonAssociate=taljes-20&Alpha=0&BGColor=FFFFFF"></embed>';
    }
}
now, the output works except one more problem:

The actual widget is giving an error stating that a username was not provided and must be provided.

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

Fixed. I had to had the = after UserName.

Thanks Lynne.

One quick question, I'd like to make an xml plugin file so people can install this as a product. Could I trouble you to explain how this can be done?
Reply With Quote
  #97  
Old 04-24-2009, 02:16 PM
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 Chadi View Post
One quick question, I'd like to make an xml plugin file so people can install this as a product. Could I trouble you to explain how this can be done?
Looks like you already figured that out since I saw you released your mod.
Reply With Quote
  #98  
Old 04-24-2009, 02:33 PM
Chadi's Avatar
Chadi Chadi is offline
 
Join Date: May 2004
Location: USA
Posts: 2,043
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, and gave you and Wired1 credit for the help.

Thank you Lynne, appreciate it.

PS: would you like me to make you co-author of the mod? I'm honestly not sure how these things work on the forums. I've only started releasing mods a couple days ago. I'm not even a programmer.
Reply With Quote
  #99  
Old 04-24-2009, 03:41 PM
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 Chadi View Post
PS: would you like me to make you co-author of the mod? I'm honestly not sure how these things work on the forums. I've only started releasing mods a couple days ago. I'm not even a programmer.
No, no. I am here just to help out. I really don't know what the co-author thing is for, but just giving you a couple pointers doesn't make me a co-author. You did all the hard work.
Reply With Quote
  #100  
Old 04-29-2009, 09:52 PM
H3C x Nevz H3C x Nevz is offline
 
Join Date: Mar 2009
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay, I've installed this properly, and I need a somewhat specific request:

-- Search for all threads started by user, in forumID 12 and all child boards -- [USERNAME]'s Posted Content -- End Link --

Sorry, I really don't know a lot about using variables...
Reply With Quote
  #101  
Old 05-07-2009, 07:42 AM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you want to know how to pull HTML from a template rather than writing the HTML in the plugin take a look at what I've wrote.
PHP Code:
function prepare_output($id ''$options = array())
{
    global 
$vbulletin$db;       

    
$query $db->query_read("SELECT * FROM " TABLE_PREFIX "mkwtracktimes WHERE userid = '".$vbulletin->userinfo['userid']."'");
    while(
$mkw $db->fetch_array($query))
    {
        eval(
'$data .= "' fetch_template('mkw_profilebit') . '";');
    }

    
$this->block_data['mkwttrecords'] = $data;

Reply With Quote
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 05:01 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.11720 seconds
  • Memory Usage 2,357KB
  • 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
  • (9)bbcode_code
  • (2)bbcode_php
  • (3)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