News:

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

Main Menu

do not allow guest to view URLs

Started by Gandalf, February 11, 2005, 03:36:00 PM

Previous topic - Next topic

Gandalf

hello
i need this modification (well at least where to do it) I'll explain below:
when we post something like this [*url=http://www.siemens-mobiles.org/forum/index.php][*img]http://membres.lycos.fr/redouane171/Resize%20of%20wael.jpg[/*img][*/url]
it give the following image which is assigned to an URL like this


i need to disallow guest from viewing URLs but they still can view the images which i mean the above code will be visible to guests like this (an image without a link)

, in other world the guests view the message just like if we typed ONLY [*img]http://membres.lycos.fr/redouane171/Resize%20of%20wael.jpg[*img] so how to do it???
thanks
Siemens-mobiles.org Visit it and you won't regret it :D

[Unknown]

#1
Find, Sources/Subs.php:

// Find a (named?) URL... [url]www.simplemachines.org[/url] or [url=www.simplemachines.org]SMF[/url]
'~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie' => isset($disabled['url']) ? 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'' : '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\'',
'~\[url=(.+?)\](.+?)\[/url\]~ie' => isset($disabled['url']) ? '\'$2 ($1)\'' : '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\'',
'~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i' => isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>',


Replace:
// Find a (named?) URL... [url]www.simplemachines.org[/url] or [url=www.simplemachines.org]SMF[/url]
'~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie' => $context['user']['is_guest'] ? '\'$2\'' : (isset($disabled['url']) ? 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'' : '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\''),
'~\[url=(.+?)\](.+?)\[/url\]~ie' => $context['user']['is_guest'] ? '\'$2\'' : (isset($disabled['url']) ? '\'$2 ($1)\'' : '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\''),
'~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i' => $context['user']['is_guest'] ? '' : (isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>'),


How do I modify files?

-[Unknown]

Gandalf

thanks man i'll try it and i'll tell you :D
Siemens-mobiles.org Visit it and you won't regret it :D

Gandalf

it works perfect just like i want
Respect to you [Unknown]  :)
Siemens-mobiles.org Visit it and you won't regret it :D

Gandalf

[unknown] i've removed this patch because i need to install Faster Parse Code mod so the new (original code) is // Find a (named?) URL... [url]www.simplemachines.org[/url] or [url=www.simplemachines.org]SMF[/url]
if(isset($add['[url='])){
$arr1[] = '~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie';
$arr1[] = '~\[url=(.+?)\](.+?)\[/url\]~ie';
if(isset($disabled['url'])){
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'';
$arr2[] = '\'$2 ($1)\'';
}else{
$arr2[] = '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\'';
$arr2[] = '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\'';
}
}
if(isset($add['[url]'])){
$arr1[] = '~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i';
$arr2[] = isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>';
}
so how to patch in this case??? thanks
Siemens-mobiles.org Visit it and you won't regret it :D

niko


if(isset($add['[url='])){
$arr1[] = '~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie';
$arr1[] = '~\[url=(.+?)\](.+?)\[/url\]~ie';
if(isset($disabled['url'])){
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'';
$arr2[] = '\'$2 ($1)\'';
}
if(isset($context['user']['is_guest'])){
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'';
$arr2[] = '\'$2 ($1)\'';
}
else{
$arr2[] = '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\'';
$arr2[] = '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\'';
}
}
if(isset($add['[url]'])){
$arr1[] = '~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i';
$arr2[] = isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>';
}

this may work
Websites: Madjoki || (2 links retracted by team, links out of date and taken over.)
Mods: SMF Arcade, Related topics, SMF Project Tools, Post History

WIP Mods: Bittorrent Tracker || SMF Wiki

Gandalf

Siemens-mobiles.org Visit it and you won't regret it :D

Gandalf

that one didn't work!!!
i get under the image the URL in text, in case if you ask i added $context to the global instruction of theis function,so there's something worg with [*url=http://..][*img]..[*/img][*/url]

and nothing happens with [*url]...[*/url]
any other suggestions???
Siemens-mobiles.org Visit it and you won't regret it :D

Gandalf

Siemens-mobiles.org Visit it and you won't regret it :D

[Unknown]

Try:

// Find a (named?) URL... [url]www.simplemachines.org[/url] or [url=www.simplemachines.org]SMF[/url]
if(isset($add['[url='])){
$arr1[] = '~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie';
$arr1[] = '~\[url=(.+?)\](.+?)\[/url\]~ie';

if ($context['user']['is_guest'])
{
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\')';
$arr2[] = '$2';
}
elseif (isset($disabled['url'])){
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'';
$arr2[] = '\'$2 ($1)\'';
}else{
$arr2[] = '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\'';
$arr2[] = '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\'';
}
}
if(isset($add['[url]'])){
$arr1[] = '~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i';
$arr2[] = $context['user']['is_guest'] ? '' : (isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>');
}


-[Unknown]

Gandalf

Siemens-mobiles.org Visit it and you won't regret it :D

Gandalf

i get the following error

Parse error: parse error, unexpected '[' in /var/www/virtual/siemens-mobiles.org/htdocs/slash/Sources/Subs.php(1237) : regexp code on line 1

Fatal error: Failed evaluating code: [img]http://www.siemens-mobiles.org/patchgen/patchgen.jpg[/img] in /var/www/virtual/siemens-mobiles.org/htdocs/slash/Sources/Subs.php on line 1237


test forum url : http://www.siemens-mobiles.org/slash/index.php
Siemens-mobiles.org Visit it and you won't regret it :D

Gandalf

i made a .mod file so i can install and test easly without having to do it manually, i'll include the file in case you want to test it/verify it

.mod contents

<id>
Disable URL from guests
</id>

<version>
1.0
</version>

<mod info>
This mod will disable URL from guests
</mod info>

<author>
Gandalf code givin by [Unknown]
</author>

<homepage>
http://www.siemens-mobiles.org/
</homepage>


<edit file>
Sources/Subs.php
</edit file>

<search>
// Find a (named?) URL... [url]www.simplemachines.org[/url] or [url=www.simplemachines.org]SMF[/url]
if(isset($add['[url='])){
$arr1[] = '~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie';
$arr1[] = '~\[url=(.+?)\](.+?)\[/url\]~ie';
if(isset($disabled['url'])){
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'';
$arr2[] = '\'$2 ($1)\'';
}else{
$arr2[] = '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\'';
$arr2[] = '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\'';
}
}
if(isset($add['[url]'])){
$arr1[] = '~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i';
$arr2[] = isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>';
}
</search>

<replace>
// Find a (named?) URL... [url]www.simplemachines.org[/url] or [url=www.simplemachines.org]SMF[/url]
if(isset($add['[url='])){
$arr1[] = '~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie';
$arr1[] = '~\[url=(.+?)\](.+?)\[/url\]~ie';

if ($context['user']['is_guest'])
{
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\')';
$arr2[] = '$2';
}
elseif (isset($disabled['url'])){
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'';
$arr2[] = '\'$2 ($1)\'';
}else{
$arr2[] = '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\'';
$arr2[] = '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\'';
}
}
if(isset($add['[url]'])){
$arr1[] = '~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i';
$arr2[] = $context['user']['is_guest'] ? '' : (isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>');
}
</replace>
Siemens-mobiles.org Visit it and you won't regret it :D

[Unknown]

I think you want this, then:

// Find a (named?) URL... [url]www.simplemachines.org[/url] or [url=www.simplemachines.org]SMF[/url]
if(isset($add['[url='])){
$arr1[] = '~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie';
$arr1[] = '~\[url=(.+?)\](.+?)\[/url\]~ie';

if ($context['user']['is_guest'])
{
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\')';
$arr2[] = '\'$2\'';
}
elseif (isset($disabled['url'])){
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'';
$arr2[] = '\'$2 ($1)\'';
}else{
$arr2[] = '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\'';
$arr2[] = '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\'';
}
}
if(isset($add['[url]'])){
$arr1[] = '~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i';
$arr2[] = $context['user']['is_guest'] ? '' : (isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>');
}


-[Unknown]

Gandalf

#14
exactly, in fact i repaired it two days ago the problem was

$arr2[] = '\'$2\'';

instead of

$arr2[] = '$2';


but there's something weird that i couldn't figure out myself, when viewing an url with spaces before and after it, it works, but if there's an url with letter before or after it, without spaces, it doesn't work and i couldn't figure out why
see those two topics to know what i mean
http://www.siemens-mobiles.org/forum/index.php/topic,1255.0.html where the weird thing is
http://www.siemens-mobiles.org/forum/index.php/topic,1657.0.html where it works

login with smf as username, programming as password if you need to see the topics as a user

the code that i used

// Find a (named?) URL... [url]www.simplemachines.org[/url] or [url=www.simplemachines.org]SMF[/url]
if(isset($add['[url='])){
$arr1[] = '~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie';
$arr1[] = '~\[url=(.+?)\](.+?)\[/url\]~ie';

if ($context['user']['is_guest'])
{
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\')';
$arr2[] = '\'$2\'';
}
elseif (isset($disabled['url'])){
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'';
$arr2[] = '\'$2 ($1)\'';
}else{
$arr2[] = '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\'';
$arr2[] = '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\'';
}
}
if(isset($add['[url]'])){
$arr1[] = '~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i';
$arr2[] = $context['user']['is_guest'] ? '[URL REMOVED BECAUSE YOU ARE VISITING THE SITE AS A GUEST, PLEASE LOGIN TO SEE THE URLs]' : (isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>');
}


BTW thanks master [Unknown] so nice from you to help...
Siemens-mobiles.org Visit it and you won't regret it :D

[Unknown]

Try changing this:

$arr2[] = '\'$2\'';

To:

$arr2[] = '\'[URL REMOVED BECAUSE YOU ARE VISITING THE SITE AS A GUEST, PLEASE LOGIN TO SEE THE URLs]\'';

-[Unknown]


[Unknown]

Sorry, sorry, I see where I'm misunderstanding that code.  Replace this one too with the same:

$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\')';

-[Unknown]

Gandalf

#18
again not working :'(
http://www.siemens-mobiles.org/slash/index.php/topic,1255.0.html

code that i used

// Find a (named?) URL... [url]www.simplemachines.org[/url] or [url=www.simplemachines.org]SMF[/url]
if(isset($add['[url='])){
$arr1[] = '~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie';
$arr1[] = '~\[url=(.+?)\](.+?)\[/url\]~ie';

if ($context['user']['is_guest'])
{
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\')';
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\')';
}
elseif (isset($disabled['url'])){
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'';
$arr2[] = '\'$2 ($1)\'';
}else{
$arr2[] = '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\'';
$arr2[] = '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\'';
}
}
if(isset($add['[url]'])){
$arr1[] = '~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i';
$arr2[] = $context['user']['is_guest'] ? '[URL REMOVED BECAUSE YOU ARE VISITING THE SITE AS A GUEST, PLEASE LOGIN TO SEE THE URLs]' : (isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>');
}


in case you need the original code to compare

// Find a (named?) URL... [url]www.simplemachines.org[/url] or [url=www.simplemachines.org]SMF[/url]
if(isset($add['[url='])){
$arr1[] = '~\[url=([^\]]+?)\]([^\]]*?\[url(?:=[^\]]+?)?\].+?\[/url\].*?)\[/url\]~ie';
$arr1[] = '~\[url=(.+?)\](.+?)\[/url\]~ie';
if(isset($disabled['url'])){
$arr2[] = 'preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', \'$2\') . \' ($1)\'';
$arr2[] = '\'$2 ($1)\'';
}else{
$arr2[] = '\'<a href="$1" target="_blank">\' . preg_replace(\'~(\[url.*?\]|\[/url\])~\', \'\', strtr(\'$2\', array(\'@\' => \'&#64;\'))) . \'</a>\'';
$arr2[] = '\'<a href="$1" target="_blank">\' . strtr(\'$2\', array(\'@\' => \'&#64;\')) . \'</a>\'';
}
}
if(isset($add['[url]'])){
$arr1[] = '~\[url\](?:<br />)*(.+?)(?:<br />)*\[/url\]~i';
$arr2[] = isset($disabled['url']) ? '$1' : '<a href="$1" target="_blank">$1</a>';
}
Siemens-mobiles.org Visit it and you won't regret it :D

[Unknown]

No, no, you did it backwards.  I meant to replace that with this:

$arr2[] = '\'[URL REMOVED BECAUSE YOU ARE VISITING THE SITE AS A GUEST, PLEASE LOGIN TO SEE THE URLs]\'';

Meaning, both lines should be that.

-[Unknown]

Advertisement: