The link to the main image that is generated by the code that handles the case where no imagecache preset is used for the main image is wrong when using i18n and using a prefix for selecting the language.

For example, if an image path is "foo.jpg", the link generated is something like "/en/sites/default/files/foo.jpg", which is clearly wrong because there is no 'en' directory on the server. It should be "/sites/default/files/foo.jpg". This is caused by the l() function when using it with a relative path. Instead of letting the URL be generated by l(), it should be fully generated by file_create_url() before handing it off to l(). Full URLs including the scheme are _not_ rewritten, so this problem will not occur.

Attached is a patch to fix this problem.

Comments

chirale’s picture

Thanks Peter, this patch works like a charm on 6.x-1.0!

I hope it'll be applied soon to Galleria.

volito’s picture

thank you for saving my day! i had the same problem with a dual language installation when using galleria with lightbox2 integration. note, that the patch only worked, after explicitly setting a Lightbox ImageCache preset under galleria settings.

piotr_a’s picture

Version: 6.x-1.x-dev » 6.x-1.0
Assigned: Unassigned » piotr_a

This path don't work for me on 6.x-1.0.

Image link are incorrect when using i18n only if you want to show in lightbox orginal image, if you explicitly setting a "Lightbox ImageCache preset" under galleria settings. Then picture will be show - but this work with or without this path.

Peter Bex’s picture

I'm not using a Lightbox on the site I needed this for, so I think this is a different error.

Perhaps the problem occurs in the bit above the code I patched (line 302 which says $alt_text = url($filepath, array('absolute' => TRUE));). Indeed when using a preset it follows a different code path that calls imagecache_create_url, which presumably does create a proper URL.

Try changing that line 302 so it reads $alt_text = file_create_url($filepath); instead. That might fix the problem when using lightboxes.

piotr_a’s picture

Now it works, thanks Peter

Peter Bex’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new866 bytes

Here's a new version of the patch that also includes my fix of comment #4.

hexblot’s picture

For some reason, the above patch did not fix my problem.

My use-case is the same as the user above, I display an image-cached thumbnail along with an image-cached full image, which opens in lightbox when clicked to the original image size.

After checking the code, it appears that file_create_path() generates relative paths ( using drupal core 6.17 ), so adding base_path() before the alt_text did the thing for me.

If anyone else has this problem, solution is to change the line

$alt_text = url($filepath, array('absolute' => TRUE));

to

$alt_text = base_path().file_create_path($filepath);

josephcheek’s picture

why does this code use alt tags? it breaks Section 508 compatibility.

http://www.section508.info/section-508-checklist.cfm

Peter Bex’s picture

Good point; that's seriously bogus.

I suggest you create a new ticket for that though, since this has nothing to do with the bug under discussion (the original code uses alt tags; my patch does not change that - it just fixes a bug in the creation of a path).

davidkebo’s picture

Hello,
I have the same problem as well.
Looks like all the answers apply to the Galleria module.
Im am using the lightbox module only, not Galleria.
How can i fix this please, thanks?

ioanmar’s picture

I have a very similar problem with my Galleria gallery of photos I was planning to put in my front page for a photographer's online portfolio project. According to Firebug, Galleria is trying to fetch the thumbnails using the wrong path (the site is bilingual, Greek and English, and there is always the language -either "el" for Greek or "en" for English- prefix added in the beginning of the path). This is the only place I've found a way to possibly fix this problem but I don't know how to use this patch, as I'm have never user Xcode (I prefer to use that instead of Terminal as it seems more user-friendly for my case). I'm downloading Xcode to install it. Can someone give me some help on how to apply this patch using Xcode?
Thanks a lot guys!

Peter Bex’s picture

I have absolutely no clue how XCode works, but applying a patch from the terminal is easy. Just navigate with "cd" to the directory where the files to patch are (the module directory) and type patch < ~/galleria.i18n-url-generation.patch assuming you saved it to your home directory.

If you're using a graphical version control tool it may have a built-in system for applying patch files. However, it's probably a good idea to learn the commandline basics since it's a very useful skill when dealing with open source projects. People generally kinda assume you're working on the commandline of a Unix-like system, or know the equivalent GUI operations yourself.

ioanmar’s picture

Thank you so much for your help!
(just so the last reply... and it's been a while!)

luxigo’s picture

Issue tags: +galleria

I have almost the same problem with drupal-7.0 i18n and Galleria 7.x-1.x-dev (2011-Feb-25)

In function Galleria.Picture.load(), jquery.galleria.js, line 3598 (Galleria v 1.2 prerelease 1.1 2010-11-23)
src is equal to //sites/default/files/img.jpg and the browser try to load http://sites/default/files/img.jpg

Please note that my Drupal install is in a subdirectory: the file path MUST be relative. :

The proposed patch doesn't apply to module version 7.x-1.x-dev

This one solves the problem

--- drupal_7/sites/all/modules/galleria/galleria-container.tpl.php.orig 2011-03-02 12:44:02.000000000 +0100
+++ drupal_7/sites/all/modules/galleria/galleria-container.tpl.php      2011-03-02 12:45:11.000000000 +0100
@@ -6,7 +6,7 @@
  * Default output for a galleria node.
 */
 ?>
-<?php if ((count($images) > 0) && isset($path)): ?>
+<?php if ((count($images) > 0) && isset($path)): $path=preg_replace('/^\/+/','',$path); ?>
   <div class="galleria-content">
       <ul class="gallery">
       <?php foreach($images as $key => $val): ?>