From 2ef2a996f26a2c96f8cc16e27bd43db76b843af1 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 02:29:15 +0000 Subject: counter support by DBI git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@897 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- blog/blog.pl | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file 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 .= "$_"; } @@ -167,7 +196,7 @@ sub AddArticle($$$) if( $fields =~ /content/i ){ $content = $article{"$s.content"}; if( $config{outputfilter} == 1 ){ - $content =~ s/\n/
\n/gs; + $content =~ s/\n/
\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; -- cgit v1.2.3