Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: Robert. in April 15, 2012, 12:17:18 NACHMITTAGS

Titel: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Robert. in April 15, 2012, 12:17:18 NACHMITTAGS
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.
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Robert. in April 15, 2012, 12:42:31 NACHMITTAGS
I have also packaged this in a mod and submitted this to the mod site. :)
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Spectrum..!! in April 15, 2012, 08:28:52 NACHMITTAGS
Good, very good trick.

Thank you.
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Colin in April 15, 2012, 08:33:06 NACHMITTAGS
Very helpful. Thanks!
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Adrek in April 16, 2012, 04:55:45 VORMITTAG
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?
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Robert. in April 16, 2012, 07:45:52 VORMITTAG
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
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: soumarin in April 17, 2012, 10:18:15 NACHMITTAGS
thanks i hade the same question
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Robert. in April 18, 2012, 01:14:02 VORMITTAG
You're welcome :)
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Adrek in April 18, 2012, 03:54:25 VORMITTAG
and what if I want redirect guests to the login page only in selected boards?
is there any way to do this?
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Robert. in April 18, 2012, 04:35:28 VORMITTAG
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. :)
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Adrek in April 18, 2012, 04:56:13 VORMITTAG
thanks ;)
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: shubha in April 20, 2012, 11:53:49 NACHMITTAGS
Thanks but already a mod is there.  "Look but no read".
Titel: PLEASE HELP ME
Beitrag von: fifacluborg in Mai 02, 2012, 09:21:24 VORMITTAG
Zitat von: 医生唱片骑师 in April 15, 2012, 12:17:18 NACHMITTAGS
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... :(
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Robert. in Mai 02, 2012, 09:41:35 VORMITTAG
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
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: CHAOS-THEORY in Dezember 20, 2013, 05:20:15 NACHMITTAGS
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
Titel: Re: [Trick] Redirect guests to the login page when trying to view a topic
Beitrag von: Colin in Dezember 20, 2013, 09:52:32 NACHMITTAGS
Haha, glad you finally found it :)