TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

April 18, 2024, 03:57:39 AM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,164
  • Total Topics: 21,219
  • Online today: 190
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 128
  • Total: 128

Online Buddy List

Started by Xarcell, December 24, 2006, 06:55:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Xarcell

Any chance someone can create a buddy list block. A block that only shows your buddies that are online. Just a list of buddy names...

I tried and didn't have much luck.

G6Cad

Well where is Max when you need him the most  :P

JPDeni

I can't be sure this will work because I'm the only person who goes to my test site, so there can't be any buddies online. But at least I know there are no syntax errors and it tells me that there are no buddies online. :)


global $scripturl, $db_prefix, $user_info, $txt;

// Load the users online right now.
$result = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline,
mg.onlineColor, mg.ID_GROUP
FROM {$db_prefix}log_online AS lo
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))", __FILE__, __LINE__);

$return['users'] = array();
$return['buddies'] = 0;
$show_buddies = !empty($user_info['buddies']);

while ($row = mysql_fetch_assoc($result))
{
        if (in_array($row['ID_MEMBER'], $user_info['buddies']) && (!empty($row['showOnline']) || allowedTo('moderate_forum')))
{
$return['buddies']++;
// Some basic color coding...
if (!empty($row['onlineColor']))
$link = '<b><a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" style="color: ' . $row['onlineColor'] . ';">' . $row['realName'] . '</a></b>';
else
$link = '<b><a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></b>';

$return['users'][$row['logTime'] . $row['memberName']] = array(
'id' => $row['ID_MEMBER'],
'username' => $row['memberName'],
'name' => $row['realName'],
'group' => $row['ID_GROUP'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => $link,
'hidden' => empty($row['showOnline']),
'is_last' => false,
);
}
}
mysql_free_result($result);

if (!empty($return['users']))
{
krsort($return['users']);
$userlist = array_keys($return['users']);
$return['users'][$userlist[count($userlist) - 1]]['is_last'] = true;
        foreach ($return['users'] as $user)
        echo $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'], $user['is_last'] ? '' : ', ';
}
else
        echo 'No buddies online at this time';


This is really just taking some lines out of function ssi_whosOnline in SSI.php.

Xarcell


Xarcell

I changed the title and added the topic link to the snippet index.

Max

Quote from: G6 on December 24, 2006, 01:25:49 PM
Well where is Max when you need him the most  :P

Haha.. Id probs with a previous code to do with buddys, JPDeni had to help me with it.  :up:

Show a "Add Buddy" link under karma in members posts...

Open
default/Display.template.php

Find:

// Show online and offline buttons?


Add Before:
// Can they add this member as a buddy?
if (!empty($modSettings['enable_buddylist']) && ($message['member']['id'] != $context['user']['id'])){
echo '<a href="' . $scripturl . '?action=buddy;u=' . $message['member']['id'] . ';sesc=' . $context['session_id'] . '">' . (empty($message['member']['is_buddy']) ? '[Add To Buddy List]' : '[Remove Buddy From List]') . '</a><br />';
}

Lord Anubis

#6
Did a bit of work on this to make it linear with an online symbol (wanted to do avatars, but here it is)

Preview:
Buddies OnlineNo Buddies Online

Disclaimer:

THIS CODE WILL LOOK FUNNY ON YOUR SITE IF YOU HAVE IT ALLOWED FOR GUEST ACCESS, SO I WOULD UNCHECK THAT...HAHA


global $scripturl, $db_prefix, $user_info, $txt, $modSettings;

// Load the users online right now.
$result = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline,
mg.onlineColor, mg.ID_GROUP
FROM {$db_prefix}log_online AS lo
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))", __FILE__, __LINE__);

$return['users'] = array();
$return['buddies'] = 0;
$show_buddies = !empty($user_info['buddies']);
$friend_bullet = '<img src ="/Themes/default/images/useron.gif"> ';


while ($row = mysql_fetch_assoc($result))
{
        if (in_array($row['ID_MEMBER'], $user_info['buddies']) && (!empty($row['showOnline']) || allowedTo('moderate_forum')))
{

$return['buddies']++;
// Some basic color coding...
if (!empty($row['onlineColor']))
$link = '<b><a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" style="color: ' . $row['onlineColor'] . ';">' . $row['realName'] . '</a></b>';
else
$link = '<b><a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></b>';

$return['users'][$row['logTime'] . $row['memberName']] = array(
'id' => $row['ID_MEMBER'],
'username' => $row['memberName'],
'name' => $row['realName'],
'group' => $row['ID_GROUP'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => $link,
'hidden' => empty($row['showOnline']),
'is_last' => false,
);
}
}
mysql_free_result($result);

if (!empty($return['users']))
{
krsort($return['users']);
$userlist = array_keys($return['users']);
$return['users'][$userlist[count($userlist) - 1]]['is_last'] = true;
        foreach ($return['users'] as $user)
               
        echo $user['hidden'] ? '<i>' . $friend_bullet.$user['link'] . '</i>' : $friend_bullet.$user['link'], $user['is_last'] ? '' : '<br> ';

}
else
        echo '<img src ="/Themes/default/images/useroff.gif"> No Friends Online';




Renegd98


Lord Anubis

I just customize to suit users :D