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

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 7.x-1.x!

 gallery_manage.inc   |   14 ++++++++------
 gallery_showtime.inc |   31 ++++++++++++++++++-------------
 views.inc            |   21 +++++++++++++--------
 3 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/gallery_manage.inc b/gallery_manage.inc
index 99a54c8..40b450b 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);
@@ -96,15 +95,18 @@ HEADER;
           #@$smallenough = $retval_dimensions[$poct - 1]['smallenough'];
           #$style_li = "float: left; width: " . $imagewidth . "px; list-style: none; background: " . $bgcolour . "; height: " . $imagemaxh . "px; padding: " . $padding . "px; text-align: center; margin: 0; border: none;"; #$style_li = "float: left; list-style: none; background: #000; width: 44px; height: 33px; padding: 4px; text-align: center; margin: 0; 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);
+
           $displayimage = '';
           #if ($smallenough === true) {
           #  $displayimage .= '<br><a href="'. $fullimgpath .'"';
diff --git a/gallery_showtime.inc b/gallery_showtime.inc
index ea127c2..b40cca3 100644
--- a/gallery_showtime.inc
+++ b/gallery_showtime.inc
@@ -75,10 +75,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 = '';
@@ -144,13 +144,14 @@ function render_brilliant_gallery($paramarray = array()) {
   }
   $padding = variable_get('brilliant_gallery_padding', 3);
   $overbrowser = variable_get('brilliant_gallery_overbrowser', 'lightbox');
+
   // Totally full resolution display would be impractical, so this is the maximum width of "full" resolution.
   $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);
@@ -424,15 +425,18 @@ 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) {
         #  $result .= '<a href="'. $fullimgpath .'"';
         #}
@@ -496,10 +500,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 4c3c406..6daf16a 100644
--- a/views.inc
+++ b/views.inc
@@ -141,22 +141,27 @@ function brilliant_gallery_views_handler_image_img($fieldinfo, $fielddata, $valu
   $result  = $absolpath . '/' . $retval[$randimg];
   $temp    = getimagesize($result);
   #$imagewidth = variable_get('brilliant_gallery_maximagewidth', 150);
+
   # 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) . '"';
   $setname     = mt_rand(1, 9999999);
   $overbrowser = variable_get('brilliant_gallery_overbrowser', 'thickbox');
-- 
1.7.2.3


