Subject: [PATCH] Multilingual support: fix prefix of the urls.
Date: Fri,  4 Feb 2011 17:34:00 -0200
X-Mailer: git-send-email 1.7.2.3
X-Length: 7470
X-UID: 2263

This patch fix a failing correction for multilingual sites.

The language prefix is used for distinction not the language code.
---
This patch is relative to Brilliant Gallery 6.x-4.x!

 gallery_manage.inc   |   12 ++++++------
 gallery_showtime.inc |   28 +++++++++++++++-------------
 views.inc            |   19 +++++++++++--------
 3 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/gallery_manage.inc b/gallery_manage.inc
index 53d9e16..d793a8e 100644
--- a/gallery_manage.inc
+++ b/gallery_manage.inc
@@ -24,9 +24,8 @@ HEADER;
     $path          = url(file_directory_path() .'/'. $galleryfolder, array('absolute' => TRUE));
 
     # url() ads i18n codes to the URL ... we need to remove them here...
-    if ($langcode <> '') {
-        $path = str_replace('/'. $langcode .'/', '/', $path);
-    }
+    if ($langprefix <> '')
+        $path = str_replace('/'. $langprefix .'/', '/', $path);
 
     # Non-clean URLs need removing ?q=
     $path = str_replace("?q=", "", $path);
@@ -99,10 +98,11 @@ HEADER;
                     # Get this module's path:
                     //$modulepath = url(drupal_get_path('module', 'brilliant_gallery'), array('absolute' => TRUE));
                     $modulepath = drupal_get_path('module', 'brilliant_gallery');
+
                     # url() ads i18n codes to the URL ... we need to remove them here...
-                    if ($langcode <> '') {
-                        $modulepath = str_replace('/'. $langcode .'/', '/', $modulepath);
-                    }
+                    if ($langprefix <> '')
+                        $modulepath = str_replace('/'. $langprefix .'/', '/', $modulepath);
+
                     # Non-clean URLs need removing ?q=
                     $modulepath = str_replace("?q=", "", $modulepath);
                     $displayimage = '';
diff --git a/gallery_showtime.inc b/gallery_showtime.inc
index 70b9caf..8956edf 100644
--- a/gallery_showtime.inc
+++ b/gallery_showtime.inc
@@ -66,10 +66,10 @@ function render_brilliant_gallery($paramarray = array()) {
     #drupal_add_css(drupal_get_path('module', 'brilliant_gallery') .'/brilliant_gallery.css');
 
     # Patching a possible problem with i18n
-    $langcode = '';
-    if (function_exists('i18n_get_lang')) {
-        $langcode = i18n_get_lang();
-    }
+    if ( function_exists('i18n_get_lang') )
+        $langprefix = i18n_language_property(i18n_get_lang(), 'prefix');
+    else
+        $langprefix = '';
 
     #$result = '</p>';
     $result = '';
@@ -139,9 +139,8 @@ function render_brilliant_gallery($paramarray = array()) {
     $fullresolutionmaxwidth = variable_get('brilliant_gallery_maxwidth', '1000');
     $path = url(file_directory_path() .'/'. $galleryfolder, array('absolute' => TRUE));
     // url() ads i18n codes to the URL ... we need to remove them here...
-    if ($langcode <> '') {
-        $path = str_replace('/'. $langcode .'/', '/', $path);
-    }
+    if ($langprefix <> '')
+        $path = str_replace('/'. $langprefix .'/', '/', $path);
 
     // Non-clean URLs need removing ?q=
     $path = str_replace("?q=", "", $path);
@@ -407,13 +406,15 @@ function render_brilliant_gallery($paramarray = array()) {
 
                 $style_li = "font-size:0; float: left; width: ". $imagewidth_here ."px; list-style: none; background: ". $bgcolour ."; height: ". $imagemaxh_here ."px; padding: ". $padding ."px; text-align: ".$thumbalignincell."; margin: 0px; border: none;";
                 $result .= ('<li style="'. $style_li .'">' . "\n");
+
                 # Get this module's path:
                 //$modulepath = url(drupal_get_path('module', 'brilliant_gallery'), array('absolute' => TRUE));
                 $modulepath = drupal_get_path('module', 'brilliant_gallery');
+
                 # url() ads i18n codes to the URL ... we need to remove them here...
-                if ($langcode <> '') {
-                    $modulepath = str_replace('/'. $langcode .'/', '/', $modulepath);
-                }
+                if ($langprefix <> '')
+                    $modulepath = str_replace('/'. $langprefix .'/', '/', $modulepath);
+
                 # Non-clean URLs need removing ?q=
                 $modulepath = str_replace("?q=", "", $modulepath);
                 #if ($smallenough === true) {
@@ -479,10 +480,11 @@ function render_brilliant_gallery($paramarray = array()) {
                 # Important to begin with the "/" otherwise thumbnails in non-root folders fail. See http://drupal.org/node/175292
                 /*
                 $modulepath = url(drupal_get_path('module', 'brilliant_gallery'), array('absolute' => TRUE));
+
                 # url() ads i18n codes to the URL ... we need to remove them here...
-                if ( $langcode <> '' ) {
-                $modulepath = str_replace( '/' . $langcode . '/', '/', $modulepath );
-                }
+                if ( $langprefix <> '' )
+                    $modulepath = str_replace( '/' . $langprefix . '/', '/', $modulepath );
+
                 # Non-clean URLs need removing ?q=
                 $modulepath = str_replace( "?q=", "",  $modulepath );
                 */
diff --git a/views.inc b/views.inc
index 4c69197..f6b8839 100644
--- a/views.inc
+++ b/views.inc
@@ -143,17 +143,20 @@ function brilliant_gallery_views_handler_image_img($fieldinfo, $fielddata, $valu
     # Hard-coded height for this purpose.
     $imgh = 100;
     $imgw = round(($temp[0] / $temp[1]) * $imgh);
+
     # Get this module's path:
-    # Patching a possible problem with i18n
-    $langcode = '';
-    if (function_exists('i18n_get_lang')) {
-        $langcode = i18n_get_lang();
-    }
     $modulepath = url(drupal_get_path('module', 'brilliant_gallery'), array('absolute' => TRUE));
+
+    # Patching a possible problem with i18n
+    if ( function_exists('i18n_get_lang') )
+        $langprefix = i18n_language_property(i18n_get_lang(), 'prefix');
+    else
+        $langprefix = '';
+
     # url() ads i18n codes to the URL ... we need to remove them here...
-    if ($langcode <> '') {
-        $modulepath = str_replace('/'. $langcode .'/', '/', $modulepath);
-    }
+    if ($langprefix <> '')
+        $modulepath = str_replace('/'. $langprefix .'/', '/', $modulepath);
+
     # Non-clean URLs need removing ?q=
     $modulepath  = str_replace("?q=", "", $modulepath);
     $result      = '<a href="'.file_create_url($modulepath .'/image.php?imgp='. base64_encode($absolpath .'/'. $retval[$randimg]) .'&imgw='. $imgw * 6 .'&imgh='. $imgh * 6).'"';
-- 
1.7.2.3


