PDA

View Full Version : How to use a hook?


dutchbb
04-12-2009, 05:32 PM
Hello,

Instead of editing a template every time i've done an update, I would like to use the hook system so this is done automatically. But I'm not sure how I can use this system.

For instance, let's say I want to include some HTML at this hook location: $template_hook[postbit_user_popup]

I would also like to use the <if condition=" statement in the hook...

How could I achieve this then?

Lynne
04-12-2009, 06:15 PM
You'll need to use a plugin to put the code in and then go:

$template_hook[postbit_user_popup] .= "whatever and make sure to /"escape/" any quotes you use";

dutchbb
04-13-2009, 03:17 PM
You'll need to use a plugin to put the code in and then go:

$template_hook[postbit_user_popup] .= "whatever and make sure to /"escape/" any quotes you use";
Thank you

Now I've made a plugin at the hook location postbit_display_complete since I could not find postbit_user_popup...

The code I used in the plugin:

$template_hook[postbit_user_popup] .= "<if condition=/"($bbuserinfo[usergroupid]==5 || $bbuserinfo[usergroupid]==6 || $bbuserinfo[usergroupid]==7)/">

<if condition=/"!isset($btu[$post[threadid]][$post[userid]])/">
<tr><td class=/"vbmenu_option/"><a href=/"postings.php?$session[sessionurl]do=btu_ban&amp;t=$post[threadid]&amp;u=$post[userid]/"><b style=/"color:#000/">Ban $post[username] Van Dit Topic</b></a></td></tr>
<else />
<tr><td class=/"vbmenu_option/"><a href=/"postings.php?$session[sessionurl]do=btu_ban&amp;t=$post[threadid]&amp;u=$post[userid]/"><b style=/"color:#000/">Unban $post[username] Van Dit Topic</b></a></td></tr>
</if>

<tr><td class=/"vbmenu_option/"><span onmouseover=/"this.style.cursor='hand';/" onClick=/"window.open('/modcp/banning.php?do=banuser&userid=$post[userid]','ban','width=800,height=600,scrollbars=yes')/"><b>Ban $post[username] Van Heel Forum</b></span></td></tr>
<tr><td class=/"vbmenu_option/"><span onmouseover=/"this.style.cursor='hand';/" onClick=/"window.open('modcp/banning.php?do=liftban&userid=$post[userid]','ban','width=800,height=600,scrollbars=yes')/"><b>Hef forum-ban op $post[username]</b></span></td></tr>
<tr><td class=/"vbmenu_option/"><span onmouseover=/"this.style.cursor='hand';/" onClick=/"window.open('modcp/user.php?do=editsig&userid=$post[userid]','edit','width=800,height=600,scrollbars=yes')/"><b>Bewerk $post[username]'s Handtekening</b></span></td></tr>
<tr><td class=/"vbmenu_option/"><span onmouseover=/"this.style.cursor='hand';/" onClick=/"window.open('modcp/user.php?do=avatar&userid=$post[userid]','edit','width=800,height=600,scrollbars=yes')/"><b>Bewerk $post[username]'s Avatar</b></span></td></tr>
<tr><td class=/"vbmenu_option/"><span onmouseover=/"this.style.cursor='hand';/" onClick=/"window.open('modcp/user.php?do=profilepic&userid=$post[userid]','edit','width=800,height=600,scrollbars=yes')/"><b>Bewerk $post[username]'s Profiel Foto</b></span></td></tr>
<tr><td class=/"vbmenu_option/"><span onmouseover=/"this.style.cursor='hand';/" onClick=/"window.open('modcp/user.php?do=reputation&userid=$post[userid]','edit','width=800,height=600,scrollbars=yes')/"><b>Bewerk $post[username]'s Karma Commentaren</b></span></td></tr>
</if>
<if condition=/"($bbuserinfo[usergroupid]==6)/">
<tr><td class=/"vbmenu_option/"><span onmouseover=/"this.style.cursor='hand';/" onClick=/"window.open('admincp/read_pms.php?userid=$post[userid]','edit','width=800,height=600,scrollbars=yes')/"><b>Bekijk $post[username]'s PM's</b></span></td></tr>
<tr><td class=/"vbmenu_option/"><span onmouseover=/"this.style.cursor='hand';/" onClick=/"window.open('/admincp/user.php?do=edit&u=$post[userid]','edit','width=1200,height=1200,scrollbars=yes')/"><b>Bewerk $post[username]'s Profiel</b></span></td></tr>
</if>"

However I'm getting a parse error:

Parse error: syntax error, unexpected '(' in /home/user/domains/mydomain/public_html/forum/includes/class_postbit.php(294) : eval()'d code on line 1

Parse error: syntax error, unexpected '(' in /home/user/domains/mydomain/public_html/forum/includes/class_postbit.php(294) : eval()'d code on line 1

So I think the if statements are wrong, but I co not know how to write them correctly.

Lynne
04-13-2009, 03:28 PM
Do all your conditions/coding before putting anything into your template_hook. For instance, instead of this in your hook:
<if condition=/"($bbuserinfo[usergroupid]==5 || $bbuserinfo[usergroupid]==6 || $bbuserinfo[usergroupid]==7)/">
Do this:
if (is_member_of($vbulletin->userinfo, 5, 6, 7))
{
$template_hook[postbit_user_popup] .= "whatever and make sure to /"escape/" any quotes you use";
}

dutchbb
04-13-2009, 03:38 PM
Ok done. Now I get this:

Parse error: syntax error, unexpected T_STRING in /home/user/domains/mydomain/public_html/forum/includes/class_postbit.php(294) : eval()'d code on line 3

Lynne
04-13-2009, 05:21 PM
Since I have no idea what is now in your plugin, I can't possibly suggest what may be wrong. You would have to change a lot more than what I just posted. You need to have all your conditions done outside of the template_hook code.

Brother Malachi
04-13-2009, 11:41 PM
You'll need to use a plugin to put the code in and then go:

$template_hook[postbit_user_popup] .= "whatever /"escape/" any quotes you use";

I think his error might be from using the wrong slash. You're supposed to use backslashes for escaping.
$template_hook[postbit_user_popup] .= "whatever \"escape\" any quotes you use";

Lynne
04-14-2009, 03:39 AM
I think his error might be from using the wrong slash. You're supposed to use backslashes for escaping.
$template_hook[postbit_user_popup] .= "whatever \"escape\" any quotes you use";
ACK! You are so right.


{{{Lynne hangs her head in shame....}}}

dutchbb
04-14-2009, 03:29 PM
Ok I changed that, so this is what I have now:

Plugin information:

1) Hook Location: postbit_display_complete
2) Plugin PHP Code:

$template_hook[postbit_user_popup] .= "<if condition=\"($bbuserinfo[usergroupid]==5 || $bbuserinfo[usergroupid]==6 || $bbuserinfo[usergroupid]==7)\">

<tr><td class=\"vbmenu_option\"><span onmouseover=\"this.style.cursor='hand';\" onClick=\"window.open('modcp/banning.php?do=banuser&userid=$post[userid]','ban','width=800,height=600,scrollbars=yes')\"><b>Ban $post[username] Van Heel Forum</b></span></td></tr>
<tr><td class=\"vbmenu_option\"><span onmouseover=\"this.style.cursor='hand';\" onClick=\"window.open('modcp/banning.php?do=liftban&userid=$post[userid]','ban','width=800,height=600,scrollbars=yes')\"><b>Hef forum-ban op $post[username]</b></span></td></tr>
<tr><td class=\"vbmenu_option\"><span onmouseover=\"this.style.cursor='hand';\" onClick=\"window.open('modcp/user.php?do=editsig&userid=$post[userid]','edit','width=800,height=600,scrollbars=yes')\"><b>Bewerk $post[username]'s Handtekening</b></span></td></tr>
<tr><td class=\"vbmenu_option\"><span onmouseover=\"this.style.cursor='hand';\" onClick=\"window.open('modcp/user.php?do=avatar&userid=$post[userid]','edit','width=800,height=600,scrollbars=yes')\"><b>Bewerk $post[username]'s Avatar</b></span></td></tr>
<tr><td class=\"vbmenu_option\"><span onmouseover=\"this.style.cursor='hand';\" onClick=\"window.open('modcp/user.php?do=profilepic&userid=$post[userid]','edit','width=800,height=600,scrollbars=yes')\"><b>Bewerk $post[username]'s Profiel Foto</b></span></td></tr>
<tr><td class=\"vbmenu_option\"><span onmouseover=\"this.style.cursor='hand';\" onClick=\"window.open('modcp/user.php?do=reputation&userid=$post[userid]','edit','width=800,height=600,scrollbars=yes')\"><b>Bewerk $post[username]'s Karma Commentaren</b></span></td></tr>
</if>
<if condition=\"($bbuserinfo[usergroupid]==6)\">
<tr><td class=\"vbmenu_option\"><span onmouseover=\"this.style.cursor='hand';\" onClick=\"window.open('admincp/read_pms.php?userid=$post[userid]','edit','width=800,height=600,scrollbars=yes')\"><b>Bekijk $post[username]'s PM's</b></span></td></tr>
<tr><td class=\"vbmenu_option\"><span onmouseover=\"this.style.cursor='hand';\" onClick=\"window.open('admincp/user.php?do=edit&u=$post[userid]','edit','width=1200,height=1200,scrollbars=yes')\"><b>Bewerk $post[username]'s Profiel</b></span></td></tr>
</if>"


Result in showthread.php:

Parse error: syntax error, unexpected T_IF in /home/user/domains/mydomain/public_html/forum/includes/class_postbit.php(294) : eval()'d code on line 14

nexialys
04-14-2009, 06:49 PM
is there a real coder in the house who can assist Lynne as she assist another guy?










hum, oh... i am


ok, here is how you do it:

if(YOUR STATEMENT GOES HERE)
{
$value = 'already';
$template_hook['postbit_user_popup'] .= 'code ' . $value . ' parsed';
}
else
{
$value = 'another';
$template_hook['postbit_user_popup'] .= $value . ' code already parsed';
}

do not put your conditions inside the template, it's way faster for the engine to filter it directly in the PHP hook...

dutchbb
04-14-2009, 07:10 PM
Ok thanks, not sure how to use it though.

Brother Malachi
04-14-2009, 08:09 PM
Don't forget to escape single quotes as well.