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

refreshing counter of users in chatbox in phpbb header?

This forum is now locked as we will no longer be developing the v1.x branch

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

Topic locked
4 posts • Page 1 of 1

Postby Jeroen » Thu Mar 23, 2006 1:15 am

i have a counter in the header of our forum but it only refreshes when te page is reloaded. is there a way to make it refresh like the chatbox itself does without reloading the whole page?

if it refreshes every minute or so, then i can monitor the chat without being logged in to the chat.

what i have now is like this

$messages_filename = '../phpFreeChat/data/private/chat/mychatbox/messages.data';
if (file_exists($messages_filename))
{
$Diff = (time() - filectime("$messages_filename"));
if ($Diff < 300) //300 seconden = 5 minuten
{
$files = array();
$files = array_merge($files, glob('../phpFreeChat/data/private/chat/mychatbox/nicknames/*'));
$free_chat_online_users =count($files);
}
if ( $free_chat_online_users > 0)
{
$free_chat_icon_suffix='_active';//show other icon
}
}
$l_free_chat_online_users = "(".$free_chat_online_users.")";

$l_free_chat_online_users_explain = 'Last message on '.date("d/m/Y H:i",filectime("$messages_filename")+6*3600); //6 hour shift
Jeroen
Member
 
Posts: 13
Joined: Mon Mar 20, 2006 2:38 pm
Top

Postby phpfreechat » Thu Mar 23, 2006 9:07 am

You should use an AJAX periodic request or a iframe periodic reload.

This is just advices, I don't have time to write a full piece of code, sorry.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby Jeroen » Fri Mar 24, 2006 1:53 pm

This is what ive come up with (mostly with help of this page:http://ajaxpatterns.org/ )
you are welkom to use it or give comments to make it better
i created a new php that gives me the onlineusers
a piece of javascipt in the template for my forum(only when user is logged in)
a active chat icon that blinks franticly to attract attention. it stops checking after an hour.

php that gives me the onlineusers like this:(sorry comments are dutch)



<?php

$free_chat_online_users =0;

//file doorfietsen als de laatste aanpassing niet langer dan 5 minuten geleden is
$messages_filename = './data/private/chat/mychat/messages.data';
if (file_exists($messages_filename))
{
$Diff = (time() - filectime("$messages_filename"));
if ($Diff < 300) //300 seconden = 5 minuten
{
$files = array();
$files = array_merge($files, glob('./data/private/chat/mychat/nicknames/*'));
$free_chat_online_users =count($files);
}
}

echo $free_chat_online_users ;
?>




And a piece of javascript combined with a phpbbforum template like this:




...
<!-- BEGIN switch_user_logged_in -->
<script type="text/javascript" language="JavaScript"><!--

function createXMLHttpRequest() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
}
try { return new XMLHttpRequest(); } catch(e) {
}
//alert("XMLHttpRequest not supported");
return null;
}

function ververs()
{
xhReq.abort();
xhReq.open("GET", "../phpFreeChat/OnlineUsers.php?timestamp=" + new Date().getTime()+"&last="+serverResponse, true);
xhReq.onreadystatechange = onSumResponse;
requestTimer = setTimeout(function(){ xhReq.abort(); }, 10000);
xhReq.onreadystatechange = onSumResponse;
xhReq.send(null);
if(checks>0)
{
checks=checks-1;
setTimeout(ververs, 60000);
}

}

function onSumResponse() {
clearTimeout(requestTimer);
if (xhReq.readyState != 4)
{ return; }
serverResponse = xhReq.responseText;
document.getElementById("currentlyOnline").innerHTML = "Chat("+serverResponse+")";
var img = document.getElementById("chatico");
if(serverResponse > 0)
{
img.src="templates/Acid/images/icon_mini_chat_active.gif" ;
}
else
{
img.src="templates/Acid/images/icon_mini_chat.gif" ;
}
// alert(serverResponse); // Shows "15"

}

var checks=60; //niet eeuwig blijven checken
var serverResponse="";
var requestTimer;
var xhReq = createXMLHttpRequest();

if( xhReq!=null)
{
ververs();
}

//-->
</script>
<!-- END switch_user_logged_in -->

</head>
...
<a href="{U_FREE_CHAT}" class="mainmenu"><img src="templates/Acid/images/icon_mini_chat{L_FREE_CHAT_ICON}.gif" width="12" height="13" border="0" alt="{L_FREE_CHAT} {L_ONLINE_FREE_CHAT_USERS_EXPLAIN}" hspace="3" id="chatico"/></a><a id="currentlyOnline" href="{U_FREE_CHAT}" class="mainmenu">{L_FREE_CHAT} </a>
...
Jeroen
Member
 
Posts: 13
Joined: Mon Mar 20, 2006 2:38 pm
Top

Postby phpfreechat » Fri Mar 24, 2006 2:07 pm

Thank you for sharing the code! :)
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top


Topic locked
4 posts • Page 1 of 1

Return to Feature Requests (v1.x)

Who is online

Users browsing this forum: No registered users and 8 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