I've looked through the function list, but don't see where these are made.
I mean; when you submit a new post with a plain URL in it, the URL is turned into a link once the post is submitted.
I would like to find where the code to do that is located please.
Thanks!
What *exactly* do you want to do with it?
This particular piece of code is one of the most complex parts of the bbcode parser and changing it can actually make your site insecure, so it is not recommended.
But if you can explain what you're trying to do, we'll help explain what exactly is needed to be done to do it safely.
Thanks for the reply. I am wanting to make internal links open in the same window rather than open them in new windows.
Unless I'm terribly mistaken, that is default behaviour in SMF.
EDIT: Testing this, I may actually be mistaken. And thinking a bit, it actually makes sense it isn't like that always.
Default (URL) link https://www.simplemachines.org/community/index.php
Internal (IURL) link https://www.simplemachines.org/community/index.php
Did you use the IURL tag?
I know that I can use the BBC code, but it's annoying having to use it all the time when I want to link internally.
Yeah, turns out I was mistaken. Some sort of brain fart moment there.
It actually makes perfect sense to me that it isn't defaulting to iurl behaviour.
It doesn't to me ;D
To me it's bad practice to force new windows on a user.
There was a mod which made all local links use IURL
Yep this one: https://custom.simplemachines.org/index.php?mod=980
But it's not been updated for years. I will take a look at the code to see if I can find any pointers.
I had a look and it's not a good solution - it works by using preg_replace on the entire message.
I'd like to nip it in the bud at the point the link gets made.
Subs.php line 3133 is where it's actually built after the 300 or so lines of figuring out where the links are (and if you fret about the preg-regex in that mod, do NOT look at the code before line 3133 in an unmodified Subs.php because it's many MANY lines of regex)
return '[url="' . str_replace(array('[', ']'), array('[', ']'), iri_to_url($fullUrl)) . '"]' . $url . '[/url]';
As long as you return the correct bbcode format it'll be fine. Do not try to unwrap the iri_to_url call (this is required for proper link handling in SMF)
I don't see that at that line.
Whereabouts did you think it has to go please?
Thanks!
Regex is fine when necessary.
I gave you the very line you need to change, and that's where it is in an unmodified SMF 2.1.1, the current SMF version.
Okay, which function is it in please?
My file is edited.
It's in parse_bbc. The function that in 2.0 is 1500 lines long, and even longer in 2.1. There's a reason I went and found you the code from 2.1.1 that you'd specifically need to edit because finding it otherwise is a complete nightmare.
Wait, you *are* using 2.1, right? Because if not, the line I linked doesn't exist (as that whole piece of code was rewritten in 2.1)... in which case for 2.0 you need to find this chunk instead:
// Parse any URLs.... have to get rid of the @ problems some things cause... stupid email addresses.
if (!isset($disabled['url']) && (strpos($data, '://') !== false || strpos($data, 'www.') !== false) && strpos($data, '[url') === false)
{
// Switch out quotes really quick because they can cause problems.
$data = strtr($data, array(''' => '\'', ' ' => $context['utf8'] ? "\xC2\xA0" : "\xA0", '"' => '>">', '"' => '<"<', '<' => '<lt<'));
// Only do this if the preg survives.
if (is_string($result = preg_replace(array(
'~(?<=[\s>\.(;\'"]|^)((?:http|https)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\w\-_\~%\.@!,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i',
'~(?<=[\s>\.(;\'"]|^)((?:ftp|ftps)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i',
'~(?<=[\s>(\'<]|^)(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@!,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i'
), array(
'[url]$1[/url]',
'[ftp]$1[/ftp]',
'[url=http://$1]$1[/url]'
), $data)))
$data = $result;
$data = strtr($data, array('\'' => ''', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ', '>">' => '"', '<"<' => '"', '<lt<' => '<'));
}
and modify $data just before the closing brace because that's the part where the url bbcode will have been inserted around the link. 2.0 doesn't support IRI addresses so matching against your site URL will be a lot simpler here.
Quote from: MrMorph on February 20, 2022, 09:49:39 AMI've looked through the function list, but don't see where these are made.
I mean; when you submit a new post with a plain URL in it, the URL is turned into a link once the post is submitted.
I would like to find where the code to do that is located please.
Thanks!
There's a github mod I use for this purpose, works for 2.0 not sure about 2.1:
https://github.com/LinuxPanda/SMF2.0Mod--Auto_-iurl-_For_Internal_Links_And_-nofollow-_For_External_Links
Quote from: Wellwisher on February 20, 2022, 11:26:44 PMThere's a github mod I use for this purpose, works for 2.0 not sure about 2.1:
That will not work for SMF 2.1.
Hi guys, sorry for the late reply.
@Arantor I'm using 2.0.19 so that explains why I couldn't find it!
So $data will be holding the raw href it looks like? I can just do a test against my $scripturl if that's the case.
@Wellwisher Thanks, I will take a look if I get nowhere on my own 8)
I would suggest $boardurl rather than $scripturl, in case you want to catch links to files stored within your SMF directory as well.
If you implement where I suggested, it'll contain the full bbcode form including the tag - this is because depending on the form of the link it may or may not have the http: part in front of it so this fixes it either way.
Note that if you're using HTTPS you'll want to not match boardurl directory (definitely better than scripturl) precisely because of the interplay between HTTP and HTTPS links.