Tadashi Okoshi
slash****@users*****
2005年 6月 27日 (月) 01:39:38 JST
Index: affelio/lib/Affelio/App/Admin/AffelioNews.pm diff -u /dev/null affelio/lib/Affelio/App/Admin/AffelioNews.pm:1.1 --- /dev/null Mon Jun 27 01:39:37 2005 +++ affelio/lib/Affelio/App/Admin/AffelioNews.pm Mon Jun 27 01:39:37 2005 @@ -0,0 +1,101 @@ +# Affelio: Open social networking software +# Copyright 2004-2005 Fish Grove +# For more information, please refer following web site. +# http://affelio.jp/ (Japan) +# http://affelio.jp/ (USA and other area) +# +# $Id: AffelioNews.pm,v 1.1 2005/06/26 16:39:37 slash5234 Exp $ + +package Affelio::App::Admin::AffelioNews; +{ + use strict; + + use lib("../../../../extlib/"); + use Error qw(:try); + use Fcntl; + use LWP::Simple 'get'; + use XML::RSS; + use lib("../../../"); + use Affelio; + use Affelio::misc::CGIError; + use Affelio::misc::Debug qw(debug_print); + use Affelio::misc::WebInput qw(delete_HTML); + use Affelio::exception::IOException; + use Affelio::misc::Time qw(get_timestamp); + + use Exporter; + @Affelio::App::Admin::AffelioNews::ISA = "Exporter"; + @Affelio::App::Admin::AffelioNews::EXPORT = qw (getnews getRSS); + + ####################################################################### + #getRSS + ####################################################################### + sub getRSS{ + my $af = shift; + + if(-e "$af->{site__user_dir}/AffelioNews/"){ + }else{ + mkdir("$af->{site__user_dir}/AffelioNews/", 755); + if($@){ + throw Affelio::exception::IOException("Cannot make directory for AffelioNews!"); + } + } + + #Load last-updated time + sysopen(IN, "$af->{site__user_dir}/AffelioNews/update", O_RDONLY); + my $updated_time = <IN>; + my $cur_time = get_timestamp(); + if($cur_time < $updated_time + 030000){ + return; + } + + my $rss = new XML::RSS; + my $url = 'http://www.okoshi.org/tadashi/bbs2/archives/cat_0206affelio.rdf'; + $rss->parse( get($url) ); + if($@){ + throw Affelio::exception::IOException("Network connection error to affelio web site"); + } + + sysopen(OUT, "$af->{site__user_dir}/AffelioNews/news.html", + O_WRONLY|O_CREAT); + + my $line = 1; + foreach my $ref(@{$rss->{items}}){ + if($line < 6){ + $ref->{dc}->{date} =~ /(\d\d\d\d)\-(\d\d\-\d\d)/; + my $date = $2; + $date =~ s/\-/\//g; + print OUT "<TR><TH>$date</TH><TD><A HREF=\"$ref->{'link'}\">$ref->{'title'}</A></TD></TR>"; + } + $line = $line + 1; + } + + close(OUT); + + #Record current time + sysopen(OUT, "$af->{site__user_dir}/AffelioNews/update", + O_WRONLY|O_CREAT); + print OUT $cur_time; + close(OUT); + } + + ####################################################################### + #getnews + ####################################################################### + sub getnews{ + my $af = shift; + my $output_ref = shift; + + getRSS($af); + + sysopen(IN, "$af->{site__user_dir}/AffelioNews/news.html", + O_RDONLY); + if(!$@){ + $output_ref->{"AffelioNews"} = <IN>; + } + close(IN); + } + + +} +1;