summaryrefslogtreecommitdiffstats
path: root/blog
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-05-26 10:29:15 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-05-26 10:29:15 +0800
commit2ef2a996f26a2c96f8cc16e27bd43db76b843af1 (patch)
treef5527cf51d3ab378a7e198cf45d83225cf8a97b2 /blog
parent4eaaf02d894828c8608b5993d0a5667679593191 (diff)
downloadpttbbs-2ef2a996f26a2c96f8cc16e27bd43db76b843af1.tar
pttbbs-2ef2a996f26a2c96f8cc16e27bd43db76b843af1.tar.gz
pttbbs-2ef2a996f26a2c96f8cc16e27bd43db76b843af1.tar.bz2
pttbbs-2ef2a996f26a2c96f8cc16e27bd43db76b843af1.tar.lz
pttbbs-2ef2a996f26a2c96f8cc16e27bd43db76b843af1.tar.xz
pttbbs-2ef2a996f26a2c96f8cc16e27bd43db76b843af1.tar.zst
pttbbs-2ef2a996f26a2c96f8cc16e27bd43db76b843af1.zip
counter support by DBI
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@897 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'blog')
-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;