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)

Marco van Herwaarden 06-15-2005 07:50 AM

A Plug-In is the code that uses a Hook to attach itself to exisitng code.

Revan 06-15-2005 08:34 AM

Quote:

Originally Posted by Live Wire
hacking it, as if you add it to the plugin area, it has to call a query just to call that line.

Not true. I tried adding 5 plugins to the showthread all with useless variable definitions, and it did not call any additional queries.

dreck 06-18-2005 05:40 AM

Thanks Brad

deathemperor 06-25-2005 02:41 PM

When adding new plugin, there's a input field name 'Developer Key' . Do you know what it does, Brad ? the strange thing is that I installed 2 vb3.5 board, one has it but the another doesn't

Edit: it shows when you enabled debug mode

dwh 06-29-2005 10:34 PM

Quote:

Originally Posted by MarcoH64
A Plug-In is the code that uses a Hook to attach itself to exisitng code.

I think I get it. So it's like "including" some code in a certain place in the code? Is that all??

I thought it was going to be more of a standardized method of calling certain functions.

Like if you want to start a new thread each time someone registers, instead of copying all the code around creating a new thread you just call build_new_post() (which surprisingly wasn't enough in vb 3.07). Or for a custom PM every time someone reaches 100 posts you call build_new_pm().

It sounds like this is very different than I was expecting.

Marco van Herwaarden 06-30-2005 07:37 AM

You can see a Plugin as an externally definable include.

What you are talking about has nothing to fo with Plugins, but with standard functions offered, and maybe with approaching this as OOP classes.

dwh 06-30-2005 03:13 PM

Quote:

Originally Posted by MarcoH64
You can see a Plugin as an externally definable include.

What you are talking about has nothing to fo with Plugins, but with standard functions offered, and maybe with approaching this as OOP classes.

Thanks for explaining it.

To tell the truth, I'm pretty disappointed by this. It sounds like adding a ton of complexity to something as simple as inserting a bit of code in a file. This might actually make upgrades worse. Includes need to happen at the right place. I'd rather look at the code on one page when upgraded to see if the placement has to change. Now if there are 3 mods working on a similar piece of code, it will be much harder to get a feel of the flow of the code. As it is, with regular code, to follow the logic you need to look at all the included files. I've found that to be quite a pain several times, but there it's understandable. I dunno. Maybe it will all work out, but I'm wondering if this is such a good thing...

What's the big benefit? Just to make mods easier to install for newbies?

(Just in case this comes off wrong, I'm not trying to say this in a negative manner or just to nag...I also want to check if I'm understanding this properly and give feedback about it. As always, I want it clear that I love vb!)

sketch42 08-09-2005 03:40 AM

ok im a bit confused at how these hooks work.. i mean i understand the basics of it but i think i need a bit more explanation

now say i wanted to add my code into /admincp/user.php
and i want to modify this area

PHP Code:

// ###################### Start Edit Access #######################
if ($_REQUEST['do'] == 'editaccess')
{
        if (!
can_administer('canadminpermissions'))
        {
                
print_cp_no_permission();
        }

        
$vbulletin->input->clean_array_gpc('r', array(
                
'userid' => TYPE_INT
        
));

        
$user $db->query_first("SELECT username, options FROM " TABLE_PREFIX "user WHERE userid = " $vbulletin->GPC['userid']);

        
$accesslist $db->query_read("SELECT * FROM " TABLE_PREFIX "access WHERE userid = " $vbulletin->GPC['userid']);

        
//echo '<h1>$db->numrows($accesslist) = ' . $db->num_rows($accesslist) . '<br />user.hasaccessmask = ' . ($user['options'] & $vbulletin->bf_misc_useroptions['hasaccessmask'] ? 'yes' : 'no') . '</h1>';

        
while ($access $db->fetch_array($accesslist))
        {
                
$accessarray[$access['forumid']] = $access;
        }

        
print_form_header('user''updateaccess');
        
construct_hidden_code('userid'$vbulletin->GPC['userid']);

        
print_table_header($vbphrase['edit_access_masks'] . ": <span class=\"normal\">$user[username]</span>"20);
        
print_description_row($vbphrase['here_you_may_edit_forum_access_on_a_user_by_user_basis']);
        
print_cells_row(array($vbphrase['forum'], $vbphrase['allow_access_to_forum']), 0'thead', -2);
        
print_label_row('&nbsp;''
                <input type="button" value="' 
$vbphrase['all_yes'] . '" onclick="js_check_all_option(this.form, 1);" class="button" />
                <input type="button" value=" ' 
$vbphrase['all_no'] . ' " onclick="js_check_all_option(this.form, 0);" class="button" />
                <input type="button" value="' 
$vbphrase['all_default'] .'" onclick="js_check_all_option(this.form, -1);" class="button" />
        '
); 

so the closest hook i could find is this
PHP Code:

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

which is 20 lines above
so would i need to do this?
PHP Code:

       ($hook vBulletinHook::fetch_hook('useradmin_update_save')) ? eval($hook) : false;

        
// save data
        
$userid $userdata->save();
        if (
$vbulletin->GPC['userid'])
        {
                
$userid $vbulletin->GPC['userid'];
        }

        
// #############################################################################
        // now do the redirect

        
if ($vbulletin->GPC['modifyavatar'])
        {
                
define('CP_REDIRECT'"usertools.php?do=avatar&amp;u=$userid");
        }
        else if (
$vbulletin->GPC['modifyprofilepic'])
        {
                
define('CP_REDIRECT'"usertools.php?do=profilepic&amp;u=$userid");
        }
        else
        {
                
define('CP_REDIRECT'"user.php?do=modify&amp;u=$userid. ($userdata->insertedadmin '&insertedadmin=1' ''));
        }

        
print_stop_message('saved_user_x_successfully'$user['username']);
}

// ###################### Start Edit Access #######################

BLAH BLAH BLAH CUSTOM PHP CODE 

or am i way off base?

dwh 08-15-2005 10:22 AM

Quote:

Originally Posted by Fusion
Actually, that's an excellent idea.

Has there been any traction on this idea? Does vb think of doing this in a future version?

DJ RRebel 09-09-2005 09:07 PM

yeah ... I'd have to agree that most of the hacking I've done and would like to do involves calling extra fields in the database ... I haven't really looked into it yet, but it would seem that it would make alot of sense to have hooks at the end of some select statements.

... or better yet, have "replacement hooks" for some queries ... where the default querry would be used ... but if there was an active hook for that location, that segment would be replaced. Although I'm guessing this 2nd option would make you have to change your hook after upgrading if the original query required changes.

Anyhow ... I guess I should try a Plug-in or two before I make too many more suggestions! lol


All times are GMT. The time now is 08:49 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.03621 seconds
  • Memory Usage 1,778KB
  • 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
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)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