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] Hooks and Plugins
calorie
Join Date: May 2003
Posts: 2,804

 

Show Printable Version Email this Page Subscription
calorie calorie is offline 06-11-2005, 10:00 PM

In hooks_vbulletin.xml you will see things like the following:
Code:
	<hooktype type="general">
		<hook>global_start</hook>
		<hook>global_complete</hook>
The hooktype is just a unigue name for the hook tags within. The hook tags refer specifically to PHP code in the vB files.

The PHP code in the vB files looks like the following:
Code:
	($hook = vBulletinHook::fetch_hook('global_start')) ? eval($hook) : false;
Note how global_start is in a hook tag in hooks_vbulletin.xml and also in the vB PHP code.

To make a plugin hooked to global.php, you create an XML file as follows:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<plugins>
	<plugin active="1" devkey="Name" product="vbulletin">
		<title>Your Title</title>
		<hookname>global_start</hookname>
		<phpcode><![CDATA[//
// START PHP CODE

$foo = "bar";

// END PHP CODE
//]]></phpcode>
	</plugin>
</plugins>
The place in vB PHP code where your global_start plugin runs is where the following occurs in global.php:
Code:
	($hook = vBulletinHook::fetch_hook('global_start')) ? eval($hook) : false;
Basically, you make plugins via XML and your plugins hook to vB PHP code
via <hookname>hook_name</hookname> from the plugins,
which needs to match the fetch_hook('hook_name') in the vB PHP code,
which needs to match <hook>hook_name</hook> in hooks_vbulletin.xml.

You can even make a plugin that hooks to multiple vB PHP files as follows:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<plugins>
	<plugin active="1" devkey="Name1" product="vbulletin">
		<title>Your Title1</title>
		<hookname>global_start</hookname>
		<phpcode><![CDATA[//
// START PHP CODE1

$foo = "bar";

// END PHP CODE1
//]]></phpcode>
	</plugin>
	<plugin active="1" devkey="Name2" product="vbulletin">
		<title>Your Title2</title>
		<hookname>forumhome_start</hookname>
		<phpcode><![CDATA[//
// START PHP CODE2

$bar = "foo";

// END PHP CODE2
//]]></phpcode>
	</plugin>
</plugins>
This latter example runs the first batch of PHP code where the following occurs in global.php:
Code:
($hook = vBulletinHook::fetch_hook('global_start')) ? eval($hook) : false;
And runs the second batch of PHP code where the following occurs in index.php:
Code:
($hook = vBulletinHook::fetch_hook('forumhome_start')) ? eval($hook) : false;
Again, note how <hookname>hook_name</hookname> in the XML plugin
matches fetch_hook('hook_name') in the vB PHP code
matches <hook>hook_name</hook> in hooks_vbulletin.xml.

Further readings...

What is a hook:

- https://vborg.vbsupport.ru/showpost....9&postcount=11

How to make a plugin:

- https://vborg.vbsupport.ru/showpost....5&postcount=14

How to add a new hook location:

- https://vborg.vbsupport.ru/showpost....01&postcount=1
Reply With Quote
  #2  
Old 06-22-2005, 10:57 AM
ojay ojay is offline
 
Join Date: Apr 2005
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

the devkeys in the opening plugin tags mustn't be equal
Reply With Quote
  #3  
Old 06-22-2005, 09:27 PM
calorie calorie is offline
 
Join Date: May 2003
Posts: 2,804
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay, thanks, updated.
Reply With Quote
  #4  
Old 06-23-2005, 12:20 AM
Qualia Qualia is offline
 
Join Date: Jan 2003
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

calorie, Thank you for explaining that. I had someone tell me what a hook was and I kind of got my brain wrapped around the idea, but you finished off the explaination really well. I'm a visual thinker and the way you explained how this will work was good for me.
Reply With Quote
  #5  
Old 06-23-2005, 03:21 AM
calorie calorie is offline
 
Join Date: May 2003
Posts: 2,804
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks. KirbyDE was helping me to understand, along with the authors of the other posts I listed, so I'm glad that you found it useful, and that I got to "pay it forward."
Reply With Quote
  #6  
Old 06-23-2005, 09:02 AM
Christine's Avatar
Christine Christine is offline
 
Join Date: Oct 2001
Location: PA
Posts: 472
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks calorie -- nice job!
Reply With Quote
  #7  
Old 06-25-2005, 10:52 AM
flup's Avatar
flup flup is offline
 
Join Date: Jan 2002
Location: Maastricht, NL
Posts: 872
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I still don't understand much about the plugin and hooks... somebody should write a dutch how-to (Floris maybe?)
Reply With Quote
  #8  
Old 07-07-2005, 05:52 PM
Highlander65 Highlander65 is offline
 
Join Date: Mar 2005
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are there restrictions on what can go inside the
Code:
//Start PHP Code

//End PHP Code
For example:
  • Can we use a simple include or require statement for large code sections or functions?
  • Do we have length restrictions?
  • Can we make new SQL queries?
  • Is there any PHP code that can't be used?
  • Is there any PHP code that SHOULDN'T be used (different then can't)?


Stuff like that...
Thanks!
Reply With Quote
  #9  
Old 08-01-2005, 06:17 AM
ToraTora! ToraTora! is offline
 
Join Date: Nov 2001
Posts: 255
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have ran into several roadblocks on this new plugin situation and it is frustrating to say the least.
Entering in SQL queries seem to work, but eval codes for template calls (even by the new standard like error templates) cause errors.

I am pretty sure it is user error on my end, but what would be really nice to see for once is a real life example of a mysql plugin-template exchange within a plugin so we have a general idea of what needs to be done in order to make it work properly.

Ok, starting to get the hang of it. I still prefer the old way of simply creating a include script to handle all of my hacks, but I can also see where the plugin manager will be beneficial for many areas such as a seperate front page with left, middle and right columns similar to the old Nuke class system.

Quote:
Originally Posted by Highlander65
Are there restrictions on what can go inside the
Code:
//Start PHP Code

//End PHP Code
For example:
  • Can we use a simple include or require statement for large code sections or functions?
  • Do we have length restrictions?
  • Can we make new SQL queries?
  • Is there any PHP code that can't be used?
  • Is there any PHP code that SHOULDN'T be used (different then can't)?


Stuff like that...
Thanks!
Most of the PHP code does work, but forget old functions such as the bbcode_parse or things along that nature.

The SQL queries will work as well, but you have to use the new format which was posted by VBLuke earlier, in which Keir created a document on those new settings.

A example of what I did with just a very elementary and simple condition within a plugin was this:

Code:
if ($vbulletin->userinfo['userid'] == 1){ 

echo "You are the admin and this should load a template"; 
eval('print_output("' . fetch_template('FORUM_STANDOFF') . '");'); 
} 

else 

{ 
echo "Well that sucked didnt it?"; 

}
Which worked. As long as I have that basis and get re-familiarized with many of the new variables, things should be pretty well back to normal within the plugin system, rather than creating a include script for my own created hacks.
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 01:22 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.04897 seconds
  • Memory Usage 2,284KB
  • Queries Executed 22 (?)
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
  • (10)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (8)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
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete