Version: 1.00, by ICThawk
Developer Last Online: Mar 2014
Category: Chat Modifications -
Version: 4.1.4
Rating:
Released: 08-31-2011
Last Update: Never
Installs: 15
Uses Plugins
Re-useable Code Translations
No support by the author.
So I have been using vBulletin for awhile and have been very frustrated with the current lack of integration with AJAX Chat by blueimpu. So, I have decided to do the integration myself and with the help of other users on vB.org I have put together a few plugins.
Add Popup Link for Chat:
I started by adding in the Chat popup link to my navbar. In your navbar template, add the following code to display the Chat Link.
Displaying UserNames of Those Online:
Just like in the above there are two parts to this plugin. Modifying a template and creating a plugin. First we need to modify your FORUMHOME template. Right below the <!-- end logged in users --> line add the following.
HTML 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 -->
Next we need to create a new plugin. The Hook is global_start and the PHP code is:
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));
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
Alright I have completed the project and updated the code above to display how I have mine setup. I hope this comes in handy for anyone else wanting to use AJAX chat.
I was so glad to find a description how to implement this. But I think there is a problem with vB 4.1.5.
I wanted to use the "Displaying UserNames of Those Online". I created the plugin and I inserted the code in forumhome. When I load my vB there is the following error message:
Feechen, yes I had the same problem. It came from when there were NO users in chat it broke the code. I have added a "If Null" statement. I have fixed the "Display Users" Plugin Code above. But here it is again.
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));
Hi Hawk,
I'm trying to simply put the output in title tag like below, however, I'm just getting no echo.
Any thoughts on what I might be missing?
Thank you for your help.
Chris
$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('header', array('chat_userlist' => $chat_userlist));
How can I show the users on other forum pages besides the start page? And how can I show the chat users in another location of my website - outside of vBulletin?
I'd like a widget on the front page to show who is chatting. Any idea how to modify this code to make that work?
That's what the second half ICThawk's original post does for you. Look carefully at the "Displaying the UserNames of Those Online" section. Those two pieces of code will show the usernames of users that are chatting. Just don't forget to turn on the plugin after you create it (I keep doing that and wondering why my plugin doesn't work...
For what I was working on I wanted the chat window to be "inside", that is, have the usual header, navigation bar, footer, etc. as the rest of the forums, instead of popping up as a window.
This is how I did it (in case someone else needs to do the same thing).
First I made a custom template, named custom_ajaxchat with the following code as the body of the template:
The important parts is the url in href that points to the custom template and removing the 'onclick' event. I also added target="_blank" so that it would open a new tab so the user can continue browsing forums in one tab and chat in another.
You'll still need the Plugin (hooked to global_bootstrap_init_start) that ICThawk provided, I didn't make any changes there.