1 (edited by hacklover99 2013-10-24 00:11)

Topic: [Request] Guest can see hidden forums in home page

WRONG TOPIC, MOVE IT WHERE YOU WANT, MODERATORS

Hi, how can I set permissions to make guests able to see forums (in homepage) only for members, showing them "You must be registred to view this forum"?

I tried to edit index.php at line 26 removing

if (!$forum_user['is_guest']) { }

from the query but nothing appears

2 (edited by hacklover99 2013-10-24 00:09)

Re: [Request] Guest can see hidden forums in home page

Ok lol before I removed a wrong thing.


To do what I need, you must go on line 70 of index.php and replace

// Print the categories and forums
$query = array(
    'SELECT'    => 'c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster',
    'FROM'        => 'categories AS c',
    'JOINS'        => array(
        array(
            'INNER JOIN'    => 'forums AS f',
            'ON'            => 'c.id=f.cat_id'
        ),
        array(
            'LEFT JOIN'        => 'forum_perms AS fp',
            'ON'            => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
        )
    ),
    'WHERE'        => 'fp.read_forum IS NULL OR fp.read_forum=1',
    'ORDER BY'    => 'c.disp_position, c.id, f.disp_position'
);

with

// Print the categories and forums
$query = array(
    'SELECT'    => 'c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster',
    'FROM'        => 'categories AS c',
    'JOINS'        => array(
        array(
            'INNER JOIN'    => 'forums AS f',
            'ON'            => 'c.id=f.cat_id'
        )
    ),
    'ORDER BY'    => 'c.disp_position, c.id, f.disp_position'
);

to make the query for get all forums.



Then, open lang/your_language/common.php and search

'Bad request'

and edit the text.

This works for me on PunBB 1.4
Enjoy PunBB!

Re: [Request] Guest can see hidden forums in home page

Just wanted to say, this works perfectly

It also keeps out other member groups that do not have permission.

You can see the forum on the board but when you click on it you cannot read unless you have the specified member level.

I edited my language file to say....

This forum is restricted to a specific member level.

4 (edited by KamWest 2021-06-12 22:13)

Re: [Request] Guest can see hidden forums in home page

Everytime I implement this I get the following in my error log.

It only happens when members visit the index page that do not have access to the restricted forum



in /home/ca6413/public_html/index.php on line 155
[12-Jun-2021 20:39:34 UTC] PHP Warning:  Invalid argument supplied for foreach() in /home/ca6413/public_html/index.php on line 155


This is what my line 155 looks like

https://i.postimg.cc/3wJMzw0k/Picture0212.png



The error goes away when I change it back and remove hacklover99's changes.


It looks to me like there is a small error of some kind

Anyone have any ideas?

Re: [Request] Guest can see hidden forums in home page

replace

if (!$forum_user['is_guest'] && $cur_forum['last_post'] > $forum_user['last_visit'] && (empty($tracked_topics['forums'][$cur_forum['fid']]) || $cur_forum['last_post'] > $tracked_topics['forums'][$cur_forum['fid']]))

to

if (!$forum_user['is_guest'] && isset($new_topics[$cur_forum['fid']]) && is_array($new_topics[$cur_forum['fid']]) && $cur_forum['last_post'] > $forum_user['last_visit'] && (empty($tracked_topics['forums'][$cur_forum['fid']]) || $cur_forum['last_post'] > $tracked_topics['forums'][$cur_forum['fid']]))
ForkBB
I speak only Russian  :P

Re: [Request] Guest can see hidden forums in home page

@Visman that is perfect and it fixes the error log.

It took me a while to find the error and I thought the mod posted by @hacklover99 was working but when a member who did not have access to the forum visited the error was generated.


Thank you for the fix and may I suggest nobody install this unless you make the changes noted by @Visman