PDA

View Full Version : [HOW TO - vB4] Adding a New Tab in Member Profile


Dylanblitz
02-13-2010, 10:00 PM
If you are using anything above vB4.0.8 then refer to cellarius' updated article.
https://vborg.vbsupport.ru/showthread.php?p=2214470

I haven't seen a tutorial on doing this and I had to do it for a mod of mine, so I figured I would share. It is actually quite a bit easier to do in vb4 then it was before.

You will need 4 templates and 2 plugins. You could reduce it down to 2 templates but mine is used for distribution so I have to account for all versions.

First Template: This will create the tab next to About Me, Friends, etc

(my_data_tab)
<dd<vb:if condition="$selected_tab == 'test'"> class="selected"</vb:if>><a id="test-tab" href="{vb:raw relpath}#test" onclick="return tabViewPicker(this);">Test</a></dd>Where the text is red you can either leave it or replace it with your own reference. Just make sure it is the same throughout.

Second Template: The data you want to show.

(my_data_data)
<div id="view-test" class="<vb:if condition="$selected_tab == 'test'">selected_view_section<vb:else />view_section</vb:if>">
<div class="blockbody">
<div class="blockrow">
<ul class="friends_list floatcontainer">
{vb:raw new_user_data}
</ul>
</div>
</div>
</div>Same thing here, change the text in red to match the previous template.

Third Template: This will create the tab next to About Me, Friends, etc (4.0.8+)

(my_data_tab_408)
<style>
#test'-tab, #test'-tab a:hover {height:25px; display:inline; background-color:transparent; margin:0px; padding:0px; text-align:center; border:none;}
a:hover#test'-tab {background:transparent;}
</style>

<dd<vb:if condition="$selected_tab == 'test''"> class="userprof_module" <vb:else /> class="userprof_moduleinactive"</vb:if>><a id="test'-tab" href="{vb:raw relpath}?tab=test'#test'-content" onclick="return tabViewPicker(this);">Test</a></dd>Where the text is red you can either leave it or replace it with your own reference. Just make sure it is the same throughout.

Fourth Template: The data you want to show (4.0.8+).

(my_data_data_408)
<div id="view-test'-content" class="<vb:if condition="$selected_tab == 'test''">selected_view_section<vb:else />view_section</vb:if>">
<div class="blockbody">
<div class="blockrow">
<ul class="friends_list floatcontainer">
{vb:raw new_user_data}
</ul>
</div>
</div>
</div>Same thing here, change the text in red to match the previous template.



Now the first plugin
Hook Location: member_build_blocks_start
Title: Whatever you want to call it
Plugin Code


if ($vbulletin->versionnumber < "4.0.8")
{
$templater = vB_Template::create('my_data_tab');
} else {
$templater = vB_Template::create('my_data_tab_408');
}

$templater->register('selected_tab', $selected_tab);
$templater->register('relpath', $relpath);

if ($vbulletin->versionnumber < "4.0.2")
{
$template_hook['profile_left_last'] .= $templater->render();
} else {
$template_hook['profile_tabs_last'] .= $templater->render();
}


//Do your processing to get your data ready here.
$new_user_data = "Data for the new tab";


if ($vbulletin->versionnumber < "4.0.8")
{
$templater = vB_Template::create('my_data_data');
} else {
$templater = vB_Template::create('my_data_data_408');
}

$templater->register('selected_tab', $selected_tab);
$templater->register('new_user_data', $new_user_data);

if ($vbulletin->versionnumber < "4.0.2")
{
$template_hook['profile_left'] .= $templater->render();
} else {
$template_hook['profile_tabs'] .= $templater->render();
}
Second plugin
Hook Location: cache_templates
Title: Whatever you want to call it

if (THIS_SCRIPT == 'member')
{
if ($vbulletin->versionnumber < "4.0.8")
{
$cache[] = 'my_data_tab';
$cache[] = 'my_data_data';
} else {
$cache[] = 'my_data_tab_408';
$cache[] = 'my_data_data_408';
}
}
And the result
https://vborg.vbsupport.ru/attachment.php?attachmentid=112330&stc=1&d=1266180760

Sarcoth
02-15-2010, 08:02 PM
Thank you. I do a lot of stuff with custom profiles and this code is nice to have.

/subscribed.

I'll now look into seeing how I can get certain profilefields to appear on the new tab.

ageurtse
02-18-2010, 05:24 PM
is this article written for the latest vb 4.0.2 or is this for a different version ?

i now had my mod working on vb 4.0.1 and on vb 4.0.2 this mod is working but on every tab there is a link of the tab.

so if your solution works on 4.0.2 i have to rewrite my mod :(

i don't like it that vbulletin changes on every release the way things should be done.
so a mod can't be use on several version's

Dylanblitz
02-18-2010, 06:21 PM
is this article written for the latest vb 4.0.2 or is this for a different version ?

i now had my mod working on vb 4.0.1 and on vb 4.0.2 this mod is working but on every tab there is a link of the tab.

so if your solution works on 4.0.2 i have to rewrite my mod :(

i don't like it that vbulletin changes on every release the way things should be done.
so a mod can't be use on several version's

I wrote it on 4.0.0 and had others test on 4.0.1. I haven't downloaded 4.0.2 yet.
I'm going to have to bite the bullet and install it on my production box. 4.0.0 only half works for me on my dev because the CMS wont allow me to use a port other then 80. 4.0.1 doesn't work at all on my dev. I'm sure 4.0.2 will be worse for me heh.

Dylanblitz
02-19-2010, 08:16 PM
ageurtse,
They changed the template hook names. I found the new hooks to use and it works fine on my test system. I updated the code in the original post.
Let me know if you have problems with it. Wish they would at least keep the old ones for a while and let us know they're going to be gone.

as7apcool
02-24-2010, 09:45 PM
thanks 4 great work !

derfelix
02-28-2010, 03:43 AM
very nice.. you saved my day.. !!!
just one thing..
I thought the $show array does NOT need to be registered...
$templater->register('show', $show);
havent tested here yet.. but usually on other pages it does not...

F.

Dylanblitz
02-28-2010, 04:49 AM
I wasn't sure, I haven't seen a list of what is auto registered, so I usually just register everything I need in the template.

derfelix
02-28-2010, 05:16 AM
well as far as I know (assume) ....
(not sure read somewhere, but sorry, cant remember where)
magic globals dont need registering,
like $template_hook, $show, $vboptions, $stylevar, $vbphrase
not sure with $template_hook, but thats easy to test..
there might be others.. would be interesting if someone knew where to find a complete list!!

F.

PS: check class_core.php line: 3959 and following: public function render
$template_hook and $show are 'magic globals'

Dylanblitz
02-28-2010, 05:57 AM
Yeah would be nice to have a list of everything. I removed the $show registration from the code, thanks for the input :)

losedude
03-14-2010, 11:07 PM
How would one add tabs to a custom page instead of profile page?

Dylanblitz
03-15-2010, 12:14 AM
I don't remember where I found it but there is a article or mod that shows how to add tabs to a custom page for 3.x that still works for 4.x
I just looked but I couldn't find it this time around, not sure where it's at.

Link14716
03-16-2010, 10:39 AM
You forgot to mention that you should cache the templates used by making a plugin on the hook cache_templates containing:
if (THIS_SCRIPT == 'member') {
$cache[] = 'my_data_tab';
$cache[] = 'my_data_data';
}

Pretty good guide otherwise.

Dylanblitz
03-17-2010, 06:06 AM
You forgot to mention that you should cache the templates used by making a plugin on the hook cache_templates containing:
if (THIS_SCRIPT == 'member') {
$cache[] = 'my_data_tab';
$cache[] = 'my_data_data';
}

Pretty good guide otherwise.

Thanks, I didn't think about the cache, I added it :)

Leonard
05-01-2010, 04:47 PM
Hey....thanks for the tutorial. Very useful!

Just one question for anyone out there who may know if this is possible. I'm trying to link directly to a tab in the member.php. By default, it will always load up the first tab. I want it to load a specific tab. How would I do this? If it is possible?

Leonard

--------------- Added 1272737152 at 1272737152 ---------------

Worked it out...

You can move the hook to member_complete and manually set the $selected_tab variable to make it select your custom tab.

mokujin
05-01-2010, 05:11 PM
Do you know how to load the tab as AJAX like facebook? :) THanks

identitas
05-24-2010, 07:47 PM
manually set the $selected_tab variable to make it select your custom tab.

How do i do that?

Vaupell
08-13-2010, 07:17 PM
tx, worked in first go..

jeejuh
09-09-2010, 12:36 AM
How do i do that?


Change the first plugin to...

Hook Location: member_complete
Plugin Code - vb4.0.2
$selected_tab = "test";

$templater = vB_Template::create('my_data_tab');
$templater->register('selected_tab', $selected_tab);
$templater->register('relpath', $relpath);
$template_hook['profile_tabs_last'] .= $templater->render();


//Do your processing to get your data ready here.
$new_user_data = "Data for the new tab";


$templater = vB_Template::create('my_data_data');
$templater->register('selected_tab', $selected_tab);
$templater->register('new_user_data', $new_user_data);
$template_hook['profile_tabs'] .= $templater->render();

gurler
11-01-2010, 05:35 PM
is it possible to move ALBUM widget to the tabs ?

Dylanblitz
11-04-2010, 08:59 AM
is it possible to move ALBUM widget to the tabs ?

I don't see why not. You could find the album code and replicate how they do it with plugins.

I can't look at it right now though, trying to figure out what css changes they made in 4.0.8 that makes non default tabs look jacked up.

noppid
11-04-2010, 06:09 PM
I don't see why not. You could find the album code and replicate how they do it with plugins.

I can't look at it right now though, trying to figure out what css changes they made in 4.0.8 that makes non default tabs look jacked up.

There's a tracker entry about it. http://tracker.vbulletin.com/browse/VBIV-9832

I'm hoping that they will implement the suggestions from DP if enough people vote. (I have no clue how that works.) Otherwise we have to bloat mods with an added template for css and a hook.

Dylanblitz
11-05-2010, 06:26 PM
There's a tracker entry about it. http://tracker.vbulletin.com/browse/VBIV-9832

I'm hoping that they will implement the suggestions from DP if enough people vote. (I have no clue how that works.) Otherwise we have to bloat mods with an added template for css and a hook.

Yeah, hopefully they take the suggestion and implement it. I changed the code, it adds 2 templates if it's something you distribute. Otherwise you can do it still with 2 templates and 2 plugins.

Might not be the best way but it's how I got it to work heh.

Hall of Famer
11-12-2010, 07:01 AM
looks really cool, oh btw do you know if its possible to add iframes tags in members new profile tabs so that it links to an external site of mine without directing users away from the forum? If so, can you please show me an example of how to do this?

Dylanblitz
11-12-2010, 05:43 PM
looks really cool, oh btw do you know if its possible to add iframes tags in members new profile tabs so that it links to an external site of mine without directing users away from the forum? If so, can you please show me an example of how to do this?

Should be fairly easy. I would put this in your plugin code. Replace the red text with your link.

if ($vbulletin->versionnumber < "4.0.8")
{
$templater = vB_Template::create('my_data_tab');
} else {
$templater = vB_Template::create('my_data_tab_408');
}

$templater->register('selected_tab', $selected_tab);
$templater->register('relpath', $relpath);

if ($vbulletin->versionnumber < "4.0.2")
{
$template_hook['profile_left_last'] .= $templater->render();
} else {
$template_hook['profile_tabs_last'] .= $templater->render();
}

//Do your processing to get your data ready here.
$new_user_data = "<iframe src=\"http://www.yoursite.com/your_page.html\" width=\"550\" height=\"500\" frameborder=\"0\">\n";
$new_user_data .= "<a href=\"http://www.yoursite.com/your_page.html\" target=\"ResourceWindow\">Your browser doesn't support iframe content.\n";
$new_user_data .= "Click here to go directly to included content.</a>\n";
$new_user_data .= "</iframe>\n";

if ($vbulletin->versionnumber < "4.0.8")
{
$templater = vB_Template::create('my_data_data');
} else {
$templater = vB_Template::create('my_data_data_408');
}

$templater->register('selected_tab', $selected_tab);
$templater->register('new_user_data', $new_user_data);

if ($vbulletin->versionnumber < "4.0.2")
{
$template_hook['profile_left'] .= $templater->render();
} else {
$template_hook['profile_tabs'] .= $templater->render();
}

Hall of Famer
11-13-2010, 10:04 PM
Thank you so much for this reply, I will give a try on my forum soon. ^^

FreshFroot
12-01-2010, 06:05 PM
Anyone got this working for 3.8.x?

Lynne
12-01-2010, 06:46 PM
Anyone got this working for 3.8.x?
There is an article in the vB3 forum for this for 3.8.x. It's by Calorie.

Hippy
12-04-2010, 01:25 AM
There's a tracker entry about it. http://tracker.vbulletin.com/browse/VBIV-9832

I'm hoping that they will implement the suggestions from DP if enough people vote. (I have no clue how that works.) Otherwise we have to bloat mods with an added template for css and a hook.

thanks for the info ..

this has bothered me since vb4.0.8 came out ..

prevented me from upgrading ..
lol

I just couldn't do it

I may now tho after seeing that bug reported

thanks to all that help here at vb.org
your all much appreciated

hurricane_sh
12-31-2010, 01:02 PM
Anyone tried this on VB 4.1.0? My tab was added successfully, but the content is blank. I can find the content in the browser source file, but it doesn't show in the tab.

Edit: never mind, I had a typo.

BirdOPrey5
01-10-2011, 12:33 AM
The two 408 templates have an error in the code, there's an extra single quote (') after the word "test" in the conditionals. You'll get an error if you try to save the templates without fixing it. Once fixed it worked great on my 4.0.8.

Edit- Actually there's quite a few extra single quotes in 408 data tab as well breaking the style, it seems there's an extra single quote after each red test in the code. Once they are all removed it works well.

computer22
04-09-2011, 09:18 PM
I have a problem with my profile tab, when loading it it's displaying it like in the picture about the red line. When I click the "button" then it turns right into the correct color and format (below red line)

http://images.glua.info/?di=113023873364

Does anyone know what could cause that?

cellarius
05-23-2011, 02:04 PM
Yep, the profile tabs template has changed a little in previous versions.

I would advise not to create a specific template for your tab - template nr. 1 (my_data_tab) in the tutorial is actually unnecessary. I call the standard memberinfo_tab instead and prefill the necessary variables. Saves you one template. PHP for this looks like that:

if (isset($vbulletin->GPC['tab']))
{
$selected_tab = $vbulletin->GPC['tab'];
}
$blockinfo['title'] = "Test Title";
$blockid = "test";
$taburl = $memberurl = fetch_seo_url('member', $prepared) . "&amp;tab=test#test";

$templater = vB_Template::create('memberinfo_tab');
$templater->register('selected_tab', $selected_tab);
$templater->register('relpath', $relpath);
$templater->register('blockinfo', $blockinfo);
$templater->register('blockid', $blockid);
$templater->register('taburl', $taburl);
$template_hook['profile_tabs_last'] .= $templater->render();

Also, the hook where the plugin needs to reside is member_complete, not member_build_blocks_start. Else the direct link to the tab by URL (member.php?123-testuser&tab=test#test) will not work properly.

Pandemikk
06-14-2011, 02:34 AM
I can't get this to work. I used the above's PHP code for the plugin and the my_data_data_408 for the template.

The tab shows up fine but when I click it nothing is shown in the box.

cellarius
06-14-2011, 05:15 AM
Have you seen my post directly over yours?

Pandemikk
06-14-2011, 06:20 AM
Yes, I used your PHP code for the plugin and the my_data_data_408 for the template.

Pandemikk
06-15-2011, 03:32 PM
Really need some help with this. It's driving me nuts that vB still hasn't a decent article on these member profile tabs.

Pandemikk
06-20-2011, 04:24 AM
++++ you +++++++ then.

cellarius
06-20-2011, 06:54 AM
I'm sure that this childish behaviour is going to get you LOTS of help.

Pandemikk
06-20-2011, 05:43 PM
I already tried mature and exasperated behavior to no avail. Didn't have much hope for childish, but it did lift my spirits a bit which is always a plus.

Anyway, this thread is really outdated or just full of bad code. I've managed to clean it up a little but still can not get the tab to show via its AJAX call. Going to the tab via direct link shows up fine. It's weird. Has anybody got this working yet? I'd assume so.

cellarius
06-20-2011, 07:26 PM
Yes, I have. I described what I did different to firstpost in this thread.

Pandemikk
06-22-2011, 04:09 AM
And I followed that to no avail. Perhaps you left out some information?

Lynne
06-22-2011, 03:12 PM
And I followed that to no avail. Perhaps you left out some information?
It is very hard to troubleshoot something when you have not posted a single line of code that you are using. If you want help, post your *exact* code (in code tags), with the hook location, and any other needed information.

Pandemikk
06-23-2011, 01:33 AM
Sorry for that.


Hook Location: member_complete

// ###################### TAB DATA ######################
if (isset($vbulletin->GPC['tab']))
{
$selected_tab = $vbulletin->GPC['tab'];
}
$blockinfo['title'] = 'Battle Statistics';
$blockid = 'bbebs_stats';
$taburl = $memberurl = fetch_seo_url('member', $prepared) . "&amp;tab=bbebs_stats#bbebs_stats";

$templater = vB_Template::create('memberinfo_tab');
$templater->register('selected_tab', $selected_tab);
$templater->register('relpath', $relpath);
$templater->register('blockinfo', $blockinfo);
$templater->register('blockid', $blockid);
$templater->register('taburl', $taburl);
$template_hook['profile_tabs_last'] .= $templater->render();

// ###################### MAIN SCRIPT ######################
if ($selected_tab == 'bbebs_stats')
{
// Irrelevant code goes here

$templater = vB_Template::create('bbebs_memberinfo_data');
$templater->register('selected_tab', $selected_tab);
$templater->register('prepared', $prepared);
$templater->register('user', $user);
$templater->register('stats_bits', $stats_bits);
$template_hook['profile_tabs'] .= $templater->render();
}
?>

It's not exactly like cellarius's, of course. Because his example fails to include any PHP code to render the actual data. The tabs worked perfectly with his code, though.

Template: bbebs_memberinfo_data


<div id="view-bbebs_stats-content" class="<vb:if condition="$selected_tab == 'bbebs_stats'">selected_view_section<vb:else />view_section</vb:if>">
<div class="blockbody">
<!-- Irrelevant Code -->
</div>
</div>

Pandemikk
06-27-2011, 05:12 AM
Boy oh boy. I really did miss that awesome vB.org support!

cellarius
06-27-2011, 06:01 AM
Boy oh boy. I really do miss the times when people were asking clear questions and giving relevant information and not whining and complaining all the time! Honestly, what's the matter with you?

What exactly is the problem you're having? Can you put it in one or more sentences so a person not deterred by your attitude could understand what exactly does not work for you?

The tab shows up fine but when I click it nothing is shown in the box.
In what box? What do you expect to be shown?

The code you posted works perfectly fine in vB4.1.4. It creates the tab, as it should, and the tab is accessible from within the profile and it can be directly accessed by url. See screenshot - the URL entered takes me directly to the tab.


130441

Whatever you want to show in the tab is not covered in this tutorial, and you snipped every code out that would be relevant for showing anything in whatever box as "Irrelevant".

Pandemikk
06-27-2011, 08:29 AM
The irrelevant code can be anything. An echo construct. Anything. It does not show. I'm sorry that you feel that my information is not clear enough, but I am not sure how much more clear I can be.

The box that the tab shows when clicked does not display anything unless accessed directly via the link. Clicking on the tab does not show anything.

cellarius
06-27-2011, 10:36 AM

Lynne
06-27-2011, 01:43 PM

cellarius
06-27-2011, 04:12 PM

Pandemikk
06-27-2011, 08:49 PM

Lynne
06-27-2011, 09:39 PM
I do not understand your comments about an echo statement. An echo will not put the text where you want it - it will put it wherever it feels like it (if at all). You need to assign the text that you want output to the $template_hook['profile_tabs'].

What does your template "bbebs_memberinfo_data" look like?

Pandemikk
06-27-2011, 10:37 PM

cellarius
06-28-2011, 03:52 AM

Pandemikk
06-28-2011, 04:43 AM

cellarius
06-28-2011, 04:52 AM
I've already written to the author of this tutorial, but received no answer so far. If he is no longer around or does not want to actualize the firstpost with the information already presented in this thread, I will post a new version myself.

Pandemikk
06-28-2011, 06:25 PM
Good on you. An update is definitely needed.

cellarius
06-29-2011, 07:41 PM