Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 19, 2022, 09:09:38 PM

Login with username, password and session length
Members
  • Total Members: 3843
  • Latest: Tricky
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 60
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 51
Total: 51

Author Topic: Possible to create Who's Chatting TP module for Integrated Ajax Chat?  (Read 15010 times)

0 Members and 1 Guest are viewing this topic.

Offline Greater Realms

  • Jr. Member
  • **
  • Posts: 11
    • GreaterRealms
Link to my forum: gr.2phatgeeks.com
SMF version: 2.0.4
TP version: 1.107
Default Forum Language: English
Theme name and version: Argentum2 Enhanced, Final. The sexiest of the Argentums. 
Browser Name and Version: Chrome  28.0.1500.72 m
Mods installed: 1.   KeyCAPTCHA for SMF    2.5 
2.   TinyPortal    1.107     
3.   Add Social Media Icons To Profiles    1.1.0     
4.   Ban List    2.0     
5.   Dice Roller BBcode    1.3     
6.   FancyPosts    0.4.2     
7.   SMFSIMPLE Bookmarks
8.     SMF Shop     3.2.1

Hello! I would very much like to display a Who is in the Chat room within a TP module. I am using Blueimp's Ajax chat integrated with SMF: http://frug.github.io/AJAX-Chat/ I've tried to no avail as an utter nubbin to parse the smf mod to see if I can play match-the-theme-edits and I just plain suck.

I am hoping that there is an easier way about it to display who is in the chat via TP. Or at least, someone is patient enough to 's'plain it to a newb like me?

Edited to add 1 new mod: Smf shop
« Last Edit: July 29, 2013, 01:55:04 PM by Greater Realms »

Offline Lesmond

  • Do what you have to!
  • Administrator
  • *
  • Posts: 3169
    • Tiny Pix... Free Image Hosting and Sharing.
It might help if you Could tell us what chat software are you using please?
Please don't PM me for support without an invitation.


Offline Greater Realms

  • Jr. Member
  • **
  • Posts: 11
    • GreaterRealms
Ajax chat. Sorry, I only put it in the title. :)

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Took the code right from the mod basically. Give this a try.

Code: [Select]
global $context, $smcFunc, $scripturl, $txt;

//ajax chat start
$userIDs = chatOnlineUsers();
$context['chat_links'] = array();
if (count($userIDs) > 0){
if (count($userIDs) == 1){
$result = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.real_name, mem.id_group, mg.online_color, mg.id_group
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}membergroups AS mg ON
(mg.id_group = IF(mem.id_group = 0, mem.id_post_group, mem.id_group)) WHERE mem.id_member = {int:the_id}',
array(
'the_id' => $userIDs[0],
)
);
} else {
$result = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.real_name, mem.id_group, mg.online_color, mg.id_group
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}membergroups AS mg ON
(mg.id_group = IF(mem.id_group = 0, mem.id_post_group, mem.id_group)) WHERE mem.id_member IN ({array_int:the_ids})',
array(
'the_ids' => $userIDs,
)
);
}
while ($row = $smcFunc['db_fetch_assoc']($result)) {
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'];
if($row['online_color'] != ""){
$link.= '" style="color: ' . $row['online_color'];
}
$link.= '">' . $row['real_name'] . '</a>';
array_push($context['chat_links'], $link);
}
$smcFunc['db_free_result']($result);
}

if (isset($context['chat_links'])) {
if (count($context['chat_links']) == 0)
echo '<br />' . $txt['chat_no_user'];
elseif (count($context['chat_links']) == 1 )
echo '<br />  1' . $txt['chat_aUser']. ':<br />', implode($context['chat_links']);
else
echo '<br /> ' . count($context['chat_links']). $txt['chat_users']. ':<br />', implode(', ', $context['chat_links']);
}

Offline Greater Realms

  • Jr. Member
  • **
  • Posts: 11
    • GreaterRealms
Quote
Fatal error: Call to undefined function chatOnlineUsers() in /home/bariguy/gr.2phatgeeks.com/Sources/Load.php(2207) : eval()'d code(127) : eval()'d code on line 4

I'm assuming that I am doing something wrong here lol--Which shouldn't surprise anyone!



Thank you both for your help so far!

Offline IchBin

  • Friends
  • *
  • Posts: 16231
I assumed the file was loaded that had the chatOnlineUsers() function in it.

So all you need to do is find out which file in the smf mod has the chatOnlineUsers() function in it. First add $sourcedir to the global line at the top of the code I posted above. Right after the global line, add the include with the name of the file (assuming it's in the Sources/ folder).
require_once($sourcedir . '/NameofFile.php');

Offline Greater Realms

  • Jr. Member
  • **
  • Posts: 11
    • GreaterRealms
So for me to be clear (sorry, you are dealing with yet another complete and total newbie here)

Pretending that www.myawesomesmfforum.com/directory/sources/magicfilewithChatOnlineUsersInIt I would then add:

require_once($sourcedir . 'www.myawesomesmfforum.com/directory/sources/magicfilewithChatOnlineUsersInIt');

To the code you provided into a PHP TP module and if all goes well it should work and no one will die, yes?

Thank you so much. I'll get to work trying to find where that function is.

Offline IchBin

  • Friends
  • *
  • Posts: 16231
No, you add it like I showed you above. You only need to exchange the filename with the actual filename that you find the function in.

$sourcedir will automatically add the path to the Sources directory.

Offline Greater Realms

  • Jr. Member
  • **
  • Posts: 11
    • GreaterRealms
No, you add it like I showed you above. You only need to exchange the filename with the actual filename that you find the function in.

$sourcedir will automatically add the path to the Sources directory.

Thank you for being patient with me and helping!

I found the line chatOnlineUsers in my SSI.php. So the top of the code you originally shared, I added below global:

require_once($sourcedir . '/SSI.php');

Is that correct? I feel like I am missing something super obvious because I have no clue what I am doing--but the above didn't work.

Quote
Fatal error: require_once(): Failed opening required '/SSI.php' (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/#######/###/Sources/Load.php(2151) : eval()'d code(127) : eval()'d code on line 2

Offline Lesmond

  • Do what you have to!
  • Administrator
  • *
  • Posts: 3169
    • Tiny Pix... Free Image Hosting and Sharing.
I have been trying this on my test server, I found chatOnlineUsers in index.template.php, I am also getting errors.

here is my code I used in a block..
Code: [Select]
global $context, $smcFunc, $scripturl, $txt, $sourcedir;
require_once($sourcedir . '/index.template.php');

//ajax chat start
$userIDs = chatOnlineUsers();
$context['chat_links'] = array();
if (count($userIDs) > 0){
if (count($userIDs) == 1){
$result = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.real_name, mem.id_group, mg.online_color, mg.id_group
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}membergroups AS mg ON
(mg.id_group = IF(mem.id_group = 0, mem.id_post_group, mem.id_group)) WHERE mem.id_member = {int:the_id}',
array(
'the_id' => $userIDs[0],
)
);
} else {
$result = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.real_name, mem.id_group, mg.online_color, mg.id_group
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}membergroups AS mg ON
(mg.id_group = IF(mem.id_group = 0, mem.id_post_group, mem.id_group)) WHERE mem.id_member IN ({array_int:the_ids})',
array(
'the_ids' => $userIDs,
)
);
}
while ($row = $smcFunc['db_fetch_assoc']($result)) {
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'];
if($row['online_color'] != ""){
$link.= '" style="color: ' . $row['online_color'];
}
$link.= '">' . $row['real_name'] . '</a>';
array_push($context['chat_links'], $link);
}
$smcFunc['db_free_result']($result);
}

if (isset($context['chat_links'])) {
if (count($context['chat_links']) == 0)
echo '<br />' . $txt['chat_no_user'];
elseif (count($context['chat_links']) == 1 )
echo '<br />  1' . $txt['chat_aUser']. ':<br />', implode($context['chat_links']);
else
echo '<br /> ' . count($context['chat_links']). $txt['chat_users']. ':<br />', implode(', ', $context['chat_links']);
}

here is the error I get...
Code: [Select]
Fatal error: require_once(): Failed opening required 'D:/Ampp/Ampps/www/smf/Sources/index.template.php' (include_path='.;C:\php\pear') in D:\Ampp\Ampps\www\smf\Sources\Load.php(2161) : eval()'d code(127) : eval()'d code on line 2
Just trying to help, not much good at php :idiot2:
Please don't PM me for support without an invitation.