Changeset 296


Ignore:
Timestamp:
May 18, 2006, 5:06:43 PM (14 years ago)
Author:
nick
Message:

Finish shifting common code out into Listing.pm

Location:
wiki-toolkit/trunk/lib/Wiki/Toolkit/Feed
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Feed/Atom.pm

    r295 r296  
    5555
    5656    my @changes = $self->fetch_recently_changed_nodes(%args);
    57     my $atom_timestamp = $self->feed_timestamp(%args);
     57    my $atom_timestamp = $self->feed_timestamp(
     58                              $self->fetch_oldest_for_recently_changed(%args)
     59    );
    5860
    5961    return $self->generate_node_list_feed($atom_timestamp, @changes);
     
    147149}
    148150
     151=item B<feed_timestamp>
     152
     153Generate the timestamp for the Atom, based on the oldest node (if available)
     154
     155=cut
    149156sub feed_timestamp
    150157{
    151   my ($self, %args) = @_;
    152  
    153   my %criteria = (ignore_case => 1);
    154 
    155   $args{days} ? $criteria{days}           = $args{days}
    156               : $criteria{last_n_changes} = $args{items} || 15;
    157 
    158   $criteria{metadata_wasnt} = { major_change => 0 }     if $args{ignore_minor_edits};
    159   $criteria{metadata_was}   = $args{filter_on_metadata} if $args{filter_on_metadata};
    160 
    161   my @changes = $self->{wiki}->list_recent_changes(%criteria);
    162 
    163   if ($changes[0]->{last_modified})
    164   {
    165     my $time = Time::Piece->strptime( $changes[0]->{last_modified}, $self->{timestamp_fmt} );
     158  my ($self, $oldest_node) = @_;
     159 
     160  if ($oldest_node->{last_modified})
     161  {
     162    my $time = Time::Piece->strptime( $oldest_node->{last_modified}, $self->{timestamp_fmt} );
    166163
    167164    my $utc_offset = $self->{utc_offset};
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Feed/Listing.pm

    r295 r296  
    4747
    4848=cut
     49sub fetch_oldest_for_recently_changed {
     50    my ($self, %args) = @_;
     51
     52    my %criteria = (ignore_case => 1);
     53
     54    $args{days} ? $criteria{days}           = $args{days}
     55                : $criteria{last_n_changes} = $args{items} || 15;
     56
     57    $criteria{metadata_wasnt} = { major_change => 0 }     if $args{ignore_minor_edits};
     58    $criteria{metadata_was}   = $args{filter_on_metadata} if $args{filter_on_metadata};
     59
     60    my @changes = $self->{wiki}->list_recent_changes(%criteria);
     61
     62    return $changes[0];
     63}
    4964
    50651;
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Feed/RSS.pm

    r295 r296  
    6262
    6363  my @changes = $self->fetch_recently_changed_nodes(%args);
    64   my $rss_timestamp = $self->rss_timestamp(%args);
     64  my $rss_timestamp = $self->rss_timestamp(
     65                              $self->fetch_oldest_for_recently_changed(%args)
     66  );
    6567
    6668  return $self->generate_node_list_feed($rss_timestamp, @changes);
     
    214216=item B<rss_timestamp>
    215217
    216 Generate the timestamp for the RSS, by figuring out the age range of
    217 the source data for the feed
     218Generate the timestamp for the RSS, based on the oldest node (if available)
    218219
    219220=cut
    220221sub rss_timestamp
    221222{
    222   my ($self, %args) = @_;
    223  
    224   my %criteria = (ignore_case => 1);
    225 
    226   if ($args{days})
    227   {
    228     $criteria{days} = $args{days};
    229   }
    230   else
    231   {
    232     $criteria{last_n_changes} = $args{items} || 15;
    233   }
    234  
    235   if ($args{ignore_minor_edits})
    236   {
    237     $criteria{metadata_wasnt} = { major_change => 0 };
    238   }
    239  
    240   if ($args{filter_on_metadata})
    241   {
    242     $criteria{metadata_was} = $args{filter_on_metadata};
    243   }
    244 
    245   my @changes = $self->{wiki}->list_recent_changes(%criteria);
    246 
    247   if ($changes[0]->{last_modified})
    248   {
    249     my $time = Time::Piece->strptime( $changes[0]->{last_modified}, $self->{timestamp_fmt} );
    250 
    251     my $utc_offset = $self->{utc_offset};
    252    
    253     return $time->strftime( "%Y-%m-%dT%H:%M:%S$utc_offset" );
    254   }
    255   else
    256   {
    257     return '1970-01-01T00:00:00+0000';
    258   }
     223    my ($self, $oldest_node) = @_;
     224
     225    if ($oldest_node->{last_modified})
     226    {
     227        my $time = Time::Piece->strptime( $oldest_node->{last_modified}, $self->{timestamp_fmt} );
     228
     229        my $utc_offset = $self->{utc_offset};
     230
     231        return $time->strftime( "%Y-%m-%dT%H:%M:%S$utc_offset" );
     232    }
     233    else
     234    {
     235        return '1970-01-01T00:00:00+0000';
     236    }
    259237}
    260238
Note: See TracChangeset for help on using the changeset viewer.