To use this website completely, it is necessary to store cookies on your computer.
 

* Navigator

Expand - Collapse

* Statistic

  • *Total Posts: 14963
  • *Total Topics: 2276
  • *Online Today: 46
  • *Most Online: 292
(2016 November 12, 09:37:31 am)

Limit Viewable Member Lists And Stats To Own Group Only

Started by ahrasis, 2012 December 19, 06:33:50 am

previous topic - next topic

0 Members and 0 Guests are viewing this topic.

ahrasis

2012 December 19, 06:33:50 am
 wish for a user in a membergroup is limited to seeing only his group members in memberlist. And if possible in the stats as well.

My idea is to modify either source (which I am afraid to do  ;) ) or template files for both memberlist and stats (which templates are they in?)

feline

2012 December 30, 02:48:38 pm Last Edit: 2012 December 30, 04:19:57 pm by portamx
Well .. you can filter out the membergroups by
Code Select
array_intersect($user_info['groups'], $modSettings['subforums'][$_SERVER['SERVER_NAME']]['groups'])
as example ...
for more I must look at the code before I can say more.
Many are stubborn in relation to the path, a few in relation to the target.

ahrasis

#2
2013 January 01, 06:17:59 pm
As I checked, the source for memberlist is in Memberlist.php and its template is in Memberlist.template.php but Groups.php as well as ManageMembergroup.template.php could be relevant as well.

feline

#3
2013 January 02, 05:25:32 pm
For the memberlist you can try follow modification you have to make on Memberlist.php

find ~line 371:
Code Select

// Select the members from the database.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member
FROM {db_prefix}members AS mem' . ($_REQUEST['sort'] === 'is_online' ? '


replace with:
Code Select

// Select the members from the database.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.id_group, mem.id_post_group, mem.additional_groups
FROM {db_prefix}members AS mem' . ($_REQUEST['sort'] === 'is_online' ? '


find ~line 510:
Code Select

// Find the members from the database.
// !!!SLOW This query is slow.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member
FROM {db_prefix}members AS mem


replace with:
Code Select

// Find the members from the database.
// !!!SLOW This query is slow.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.id_group, mem.id_post_group, mem.additional_groups
FROM {db_prefix}members AS mem


find ~line 573:
Code Select

$members = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$members[] = $row['id_member'];


replace with:
Code Select

$members = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if(isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]))
{
if(array_intersect(array_merge(array($row['id_group'], $row['id_post_group']), explode(',', $row['additional_groups'])), array_merge(array(1), $modSettings['subforums'][$_SERVER['SERVER_NAME']]['groups'])) != array())
$members[] = $row['id_member'];
}
else
$members[] = $row['id_member'];
}


Now the memberlist show only user they have access to the current subforum.

For the Stats I don't have a solution currently ...
Many are stubborn in relation to the path, a few in relation to the target.

feline

#4
2013 January 04, 10:50:22 am
Here now the changes for the stats (Sources/Stats.php)

find ~line 230:
Code Select

// Poster top 10.
// SubForums
if(isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]))
$members_result = $smcFunc['db_query']('', '
SELECT m.id_member, u.real_name, COUNT(m.id_msg) AS posts
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}members AS u ON (u.id_member = m.id_member)
WHERE posts > 0{subforums_see_board:m-id_board}
GROUP BY m.id_member, u.real_name
ORDER BY posts DESC
LIMIT 10',
array('guest' => 'Guest')
);


replace with:
Code Select

// Poster top 10.
// SubForums
if(isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]))
$members_result = $smcFunc['db_query']('', '
SELECT m.id_member, u.real_name, COUNT(m.id_msg) AS posts, u.id_group, u.id_post_group, u.additional_groups
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}members AS u ON (u.id_member = m.id_member)
WHERE posts > 0{subforums_see_board:m-id_board}
GROUP BY m.id_member, u.real_name
ORDER BY posts DESC
LIMIT 10',
array('guest' => $txt['guest_title'])
);


find ~line 255:
Code Select

$context['top_posters'] = array();
$max_num_posts = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
{
$context['top_posters'][] = array(
'name' => $row_members['real_name'],
'id' => $row_members['id_member'],
'num_posts' => $row_members['posts'],
'href' => $scripturl . '?action=profile;u=' . $row_members['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
);

if ($max_num_posts < $row_members['posts'])
$max_num_posts = $row_members['posts'];
}


replace with:
Code Select

$context['top_posters'] = array();
$max_num_posts = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
{
if(isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]))
{
if(array_intersect(array_merge(array($row_members['id_group'], $row_members['id_post_group']), explode(',', $row_members['additional_groups'])), array_merge(array(1), $modSettings['subforums'][$_SERVER['SERVER_NAME']]['groups'])) == array())
continue;
}

$context['top_posters'][] = array(
'name' => $row_members['real_name'],
'id' => $row_members['id_member'],
'num_posts' => $row_members['posts'],
'href' => $scripturl . '?action=profile;u=' . $row_members['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
);

if ($max_num_posts < $row_members['posts'])
$max_num_posts = $row_members['posts'];
}


find ~line 493:
Code Select

// Topic poster top 10.
$members_result = $smcFunc['db_query']('top_topic_starters', '
SELECT id_member, real_name
FROM {db_prefix}members
WHERE id_member IN ({array_int:member_list})
ORDER BY FIND_IN_SET(id_member, {string:top_topic_posters})
LIMIT 10',
array(
'member_list' => array_keys($members),
'top_topic_posters' => implode(',', array_keys($members)),
)
);
$context['top_starters'] = array();
$max_num_topics = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
{
$context['top_starters'][] = array(
'name' => $row_members['real_name'],
'id' => $row_members['id_member'],
'num_topics' => $members[$row_members['id_member']],
'href' => $scripturl . '?action=profile;u=' . $row_members['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
);


replace with:
Code Select

// Topic poster top 10.
$members_result = $smcFunc['db_query']('top_topic_starters', '
SELECT id_member, real_name, id_group, id_post_group, additional_groups
FROM {db_prefix}members
WHERE id_member IN ({array_int:member_list})
ORDER BY FIND_IN_SET(id_member, {string:top_topic_posters})
LIMIT 10',
array(
'member_list' => array_keys($members),
'top_topic_posters' => implode(',', array_keys($members)),
)
);
$context['top_starters'] = array();
$max_num_topics = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
{
if(isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]))
{
if(array_intersect(array_merge(array($row_members['id_group'], $row_members['id_post_group']), explode(',', $row_members['additional_groups'])), array_merge(array(1), $modSettings['subforums'][$_SERVER['SERVER_NAME']]['groups'])) == array())
continue;
}

$context['top_starters'][] = array(
'name' => $row_members['real_name'],
'id' => $row_members['id_member'],
'num_topics' => $members[$row_members['id_member']],
'href' => $scripturl . '?action=profile;u=' . $row_members['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
);


find ~ line 534:
Code Select

// Time online top 10.
$temp = cache_get_data('stats_total_time_members', 600);
$members_result = $smcFunc['db_query']('', '
SELECT id_member, real_name, total_time_logged_in
FROM {db_prefix}members' . (!empty($temp) ? '
WHERE id_member IN ({array_int:member_list_cached})' : '') . '
ORDER BY total_time_logged_in DESC
LIMIT 20',
array(
'member_list_cached' => $temp,
)
);
$context['top_time_online'] = array();
$temp2 = array();
$max_time_online = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
{
$temp2[] = (int) $row_members['id_member'];
if (count($context['top_time_online']) >= 10)
continue;


replace with:
Code Select

// Time online top 10.
$temp = cache_get_data('stats_total_time_members', 600);
$members_result = $smcFunc['db_query']('', '
SELECT id_member, real_name, total_time_logged_in, id_group, id_post_group, additional_groups
FROM {db_prefix}members' . (!empty($temp) ? '
WHERE id_member IN ({array_int:member_list_cached})' : '') . '
ORDER BY total_time_logged_in DESC
LIMIT 20',
array(
'member_list_cached' => $temp,
)
);
$context['top_time_online'] = array();
$temp2 = array();
$max_time_online = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
{
if(isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]))
{
if(array_intersect(array_merge(array($row_members['id_group'], $row_members['id_post_group']), explode(',', $row_members['additional_groups'])), array_merge(array(1), $modSettings['subforums'][$_SERVER['SERVER_NAME']]['groups'])) == array())
continue;
}

$temp2[] = (int) $row_members['id_member'];
if (count($context['top_time_online']) >= 10)
continue;


Now the Stats shows only members the have access to the subforum...
Many are stubborn in relation to the path, a few in relation to the target.

ahrasis

#5
2013 January 15, 04:12:59 pm
Thank you very much feline. I am planning to test this when I have a better time. I will report the development in a week or two.

ahrasis

#6
2013 January 27, 07:33:54 am
I was about to reply to this soonest but I have something coming up. In short this is working but not as expected especially for memberlist. It shows a list of empty pages except to the one where there is member in it. My best guess is it is still calling all members but filter to show only subforum members. Thus, the pages where members are not shown is still there but blank page. I wanna provide samples (access) to this but I cant do it now. I will provide this later. I think the Stats are shown correctly but I'll have to do further test which I am unable to do until quite some times.

I am currently booked by my real work. I will be back back when I have freer time for this.

ahrasis

#7
2015 January 12, 06:53:46 am
Quote from: feline ,  2013 January 02, 05:25:32 pm
For the memberlist you can try follow modification you have to make on Memberlist.php


Was checking this line by line while converting this for ElkArte. The issue was actually not globalizing $modSettings. My bad. Your code for memberlist is actually already perfect feline.

ahrasis

#8
2015 January 13, 05:15:48 am
Quote from: feline ,  2013 January 04, 10:50:22 am
Here now the changes for the stats (Sources/Stats.php)


I forgot to mention, since the Online Top 10 was not covered by the above code for stats, I made some additional modifications based on the above code.

Find:
Code Select

// Time online top 10.
$temp = cache_get_data('stats_total_time_members', 600);
$members_result = $smcFunc['db_query']('', '
SELECT id_member, real_name, total_time_logged_in
FROM {db_prefix}members' . (!empty($temp) ? '
WHERE id_member IN ({array_int:member_list_cached})' : '') . '
ORDER BY total_time_logged_in DESC
LIMIT 20',
array(
'member_list_cached' => $temp,
)
);
$context['top_time_online'] = array();
$temp2 = array();
$max_time_online = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
{

Change to:
Code Select

// Time online top 10.
$temp = cache_get_data('stats_total_time_members', 600);
$members_result = $smcFunc['db_query']('', '
SELECT id_member, real_name, total_time_logged_in, id_group, id_post_group, additional_groups
FROM {db_prefix}members' . (!empty($temp) ? '
WHERE id_member IN ({array_int:member_list_cached})' : '') . '
ORDER BY total_time_logged_in DESC
LIMIT 20',
array(
'member_list_cached' => $temp,
)
);
$context['top_time_online'] = array();
$temp2 = array();
$max_time_online = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
{
if(isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]))
{
if(array_intersect(array_merge(array($row_members['id_group'], $row_members['id_post_group']), explode(',', $row_members['additional_groups'])), array_merge(array(1), $modSettings['subforums'][$_SERVER['SERVER_NAME']]['groups'])) == array())
continue;
}


Now Online Top 10 will also limited to the respective subforum only.