Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-08-2006, 07:37 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Hook Question

When you write an XML file and use plugin code at a certain hook location...does the code in your plugin execute before the hook location or after it?

Does your code run alongside the preexisting code in the PHP file, or does it replace it?

For example...if I had a xml file where I was trying to replace a certain chunk of code in the PHP file, how does that work?


Im trying to add a condition to this chunk of code without directly editing the file:

PHP Code:
if ($_REQUEST['do'] == 'sendtofriend' OR $_POST['do'] == 'dosendtofriend')
{
    
$forumperms fetch_permissions($threadinfo['forumid']);

    if (!(
$forumperms $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR !($forumperms $vbulletin->bf_ugp_forumpermissions['canemail']) OR (($threadinfo['postuserid'] != $vbulletin->userinfo['userid']) AND !($forumperms $vbulletin->bf_ugp_forumpermissions['canviewothers'])))
    {
        
print_no_permission();
    }

    
// check if there is a forum password and if so, ensure the user has it set
    
verify_forum_password($foruminfo['forumid'], $foruminfo['password']);


Reply With Quote
  #2  
Old 08-08-2006, 07:43 PM
Sean S's Avatar
Sean S Sean S is offline
 
Join Date: Jan 2004
Location: Chicago
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Personally I don't think that there is a way to edit a line or overwrite parts of it with hook/plugins.

Basically what you want to do is a file edit, and you should edit the php file. However, leave that as your last option and try to find another way of coding to get the same job done. If you can't find any, then you have to edit the php file.

Basically the hooks/plugins allow you to place a chunk of code within vbulletin's php files at certain predefined locations. You can't overwrite or replace lines with it, as far as I know.

May I ask what condition you are trying to add?
Reply With Quote
  #3  
Old 08-08-2006, 07:45 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just trying to add a if condition around it

if (!$_REQUEST['refer'])
{
code block here
{
Reply With Quote
  #4  
Old 08-08-2006, 07:51 PM
Sean S's Avatar
Sean S Sean S is offline
 
Join Date: Jan 2004
Location: Chicago
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So you want to add
PHP Code:
!$_REQUEST['refer'
to this part
PHP Code:
if ($_REQUEST['do'] == 'sendtofriend' OR $_POST['do'] == 'dosendtofriend'
?

If so, then I think you have to edit the php file.

Also have you tried putting the exact same code in the plugin and see if it works? So that you're plugin would look the exact same with that extra condition?

PHP Code:
if ($_REQUEST['do'] == 'sendtofriend' OR $_POST['do'] == 'dosendtofriend' OR !$_REQUEST['refer'])
{
    
$forumperms fetch_permissions($threadinfo['forumid']);

    if (!(
$forumperms $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR !($forumperms $vbulletin->bf_ugp_forumpermissions['canemail']) OR (($threadinfo['postuserid'] != $vbulletin->userinfo['userid']) AND !($forumperms $vbulletin->bf_ugp_forumpermissions['canviewothers'])))
    {
        
print_no_permission();
    }

    
// check if there is a forum password and if so, ensure the user has it set
    
verify_forum_password($foruminfo['forumid'], $foruminfo['password']);


not sure if that will work but give it a try.
Reply With Quote
  #5  
Old 08-08-2006, 07:54 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

no like this

PHP Code:
if (!$_REQUEST['refer']) 

if (
$_REQUEST['do'] == 'sendtofriend' OR $_POST['do'] == 'dosendtofriend')
{
    
$forumperms fetch_permissions($threadinfo['forumid']);

    if (!(
$forumperms $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR !($forumperms $vbulletin->bf_ugp_forumpermissions['canemail']) OR (($threadinfo['postuserid'] != $vbulletin->userinfo['userid']) AND !($forumperms $vbulletin->bf_ugp_forumpermissions['canviewothers'])))
    {
        
print_no_permission();
    }

    
// check if there is a forum password and if so, ensure the user has it set
    
verify_forum_password($foruminfo['forumid'], $foruminfo['password']);

}

Reply With Quote
  #6  
Old 08-08-2006, 07:56 PM
Sean S's Avatar
Sean S Sean S is offline
 
Join Date: Jan 2004
Location: Chicago
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

oh ok, then I don't know. Again try putting that whole thing in the plugin and see if it will work. If the plugin/hook location is called before that chunk of code, I'm guessing that it will work. But I'm not sure, sorry.
Reply With Quote
  #7  
Old 08-08-2006, 08:00 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

well ya, I tried placing the whole thing in the plugin at the right hook location, but no go. Oh well, file edit is the way to go
Reply With Quote
  #8  
Old 08-08-2006, 08:08 PM
Nxs's Avatar
Nxs Nxs is offline
 
Join Date: May 2004
Posts: 79
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yeah the code you hook replaces the hook - so to speak.

eg.

code line 1
code line 2
$hook = blahblah
code line 3
code line 4

Anything you put in the hook will execute between line 2 and line 3
Reply With Quote
  #9  
Old 08-08-2006, 08:12 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So Id almost have to make a new hook at the location I want it to execute. In which case, how do you release a new hook with ur hack?
Reply With Quote
  #10  
Old 08-08-2006, 08:43 PM
Sean S's Avatar
Sean S Sean S is offline
 
Join Date: Jan 2004
Location: Chicago
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

in that case it doesn't really matter whether you add another hook location in your file or just edit the php file and add in your code. Cause either way you are going to end up editting the php file.
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 12:39 AM.


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.04410 seconds
  • Memory Usage 2,273KB
  • Queries Executed 13 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • 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