Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Robert. on April 15, 2012, 12:17:18 PM

Title: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Robert. on April 15, 2012, 12:17:18 PM
Index.php
Find
// Board is not empty... topic is not empty... action is empty.. Display!
else
{
require_once($sourcedir . '/Display.php');
return 'Display';
}

Replace with
// Board is not empty... topic is not empty... action is empty.. Display!
elseif(!empty($topic) && $context['user']['is_logged'])
{
require_once($sourcedir . '/Display.php');
return 'Display';
}
elseif(!empty($topic) && !$context['user']['is_logged']) {
require $sourcedir . '/LogInOut.php';
return 'Login';
}

And change
global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir
To
global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir, $context
Not heavily tested but should work :) Actually it shows the login page rather than redirecting, but it has the same effect.
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Robert. on April 15, 2012, 12:42:31 PM
I have also packaged this in a mod and submitted this to the mod site. :)
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Spectrum..!! on April 15, 2012, 08:28:52 PM
Good, very good trick.

Thank you.
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Colin on April 15, 2012, 08:33:06 PM
Very helpful. Thanks!
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Adrek on April 16, 2012, 04:55:45 AM
I'm just curious, what is the difference between Hide Topics from Guests (http://custom.simplemachines.org/mods/index.php?mod=2380) and this trick?
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Robert. on April 16, 2012, 07:45:52 AM
You're welcome :)

@Phantomm: this mod has a very small difference in functionality. This mod just shows a login page when a guest tries to read topics. Hide Topics from Guests is a more advanced mod. :P

Just wondering though, does anyone have problems with this trick? I haven't got problems with it myself, but I was told that admins can't see topics either. =/ Doesn't happen to me though
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: soumarin on April 17, 2012, 10:18:15 PM
thanks i hade the same question
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Robert. on April 18, 2012, 01:14:02 AM
You're welcome :)
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Adrek on April 18, 2012, 03:54:25 AM
and what if I want redirect guests to the login page only in selected boards?
is there any way to do this?
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Robert. on April 18, 2012, 04:35:28 AM
Yup, but it would require a few extra edits. I'm quite busy with other stuff right now, but I will look into it when I have some time. :)
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Adrek on April 18, 2012, 04:56:13 AM
thanks ;)
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: shubha on April 20, 2012, 11:53:49 PM
Thanks but already a mod is there.  "Look but no read".
Title: PLEASE HELP ME
Post by: fifacluborg on May 02, 2012, 09:21:24 AM
Quote from: 医生唱片骑师 on April 15, 2012, 12:17:18 PM
And change
global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir
To
global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir, $context
Not heavily tested but should work :) Actually it shows the login page rather than redirecting, but it has the same effect.
I not find this line! Can anyone tell me what file I find?
I did have searched in index.php and I not found nothing there... :(
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Robert. on May 02, 2012, 09:41:35 AM
You can find that in the index.php in the root of your forum (there are multiple index.php, each directory has one :P). ;) Also, I'm planning to release an updated version soon (Thanks Labradoodle :) ). ;D
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: CHAOS-THEORY on December 20, 2013, 05:20:15 PM
u sir is ae pure genius,
i have searched for this kind of - S aech ai Tee - for 5 hours straigh, i can't feel ma eyes.
then suddenly this topic comes up; thanks dude.
and for your information posters, all the packages u provided aren't working anymore / deleted or  just drown; this one right here, this trick is working like ae boss in my latest SMF release.
respect earned
*GTA SA theme song playing* ill add u 

[edit]tt removed -- Illori
Title: Re: [Trick] Redirect guests to the login page when trying to view a topic
Post by: Colin on December 20, 2013, 09:52:32 PM
Haha, glad you finally found it :)