Changeset 813


Ignore:
Timestamp:
Jun 22, 2006, 3:11:27 PM (15 years ago)
Author:
nick
Message:

Add method for generating a feed from an arbitary list of nodes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/Feed.pm

    r807 r813  
    5757}
    5858
     59=item B<make_feed>
     60Produce one of the standard feeds, in the requested format.
     61
     62
     63my $feed_contents = feeds->make_feed(
     64                                feed_type => 'rss',
     65                                feed_listing => 'recent_changes'
     66                    );
     67
     68Passes additional arguments through to the underlying Wiki::Toolkit::Feed
     69=cut
    5970sub make_feed {
    6071    my ($self, %args) = @_;
     
    8192        return $maker->node_all_versions(%args);
    8293    }
     94}
     95
     96=item B<build_feed_for_nodes>
     97For the given feed type, build a feed from the supplied list of nodes.
     98Will figure out the feed timestamp from the newest node, and output a
     99 last modified header based on this.
     100
     101my @nodes = $wiki->fetch_me_nodes_I_like();
     102my $feed_contents = $feed->build_feed_for_nodes("rss", @nodes);
     103=cut
     104sub build_feed_for_nodes {
     105    my ($self, $format, @nodes) = @_;
     106
     107    # Grab our feed maker
     108    my $maker = $self->fetch_maker($format);
     109
     110    # Find our newest node, so we can use that for the feed timestamp
     111    my $newest_node;
     112    foreach my $node (@nodes) {
     113        if($node->{last_modified}) {
     114            if((!$newest_node) || $node->{last_modified} < $newest_node->{last_modified}) {
     115                $newest_node = $node;
     116            }
     117        }
     118    }
     119
     120    # Grab the timestamp, and do our header
     121    my $timestamp = $maker->feed_timestamp($newest_node);
     122
     123    my $feed = "Last-Modified: ".$timestamp."\n\n";
     124
     125    # Generate the feed itself
     126    $feed .= $maker->generate_node_list_feed($timestamp, @nodes);
     127
     128    return $feed;
    83129}
    84130
Note: See TracChangeset for help on using the changeset viewer.