vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Hook Question (https://vborg.vbsupport.ru/showthread.php?t=123428)

paul41598 08-08-2006 07:37 PM

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']);




Sean S 08-08-2006 07:43 PM

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?

paul41598 08-08-2006 07:45 PM

Just trying to add a if condition around it

if (!$_REQUEST['refer'])
{
code block here
{

Sean S 08-08-2006 07:51 PM

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.

paul41598 08-08-2006 07:54 PM

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']);

}



Sean S 08-08-2006 07:56 PM

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.

paul41598 08-08-2006 08:00 PM

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

Nxs 08-08-2006 08:08 PM

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

paul41598 08-08-2006 08:12 PM

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?

Sean S 08-08-2006 08:43 PM

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.


All times are GMT. The time now is 06:44 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.01242 seconds
  • Memory Usage 1,754KB
  • 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
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete