rss generation seems to work somehow
authorEugene Crosser <crosser@average.org>
Thu, 4 Sep 2008 20:02:49 +0000 (20:02 +0000)
committerEugene Crosser <crosser@average.org>
Thu, 4 Sep 2008 20:02:49 +0000 (20:02 +0000)
mkgallery.pl
mkgalrss.pl [deleted file]

index f672b6c3895234f6665d6da8a8eda1abb566bfa2..40840b76e1425b639b8412ea592c7a5bf475acb9 100755 (executable)
@@ -44,6 +44,7 @@ my $haverssxml = eval { require XML::RSS; };
 { package XML::RSS; }          # to make perl compiler happy
 
 my @sizes = (160, 640, 1600);
+my $incdir = ".gallery2";
 
 ######################################################################
 
@@ -137,32 +138,35 @@ sub initpaths {
        my $depth=20;           # arbitrary max depth
        my $fullpath=$self->{-fullpath};
        my $inc;
-       my $rss;
        my $relpath;
 
        if ($incpath) {
-               $inc = $incpath."/.gallery2";
+               $inc = $incpath;
+               $inc .= '/' unless ($inc =~ m%/$%);
        } else {
-               $inc=".gallery2";
-               while ( ! -d $fullpath."/".$inc ) {
+               $inc="";
+               while ( ! -d $fullpath."/".$inc."/".$incdir ) {
                        $inc = "../".$inc;
                        last unless ($depth-- > 0);
                }
        }
        if ($depth > 0) {
-               $self->{-inc} = $inc.'/';
+               $self->{-inc} = $inc;
                my $dp=0;
                my $pos;
                for ($pos=index($inc,'/');$pos>=0;
                                        $pos=index($inc,'/',$pos+1)) {
                        $dp++;
                }
-               for ($pos=length($fullpath);$dp-->0 && $pos>0;
-                                       $pos=rindex($fullpath,'/',$pos-1)) {;}
+               for ($pos=length($fullpath);$dp>0 && $pos>0;
+                                       $pos=rindex($fullpath,'/',$pos-1)) {
+                       $dp--;
+               }
                my $relpath = substr($fullpath,$pos);
                $relpath =~ s%^/%%;
                $self->{-relpath} = $relpath;
                $self->{-toppath} = substr($fullpath,0,$pos);
+               #print "rel=$relpath, top=$self->{-toppath}, inc=$inc\n";
                initrss($self);
        } else {
                $self->{-inc} = 'NO-.INCLUDE-IN-PATH/'; # won't work anyway
@@ -174,31 +178,67 @@ sub initpaths {
 sub initrss {
        my $self=shift;         # this is not a method but we cheat
        my $fullpath=$self->{-fullpath};
-       my $depth=20;
+       my $inc=$self->{-inc}.$incdir.'/';
+       my $conffile=$inc.'rss.conf';
+       my $CONF;
+
+       if ($rssfile) {
+               if (open($CONF,">".$conffile)) {
+                       print $CONF "file: ",$rssfile,"\n";
+                       close($CONF);
+               } else {
+                       print STDERR "could not open $conffile: $!\n";
+               }
+       } else {
+               if (open($CONF,$conffile)) {
+                       my $ln=<$CONF>;
+                       close($CONF);
+                       chop $ln;
+                       my ($k,$v)=split(':', $ln);
+                       $k =~ s/^\s*//;
+                       $k =~ s/\s*$//;
+                       $v =~ s/^\s*//;
+                       $v =~ s/\s*$//;
+                       if ($k eq 'file') {
+                               $rssfile=$v;
+                       }
+               }
+       }
 
-       return;
-       return "" unless $rssfile;
+       return unless ($rssfile);
 
-       my $rss=$rssfile;
-       while ( ! -f $fullpath."/".$rss ) {
-               $rss = "../".$rss;
-               last unless ($depth-- > 0);
-       }
-       if ($depth > 0) {
-               $rssobj->{'file'} = $rss;
-               $rssobj->{'rss'} = new XML::RSS (version=>2);
-               $rssobj->{'rss'}->parsefile($rss);
+       $rssobj->{'file'} = $self->{-toppath}.'/'.$rssfile;
+       $rssobj->{'rss'} = new XML::RSS (version=>'2.0');
+       if ( -f $rssobj->{'file'} ) {
+               $rssobj->{'rss'}->parsefile($rssobj->{'file'});
                my $itemstodel = @{$rssobj->{'rss'}->{'items'}} - 15;
                while ($itemstodel-- > 0) {
                        pop(@{$rssobj->{'rss'}->{'items'}})
                }
                $rssobj->{'rss'}->save($rssobj->{'file'});
-               return $rss;
        } else {
-               print STDERR "There is no $rssfile in this or parent ".
-                       "directories, you must create one with mkgalrss.pl\n";
-               exit 1;
+               my $link="";
+               for (my $pos=index($rssfile,'/');$pos>=0;
+                                       $pos=index($rssfile,'/',$pos+1)) {
+                       $link = '../'.$link;
+               }
+               
+               $rssobj->{'rss'}->channel(
+                       title=>'Gallery',
+                       link=>$link,
+                       description=>'Gallery Feed',
+                       #language=>$language,
+                       #rating=>$rating,
+                       #copyright=>$copyright,
+                       #pubDate=>$pubDate,
+                       #lastBuildDate=>$lastBuild,
+                       #docs=>$docs,
+                       #managingEditor=>$editor,
+                       #webMaster=>$webMaster
+               );
+               $rssobj->{'rss'}->save($rssobj->{'file'});
        }
+       $self->{-rss} = $rssobj->{'rss'};
 }
 
 sub iterate {
@@ -466,7 +506,7 @@ sub makeaux {
        my $dn = $self->{-parent}->{-fullpath};
        my $pref = $self->{-previmg}->{-base};
        my $nref = $self->{-nextimg}->{-base};
-       my $inc = $self->{-inc};
+       my $inc = $self->{-inc}.$incdir.'/';
        my $title = $self->{-info}->{'Comment'};
        $title = $name unless ($title);
 
@@ -586,7 +626,7 @@ sub startindex {
        binmode($IND, ":utf8");
        $self->{-IND} = $IND;
 
-       my $inc = $self->{-inc};
+       my $inc = $self->{-inc}.$incdir.'/';
        my $title = $self->{-title};
        my $rsslink="";
        if ($self->{-rss}) {
@@ -642,7 +682,7 @@ sub endindex {
 
        print $IND end_div;
        my $EVL;
-       if (open($EVL,$self->{-inc}.'footer.pl')) {
+       if (open($EVL,$self->{-inc}.$incdir.'/footer.pl')) {
                my $prm;
                while (<$EVL>) {
                        $prm .= $_;
@@ -665,7 +705,8 @@ sub endindex {
                                $self->{-title},
                                $self->{-numofimgs},
                                $self->{-numofsubs};
-               my $rsslink=$rssobj->{'rss'}->channel('link')."index.html";
+               my $rsslink=$rssobj->{'rss'}->channel('link').
+                       $self->{-relpath}."/index.html";
                $rssobj->{'rss'}->add_item(
                        title           => $self->{-title},
                        link            => $rsslink,
diff --git a/mkgalrss.pl b/mkgalrss.pl
deleted file mode 100755 (executable)
index 29b4676..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/usr/bin/perl
-
-# $Id$
-
-# Build initial (empty) RSS file for mkgallery.pl
-
-# Copyright (c) 2007 Eugene G. Crosser
-
-#  This software is provided 'as-is', without any express or implied
-#  warranty.  In no event will the authors be held liable for any damages
-#  arising from the use of this software.
-#
-#  Permission is granted to anyone to use this software for any purpose,
-#  including commercial applications, and to alter it and redistribute it
-#  freely, subject to the following restrictions:
-#
-#  1. The origin of this software must not be misrepresented; you must not
-#     claim that you wrote the original software. If you use this software
-#     in a product, an acknowledgment in the product documentation would be
-#     appreciated but is not required.
-#  2. Altered source versions must be plainly marked as such, and must not be
-#     misrepresented as being the original software.
-#  3. This notice may not be removed or altered from any source distribution.
-
-use strict;
-use Carp;
-use Term::ReadLine;
-use XML::RSS;
-use Getopt::Long;
-use Encode;
-use encoding 'utf-8';
-binmode(STDOUT, ":utf8");
-
-######################################################################
-
-my $debug = 0;
-my $rssfile = "";
-
-unless (GetOptions(
-               'help'=>\&help,
-               'rssfile=s'=>\$rssfile,
-               'debug'=>\$debug)) {
-       &help;
-}
-
-sub help {
-
-       print STDERR <<__END__;
-usage: $0 [options]
- --help:        print help message and exit
- --debug:       print a lot of debugging info to stdout as you run
- --rssfile=...:        name of the rss file to create
-__END__
-
-       exit 1;
-}
-
-unless ($rssfile) {
-       print STDERR "you must specify --rssfile\n";
-       exit 1;
-}
-
-my $term = new Term::ReadLine "Edit RSS Attribute";
-
-my $rssobj = new XML::RSS (version=>'2.0');
-die "could not build new RSS object" unless ($rssobj);
-
-my $OUT = $term->OUT || \*STDOUT;
-print $OUT "Enter attributes for this gallery RSS feed\n";
-my $title = $term->readline('Feed title >','');
-$term->addhistory($title) if ($title);
-my $link = $term->readline('Gallery root URL >','');
-$term->addhistory($link) if ($link);
-my $desc = $term->readline('Gallery description >','');
-$term->addhistory($desc) if ($desc);
-
-$link .= '/' unless ($link =~ m%/$%);
-
-$rssobj->channel(
-               title=>$title,
-               link=>$link,
-               description=>$desc,
-               #language=>$language,
-               #rating=>$rating,
-               #copyright=>$copyright,
-               #pubDate=>$pubDate,
-               #lastBuildDate=>$lastBuild,
-               #docs=>$docs,
-               #managingEditor=>$editor,
-               #webMaster=>$webMaster
-               );
-$rssobj->save($rssfile);