SimplePortal
Customization => Custom Coding => Topic started 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! ;)
-
You can use the following in a Custom PHP block:
<?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'] > 0 ? (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>';
-
Wow, PERFECT, thank you so much!!! :D :D
-
I also added a top section, and this seems to work!
<?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'] > 0 ? (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>';
-
Well, yeah. You can modify it to your liking.
You're welcome. ;)