|
Cookbook /
ExternalLinks2Summary: Add and icon to external links and make them automatically open in a new window
Version:
Prerequisites:
Status:
Maintainer: Pierre Racine
Categories: links
Questions answered by this recipe
DescriptionThe following markup adds an icon for every external links and make them to open in a new window. Add the markup definition to config.php or another local customisation file. You also need to create an icon images This recipe is different from ExternalLinks in that it will not add the icon for internal links inadvertendly written with http://... Markup('[[newwin|','<[[|',"/(?>\\[\\[\\s*(http:\/\/[^|\\]]*)\\s*\\|\\s*)(.*?)\\s*\\]\\]($SuffixPattern)/e",
"MakeLinkNewWin(\$pagename, PSS('$1'), PSS('$2'), PSS('$3'),'$4')");
Markup('[[newwin','<[[', "/(?>\\[\\[\\s*(http:\/\/.*?)\\s*\\]\\])($SuffixPattern)/e",
"MakeLinkNewWin(\$pagename, PSS('$1'), NULL, '$2')");
function MakeLinkNewWin($pagename, $target, $text, $suffix)
{
global $UrlLinkFmt, $_SERVER, $PubDirUrl;
$host = 'http://'.$_SERVER['HTTP_HOST'];
// We do not make the link external if it is internal
if (substr_count($target, $host) == 0 && substr_count($text, "Attach:") == 0)
$fmt = "%newwin%".$UrlLinkFmt." <img src=".$PubDirUrl."/icons/ext.gif>";
if (is_null($text))
return Keep(MakeLink($pagename, PSS($target), NULL, $suffix, $fmt), 'L');
else
return Keep(MakeLink($pagename, PSS($target), PSS($text), $suffix, $fmt), 'L');
}
Get your icon from here: www.stylegala.com/features/bulletmadness/ Rename it to be named like this: NotesI could not make this to work with bare hyperlink like Release Notes
CommentsThanks a lot for this useful recipe! I have intalled it, and it works fine for all URLs starting with http://. However, it does not recognize external URLs that are implemented with the InterMap feature, so its coverage is somewhat limited. Perhaps it would be possible to include intermap consideration to this recipe to make it even more useful? --Henning March 10, 2008, at 12:32 PM See AlsoContributors |