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] Write Plug-ins/Hooks (https://vborg.vbsupport.ru/showthread.php?t=82625)

Logikos 02-01-2006 08:13 PM

Quote:

Originally Posted by Brad
Second thing, hooks will not get you into every corner of the code. Some things will always be done best with a hack. For example if you are looking to add something but need to query the db for some extra data and want to avoid and extra query (in other words you are going to modify an existing one with a join or such) forget it and hack it in, there are no hooks that let you modify existing queries.

This quote should be updated:

You can join into Queries now:
Lets say you wanted to show some custom info on each post. In 3.0x you would modify an exsiting query. Its the biggest query in showthread.php. Starts like "$posts = $db->query_read("".

You would have to add you own SELECT statments like table.username AS username, and JOIN statements like LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = post.userid). You don't need to do that anymore.

If you wanted to do this is 3.5 using hooks you can. Open showthread.php and find around line: 923-924. You should see...

PHP Code:

$hook_query_fields $hook_query_joins '';
(
$hook vBulletinHook::fetch_hook('showthread_query')) ? eval($hook) : false

Under that you will see a very large query, in that query you will notice the variables, $hook_query_fields, and $hook_query_joins. Thats your ticket into this query.

You would simple go into the plugins, add new plugin and write it like so: Plugin Name is "showthread_query"
PHP Code:

$hook_query_fields ",tablename.rowname AS newname";
$hook_query_joins "LEFT JOIN " TABLE_PREFIX "tablename AS newtable ON(tablename.rowname = post.rowname)"

Tips:
Just remember to start "$hook_query_fields" variable with a comma.
You can also add conditions around this which is great I think. Example:
PHP Code:

if ($var == $var2)
{
        
$hook_query_fields ",tablename.rowname AS newname";
        
$hook_query_joins "LEFT JOIN " TABLE_PREFIX "tablename AS newtable ON(tablename.rowname = post.rowname)";


Hope this helps some advance users. :)

Eagle Creek 10-24-2006 11:11 AM

Can't this thread be sticky :-)?

LaCN 05-22-2007 07:28 PM

Help..

I got this part in my plugin:

Quote:

Originally Posted by plugin
if ( ($vbulletin->options['LaCN_enable']) && ($vbulletin->userinfo[usergroupid] == '0') )
{
$guestIC = $vbulletin->options['LaCN_guest_text'];
}


eval('$LaCN_message = "' . fetch_template('LaCN_message') . '";');

in the templates I have this:

Quote:

Originally Posted by template forum_home
blabla
$LaCN_message
blabla

Quote:

Originally Posted by template LaCN_message
blabla
$guestIC
blabla


the template shows.
But $guestIC won't show :(

What's wrong ?

Wired1 05-23-2007 07:50 PM

Re-read the instructions. Your code that calls the hook is wrong, and you need to enter the hook into the xml file that holds the hooks.

LaCN 05-23-2007 08:29 PM

Before I make an xml file, I'm building it first as if it was already installed ;)
The plugin is set in the global_start hook, so that's fine.

the plugin itself has to add the to be used templated to the cache, that's what I've used that eval line for

Lea Verou 08-13-2007 04:59 PM

Can one add hooks in plugins (for add-ons)?
I guess not, but I don't lose anything by asking...

Opserty 08-13-2007 07:37 PM

Quote:

Originally Posted by Michelle (Post 1316661)
Can one add hooks in plugins (for add-ons)?
I guess not, but I don't lose anything by asking...

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

Another article by Brad lol :)

Lea Verou 08-14-2007 07:48 AM

Quote:

Originally Posted by Opserty (Post 1316774)

I read the whole thread but there is nothing mentioned about hooks in plugins.

Opserty 08-14-2007 09:15 PM

Quote:

Originally Posted by Michelle (Post 1317095)
I read the whole thread but there is nothing mentioned about hooks in plugins.

Have you tried it out anyway? I don't really see the point of including a hook in your plugin code if people want to develop modifications for it then they could just edit the plugin code. I guess it is your choice but it wouldn't be something I would do.

Lea Verou 08-14-2007 09:24 PM

Quote:

Originally Posted by Opserty (Post 1317637)
Have you tried it out anyway? I don't really see the point of including a hook in your plugin code if people want to develop modifications for it then they could just edit the plugin code. I guess it is your choice but it wouldn't be something I would do.

In fact, I want to develop a "bridge" for users that have one of my modifications and one I'm planning to release soon. I don't want them to edit the plugin code, because they'll have to do it over and over again on each update.
So hooks would really come in handy here.


All times are GMT. The time now is 08:02 PM.

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.01296 seconds
  • Memory Usage 1,752KB
  • 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
  • (3)bbcode_php_printable
  • (8)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)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