Display other protocols links as hyperlinks

Started by poolhall, February 23, 2011, 11:34:44 AM

Previous topic - Next topic

poolhall

I want my forum to display some other protocols links as hyperlinks. For example, sop:// or tvants:// .

Can someone please guide me through what changes I should make? Thank you!

I am using SMF 2.0 RC5.

texasman1979

I udnerstand ur issue but dont know how. With said you can cheat and make the links picture links, tbe browser can tben do it. Work just as well and you can differenriate them from regular links. I hope this helps.
SMF 2.0.4
SimplePortal 2.3.5

LOGIC is a FOUR letter word! :)


poolhall

well, as a forum administrator it is not that I want to make these kind of links work in my browser :)

Thanks for your reply, though :)

Arantor

QuoteWith said you can cheat and make the links picture links, tbe browser can tben do it. Work just as well and you can differenriate them from regular links. I hope this helps.

It won't work. The url bbcode enforces that the link starts with http:// or https:// rather than anything else (and that's done for security)

But you could look at the test done for the url bbcode and expand it for other types.

poolhall

Quote from: Arantor on February 23, 2011, 02:17:38 PM
But you could look at the test done for the url bbcode and expand it for other types.
where I can find that?

Arantor


texasman1979

Well helping is the game and i gave it my best shot. I have been bested. :( thx arantor for keeping him straight. :)
SMF 2.0.4
SimplePortal 2.3.5

LOGIC is a FOUR letter word! :)


poolhall

Quote from: Arantor on February 23, 2011, 02:24:25 PM
Subs.php

I guess this is the code that needs to be modified:


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;
'),
),
array(
'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)',
),


Though, not being a programmer, I am not sure how I can adapt it to make it work with sop:// . Can you please help?

Arantor

Not right now, no, since typing code on an iPad is a lot of a pain, however you see that if statement that is doing strpos for http and https, well you sort of start with extending that.

That will allow the URL bbcode to use non http links, making auto link detection is a fair bit trickier though.

poolhall

wow, I thought real programmers have devices like iPad :)


if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0 && strpos($data, \'sop://\') !== 0)
but I am not sure about the next line $data = \'http://\' . $data;

Arantor

That's just fine - the test is "if the content doesn't start with http and doesn't start with https and doesn't start with sop, rewrite the content to put http:// at the start so it's always a valid link"

Needs to be done twice, of course.

poolhall

Quote from: Arantor on February 23, 2011, 03:17:29 PM
That's just fine - the test is "if the content doesn't start with http and doesn't start with https and doesn't start with sop, rewrite the content to put http:// at the start so it's always a valid link"
got it. Thanks a lot man!

poolhall

in the post above I meant to say "hate devices...", not "have devices..." :)

Arantor

Heh, well it also means I can sit downstairs with the TV to get a break from being sat in front of the same four walls ;)

poolhall

:)

Arantor, this part of code is responsible where url tags specifically applied to links, isn't it? If so, where is the code responsible for auto html link parsing?

Arantor

It's further up but I'm not going to dig through the 1500 lines of the bbcode system on an iPad...

texasman1979

What you need arantor is a round room. Possibly padded walls, but well put a hold on that. ;)
SMF 2.0.4
SimplePortal 2.3.5

LOGIC is a FOUR letter word! :)


poolhall

Quote from: Arantor on February 23, 2011, 03:36:32 PM
It's further up but I'm not going to dig through the 1500 lines of the bbcode system on an iPad...
If you later have some time for that, please let me know. And thanks a lot anyway!

poolhall

I changed the code in subs.php to this:


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 && strpos($data, \'sop://\') !== 0)
$data = \'http://\' . $data;
'),
),
array(
'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 && strpos($data, \'sop://\') !== 0)
$data = \'http://\' . $data;
'),
'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_after' => ' ($1)',
),


but still http:// is being added in front of Sopcast links, so that, for example, sop://broker.sopcast.com:3912/98660 turns into http://sop//broker.sopcast.com:3912/98660 (exactly like that, without a colon after sop). There must be another part of the code responsible for that?

Joker™

I think you need to make change in iurl tag also.
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

poolhall


Arantor

To fix the protocol part, you will need to edit Sources/Subs-Post.php

// [url]http://...[/url]
array(
'tag' => 'url',
'protocols' => array('http', 'https'),
'embeddedUrl' => true,
'hasEqualSign' => false,
),
// [url=http://...]name[/url]
array(
'tag' => 'url',
'protocols' => array('http', 'https'),
'embeddedUrl' => true,
'hasEqualSign' => true,
),
// [iurl]http://...[/iurl]
array(
'tag' => 'iurl',
'protocols' => array('http', 'https'),
'embeddedUrl' => true,
'hasEqualSign' => false,
),
// [iurl=http://...]name[/iurl]
array(
'tag' => 'iurl',
'protocols' => array('http', 'https'),
'embeddedUrl' => true,
'hasEqualSign' => true,
),


to add 'sop' to each of those 'protocols' lines.

As for the auto linking itself, find these lines in Subs.php
// Only do this if the preg survives.
if (is_string($result = preg_replace(array(
'~(?<=[\s>\.(;\'"]|^)((?:http|https|ftp|ftps)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i',
'~(?<=[\s>(\'<]|^)(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i'


Replace with
// Only do this if the preg survives.
if (is_string($result = preg_replace(array(
'~(?<=[\s>\.(;\'"]|^)((?:http|https|ftp|ftps|sop)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i',
'~(?<=[\s>(\'<]|^)(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i'

poolhall


poolhall

It's all working, Arantor. Thanks a lot again.

BunNicu

The SOP:// it`s not working on SMF 2.0.9.....
When I made the changes in script it`s giveing the SOP// with no ":" symbol.... Why?

Advertisement: