#!/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/むつの日記"; $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;} if ($_ =~ /^mail:/){ $mail = $_; $mail =~ s/^mail://; chomp $mail;} if ($_ =~ /^message:/){ $message = $_; $message =~ s/^message://; chomp $message;} if ($_ =~ /^attach:/){ $attach = $_; $attach =~ s/^attach://; chomp $attach;} if ($_ =~ /^suffix:/){ $suffix = $_; $suffix =~ s/^suffix://; chomp $suffix;} if ($_ =~ /^pubkey:/){ $pubkey = $_; $pubkey =~ s/^pubkey://; chomp $pubkey;} if ($_ =~ /^remove_id:/){ $remove_id = $_; $remove_id =~ s/^remove_id://; chomp $remove_id;} } @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]); $year = $year + 1900; $mon = $mon + 1; $date = sprintf("%d/%02d/%02d %02d:%02d:%02d", $year, $mon, $mday, $hour, $min, $sec); $id = substr(@thread[1], 0, 8); if ( $remove_id ne "") { $remove_id = substr($remove_id, 0, 8); } if ($attach ne "") { $attachurl = "$baseurl/thread.cgi/thread_\U$filename\E/@thread[1]/@thread[0].$suffix"; $body = join("
", $body, "[添付][$suffix]", $attachurl); } $body =~ s/
//g; $ititle[$num]="$name: $btitle"; $ilink[$num]="$baseurl$urlarg#r$id"; $idate[$num]="$date"; $idesc[$num]="$body"; push(@items_list, " \n"); $body = ""; $name = ""; $mail = ""; $attach = ""; $suffix = ""; $attachurl = ""; $message = ""; $pubkey = ""; $remove_id = ""; $num++; } #@ritems_list=reverse(@items_list); #$link[++$items] = $1; # &www("$1"); # $items_list .= qq( \n); # $str = $2; # $str =~ s/<.*?>//g; #不要なマークアップを削除 # $title[$items] = $str; # $dc_date[$items] = $3; #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 " \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"; print " \n"; } } print "\n"; exit 0;