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

Reply
 
Thread Tools Display Modes
  #1  
Old 10-06-2013, 03:40 PM
thunderclap82 thunderclap82 is offline
 
Join Date: Nov 2008
Posts: 305
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default HTML Code in Widget

I have AJAX Chat installed on my site, and there is code someone shared that allows the number of users using chat, as well as listing the names, that appear in the What's Going On section. (See here.) It involves a plugin and template change and, once done, works. I'd like to use this code in a Widget on the front page but no matter how I alter the code it doesn't work in the widget. The code for the templates is:

Code:
<!-- chat users -->
<div id="wgo_onlineusers" class="wgo_subblock section">
<h3 class="blocksubhead"><img src="{vb:stylevar imgdir_misc}/users_online.png" alt="Users In Chat" />{vb:raw num_chatting} Users In Chat</h3>

<div>
<p>{vb:raw chat_userlist}</p>
</div>
</div>
<!-- end chat users -->
Basically, in the widget, it doesn't convert the num_chatting or chat_userlist. Is it because widgets can't handle these calls? Is there a way to get this code working in a static HTML widget?
Reply With Quote
  #2  
Old 10-06-2013, 04:00 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You probably need to preRegister the variables to the template you're using. In the code on that page there are calls to vB_Template:reRegister() for FORUMHOME and navbar, but you need to change it (or add calls) to register to your template.
Reply With Quote
  #3  
Old 10-06-2013, 07:00 PM
thunderclap82 thunderclap82 is offline
 
Join Date: Nov 2008
Posts: 305
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
You probably need to preRegister the variables to the template you're using. In the code on that page there are calls to vB_Template:reRegister() for FORUMHOME and navbar, but you need to change it (or add calls) to register to your template.
I created a new template called "ajax_chat_widget" and added the HTML code to that:

Code:
				<h3 class="blocksubhead"><img src="{vb:stylevar imgdir_misc}/users_online.png" alt="Users In Chat" />{vb:raw num_chatting} Users In Chat</h3>
				<div>
					<p>{vb:raw chat_userlist}</p>
				</div>
I had created the plug-in as instructed:

PHP Code:
global $vbulletin;   

$results $vbulletin->db->query_read_slave("SELECT userName FROM ajax_chat_online");   
while (
$row $vbulletin->db->fetch_array($results))   
    
$chat_userlist[] = $row['userName'];   
if (
is_array($chat_userlist))  
{  
    
$chat_userlist implode(', '$chat_userlist);   
    
$vbulletin->db->free_result($results);   
}  
else  
{  
    
// set $chat_userlist to a "no one chatting" message if you want, or leave blank.
    
$chat_userlist '';  
}  
vB_Template::preRegister('FORUMHOME', array('chat_userlist' => $chat_userlist)); 
And added a second preRegister:

PHP Code:
vB_Template::preRegister('ajax_chat_widget', array('chat_userlist' => $chat_userlist)); 
I then created the Static HTML Widget and have it configured to use the template "ajax_chat_widget", and in the HTML code box I add "a". If I leave it blank the widget isn't displayed at all.

The widget now appears, but only says "Users in Chat". Looking at the code it should show the number of users (i.e. 2 Users in Chat) as well as list their names, but it doesn't.

Thoughts?
Reply With Quote
  #4  
Old 10-06-2013, 07:26 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Instead of a static html widget, try creating a php direct execution widget and use code like this:

Code:
$templater = vB_Template::create('ajax_chat_widget');
$output = $templater->render();

Also, those instructions you linked to show another plugin using hook global_bootstrap_init_start that calculates the number chatting, so you'd need to add another preRegister call there as well.

When configuring the php direct execution widget, there's a field for cache time. If you set it to 0 it will execute every time someone accesses a page that shows the widget, but if you set it to 1 (the minimum allowed), then the widget will only update once per minute. You can choose which one works for you. Setting it to 0 probably isn't a problem since you aren't doing much in your widget code, and the database queries in the plugin are being done each time anyway.
Reply With Quote
  #5  
Old 10-06-2013, 08:12 PM
thunderclap82 thunderclap82 is offline
 
Join Date: Nov 2008
Posts: 305
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Appreciate the help. I enabled the other plug-in and added the preRegister for ajax_chat_widget in that plugin, and now the number of people chatting shows but the list of users is still empty. I even attempted to add

PHP Code:
vB_Template::preRegister('ajax_chat_widget', array('chat_userlist' => $chat_userlist)); 
to the other template but that didn't work.
Reply With Quote
  #6  
Old 10-06-2013, 08:44 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...it might have to do with the order that things happen. I'm away from my test system so I can't try it right now. You left the preRegister in for $chat_userlist, right?

Did you set the cache time to 0? You'd want to do that while working on it even if you've decided to set it to 1 minute, otherwise it's easy to get confused when things don't change right away.
Reply With Quote
  #7  
Old 10-06-2013, 08:55 PM
thunderclap82 thunderclap82 is offline
 
Join Date: Nov 2008
Posts: 305
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Hmm...it might have to do with the order that things happen. I'm away from my test system so I can't try it right now. You left the preRegister in for $chat_userlist, right?
You mean this code?

PHP Code:
vB_Template::preRegister('ajax_chat_widget', array('chat_userlist' => $chat_userlist)); 
Yes. I left it in.

Quote:
Did you set the cache time to 0? You'd want to do that while working on it even if you've decided to set it to 1 minute, otherwise it's easy to get confused when things don't change right away.
I set it to 1 and left it for 5-10 min and came back, but it was still empty.

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

I fixed the problem. I ended up changing the hook from global_start to global_bootstrap_init_start. Not sure if that will mess anything else up, but it got the job done. Thanks again for all your help, kh99.
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 10:00 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07594 seconds
  • Memory Usage 2,236KB
  • 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
  • (3)bbcode_code
  • (4)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete