Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: rcane on November 27, 2021, 10:08:26 AM

Title: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on November 27, 2021, 10:08:26 AM
Good morning Gurus:

I'd like to have the 'guests' memberGroup (and perhaps one other group) be restricted from seeing the NEWS feature window.

I found a mod for it called Advanced News but it wouldn't work (wasn't entirely for 2.0.18).

I've never written in php before, only swift for iOS, but I'd like to give it a shot. 

Any guidance would be greatly appreciated.

Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: Sir Osis of Liver on November 27, 2021, 05:24:48 PM
This will hide it from guests -

BoardIndex.template.php



/// hide info center from guests
if ($context['user']['is_logged'])
template_info_center();

}

function template_info_center()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;

Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on November 27, 2021, 05:26:41 PM
Quote from: Sir Osis of Liver on November 27, 2021, 05:24:48 PMThis will hide it from guests -

BoardIndex.template.php



/// hide info center from guests
if ($context['user']['is_logged'])
template_info_center();

}

function template_info_center()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;



Hi and thanks,

This is for the info center though; I was referring to the NEWS feature at the top of the page.   I don't allow guests so the only "guests" are folks looking at the registration and/or login page.  But, the NEWS still appears for those initial views.  Trying to keep that under wraps.
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: Shades. on November 27, 2021, 05:47:27 PM
Maybe this will help... 8)

https://www.simplemachines.org/community/index.php?topic=515425.msg3644601#msg3644601

Works for 2.0 & 2.1 ;)
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: Sir Osis of Liver on November 27, 2021, 06:00:42 PM
Ooofa, don't know how I misread that.  Do you want to hide the random news item, news fader, or both?
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on November 27, 2021, 06:45:12 PM
Quote from: Shades. on November 27, 2021, 05:47:27 PMMaybe this will help... 8)

https://www.simplemachines.org/community/index.php?topic=515425.msg3644601#msg3644601

Works for 2.0 & 2.1 ;)

elegant & genius.
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on November 27, 2021, 06:46:03 PM
Quote from: Sir Osis of Liver on November 27, 2021, 06:00:42 PMOoofa, don't know how I misread that.  Do you want to hide the random news item, news fader, or both?


Well both actually.  But if this is the easiest fix, then just this. 

Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on November 27, 2021, 06:52:08 PM
Quote from: rcane on November 27, 2021, 06:46:03 PM
Quote from: Sir Osis of Liver on November 27, 2021, 06:00:42 PMOoofa, don't know how I misread that.  Do you want to hide the random news item, news fader, or both?


Well both actually.  But if this is the easiest fix, then just this. 

It seems like this fix above works fine for both. 

I need a good book on this.  Trying to understand all the php files and their relationships in SMF is overwhelming.


Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on November 28, 2021, 01:05:23 PM
Quote from: Shades. on November 27, 2021, 05:47:27 PMMaybe this will help... 8)

https://www.simplemachines.org/community/index.php?topic=515425.msg3644601#msg3644601

Works for 2.0 & 2.1 ;)

A follow-up question to this solution:

If I have another restricted memberGroup I'd like to prevent from seeing news, can I add it within this code as an "or", or would I have to duplicate the entire statement for the new group?

And if that group's name was a two word, like "pending approval" would it require an underscore between the words?

if ($user_info['is_guest'])
    $settings['enable_news'] = false;
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: Sir Osis of Liver on November 28, 2021, 10:32:46 PM


if ($user_info['is_guest']) || $user_info['groups']['0'] == 9)
    $settings['enable_news'] = false;


9 would be id_group of the membergroup you want to block.  Members pending approval are guests.


Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: Diego Andrés on November 29, 2021, 02:06:30 AM
in_array could probably be another option instead of [groups][0], the user could have primary and additional groups too and might fail
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on November 29, 2021, 12:07:10 PM
Sir Osis, thanks.  I'll try that.

And Diego, a person wouldn't have conflicting groups if that is what you meant. 

If they are in that restricted group (in the door but not full access to the forums) they can't have additional groups.  I think this should work.
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on November 29, 2021, 12:11:24 PM
Quote from: Sir Osis of Liver on November 28, 2021, 10:32:46 PM
if ($user_info['is_guest']) || $user_info['groups']['0'] == 9)
    $settings['enable_news'] = false;


9 would be id_group of the membergroup you want to block.  Members pending approval are guests.




I replaced the "9", with:  13   (which is the group id of the desired group to block). 

The entire forum was inaccessible.   admin level too.  couldn't even bring up the login page.  :)

I think there was a typ. lol.    I entered it as a separate conditional statement below the one restricting guests.  Seems to work. 

If you can explain, what is the [groups]['0'] == 9 part ?  I get the 9 == the group in question, but why the zero in the braces after "group"?
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: Diego Andrés on November 29, 2021, 12:57:07 PM
It's the index of the first element in the array of groups. In theory that should be either the primary group or the first group found
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: Kindred on November 29, 2021, 01:00:07 PM
the forum was not accessible because your code is wrong...   it has an extra closing ) which will definitely break everything.

should be this

if ($user_info['is_guest'] || $user_info['groups']['0'] == 9)
    $settings['enable_news'] = false;


Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on February 03, 2022, 10:44:29 PM
Quote from: Diego Andrés on November 29, 2021, 12:57:07 PMIt's the index of the first element in the array of groups. In theory that should be either the primary group or the first group found

It's been a while and I'm building 3 more SFM's.  I tried implementing this again (though now the group in question is "10" and not "13" in this install...ordering I suppose.  It's not working though. 

Can't figure out why....
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: Diego Andrés on February 03, 2022, 11:33:53 PM
Because like I said in my previous post, using that code could be inconsistent.
You should instead use something like this:  if (in_array(12, $user_info['groups']))
Where 12 is the id of the group.

Searching for multiple:
if (in_array(12, $user_info['groups']) || in_array(7, $user_info['groups']))
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on February 03, 2022, 11:40:32 PM
Quote from: Diego Andrés on February 03, 2022, 11:33:53 PMBecause like I said in my previous post, using that code could be inconsistent.
You should instead use something like this:  if (in_array(12, $user_info['groups']))
Where 12 is the id of the group.

Searching for multiple:
if (in_array(12, $user_info['groups']) || in_array(7, $user_info['groups']))

no i understood.  searching the array was better than position 0. 

this test account only has one member group and it's still not working. going to go check permissions and see if i missed something
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: Diego Andrés on February 03, 2022, 11:45:56 PM
Anything in the error log?
Did you add $user_info to the globals in the function you are adding this code?
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on February 03, 2022, 11:53:36 PM
Quote from: Diego Andrés on February 03, 2022, 11:45:56 PMAnything in the error log?
Did you add $user_info to the globals in the function you are adding this code?


yeah, it's already in the function.  no error logs. works fine on my other smf.
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on February 04, 2022, 12:24:41 AM
it's the fader.  i had that enabled.  i need to find the fader feature as that's what is set to show
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on February 04, 2022, 12:42:04 AM
Quote from: rcane on February 04, 2022, 12:24:41 AMit's the fader.  i had that enabled.  i need to find the fader feature as that's what is set to show

I mean, fader was set in theme settings. enable_news = false isn't affecting that.
Title: In sources\subs.php is there a function for the news fader?
Post by: rcane on February 04, 2022, 08:47:21 AM
A while back I saw some ideas here on refusing to show the news based on a person's group number.

It worked well for the news when shown in the header but not when using the fader.


is there an equivalent to "enable_news" for the fader?

I am unsure if enable_ is a php command or a function here.
   
Title: Re: In sources\subs.php is there a function for the news fader?
Post by: Kindred on February 04, 2022, 09:15:36 AM
Theme settings: Show news fader on board index

in BoardIndex.template.php
// Show the news fader?  (assuming there are things to show...)
if ($settings['show_newsfader'] && !empty($context['fader_news_lines']))
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: Kindred on February 04, 2022, 09:16:40 AM
can you please not open multiple threads with the same question...

merging your other thread in.
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on February 04, 2022, 10:11:50 AM
Quote from: Kindred on February 04, 2022, 09:16:40 AMcan you please not open multiple threads with the same question...

merging your other thread in.

didn't intend for it that way, but one was about news..the other fader.   syllogistically related, but I couldn't remove the other.
Title: Re: Could someone guide me on restricting the NEWS panel from specific membergroups?
Post by: rcane on February 04, 2022, 10:24:10 AM
Quote from: Kindred on February 04, 2022, 09:15:36 AMTheme settings: Show news fader on board index

in BoardIndex.template.php
// Show the news fader?  (assuming there are things to show...)
if ($settings['show_newsfader'] && !empty($context['fader_news_lines']))

The group in question is "10".

The hope would be by adding && !in_array(10, $user_info['groups'])   in there it wouldn't process the news fader if you're in group 10--only showing to anyone NOT in that group.

But, putting in there didn't have an effect on any group.

What did have affect was taking out the "!". 

That removed the fader for everyone, including the admin (group 1).