• R/O
  • SSH
  • HTTPS

wutsecgi: コミット


コミットメタ情報

リビジョン15 (tree)
日時2007-01-27 21:37:28
作者wutse

ログメッセージ

[wifkyplugin]Version0.9リリース
・RSS対応

変更サマリ

差分

--- trunk/wifkyplugin/bbs/bbs.pl (revision 14)
+++ trunk/wifkyplugin/bbs/bbs.pl (revision 15)
@@ -5,6 +5,7 @@
55 # 日時のフォーマット
66 @week = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
77
8+# 掲示板表示
89 $inline_plugin{bbs} = sub {
910 my ($session, $bbsName, $bbsTitle) = @_;
1011 my $page = exists($::form{bbspage}) ? $::form{bbspage} : 1;
@@ -55,7 +56,13 @@
5556 </form>), $::me, $defaultName, $bbsName, &enc($::form{p})));
5657 my $totalLines = @bbsLines;
5758 my $totalPages = ($totalLines % $bbsMaxLine == 0) ? $totalLines / $bbsMaxLine : int($totalLines / $bbsMaxLine) + 1;
58- &putsPaging($page, $totalPages);
59+ if ($bbsNo > 0) {
60+ $page = int(($totalLines - $bbsNo) / $bbsMaxLine) + 1;
61+ if ($page <= 0) {
62+ $page = 1;
63+ }
64+ }
65+ &putsPaging($page, $totalPages, $bbsName, $bbsTitle);
5966 if ($bbsEmpty == false) {
6067 &puts("<dl>");
6168 for ($i = ($page - 1) * $bbsMaxLine; $i <= $#bbsLines and $i < $page * $bbsMaxLine; $i++) {
@@ -63,20 +70,22 @@
6370 ($min,$hour,$mday,$mon,$year,$wday) = (localtime($time))[1..6];
6471 $date = sprintf("%04d/%02d/%02d(%s) %02d:%02d",
6572 $year+1900,$mon+1,$mday,$week[$wday],$hour,$min);
66- &puts(sprintf(qq(<dt><hr>[<strong>%d</strong>]<strong>&nbsp;<font color="#006600">%s</font></strong> 投稿者:<strong>%s</strong> 投稿日:%s</dt>),
67- $no, $subject, $name, $date, $message));
73+ &puts(sprintf(qq(<dt><hr><a name="bbs_%d"/>[<strong>%d</strong>]<strong>&nbsp;<font color="#006600">%s</font></strong> 投稿者:<strong>%s</strong> 投稿日:%s</dt>),
74+ $no, $no, $subject, $name, $date, $message));
6875 &puts(sprintf("<dd>%s</dd>", $message));
6976 }
7077 &puts("</dl>");
7178 }
7279 &puts("<hr>");
73- &putsPaging($page, $totalPages);
80+ &putsPaging($page, $totalPages, $bbsName, $bbsTitle);
7481 &puts("</form></div>");
7582 };
7683
84+# ページングのリンク、RSSリンクの表示
7785 sub putsPaging {
78- my ($currentPage, $maxPage) = @_;
79- my $myUrl = &title2url(exists $::form{p} ? $::form{p} : 'FrontPage') . "&bbspage=";
86+ my ($currentPage, $maxPage, $bbsName, $bbsTitle) = @_;
87+ my $pageName = exists $::form{p} ? $::form{p} : 'FrontPage';
88+ my $myUrl = &title2url($pageName) . "&bbspage=";
8089 &puts(qq(<div class="bbsPage"><table border="0" width="100%"><tr><td align="right">));
8190 if ($currentPage > 1) {
8291 &puts(sprintf(qq(<a href="%s">&lt;&lt;</a>), $myUrl . "1"));
@@ -100,9 +109,12 @@
100109 &puts(sprintf(qq(<a href="%s">&gt;</a>), $myUrl . ($currentPage + 1)));
101110 &puts(sprintf(qq(<a href="%s">&gt;&gt;</a>), $myUrl . $maxPage));
102111 }
112+ &puts(sprintf(qq(<a href="wifky.cgi?a=bbsRss&p=%s&bbsTitle=%s&bbsName=%s" style="border: 1px solid white; font-size: small; font-weight: bold; text-decoration: none; background-color: darkorange; color: white; font-style: normal;">RSS</a>),
113+ $pageName, $bbsTitle, $bbsName));
103114 &puts("</td></tr></table></div>");
104115 }
105116
117+# XML用エンコード
106118 sub bbsEncode {
107119 my ($targetText) = @_;
108120 $targetText =~ s/&/&amp;/g;
@@ -115,6 +127,7 @@
115127 return $targetText;
116128 };
117129
130+# 投稿処理
118131 $main::action_plugin{bbsSubmit} = sub {
119132 my $name = $::form{name};
120133 if ($name) {
@@ -206,6 +219,7 @@
206219 }
207220 };
208221
222+# 投稿処理でエラーになった場合
209223 sub showBBSError {
210224 my @errorMessages = @_;
211225 my $url = &title2url(exists($::form{p}) ? $::form{p} : 'FrontPage');
@@ -221,7 +235,8 @@
221235 </center></body>
222236 </html>), $::me, &enc($::form{p})));
223237 }
224-
238+
239+# 投稿処理が正常終了した場合
225240 sub showBBSSubmit {
226241 my $url = &title2url(exists($::form{p}) ? $::form{p} : 'FrontPage');
227242 &puts(@::http_header, '');
@@ -231,6 +246,83 @@
231246 <meta http-equiv="refresh" content="1;URL=${url}"></head>
232247 <body><a href="${url}">Wait or Click Here</a></body></html>));
233248 };
249+
250+# 掲示板の更新情報をRSS出力する
251+$main::action_plugin{bbsRss} = sub {
252+ my $URL = sprintf('http://%s%s', $ENV{'HTTP_HOST'}, $ENV{'SCRIPT_NAME'});
253+ my $bbsName = $::form{bbsName};
254+ my $bbsTitle = exists($::form{bbsTitle}) ? $::form{bbsTitle} : $bbsName;
255+ my $RSS = sprintf("%s?a=bbsRss&p=%s&bbsName=%s", $URL, &percent($::form{p}), $bbsName);
256+ my $pageUrl = sprintf("%s?p=%s&bbsName=%s", $URL, &percent($::form{p}), $bbsName);
257+ my $bbsEmpty = 0;
258+ open(BBSFP, "bbs_$bbsName.cgi") or $bbsEmpty = 1;
259+ my @bbsLines = <BBSFP>;
260+ close(BBSFP);
261+ my @bbsItems = ();
262+ if (!$bbsEmpty) {
263+ for (my $i = 0; $i < $bbsMaxLine && $i < @bbsLines; $i++) {
264+ my %rssItem = ();
265+ my ($no,$name,$subject,$message,$time) = split(/<>/, $bbsLines[$i]);
266+ if ($#bbsLines == $i) {
267+ my $lastTime = sprintf("%s, %02d %s %04d %s GMT", (split(/\s+/, gmtime($time)))[0,2,1,4,3]);
268+ }
269+ my @updateDateTime = gmtime($time);
270+ my %rssItem = (
271+ url => sprintf("%s&bbsNo=%s#bbs_%s", $pageUrl, $no, $no),
272+ subject => $subject,
273+ submitDateTime => sprintf("%s, %02d %s %04d %s GMT",
274+ (split(/\s+/, gmtime($time)))[0,2,1,4,3]),
275+ name => $name,
276+ message => $message,
277+ date => sprintf("%04d-%02d-%02dT%02d:%02d:%02d+00:00",
278+ $updateDateTime[5]+1900, $updateDateTime[4]+1, @updateDateTime[3,2,1,0])
279+ );
280+ push(@bbsItems, \%rssItem);
281+ }
282+ }
283+
284+ # RSS出力
285+ print("Content-Type: application/rss+xml; charset=EUC-JP\n");
286+ # デバッグ用
287+# print("Content-Type: text/plain; charset=EUC-JP\n");
288+
289+ printf("Last-Modified: %s\n\n", $lastTime);
290+
291+ printf(qq(<?xml version="1.0" encoding="EUC-JP" ?>
292+<rdf:RDF
293+ xmlns="http://purl.org/rss/1.0/"
294+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
295+ xmlns:dc="http://purl.org/dc/elements/1.1/"
296+ xml:lang="ja">
297+ <channel rdf:about="%s">
298+ <title>%s</title>
299+ <link>%s</link>
300+ <description>${bbsTitle}</description>
301+ <items>
302+ <rdf:Seq>
303+), &enc(sprintf("%s&bbsTitle=%s", $RSS, &percent($bbsTitle))), &enc($bbsTitle), &enc($RSS));
304+ foreach $item (@bbsItems) {
305+ printf(qq( <rdf:li rdf:resource="%s"/>\n), &enc($item->{url}));
306+ }
307+ print(" </rdf:Seq>\n");
308+ print(" </items>\n");
309+ print(" </channel>\n");
310+ foreach $item (@bbsItems) {
311+ printf(qq( <item rdf:about="%s">\n), &enc($item->{url}));
312+ printf(" <title>%s</title>\n", &enc($item->{subject}));
313+ printf(qq( <link>%s</link>\n), &enc($item->{url}));
314+ printf(" <lastBuildDate>%s</lastBuildDate>\n", $item->{submitDateTime});
315+ printf(" <pubDate>%s</pubDate>\n", $item->{submitDateTime});
316+ printf(" <author>%s</author>\n", $item->{name});
317+ printf(" <dc:creator>%s</dc:creator>\n", $item->{name});
318+ printf(" <dc:date>%s</dc:date>\n", $item->{date});
319+ printf(" <description><![CDATA[%s]]></description>\n", $item->{message});
320+ printf(" </item>\n");
321+ }
322+ print("</rdf:RDF>\n");
323+ &flush();
324+ exit(0);
325+};
234326
235327 $main::preferences{'BBS Preference'}= [
236328 { desc=>'1ページに表示する件数' , type=>'text' , name=>'BBS_MAX_LINE' , size=>3 },
旧リポジトリブラウザで表示