<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Vb4_misc extends vB_Api { public function buddylist() { $currentUserContext = vB::getUserContext(); $userid = $currentUserContext->fetchUserId(); if (empty($userid)) { return array('response' => array('errormessage' => array('nopermission_loggedout'))); } $bf_misc_useroptions = vB::getDatastore()->getValue('bf_misc_useroptions'); $timeout = vB::getDatastore()->getOption('cookietimeout'); $cutoff = vB::getRequest()->getTimeNow() - $timeout; $data = array( 'userid' => $userid, 'bit_useroptions_invisible' => $bf_misc_useroptions['invisible'], 'cutoff' => $cutoff, ); $allusers = vB::getDbAssertor()->assertQuery('fetchDataForBuddyList', $data); $canSeeHidden = $currentUserContext->hasPermission('genericpermissions', 'canseehidden'); $onlineFriends = array(); $offlineFriends = array(); foreach($allusers as $_friend) { $_friendid = $_friend['userid']; $_invisiblemark = ""; $_online = "offline"; $_onlinestatusphrase = "x_is_offline"; $_isOnline = !empty($_friend['lastactivity']); if ($_isOnline) { if ($_friend['invisible'] > 0) { if ($canSeeHidden) { $_invisiblemark = "*"; $_online = "invisible"; $_onlinestatusphrase = "x_is_invisible"; $_isOnline = true; } else { $_friend['lastactivity'] = NULL; $_isOnline = false; } } else { $_online = "online"; $_onlinestatusphrase = "x_is_online_now"; } } $_data = [ 'buddy' => [ 'username' => $_friend['username'], 'displayname' => $_friend['displayname'], 'invisible' => $_friend['invisible'], 'userid' => $_friendid, 'lastactivity' => $_friend['lastactivity'], 'buddymark' => '+', 'invisiblemark' => $_invisiblemark, 'online' => $_online, 'onlinestatusphrase' => $_onlinestatusphrase, 'statusicon' => $_online, ], ]; if ($_isOnline) { if (!isset($onlineFriends[$_friendid])) { $onlineFriends[$_friendid] = $_data; } } else { $offlineFriends[$_friendid] = $_data; } } return array( 'response' => array( 'offlineusers' => $offlineFriends, 'onlineusers' => $onlineFriends, ) ); } } 