PDA

View Full Version : Chat Modifications - AJAX Chat Integration


ICThawk
08-31-2011, 10:00 PM
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.

<a class="navtab" href="#" onClick="MyWindow=window.open('http://www.wavingthewheat.com/chat/index.php','MyWindow','toolbar=no,location=no,dire ctories=no,status=no,menubar=no,scrollbars=no,resi zable=yes,width=800,height=600'); return false;">Chat ({vb:raw num_chatting})</a>

Next you will need to create a new plugin. Set the Hook Location to global_bootstrap_init_start and add the following into the PHP Code box.

$result = mysql_query("SELECT * FROM ajax_chat_online");
$num_chatting = mysql_num_rows($result);
vB_Template::preRegister('navbar',array('num_chatt ing' => $num_chatting));
vB_Template::preRegister('FORUMHOME',array('num_ch atting' => $num_chatting));



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.

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

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

ICThawk
09-01-2011, 03:12 PM
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.

Feechen
09-04-2011, 11:40 AM
Hi,

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:

Warning: implode() [function.implode]: Invalid arguments passed in [path]/global.php(29) : eval()'d code (line 35)

Do you have an idea what I have done wrong?

Thank you in advance for your help.

Regards,
Feechen

ICThawk
09-06-2011, 03:40 PM
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.

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

chrisbjax
03-23-2012, 01:59 PM
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

<a class="ajaxchat" style="float:left; position:relative; top:4px;" href="#" title="Chatting: {vb:raw chat_userlist}" onClick="ChatWindow=window.open('http://forums.usmilitarygamers.com/chat/index.php','ChatWindow','toolbar=no,location=no,di rectories=no,status=no,menubar=no,scrollbars=no,re sizable=yes,width=800,height=600'); return false;">Chat ({vb:raw num_chatting})</a>

$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('header', array('chat_userlist' => $chat_userlist));

Pianobiz
04-06-2012, 08:18 AM
Thanks for the Plugin!!!

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?

kpmedia
04-11-2012, 03:33 AM
What needs to be modified to make this work in vB 3.8 ?

I figured it out. I'll try and make some time to create an actual v3.8.x plugin.
It wasn't too hard, having read the vB4 docs on template variables (https://vborg.vbsupport.ru/showthread.php?t=228078).

Thanks for making this vB4 plugin available. :)

thunderclap82
04-13-2012, 02:54 PM
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?

feaelin
04-16-2012, 06:17 PM
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...:)

feaelin
04-16-2012, 06:27 PM
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:

{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>{vb:raw vboptions.bbtitle}</title>
{vb:raw headinclude}
</head>
<body>
{vb:raw header}
{vb:raw navbar}

<div class="blockbody">
<div class="blockrow">
<!-- Custom Code Start Here -->
<center>
<iframe src="http://DOMAINNAME.COM/chat/" width="80%" height="640>
</iframe>
</center>
<!-- / Custom Code Ends here -->
</div>
</div>
{vb:raw footer}
</body>
</html>


Obviously, you'll need to change "DOMAINNAME.COM" to your forum's domain name.

The link in the navbar template I changed from what ICThawk gave us, to this:

<a class="navtab" href="misc.php?do=page&template=ajaxchat" target="_blank">Chat ({vb:raw num_chatting})</a>

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.

oshrizak
04-20-2012, 02:52 AM
I was wondering if anyone had luck or knows how to make the chat window show on the forum home page also that way if no one wanted to have it in a popup they can just have it on the page under the navbar.

thunderclap82
05-22-2012, 08:32 PM
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...:)

Unless I'm missing something this is for the Forum, not a CMS widget. When I add the code to a widget (not the plugin code) it just generates an error.

thedukeboard
08-01-2012, 06:32 PM
This is pretty much exactly what I was looking for.

Question/help:

I'd like to add that first bit of code that links to the chat and shows active users to be inside a navtab. Is this possible? Thanks in advance.

dorans
08-11-2012, 08:56 AM
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>{vb:raw vboptions.bbtitle}</title>
{vb:raw headinclude}
</head>
<body>
{vb:raw header}
{vb:raw navbar}

<div class="blockbody">
<div class="blockrow">
<!-- Custom Code Start Here -->
<center>
<iframe src="http://DOMAINNAME.COM/chat/" width="80%" height="640>
</iframe>
</center>
<!-- / Custom Code Ends here -->
</div>
</div>
{vb:raw footer}
</body>
</html>




Missing a quotation mark at the end ...

peppefark
08-22-2012, 04:44 PM
Hi

I installed the chat but I can not integrate with vbulletin, please help me!!!

thanks

wishtheend
09-03-2012, 01:40 AM
Is there any way to have this work with the vsa Chatbox?
https://vborg.vbsupport.ru/showthread.php?t=235271

Love that chat, but can't figure out how to get a Who's Chatting put together for that one.

satwobex
09-03-2012, 09:49 PM
Hello!

Where can I find the "hook"?

Thanks!

JustAskJulie
06-05-2013, 05:44 PM
Can anyone tell me if the BlueImp chat has a private chat function?

JustAskJulie
06-15-2013, 04:38 PM
Can anyone tell me if the BlueImp chat has a private chat function?

It does. I was trying to determine this without installing it.


Another question. Has anyone figured out how to integrate it into VB so that you can click on a username and go to their profile to see more than just the username?

jonastio
06-20-2013, 05:47 AM
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>{vb:raw vboptions.bbtitle}</title>
{vb:raw headinclude}
</head>
<body>
{vb:raw header}
{vb:raw navbar}

<div class="blockbody">
<div class="blockrow">
<!-- Custom Code Start Here -->
<center>
<iframe src="http://DOMAINNAME.COM/chat/" width="80%" height="640">
</iframe>
</center>
<!-- / Custom Code Ends here -->
</div>
</div>
{vb:raw footer}
</body>
</html>


Is there a way to do this with a variable height, so that the iframe takes up all space on the screen without causing scrollbars AND the header/footer remains on the page? My Google-Fu with this seems to be super weak.

sixpackspeak
07-10-2016, 01:45 AM
***

sixpackspeak
11-07-2016, 02:09 PM
Updated to the following recently:
vBulletin 4.2.3 Patch Level 2
PHP 5.6.27-0+deb8u1 (cli)

And now the user counter doesn't work properly on the nav bar or who's chatting in the info section.

FYI, I've updated the "global_bootstrap_init_start" slightly, to make it a little more specific (and to remove duplicate login entries):
$resCNT = mysql_query("SELECT COUNT(userID) FROM ajax_chat_online GROUP BY userID");
$num_chatting = $resCNT[0];
vB_Template::preRegister('navbar',array('num_chatt ing' => $num_chatting));
vB_Template::preRegister('FORUMHOME',array('num_ch atting' => $num_chatting));

The query works perfectly as intended, however, it was not outputting any numerical counts, either with the current code (in OP) or the updated code.