News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Disable external links?

Started by brettuk, May 27, 2018, 03:19:02 PM

Previous topic - Next topic

brettuk

Hi,

Is there any way I am able to make it so NO-ONE, besides Admins, can post external links?

Even by BBC code and writing the code manually, etc.

I'd only like external links to be shared via PM's, not posts or threads.

Thanks!

Illori


Bigguy

There probably is a way but it may take a lot coding.

Chen Zhen

The edit is actually fairly simple.

File: ../Sources/Post.php

find (near top of Post2() function):

// Previewing? Go back to start.


insert BEFORE the above comment line:

$replacement = '';
$search = array('/\[url\](.*?)\[\/url\]/is'  . ($context['utf8'] ? 'u' : ''), '/\[url\=(.*?)\](.*?)\[\/url\]/is'  . ($context['utf8'] ? 'u' : ''), '/\<a(.*)\>(.*)\<\/a\>/iU'  . ($context['utf8'] ? 'u' : ''), "/(?i)\b((?:(http|https)?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?]))/"  . ($context['utf8'] ? 'u' : ''));
if (isset($_POST['message']) && empty($user_info['is_admin']))
$_POST['message'] = preg_replace($search, $replacement, $_POST['message']);
elseif (isset($_REQUEST['message']) && empty($user_info['is_admin']))
$_REQUEST['message'] = preg_replace($search, $replacement, $_REQUEST['message']);


.. just change the value of $replacement to what you want links replaced with (within its quotes).

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Bigguy

Hey, it was easier than I thought, thanks man. :)

Chen Zhen

Actually 2 edits if you want it to also effect previewing.
You can forget about the previous edit (it should be shorter..) & do these 2 instead

file: ../Post.php

for "preview" find:

// Previewing, modifying, or posting?


add BEFORE that comment:

$replacement = '[LINK OMITTED]';
$search = array('/\[url\](.*?)\[\/url\]/is'  . ($context['utf8'] ? 'u' : ''), '/\[url\=(.*?)\](.*?)\[\/url\]/is'  . ($context['utf8'] ? 'u' : ''), '/\<a(.*)\>(.*)\<\/a\>/iU'  . ($context['utf8'] ? 'u' : ''), "/(?i)\b((?:(http|https)?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?]))/"  . ($context['utf8'] ? 'u' : ''));
if (isset($_REQUEST['message'])  && empty($user_info['is_admin']))
$_REQUEST['message'] = preg_replace($search, ($replacement), $_REQUEST['message']);


for saving the post find:

// Previewing? Go back to start.


add BEFORE that comment:

$replacement = '[LINK OMITTED]';
$search = array('/\[url\](.*?)\[\/url\]/is'  . ($context['utf8'] ? 'u' : ''), '/\[url\=(.*?)\](.*?)\[\/url\]/is'  . ($context['utf8'] ? 'u' : ''), '/\<a(.*)\>(.*)\<\/a\>/iU'  . ($context['utf8'] ? 'u' : ''), "/(?i)\b((?:(http|https)?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?]))/"  . ($context['utf8'] ? 'u' : ''));
if (isset($_POST['message']) && empty($user_info['is_admin']))
$_POST['message'] = preg_replace($search, $replacement, $_POST['message']);


Again.. change [LINK OMITTED] in either/both to what you want as replacements.

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Kindred

That will, however, affect ALL links, not just external links
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

shawnb61

If you haven't yet, think you should consider disabling:
- Automatically link posted URLs
- Url BBC
- Enable basic Html

These are all on the Features and Options | Bulletin Board Code page in the Admin Control Panel.

Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Dav999

Quote from: shawnb61 on June 06, 2018, 01:03:16 AM
If you haven't yet, think you should consider disabling:
- Automatically link posted URLs
- Url BBC
- Enable basic Html

These are all on the Features and Options | Bulletin Board Code page in the Admin Control Panel.
As a bonus, admins would be able to post working links using the [html] tags.

Chen Zhen

This will allow $boardurl but I wrote it so you can add allowed site links in the $allowed array.

file: ../Post.php

for "preview" find:

// Previewing, modifying, or posting?


add BEFORE that comment:

global $boardurl;
$allowed = array($boardurl);
$replacement = '[LINK OMITTED]';
$search = array('/\[url\](.*?)\[\/url\]/is'  . ($context['utf8'] ? 'u' : ''), '/\[url\=(.*?)\](.*?)\[\/url\]/is'  . ($context['utf8'] ? 'u' : ''), '/\<a(.*)\>(.*)\<\/a\>/iU'  . ($context['utf8'] ? 'u' : ''), "/(?i)\b((?:(http|https)?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?]))/"  . ($context['utf8'] ? 'u' : ''));
if (isset($_REQUEST['message'])  && empty($user_info['is_admin']))
{
$new = preg_replace_callback($search, function($m) use($replacement, $allowed) {
foreach ($allowed as $allow)
{
$length = strlen($allow);
if (substr($m[0], 0, $length) == $allow)
return $m[0];
}

return $replacement;
}, $_REQUEST['message']);

$_REQUEST['message'] = rtrim($new);
}


for saving the post find:

// Previewing? Go back to start.


add BEFORE that comment:

global $boardurl;
$allowed = array($boardurl);
$replacement = '[LINK OMITTED]';
$search = array('/\[url\](.*?)\[\/url\]/is'  . ($context['utf8'] ? 'u' : ''), '/\[url\=(.*?)\](.*?)\[\/url\]/is'  . ($context['utf8'] ? 'u' : ''), '/\<a(.*)\>(.*)\<\/a\>/iU'  . ($context['utf8'] ? 'u' : ''), "/(?i)\b((?:(http|https)?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?]))/"  . ($context['utf8'] ? 'u' : ''));
if (isset($_POST['message'])  && empty($user_info['is_admin']))
{
$new = preg_replace_callback($search, function($m) use($replacement, $allowed) {
foreach ($allowed as $allow)
{
$length = strlen($allow);
if (substr($m[0], 0, $length) == $allow)
return $m[0];
}

return $replacement;
}, $_POST['message']);

$_POST['message'] = rtrim($new);
}


My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Advertisement: