Links to New Windows
|
sconnelly
![]()
Joined: 2005-05-07
Posts: 34 |
Posted: Wed, 2005-09-21 16:50
|
|
Something that is useful to me is to have embedded links in my Gallery to open new windows. After looking through the code, I have changed the following code in the file /gallery2/lib/smarty_plugins/modifier.markup.php: (open bracket with space behind "[ url" to suppress BBCode, in actual code there would not be the space behind the open bracket) if ($openClose == 'all') {
if (preg_match('/^(http|ftp|mailto|https):/', $elementContents)) {
return sprintf('<a href="%s">%s</a>', $elementContents, $elementContents);
} else {
return sprintf('[ url=%s]', $elementContents, $elementContents);
}
} else if ($openClose == 'open') {
if (preg_match('/^(http|ftp|mailto|https):/', $attrs['default'])) {
$lastOpenSuccess = true;
return sprintf('<a href="%s">', $attrs['default']);
} else {
$lastOpenSuccess = false;
return sprintf('[ url=%s]', $attrs['default']);
}
} else if ($openClose == 'close') {
if (isset($lastOpenSuccess) && $lastOpenSuccess) {
return '</a>';
} else {
return '[/url]';
}
} else {
return false;
}to: if ($openClose == 'all') {
if (preg_match('/^(http|ftp|mailto|https):/', $elementContents)) {
return sprintf('<a href="%s" target="_blank">%s</a>', $elementContents, $elementContents);
} else {
return sprintf('[ url=%s]', $elementContents, $elementContents);
}
} else if ($openClose == 'open') {
if (preg_match('/^(http|ftp|mailto|https):/', $attrs['default'])) {
$lastOpenSuccess = true;
return sprintf('<a href="%s" target="_blank">', $attrs['default']);
} else {
$lastOpenSuccess = false;
return sprintf('[ url=%s]', $attrs['default']);
}
} else if ($openClose == 'close') {
if (isset($lastOpenSuccess) && $lastOpenSuccess) {
return '</a>';
} else {
return '[/url]';
}
} else {
return false;
}This seems to work in getting new winsows to open with these embedded links. Hope this helps someone else. Shawn Connelly |
|


Posts: 4
Wow, thanks!
I've been wanting this feature for a while. It works great.
I think this should be an option in the Gallery administration.
Posts: 23
Can this modification be made in a way that doesn't get wiped out on each upgrade of gallery or does that mean basically integrating this option into gallery code?
Posts: 4
There is a feature request for this. Go vote for it! #1262123
Posts: 16503
Currently, no. Unless it becomes a feature that is an option which can be turned off and on, if you modify core files that are not "localized" template files they will be overwritten on an upgrade.
Posts: 16
Very nice! Thank you! This is what i was looking for since 1 year. It should be implemented in new versions. I'm currently using G2.0.2.
kind regards,
pah
Posts: 3
sorry to dig on an old thread.
is there a way that instead of opening in a new full size window(browser) this will open in a pop up window instead?
- guilliam
Posts: 135
I couldn't find the code you mentioned - in order to replace it.
I'm using the latest version of gallery.
Is there any way I can make bb code links open in new windows??
Thanks for any info
Posts: 16503
First, you need to edit the same file; /gallery2/lib/smarty_plugins/modifier.markup.php
As of version 2.3, you need to edit lines 173 and 176. For a new window, I've added target="_blank". For a popup, you'd want to add in some javascript or some other method, like what's described here; http://binnyva.blogspot.com/2006/04/best-way-to-open-popup.html
/* Output of HTML. */ /* The code is like [ url ]http://.../[ /url ] */ if (!isset($attributes['default'])) { return '<a href="' . $content . '" rel="nofollow" target="_blank">' . $content . '</a>'; } else { /* The code is like [ url=http://.../ ]Text[ /url ] */ return '<a href="' . $attributes['default'] . '" rel="nofollow" target="_blank">' . $content . '</a>'; }____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 135
This is a great mod. I'm using 2.3 SVN and it works without a hitch.
Do you have any idea how to force URLs added by the Link Items module to open in a new window?
Posts: 51
Very useful,,,,thanks for the tip & the work!!!
Kevin Logan
Posts: 3
Hi,
I dig in your post about a function to open new window in g2. for some reason, the new g2 smart_plugin file that you mention doesn't contain anything. I don't know if it is because I got the typical version. So I couldn't find those code to change. The file is completely empty... could you help?
Thanks.
Posts: 16503
As of 2.2.4
First, the file is there, but it looks like the code has changed. Make sure you are looking at /gallery2/lib/smarty_plugins and not /gallery2/lib/smarty/plugins
This is untested!
Now, it looks like you would still edit /gallery2/lib/smarty_plugins/modifier.markup.php
Around line 170 you should find a bit of code that looks like this:
} else { /* Output of HTML. */ /* The code is like http://.../ */ if (!isset ($attributes['default'])) { return '<a href="' . $content . '">' . $content . '</a>'; } else { /* The code is like Text */ return '<a href="' . $attributes['default'] . '">' . $content . '</a>'; } }Change two lines in that bit of code to this:
} else { /* Output of HTML. */ /* The code is like http://.../ */ if (!isset ($attributes['default'])) { return '<a href="' . $content . ' target="_blank" ">' . $content . '</a>'; } else { /* The code is like Text */ return '<a href="' . $attributes['default'] . ' target="_blank" ">' . $content . '</a>'; } }Again, this is untested.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 16
Is there any way to get "Link Items" to open in a new window with a modification like this?
Posts: 47
In version 2.3, same file, modifier.markup.php, lines 170-178 just add target="_blank" twice before rel="nofollow":
/* Output of HTML. */
/* The code is like http://.../ */
if (!isset($attributes['default'])) {
return '<a href="' . $content . '" target="_blank" rel="nofollow">' . $content . '</a>';
} else {
/* The code is like Text */
return '<a href="' . $attributes['default'] . '" target="_blank" rel="nofollow">'
. $content . '</a>';
}
Posts: 14
I made the changes as directed to the modifier.markup.php file. No luck.
What I want is a click on a link to an external URL to open that page in a new window. Now, it's replacing the Gallery, and you must hit back to return.
Is this change what is needed to get the result I want?