21
Monika
Re: Poster's status
  • 2008/12/24 19:43

  • Monika

  • Not too shy to talk

  • Posts: 103

  • Since: 2008/12/19


Trabis, now it's working :)

Between DELETE is delete lol

22
Monika
Re: Poster's status
  • 2008/12/24 21:36

  • Monika

  • Not too shy to talk

  • Posts: 103

  • Since: 2008/12/19


Another similar challenge guys:

I tried to apply the same code in the yogurt friends page to show if a friend is online/offline, but i failed.

23
mjoel
Re: Poster's status
  • 2008/12/24 23:21

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


after adding this code to my root/header.php ..the online/offline code works(no modifications) in yogurt and in profile module..thanks trabis..merry xmas to u

$online_handler =& xoops_gethandler('online');
    
mt_srand((double)microtime()*1000000);
    
// set gc probabillity to 10% for now..
    
if (mt_rand(1100) < 11) {
        
$online_handler->gc(300);
    }
    if (
is_object($xoopsUser)) {
        
$uid $xoopsUser->getVar('uid');
        
$uname $xoopsUser->getVar('uname');
    } else {
        
$uid 0;
        
$uname '';
    }
    if (
is_object($xoopsModule)) {
        
$online_handler->write($uid$unametime(), $xoopsModule->getVar('mid'), $_SERVER['REMOTE_ADDR']);
    } else {
        
$online_handler->write($uid$unametime(), 0$_SERVER['REMOTE_ADDR']);
    }


p/s: displaying <{$user_online}> directly in template ..returns 1

24
mjoel
Re: Poster's status
  • 2008/12/24 23:22

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


Quote:

I tried to apply the same code in the yogurt friends page to show if a friend is online/offline, but i failed.

refer this
https://xoops.org/modules/newbb/viewtopic.php?topic_id=66999&forum=15&post_id=302548#forumpost302548

25
Monika
Re: Poster's status
  • 2008/12/25 0:04

  • Monika

  • Not too shy to talk

  • Posts: 103

  • Since: 2008/12/19


I did refer to that post but i couldn't get it done, because the code posted there is to show all the online friends. For me I need to show beside a user's name Online/Offline. i hope Trabis will help me with this.


26
trabis
Re: Poster's status
  • 2008/12/25 14:23

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Adding online status to friends in friends.php could look like this:
//start of hack
$online_uids = array();
$online_handler =& xoops_gethandler('online');

$onlines $online_handler->getAll();
foreach(
$onlines as $online){
    
$online_uids[] = $online['online_uid'];
}

foreach (
$vetor as $i => $friend) {
    
$vetor[$i]['online'] = in_array($friend['uid'], $online_uids) ? true false;
}
//end of hack

$xoopsTpl->assign('friends',$vetor);

$xoopsTpl->assign('lang_delete',_MD_YOGURT_DELETE );
$xoopsTpl->assign('lang_evaluate',_MD_YOGURT_FRIENDSHIPCONFIGS );

include 
'../../footer.php';
?>


You can also use something like
$vetor[$i]['online'] = in_array($friend['uid'], $online_uids) ? 'Online!' 'Offline';


The value can be used in the template as <{$friends[i].online}>

I did not test this.

27
Monika
Re: Poster's status
  • 2008/12/25 18:54

  • Monika

  • Not too shy to talk

  • Posts: 103

  • Since: 2008/12/19


Trabis i have added your code to friends.php, and in the template i added this code:
<{if $friends[i].online==true}>

                <
span style='color:#ee0000 font-weight:bold;'>Online</span><br />
<{else}>               

                <
span style='color:#000000;font-weight:bold;'>Offline</span><br />
<{/if}>


But it always show me Offline

28
trabis
Re: Poster's status
  • 2008/12/25 20:14

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

Monika wrote:
Trabis i have added your code to friends.php, and in the template i added this code:
<{if $friends[i].online==true}>

                <
span style='color:#ee0000 font-weight:bold;'>Online</span><br />
<{else}>               

                <
span style='color:#000000;font-weight:bold;'>Offline</span><br />
<{/if}>


But it always show me Offline


That code must go inside the foreach loop in your template.

It works here.

29
Monika
Re: Poster's status
  • 2008/12/25 21:04

  • Monika

  • Not too shy to talk

  • Posts: 103

  • Since: 2008/12/19


Ok thanks

30
maxxy
Re: Poster's status
  • 2009/12/29 15:32

  • maxxy

  • Quite a regular

  • Posts: 286

  • Since: 2007/6/11


..its a little bit confusing reading the instruction in this thread


For my and all xoopser future reference and info.........here's what i did in XOOPS 2.42 profile to show online/offline status in user profile


1. open root/header.php..put code below before the closing tag ?>

$online_handler =& xoops_gethandler('online');
    
mt_srand((double)microtime()*1000000);
    
// set gc probabillity to 10% for now..
    
if (mt_rand(1100) < 11) {
        
$online_handler->gc(300);
    }
    if (
is_object($xoopsUser)) {
        
$uid $xoopsUser->getVar('uid');
        
$uname $xoopsUser->getVar('uname');
    } else {
        
$uid 0;
        
$uname '';
    }
    if (
is_object($xoopsModule)) {
        
$online_handler->write($uid$unametime(), $xoopsModule->getVar('mid'), $_SERVER['REMOTE_ADDR']);
    } else {
        
$online_handler->write($uid$unametime(), 0$_SERVER['REMOTE_ADDR']);
    }


2. Open modules/profile/userinfo.php

add this code
$user_online = new XoopsUser($thisUser->getVar('uid'));
if (
$user_online->isOnline())
{
    
$xoopsTpl->assign('user_online'true);
}

before

//User info
$xoopsTpl->assign('uname'$thisUser->getVar('uname'));


3. Open modules/profiles/templates/profile_userinfo.html
add the code below where you want to show it in user profile

<br /><bOnline Status:</b> <{if $user_online == true}>
                <
span style='color:#ee0000;'>Online</span><br />
<{else}>
                <
span style='color:#000000;'>Offline</span><br />
<{/if}>


4. Clear Cache..Voila


Login

Who's Online

170 user(s) are online (105 user(s) are browsing Support Forums)


Members: 0


Guests: 170


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits