SimplePortal

Customization => Custom Coding => Topic started by: samborabora on July 27, 2014, 08:06:08 AM

Title: My online buddies block with avatars??
Post by: samborabora on July 27, 2014, 08:06:08 AM
Is it possible to have a custom block that shows the avatars of all of one's own buddies that are currently online? The avatrs would preferably be at about the size of 30px x 30px, so they fit nicely into the block, and bonus points if the whole block section just doesn't display anything if there are no users online currently! ;)
Title: Re: My online buddies block with avatars??
Post by: [SiNaN] on July 27, 2014, 09:27:43 AM
You can use the following in a Custom PHP block:

Code: [Select]
<?php

global $smcFunc$sourcedir$scripturl$modSettings;

require_once(
$sourcedir '/Subs-MembersOnline.php');

$options = array(
'show_hidden' => allowedTo('moderate_forum'),
'sort' => 'log_time',
'reverse_sort' => true,
);
$return getMembersOnlineStats($options);

if (empty(
$return['users_online']))
return;

$buddies = array();
foreach (
$return['users_online'] as $user)
{
if ($user['is_buddy'])
$buddies[$user['id']] = $user['href'];
}

if (empty(
$buddies))
return;

$request $smcFunc['db_query']('''
SELECT
m.id_member, m.avatar, a.id_attach,
a.attachment_type, a.filename
FROM {db_prefix}members AS m
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member)
WHERE m.id_member = {array_int:members}'
,
array(
'members' => array_keys($buddies),
)
);
$avatars = array();
while (
$row $smcFunc['db_fetch_assoc']($request))
$avatars[$row['id_member']] = $row['avatar'] == '' ? ($row['id_attach'] > ? (empty($row['attachment_type']) ? $scripturl '?action=dlattach;attach=' $row['id_attach'] . ';type=avatar' $modSettings['custom_avatar_url'] . '/' $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' $row['avatar']);
$smcFunc['db_free_result']($request);

foreach (
$buddies as $id => $href)
echo '<a href="'$href'"><img src="'$avatars[$id], '" alt="" style="width: 30px; height: 30px;" /></a>';
Title: Re: My online buddies block with avatars??
Post by: samborabora on July 27, 2014, 12:30:34 PM
Wow, PERFECT, thank you so much!!! :D :D
Title: Re: My online buddies block with avatars??
Post by: samborabora on July 27, 2014, 01:26:26 PM
I also added a top section, and this seems to work!

Code: [Select]
<?php

global $smcFunc$sourcedir$scripturl$modSettings;

require_once(
$sourcedir '/Subs-MembersOnline.php');

$options = array(
'show_hidden' => allowedTo('moderate_forum'),
'sort' => 'log_time',
'reverse_sort' => true,
);
$return getMembersOnlineStats($options);

if (empty(
$return['users_online']))
return;

$buddies = array();
foreach (
$return['users_online'] as $user)
{
if ($user['is_buddy'])
$buddies[$user['id']] = $user['href'];
}

if (empty(
$buddies))
return;

$request $smcFunc['db_query']('''
SELECT
m.id_member, m.avatar, a.id_attach,
a.attachment_type, a.filename
FROM {db_prefix}members AS m
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member)
WHERE m.id_member = {array_int:members}'
,
array(
'members' => array_keys($buddies),
)
);
$avatars = array();
while (
$row $smcFunc['db_fetch_assoc']($request))
$avatars[$row['id_member']] = $row['avatar'] == '' ? ($row['id_attach'] > ? (empty($row['attachment_type']) ? $scripturl '?action=dlattach;attach=' $row['id_attach'] . ';type=avatar' $modSettings['custom_avatar_url'] . '/' $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' $row['avatar']);
$smcFunc['db_free_result']($request);

if (!empty(
$buddies))
echo 
'
<div id="onlinefriendstitle"></div>

'
;

foreach (
$buddies as $id => $href)
echo '<a href="'$href'"><img src="'$avatars[$id], '" alt="" style="width: 30px; height: 30px;" /></a>';
Title: Re: My online buddies block with avatars??
Post by: [SiNaN] on July 27, 2014, 01:49:35 PM
Well, yeah. You can modify it to your liking.

You're welcome. ;)
SimplePortal 2.3.8 © 2008-2024, SimplePortal