1
Hi,
This code below will show user who recently login to your site
example like
sarahmx
2 minutes and 25 seconds ago
and in the code if the user have not yet have an avatar it will show an image from /uploads/blank_avatar
and if the user has avatar uploaded it will show his/her avtar
create a php custom block and named it as recent login and enter this code
//credits to JCbones of Hotscripts.com and XOOPS community
function timeDifference($start,$end,$return='days') {
//change times to Unix timestamp.
//$start = strtotime($start);
//$end = strtotime($end);
//subtract dates
//echo 'Start Timestamp: ' . $start . '<br/>End Timestamp: ' . $end . '<br/>';
$difference = max($end, $start) - min($end,$start);
$time = NULL;
//calculate time difference.
switch($return) {
case 'days':
$days = floor($difference/86400);
$difference = $difference % 86400;
$time['days'] = $days;
case 'hours':
$hours = floor($difference/3600);
$difference = $difference % 3600;
$time['hours'] = $hours;
case 'minutes':
$minutes = floor($difference/60);
$difference = $difference % 60;
$time['minutes'] = $minutes;
case 'seconds':
$seconds = $difference;
$time['seconds'] = $seconds;
}
if(is_array($time))
foreach($time as $key => $value) {
if($value > 0) {
$output[] = $value . ' ' . ucwords($key);
}
}
return implode(',',$output);
}
$now = time();
$hours = 24;
$kira=0;
$time = ( intval( $hours ) > 0 ) ? time() - ( intval( $hours ) * 3600 ) : ( time() - 24*3600 );
global $xoopsDB;
echo "<table><tr>";
$sql = "SELECT distinct uid, uname, user_avatar, last_login FROM ".$xoopsDB->prefix("users")." WHERE level > 0 AND uid NOT IN (0) AND last_login >= '" . $time . "' ORDER BY last_login DESC";
$result = $xoopsDB->query($sql);
while (list($uid, $uname,$user_avatar,$last_login) = $xoopsDB->fetchRow($result) ) {
//Put this variable in the echo statements where you would like them to show up.
$sinceLastLogin = ' ' . timeDifference($last_login,$now,'hours') . ' ago ';
$kira++;
if ($user_avatar == 'blank.gif')
{
echo "<td style='padding:5px;text-align:center'><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/blank_avatar.gif' title='".$uname."' border='0' alt='".$uname."' height='48' width='48'></a><br /><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'>".$uname."</a><br />$sinceLastLogin</td>";
}
else
{
echo "<td style='padding:5px;text-align:center'><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/".$user_avatar."' title='".$uname."' border='0' alt='".$uname."' height='48' width='48'></a><br /><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'>".$uname."</a><br />$sinceLastLogin</td>";
}
if($kira == 4)
{
echo "</tr><tr>";
}}
echo "</tr></table>";
the problem right now is it seems the time can't reach more than 5 minutes
after it reach more than 5 minutes
it will reset back to 0 seconds ago....btw does anyone know how to autorefresh this block or make it ajaxized