PDA

View Full Version : How to modify a function (PHP) between hooks


NolF
06-07-2007, 10:26 AM
Ok hi
I'm trying to write my first product, and it would be a small extension to the thank you hack... Is a very small thing and can be achieve by just changing a line in the code, but I wanted to do it by using the product system... Things is I don't exactly know exactly how

to begin with the thing I want to modify is
function can_delete_all_thanks()
{
global $vbulletin;

($hook = vBulletinHook::fetch_hook('post_thanks_function_ca n_delete_all_thanks_start')) ? eval($hook) : false;

if ($vbulletin->userinfo['usergroupid'] == '6')
{
return true;
}

($hook = vBulletinHook::fetch_hook('post_thanks_function_ca n_delete_all_thanks_end')) ? eval($hook) : false;

return false;
}

and it would basically be to change "if ($vbulletin->userinfo['usergroupid'] == '6')" into
if (is_member_of($vbulletin->userinfo['usergroupid'], explode("|", $vbulletin->options['post_thanks_who_delete_all'])))
(pS: options['post_thanks_who_delete_all'] is an option created by the modification which is used to insert the usergroups)

[See attachment for the whole modification]

I', not sure if I'm being clear enough... I just can figure out what to put in the hooks to make the thing work...

I hope someone can lend me just few mins to teach me how to do it ^^
Thank you mates

harmor19
06-07-2007, 10:56 AM
If the function you posted doesn't have any extra code you can comment out the statement.

In the first hook add
/*



In the second hook add
*/
if (is_member_of($vbulletin->userinfo['usergroupid'], explode("|", $vbulletin->options['post_thanks_who_delete_all'])))
{
return true;
}

Dismounted
06-07-2007, 11:43 AM
Nice workaround, I wouldn't have ever though of that.

NolF
06-07-2007, 02:36 PM
I had tried that idea /* */ problem is you get an error message at evaluation :( (see attachment) obviously those two lines are the ones related to the hooks ^^

Besides that I couldn't think of anything else. Any other solution?

I really appreciate the help :)

harmor19
06-07-2007, 06:42 PM
In the second hook add


if ($vbulletin->userinfo['usergroupid'] == '6')
{
return false;
}

if (is_member_of($vbulletin->userinfo['usergroupid'], explode("|", $vbulletin->options['post_thanks_who_delete_all'])))
{
return true;
}

Brad
06-07-2007, 07:06 PM
Why not just place this in the first hook location?

if (is_member_of($vbulletin->userinfo['usergroupid'], explode("|", $vbulletin->options['post_thanks_who_delete_all'])))
{
return true;
}

1) If it returns true the code below it doesn't matter anyway.
2) usergroupid 6 is the admin group so there is no real reason to work around that code. Either way it's sitting there doing nothing (assuming usergroupid 6 is in $vbulletin->options['post_thanks_who_delete_all'])

The work around is nice but it won't play well in an enviroment using multiple products.

NolF
06-08-2007, 11:17 AM
THANK YOU ALOT!!!!!!!!!!!!!!
Both solutions work perfectly ^^ Thank you guys ^^

Carnage
06-09-2007, 03:29 AM
well, you could always change the value of usergroup id to say 'a' in the first hook then change it back in the second.

1st hook

if ($vbulletin->userinfo['usergroupid'] == '6')
{
$vbulletin->userinfo['usergroupid'] = 'a'
}


2nd hook


if ($vbulletin->userinfo['usergroupid'] == 'a')
{
$vbulletin->userinfo['usergroupid'] = '6';
}

if (is_member_of($vbulletin->userinfo['usergroupid'], explode("|", $vbulletin->options['post_thanks_who_delete_all'])))
{
return true;
}