Support Forum

Make restricted areas grey for members with no access

JK Julian Paul Francis Kitagawa
Julian Paul Francis Kitagawa
Member

Sorry if this is written somewhere, but I couldn’t find anything.

I have multiple usergroups set up, and right now members only see forums that they have access to.

How can I make these show in grey (like this forum does). Basically I want users with no access to see what they’re missing out on ;)

20 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

This comes in two stages, the second of which is a little theme customisation. So I suggest we start with the first…

We use what we call the ‘sneak peek’ feature. For those user groups that are NOT allowed to access a forum we turn on the permission ‘Can view a list of forums and list of topics only‘. This allows the lists to be viewed but no posts within a topic.

Then in the forum admin > components > custom messages – you can optionally set up a message that will display to those users – or a url redirect that could go to a sign-up page or something like that.

So that covers showing the forums and/or topic listings to groups of users who can not access the actual posts. As I say – the next bit – the greying – involves some custom work to your theme template and CSS files. If you want to go that far then we can walk you through the changes but before we do that you will need to make a custom or child theme. The child theme is the easiest and best way to go – see this post for details: https://simple-press.com/simplepress-version-5-5-child-themes/

JK Julian Paul Francis Kitagawa
Julian Paul Francis Kitagawa
Member

Thanks, as always, for your swift reply.

I’ve made those changes in the settings, and added a “default child” theme.

Would you let me know what I need to change?

Thank you. 

YS Yellow Swordfish
Yellow Swordfish
Member

First step: In you child theme CSS file you can, of course, remove everything tyhat was from the parent – but add:

.spOpaque {
    opacity: .5;
}

Next you will need to copy from the parent to the child theme the template spGroupView.php. In the middle of that template you will see calls to the function sp_ColumnStart() – probably abot 4 of them. They will look more or less like this depending upon the theme:

sp_ColumnStart("tagClass=spColumnSection spLeft&width=6%&height=55px");

You need to make an insert into EACH one in the template like this:

sp_ColumnStart("tagClass=spColumnSection spLeft$spOpaque&width=6%&height=55px");

Note the insertion of the $spOpaque – no spaces either side.

Finally below this line of code (and the following comment) add:

$spOpaque = '';
if($spThisUser->guest && $spThisGroup->group_id != XX) $spOpaque = ' spOpaque';

Note the XX. This needs to equal the ID of the forum group that your guests CAN post to. You can get the ID from the Manage Groups and Forums admin panel. Also note the space character in ‘ spOpaque’. better to use the view raw code button and copy and paste as needed,

OK?

JK Julian Paul Francis Kitagawa
Julian Paul Francis Kitagawa
Member

Sorry, can I just clarify exactly what I need in the “default child” folder? I thought it was a case of just copying the whole theme folder and adding “parent: default” to the spTheme.txt file.

… but I now see this probably isn’t the case, as the child-theme isn’t working.

MP Mr Papa
Mr Papa
Member

no… like in the article, create it empty…   add in a styles and templates directory, also empty…

in the child directory, you need a spTheme.txt file which lists the parent and the stylesheet…

in the child styles directory, you will need mostly empty stylesheet and just add your changes…

in the child templates directory, copy over any templates that you want to modify and make your changes… you only need to copy the ones you want to change…

here is a shell of a default child you can use…

just add your new styles per Andy’s feedback and then copy from default the template files and modify (just the ones you want to change)…

JK Julian Paul Francis Kitagawa
Julian Paul Francis Kitagawa
Member

Mr Papa – thank you. 

I’ve made the changes, but I’m finding the layout gets all messed up. All of the columns are getting pushed over to the left side, if that makes sense.

I’m guessing it’s a problem with this line:

if($spThisUser->guest && $spThisGroup->group_id != 4) $spOpaque = ‘ spOpaque’;

I wasn’t too sure what you meant by “Finally below this line of code (and the following comment)”

I’ve copied the code below (I figured that’d be easier).

 

.

.

 

<?php
# ————————————————————————————–
#
# Simple:Press Template
# Theme : Default
# Template : group
# Author : Simple:Press
#
# The ‘group’ template is used to display the Group/Forum Index Listing
#
# ————————————————————————————–

# Load the forum header template – normally first thing
# ———————————————————————-
sp_SectionStart(‘tagClass=spHeadContainer’, ‘head’);
sp_load_template(‘spHead.php’);
sp_SectionEnd(”, ‘head’);

sp_SectionStart(‘tagClass=spBodyContainer’, ‘body’);

# Start the ‘groupView’ section
# ———————————————————————-
sp_SectionStart(‘tagClass=spListSection’, ‘groupView’);

# Start the Group Loop
# ———————————————————————-
if (sp_has_groups()) : while (sp_loop_groups()) : sp_the_group();

# Start the ‘groupHeader’ section
# ———————————————————————-
sp_SectionStart(‘tagClass=spGroupViewSection’, ‘group’);
sp_GroupHeaderRSSButton(‘tagClass=spButton spRight’, __sp(‘Group RSS’), __sp(‘Subscribe to the RSS feed for this forum group’));
sp_GroupHeaderIcon(‘tagClass=spHeaderIcon spLeft’);
sp_GroupHeaderName(‘tagClass=spHeaderName’);
sp_InsertBreak(‘direction=right’);
sp_GroupOpenClose(‘tagClass=spIcon spRight&default=open’, ‘Open forum listing’, ‘Close forum listing’);
if (function_exists(‘sp_ShareThisTag’)) sp_ShareThisTag(‘tagClass=ShareThisTag spRight’);
sp_GroupHeaderDescription(‘tagClass=spHeaderDescription’);
sp_GroupHeaderMessage(‘tagClass=spHeaderMessage’);

sp_InsertBreak();

sp_SectionStart(‘tagClass=spGroupForumContainer’, ‘forumlist’);

# Start the Forum Loop
# ———————————————————————-
if (sp_has_forums()) : while (sp_loop_forums()) : sp_the_forum();

# Start the ‘forum’ section
# ———————————————————————-
sp_SectionStart(‘tagClass=spGroupForumSection’, ‘forum’);

# Column 1 of the forum row
# ———————————————————————-
sp_ColumnStart(‘tagClass=spColumnSection spLeft$spOpaque&width=6%&height=55px’);
$spOpaque = ”;
if($spThisUser->guest && $spThisGroup->group_id != 4) $spOpaque = ‘ spOpaque’;

sp_ForumIndexIcon(‘tagClass=spRowIcon spLeft’);
sp_ColumnEnd();

# Column 2 of the forum row
# ———————————————————————-
sp_ColumnStart(‘tagClass=spColumnSection spLeft$spOpaque&width=48%&height=55px’);
$spOpaque = ”;
if($spThisUser->guest && $spThisGroup->group_id != 4) $spOpaque = ‘ spOpaque’;

sp_ForumIndexName(‘tagClass=spRowName’, __sp(‘Browse topics in %NAME%’));
sp_ForumIndexDescription(‘tagClass=spRowDescription’);
sp_ForumIndexPageLinks(‘tagClass=spInRowPageLinks spLeft’, __sp(‘Jump to page %PAGE% of topics’));
sp_ColumnEnd();

# Column 4 of the forum row
# ———————————————————————-
sp_ColumnStart(‘tagClass=spColumnSection spRight$spOpaque&width=32%&height=55px’);
$spOpaque = ”;
if($spThisUser->guest && $spThisGroup->group_id != 4) $spOpaque = ‘ spOpaque’;
sp_ForumIndexLastPost(‘tagClass=spInRowPostLink&nicedate=1&date=0&time=0&stackdate=0’, __sp(‘Last Post’), __sp(‘No Topics’));
sp_ColumnEnd();

# Column 3 of the forum row
# ———————————————————————-
sp_ColumnStart(‘tagClass=spColumnSection spRight$spOpaque&width=14%&height=55px’);
$spOpaque = ”;
if($spThisUser->guest && $spThisGroup->group_id != 4) $spOpaque = ‘ spOpaque’;
sp_ForumIndexTopicCount(‘tagClass=spInRowCount’, __sp(‘Topics’), __sp(‘Topic’));
sp_ForumIndexPostCount(‘tagClass=spInRowCount’, __sp(‘Posts’), __sp(‘Post’));
sp_ForumIndexStatusIcons(‘tagClass=spStatusIcon spCenter’, __sp(‘This forum is locked’), __sp(‘This forum has unread posts in %COUNT% topic(s)’), __sp(‘Add new topic in this forum’), __sp(‘No permission to start topics’));
sp_ColumnEnd();

sp_InsertBreak();

sp_ForumIndexSubForums(‘unreadIcon=sp_SubForumUnreadIcon.png’, __sp(‘Sub-Forums’), __sp(‘Browse topics in %NAME%’));
sp_SectionEnd(”, ‘forum’);

endwhile; else:
sp_NoForumsInGroupMessage(‘tagClass=spMessage’, __sp(‘There are no forums in this group’));
endif;

sp_SectionEnd(”, ‘forumlist’);

sp_SectionEnd(”, ‘group’);

endwhile; else:
sp_NoGroupMessage(‘tagClass=spMessage’, __sp(‘The requested group does not exist or you do not have permission to view it’), __sp(‘No groups have been created yet’));
endif;

sp_SectionEnd(”, ‘groupView’);

sp_RecentPostList(‘show=10’, __sp(‘Unread and recently updated topics’));

sp_SectionEnd(”, ‘body’);

# Load the forum footer template – normally last thing
# ———————————————————————-
sp_SectionStart(‘tagClass=spFootContainer’, ‘foot’);
sp_load_template(‘spFoot.php’);
sp_SectionEnd(”, ‘foot’);

?>

MP Mr Papa
Mr Papa
Member

It looks like you didnt copy this part right:

sp_ColumnStart("tagClass=spColumnSection spLeft$spOpaque&width=6%&height=55px");

note, yours starts and ends with single quotes… must be double quotes…

JK Julian Paul Francis Kitagawa
Julian Paul Francis Kitagawa
Member

Thank you.

Everything is displaying correctly now. I’m not seeing anything different for members with no access though. the colour is just the same as normal (i.e. not semi-opaque).

I’ve checked, and members don’t have access to anything they shouldn’t, so the roles are definitely working properly. 

JK Julian Paul Francis Kitagawa
Julian Paul Francis Kitagawa
Member

update:

This *is* working fine for guests; it’s just my (custom) usergroup it’s not working for. 

MP Mr Papa
Mr Papa
Member

not sure what you mean….  custom usergroup???

the code you have is checking against a specific group, but not usergroup… do you really mean group?

If so, is group id of 4 what you want?  its the id of the group of forums that you want to be greyed out…  and the way you have it defined, only guests will see the group greyed…

or do you really want a specific usergroup to also see it greyed out as well as guests??  this is a bit different than what you set out to do…

if so, you might want to try changing:

if($spThisUser->guest && $spThisGroup->group_id != 4) $spOpaque = ' spOpaque';

to

if (!sp_can_view($spThisForum->forum_id, 'post-content')) $spOpaque = ' spOpaque';

but not entirely sure what you want to do…  this would grey out the forum in group view for anyone that cannot view the actual post content (ie sneak peek)…

JK Julian Paul Francis Kitagawa
Julian Paul Francis Kitagawa
Member

Yes, I’m sorry, while having lunch I just realised myself what I’d done.

I have two levels of members with different levels of access to the forum. Guests have no access to anything at all.

This worked perfectly, thank you, and sorry again for the confusion.

JK Julian Paul Francis Kitagawa
Julian Paul Francis Kitagawa
Member

I’m sorry to come back with this one…

But it seems after the recent update, this stopped working.

I’m also getting the message “Either the theme CSS file and/or color Overlay file from the selected theme is missing” in the “themes” admin panel, as well as the following warning (I don’t know if it’s related though):

February 20, 2015 12:52 am | spaErrWarning | 40 | php


file: /simple-press/sp-api/sp-api-filters.php
line: 1777
function: htmlspecialchars
Warning | htmlspecialchars() [function.htmlspecialchars]: Invalid multibyte sequence in argument