• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ Contributions (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

who is in the chat?

Post a bug fix, a new feature, a theme ...

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
15 posts • Page 1 of 1

Postby remko » Thu Mar 09, 2006 5:38 pm

Code: Select all
function namelink($id)
{
   global $url,$installiemap;
   $sql="select gebruikersnaam from bert_leden where lidid=$id";
   $res=mysql_query($sql);
   $row=mysql_fetch_row($res);
   $link=$url.'/'.$installiemap.'/leden/'.$row[0];
   $tot="<a href="$link">$row[0]</a>";
   return $tot;
   
}

// funcs to see who is in chat

function getdir($pad)
{
   $res=array();
$handle=opendir($pad);
while (false!==($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
        $res[]=$file;
    }
}
closedir($handle);
return $res;
}

function whochat($base)
{
$nicks=array();
$rooms=getdir($base);
foreach ($rooms as $room)
{
   $roompad=$base.$room.'/nicknames';
   $nicks_room=getdir($roompad);
   if(count($nicks_room)>1)
   {
      foreach($nicks_room as $n) $nicks[]=$n;
   }
}

for($i=0;$i<count($nicks);$i++)
$nicks[$i]=urldecode(base64_decode($nicks[$i]));
return $nicks;
}

To see who is in the chat call whochat with the path to the chat as parameter.

example (from chatroot)

$base='newchat/data/private/chat/';
$nicks=whochat($base);

the result? an array[..n] of the nicknames.


who makes something like this of the most recent messages?
remko
Member
 
Posts: 21
Joined: Tue Feb 28, 2006 8:26 am
Top

Postby phpfreechat » Fri Mar 10, 2006 9:45 am

Thank you remko for this nice contribution.
It will certainly help out a lot of people while the tools API in not ready.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby DorBer » Wed Jun 28, 2006 1:33 pm

Sorry for my english, i'm russian.

phpFreeChat v1-beta2

when i run "who is on-line" demo, i see errors.
i think, that some files are old and some are new.

And i wrote: file pfcinfo.class.php

function getOnlineNick()
{
$container =& $this->getContainerInstance();
$users = $container->getOnlineNick();
$new = Array();
foreach($users["nickid"] as $user) {
$new[] = $container->getNickname($user);
}
return $new;
}
DorBer
New member
 
Posts: 3
Joined: Wed Jun 28, 2006 1:21 pm
Top

Postby DorBer » Wed Jun 28, 2006 2:09 pm

and /ban not working for this reasons
DorBer
New member
 
Posts: 3
Joined: Wed Jun 28, 2006 1:21 pm
Top

Postby phpfreechat » Wed Jun 28, 2006 2:13 pm

- this contribution is for 0.x branche.
- for the 1.x branche, I will add an API to query the chat (who is online, last posted messages ...)
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby softwareNerd » Thu Aug 17, 2006 2:30 am

DorBer wrote:$users = $container->getOnlineNick(NULL);

On our chat (1.0 beta) the API call above often gets ONE user when there are none. If the last user QUITs, then the API returns no users. However, if the last user simply times-out, then they continue to be returned by the call. However, when someone else goes into the Chat, then the system immediately shows the previously "last" user as timing out.

It is as if the actual Chat room is "refreshing" some list, while the call to $container->getOnlineNick(NULL) is not.

Any advice would be appreciated.
softwareNerd
Member
 
Posts: 17
Joined: Thu Feb 23, 2006 4:00 pm
Top

Postby phpfreechat » Thu Aug 17, 2006 10:03 am

In fact, to detect it there is no more user in the chat, I use a timeout parameter.

By default I set it up to 20 secondes bu you can change it to 5 :
Code: Select all
$users = $info->getOnlineNick(NULL, 5 /*this is the number of seconds to wait before to considere a user disconnected */);
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby softwareNerd » Fri Aug 18, 2006 12:52 am

I tried with a time-out of 1 second, but no luck.
I also set $params["quit_on_closedwindow"] = true;
and users from IE disappear at once. However, FF users (the last one) still shows up if they do not explicitly /quit.

What could I be doing wrong?
Code: Select all
     
$serverId = "65c46d5a6e14e708c3dd4d928879b2be";
$chatinfo= new pfcInfo($serverId );
$container =& $chatinfo->getContainerInstance();
$userInfo = $container->getOnlineNick(NULL,1);
$users =  $userInfo["nickid"] ;
$nd_users = count($users);

 if ($nd_users==0)
{
//Always comes here if LAST user timed out,
//instead of QUITTING
}
else
{
}
softwareNerd
Member
 
Posts: 17
Joined: Thu Feb 23, 2006 4:00 pm
Top

Postby phpfreechat » Fri Aug 18, 2006 10:26 am

It is wrong, here is the correct code (look at the pfcinfo.class.php source code to understand) :
Code: Select all
$serverId = "65c46d5a6e14e708c3dd4d928879b2be";
$chatinfo= new pfcInfo($serverId );
$users = $chatinfo->getOnlineNick(NULL,10);
$nd_users = count($users);

 if ($nd_users==0)
{
//Always comes here if LAST user timed out,
//instead of QUITTING
}
else
{
}

ps: do NOT set the timeout to a value minore to "refresh_delay" value. (by default 5seconds)
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby softwareNerd » Fri Aug 18, 2006 7:35 pm

Thanks so much. Actually I had tried $chatinfo->getOnlineNick() along the way, but did not realize that it returns a *data-type* from $container->getOnlineNick(NULL); So, I was trying to interpret the $chatinfo->getOnlineNick() as nick-ids that I then had to lookup to get a nick-name.

Thanks again for all your help.
softwareNerd
Member
 
Posts: 17
Joined: Thu Feb 23, 2006 4:00 pm
Top

Postby NautTboy » Thu Jun 25, 2009 1:40 pm

I'm sorry, but where do i put the coding? Is it in the root index.php? Is there a demo page/site I could check out?
NautTboy
Member
 
Posts: 37
Joined: Sat Mar 14, 2009 7:40 am
Top

Postby chap » Sat Jun 27, 2009 1:43 am

I use the "who's on line" like this ...

I created a user.css file and placed it in the styles/ dir.

(here's my user.css)


Code: Select all
div.user {
        position: absolute;
        top: 700px;
        left: 0.8em;
        margin-top: 0.5em;
        margin-left: 0.4em;
        padding:3px;
        border: 1px solid #e7cd83;
        -moz-border-radius:10px;
        -webkit-border-radius:10px;
        behavior:url(border-radius.htc);
        width: 13em;
        font-size: 12px;
        display: inline;
        background-color: #1d2d4f;
        color: #e7cd83;
        text-align: center;
}

****

Then added this line in the index.php file with the other links to style sheets

Code: Select all
<link rel="stylesheet" title="classic" type="text/css" href="style/user.css" />

****


And then placed this php calling the users and the style sheet parameters in the index.php file

Code: Select all
<?php

require_once dirname(__FILENAME__)."/src/pfcinfo.class.php";
$info  = new pfcInfo( md5("FILENAME") );
// NULL is used to get all the connected users, but you can specify
// a channel name to get only the connected user on a specific channel
$users = $info->getOnlineNick(NULL);


echo '<div class="user">';
$info = "";
$nb_users = count($users);
if ($nb_users <= 1)
  $info = "<strong>%d</strong> Users<br>Are On This Chat!";
else
  $info = "<strong>%d</strong> Users Are Chattting<br>On This Chat!<hr>";
echo "<p>".sprintf($info, $nb_users)."</p>";

echo "<ul>";
foreach($users as $u)
{
  echo "<li>".$u."</li>";
}
echo "</ul>";
echo "</div>";

?>

Hope this helps out a little :).

Chap
chap
New member
 
Posts: 8
Joined: Mon May 25, 2009 4:20 am
Top

Postby MarkHoward » Thu Oct 08, 2009 3:15 am

Having trouble implementing a version of this.
Here is my code:
Code: Select all
<?php

require_once "/NZMotorhomeChat/src/pfcinfo.class.php";
$info  = new pfcInfo( md5("FILENAME") );
// NULL is used to get all the connected users, but you can specify
// a channel name to get only the connected user on a specific channel
$users = $info->getOnlineNick(NULL);
$chatcount = count($users);
$info = "";
if ($chatcount  <= 1)
  $info = "<strong>%d</strong> Users<br>Are On This Chat!";
else
  $info = "<strong>%d</strong> Users Are Chatting<br>On This Chat!<hr>";
echo "<p>".sprintf($info, $chatcount)."</p>";

?>

Here is the error I get.
Code: Select all
Warning: require_once(/NZMotorhomeChat/src/pfcinfo.class.php) [function.require-once]: failed to open stream: No such file or directory in D:xampphtdocsNZMotorhomeLinks.php on line 3

Fatal error: require_once() [function.require]: Failed opening required '/NZMotorhomeChat/src/pfcinfo.class.php' (include_path='.;D:xamppphppear') in D:xampphtdocsNZMotorhomeLinks.php on line 3

I suspect it's to do with "FILENAME". I don't knoe what should be in here. Can someone tell me how to find out what I should hardcode into "FILENAME" (if you agree that is the problem)
Otherwise any general help would be appreciated.
MarkHoward
Member
 
Posts: 20
Joined: Sun Jul 19, 2009 12:47 am
Top

Postby chap » Thu Oct 08, 2009 3:25 am

require_once "/NZMotorhomeChat/src/pfcinfo.class.php";

Your line should read .....

require_once dirname "/NZMotorhomeChat/src/pfcinfo.class.php";


:)

Chap
chap
New member
 
Posts: 8
Joined: Mon May 25, 2009 4:20 am
Top

Postby waiheke » Mon Sep 13, 2010 12:39 pm

Brilliant - got it working by combining the best of both worlds

require_once dirname(__FILE__)."/src/pfcinfo.class.php";
// the next line is a copy of the unique data/private/logs/ folder name
$serverId = "a3f5a82f559762b5f846e395525ada5d";
$chatinfo= new pfcInfo($serverId );
$users = $chatinfo->getOnlineNick(NULL);
echo '<div class="user">';
sort($users);
$nd_users = count($users);
$info = "";
if ($nd_users==0) {
echo "There are no users online";
} else {
echo "$nd_users users online";
foreach($users as $u)
{
echo "<li>".$u."</li>";
}}
echo "</ul>";
echo "</div>";

and then using 'Chaps' css file for a lovely layout

Thank you everybody

:-)
waiheke
Member
 
Posts: 126
Joined: Sun Sep 12, 2010 4:33 pm
Top


Post a reply
15 posts • Page 1 of 1

Return to Contributions (v1.x)

Who is online

Users browsing this forum: No registered users and 20 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
cron
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub