summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xblog/blog.pl52
1 files changed, 50 insertions, 2 deletions
diff --git a/blog/blog.pl b/blog/blog.pl
index 4f177972..6fc63b1b 100755
--- a/blog/blog.pl
+++ b/blog/blog.pl
@@ -55,6 +55,15 @@ sub main
packdate($y1, $m1, $d1));
}
}
+ elsif( $attr{"$fn.loadBlog"} =~ /^last(\d+)/i ){
+ my($ptr, $i);
+ for( $ptr = $article{last}, $i = 0 ;
+ $ptr && $i < $1 ;
+ $ptr = $article{"$ptr.prev"} ){
+ AddArticle('blog', $attr{"$fn.loadBlogFields"},
+ $ptr);
+ }
+ }
if( $attr{"$fn.loadBlogPrevNext"} ){
my $s = packdate($y, $m, $d);
@@ -63,6 +72,7 @@ sub main
AddArticle('prev', $attr{"$fn.loadBlogPrevNext"},
$article{"$s.prev"});
}
+
# loadArchives -----------------------------------------------------------
if( $attr{"$fn.loadArchives"} =~ /^monthly/i ){
# 找尋 +-1 year 內有資料的月份
@@ -97,6 +107,25 @@ sub main
}
}
+ # Counter ----------------------------------------------------------------
+ if( $attr{"$fn.loadCounter"} ){
+ my($c);
+ $c = dodbi(sub {
+ my($dbh) = @_;
+ my($sth, $t);
+ $dbh->do("update counter set v = v + 1 where k = '$brdname'");
+ $sth = $dbh->prepare("select v from counter where k='$brdname'");
+ $sth->execute();
+ $t = $sth->fetchrow_hashref();
+ return $t->{v} if( $t->{v} );
+
+ $dbh->do("insert into counter (k, v) ".
+ "values ('$brdname', 1)");
+ return 1;
+ });
+ $th{counter} = $c;
+ }
+
# Calendar ---------------------------------------------------------------
if( $attr{"$fn.loadCalendar"} ){
# 沒有合適的 module , 自己寫一個 |||b
@@ -131,7 +160,7 @@ sub main
}
else{
my $link = $attr{"$fn.loadCalendar"};
- $link =~ s/\[\% key \%\]/,$t/g;
+ $link =~ s/\[\% key \%\]/$t/g;
$c .= "<a href=\"$link\">$_</a>";
}
@@ -167,7 +196,7 @@ sub AddArticle($$$)
if( $fields =~ /content/i ){
$content = $article{"$s.content"};
if( $config{outputfilter} == 1 ){
- $content =~ s/\n/<br>\n/gs;
+ $content =~ s/\n/<br \/>\n/gs;
}
}
@@ -216,6 +245,25 @@ sub unpackdate($)
$_[0] % 100);
}
+sub dodbi
+{
+ my($func) = @_;
+ my($ret);
+ use DBI;
+ use DBD::mysql;
+ my $dbh = DBI->connect("DBI:mysql:database=blog;".
+ "host=localhost",
+ 'root',
+ '',
+ {'RaiseError' => 1});
+ eval {
+ $ret = &{$func}($dbh);
+ };
+ $dbh->disconnect();
+ print "SQL: $@\n" if( $@ );
+ return $ret;
+}
+
main();
1;