vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   [How to] Add new/custom hook locations (https://vborg.vbsupport.ru/showthread.php?t=82703)

Brad 06-08-2005 10:00 PM

[How to] Add new/custom hook locations
 
This guide will teach you how to add your own hook locations to your scripts/default vBulletin source code. Note that I assume that you are working within the vBulletin.php files or you have included vBulletin's global.php.

Adding custom hook locations -

Method one:

See paul's thread here for the best method, if you are going to release your modification to the public this is the way you should go:

https://vborg.vbsupport.ru/showthread.php?t=83390

Method two:

All hooks listed in this drop down live in the .xml file located at /vbroot/includes/xml/hooks_vbulletin.xml

Find this bit of code at the very top of the file:

HTML Code:

<hooks>
       
        <hooktype type="admindata">
                <hook>admindata_start</hook>
                <hook>admindata_presave</hook>
                <hook>admindata_postsave</hook>
                <hook>admindata_delete</hook>
        </hooktype>


Looks simple eh? Heres what these tags do

<hooks> - anything between this tag and </hooks> will be included in the drop down

<hooktype type="name"> - The name of your hook group, you should group all common hooks under a group so you can find them quickly. Make sure you don't use a name already used by a default hooktype.

<hook> - The name of your hook, this must be the same as the hook's name in the php code

Here is an example of my .xml file, I added three custom hooks under a new hooktype:

HTML Code:

<hooks>
       
        <hooktype type="loo_custom">
                <hook>loo_custom1</hook>
                <hook>loo_custom2</hook>
                <hook>loo_custom3</hook>
        </hooktype>

The php code:

Adding a hook location to the php code is easy, just make sure you use the correct hook name! Use this bit of php anywhere after your call to global.php to call your custom hook. Also note that you must use the $hook var!

PHP Code:

($hook vBulletinHook::fetch_hook('hook_name')) ? eval($hook) : false

Here is an example of my custom hooks working in vBulletin's index.php file:

PHP Code:

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

($hook vBulletinHook::fetch_hook('forumhome_start')) ? eval($hook) : false;
(
$hook vBulletinHook::fetch_hook('loo_custom1')) ? eval($hook) : false;
(
$hook vBulletinHook::fetch_hook('loo_custom2')) ? eval($hook) : false;
(
$hook vBulletinHook::fetch_hook('loo_custom3')) ? eval($hook) : false

As you can see I added them right under a current hook, which mostly defeats the purpose of making custom hooks. But for this post they serve their purpose ;)

Now all you need to do is browse to your admincp's add new plug-in page and test your new hook location! I use this just to make sure it is working correctly:

PHP Code:

echo('Testing hook_name hook'); 

If that outputs its text above the vBulletin header then you are good to go!. :)

Floris 06-09-2005 04:16 PM

Great job, nice of you to share

Logikos 06-09-2005 05:51 PM

Very handy information

Creative Suite 06-09-2005 10:29 PM

it's ok with me , thank you

rjordan 06-10-2005 01:43 AM

If I might offer a suggestion... if were to add custom hooks in my code and upgrade my forums later, I would want to be able to find my hooks I entered easily so I can re-enter them if needed.

My suggestion:

Instead of doing this:
PHP Code:

($hook vBulletinHook::fetch_hook('hook_name')) ? eval($hook) : false

I would do this instead:
PHP Code:

($customhook vBulletinHook::fetch_hook('hook_name')) ? eval($customhook) : false

Of course, there is absolutely nothing wrong the other way, but this way I can search for $customhook and know exactly what was added instead of searching through all of the $hook lines.

Only a thought I would share. Noone has to use it! :nervous:

deathemperor 06-21-2005 10:16 AM

Ok I think I forgot it but what are hooks used for ? (in the programming term, not end-users)

something like this line:

PHP Code:

($hook vBulletinHook::fetch_hook('newreply_start')) ? eval($hook) : false

what does it mean ?

Brad 06-21-2005 10:23 AM

Hooks are used to execute raw php code in the files.

Basicly that bit of code does this:

Checks if hooks are on in vboptions, checks if any hooks exist for that hook location.
If any hooks are found and enabled your custom php code is set to the $hook var
If there is php code set to $hook it is sent to eval for the php code to be executed, if not nothing is done and php moves on to the rest of the code in the file.

deathemperor 06-21-2005 01:02 PM

many thanks, I understand it now and is writing my hack.

Paul M 06-21-2005 03:51 PM

If you are adding custom hooks, you might want to read this as well.


https://vborg.vbsupport.ru/showthread.php?t=83390

Highlander65 07-07-2005 03:26 PM

Quote:

Originally Posted by rjordan
If I might offer a suggestion... if were to add custom hooks in my code and upgrade my forums later, I would want to be able to find my hooks I entered easily so I can re-enter them if needed.

You could also just use "My_" (or any tag) in front of all your custom hook names. Then just search for your tag.


All times are GMT. The time now is 06:44 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.01276 seconds
  • Memory Usage 1,755KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_html_printable
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete