vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How to use a hook? (https://vborg.vbsupport.ru/showthread.php?t=211015)

dutchbb 04-12-2009 05:32 PM

How to use a hook?
 
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:

PHP Code:

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


dutchbb 04-13-2009 03:17 PM

Quote:

Originally Posted by Lynne (Post 1789704)
You'll need to use a plugin to put the code in and then go:

PHP Code:

$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:

Code:

$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:

Code:

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:
PHP Code:

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

Do this:
PHP Code:

if (is_member_of($vbulletin->userinfo567)) 
{
$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:

Code:

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

Quote:

Originally Posted by Lynne (Post 1789704)
You'll need to use a plugin to put the code in and then go:

PHP Code:

$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.
PHP Code:

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


Lynne 04-14-2009 03:39 AM

Quote:

Originally Posted by hammerhead24 (Post 1790643)
I think his error might be from using the wrong slash. You're supposed to use backslashes for escaping.
PHP Code:

$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:

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:

Code:

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:

PHP Code:

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...


All times are GMT. The time now is 06:54 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.01277 seconds
  • Memory Usage 1,777KB
  • 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_code_printable
  • (8)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)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