Links to New Windows

sconnelly
sconnelly's picture

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
hyperSystems, Inc. http://www.hypersystems.us
phone: 720-260-3200, fax: 303-740-0329

 
AggieJon

Joined: 2005-08-06
Posts: 4
Posted: Wed, 2005-09-21 18:58

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.

 
nemloc

Joined: 2005-11-25
Posts: 23
Posted: Sun, 2005-11-27 18:30

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?

 
AggieJon

Joined: 2005-08-06
Posts: 4
Posted: Sun, 2005-11-27 18:54

There is a feature request for this. Go vote for it! #1262123

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Sun, 2005-11-27 20:51
nemloc wrote:
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?

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.

 
pah

Joined: 2005-12-21
Posts: 16
Posted: Sat, 2006-10-28 20:01

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

 
guilliam
guilliam's picture

Joined: 2006-01-20
Posts: 3
Posted: Sat, 2007-01-20 05:40

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

 
djpumpkin

Joined: 2006-12-06
Posts: 135
Posted: Fri, 2007-10-05 19:00

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

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Sat, 2007-10-06 04:19

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

 
djpumpkin

Joined: 2006-12-06
Posts: 135
Posted: Fri, 2007-11-09 21:20

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?

 
Kevin Logan
Kevin Logan's picture

Joined: 2006-07-06
Posts: 51
Posted: Mon, 2007-11-26 12:05

Very useful,,,,thanks for the tip & the work!!!

Kevin Logan

 
alixky

Joined: 2007-03-19
Posts: 3
Posted: Wed, 2008-01-23 12:03

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.

sconnelly wrote:
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
hyperSystems, Inc. http://www.hypersystems.us
phone: 720-260-3200, fax: 303-740-0329

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Wed, 2008-01-23 18:34

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

 
stellarblue153

Joined: 2008-02-05
Posts: 16
Posted: Fri, 2008-02-08 01:01

Is there any way to get "Link Items" to open in a new window with a modification like this?

 
CeliaD

Joined: 2009-01-03
Posts: 47
Posted: Mon, 2009-01-19 07:15

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>';
}

 
mcnesco

Joined: 2009-08-09
Posts: 14
Posted: Tue, 2009-10-06 04:06

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?