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)

timetunnel 11-30-2005 03:45 AM

Hello.

How do you create a 'product' plugin file like the one at https://vborg.vbsupport.ru/showthread.php?t=99579

(see the code in Ted S's 'welcome hdr 4 0 6.zip' file download).

In the xml file contained in the zip file, it begins with the tags, '<product...>' then '<templates>', then '<plugins>', etc.

Was this coded by hand or is there a template that is used to create these types of xml files for importing into the vB Plugin system? I see how to create the <plugins> code using the vB Plugin Manager (Download) in AdminCP, but not the rest. I'd like to create a clean file for creating templates via this type of xml so when I create revisions for others, I can make it where they can 'import' the complete xml 'product/plugin' vs. using a 'txt' file download that says, 'Find' this, 'Add' that, etc.

Thanks in advance.

TyleR 11-30-2005 03:46 AM

Quote:

Originally Posted by timetunnel
Hello.

How do you create a 'product' plugin file like the one at https://vborg.vbsupport.ru/showthread.php?t=99579

(see the code in Ted S's 'welcome hdr 4 0 6.zip' file download).

In the xml file contained in the zip file, it begins with the tags, '<product...>' then '<templates>', then '<plugins>', etc.

Was this coded by hand or is there a template that is used to create these types of xml files for importing into the vB Plugin system? I see how to create the <plugins> code using the vB Plugin Manager (Download) in AdminCP, but not the rest. I'd like to create a clean file for creating templates via this type of xml so when I create revisions for others, I can make it where they can 'import' the complete xml 'product/plugin' vs. using a 'txt' file download that says, 'Find' this, 'Add' that, etc.

Thanks in advance.

it's coded by hand, I believe..atleast thats how i've coded mine thus far.

Marco van Herwaarden 11-30-2005 06:54 AM

You should not code Product/Plugin XML-files by hand. If you set the correct Product everywhere (new templates, phrases, settings,...) it will all be in the file when you export it.

timetunnel 12-01-2005 12:15 AM

Quote:

Originally Posted by MarcoH64
You should not code Product/Plugin XML-files by hand. If you set the correct Product everywhere (new templates, phrases, settings,...) it will all be in the file when you export it.

How? Is this done within vB AdminCP? If so, where? How to create e.g. a new template or phrases using the plugin manager (or wherever in vB) without coding by hand? How to '...set the correct Product everywhere...'? What is that?

Thanks in advance.

Cap'n Steve 12-01-2005 02:48 AM

<a href="showthread.php?t=92953" title="vBulletin.org Forum - Article 92953">This thread should answer all your questions.</a>

timetunnel 12-01-2005 03:21 AM

Thank you. Thank you. Thank you. This is just what I need to get more power out of this wonderful software.

HaMaDa4eVeR 01-31-2006 11:03 AM

Hello
I would like to use function.php file in my priavte plugins and I didn't find sutable Hook Location
I need to change this line :
PHP Code:

return $datefunc($format$timestamp_adjusted); 

with this :
PHP Code:


               $new
=$datefunc($format$timestamp_adjusted);
                
$new=preg_replace('/AM/''After Morining'$new);
$new=preg_replace('/PM/''P - M'$new);

        return  
$new


HaMaDa4eVeR 02-01-2006 01:13 PM

Is there any 1 can help me here

Cap'n Steve 02-01-2006 07:27 PM

Look in whatever function is contained in $datefunc. If that doesn't work you'll probably need to modify the code.

Marco van Herwaarden 02-01-2006 07:50 PM

Are AM & PM not defined by Phrases? Couldn't you just change the phrase?


EDIT: No it looks like this is not phrased

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.

Opserty 08-15-2007 11:12 AM

Fair enough, I don't see why that link I posted wouldn't work the same in a plugin. Just do the same but instead of writing the hook in the PHP file stick it in your plugin. No harm in trying if you haven't already done so :p

Did you get some kind of error or was it just not working?

Lea Verou 08-15-2007 11:21 AM

I didn't try it yet, as I didn't need it at the time (I need it today).
I'll try soon though and post what happened.

amnesia623 09-03-2007 04:53 AM

Is this tutorial current as of vb 3.6.8?

I'm looking for a plugin tutorial and wondered if this is still relavent

Birched 09-21-2007 03:42 PM

The advice by KirbyDE at the end of the main entry was BY FAR the most useful part for me, but yes, I believe it is all still relevant.

Hubbitus 09-24-2007 12:04 PM

At the beginning, thank you for the good basic guide.

But I'm not completely understudying how I can associate my hook with two or more "hookname" at once? E.g. "newreply_post_start", "newthread_post_start".
Quote:

Originally Posted by Brad (Post 663102)
Code:

<title>vB Category Icons</title>
<hookname>forumdata_start</hookname>


If I try this code:
Code:

<title>vB Category Icons</title>
<hookname>newreply_post_start</hookname>
<hookname>newthread_post_start</hookname>

I get hook, associated to "useradmin_edit_start", as I understood the first item at the list.

Is it the only way to make the fully copy of the code into a new hook and associate it with new hookname???

Opserty 09-24-2007 03:03 PM

This tutorial is old. You can add plugins through the AdminCP via the Plugin Manager.

I don't think it is possible to associate the same code to two hooks. Just copy the code over to a new plugin to create code for another hook.

Hubbitus 09-24-2007 06:00 PM

Quote:

Originally Posted by Opserty (Post 1346069)
This tutorial is old. You can add plugins through the AdminCP via the Plugin Manager.

Of cause, I known. But, I'm don't known how associate the same code to two hooks in this case too.

Quote:

Originally Posted by Opserty (Post 1346069)
I don't think it is possible to associate the same code to two hooks. Just copy the code over to a new plugin to create code for another hook.

If no other, "normal" way, off cause i do that. But I hope that someone will prompt more correct way.

hobeau 10-05-2007 04:28 PM

Hi, I just want to display a list of users who have posted on a thread at the top of the thread using the hook system. I'm brand new to VBulletin and was wondering if there is a good tutorial or documentation that would help. I've looked in the vb manual and it just has like 2 pages on writing plugins. Can anyone help?

wottech 05-05-2009 04:34 PM

Quote:

Originally Posted by Ken Iovino (Post 887950)
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)"



Is there a way to add WHERE and ORDER statements to this query as well, using hooks?


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.01756 seconds
  • Memory Usage 1,835KB
  • 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_code_printable
  • (7)bbcode_php_printable
  • (14)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
  • (29)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