package Kwiki::RSSFeed; use strict; use warnings; use Kwiki::Plugin '-Base' ; use Kwiki::Installer '-base' ; our $VERSION = '0.10' ; use XML::RSS ; const class_id => 'rss_feed' ; const class_title => 'RSS Feed' ; const cgi_class => 'Kwiki::RSSFeed::CGI'; sub register { my $registry = shift; $registry->add(action => 'rss_feed'); $registry->add(toolbar => 'rss_feed_button', template => 'rss_feed_button.html', ); } sub rss_feed { my %args = ( days => $self->cgi->days || '', edits => $self->cgi->edits || '', ); return $self->build_rss( %args ); } sub build_rss { my( %args ) = @_; if( defined $args{'edits'} and length $args{'edits'} ) { $args{days} ||= 100; undef $args{'edits'} if ( $args{'edits'} < 3 or $args{'edits'} > 100 ) ; } else { delete $args{'edits'}; $args{days} ||= 7; } $args{days} = 7 if $args{days} < 1 or $args{days} > 100; my $pages = [ grep { $_->[1] <= $args{days} } map {[$_, -M $_->file_path]} grep { $_->exists ; } $self->pages->all ]; my $feed = XML::RSS->new( version => '1.0' ); my $base = $self->config->url_base || $self->config->url_base ; my $script ; if( ! defined $self->config->script_base ) { $script = $self->script ; } elsif( $self->config->script_base ) { $script = $self->config->script_base."\?" ; } else { $script = '' ; } $feed->channel( title => $self->config->title_prefix. " ". $self->config->changes_page, link => $base.$script.$self->config->changes_page, description => $self->config->slogan, ); $feed->image( title => $self->config->title_prefix, link => $base, url => $base.$self->config->logo_image, ); my $count = 0; for my $page (sort {-M $a->file_path <=> -M $b->file_path} map {$_->[0]} @$pages) { last if defined $args{'edits'} and $count++ >= $args{'edits'}; my $edit_by = $self->utf8_decode( $page->metadata->edit_by ) || ' '; my $edit_time = $page->metadata->edit_time || ' '; # $id is needed to ensure uniqueness of resource ids. (my $id = $edit_time) =~ tr/a-zA-Z0-9//dc; $feed->add_item( title => $self->uri_unescape( $page->id ), description => "Edit by $edit_by on $edit_time GMT", link => "$base".$script.$page->id."#$id", ); } return $feed->as_string; } # Name of the current script sub script { my $script = $0; $script =~ s/.*[\\\/]//; return $script; } 1; #################################################################### package Kwiki::RSSFeed::CGI ; use Kwiki::CGI '-base' ; cgi 'days' ; cgi 'edits' ; 1; ################################################################### package Kwiki::RSSFeed ; __DATA__ =head1 NAME RSSFeed - Syndicate Kwiki RecentChanges for Kwiki 0.31 =head1 SYNOPSIS List feed with defaults: http://wiki.wubi.org/index.cgi?action=rss_feed List, at most, 10 edits from the past 24 days: http://wiki.wubi.org/index.cgi?action=rss_feed&days=24&edits=10 List all changes from the past 14 days: http://wiki.wubi.org/index.cgi?action=rss_feed&days=14 List, at most, 12 changes from the past 100 days: http://wiki.wubi.org/index.cgi?action=rss_feed&edits=12 =head1 METHODS =head1 INSTALLATION NOTES This plugin takes two config options, both optional. url_base: the URL at which the wiki resides. ex: http://kwiki.org/ script_base: the filename of the base wiki CGI script ex: index.cgi If script_base is given a line in the configuration file but left blank, the URLs will be rendered as KwikiPermaLinks, like so: http://kwiki.org/RssPlugin =head1 THANKS =head1 SUPPORT =head1 LICENCE AND COPYRIGHT =head1 AUTHOR =head1 SEE ALSO =cut __template/tt2/rss_feed_button.html__ [% INCLUDE rss_feed_button_icon.html %] __template/tt2/rss_feed_button_icon.html__ RSS