SimplePortal

Customization => Blocks and Modifications => Topic started by: ccbtimewiz on November 04, 2015, 07:13:26 PM

Title: [Block] Show Members (in staff block style)
Post by: ccbtimewiz on November 04, 2015, 07:13:26 PM
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: [Select]
<?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'] > '<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'] > ? (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>'
;
}

?>
Title: Re: [Block] Show Members (in staff block style)
Post by: 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.   :'(
Title: Re: [Block] Show Members (in staff block style)
Post by: ♦ Ninja ZX-10RR ♦ on September 13, 2018, 08:32:35 AM
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.   :'(
Add the administrator group to
Code: [Select]
$groups_to_use = array(X);
Title: Re: [Block] Show Members (in staff block style)
Post by: LittleFang on September 19, 2018, 03:12:55 PM
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.
Title: Re: [Block] Show Members (in staff block style)
Post by: ♦ Ninja ZX-10RR ♦ on September 19, 2018, 03:38:29 PM
Code: [Select]
$groups_to_use = array(16);And if group 16 includes more than the ones you want to show, use the
Code: [Select]
$members_to_ignore = array(); and fill it up with each and every user ID you do not want to be displayed.
Title: Re: [Block] Show Members (in staff block style)
Post by: LittleFang on September 19, 2018, 06:29:56 PM
Aha!  I fixed my people appearing issue, but the box still breaks with more than one member showing, and destroys the formatting as shown in the screenshot.
Title: Re: [Block] Show Members (in staff block style)
Post by: ♦ Ninja ZX-10RR ♦ on September 19, 2018, 07:29:13 PM
I feel you either screwed up somewhere in the code (please post it), or the theme is weird (need link with visible block).
Title: Re: [Block] Show Members (in staff block style)
Post by: LittleFang on September 20, 2018, 02:37:03 PM
I went to the simple portal php for the staff block and Frankenstein'd a code that works. Now I'm just trying to tweak it with custom links. I can post what I created if it would help others
Title: Re: [Block] Show Members (in staff block style)
Post by: ♦ Ninja ZX-10RR ♦ on September 20, 2018, 08:44:49 PM
You're not meant to put any links into the above code O.o
Title: Re: [Block] Show Members (in staff block style)
Post by: LittleFang on September 21, 2018, 01:40:24 PM
Yes somebody posted another mod I'm trying to work through
SimplePortal 2.3.8 © 2008-2024, SimplePortal