#!/usr/local/bin/perl # # rss.cgi for Ulara Diary # # RSS生成CGI # # version 0.0.8i # 2003/02/21-24,2004/10/23 by ulara # Based on: ## HyperNikkiSystem di.cgi ## version 0.0.5 ## 2000/6/26 yar-3 ## Copyright (C) 2000 yar-3 ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; either version 2 ## of the License, or (at your option) any later version. ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## Id: di.cgi.in,v 1.7 2000/09/27 14:18:15 kenji Exp use strict; use lib qw(lib); use CGI::Carp qw(fatalsToBrowser); use Time::Local; use XML::RSS; use Jcode; require './config.ph'; my $rss = new XML::RSS(version => '1.0'); # *.hnfのあるディレクトリ my $diarydir = $HNS::System::DiaryDir; my $lastmodified = 0; my $newestfile = ""; my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); $year += 1900; my $file; my @a = (); opendir(DIR, "$diarydir/$year"); while ($file = readdir(DIR)) { push (@a, "$diarydir/$year/$file") if $file =~ /^d.*\.hnf$/; } $year = $year - 1; opendir(DIR, "$diarydir/$year"); while ($file = readdir(DIR)) { push (@a, "$diarydir/$year/$file") if $file =~ /^d.*\.hnf$/; } opendir(DIR, "$diarydir"); while ($file = readdir(DIR)) { push (@a, "$diarydir/$file") if $file =~ /^d.*\.hnf$/; } sort @a; # ascii順に並び替え @a = reverse(@a); # 逆順に foreach my $i (@a) { my $t = (stat($i))[9]; #print "$i time:$t\n"; if ($lastmodified < $t) { $lastmodified = $t; $newestfile = $i; } } my $lm = gmtime($lastmodified); # Wed Oct 6 21:10:18 1999 # $1 $2 $3 $4 $5 $lm =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/; # DD Cal YYYY hh:mm:ss Zone # 24 Aug 1999 13:12:01 JST # RFCにのっとった形に my $day = $3; if ($day < 10) { $day = "0" . $day; } my $LM = "$1, $day $2 $5 $4 GMT"; my ($y, $m, $d, $hr, $mn) = (gmtime($lastmodified))[5,4,3,2,1]; $y+=1900; $m++; $rss->channel( about => 'http://cgi.members.interq.or.jp/sun/chanoyu/private/hns-lite/rss.cgi', title => jcode($HNS::System::Title)->utf8, 'link' => $HNS::System::MyDiaryURI, description => jcode('うらゝの日記')->utf8, dc => { type => 'text', language => 'ja', creator => jcode('うらゝ')->utf8, date => sprintf("%04d-%02d-%02dT%02d:%02dZ", $y,$m,$d,$hr,$mn), rights => "Copyright © 2001-$y ulara" }, syn => { updatePeriod => "Daily", updateFrequency => 1, updateBase => "2001-03-04T00:00Z" } ); $rss->image( title => jcode($HNS::System::Title)->utf8, url => 'http://www.interq.or.jp/sun/chanoyu/private/hns-lite/ulara_diary.png', 'link' => $HNS::System::MyDiaryURI ); $rss->textinput( title => jcode('namazu検索')->utf8, description => jcode('日記内キーワード検索(UTF-8の日本語文字は検索できません)')->utf8, name => 'key', 'link' => 'http://cgi.members.interq.or.jp/sun/chanoyu/private/hns-lite/namazu.cgi' ); open(HNF, $newestfile) || die ("Could not open $newestfile\n"); ($y, $m, $d) = ($newestfile =~ m{.*/d(\d\d\d\d)(\d\d)(\d\d)\.hnf$}); my $sectionCount=0; $rss->add_item( title => jcode(sprintf("%04d年%02d月%02d日の日記",$y,$m,$d))->utf8, 'link' => &anchorURL($y,$m,$d,0) ); my $category=""; while(){ next if(1../^OK$/); if(/^CAT\s*(.*)$/){ $category=$1; next; } if(/^(?:NEW |LNEW \S+ |RLNEW \S+ \S* )\s*(.*)$/){ $sectionCount++; if($category ne ""){ $rss->add_item( title => "#$sectionCount " . jcode($1)->utf8, 'link' => &anchorURL($y, $m, $d, $sectionCount), dc => { subject => $category } ); }else{ $rss->add_item( title => "#$sectionCount " . jcode($1)->utf8, 'link' => &anchorURL($y, $m, $d, $sectionCount) ); } } $category=""; } close(HNF); print "Content-Type: text/xml; charset=utf-8\r\n"; print "Last-Modified: $LM\r\n"; print "\r\n"; print $rss->as_string(); exit; sub anchorURL($$$$){ my ($y,$m,$d,$n)=@_; sprintf("%s?%04d%02d%02d&to=%04d%02d%02d%d#%04d%02d%02d%d", $HNS::System::MyDiaryURI, $y, $m, $d, $y, $m, $d, $n, $y, $m, $d, $n); } 1;