News:

Wondering if this will always be free?  See why free is better.

Main Menu

Buddies Block

Started by Mr. Pedram, June 06, 2013, 09:54:41 AM

Previous topic - Next topic

Hj Ahmad Rasyid Hj Ismail

Nice... Thank you for sharing...

samborabora

Quote from: ahrasis on July 28, 2014, 03:21:21 AM
Nice... Thank you for sharing...

No problem, sorry Mr Pedran for hijacking this thread with the unrelated code, but it should be useful to anyone attempting what I initially was attempting with Buddies Block. @ahrasis I also modified that code to add a header that only displays if there are some on-line friends, if not, the whole block is invisible:

<?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>';


Ok, last time you'll hear from me, sorry again for getting OT :D

ittiphol

Quote from: samborabora on July 28, 2014, 06:21:34 AM
Quote from: ahrasis on July 28, 2014, 03:21:21 AM
Nice... Thank you for sharing...

No problem, sorry Mr Pedran for hijacking this thread with the unrelated code, but it should be useful to anyone attempting what I initially was attempting with Buddies Block. @ahrasis I also modified that code to add a header that only displays if there are some on-line friends, if not, the whole block is invisible:

<?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>';


Ok, last time you'll hear from me, sorry again for getting OT :D

Thank you

What file to edit  ???

Hj Ahmad Rasyid Hj Ismail

I guess that is made in a block (portal block)... If you wish to add not using a block, you will need to decide whether it shall appear in all pages or on certain pages. For all pages, definitely you add it in index template. Boardindex for index page and so on...

ittiphol

Quote from: ahrasis on August 06, 2014, 09:38:05 AM
I guess that is made in a block (portal block)... If you wish to add not using a block, you will need to decide whether it shall appear in all pages or on certain pages. For all pages, definitely you add it in index template. Boardindex for index page and so on...

Thank you
that so hard for me  :'(

aegersz

my mod is on and sort of working but when you add a buddy, it does not tell you that the target member is being notified and the buddies do not get added.

is this a bug or did make a mistake ? i had to reapply the code mods to Display.template.php but the rest looks fine.
The configuration of my Linux VPS (SMF 2.0 with 160+ mods & some assorted manual tweaks) can be found here and notes on my mods can be found here (warning: those links will take you to a drug related forum). My (House) music DJ dedication page is here

Advertisement: