vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4.x Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=245)
-   -   Chat Modifications - AJAX Chat Integration (https://vborg.vbsupport.ru/showthread.php?t=269509)

ICThawk 08-31-2011 10:00 PM

AJAX Chat Integration
 
1 Attachment(s)
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.

HTML Code:

<a class="navtab" href="#" onClick="MyWindow=window.open('http://www.wavingthewheat.com/chat/index.php','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=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.

PHP Code:

$result mysql_query("SELECT * FROM ajax_chat_online");   
$num_chatting mysql_num_rows($result);   
vB_Template::preRegister('navbar',array('num_chatting' => $num_chatting));
vB_Template::preRegister('FORUMHOME',array('num_chatting' => $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.

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


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.

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


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

HTML Code:

<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,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=800,height=600'); return false;">Chat ({vb:raw num_chatting})</a>
PHP Code:

$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

[s]What needs to be modified to make this work in vB 3.8 ?[/s]

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.

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

Quote:

Originally Posted by thunderclap82 (Post 2319729)
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:

Code:

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

Code:

<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

Quote:

Originally Posted by feaelin (Post 2320675)
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

1 Attachment(s)
Quote:

Originally Posted by feaelin (Post 2320679)

Code:

{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

Quote:

Originally Posted by JustAskJulie (Post 2425990)
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

Quote:

Originally Posted by feaelin (Post 2320679)
Code:

{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):
Code:

$resCNT = mysql_query("SELECT COUNT(userID) FROM ajax_chat_online GROUP BY userID"); 
$num_chatting = $resCNT[0];
vB_Template::preRegister('navbar',array('num_chatting' => $num_chatting));
vB_Template::preRegister('FORUMHOME',array('num_chatting' => $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.


All times are GMT. The time now is 06:04 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.01178 seconds
  • Memory Usage 1,828KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (3)bbcode_html_printable
  • (4)bbcode_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (22)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete