[Album] [PATCH] Use the full path to find files instead of assuming where they are

Scott J. Bertin scottbertin@y...
Tue Nov 22 18:01:35 PST 2005


The following patch to album 3.10 uses the full path to find files   in 
case a plugin puts them in an unexpected place. I have a plugin that 
allows all of the image files to be someplace other than the location 
normally used by album. I'll send it to the list soon, I just need to 
document it first.

Scott J. Bertin
scottbertin@y...

Index: album
===================================================================
RCS file: /Users/scottbertin/.cvsroot/album/album,v
retrieving revision 1.4
diff -u -r1.4 album
--- album	18 Nov 2005 14:51:42 -0000	1.4
+++ album	18 Nov 2005 18:05:54 -0000
@@ -4548,11 +4548,11 @@

    # Paths
    my $dir = $data->{paths}{dir};
-  my $path = "$dir/$pic";
    my $obj = $data->{obj}{$pic};
+  my $path = $obj->{full}{path};

    # Figure out type
-  $obj->{is_movie} = is_movie($opt,$pic);
+  $obj->{is_movie} = is_movie($opt,$path);
    my $can_embed = $obj->{is_movie};
    $can_embed = 1 if $pic =~ /\.(pdf|ps)$/i;
    my $tag = 'img';
@@ -4625,12 +4625,15 @@
    # -no_embed USED to mean that movie pages didn't have image pages..
    #$use_image_pages = 0 if $obj->{is_movie} && !$opt->{embed};

+  my $image_dir = "$opt->{dir}/" if $opt->{dir};
+  my $image_path = "$dir/$image_dir";
    if ($use_image_pages) {
      my $image_page = "$pic$data->{paths}{page_post_url}";
-    $obj->{URL}{album_page}{image} = url_quote($opt, 
"$opt->{dir}/$image_page");
+    $obj->{URL}{album_page}{image} = url_quote($opt, 
"$image_dir$image_page");
  # Kludge - the number of ".." should be equal to the pathsize of 
$opt->{dir}
      my $image = ($opt->{just_medium} && $obj->{thumb})
-      ? $obj->{medium}{file} : "../$pic";
+      ? $obj->{medium}{path} : $obj->{full}{path};
+    $image = diff_path($opt, $image_path, $image);
      $obj->{URL}{image_page}{image} = url_quote($opt, $image);
      $obj->{URL}{image_page}{image_page} = url_quote($opt, $image_page);

@@ -4638,28 +4641,35 @@
      # -embed: pic or medium, but pic if movie (../$pic)
      # -noembed and -medium:	medium
      # -noembed and -nomedium:	snapshot
-    my $image_src = $obj->{medium}{file} || "../$pic";
+    my $image_src = $obj->{medium}{path} || $obj->{full}{path};
      if ($obj->{snapshot}{file}) {
-      $image_src = $opt->{embed} ? "../$pic" :
-        ($obj->{medium}{file} || $obj->{snapshot}{file});
+      $image_src = $opt->{embed} ? $obj->{full}{path} :
+        ($obj->{medium}{path} || $obj->{snapshot}{path});
      }
+    $image_src = diff_path($opt, $image_path, $image_src);
      $obj->{URL}{image_page}{image_src} = url_quote($opt, $image_src);

      # Thumbnail
-    $obj->{URL}{album_page}{thumb} = url_quote($opt, 
"$opt->{dir}/$obj->{thumb}{file}");
-    $obj->{URL}{image_page}{thumb} = url_quote($opt, $obj->{thumb}{file});
+    $obj->{URL}{album_page}{thumb} =
+      url_quote($opt, diff_path($opt, $dir, $obj->{thumb}{path}));
+    $obj->{URL}{image_page}{thumb} =
+      url_quote($opt, diff_path($opt, $image_path, $obj->{thumb}{path}));
    } else {
-    $obj->{URL}{album_page}{image} = url_quote($opt, $pic);
-    $obj->{URL}{album_page}{thumb} = url_quote($opt, 
"$opt->{dir}/$obj->{thumb}{file}");
+    $obj->{URL}{album_page}{image} =
+      url_quote($opt, diff_path($opt, $dir, $obj->{full}{path}));
+    $obj->{URL}{album_page}{thumb} =
+      url_quote($opt, diff_path($opt, $dir, $obj->{thumb}{path}));
      # We might normally have image pages, just not for this non-image
-    $obj->{URL}{image_page}{image_page} = url_quote($opt, "../$pic")
+    $obj->{URL}{image_page}{image_page} =
+      url_quote($opt, diff_path($opt, $image_path, $obj->{full}{path}))
        if $opt->{image_pages};
    }

    # -transform_url
    if ($opt->{transform_url}) {
      $obj->{URL}{album_page}{image} = $opt->{transform_url};
-    $obj->{URL}{album_page}{image} =~ s/%S/$pic/g;
+    my $pic_path = diff_path($opt, $dir, $obj->{full}{path});
+    $obj->{URL}{album_page}{image} =~ s/%S/$pic_path/g;
      my $s = $pic;  $s =~ s/\.[^\.]+$//;
      $obj->{URL}{album_page}{image} =~ s/%s/$s/g;
    }





More information about the Album mailing list