+sub initpaths {
+ my $self=shift; # this is not a method but we cheat
+ my $depth=20; # arbitrary max depth
+ my $fullpath=$self->{-fullpath};
+ my $inc;
+ my $relpath;
+
+ if ($incpath) {
+ $inc = $incpath;
+ $inc .= '/' unless ($inc =~ m%/$%);
+ } else {
+ $inc="";
+ while ( ! -d $fullpath."/".$inc."/".$incdir ) {
+ $inc = "../".$inc;
+ last unless ($depth-- > 0);
+ }
+ }
+ if ($depth > 0) {
+ $self->{-inc} = $inc;
+ my $dp=0;
+ my $pos;
+ for ($pos=index($inc,'/');$pos>=0;
+ $pos=index($inc,'/',$pos+1)) {
+ $dp++;
+ }
+ $self->{-depth} = $dp;
+ for ($pos=length($fullpath);$dp>0 && $pos>0;
+ $pos=rindex($fullpath,'/',$pos-1)) {
+ $dp--;
+ }
+ my $relpath = substr($fullpath,$pos);
+ $relpath =~ s%^/%%;
+ $relpath .= '/' if ($relpath);
+ $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
+ $self->{-rss} = '';
+ $self->{-relpath} = '';
+ $self->{-depth} = 0;
+ }
+}
+
+sub initrss {
+ my $self=shift; # this is not a method but we cheat
+ my $fullpath=$self->{-fullpath};
+ my $toppath=$self->{-toppath};
+ my $inc=$self->{-inc}.$incdir.'/';
+ my $conffile=$toppath.'/'.$incdir.'/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 unless ($rssfile);
+
+ $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'});
+ } else {
+ my $link;
+ my $p1;
+ my $p2;
+ for ($p1=0,$p2=length($toppath);
+ substr($rssfile,$p1,3) eq '../' && $p2>0;
+ $p1+=3,$p2=rindex($toppath,'/',$p2-1)) {;}
+ $link=substr($toppath,$p2);
+ $link =~ s%^/%%;
+ $link .= '/' if ($link);
+ while (($p1=index($rssfile,'/',$p1+1)) >= 0) {
+ $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'};
+}
+