Subject: [PATCH] Multilingual support: fix prefix of the urls.
Date: Fri,  4 Feb 2011 17:33:59 -0200
X-Mailer: git-send-email 1.7.2.3
X-Length: 7345
X-UID: 2262

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

 brilliant_gallery.module |   47 +++++++++++++++++++++++++++------------------
 views.inc                |   19 ++++++++++-------
 2 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/brilliant_gallery.module b/brilliant_gallery.module
index 3fc4abc..59bdf75 100644
--- a/brilliant_gallery.module
+++ b/brilliant_gallery.module
@@ -384,12 +384,14 @@ HEADER;
   $setname       = mt_rand(1, 9999999);
   $galleryfolder = variable_get('brilliant_gallery_folder', '');
   $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);
+
   $rp = file_directory_path();
   if ($galleryfolder <> '') {
     $rp .= '/'. $galleryfolder;
@@ -457,10 +459,11 @@ HEADER;
           #$result .= ('<li style="' . $style_li . '">' . "\n");
           # Get this module's path:
           $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);
           $displayimage = '';
@@ -576,10 +579,11 @@ function render_brilliant_gallery($thisfolder = '', $colcountoverride = '', $wid
   #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 = '';
   $galleryfolder = variable_get('brilliant_gallery_folder', '');
@@ -647,10 +651,10 @@ function render_brilliant_gallery($thisfolder = '', $colcountoverride = '', $wid
   // 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);
@@ -802,14 +806,17 @@ function render_brilliant_gallery($thisfolder = '', $colcountoverride = '', $wid
       #$style_li = "float: left; list-style: none; background: #000; width: 44px; height: 33px; padding: 4px; text-align: center; margin: 0; border: none;";
       $style_li = "font-size:0; float: left; width: ". $imagewidth ."px; list-style: none; background: ". $bgcolour ."; height: ". $imagemaxh ."px; padding: ". $padding ."px; text-align: center; 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));
+
       # 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 .'"';
       #}
@@ -848,13 +855,15 @@ function render_brilliant_gallery($thisfolder = '', $colcountoverride = '', $wid
         $result .= ' title="'. $caption .'"';
       }
       $result .= '>';
+
       # 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 8f550c7..6a0719e 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="'. $modulepath .'/image.php?imgp='. base64_encode($absolpath .'/'. $retval[$randimg]) .'&imgw='. $imgw * 6 .'&imgh='. $imgh * 6 .'"';
-- 
1.7.2.3


