package CGI::Kwiki::Plugin::RSSPlugin; use strict; use warnings; use base qw( CGI::Kwiki::Plugin ); use CGI::Kwiki::Config_yaml; use XML::RSS; =head1 NAME RSSPlugin - Syndicate Kwiki RecentChanges for Kwiki 0.18 =head1 SYNOPSIS List feed with defaults: http://wiki.wubi.org/index.cgi?action=plugin&plugin_name=RSSPlugin List, at most, 10 edits from the past 24 days: http://wiki.wubi.org/index.cgi?action=plugin&plugin_name=RSSPlugin&days=24&edits=10 List all changes from the past 14 days: http://wiki.wubi.org/index.cgi?action=plugin&plugin_name=RSSPlugin&days=24 List, at most, 12 changes from the past 100 days: http://wiki.wubi.org/index.cgi?action=plugin&plugin_name=RSSPlugin&edits=12 =head1 METHODS =head2 process This is the handler called by Kwiki. It just reads arguments from any query arguments and defers to L<"rss">. The arguments recognised match the named arguments to L<"rss">. =cut sub process { my ($self) = shift; my %args = ( days => $self->cgi->days, edits => $self->cgi->edits, ); $self->driver->load_class('metadata'); return $self->rss( %args ); } =head2 rss C produces an RSS file for the RecentChanges of the current Kwiki. Optional, named arguments: =over 4 =item * B is the number of days to look backwards for changes. e.g. give a value of 7 to check for changes in the past week. Defaults to 100 if B is specified, 7 otherwise. If the value specified is out of range (less than 1 or greater than 100) then it is reset to 7 days. =item * B will limit to a particular number of entries. By default there is no limit. If the value is less than 3 or greater than 100 then it is reset to 'no limit'. =back =cut sub rss { my ($self, %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 $database = $self->driver->database; my $pages = [ grep { $_->[1] <= $args{days} } map {[$_, -M $_]} grep { (my $p_id = $_) =~ s/.*[\/\\]//; $database->exists( $self->unescape( $p_id ) ); } glob "database/*" ]; my $feed = XML::RSS->new( version => '1.0' ); my $base = $self->config->url_base; $feed->channel( title => $self->config->title_prefix." ".$self->config->changes_page, link => $base.$self->config->changes_page, description => $self->config->slogan, ); $feed->image( title => $self->config->title_prefix, link => $base, url => $base.$self->config->kwiki_image, ); my $count = 0; for my $page_id (sort {-M $a <=> -M $b} map {$_->[0]} @$pages) { last if defined $args{edits} and $count++ >= $args{edits}; $page_id =~ s/.*[\/\\]//; my $metadata = $self->driver->metadata->get( $self->unescape( $page_id ) ); my $edit_by = $metadata->{edit_by} || ' '; my $edit_time = $metadata->{edit_time} || ' '; # $id is needed to ensure uniqueness of resource ids. (my $id = $edit_time) =~ tr/a-zA-Z0-9//dc; my $script = $self->script; $feed->add_item( title => $self->unescape( $page_id ), description => "Edit by $edit_by on $edit_time GMT", link => "$base".$page_id."#$id", ); } return $feed->as_string; } # Name of the current script sub script { my $script = $0; $script =~ s/.*[\\\/]//; return $script; } 1; __END__ =head1 INSTALLATION NOTES =head2 config.yaml Your F file needs a C key added. My Kwiki uses: url_base: http://iain.truskett.id.au/ kwiki.org would use: url_base: http://www.kwiki.org/ http://who.dellah.org/jp/ would use: url_base: http://who.dellah.org/jp/ Note the trailing slashes. If you like, include C on the end: it won't harm it. Other optional F keys used are: slogan title_prefix kwiki_image =head1 THANKS Brian Ingerson (INGY) for making Kwiki. Everyone who's contributed to Kwiki -- be it code, docs, styles, plugins, wiki pages, whatever. Hlb for giving me impetus to actually get off my arse and write this plugin. =head1 SUPPORT Support for this module is provided via the Kwiki page: L. =head1 LICENCE AND COPYRIGHT Copyright E Iain Truskett, 2003. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the licences can be found in the F and F files included with this module, or in L and L in Perl 5.8.1 or later. =head1 AUTHOR Iain Truskett =head1 SEE ALSO L L, L. =cut 1;