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.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | galleria.i18n-url-generation.patch | 866 bytes | Peter Bex |
| galleria.i18n-url-generation.patch | 713 bytes | Peter Bex |
Comments
Comment #1
chirale commentedThanks Peter, this patch works like a charm on 6.x-1.0!
I hope it'll be applied soon to Galleria.
Comment #2
volito commentedthank 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.
Comment #3
piotr_a commentedThis 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.
Comment #4
Peter Bex commentedI'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 callsimagecache_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.Comment #5
piotr_a commentedNow it works, thanks Peter
Comment #6
Peter Bex commentedHere's a new version of the patch that also includes my fix of comment #4.
Comment #7
hexblot commentedFor 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);
Comment #8
josephcheekwhy does this code use alt tags? it breaks Section 508 compatibility.
http://www.section508.info/section-508-checklist.cfm
Comment #9
Peter Bex commentedGood 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).
Comment #10
davidkebo commentedHello,
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?
Comment #11
ioanmar commentedI 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!
Comment #12
Peter Bex commentedI 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.patchassuming 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.
Comment #13
ioanmar commentedThank you so much for your help!
(just so the last reply... and it's been a while!)
Comment #14
luxigo commentedI 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