collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 555
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

NEED HELP? If you're looking for support with Simple Portal, look no further than the Support Board!

Author Topic: Show a list of members in a particular membergroup i.e "Valued contributors"?  (Read 7710 times)

0 Members and 1 Guest are viewing this topic.

Offline wellwisher

  • Semi Newbie
  • *
  • Posts: 15
  • SMF Version: 2.0.11
  • SP Version: 2.3.6
Hello SP team and community,

I am trying to display a list of members in a particular membergroup i.e "Valued contributors" in a block. There's already a "staff list" block but I want one which displays a membergroup of my choice?
« Last Edit: October 19, 2015, 08:17:41 PM by wellwisher »

Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal Version: None
Do you want it to look identical to the staff block?

Offline wellwisher

  • Semi Newbie
  • *
  • Posts: 15
  • SMF Version: 2.0.11
  • SP Version: 2.3.6
Yes, that would be pretty awesome Sayaka Maizono. Can this be achieved with php block option?


Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal Version: None
Yes, make a custom PHP block and place the following code in it.

This is an old version. Please use the updated version here, later in the topic.

Code: [Select]
<?php

/**
 * @block List Groups in Staff Style
 * @author Rhode Fey (Sayaka Maizono)
 * @version 1.0.0
*/

/*
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);
include(
dirname(__FILE__) . '/SSI.php');

global 
$smcFunc$sourcedir$scripturl$modSettings;

if (empty(
$groups_to_use))
return 'No groups to show...';

$request $smcFunc['db_query']('''
SELECT
mem.id_member, mem.real_name, mem.avatar, mem.id_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 = mem.id_group)
WHERE mem.id_group IN ({array_int:groups_to_use})'
,
array(
'groups_to_use' => $groups_to_use,
)
);

$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[] = 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))
return 'No members to show...';

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

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

foreach (
$member_list as $member)
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>'
;

?>
« Last Edit: October 19, 2015, 08:17:11 PM by Sayaka Maizono »

Offline wellwisher

  • Semi Newbie
  • *
  • Posts: 15
  • SMF Version: 2.0.11
  • SP Version: 2.3.6
Thank you for responding Sayaka Maizono just tried your code and it works brilliantly for "Regular groups" i.e administors, global mods, mods, and basically any group you make.

What about targetting "Post count based groups"? I tried putting in a post count group number:

$groups_to_use = array(7);

But the group doesn't get listed. Any help would be awesome thank you.

Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal Version: None
Code: [Select]
<?php

/**
 * @block List Groups in Staff Style
 * @author Rhode Fey (Sayaka Maizono)
 * @version 1.0.1
*/

/*
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);

/*
 *
*/

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);

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

?>

Changelog (Version 1.0.1)
- Fixed error handling when members/groups are not defined.
- Sanitized the variable that users edit to make it safe, casting the variable as a different type or putting invalid data in it (such as the names of groups instead of ids) will not cause a database error anymore. However syntax errors are unavoidable, I will look into a way to edit the variable with a small interface in the future.
- Added the ability to define post count based groups, and to show post count based group titles.
- Made the arrays unique so members that are in post count groups and also in other groups defined will not be shown multiple times. However the member will be shown as a part of the group defined first for that member.

Offline wellwisher

  • Semi Newbie
  • *
  • Posts: 15
  • SMF Version: 2.0.11
  • SP Version: 2.3.6
@SayakaMaizono thank you for your help, this is a sexy piece of code. Works like a charm, plus you've made it so easy for nubsters like me - for this, I pledge my heartful thank you! Plus this will help out a tone of other people in the same boat as I was. Now I can pretty much add whichever postgroup I wish. Thank you again, this will help promote members hard work within our forums! I can't wait to make membergroups like "Hall of fame", Special members etc and showcase them in the sp sidebar with your help. Cheers Sayaka!

I also didn't have to edit any forum files which can get messy, this was really quick and easy simple instructions.

Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal Version: None
Of course, let me know if you run into any problems with the code. I can adapt it a lot, like making it so certain members won't appear or making it so only certain conditions are met (like name format, amount of posts, etc).

While I knew you really wanted to only have the code show one group, I thought about making it show any number of groups just to make it more versatile for both you and other members.

If you have other requests feel free to post them here in the Custom Coding board.

Offline wellwisher

  • Semi Newbie
  • *
  • Posts: 15
  • SMF Version: 2.0.11
  • SP Version: 2.3.6
You've been more than kind mate thank you, yes I will let you know if I run into issues although I doubt this will happen.

One thing that comes to mind (it's not a bug or a SP problem) and I apologise for going off-topic...
When I first created the 'Staff list' block... some of our staff did not have avatars, this made the Staff list block look aesthetically weak. Same problem with SMF forum. I overcame this issue by using the Mod by Jokerâ„¢ called "Default Avatar".

Having a default avatar option in these 'member blocks' would be a much welcomed upgrade in future SP releases. 

Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal Version: None
The function checkDefaultAvatar() has undefined array keys, and doesn't really seem optimized to use. Really should ask the mod author to update it and make it easier to call. The mod doesn't even use the function itself and it seems that it was designed solely for integration purposes too.

Regardless, try out this edit for my block:

Find:
Code: [Select]
}
$smcFunc['db_free_result']($request);

Code: [Select]
global $settings;
if (empty($member_list[$row['id_member']]['avatar']['href']))
$member_list[$row['id_member']]['avatar']['href'] = $settings['default_images_url'] . '/default_avatar.png';
}
$smcFunc['db_free_result']($request);

Note that this ignores the male/female options of the mod and just uses the default url and not one you define. Maybe I'll look into making my own default avatar modification.

Offline wellwisher

  • Semi Newbie
  • *
  • Posts: 15
  • SMF Version: 2.0.11
  • SP Version: 2.3.6
Thank you for responding. Again apologies for side-tracking the topic. I want to give this new avatar code a shot Sayaka! Just to clarify things for my small mind... I find this code below:

What's the file location of this code by the way?

Code: [Select]
}
$smcFunc['db_free_result']($request);

Then all I do is replace the above code with the one below, am I correct Sayaka?:

Code: [Select]
global $settings;
if (empty($member_list[$row['id_member']]['avatar']['href']))
$member_list[$row['id_member']]['avatar']['href'] = $settings['default_images_url'] . '/default_avatar.png';
}
$smcFunc['db_free_result']($request);


Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal Version: None
It's for the custom PHP block earlier.

Here, I made the edits for you:

Code: [Select]
<?php

/**
 * @block List Groups in Staff Style
 * @author Rhode Fey (Sayaka Maizono)
 * @version 1.0.1
*/

/*
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);

/*
 *
*/

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);

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'])
),
);

global $settings;
if (empty($member_list[$row['id_member']]['avatar']['href']))
$member_list[$row['id_member']]['avatar']['href'] = $settings['default_images_url'] . '/default_avatar.png';
}
$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)
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>'
;

?>

Offline wellwisher

  • Semi Newbie
  • *
  • Posts: 15
  • SMF Version: 2.0.11
  • SP Version: 2.3.6
Just tested your code on my local and I can see the default avatars now. Thank you Sayaka Maizono, this works perfectly. Have a happy halloween! This is pretty awesome!