Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Juo on July 24, 2009, 05:06:11 PM

Title: Image Host Whitelist
Post by: Juo on July 24, 2009, 05:06:11 PM
I was wondering if there is a way to check posts when members try and make them for services they have used within [img] hosting tags, im pretty sick of my members hotlinking files from over peoples websites and wanted to create a whitelist of admin approved image hosting services? this would be images.mydomain.com

Is this possible?

Thanks :)
Title: Re: Image Host Whitelist
Post by: Arantor on July 25, 2009, 04:43:36 AM
If it's a fixed domain that isn't going to change, it would be possible to modify the img tag to only handle such URLs, and not embed pictures from other domains.

In fact, let's do just that.

In Sources/Subs.php, find:

array(
'tag' => 'img',
'type' => 'unparsed_content',
'parameters' => array(
'alt' => array('optional' => true),
'width' => array('optional' => true, 'value' => ' width="$1"', 'match' => '(\d+)'),
'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
),
'content' => '<img src="$1" alt="{alt}"{width}{height} class="bbc_img" />',
'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
'disabled_content' => '($1)',
),
array(
'tag' => 'img',
'type' => 'unparsed_content',
'content' => '<img src="$1" alt="" class="bbc_img" />',
'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
'disabled_content' => '($1)',
),


Replace it with, making sure to change http://intranet to the domain of your choice.


array(
'tag' => 'img',
'type' => 'unparsed_content',
'parameters' => array(
'alt' => array('optional' => true),
'width' => array('optional' => true, 'value' => ' width="$1"', 'match' => '(\d+)'),
'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
),
'content' => '<img src="$1" alt="{alt}"{width}{height} class="bbc_img" />',
'validate' => create_function('&$tag, &$data, $disabled', '
$data = strtr($data, array(\'<br />\' => \'\'));
$domain = "http://intranet/";
if(substr($data, 0, strlen($domain)) != $domain) {
$tag[\'content\'] = \'$1\';
}
'),
'disabled_content' => '($1)',
),
array(
'tag' => 'img',
'type' => 'unparsed_content',
'content' => '<img src="$1" alt="" class="bbc_img" />',
'validate' => create_function('&$tag, &$data, $disabled', '
$data = strtr($data, array(\'<br />\' => \'\'));
$domain = "http://intranet/";
if(substr($data, 0, strlen($domain)) != $domain) {
$tag[\'content\'] = \'$1\';
}
'),
'disabled_content' => '($1)',
),


For img links on http://intranet they will be converted to images, but for any other domain - it just leaves the URL in its place. The instructions are for 2.0 but it should be virtually the same on 1.1 though I haven't checked or tried it.

EDIT: I have made a more powerful version into a mod that lets you specify multiple domains, plus paths, and this is on the mod site waiting to be approved. When it is approved it will be available from here (http://custom.simplemachines.org/mods/index.php?mod=2027).
Title: Re: Image Host Whitelist
Post by: Juo on July 25, 2009, 08:50:35 AM
wow that's insane, not only a fix but a modification thanks so much Arantor you have no idea how much I appreciate this :)
Title: Re: Image Host Whitelist
Post by: Arantor on July 25, 2009, 10:10:21 AM
No worries - the mod isn't approved yet but it's done ready for then.
Title: Re: Image Host Whitelist
Post by: Juo on September 02, 2009, 09:11:02 AM
Now using this on my forum and its excellent thanks so much :D
Topic Solved!