Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-27-2011, 10:14 PM
radiofranky radiofranky is offline
 
Join Date: Jun 2011
Posts: 149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default how to set "hook location"?

Hi,
in the template no direct php code can be pasted. Therefore, you need to create a "plugin" if you want to execute a php script. But my question is how to figure out which hook location should I use?

For example, I want to add "total posts: total users:" to my header, above the logo img.

How do I do that?


Do I create a plugin and then? What hook location should I select? What happens if I can't find one just sounded right?

Thanks for the helps.


Code:
ob_start(); 
global $vbulletin, $db, $vbphrase; 
//Begin Forum Stats 
// forum stats start 
$numbersmembers = $db->query_first("SELECT COUNT(*) AS users,MAX(userid) AS max FROM " . TABLE_PREFIX . "user");
$numbermembers = number_format($numbersmembers['users']); 
$counter = $db->query_first("SELECT COUNT(postid) AS posts, COUNT(threadid) AS threads FROM " . TABLE_PREFIX . "post");
$totalposts=number_format($counter['posts']); 
$countthreads = $db->query_first("SELECT COUNT(*) AS threads FROM " . TABLE_PREFIX . "thread"); 
$totalthreads=number_format($countthreads['threads']); 
// forum stats end 

// total online start 
$datecut = TIMENOW - $vbulletin->options['cookietimeout']; 
$headerguests=$db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "session WHERE userid=0 AND lastactivity>$datecut");
$headerusers=$db->query_first("SELECT COUNT(DISTINCT(userid)) AS count FROM " . TABLE_PREFIX . "session WHERE " . TABLE_PREFIX . "session.userid>0 AND " . TABLE_PREFIX . "session.lastactivity>$datecut");
$headerguests=$headerguests[count]; 
$headerusers=$headerusers[count]; 
$totalonline=$headerguests+$headerusers; 
// total online end 

// get newest member name and userid start 
$getnewestmember=$db->query_first("SELECT userid, username FROM " . TABLE_PREFIX . "user WHERE userid=$numbersmembers[max]");
$newusername = $getnewestmember['username']; 
$newuserid = $getnewestmember['userid']; 
// get newest member name and userid end 

 //End Forum Status 
//SideBar - Begin forum Stats 
$sb_stats=' 
<table width="100%" align="center"> <tr> <td class="" align="left"> <div class="smallfont"> <strong>Number of Members: </strong> '.$numbermembers.'<br /> <strong>Total Threads: </strong>'. $totalthreads.'<br /> <strong>Total Posts: </strong>'. $totalposts.'<br /> <strong>Currently Online: </strong>'. $totalonline.'<br /> <br /> <strong>Newest Member:</strong> <a href="'.$vboptions[bburl].'/member.php?u='.$newuserid.'"><b>'.$newusername.'</b></a> </td> </tr> </table>'; 
//SideBar = End forum Status 
echo $sb_stats; 
$output=ob_get_contents(); 
ob_end_clean();
Reply With Quote
  #2  
Old 07-27-2011, 11:24 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's a good question, and I'm kind of curious to see if anyone else has an answer to this, because I really have a hard time imagining how it could be done without looking at the vb PHP code. In your case you want to add something to the header, so it has to be done before the header template is rendered. I happen to remember that a good hook location for that is parse_templates. I suppose if you didn't know that, you might search and find that the header template is rendered in the file includes/class_bootstrap.php around line 486, so you could then look at the code before that and notice at around line 414:

PHP Code:
($hook vBulletinHook::fetch_hook('parse_templates')) ? eval($hook) : false
which is the line that evaluates any plugin code using hook "parse_templates".

So anyway, if you're doing a lot of modifications I would recommend finding an editor that lets you search across a set of php files (I think notepad++ does that, and it's free), then have the vb source on your local computer so you can easily look at it when you need to figure something out.
Reply With Quote
  #3  
Old 07-28-2011, 02:10 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I always look at the list of plugins called when in debug mode (they are all shown in the bottom right corner). And, depending on if this is a page specific change or not, I would look at the php page itself and see what hooks are there.
Reply With Quote
  #4  
Old 07-28-2011, 06:22 AM
radiofranky radiofranky is offline
 
Join Date: Jun 2011
Posts: 149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

that's too much for me.. i guess i need to play vb a little more before I can grasp the idea

is there an easier way to display forum total post and total user number in the header section?
cheers

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

Quote:
Originally Posted by kh99 View Post
That's a good question, and I'm kind of curious to see if anyone else has an answer to this, because I really have a hard time imagining how it could be done without looking at the vb PHP code. In your case you want to add something to the header, so it has to be done before the header template is rendered. I happen to remember that a good hook location for that is parse_templates. I suppose if you didn't know that, you might search and find that the header template is rendered in the file includes/class_bootstrap.php around line 486, so you could then look at the code before that and notice at around line 414:

PHP Code:
($hook vBulletinHook::fetch_hook('parse_templates')) ? eval($hook) : false
which is the line that evaluates any plugin code using hook "parse_templates".

So anyway, if you're doing a lot of modifications I would recommend finding an editor that lets you search across a set of php files (I think notepad++ does that, and it's free), then have the vb source on your local computer so you can easily look at it when you need to figure something out.

thanks. But how did you figure out that this is where plugin code gets evaluated? Is there any documentation from vb or just by doing try and error?

what does {vb raw totalpost} menas? and how to use it in the templates?
If I see it in xyz template, can I use it in zzz template? I tried it, but with no luck so far. It seems is returning null.
Reply With Quote
  #5  
Old 07-28-2011, 06:57 AM
Badshah93 Badshah93 is offline
 
Join Date: Jun 2010
Location: India
Posts: 505
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by radiofranky View Post
that's too much for me.. i guess i need to play vb a little more before I can grasp the idea

is there an easier way to display forum total post and total user number in the header section?
cheers

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




thanks. But how did you figure out that this is where plugin code gets evaluated? Is there any documentation from vb or just by doing try and error?

what does {vb raw totalpost} menas? and how to use it in the templates?
If I see it in xyz template, can I use it in zzz template? I tried it, but with no luck so far. It seems is returning null.
You look to confused but that happens if it is ur first time.

{vb:raw totalpost} = $totalpost


First will start from VB3


For Ex:


Suppose i created a plugin:

Hook: forumhome_complete

Code:

Code:
$myvar = 2;

//and other things....

As you can see in plugin we assigned $myvar = 2,
so we can use $myvar variable in FORUMHOME template.

Now some question's comes in our mind:

1. can i use $myvar in other place like user profile.

Ans. No, because forumhome_complete plugin hook execute at homepage only. So you need to find a diff hook for it, you can use debug mode to get the right hook.



Now lets come to VB4

All the things will be same as in vb3, except few changes.


Hook: forumhome_complete

Code:

PHP Code:
$myvar 2;

//and other things....


vB_Template::preRegister('FORUMHOME',array('myvar' => $myvar));  //This line register myvar in FORUMHOME template. 

Now in FORUMHOME template u can use

Code:
{vb:raw myvar}


Read This article to know more about Registering variable's in templates.

Code:
https://vborg.vbsupport.ru/showthread.php?t=228078
Reply With Quote
  #6  
Old 07-28-2011, 08:26 PM
radiofranky radiofranky is offline
 
Join Date: Jun 2011
Posts: 149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the example.

Let's say I find {vb raw: totalpost} in FORUMHOME and I would like to use the same {vb raw: totalpost} in HEADER.

totalpost is a VB build-in variable. Is there a way to find out all the VB build-in variables and it's PHP location?

Where do I find which PHP file should I register with? and do I just add this line below FORUMHOME?
PHP Code:

vB_Template
::preRegister('FORUMHOME',array('totalpost' => $totalpost)); 
vB_Template::preRegister('HEADER',array('totalpost' => $totalpost));  //This line register myvar in FORUMHOME template. 
Reply With Quote
  #7  
Old 07-28-2011, 09:00 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

{vb raw: totalposts} is used in the template FORUMHOME, and that template is rendered at the end of forum.php. So we look in forum.php and see that there's code that calculates $totalposts, and later a line that registers $totalpost in that template. Now you want to use it in header, well, there's a problem. Header is included in every page, not just forum.php, but the code to calculate $totalposts is only in forum.php. So to make it work in the header you'd need to find the code in forum.php that does the calculations, copy it somewhere before the header template is rendered (like a plugin using hook parse_templates), then register the variable in the header template (and of course, insert it in the header template).

Now there's one problem with that - the code calculates the value for a specific forum, and not every page has just one specific forum associated with it. So what would you do in those cases? And what are you trying to do, do you want the value to display on all pages or do you just want to move it to a different location on the forum page?
Reply With Quote
  #8  
Old 07-28-2011, 09:36 PM
radiofranky radiofranky is offline
 
Join Date: Jun 2011
Posts: 149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

All I want is to display "total posts:" and "total users", just like in slickdeals.net which I believe they uses VB.

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

Isn't there a modification that does this already? (I thought I had seen others ask about doing this and then being pointed to a modification.)
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 02:26 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04152 seconds
  • Memory Usage 2,267KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (4)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete