Masato Kikuhara
en-sf****@users*****
2005年 6月 30日 (木) 02:38:50 JST
Index: affelio/apps/diary/AF_app.cfg
diff -u affelio/apps/diary/AF_app.cfg:1.2 affelio/apps/diary/AF_app.cfg:1.3
--- affelio/apps/diary/AF_app.cfg:1.2 Tue Jun 21 02:03:40 2005
+++ affelio/apps/diary/AF_app.cfg Thu Jun 30 02:38:50 2005
@@ -7,7 +7,7 @@
app_desc=Affelioæ¥è¨
app_author=Affelio project
guest_index=list_diary.cgi
-owner_index=write_diary.cgi
+owner_index=owner.cgi
action_types=write_diary, write_comment
action_types_desc=æ¥è¨æ¸ãè¾¼ã¿, ã³ã¡ã³ãæ¸ãè¾¼ã¿
Index: affelio/apps/diary/Diary.pm
diff -u affelio/apps/diary/Diary.pm:1.11 affelio/apps/diary/Diary.pm:1.12
--- affelio/apps/diary/Diary.pm:1.11 Mon Jun 27 20:40:10 2005
+++ affelio/apps/diary/Diary.pm Thu Jun 30 02:38:50 2005
@@ -24,7 +24,7 @@
my $self = {};
$self->{afap} = $afap;
$self->{uname} = $afap->{af}->{site__username};
- $self->{datadir} = $afap->get_userdata_dir()."xml/";
+ $self->{datadir} = $afap->get_userdata_dir();
$self->{dbh} = $afap->get_userdata_dbh;
$self->{entry_table} = "diary_$afap->{install_name}_entries";
$self->{comment_table} = "diary_$afap->{install_name}_comments";
@@ -167,6 +167,15 @@
return $ret[0];
}
+##############################################
+# existsEntry
+##############################################
+
+sub existsEntry {
+ my $self = shift;
+ my $id = $self->escape(shift, 'int');
+ return $self->getColumn("SELECT COUNT(*) FROM $self->{entry_table} WHERE id = $id") > 0;
+}
##############################################
# getEntries
@@ -335,7 +344,6 @@
$tmpl->param(
CALENDER => $calender,
- RSS => $self->{afap}->get_site_info("web_root") . "/apps/diary/get_rss.cgi",
access_control_URL => $self->{afap}->get_URL("access_control"),
);
$header .= $tmpl->output;
@@ -503,7 +511,86 @@
my $id = $self->escape(shift, 'int');
return $self->getColumn("SELECT COUNT(*) FROM $self->{tb_table} WHERE id = $id");
}
+
+##############################################
+# setRDFURL
+##############################################
+
+sub setRDFURL {
+ my ($self, $url) = @_;
+ local (*OUT);
+
+ open(OUT, "> $self->{datadir}url");
+ print OUT $url;
+ close(OUT);
+}
+
+##############################################
+# getRDFURL
+##############################################
+
+sub getRDFURL {
+ my $self = shift;
+ if (-f "$self->{datadir}url") {
+ local (*IN);
+ open (IN, "$self->{datadir}url");
+ my $rssfile = <IN>;
+ $rssfile =~ s/[\r\n]//g;
+ close(IN);
+ return $rssfile;
+ }
+ return undef;
+}
+
+##############################################
+# unsetRDF
+##############################################
+
+sub unsetRDFURL {
+ my $self = shift;
+ unlink("$self->{datadir}url") if (-f "$self->{datadir}url");
+}
+
+##############################################
+# getRSS
+##############################################
+
+sub getRSS {
+ my ($self, $count) = @_;
+ unless ($count) { $count = 5; }
+
+ my $tmpl = new HTML::Template(filename => './templates/rss.tmpl');
+
+ my @entries = $self->getNewestEntries($count);
+ my @item_list;
+ my @items;
+ my $web_root = $self->{afap}->get_site_info('web_root');
+ my $uname = $self->{afap}->get_owner_info('nickname');
+
+ foreach (@entries) {
+ my $link = $web_root."apps/diary/show_diary.cgi?id=$_->{id}";
+ push @item_list, { LINK => $link, };
+ my ($sec, $min, $hour, $mday, $mon, $year) = localtime($_->{timestamp});
+ push @items, {
+ TITLE => $_->{title},
+ LINK => $link,
+ DESCRIPTION => $_->{contents},
+ DATE => sprintf("%4d-%02d-%02dT%02d:%02d+09:00", $year, $mon, $mday, $hour, $min),
+ CREATOR => $uname,
+ TPING => $web_root."apps/diary/tb.cgi/$_->{id}",
+ };
+ }
+ $tmpl->param(
+ LINK => $web_root,
+ NICKNAME => $uname,
+ ITEM_LIST => \@item_list,
+ ITEMS => \@items,
+ );
+
+ return $tmpl->output;
+}
+
##############################################
# getURLDescription
##############################################
@@ -579,8 +666,11 @@
}
else {
$str =~ s/'/"/g;
+ $str =~ s/&/&/g;
+ $str =~ s/"/"/g;
$str =~ s/</</g;
$str =~ s/>/>/g;
+ $str =~ s/<(\/?)(br|p|i|b|strong|em|u|font)([^&]*)>/<$1$2$3>/gi;
$str =~ s/\r\n/<br \/>/g;
$str =~ s/[\r\n]/<br \/>/g;
$str =~ s/(s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/<a href="$1">$1<\/a>/g;
Index: affelio/apps/diary/edit_diary.cgi
diff -u affelio/apps/diary/edit_diary.cgi:1.4 affelio/apps/diary/edit_diary.cgi:1.5
--- affelio/apps/diary/edit_diary.cgi:1.4 Mon Jun 27 18:45:02 2005
+++ affelio/apps/diary/edit_diary.cgi Thu Jun 30 02:38:50 2005
@@ -5,6 +5,8 @@
my $id = $afap->{cgi}->param('id') or $diary->errorExit('è¨äºçªå·ãæå®ããã¦ãã¾ãã');
+$diary->errorExit("åå¨ããªãè¨äºã§ã") unless $diary->existsEntry($id);
+
my $tmpl;
# ç·¨éå®äº
Index: affelio/apps/diary/external_blog.cgi
diff -u /dev/null affelio/apps/diary/external_blog.cgi:1.1
--- /dev/null Thu Jun 30 02:38:50 2005
+++ affelio/apps/diary/external_blog.cgi Thu Jun 30 02:38:50 2005
@@ -0,0 +1,111 @@
+#!/usr/bin/perl
+
+require 'init.pl';
+
+my $urlfile = $diary->{datadir}.'url';
+
+my $writable = 0;
+if($afap->check_access("write_diary")){
+ $writable = 1;
+}
+
+eval { require XML::Parser; } or $diary->errorExit("XML::Parser is not available");
+
+# print header
+my $header =
+ "Content-type: text/html; charset=UTF-8\n".
+ "Pragma: no-cache\n\n".
+ $afap->get_HTML_header($diary->{header_titile});
+
+# set url
+if ($afap->{cgi}->param('set_url')) {
+ $diary->setRDFURL($afap->{cgi}->param('url'));
+}
+# unset url
+elsif ($afap->{cgi}->param('remove_urlfile')) {
+ $diary->unsetRDFURL;
+ print $diary->getRedirection('list_diary.cgi');
+ exit;
+}
+
+# load rss file and get url of rdf
+my $rssfile = $diary->getRDFURL;
+
+# if file was not found, show configuration file
+unless ($rssfile) {
+ $diary->checkAccess('write_diary');
+ my $tmpl = new HTML::Template(filename => "./templates/external_blog_conf.tmpl");
+ print $header;
+ print $tmpl->output;
+ print $diary->get_HTML_footer;
+ exit;
+}
+
+# send request
+my $req = new HTTP::Request(GET => $rssfile);
+my $ua = new LWP::UserAgent;
+my $res = $ua->request($req);
+my $str;
+if ($res->is_success) {
+ $str = $res->content;
+ $str =~ s/&/&/g; # escape '&'
+}
+else {
+ unlink($urlfile) if (-f $urlfile);
+ print $diary->errorExit("RDFã®åå¾ã«å¤±æãã¾ãããURLãééã£ã¦ããå¯è½æ§ãããã¾ã");
+}
+
+# parse and output
+use lib 'extlib';
+use XML::RSS::LP;
+
+my $rss = new XML::RSS::LP;
+$rss->parse($str);
+
+my @entries;
+my @entry_list;
+
+my $default = @{$rss->{prefix_table}->{'#default'}}[0];
+my $dc = @{$rss->{prefix_table}->{'dc'}}[0];
+my $i = 0;
+foreach (@{ $rss->{items} }) {
+ push @entries, {
+ TITLE => $_->{$default.'title'},
+ LINK => $_->{$default.'link'},
+ CONTENTS=> &escape_html($_->{$default.'description'}),
+ DATE => $_->{$dc.'date'},
+ };
+ push @entry_list, {
+ TITLE => $_->{$default.'title'},,
+ LINK => $_->{$default.'link'},
+ };
+ last if (++$i >= 10);
+}
+
+my $tmpl = new HTML::Template(filename => "./templates/external_blog.tmpl");
+$tmpl->param(
+ WRITABLE => $writable,
+ RSS_URL => $rssfile,
+ TITLE_MAIN => $rss->{channel}->{$default.'title'},
+ LINK_MAIN => $rss->{channel}->{$default.'link'},
+ ENTRIES => \@entries,
+ ENTRY_LIST => \@entry_list,
+);
+
+print $header;
+print $tmpl->output;
+print $diary->get_HTML_footer;
+
+sub escape_html {
+ my $html = shift;
+
+ $html =~ s/'/"/g;
+ $html =~ s/&/&/g;
+ $html =~ s/"/"/g;
+ $html =~ s/</</g;
+ $html =~ s/>/>/g;
+
+ # allow <br>,<p>,<a>,<i>,<b>,<strong>,<em>,<u>,<font>
+ $html =~ s/<(\/?)(br|p|a|i|b|strong|em|u|font)( *\/?)>/<$1$2$3>/gi;
+ return $html;
+}
Index: affelio/apps/diary/get_rss.cgi
diff -u affelio/apps/diary/get_rss.cgi:1.1.1.1 affelio/apps/diary/get_rss.cgi:1.2
--- affelio/apps/diary/get_rss.cgi:1.1.1.1 Tue Jun 14 12:53:30 2005
+++ affelio/apps/diary/get_rss.cgi Thu Jun 30 02:38:50 2005
@@ -1,30 +1,8 @@
#!/usr/bin/perl
-use strict;
-use lib("../../lib");
-use AffelioApp;
-use lib("../../extlib");
-use CGI;
-use Cwd;
+require 'init.pl';
-use Diary;
-use HTML::Template;
-
-use Jcode;
-
-my $cgi = new CGI();
-
-#AffelioAppãåæå
-my $afap = new AffelioApp(ConfigDir => Cwd::getcwd(),
- cgi => $cgi);
-
-exit(1) unless $afap->check_access("DF_access");
-
-
-#Content-typeãåºå
print "Content-type: application/xml; charset=UTF-8\n";
print "Pragma: no-cache", "\n\n";
-# rssãåºå
-my $diary = new Diary($afap);
-print Jcode::convert($diary->getRSS, 'utf8', 'euc');
+print $diary->getRSS;
Index: affelio/apps/diary/list_diary.cgi
diff -u affelio/apps/diary/list_diary.cgi:1.4 affelio/apps/diary/list_diary.cgi:1.5
--- affelio/apps/diary/list_diary.cgi:1.4 Sun Jun 26 13:08:34 2005
+++ affelio/apps/diary/list_diary.cgi Thu Jun 30 02:38:50 2005
@@ -1,6 +1,12 @@
#!/usr/bin/perl
require('init.pl');
+
+if (-f "$diary->{datadir}url") {
+ print $diary->getRedirection('external_blog.cgi');
+ exit;
+}
+
print $diary->get_HTML_header;
my $user = $afap->{cgi}->param("user");
Index: affelio/apps/diary/owner.cgi
diff -u /dev/null affelio/apps/diary/owner.cgi:1.1
--- /dev/null Thu Jun 30 02:38:50 2005
+++ affelio/apps/diary/owner.cgi Thu Jun 30 02:38:50 2005
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+require 'init.pl';
+
+our $mymode="owner";
+$diary->checkAccess('write_diary');
+
+if ($afap->{cgi}->param('save_state')) {
+ my $type = $afap->{cgi}->param('type');
+ if ($type eq 'import') {
+ $diary->setRDFURL($afap->{cgi}->param('url'));
+ print $diary->getRedirection('external_blog.cgi'); exit;
+ }
+ else { # normal diary
+ $diary->unsetRDFURL;
+ print $diary->getRedirection('list_diary.cgi'); exit;
+ }
+}
+
+my $tmpl = new HTML::Template(filename => './templates/owner.tmpl');
+
+print $diary->get_HTML_header;
+print $tmpl->output;
+print $diary->get_HTML_footer;
Index: affelio/apps/diary/show_diary.cgi
diff -u affelio/apps/diary/show_diary.cgi:1.4 affelio/apps/diary/show_diary.cgi:1.5
--- affelio/apps/diary/show_diary.cgi:1.4 Mon Jun 27 18:45:02 2005
+++ affelio/apps/diary/show_diary.cgi Thu Jun 30 02:38:50 2005
@@ -5,6 +5,8 @@
my $id = $afap->{cgi}->param('id') or $diary->errorExit("è¨äºçªå·ãæå®ããã¦ãã¾ãã");
+$diary->errorExit("åå¨ããªãè¨äºã§ã") unless $diary->existsEntry($id);
+
my $entry = $diary->getEntry($id);
my $tmpl = HTML::Template->new(filename => "./templates/show_diary.tmpl");
Index: affelio/apps/diary/style.css
diff -u affelio/apps/diary/style.css:1.2 affelio/apps/diary/style.css:1.3
--- affelio/apps/diary/style.css:1.2 Sun Jun 26 13:08:34 2005
+++ affelio/apps/diary/style.css Thu Jun 30 02:38:50 2005
@@ -34,6 +34,9 @@
div#diary_etc th {
color: #6699FF;
+ border-top: 0px;
+ border-left: 0px;
+ border-right: 0px;
border-bottom: 1px dashed #989898;
text-align: left;
}
@@ -50,10 +53,15 @@
}
table#calender th {
+ border-top: 0px;
+ border-left: 0px;
+ border-right: 0px;
border-bottom: 1px solid #989898;
+ font-size: 8pt;
}
table#calender td {
+ font-size: 8pt;
border: 0px;
}
Index: affelio/apps/diary/write_comment.cgi
diff -u affelio/apps/diary/write_comment.cgi:1.4 affelio/apps/diary/write_comment.cgi:1.5
--- affelio/apps/diary/write_comment.cgi:1.4 Mon Jun 27 18:45:02 2005
+++ affelio/apps/diary/write_comment.cgi Thu Jun 30 02:38:50 2005
@@ -5,12 +5,13 @@
my $id = $afap->{cgi}->param('id') or $diary->errorExit('è¨äºçªå·ãæå®ããã¦ãã¾ãã');
-my $comment = $afap->{cgi}->param('comment');
+$diary->errorExit("åå¨ããªãè¨äºã§ã") unless $diary->existsEntry($id);
+
# ã³ã¡ã³ã確èªç»é¢
if($afap->{cgi}->param('comment_confirm')) {
my $tmpl = HTML::Template->new(filename => "./templates/write_comment_confirm.tmpl");
- $tmpl->param(COMMENT => $comment, ID => $id);
+ $tmpl->param(COMMENT_SHOW => $diary->escape($afap->{cgi}->param('comment')), COMMENT => $afap->{cgi}->param('comment'), ID => $id);
print $diary->get_HTML_header;
print $tmpl->output;
print $diary->get_HTML_footer;
@@ -30,7 +31,7 @@
$user = "<a href=\"$url\">".$afap->get_visitor_info("nickname")."</a>";
}
- $diary->addComment($id, $user, $comment);
+ $diary->addComment($id, $user, $afap->{cgi}->param('comment'));
print $diary->getRedirection("show_diary.cgi?id=$id");
exit;
Index: affelio/apps/diary/write_diary.cgi
diff -u affelio/apps/diary/write_diary.cgi:1.4 affelio/apps/diary/write_diary.cgi:1.5
--- affelio/apps/diary/write_diary.cgi:1.4 Mon Jun 27 18:45:02 2005
+++ affelio/apps/diary/write_diary.cgi Thu Jun 30 02:38:50 2005
@@ -6,31 +6,29 @@
$diary->checkAccess('write_diary');
-my $title = $afap->{cgi}->param('title');
-my $contents = $afap->{cgi}->param('contents');
-my $tmplfile;
+my $tmpl;
if($afap->{cgi}->param('submit')) {
- $diary->addEntry($title, $contents);
+ $diary->addEntry($afap->{cgi}->param('title'), $afap->{cgi}->param('contents'));
print $diary->getRedirection('list_diary.cgi');
exit;
}
else {
print $diary->get_HTML_header;
if($afap->{cgi}->param('confirm')) {
- $tmplfile = "./templates/write_diary_confirm.tmpl";
+ $tmpl = new HTML::Template(filename => "./templates/write_diary_confirm.tmpl");
+ $tmpl->param(
+ TITLE => $afap->{cgi}->param('title'),
+ CONTENTS => $afap->{cgi}->param('contents'),
+ TITLE_SHOW => $diary->escape($afap->{cgi}->param('title')),
+ CONTENTS_SHOW => $diary->escape($afap->{cgi}->param('contents')),
+ );
}
else { # edit
- $title = $contents = "";
- $tmplfile = "./templates/write_diary_edit.tmpl";
+ $tmpl = new HTML::Template(filename => "./templates/write_diary_edit.tmpl");
}
}
-my $tmpl = HTML::Template->new(filename => $tmplfile);
-$tmpl->param(
- TITLE => $title,
- CONTENTS => $contents
-);
print $tmpl->output;
print $diary->get_HTML_footer;