Tatsuki SUGIURA
sugi****@users*****
2006年 7月 12日 (水) 21:24:22 JST
Index: slashjp/plugins/Journal/Journal.pm diff -u slashjp/plugins/Journal/Journal.pm:1.6 slashjp/plugins/Journal/Journal.pm:1.7 --- slashjp/plugins/Journal/Journal.pm:1.6 Wed Jul 12 20:41:49 2006 +++ slashjp/plugins/Journal/Journal.pm Wed Jul 12 21:24:22 2006 @@ -1,7 +1,7 @@ # This code is a part of Slash, and is released under the GPL. # Copyright 1997-2005 by Open Source Technology Group. See README # and COPYING for more information, or see http://slashcode.com/. -# $Id: Journal.pm,v 1.6 2006/07/12 11:41:49 sugi Exp $ +# $Id: Journal.pm,v 1.7 2006/07/12 12:24:22 sugi Exp $ package Slash::Journal; @@ -13,10 +13,9 @@ use vars qw($VERSION); use base 'Exporter'; -use base 'Slash::DB::Utility'; use base 'Slash::DB::MySQL'; -($VERSION) = ' $Revision: 1.6 $ ' =~ /\$Revision:\s+([^\s]+)/; +($VERSION) = ' $Revision: 1.7 $ ' =~ /\$Revision:\s+([^\s]+)/; # On a side note, I am not sure if I liked the way I named the methods either. # -Brian @@ -201,6 +200,7 @@ my($date) = $self->sqlSelect('date', 'journals', "id=$id"); my $slashdb = getCurrentDB(); $slashdb->setUser($uid, { journal_last_entry_date => $date }); + $self->updateUsersJournal($uid); return $id; } @@ -248,19 +248,42 @@ } my $slashdb = getCurrentDB(); $slashdb->setUser($uid, { -journal_last_entry_date => $date }); + $self->updateUsersJournal($uid); + return $count; } +sub updateUsersJournal { + my ($self, $uid) = @_; + + my $count = $self->sqlCount("journals", "uid=$uid"); + my $jid = $self->sqlSelect("MAX(id)", "journals", "uid=$uid"); + my $date = $self->sqlSelect("date", "journals", "id=$jid"); + if ($self->sqlUpdate("users_journal", + { count => $count, + jid => $jid, + date => $date }, + "uid=$uid") < 1) { + if ($self->sqlInsert("users_journal", + { uid => $uid, + jid => $jid, + count => $count, + date => $date }) < 1) { + return 0; + } + } + return 1; +} + sub top { my($self, $limit) = @_; $limit ||= getCurrentStatic('journal_top') || 10; $self->sqlConnect; my $sql = <<EOT; -SELECT count(j.uid) AS c, u.nickname, j.uid, MAX(date), MAX(id) -FROM journals AS j, users AS u -WHERE j.uid = u.uid -GROUP BY u.nickname ORDER BY c DESC +SELECT count AS c,nickname,users_journal.uid,date,jid AS id +FROM users_journal JOIN users USING (uid) +ORDER BY count DESC LIMIT $limit EOT @@ -286,10 +309,10 @@ $self->sqlConnect; my $sql = <<EOT; -SELECT count(j.id), u.nickname, u.uid, MAX(j.date) AS date, MAX(id) -FROM journals AS j, users AS u -WHERE j.uid = u.uid -GROUP BY u.nickname +SELECT count AS c,nickname,users_journal.uid,users_journal.date,jid AS id,description,journals_text.article +FROM users_journal JOIN users USING (uid) +JOIN journals ON jid=journals.id +JOIN journals_text ON jid=journals_text.id ORDER BY date DESC LIMIT $limit EOT @@ -297,17 +320,6 @@ my $losers = $self->{_dbh}->selectall_arrayref($sql); return [ ] if !$losers || !@$losers; - my $id_list = join(", ", map { $_->[4] } @$losers); - my $loserid_hr = $self->sqlSelectAllHashref( - "id", - "id, description", - "journals", - "id IN ($id_list)"); - - for my $loser (@$losers) { - $loser->[5] = $loserid_hr->{$loser->[4]}{description}; - } - return $losers; } Index: slashjp/plugins/Journal/journal.pl diff -u slashjp/plugins/Journal/journal.pl:1.11 slashjp/plugins/Journal/journal.pl:1.12 --- slashjp/plugins/Journal/journal.pl:1.11 Wed Jul 12 20:41:49 2006 +++ slashjp/plugins/Journal/journal.pl Wed Jul 12 21:24:22 2006 @@ -2,7 +2,7 @@ # This code is a part of Slash, and is released under the GPL. # Copyright 1997-2005 by Open Source Technology Group. See README # and COPYING for more information, or see http://slashcode.com/. -# $Id: journal.pl,v 1.11 2006/07/12 11:41:49 sugi Exp $ +# $Id: journal.pl,v 1.12 2006/07/12 12:24:22 sugi Exp $ use strict; use Slash 2.003; # require Slash 2.3.x @@ -13,7 +13,7 @@ use Slash::XML; use vars qw($VERSION); -($VERSION) = ' $Revision: 1.11 $ ' =~ /\$Revision:\s+([^\s]+)/; +($VERSION) = ' $Revision: 1.12 $ ' =~ /\$Revision:\s+([^\s]+)/; sub main { my $journal = getObject('Slash::Journal'); @@ -310,7 +310,8 @@ push @items, { title => $title, - 'link' => "$gSkin->{absolutedir}/~" . fixparam($entry->[1]) . "/journal/" + link => "$gSkin->{absolutedir}/~" . fixparam($entry->[1]) . "/journal/", + description => strip_notags($entry->[6]), }; } @@ -410,6 +411,8 @@ my $user_change = {}; my $head_data = {}; + my $slashdb = getCurrentDB(); + if ($form->{uid} || $form->{nick}) { $uid = $form->{uid} ? $form->{uid} : $journal_reader->getUserUID($form->{nick}); my $tmpuser = $journal_reader->getUser($uid, ['nickname', 'karma']); @@ -432,6 +435,7 @@ $head_data->{nickname} = $nickname; $head_data->{uid} = $uid; + $head_data->{last_modified} = timeCalc($slashdb->getUser($uid, 'journal_last_entry_date'), "%a, %d %b %Y %H:%M:%S %Z", 0); if (isAnon($uid)) { # Don't write user_change. @@ -916,6 +920,7 @@ sub _printHead { my($head, $data, $edit_the_uid) = @_; my $title = getData($head, $data); + my $options = { last_modified => $data->{last_modified} }; my $links = { title => $title, @@ -924,7 +929,7 @@ nickname => $data->{nickname} } }; - header($links) or return; + header($links, undef, $options) or return; $data->{menutype} ||= 'users'; $data->{width} = '100%';