News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Hiding contents of [code] and [url]

Started by thepitster, September 11, 2017, 04:05:31 PM

Previous topic - Next topic

thepitster

I am trying to find a way to do this with [url][/url], I have already found a way, here on the forums to hide the contents of [code][/code] tags, working with SMF 2.0.14 in Subs.php if you find these lines
'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '</pre>' : ''),
and
'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '</pre>' : ''),
and add
$user_info['posts'] < 5 ? '<b>You need a 5 post minimum to see code and url tags! </b>' :
like so:
'content' => $user_info['posts'] < 5 ? '<b>You need a 5 post minimum to see code and url tags! </b>' : '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '</pre>' : ''),
'content' => $user_info['posts'] < 5 ? '<b>You need a 5 post minimum to see code and url tags! </b>' : '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '</pre>' : ''),

It works well to hide code tags stuff from users with less then 5 posts, but how can one go about hiding the contents of url tags from users with less then 5 posts, I have tried and played around with url tags but I got no luck on making this happen, below is my url arrays in Subs.php
array(
'tag' => 'url',
'type' => 'unparsed_content',
'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
'validate' => create_function('&$tag, &$data, $disabled', '
$data = strtr($data, array(\'<br />\' => \'\'));
if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
$data = \'http://\' . $data;
'),
),

'tag' => 'url',
'type' => 'unparsed_equals',
'before' => '<a href="$1" class="bbc_link" target="_blank">',
'after' => '</a>',
'validate' => create_function('&$tag, &$data, $disabled', '
if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
$data = \'http://\' . $data;
'),
'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_after' => ' ($1)',
),


any help would be greatly appreciated.

Pipke

in file
./Themes/default/languages/Modifications.english.php

Code (find) Select

?>


Code (Add Before) Select

// Hide content [url][/url]
$txt['no_view_urls'] ='<b>You need a 5 post minimum to see the url tags! </b>';



and in file

./Themes/default/languages/Modifications.english-utf8.php

Code (find) Select

?>


Code (Add Before) Select

// Hide content [url][/url]
$txt['no_view_urls'] ='<b>You need a 5 post minimum to see the url tags! </b>';



and in file

./Sources/Subs.php

Code (find) Select

// Cache the output if it took some time...


Code (Add Before) Select


// Hide content [url][/url]
if ($user_info['posts'] < 5)
{
$message = preg_replace('#<a href="(.*?)</a>#i', $txt['no_view_urls'] . "\n", $message);
}

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

thepitster

@Pipke that did the trick just nicely, you my friend are awesome!
Thank you so much.

Arantor

This will also break the quotes in a post. And mentions too, if installed.

thepitster

@Arantor how to do you mean they seem to be working on my end?

Arantor

The header of a quote is usually a link. And code tags have the select link in them.

thepitster


Arantor


Pipke

Quote from: thepitster on September 24, 2017, 12:49:51 AM
you mean like this?

Fix to keep the quote url and hide the other in if statement:

./Themes/default/languages/Modifications.english.php
Code (find) Select

?>


Code (Add Before) Select

// Hide content [url][/url]
$txt['no_view_urls'] ='<b>You need a 5 post minimum to see the url tags! </b>';



./Themes/default/languages/Modifications.english-utf8.php
Code (find) Select

?>


Code (Add Before) Select

// Hide content [url][/url]
$txt['no_view_urls'] ='<b>You need a 5 post minimum to see the url tags! </b>';




./Sources/Subs.php
Code (find) Select

'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',


Code (replace with) Select

'content' => '<a data_id="url" href="$1" class="bbc_link" target="_blank">$1</a>',


Code (find) Select

'before' => '<a href="$1" class="bbc_link" target="_blank">',


Code (replace with) Select

'before' => '<a data_id="url" href="$1" class="bbc_link" target="_blank">',


Code (find) Select

// Cache the output if it took some time...


Code (Add Before) Select


// Hide content [url][/url]
if ($user_info['posts'] < 5)
{
$message = preg_replace('#<a data_id="url" href="(.*?)</a>#i', $txt['no_view_urls'] . "\n", $message);
}
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

thepitster

Well that seem to have worked fine on that, good job Pipke, and thank you Arantor, for your troubleshooting tip on the quote url.
Only problem I am having now is, I had to disable quotes on my production site, cause one could bypass it simply by pressing the "quote" button and it showed up in the quote block. Plus I am having the same problem with the code tags and quotes too, guess I am taking that one back to the drawing board.

thepitster

okay for all that I had asked for was solved so I am leaving it as "Topic Solved" for that part and I thank you both, Pipke and Arantor, for your help with this.
I will figure out how to keep from pressing the quote button on a post and then seeing the content of [url][/url] and [code][/code] for user under 5 posts, without having to disable quotes all together.

Pipke

Quote from: thepitster on September 28, 2017, 12:59:21 PM
I will figure out how to keep from pressing the quote button on a post and then seeing the content

ok try this to disable topic quote, if posts <  5

add text string agian as before on:
./Themes/default/languages/Modifications.english.php
and
./Themes/default/languages/Modifications.english-utf8.php


$txt['no_quote_topics'] ='<b>You need a 5 post minimum to quote topics!</b>';


./Themes/default/index.template.php
Code (find) Select

function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;


Code (replace by) Select

function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings, $user_info;

if ($user_info['posts'] < 5)
{
$context['can_quote'] = false;

if (!empty($_REQUEST['quote']))
fatal_lang_error('no_quote_topics', false);
}

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

thepitster

let me make sure I got this all correct okay?

./Themes/default/languages/Modifications.english.php
Code (find) Select

?>


Code (add before) Select

// Hide content [url][/url]
$txt['no_view_urls'] ='<b>You need a 5 post minimum to see the url tags! </b>';
$txt['no_quote_topics'] ='<b>You need a 5 post minimum to quote topics!</b>';



./Themes/default/languages/Modifications.english-utf8.php
Code (find) Select

?>


Code (add before) Select

// Hide content [url][/url]
$txt['no_view_urls'] ='<b>You need a 5 post minimum to see the url tags! </b>';
$txt['no_quote_topics'] ='<b>You need a 5 post minimum to quote topics!</b>';



./Themes/default/index.template.php
Code (find) Select

function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;


Code (replace with) Select

function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings, $user_info;

if ($user_info['posts'] < 5)
{
$context['can_quote'] = false;

if (!empty($_REQUEST['quote']))
fatal_lang_error('no_quote_topics', false);
}



./Sources/Subs.php
Code (find) Select

'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',


Code (replace with) Select

'content' => '<a data_id="url" href="$1" class="bbc_link" target="_blank">$1</a>',


Code (find) Select

'before' => '<a href="$1" class="bbc_link" target="_blank">',


Code (replace with) Select

'before' => '<a data_id="url" href="$1" class="bbc_link" target="_blank">',


Code (find) Select

// Cache the output if it took some time...


Code (Add Before) Select


// Hide content [url][/url]
if ($user_info['posts'] < 5)
{
$message = preg_replace('#<a data_id="url" href="(.*?)</a>#i', $txt['no_view_urls'] . "\n", $message);
}


does that pretty much sum it up?

Pipke

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

thepitster

well It appears successful on my end, quote button is gone for those under 5 posts, links hidden, I Thank you sir and I say you've done a find job!

Advertisement: