INTERNAL LINKS USE SAME WINDOW v1.2
By Karl Benson (http://custom.simplemachines.org/mods/index.php?action=profile;u=63186)
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=980) | Support Topic (http://www.simplemachines.org/community/index.php?topic=200406.0) | Demo (http://www.adrevenueshare.com/index.php?topic=25.0) | Donate (http://www.adrevenueshare.com/donate)
CompatibilityFor SMF 1.1.x and SMF 2.0 Beta x
IntroductionThis simple mod fixes all internal SMF urls in posts/pms etc to open in the same window rather than a new window.
Alot of people either just post straight links (which get autoconverted to bbcode), don't know about [iurl][/iurl], can't be bothered or forget to use it when posting links to other smf pages on your site.
So that sometimes results in having many new tabs/windows opening for internal links when really opening in the same window is preferrable.
Featureso Makes local links (to local smf pages) open in same window
(It detects $scripturl at the beginning of the link)
o Makes adjustment if using queryless urls.
o Works for both www. and non www. links
InstallationAny previous versions of this mod need to be uninstalled prior to installing this version.
Install the mod via the SMF Package Manager, and your done. It installs on
ALL themes automatically as it only affects Source files.
There are NO theme edits required and there are NO language strings to translate.
Useful LinksSMF Package Parser (http://www.adrevenueshare.com/parser)
Manual Installation Of Mods (http://docs.simplemachines.org/index.php?topic=402)
How Do I Modify Files? (http://www.simplemachines.org/community/index.php?topic=24110.0)
DonateHas this modification helped you? Support the developer by
Donating (http://www.adrevenueshare.com/donate)
SupportPlease use the modification thread for support with this modification.
(Please don't ask me to do the edits for you)
Changelog1.0 - 9th October 2007o Initial release per request
1.1 - 16th October 2007o Fixed bug with dots (.) not escaped
o Added /u modifier for when using UTF-8
1.2 - 13th February 2008o Checked 2.0 compatible (no changes necessary)
o Improved/optimized regex pattern
o Added adjustment to use boardurl instead of scripturl if using queryless urls
o Fixed to work for www. and non www. versions
o Updated readme
It is unsafe mod! Don't use it!
You cannot just use preg_replace:
$message = preg_replace('#<a href="'.$scripturl.'(.*?)"(.*?)(target="_blank")(.*?)</a>#i','<a href="'.$scripturl.'$1"$2$4</a>',$message);
Kela, as far as I can see it IS safe.
I am eager to know why you believe it is not safe.
a) SMF has already validated/sanitized the url and converted it to bbcode
b) The ONLY change that is made is that it when it parses back out everything, it removes target="blank"
karlbenson
I have installed your mod and have deleted after 1 day of usage. Some user post became empty (BUT in edit mode all are ok)! I have deleted your mod and posts appeared again.
Second, your preg_replace doesn't take into consideration text encoding (e.g. UTF-8: u (PCRE_UTF8 (http://ua.php.net/manual/en/reference.pcre.pattern.modifiers.php)))
Third, $scripturl can be somethink like http://www.simplemachines.org/community/index.php. Dot (.) match any character except newline (by default). See http://ua.php.net/manual/en/reference.pcre.pattern.syntax.php
I'll have another test of this later.
Re:Utf-8
I tested in utf-8 without a problem. But that is easy enough to add the u support if using utf8. (and with a bunch of arabic sample text)
Re: Blank posts, I'll test again.
Re: scripturl, indeed, you are correct, the dot can match any character, however the idea was to loosely match urls, NOT to validate them. At the time I discarded the idea of escaping dots because it would add unneeded overhead and since it wasnt important for them to match. However it maybe worth looking at again.
Overall though this mod shouldnt be regarded as unsafe. Room for improvement maybe.
I'll provide you an example of post which become empty...
thanks.
Will look at this as soon as i get back from job interview.
Ok I've uploaded v1.1 [Mod] (http://custom.simplemachines.org/mods/index.php?mod=980)
During my test the /u modifier didnt seem to make any difference. But I've left it in since SMF does use it in some of its own preg_replaces.
1.1 - 16th October 2007
o Fixed bug with dots (.) not escaped
o Added /u modifier for when using UTF-8
Hi,
Thank you for this mod.
I have downloaded and installed it without any problems.
I am not sure if it works like I was thinking it would.
For example the tinyurl links in this post do not open in the same window.
http://appliancejunk.com/forums/index.php?topic=201.msg859#msg859
Should they?
Thank you,
AJ
Did you get the job? :)
Quote from: karlbenson on October 16, 2007, 07:14:41 AM
thanks.
Will look at this as soon as i get back from job interview.
Nope. But had another interview yesterday.
The ONLY links which this mod affects are ones which START http://appliancejunk.com/forums/index.php
Those ones will open in the same window rather than a new window.
Tinyurl links are external links and so would open in new window (unless you used [iurl] for the same window)
ok, then it looks like its working the way it should.
QuoteNope. But had another interview yesterday.
Good luck and thanks again for the mod.
AJ
Thanks.
Indeed, this is one of those mods that if its working, you will forget that its there.
This is exactly what I needed!...almost anyway. Could you possibly help push me in the right direction on modifying the mod?
I've put together a site for some people using smf and mkportal. As it is now, the mod only appears to fix links to pages within the forum. I'd like to fix is so it takes care of anything on the same domain.
Currently Opens in Same Window:
http://domain.com/forum/index?board=1.0
Currently Opens in New Window:
http://www.domain.com/forum/index?board=1.0 (users do silly things like add www to things they copy&paste)
http://domain.com/index?whatever
Any help is greatly appreciated,
Ron
This mod simply preg_matches the smf variable $scripturl
You would need to replace the $scripturl with your domain
Replace the line
$internal = str_replace('.','\.',$scripturl);
with
$internal = 'http://(?:www\.|)domain\.com';
The '. $scripturl . ' part also needed to be removed from the preg_replace line to get that fix to work.
Would there be an easy way to get it to treat all subdomains as internal pages instead of letting them open a new window or stripping them out as it's currently doing with the www?
Also while plugging in different urls testing the output, I found that if someone happens to enter the domain name without a slash at the end the link gets directed to the current page.
Sorry to be a pest. I'm trying to understand what the code is doing and regular expressions have always tended to go over my head. Thank you very much for the help.
There isnt a quick or easy way to securely do it for subdomain links.
Thats why I settled for the scripturl.
You could use
(.*?) instead of (?:www\.|)
but that would also make anonymized links open in a new window eg
http://www.externalsite.com/?http://www.internallink.com
If you have a specific subdomain thats easy to do
For a subdomain called 'sub'
(?:www\.|sub\.|) instead of (?:www\.|)
I have reuploaded this mod and screenshots for it.
I am in the process of doing it for ALL my other mods aswell. Please bear with me.
1.2 - 13th February 2008
o Checked 2.0 compatible (no changes necessary)
o Improved/optimized regex pattern
o Added adjustment to use boardurl instead of scripturl if using queryless urls
o Fixed to work for www. and non www. versions
o Updated readme
FYI, I've just tested and it works for SMF 2.0 Beta 3 Public
Here's one problem I noticed. I'm also using the "referral mod". When someone is registering, when it comes time to fill in the referral part, if they click on the "find referrer" link button, it opens in the same window, instead of a popup window, and there is now way to get back to the previous window. Well, you can get back to the previous window, but it will not fill in the referred box. I'll have to uninstall this mod until I can get a fix for this. I like the mod idea. Any fix for this? Thanks
Modified:
Well I uninstalled the mod and I'm still having the same issue...hmmmm. I know it's not the referral mod, I've been using it with no problem. There's something else I noticed, I'm using the default theme, visitors can click on the "plus/minus" at the top of the forum and it works to min/max the news. But, members can't. I've made sure that I've checked the box in admin to allow this feature, but it doesn't work. Wonder if there's a connection...?
The opening in the same window is not caused by the mod.
Although it does the same. The Opening in the same window ONLY affects links which we bbcoded.
The find/popup is not bbcoded. I believe it might be a bug with the referrals mod.
i dont care what anybody says about this mod. i installed it and it works perfect! its god sent! thanks for all the hard work!
This is an outdated mod that is no longer supported by its author. Use at your own risk
can check that..
Very good mod idea, I wish someone could update it.
I would also appreciate an update. :-)
Regards, Torsten
I have been using this mod from the day it was created :)
Recently I changed my domain name from http://www.domain.com to https://domain.com
Internal links are opened in a new window.
Any idea's? Something must be wrong with this preg_match:
if(preg_match('~(?:http|ftp)(?:s)?://(?:www\.)?(.*?)$~i'.($context['utf8'] ? 'u' : ''), $internal, $match))
$internal = '(?:http|ftp)(?:s)?://(?:www\.)?(?:'. preg_quote($match[1], '~') .')';
else
$internal = preg_quote($internal, '~');
Anyone?