Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Now Available => Topic started by: Joker™ on January 09, 2011, 12:29:47 PM

Title: Hide the content of [code] tags from guests
Post by: Joker™ on January 09, 2011, 12:29:47 PM
I was personally having the problem on my forum that people were posting links in code tag which was visible to guests, so as to overcome this problem we can now hide the whole data in code tag from guests.

To do so, you just have to make following edits;

In Themes\Default\Languages\Modification.english.php

Find:
Code: [Select]
?>
Add Before:
Code: [Select]
$txt['something'] = 'Only registered users can see contents.';
$txt['blabla'] = 'Please click here to <a target="_blank" href="' . $scripturl . '?action=register"">Register</a> or <a target="_blank" href="' . $scripturl . '?action=login">Login</a>';


In Sources/Subs.php

Find:
Code: [Select]
'tag' => 'code',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',

Replace it with:
Code: [Select]
'tag' => 'code',
'type' => 'unparsed_content',
'content' => $user_info['is_guest'] ? '<div class="codeheader">' . $txt['code'] . ': </div><code class="bbc_code">' . $txt['something'] . ' ' . $txt['blabla'] . '</code>' :  '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',


You can change text strings as you like.


This trick is available as mod also, here (http://custom.simplemachines.org/mods/index.php?mod=2953).
Title: Re: Hide the content of [code] tags from guests
Post by: Illori on January 09, 2011, 12:45:33 PM
this might be better on the tips board. it is a nice idea for some forums.
Title: Re: Hide the content of [code] tags from guests
Post by: tesser on January 09, 2011, 01:07:43 PM
arantor had a mod that works for RC3 but it also works on RC4  that did the  hide code  from guests  ;D lucky me i have it now his site is gone.
Title: Re: Hide the content of [code] tags from guests
Post by: Joker™ on January 09, 2011, 01:14:14 PM
arantor had a mod that works for RC3 but it also works on RC4  that did the  hide code  from guests  ;D lucky me i have it now his site is gone.
I must have missed that mod.


For working demo of code above you can open any non-sticky post from this board (http://www.freakygurus.com/index.php?board=67.0).
Title: Re: Hide the content of [code] tags from guests
Post by: Illori on January 09, 2011, 01:20:53 PM
might be slightly more professional to add a space in the code replacement
Code: [Select]
Only registered users can see contents.Please click here to Register or Login and replace with
Code: [Select]
Only registered users can see this content. Please click here to Register or Login.
Title: Re: Hide the content of [code] tags from guests
Post by: Arantor on January 09, 2011, 01:30:55 PM
Quote
I must have missed that mod.

I did a mega version of the 'registered links' mod that did code tags as well, also provided the option to only hide links that aren't internal ones.
Title: Re: Hide the content of [code] tags from guests
Post by: Joker™ on January 09, 2011, 01:31:56 PM
might be slightly more professional to add a space in the code replacement
Code: [Select]
Only registered users can see contents.Please click here to Register or Login and replace with
Code: [Select]
Only registered users can see this content. Please click here to Register or Login.
Thanks for the suggestion. Made the changes in above code regarding the space you have mentioned.
Title: Re: Hide the content of [code] tags from guests
Post by: Joker™ on January 09, 2011, 01:34:30 PM
Quote
I must have missed that mod.

I did a mega version of the 'registered links' mod that did code tags as well, also provided the option to only hide links that aren't internal ones.
Nice to see the biggest spammer back ;D.
Title: Re: Hide the content of [code] tags from guests
Post by: Arantor on January 09, 2011, 01:36:20 PM
I wouldn't call it back, seeing how the support I'm doing is extremely limited, mostly to assess things that I think need to be fixed in SMF, and that none of the mods that were on arantormods.com are being published anywhere by me, in fact the only place to get them now is a paid site I gave them to, so they could sell the mods to folks.
Title: Re: Hide the content of [code] tags from guests
Post by: Joker™ on January 09, 2011, 01:43:40 PM
I wouldn't call it back, seeing how the support I'm doing is extremely limited, mostly to assess things that I think need to be fixed in SMF, and that none of the mods that were on arantormods.com are being published anywhere by me, in fact the only place to get them now is a paid site I gave them to, so they could sell the mods to folks.
Lol, I myself was busy like hell in past month, even missed to celebrate new year :-X.
Title: Re: Hide the content of [code] tags from guests
Post by: Cowley on January 31, 2011, 07:13:34 PM
Thank you so much for your advice. Exactly what I was looking for!  ;)
Title: Re: Hide the content of [code] tags from guests
Post by: Jeet Chowdhury on February 01, 2011, 11:25:49 AM
I was personally having the problem on my forum that people were posting links in code tag which was visible to guests, so as to overcome this problem we can now hide the whole data in code tag from guests.

To do so, you just have to make following edits;

In Themes\Default\Modification.english.php

Find:
Code: [Select]
?>
Add Before:
Code: [Select]
$txt['something'] = 'Only registered users can see contents.';
$txt['blabla'] = 'Please click here to <a target="_blank" href="' . $scripturl . '?action=register"">Register</a> or <a target="_blank" href="' . $scripturl . '?action=login">Login</a>';


In Sources/Subs.php

Find:
Code: [Select]
            'tag' => 'code',
            'type' => 'unparsed_content',
            'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',

Replace it with:
Code: [Select]
            'tag' => 'code',
            'type' => 'unparsed_content',
            'content' => $user_info['is_guest'] ? '<div class="codeheader">' . $txt['code'] . ': </div><code class="bbc_code">' . $txt['something'] . ' ' . $txt['blabla'] . '</code>' :  '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',


You can change text strings as you like.

how to hide quote tag also?


also after login user backto forum index. how to log him back to where he is actually?
Title: Re: Hide the content of [code] tags from guests
Post by: Matthew K. on February 01, 2011, 11:45:28 AM
The same way you would with the code tags...only for the quote tags.
Title: Re: Hide the content of [code] tags from guests
Post by: Joker™ on February 01, 2011, 12:10:31 PM
The same way you would with the code tags...only for the quote tags.
That depends that how the data of quotes is being handled. I may take a look at the file in a bit.
Title: Re: Hide the content of [code] tags from guests
Post by: Joker™ on February 02, 2011, 08:29:36 AM
Lol hiding data in quotes seems to bit tricky as last night I was unable to find how that data is supplied in quotes tag, I will this thing a shot tonight for sure.
Title: Re: Hide the content of [code] tags from guests
Post by: Arantor on February 02, 2011, 08:32:23 AM
You actually can't directly rewrite quote tags because the contents of the tag is never supplied to the parser (since it can contain other tags)

All you can do is what I used to do in my registered-links mod: rewrite the start and end tags in the validate function to something else, then strip them out in the obsess_rewrite buffer.
Title: Re: Hide the content of [code] tags from guests
Post by: Joker™ on February 02, 2011, 08:36:05 AM
You actually can't directly rewrite quote tags because the contents of the tag is never supplied to the parser (since it can contain other tags)
That's what I thought after seeing "Remove images from quotes tag" mod.


Quote
All you can do is what I used to do in my registered-links mod: rewrite the start and end tags in the validate function to something else, then strip them out in the obsess_rewrite buffer.
Umm that seems to be a bit above my head.
Title: Re: Hide the content of [code] tags from guests
Post by: steeltape on May 24, 2011, 09:47:12 AM
hi this is very useful mod for me and i'm grateful that you share this with us the leechers
however, there is no Themes\Default\Modification.english.php file in my default theme nor my other sub themes.
so how?

smf 2.0 rc5
Title: Re: Hide the content of [code] tags from guests
Post by: mashby on May 24, 2011, 09:55:26 AM
Try one level down, so:
Themes/default/languages/Modifications.english.php
Title: Re: Hide the content of [code] tags from guests
Post by: Joker™ on May 24, 2011, 10:24:20 AM
Try one level down, so:
Themes/default/languages/Modifications.english.php
Thanks for pointing out the error ;).
Title: Re: Hide the content of [code] tags from guests
Post by: steeltape on May 28, 2011, 09:08:23 AM
thank you very much  :laugh:
Title: Re: Hide the content of [code] tags from guests
Post by: emanuele on June 11, 2011, 07:40:28 AM
/me points to his mod (http://custom.simplemachines.org/mods/index.php?mod=2861)...is this unsolicited advertising? :P
Title: Re: Hide the content of [code] tags from guests
Post by: Masterd on June 11, 2011, 08:08:57 AM
It depends on your intentions.