Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-18-2010, 07:57 PM
Rogue_SSEi Rogue_SSEi is offline
 
Join Date: Sep 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Plugin variable not showing in postbit data

Background:
I've created a userfield which contains the number of times a forum member has won an award (in this case an oven mitt). I'm trying to display a graphic in postbits for each time the winner has won. So if a member has won 3 oven mitts then the field
contains 3 and it should display the graphic 3 times. I've written some plugin code that creates a variable with an oven mitt image. I did this because I was unable to use a for loop in the postbit template.

Here is the plugin code that creates the oven mitt image data:

Code:
global $vbulletin;

if ($vbulletin->userinfo['userid'] == 1)
{
$ovenmittcount =  $vbulletin->userinfo['field12'];

$ovenmitts = "";

for ($loopcount=1; $loopcount<=$ovenmittcount; $loopcount+=1)
 {
  $ovenmitts = $ovenmitts . '<img src="http://www.badbeatspoker.net/images/isopmitt.jpg">';
}

}
This code works and has the desired effect of creating 3 oven mitts (the userfield is set to 3). I've set the plugin to only work for me so I didn't interfere with members on the board until I have it working. I've tested the plugin by placing the $ovenmitts variable in the forumdisplay template and it posted the image fine.

In forumdisplay this code shows the image correctly:

Code:
<center>
$random_banner[$random_number]
$ovenmitts
</center>
The issue is when I put the $ovenmitts variable in the postbit template to place the image amongst the other postbit data. It never displays like it can't find the variable.

I've tried setting the plugin to work in global_start and a variety of other showthread and postbit hooks with no joy.


This is the code I'm using in postbit:

Code:
<if condition="$post['field12']">
$ovenmitts
</if>
Any clues as to what I'm doing wrong?
Reply With Quote
  #2  
Old 03-18-2010, 09:58 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think the problem is that unless the variable is declared global (where it's set and where the template is eval'ed), it will be undefined and so will appear to be 0. That's a problem when doing what you're doing - you pretty much need to go in to the code to see what's going on, and find out where the template is eval'ed and where your hook is executed. In the case of postbit it looks like the template is used in includes/class_postbit.php in the function construct_postbit around line 304. I see that just above that is the "postbit_display_complete" hook, so probably the easiest thing would be to try using that hook.
Reply With Quote
  #3  
Old 03-19-2010, 12:29 PM
Rogue_SSEi Rogue_SSEi is offline
 
Join Date: Sep 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I tried that hook per you suggestion and it still doesn't display. Is there a way to declare my ovemitts variable global? I've tried putting global in front of it as the first line of the plugin like so:

Code:
global $ovenmitts;
That didn't seem to work either.

Do I need to declare this as global in the class_postbit.php file?
Reply With Quote
  #4  
Old 03-19-2010, 01:24 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...sorry, I guess I was wrong about something, just don't know what it is. There's no reason to edit class_postbit.php if putting it in the pluging didn't work.

So let's see - maybe that's not really where the template is used. You could try just putting an "$ovenmitts = something or other" in a plugin in using postbit_display_complete just to see if that's the right place. Are you sure "$post['field12']" is the right condition? If not, try taking the condition out temporarily.
Reply With Quote
  #5  
Old 03-19-2010, 01:32 PM
Rogue_SSEi Rogue_SSEi is offline
 
Join Date: Sep 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

the condition is right because I can put some random text in the the if statement and that prints as long as there is data in the field. The plugin code is correct because I can use the variable in forumdisplay and it works fine.

I thought it was a scope issue but I would have thought putting it in global_start would solve that. As a side note I noticed the random_banner code which posts an ad banner in forumdisplay correctly also does not display in the postbit template.

I've removed the conditional in the postbit template just to make sure and still nothing. It is like the variable is blank.
Reply With Quote
  #6  
Old 03-19-2010, 01:36 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, I know you'd have to have a "global" where the template is eval'ed (if it's in a function call), but it could be that the place I mentioned is not the right place for that template.

Sorry. Maybe someone else knows?

--------------- Added [DATE]1269010062[/DATE] at [TIME]1269010062[/TIME] ---------------

...oh, I did think of one thing - your plugin uses $vbulletin->userinfo['field12'] but I think you'd want $post['field12'], right?
Reply With Quote
  #7  
Old 03-19-2010, 02:48 PM
Rogue_SSEi Rogue_SSEi is offline
 
Join Date: Sep 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The plugin generates the proper image into the $ovenmitts variable. I confirmed this by putting the variable into the forumdisplay template and it shows properly. I also did a couple diagnostic print statements in the plugin to make sure the $ovenmittcount varialbe was getting the correct number from the field12 variable.

Either the $ovenmitts varialbe is getting wiped, isn't scoped correctly or I'm not calling it correctly to display in the postbit template. I'm just not sure where to go from here.

I appreciate your help though
Reply With Quote
  #8  
Old 03-23-2010, 08:12 PM
Rogue_SSEi Rogue_SSEi is offline
 
Join Date: Sep 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Anyone else have some ideas that I can try?
Reply With Quote
  #9  
Old 03-24-2010, 11:08 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, well, I have another one - use $bbuserinfo['ovenmitts'] instead of $ovenmitts to get rid of the scoping issue. I think $bbuserinfo is the same as $vbulletin->userinfo, and I don't know where $bbuserinfo gets set, so it's possible you might have to set $vbulletin->userinfo['ovenmitts'] in the plugin and use $bbuserinfo['ovenmitts'] in the template. (If someone wants to explain more about the use of those, I'd like to know).

Anyway, it may not be the "correct" thing to do but I think it will work (assuming scoping is the issue).
Reply With Quote
  #10  
Old 04-01-2010, 12:38 PM
Rogue_SSEi Rogue_SSEi is offline
 
Join Date: Sep 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'll give it a shot. Thanks
Reply With Quote
Reply


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 02:21 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.06764 seconds
  • Memory Usage 2,256KB
  • Queries Executed 11 (?)
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
  • (4)bbcode_code
  • (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
  • (10)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_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