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
  #112  
Old 12-26-2009, 04:20 AM
ageurtse ageurtse is offline
 
Join Date: Apr 2009
Location: almelo
Posts: 275
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

this works also in vb4.0
Reply With Quote
  #113  
Old 12-26-2009, 06:34 AM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not true

Plugin=> yes
Template not, have to be changed to the vB4 Syntax
Reply With Quote
  #114  
Old 12-27-2009, 11:08 AM
ageurtse ageurtse is offline
 
Join Date: Apr 2009
Location: almelo
Posts: 275
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

what is wrong with the template.
on my test site it run's almost oke.

only when i call te tab by itself http://xxx/forums/member.php?3-Peter...cation&page=10 my custom code is way below everything what is wrong.
When i hit the mymodification tab al is displayed normal.

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

is there also a way to call a php page that should display his content in this newly created tab ?
Reply With Quote
  #115  
Old 01-04-2010, 05:37 PM
Warlord's Avatar
Warlord Warlord is offline
 
Join Date: Jan 2002
Location: TN, USA
Posts: 668
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by krike View Post
just thought I would share with the people who are looking for help.

my vB version is 3.8.1

I needed to query a table I created myself to display all the tutorials of that specific user.
here is the code I used and it works like a charm

Code:
function prepare_output($id = '', $options = array())
        {
            $sql = mysql_query("SELECT * FROM tutorials WHERE approved = 1 AND user_id=".$this->profile->userinfo[userid]."");
            $test = "<ul>";
            while($result = mysql_fetch_array($sql))
            {
                $test .= "<li> <img src='http://cmstutorials.org/".$result['tutorial_thumb']."' width='50' height='50' alt='' /> 
                            <a href='http://cmstutorials.org/tutorial/".$result['tutorial_id']."' target='_blank'>".$result['title']."</a></li>
                        ";
            }
            $test .= "</ul>";
            $this->block_data['mymodification'] = $test;
    }
--------------- Added [DATE]1252407273[/DATE] at [TIME]1252407273[/TIME] ---------------

how do you call a specific tab with a url?

http://cmstutorials.org/forums/member.php?u=1#tabname ????

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

ok I found it http://cmstutorials.org/forums/membe...1&tab=favorite
Is tutorial_thumb a column in one of you sql tables? I'm trying to do something similar but it's really kicking my butt.

I have a form users submit their resume's on. It saves it to the database in the table formresults. The information I want to display on the profile is located in a column labeled output in the formresults table.

Below is the code I'm using in the member_build_blocks_start hook location.

Code:
$blocklist = array_merge($blocklist, array(
    'resume' => array(
        'class' => 'Resume',
        'title' => 'Resume',
        'hook_location' => 'profile_left_last'
    )
));

class vB_ProfileBlock_resume extends vB_ProfileBlock
{
  var $template_name = 'memberinfo_block_resume';
  function confirm_empty_wrap()
  {
    return false;
  }
  function confirm_display()
  {
    return ($this->block_data['resume'] != '');
  }
	function prepare_output($id = '', $options = array())
{
	global $db;
	$sql= $db->query_read("SELECT output FROM " . TABLE_PREFIX . "formresults WHERE userid = '.$this->profile->userinfo[userid].' AND title = 'Resume' ");
            $test = "<div>";
            while($result = mysql_fetch_array($sql))
            {
                $test .= "'.$result['output'].'"
                        ";
            }
            $test .= "</div>";


    $this->block_data['resume'] = $test;
  }
}
I think the code in bolded red is the part I'm getting lost on?

I get this error when displaying the memberinfo profile page.

Quote:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/righscom/public_html/addons/projectfanboy/vb/member.php(463) : eval()'d code on line 249
Reply With Quote
  #116  
Old 01-05-2010, 07:57 PM
Warlord's Avatar
Warlord Warlord is offline
 
Join Date: Jan 2002
Location: TN, USA
Posts: 668
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Anyone?
Reply With Quote
  #117  
Old 01-05-2010, 08:45 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 Warlord View Post
Anyone?
Too many quotes in this 'line':
PHP Code:
                $test .= "'.$result['output'].'"
                        "; 
Reply With Quote
  #118  
Old 01-05-2010, 11:51 PM
Warlord's Avatar
Warlord Warlord is offline
 
Join Date: Jan 2002
Location: TN, USA
Posts: 668
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
Too many quotes in this 'line':
PHP Code:
                $test .= "'.$result['output'].'"
                        "; 

I see what you're talking about, thanks for that. While there was some syntax error there, unfortunately it didn't solve my problem. I changed it to this:

PHP Code:
                $test .= " .$result['output']. "
I'm still getting the same error though:

Quote:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/righscom/public_html/addons/projectfanboy/vb/member.php(463) : eval()'d code on line 249
I thought maybe I was just calling the column in the table contained in the array incorrectly, which gave me the error, but you didn't mention that, so can I assume that if the column in the table is called output that this would be the correct way to retrieve that data?

PHP Code:
$result['output'
Reply With Quote
  #119  
Old 01-05-2010, 11:58 PM
dartho dartho is offline
 
Join Date: Sep 2005
Location: Australia
Posts: 2,303
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

shouldn;'t it just be :
PHP Code:
$test .= $result['output']; 
?

of if you wanted a space after each result

PHP Code:
$test .= $result['output'] . " "
Reply With Quote
  #120  
Old 01-06-2010, 12:11 AM
Warlord's Avatar
Warlord Warlord is offline
 
Join Date: Jan 2002
Location: TN, USA
Posts: 668
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by dartho View Post
shouldn;'t it just be :
PHP Code:
$test .= $result['output']; 
Thank you, that got rid of the annoying error. I really could've sworn I had tried that before but apparently not.

The Resume tab shows up now, unfortunately there is still no data in it. Could it be the type of data that's in there (a mixture of html and php variables) causing it to not show up?

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

Hmmm... I guess not. I changed the data in there to be just the string "This is only a test" and still nothing shows up.

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

HOLY CRAP! I'm almost there! I've been working on this for like a week and I was almost ready to give up but now I'm ALMOST THERE!

The problem was the SQL query was returning no results because apparently this line of code doesn't work the way I thought it did.

PHP Code:
.$this->profile->userinfo[userid]. 
I changed that to my userid and it worked! Now I just need to figure out the right way to call for the user profile id! Thanks everyone!

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

Quote:
Originally Posted by Warlord View Post
HOLY CRAP! I'm almost there! I've been working on this for like a week and I was almost ready to give up but now I'm ALMOST THERE!

The problem was the SQL query was returning no results because apparently this line of code doesn't work the way I thought it did.

PHP Code:
.$this->profile->userinfo[userid]. 
I changed that to my userid and it worked! Now I just need to figure out the right way to call for the user profile id! Thanks everyone!
Okay, apparently it does work the way I thought it did, I just had removed the extra " because I thought it was wrong. I still don't quite understand why it should be there but it seems to work now! Woohoo!

For anyone who's interested in what the code looked like that finally ended up working, here it is.

PHP Code:
$blocklist array_merge($blocklist, array(
    
'resume' => array(
        
'class' => 'Resume',
        
'title' => 'Resume',
        
'hook_location' => 'profile_left_last'
    
)
));

class 
vB_ProfileBlock_resume extends vB_ProfileBlock
{
  var 
$template_name 'memberinfo_block_resume';
  function 
confirm_empty_wrap()
  {
    return 
false;
  }
  function 
confirm_display()
  {
    return (
$this->block_data['resume'] != '');
  }
    function 
prepare_output($id ''$options = array())
{
    global 
$db;
    
$sql$db->query_read("SELECT * FROM " TABLE_PREFIX "formresults WHERE title = 'Resume' AND userid=".$this->profile->userinfo[userid]."");

            
$test "<div>";
            while(
$result mysql_fetch_array($sql))
            {
$test .= $result['output'];  
            }
            
$test .= "</div>";


    
$this->block_data['resume'] = $test;
  }

Reply With Quote
  #121  
Old 01-13-2010, 11:40 PM
Warlord's Avatar
Warlord Warlord is offline
 
Join Date: Jan 2002
Location: TN, USA
Posts: 668
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there something else you have to do to add more pages? When I repeat the steps I did to create the first tab the new tab I create replaces the first tab I created instead of appearing next to it.
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 06:15 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.04682 seconds
  • Memory Usage 2,377KB
  • 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
  • (7)bbcode_code
  • (10)bbcode_php
  • (7)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
  • (3)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (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