Guests view index only

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Anti-Spam Guide
Locked
happypappy
Registered User
Posts: 463
Joined: Wed Apr 27, 2005 1:44 am

Guests view index only

Post by happypappy »

In phpbb2 I had my forum set up so if you weren't logged in you could view the index page and all the forums but couldn't read actually view the topics unless you log in. basically what I am looking for is guests can see index page and all it's forums, you can click on every forum and see the topic lists but if you try to view a topic within the forum you will be prompted to log in. I don't see how to set up permissions like this. Is this still possible? Thanks
Skinny Vinny
Registered User
Posts: 230
Joined: Tue Dec 01, 2009 7:10 pm

Require guests to login to view topic

Post by Skinny Vinny »

Looking at permissions, I don't see that you can display topic lists to guests, but not the topic itself. digging deeper... the option may be gone, but the text still exists in the language file! Found in the en viewtopic file:

Code: Select all

'LOGIN_VIEWTOPIC'		=> 'The board requires you to be registered and logged in to view this topic.',
Correct me if I'm wrong, but at no place in phpbb3 base code does this value ever get used. Suppose it's just there for memories.



This edit will affect all forums/topics; to narrow it to specific forums would require additional code. Since your post indicates you want a general all-guests-must-login solution, well here it is.

We could have skipped calling user->setup in this by placing it further down viewtopic script after its natural call, but I really don't see the need to wait and run all the extra code to that point. So, this can be added much earlier. Find (at or around line 53):

Code: Select all

// Do we have a topic or post id?
if (!$topic_id && !$post_id)
{
	trigger_error('NO_TOPIC');
}


After, add the following:

Code: Select all

// require guests to login to view topic.
if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot'])
{
	$user->setup('viewtopic');
	login_box($_SERVER['REQUEST_URI'], $user->lang['LOGIN_VIEWTOPIC']);
}
And that's it. ALL topics will now require a login from guests but allows bots to still index your topics content. If you don't want bots to index, remove the && !$user->data['is_bot'] part of the mod.

If we're letting bots index the topics, a user can still read the topic without login through a spoofed user agent, or through search engine caches. I don't imagine this is an issue though, as 99.9% of your visitors simply won't know to do that.


Check your en/viewtopic language files to make sure the 'LOGIN_VIEWTOPIC' value exists. If not you can add it there or to common language file, but it's not that important. without it, it simply gives a generic login text.


Very simple version.
Hope this helps.
happypappy
Registered User
Posts: 463
Joined: Wed Apr 27, 2005 1:44 am

Re: Guests view index only

Post by happypappy »

That works wonderfully! Thanks so much :D

You are sure that BOTS will still be able to view the topics content right?
Skinny Vinny
Registered User
Posts: 230
Joined: Tue Dec 01, 2009 7:10 pm

Re: Guests view index only

Post by Skinny Vinny »

Yes, that's what the && !$user->data['is_bot'] part is about.
Glad it works well for you.
Skinny Vinny
Registered User
Posts: 230
Joined: Tue Dec 01, 2009 7:10 pm

Re: Require guests to login to view topic

Post by Skinny Vinny »

Skinny Vinny wrote:If we're letting bots index the topics, a user can still read the topic without login through a spoofed user agent, or through search engine caches. I don't imagine this is an issue though, as 99.9% of your visitors simply won't know to do that.
Updating an old assist, as you can request that google does not cache your pages content with:

Code: Select all

<meta name="googlebot" content="noarchive" />
This would be inserted into the head of overall_header. Wouldn't count on other search engines complying though. Also does nothing for agent spoofs, but the google cache is the most common means to view the hidden content.

Also note that this is considered a form of 'cloaking' in the seo world, and there's a good bit of debate as to whether or not it's acceptable. Many share the opinion that so long as it's not done in a manner to abuse/inflate search ranking that it's most often tolerated, but not guaranteed. I wonder if inclusion of the 'noarchive' option itself is not a flag for a manual review.

A perfect example here is experts exchange. Ranks well for many technical searches, but the content is hidden to the user.

Another consideration since I'm revisiting this request: how many times have you followed a link to a site that immediately halts you with a login/register screen, or partial content requiring an account to continue? Ask yourself just how often you actually register an account with these sites: much of your traffic will move directly to their back button and visit the next site down the list.

Do your homework on this one and draw your own conclusions. If you run a more private forum and/or have little or no concern for seo, then none of this update matters to you!
Skinny Vinny
Registered User
Posts: 230
Joined: Tue Dec 01, 2009 7:10 pm

Re: Guests view index only

Post by Skinny Vinny »

Big update for this one coming soon. Did more homework on the subject, and this is considered cloaking by google. There is a compromise to it though, but it's more than a simple mod. I'll author it soon and update.

Be advised, if you apply this originally scripted above, you risk your forums removal from googles index. Majority of you don't care, I know.
But this is very important.
paracha555
Registered User
Posts: 8
Joined: Sun Oct 26, 2014 8:04 pm

Re: Require guests to login to view topic

Post by paracha555 »

Skinny Vinny wrote:Looking at permissions, I don't see that you can display topic lists to guests, but not the topic itself. digging deeper... the option may be gone, but the text still exists in the language file! Found in the en viewtopic file:

Code: Select all

'LOGIN_VIEWTOPIC'		=> 'The board requires you to be registered and logged in to view this topic.',
Correct me if I'm wrong, but at no place in phpbb3 base code does this value ever get used. Suppose it's just there for memories.



This edit will affect all forums/topics; to narrow it to specific forums would require additional code. Since your post indicates you want a general all-guests-must-login solution, well here it is.

We could have skipped calling user->setup in this by placing it further down viewtopic script after its natural call, but I really don't see the need to wait and run all the extra code to that point. So, this can be added much earlier. Find (at or around line 53):

Code: Select all

// Do we have a topic or post id?
if (!$topic_id && !$post_id)
{
	trigger_error('NO_TOPIC');
}


After, add the following:

Code: Select all

// require guests to login to view topic.
if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot'])
{
	$user->setup('viewtopic');
	login_box($_SERVER['REQUEST_URI'], $user->lang['LOGIN_VIEWTOPIC']);
}
And that's it. ALL topics will now require a login from guests but allows bots to still index your topics content. If you don't want bots to index, remove the && !$user->data['is_bot'] part of the mod.

If we're letting bots index the topics, a user can still read the topic without login through a spoofed user agent, or through search engine caches. I don't imagine this is an issue though, as 99.9% of your visitors simply won't know to do that.


Check your en/viewtopic language files to make sure the 'LOGIN_VIEWTOPIC' value exists. If not you can add it there or to common language file, but it's not that important. without it, it simply gives a generic login text.


Very simple version.
Hope this helps.
GREAT WORK MY BROTHER BUT

Code: Select all

ROOT EDIT VIEWTOPIC.PHP 
CC0149CK
Registered User
Posts: 9
Joined: Fri Jun 19, 2015 10:28 am

Re: Require guests to login to view topic

Post by CC0149CK »

paracha555 wrote:
Skinny Vinny wrote:Looking at permissions, I don't see that you can display topic lists to guests, but not the topic itself. digging deeper... the option may be gone, but the text still exists in the language file! Found in the en viewtopic file:

Code: Select all

'LOGIN_VIEWTOPIC'		=> 'The board requires you to be registered and logged in to view this topic.',
Correct me if I'm wrong, but at no place in phpbb3 base code does this value ever get used. Suppose it's just there for memories.



This edit will affect all forums/topics; to narrow it to specific forums would require additional code. Since your post indicates you want a general all-guests-must-login solution, well here it is.

We could have skipped calling user->setup in this by placing it further down viewtopic script after its natural call, but I really don't see the need to wait and run all the extra code to that point. So, this can be added much earlier. Find (at or around line 53):

Code: Select all

// Do we have a topic or post id?
if (!$topic_id && !$post_id)
{
	trigger_error('NO_TOPIC');
}


After, add the following:

Code: Select all

// require guests to login to view topic.
if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot'])
{
	$user->setup('viewtopic');
	login_box($_SERVER['REQUEST_URI'], $user->lang['LOGIN_VIEWTOPIC']);
}
And that's it. ALL topics will now require a login from guests but allows bots to still index your topics content. If you don't want bots to index, remove the && !$user->data['is_bot'] part of the mod.

If we're letting bots index the topics, a user can still read the topic without login through a spoofed user agent, or through search engine caches. I don't imagine this is an issue though, as 99.9% of your visitors simply won't know to do that.


Check your en/viewtopic language files to make sure the 'LOGIN_VIEWTOPIC' value exists. If not you can add it there or to common language file, but it's not that important. without it, it simply gives a generic login text.


Very simple version.
Hope this helps.
GREAT WORK MY BROTHER BUT

Code: Select all

ROOT EDIT VIEWTOPIC.PHP 
Thank you , working.
Locked

Return to “[3.0.x] MOD Requests”