Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2009, 05:32 PM
dutchbb dutchbb is offline
 
Join Date: Nov 2003
Posts: 899
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 04-12-2009, 06:15 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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"
Reply With Quote
  #3  
Old 04-13-2009, 03:17 PM
dutchbb dutchbb is offline
 
Join Date: Nov 2003
Posts: 899
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
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.
Reply With Quote
  #4  
Old 04-13-2009, 03:28 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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";  

Reply With Quote
  #5  
Old 04-13-2009, 03:38 PM
dutchbb dutchbb is offline
 
Join Date: Nov 2003
Posts: 899
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 04-13-2009, 05:21 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 04-13-2009, 11:41 PM
Brother Malachi Brother Malachi is offline
 
Join Date: Jun 2008
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
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"
Reply With Quote
  #8  
Old 04-14-2009, 03:39 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by hammerhead24 View Post
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....}}}
Reply With Quote
  #9  
Old 04-14-2009, 03:29 PM
dutchbb dutchbb is offline
 
Join Date: Nov 2003
Posts: 899
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #10  
Old 04-14-2009, 06:49 PM
nexialys
Guest
 
Posts: n/a
Default

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...
Reply With Quote
Reply

Thread Tools
Display Modes

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 03:36 PM.


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.05853 seconds
  • Memory Usage 2,283KB
  • 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_code
  • (8)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (9)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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete