Hi,
I run D6.4 and the latest BG. Images on my gallery do not show. A quick look at the html shows that links to imahges are wrong such as: <a href="/index.phpsites/all/modules/brilliant_gallery/image.php?imgp=L2NsaWVudGRhdGEvd3d3L2NvbS9lL2Vra29jcmVhdGl2ZXMuY29tL3NpdGVzL2RlZmF1bHQvZmlsZXMvZWtrb2dhbGxlcnkvYXJ0Y3JhZnQvSU1HXzQ3MjQuSlBH&imgw=1000&imgh=750" rel="lightbox[2312949]" title="IMG 4724"><img style="border:0" alt="" rel="lightbox" src="/index.phpsites/all/modules/brilliant_gallery/image.php?imgp=L2NsaWVudGRhdGEvd3d3L2NvbS9lL2Vra29jcmVhdGl2ZXMuY29tL3NpdGVzL2RlZmF1bHQvZmlsZXMvZWtrb2dhbGxlcnkvYXJ0Y3JhZnQvSU1HXzQ3MjQuSlBH&imgw=115&imgh=86" /></a>. I have noticed that some people had already recorded this issue in earlier post (#283463: How to remove "index.php" from href/src tag when using [BG| ] tag? messes links up.). Any hints as to where one my start looking in order to fix the problem, assuming the galley and lightbox setup is correct? Thank you.

Comments

xaviercas’s picture

Ok,

I am not much of a coder, so here is what I have down to get the gallery working temporarily:

In the module for every instance of str_replace ( "?q=", "", ...)
I changed it to str_replace( "index.php?q=", "",...).

In image.php, I commented out all the caching processes, in essence, just keeping the resizing function.
Not pretty, but it works.

Thanks

Xavier

jostein’s picture

What do you mean by "not pretty but it works"?

That the solution isnt pretty, but the gallery looks like it is suppose to?

If so, sounds like the solution I have been waiting a month for :)

jan.n’s picture

Assigned: Unassigned » jan.n
Priority: Critical » Normal

Now what I'm wondering about is why it works for some, but not for all of us.
What's the difference in our installations?
I'm using Drupal 6.4 just like the OP and for me it works without modifications.
Which line did you modify? My line 285 reads:
$path = str_replace( "?q=", "", $path );

What else might be the problem - any ideas? I'd really like to track that down...

xaviercas’s picture

Hi,

I've deleted the 'commented out' code in the module section, therefore I cannot give you line numbers that would be helpful. So 285: $path = str_replace( "?q=", "", $path ); I have replaced "?q=" with "index.php?q=", and same for $modulepath further down.

as for image.php here is the code (as I said not pretty, basically a short term solution. the retrieval from the caches might be the issue???):

/* $Id: image.php,v 1.15.2.1 2008/07/17 20:34:53 tjfulopp Exp $ */
if ( strpos( base64_decode( $_GET['imgp'] ), "://" ) !== false ) { 
# Fixing a possible URL injection problem. Using ':' was not enough because Windows paths contain it as well.
     header("HTTP/1.0 404 Not Found");
     exit();
   }
/*drupalize();
function drupalize() {
 while (!@stat('./includes/bootstrap.inc')) {
   chdir ('..');
 }
 require_once './includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
}
$GLOBALS['devel_shutdown'] = FALSE; 
# Crucial - to suppress Devel (if installed and enabled) output appearing in the generated XML!
# Cache expiration time.*/
$bgcachexpire = 3600*24*3; 
#if ( variable_get('brilliant_gallery_cache', 'd') == 'f' ) {
     $my_data = resizeimage_wrapper_filecache();
 #  } else {
  #   $my_data = resizeimage_wrapper_dbcache();
 #  }
header($my_data[0]);
echo base64_decode($my_data[1]);           
exit(); 
# IMPORTANT - otherwise some process after BG adds strings and breaks the image!
#                                                                        
function resizeimage_wrapper_filecache() {
  /*global $bgcachexpire;
  $bgcacheid = 'bg_' . md5($_GET['imgp'] . $_GET['imgw'] . $_GET['imgh']);
  # Tested that both relative (eg sites/all/files/cache) and absolute (eg /home/data/tmp) tmp path settings work OK here.
  #$cachedfile = file_directory_temp() . '/' . $bgcacheid;
  $cachedfile =  'sites/all/files/tmp/' . $bgcacheid;
  $lastchanged = (file_exists($cachedfile) ? filemtime( $cachedfile ) : false); # See http://drupal.org/node/194923
  if ( $lastchanged === false or ( time() - $lastchanged > ( $bgcachexpire ) ) ) {*/
       $my_data = resizeimage ( $_GET['imgp'], $_GET['imgw'], $_GET['imgh'] );
       # Now put $my_data to cache!
      /* $fh = fopen( $cachedfile, "w+" );
        fwrite( $fh, $my_data );
        fclose( $fh ); */
       $my_data = unserialize( $my_data );
/*     } else {
       $my_data = unserialize( file_get_contents( $cachedfile ) );
     }*/
  return $my_data;
}

/*function resizeimage_wrapper_dbcache($reset = FALSE) {
  global $bgcachexpire;
  global $user;
   $userId = $user->uid;
  $bgcacheid = 'bg_' . md5($_GET['imgp'] . $_GET['imgw'] . $_GET['imgh']);
  static $my_data;
  if (!isset($my_data) || $reset) {
     if (!$reset && ($cache = cache_get($bgcacheid)) && !empty($cache->data)) {
      $my_data = unserialize( $cache->data );
     } else {
      // Do your expensive calculations here, and populate $my_data
      // with the correct stuff..
      $my_data = resizeimage ( $_GET['imgp'], $_GET['imgw'], $_GET['imgh'] );
      # FOR DRUPAL6 MUST USE:
        cache_set($bgcacheid,  $my_data, 'cache',time() + $bgcachexpire);
      $my_data = unserialize( $my_data );
    }
  }
  return $my_data;
}*/
/******************************************
Resize
******************************************/
function resizeimage( $imgp, $imgw, $imgh ) {
         $imagepath = base64_decode( $imgp );
         $suffix = strtolower(substr($imagepath, -4)); # Thanks to Michał Albrecht!
         $imgsize = @getimagesize($imagepath);
          $head = "Content-type: {$imgsize['mime']}"; 
		  # http://be.php.net/getimagesize
         if ( $suffix == ".gif" ) {
              #$head = "Content-type: image/gif";
              $img = imagecreatefromgif( $imagepath );
              if (!$img) { brokenimage("Error loading GIF"); }
            } else if ( $suffix == ".jpg" or $suffix == "jpeg" ) { # Thanks to Michał Albrecht!
              $img = imagecreatefromjpeg( $imagepath );
              if (!$img) { brokenimage("Error loading JPG"); }
            } else if ( $suffix == ".png" ) {
              $img = imagecreatefrompng( $imagepath );
              if (!$img) { brokenimage("Error loading PNG"); }
            }
         # Resize the image
           $src_h = imagesy( $img );
           $src_w = imagesx( $img );
           $dst_img = imagecreatetruecolor( $imgw, $imgh );
           imagecopyresampled( $dst_img, $img, 0, 0, 0, 0, $imgw, $imgh, $src_w, $src_h );
           $img = $dst_img;
         imageinterlace ( $img, 1 );
         imagecolortransparent ( $img );
         ob_start();
           if ( $suffix == ".gif" ) {
                Imagegif($img);
              } else if ( $suffix == ".jpg" or $suffix == ".jpeg" ) {
                Imagejpeg($img,'',80);
              } else if ( $suffix == ".png" ) {
                Imagepng($img);
              }
         $result = ob_get_clean();
         $result = serialize(array($head, base64_encode( $result )));
         return $result;
       }
                                                      

I would also suggest at a latter stage adding to classes instead of inline css. And yes, I do not understand either why it might work on some install and not others.
Cheers