#!/usr/bin/perl use Encode; $datdir = "/home/taka/shingetsu/saku/cache"; $rssmax = 10; $titlelength = 40; $baseurl = "http://mutumin.ddo.jp.8000.nyud.net:8090"; $rssdesc = "P2P掲示板 新月"; #$defurlarg = "/thread.cgi/%E3%82%80%E3%81%A4%E3%81%AE%E6%97%A5%E8%A8%98"; $defurlarg = "/thread.cgi/むつの日記"; $localtime = "+09:00"; $urlarg = $ENV{'PATH_INFO'}; print STDERR $urlarg, "\n"; if ($urlarg eq "") { $urlarg=$defurlarg; } $title = $urlarg; $title =~ s|#r.*$||; if ($title =~ m|/n\d+|){ $rssmax = $&; $rssmax =~ s|/n||; chomp $rssmax; $title =~ s|/n\d+||; } $title =~ s|.*/thread\.cgi/||; $title =~ s|/||g; $filename = unpack("H*", $title); $urlarg = $title; $urlarg =~ s|[^\w]|'%' . uc(unpack('H2', $&))|eg; $urlarg = "/thread.cgi/" . $urlarg; $datfile = "$datdir/thread_\U$filename\E/body.cache"; sub xdie { print "Content-Type: text/plain;\n\n"; print "no such $title\n"; print "no such $filename\n"; exit 1; } open(IN, "$datfile") or xdie; @list = ; close(IN); @rlist = reverse(@list); $num = 0; foreach(@rlist){ if ($num >= $rssmax){ last; } $dat = $_; @thread = split(/<>/, $dat); foreach(@thread){ if ($_ =~ /^body:/){ $body = $_; $body =~ s/^body://; chomp $body;} #if ($_ =~ /^name:/){ $name = $_; $name =~ s/^name://; chomp $name;} } @btitle = split(/
/, $body); $num2 = 0; while(@btitle[$num2] =~ /^>>........$/){ $num2++ } Encode::from_to(@btitle[$num2], "utf8", "euc-jp"); $btitle = substr(@btitle[$num2], 0, $titlelength); #if($btitle =~ /\x8F$/ or $btitle =~ tr/\x8E\xA1-\xFE// % 2) { chop($btitle); } # Thanks http://www.din.or.jp/~ohzaki/perl.htm#JP_Cut Encode::from_to($btitle, "euc-jp", "utf8"); #if ($name eq ""){ $name = "名無しさん"; } #($sec, $min, $hour, $mday, $mon, $year) = localtime(@thread[0]); ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime(@thread[0]); $year = $year + 1900; $mon = $mon + 1; #$date = sprintf("%d/%02d/%02d %02d:%02d:%02d", $year, $mon, $mday, $hour, $min, $sec); $date = sprintf("%d-%02d-%02dT%02d:%02d:%02d%s", $year, $mon, $mday, $hour, $min, $sec, $localtime); $id = substr(@thread[1], 0, 8); #if ( $remove_id ne "") { $remove_id = substr($remove_id, 0, 8); } $htmlbody = $body; $body =~ s/
//g; $htmlbody =~ s!((http|https):([^\x00-\x20()<>\x7F-\xFF])*)!$1!g; #$ititle[$num] = "$name: $btitle"; $ititle[$num] = "$btitle"; $ilink[$num] = "$baseurl$urlarg#r$id"; $idate[$num] = "$date"; $idesc[$num] = "$body"; $icont[$num] = "$htmlbody"; push(@items_list, " \n"); #$body = ""; $name = ""; $mail = ""; $attach = ""; $suffix = ""; $attachurl = ""; $body = ""; $name = ""; $htmlbody = ""; #$message = ""; $pubkey = ""; $remove_id = ""; $num++; } #@ritems_list=reverse(@items_list); #print "Content-Type: application/xml;\n"; #print "Content-Type: text/xml;\n"; print "Content-Type: text/plain;\n"; print "\n"; print "\n"; print "\n"; print " \n"; print " $title\n"; print " $baseurl$urlarg\n"; print " $rssdesc\n"; print " \n"; print " \n"; print "@items_list\n"; #print "@ritems_list\n"; print " \n"; print " \n"; print " \n"; for ($i = 0; $i < $rssmax; $i++){ #for ($i = $rssmax - 1; $i >= 0; $i--){ if ($ilink[$i] ne ""){ print " \n"; print " $ititle[$i]\n"; print " $ilink[$i]\n"; print " $idesc[$i]\n"; print " $idate[$i]\n"; if ($icont[$i] ne ""){ print " $icont[$i]

\n"; print " ]]>
\n"; } print "
\n"; } } print "
\n"; exit 0;