Imageblock.External - modify link target

wogri

Joined: 2005-10-06
Posts: 8
Posted: Thu, 2005-10-06 08:05

Hi!

I like the imageblock.external feature a lot. Unfortunately there doesn't seem to be a possibility to modify the link target. I would like to have either no link at all, or sometimes different targets. That shouldn't be a big patch. Is it possible to implement this?

I'd like something like this:

@readfile('http://my.gallery.com/gallery/main.php?g2_view=imageblock.External&g2_blocks=weeklyImage&g2_show=title&g2_itemId=39907&link=http://www.google.com'

and:

@readfile('http://my.gallery.com/gallery/main.php?g2_view=imageblock.External&g2_blocks=weeklyImage&g2_show=title&g2_itemId=39907&link=none'

If the creator of this module could write this up - shouldn't take him longer than an hour to do this...

thanks
wogri

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Thu, 2005-10-06 09:13

heh, thanks for estimating the time to implement this ;)

you can file a feature request on http://sf.net/projects/gallery/ for it, there are lots of small requests, so this probably won't be implemented very soon... of course you're free to submit a patch.

Login or register to post comments
wogri

Joined: 2005-10-06
Posts: 8
Posted: Thu, 2005-10-06 09:16

Well... instead of waiting, I'll submit a patch - sooner or later.
Though it might take me 3 hours instead of one :)

wogri

Login or register to post comments
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8598
Posted: Thu, 2005-10-06 15:47

doesn't site admin / imageblock list a param called linkTarget?

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Thu, 2005-10-06 16:15

isn't the linktarget argument to specify whether to open the links in the windows (<a href= ... target=...)?

Login or register to post comments
wogri

Joined: 2005-10-06
Posts: 8
Posted: Sat, 2005-10-08 09:44

the linkTarget is what valiant describes. here's my patch to achieve what I wanted. After patching you have an extra parameter called 'g2_link' which can have the options 'none' or 'linkname'. If g2_link is not defined, the default link to the gallery itself is applied. If set to none, it won't link anywhere, and if set to e.g http://www.google.com it will link there.

example:
<?php @readfile('http://gallery.on.my.server/gallery/main.php?g2_view=imageblock.External&g2_blocks=weeklyImage&g2_show=title&g2_itemId=39907&g2_link=http://www.google.com'); ?>

Here's the patch (which took me 2 hours), please let me know if you'll merge it in to your main galler code, I would be very happy about that!
(apply with patch -p0 in the modules/imageblock directory).

diff -Nur ../imageblock.bak/External.inc ./External.inc
--- ../imageblock.bak/External.inc 2005-08-23 05:49:43.000000000 +0200
+++ ./External.inc 2005-10-08 11:20:25.000000000 +0200
@@ -64,7 +64,7 @@
$frameIds = array();
$params = array('maxSize' => null);
foreach (array('blocks', 'show', 'itemId', 'maxSize',
- 'linkTarget', 'itemFrame', 'albumFrame') as $key) {
+ 'linkTarget', 'itemFrame', 'albumFrame', 'link') as $key) {
$tmp = GalleryUtilities::getRequestVariables($key);
if (!empty($tmp)) {
$params[$key] = $tmp;
diff -Nur ../imageblock.bak/classes/ImageBlockHelper.class ./classes/ImageBlockHelper.class
--- ../imageblock.bak/classes/ImageBlockHelper.class 2005-09-07 12:32:17.000000000 +0200
+++ ./classes/ImageBlockHelper.class 2005-10-06 12:19:33.000000000 +0200
@@ -111,6 +111,9 @@
if (isset($params['linkTarget'])) {
$ImageBlockData['linkTarget'] = $params['linkTarget'];
}
+ if (isset($params['link'])) {
+ $ImageBlockData['link'] = $params['link'];
+ }

if (!empty($blocks)) {
/* Prepare image frames, if available */
diff -Nur ../imageblock.bak/templates/ImageBlock.tpl ./templates/ImageBlock.tpl
--- ../imageblock.bak/templates/ImageBlock.tpl 2005-09-01 20:53:46.000000000 +0200
+++ ./templates/ImageBlock.tpl 2005-10-08 11:17:51.000000000 +0200
@@ -9,13 +9,18 @@
{if !empty($block.title)}
<h3> {g->text text=$block.title} </h3>
{/if}
-
- {capture name="link"}
- <a href="{g->url arg1="view=core.ShowItem" arg2="itemId=`$block.id`"}" {strip}
- {if isset($ImageBlockData.linkTarget)}
- target="{$ImageBlockData.linkTarget}"
- {/if}{/strip}>
- {/capture}
+ {if empty($ImageBlockData.link)}
+ {capture name="link"}
+ <a href="{g->url arg1="view=core.ShowItem" arg2="itemId=`$block.id`"}" {strip}
+ {if isset($ImageBlockData.linkTarget)}
+ target="{$ImageBlockData.linkTarget}"
+ {/if}{/strip}>
+ {/capture}
+ {else}
+ {if $ImageBlockData.link != 'none'}
+ <a href="{$ImageBlockData.link}">
+ {/if}
+ {/if}
{if $block.item.canContainChildren}
{assign var=frameType value="albumFrame"}
{else}
@@ -34,7 +39,9 @@
{g->container type="imageframe.ImageFrame" frame=$ImageBlockData.$frameType}
{$smarty.capture.link}
{g->image item=$imageItem image=$block.thumb id="%ID%" class="%CLASS%" maxSize=$maxSize}
- </a>
+ {if $ImageBlockData.link !='none'}
+ </a>
+ {/if}
{/g->container}
{else}
{$smarty.capture.link}
diff -Nur ../imageblock.bak/templates/blocks/ImageBlock.tpl ./templates/blocks/ImageBlock.tpl
--- ../imageblock.bak/templates/blocks/ImageBlock.tpl 2005-07-29 05:22:02.000000000 +0200
+++ ./templates/blocks/ImageBlock.tpl 2005-10-06 12:42:38.000000000 +0200
@@ -7,6 +7,7 @@
{g->callback type="imageblock.LoadImageBlock"
blocks=$blocks|default:null maxSize=$maxSize|default:null
itemId=$itemId|default:null linkTarget=$linkTarget|default:null
+ link=$link|default:null
useDefaults=$useDefaults|default:true
showHeading=$showHeading|default:true
showTitle=$showTitle|default:true showDate=$showDate|default:true

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Sat, 2005-10-08 09:49

wogri,
cool :)
can you please submit your patch to the Patches tracker on http://sf.net/projects/gallery/ ?
thanks!

Login or register to post comments
Haplo
Haplo's picture

Joined: 2004-03-29
Posts: 82
Posted: Sat, 2005-10-08 11:34

nice patch
i was requesting something similar a week ago. thanx
now, this patch should be expanded and such an alternative link option should be available for ANY album, also within the main Gallery enovironemt

http://gallery.menalto.com/node/37747

Login or register to post comments
wogri

Joined: 2005-10-06
Posts: 8
Posted: Sat, 2005-10-08 17:44

I submitted the patch on sf. though I forgot to prefix it with [g2], and as I submittet anonymously, I can't change it anymore, sorry for that.

http://sourceforge.net/tracker/index.php?func=detail&aid=1318485&group_id=7130&atid=307130

ID is: 1318485

Thanks for merging into the main gallery code!

wogri

Login or register to post comments
wogri

Joined: 2005-10-06
Posts: 8
Posted: Sat, 2005-10-08 17:54

To Haplo:

Thanks for liking my patch. I won't expand to your needs though, as I am a networker, not an programmer.
If you find bugs in my patch I will try correct it, but I won't (just not a good programmer here) go into the core gallery code.

wogri

Login or register to post comments
boricua

Joined: 2005-11-26
Posts: 44
Posted: Sun, 2005-11-27 00:43

Hi:

Was this one included in v2.01?? If not, How I could access this functionality??

Thanks

note:
I found out how to patch it.

Login or register to post comments
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8598
Posted: Tue, 2006-04-04 22:49

this didn't make it into 2.1, sorry.. but it is in CVS now. thanks!

Login or register to post comments
boricua

Joined: 2005-11-26
Posts: 44
Posted: Sun, 2006-11-12 23:07

Hi:

IS this included in Gallery 2.2 SVN? g2_linkTarget is not working here with the image block.

Later

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Sun, 2006-11-12 23:56

yes. see site admin -> imageblock

Login or register to post comments
boricua

Joined: 2005-11-26
Posts: 44
Posted: Mon, 2006-11-13 00:09

Hi Valiant:

g2_linkTarget is NOT working. It keeps goin into Gallery 2 url for photo in the block.

Setup: Gallery 2.2 rev 15139, PHP 5.2.0, Apache 2.2.3, LINUX RHEL 4, MySQL 4.1.21

Later

:(

Login or register to post comments
boricua

Joined: 2005-11-26
Posts: 44
Posted: Mon, 2006-11-13 01:25

Hi again:

Well, it is somekind strage here is what I found. The linkTarget works this way:

<?php
include('http://sitename/gallery2/main.php?g2_view=imageblock.External&g2_show=none&g2_linkTarget=_blank');
?>

IF I try with @readfile, the g2_linkTarget is not executed... At least the first way works...

Later

Login or register to post comments
boricua

Joined: 2005-11-26
Posts: 44
Posted: Mon, 2006-11-13 01:52

Hi again:

Finally it is working as I want. I am posting the code so others may use it...

<?php
include('http://www.sitename.com/modules/Gallery2/gallery22/main.php?g2_view=imageblock.External&g2_show=none&g2_link=http://www.sitename.com/Gallery2.phtml&g2_linkTarget=_blank');
?>

This makes the image block open new browser window AND refer to the url provided. Still need to tweak to show more than one picture but that should be easy, IMO.

Regards!

p.d.
It is weird, if I use the amp; after &, the block stop working and behaves without following the linkTarget. So I out back the & sign alone and it works again.

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Mon, 2006-11-13 04:47

use &amp; in html and & in php. the include() command is php, thus you should use & there.

Login or register to post comments
boricua

Joined: 2005-11-26
Posts: 44
Posted: Tue, 2006-11-14 03:23

One more question...

How I can use width and heigh with this approach? I mean specifying a block size without editing the template and making it 'general'... Want to be able to use diffrent size for a block...

Later
:)

Login or register to post comments
schultzy

Joined: 2005-11-04
Posts: 7
Posted: Wed, 2007-03-07 05:55

I don't know a lot about making changes, but what file do I add the code to to get this to work?

Login or register to post comments
jleezer

Joined: 2007-04-01
Posts: 5
Posted: Tue, 2007-04-03 17:54

Thank you so much for implementing this mod. Being able to specify the destination for the link was exactly what I needed. At first I was a bit nervous about upgrading my installation from the nightly updates, but everything seems to be working fine. And it went quite smoothly.

Thanks again for everything Gallery2 related.

Login or register to post comments