]> www.average.org Git - mkgallery.git/blobdiff - mkgallery.pl
work in progress on methods
[mkgallery.git] / mkgallery.pl
index 54adf58c3842d38696be97d2554d9bfa0c2f5452..bef05ccb7cc6397cfd019822abdf86528b91811f 100755 (executable)
 #     misrepresented as being the original software.
 #  3. This notice may not be removed or altered from any source distribution.
 
+package FsObj;
+
 use strict;
 use Carp;
 use POSIX qw/getcwd/;
 use CGI qw/:html *table *center *div/;
 use Image::Info qw/image_info dim/;
+use Term::ReadLine;
+
 use Image::Magick;
 
-my $ask=1;
-my $startdir=getcwd;
+my $debug=0;
+
+######################################################################
+
+FsObj->new(getcwd)->iterate;
+
+sub new {
+       my $this = shift;
+       my $class;
+       my $self;
+       if (ref($this)) {
+               $class = ref($this);
+               my $parent = $this;
+               my $path = $parent->{-path};
+               my $name = shift;
+               $path .= '/' if ($path);
+               $path .= $name;
+               my $fullpath = $parent->{-fullpath}.'/'.$name;
+               $self = {
+                               -parent=>$parent,
+                               -root=>$parent->{-root},
+                               -path=>$path,
+                               -base=>$name,
+                               -fullpath=>$fullpath,
+                               -inc=>'../'.$parent->{-inc},
+                       };
+       } else {
+               $class = $this;
+               my $root=shift;
+               $self = {
+                               -root=>$root,
+                               -fullpath=>$root,
+                               -inc=>getinc($root),
+                       };
+       }
+       bless $self, $class;
+       if ($debug) {
+               print "new $class:\n";
+               foreach my $k(keys %$self) {
+                       print "\t$k\t=\t$self->{$k}\n";
+               }
+       }
+       return $self;
+}
+
+sub getinc {
+       my $fullpath=shift;     # this is not a method
+       my $depth=20;           # arbitrary max depth
+
+       my $inc=".include";
+       while ( ! -d $fullpath."/".$inc ) {
+               $inc = "../".$inc;
+               last unless ($depth-- > 0);
+       }
+       if ($depth > 0) {
+               return $inc.'/';        # prefix with trailing slash
+       } else {
+               return 'NO-.INCLUDE-IN-PATH/'; # won't work anyway
+       }
+}
+
+sub iterate {
+       my $self = shift;
+       my $fullpath .= $self->{-fullpath};
+       print "iterate in dir $fullpath\n" if ($debug);
+
+       my @rdirlist;
+       my @rimglist;
+       my $D;
+       unless (opendir($D,$fullpath)) {
+               warn "cannot opendir $fullpath: $!";
+               return;
+       }
+       while (my $de = readdir($D)) {
+               next if ($de =~ /^\./);
+               my $child = $self->new($de);
+               if ($child->isdir) {
+                       push(@rdirlist,$child);
+               } elsif ($child->isimg) {
+                       push(@rimglist,$child);
+               }
+       }
+       closedir($D);
+       my @sdirlist = sort {$a->{-base} cmp $b->{-base}} @rdirlist;
+       undef @rdirlist; # inplace sorting would be handy here
+       my @simglist = sort {$a->{-base} cmp $b->{-base}} @rimglist;
+       undef @rimglist; # optimize away unsorted versions
+
+# 1. first of all, fill title for this directory and create hidden subdirs
+
+       $self->initdir;
+
+# 2. iterate through subdirectories to get their titles filled
+
+       foreach my $dir(@sdirlist) {
+               print "Dir: $dir->{-fullpath}\n" if ($debug);
+               $dir->iterate;
+       }
+
+# 3. start building directory index.html
+# 4. iterate through subdirectories to build subalbums list
+# 5. iterate through images to build cross-links
+
+       foreach my $img(@simglist) {
+               print "Img: $img->{-fullpath}\n" if ($debug);
+       }
+
+# 6. iterate through images to build thumb list and aux html files
 
+}
+
+sub isdir {
+       my $self = shift;
+       return ( -d $self->{-fullpath} );
+}
+
+sub isimg {
+       my $self = shift;
+       my $fullpath = $self->{-fullpath};
+       return 0 unless ( -f $fullpath );
+       my $info = image_info($fullpath);
+       if (my $error = $info->{error}) {
+               if (($error !~ "Unrecognized file format") &&
+                   ($error !~ "Can't read head")) {
+                       warn "File \"$fullpath\": $error\n";
+               }
+               return 0;
+       }
+       $self->{-isimg} = 1;
+       $self->{-info} = $info;
+       return 1;
+}
+
+sub initdir {
+       my $self = shift;
+       my $fullpath = $self->{-fullpath};
+       # do stuff
+}
+
+######################################################################
+=cut
 ######################################################################
 
-&processdir($startdir);
+&processdir(getcwd);
 
 sub processdir {
        my ($start,$dir)=@_;