Customization > Blocks and Modifications

[Block] Show Members (in staff block style)

(1/2) > >>

ccbtimewiz:
Show Members (in staff block style)

SMF 2.0 series | SP 2.3.6

This block is identical to the staff block, however you can define groups you want and you can make certain members not show.


--- Code: ---<?php

/**
 * @block Show Members
 * @author Rhode Fey (Sayaka Maizono)
 * @version 1.0.2
*/

/*
Usage:
fill the array with group ids of the groups you want to show.
Example for showing just one group, from group 1;
$groups_to_use = array(1);
Example for showing three groups, from group 1, 3, and 8
$groups_to_use = array(1, 3, 8);
*/

$groups_to_use = array(1);

/*
Usage:
fill the array with member ids you don't want to show up.
Example for hiding one member, user #1
$members_to_ignore = array(1);
Example for hiding multiple members, user #1, #3, and #8
$members_to_ignore = array(1, 3, 8);
*/

$members_to_ignore = array();

/*
 *
*/

global $smcFunc, $sourcedir, $scripturl, $modSettings, $txt;

// These are strings for errors...
$txt['no_groups'] = 'No groups have been defined! Please refer to the comments in the Block code!';
$txt['no_members'] = 'No members have been found...';

$groups = array();
foreach ($groups_to_use as $group)
$groups[] = (int) $group;
$groups = array_unique($groups);

$ignored_members = array();
foreach ($members_to_ignore as $id)
$ignored_members[] = (int) $id;
$ignored_members = array_unique($ignored_members);

if (empty($groups))
{
echo '
<span class="smalltext" style="color: red;">
'. $txt['no_groups'] . '
</span>';

return;
}

$request = $smcFunc['db_query']('', '
SELECT
mem.id_member, mem.real_name, mem.avatar, mem.id_group, mem.id_post_group, mg.group_name,
a.id_attach, a.attachment_type, a.filename
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_group_id} THEN mem.id_post_group ELSE mem.id_group END)
WHERE mem.id_group IN ({array_int:groups_to_use}) OR mem.id_post_group IN ({array_int:groups_to_use})',
array(
'groups_to_use' => $groups,
'reg_group_id' => 0,
)
);

$member_list = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
}
else
{
$avatar_width = '';
$avatar_height = '';
}

$member_list[$row['id_member']] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'group' => $row['group_name'],
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $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']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
),
);
}
$smcFunc['db_free_result']($request);

if (empty($member_list))
{
echo '
<span class="smalltext" style="color: red;">
'. $txt['no_members'] . '
</span>';

return;
}

ksort($member_list);
$member_count = count($member_list);
$count = 0;

echo '
<table class="sp_fullwidth">';

foreach ($member_list as $member)
{
if (!empty($ignored_members))
if (in_array($member['id'], $ignored_members))
return;

echo '
<tr>
<td class="sp_staff sp_center">', !empty($member['avatar']['href']) ? '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '"><img src="' . $member['avatar']['href'] . '" alt="' . $member['name'] . '" width="40" /></a>' : '', '</td>
<td class="sp_staff_info', $member_count != ++$count ? ' sp_staff_divider' : '', '">
', $member['link'], '<br />
', $member['group'], '
</td>
</tr>';

echo '
</table>';
}

?>
--- End code ---

LittleFang:
I love this mod!  However I have a problem: I can't get admins to show up in the block no matter what I do.  Nobody is set to ignored.   :'(

♦ Ninja ZX-10RR ♦:

--- Quote from: LittleFang on September 11, 2018, 06:22:59 PM ---I love this mod!  However I have a problem: I can't get admins to show up in the block no matter what I do.  Nobody is set to ignored.   :'(

--- End quote ---
Add the administrator group to
--- Code: ---$groups_to_use = array(X);
--- End code ---

LittleFang:
Thank you!

However, when I add any other group to that array, it breaks the forum formatting. 
Also I want to only show the admin if they are in group 16 as well.  I should have specified that!

So my account (Little Fang) is in group 16 as a sub group.  However I don't show up on the widget.

♦ Ninja ZX-10RR ♦:

--- Code: ---$groups_to_use = array(16);
--- End code ---
And if group 16 includes more than the ones you want to show, use the
--- Code: ---$members_to_ignore = array();
--- End code ---
and fill it up with each and every user ID you do not want to be displayed.

Navigation

[0] Message Index

[#] Next page

Go to full version