request;
if ($uri =~ m!/(\d\d\d\d)/(\d\d)/?$!) {
$FORM{'user'} = $r->notes('_journal');
$FORM{'type'} = "month";
$FORM{'y'} = $1;
$FORM{'m'} = $2 + 0;
}
$r->notes("codepath" => "bml.view.index");
my $view = $FORM{'type'};
my $user = $FORM{'user'};
if ($view ne "month") {
$title = "Error";
$body .= "Unknown view.";
return;
}
unless ($user) {
$title = "Error";
$body .= "No user given.";
return;
}
my $u = LJ::load_user($user);
unless ($u) {
$title = "Error";
$body .= "User doesn't exist.";
return;
}
# check for purged
if ($u->{'statusvis'} eq "X") {
$body = "";
return;
}
if ($u->{'journaltype'} eq "R") {
LJ::load_user_props($u, "renamedto");
if ($u->{'renamedto'}) {
return BML::redirect(sprintf(LJ::journal_base($u->{'renamedto'}) . "/%04d/%02d/", $FORM{'y'}, $FORM{'m'}));
}
}
my $remote = LJ::get_remote();
# do they have the viewall priv?
my $viewall = 0;
my $viewsome = 0;
if ($GET{'viewall'} && LJ::check_priv($remote, "canview")) {
LJ::statushistory_add($u->{'userid'}, $remote->{'userid'},
"viewall", "month: $u->{'user'}, statusvis: $u->{'statusvis'}");
$viewall = LJ::check_priv($remote, 'canview', '*');
$viewsome = $viewall || LJ::check_priv($remote, 'canview', 'suspended');
# check for deleted/suspended
} else {
# check suspended
if ($u->{'statusvis'} eq "S") {
$body = "";
return;
}
# check deleted
if ($u->{'statusvis'} eq "D") {
$body = "";
return;
}
}
LJ::load_user_props($u, "opt_blockrobots") if $u->{'statusvis'} eq 'V';
if ($u->{'statusvis'} ne 'V' || $u->{'opt_blockrobots'}) {
$head .= LJ::robot_meta_tags();
}
my $base = LJ::journal_base($u);
if (LJ::did_post()) {
my $newuri = sprintf("$base/%04d/%02d/", $POST{'y'}, $POST{'m'});
return BML::redirect($newuri);
}
my $secwhere = "AND l.security='public'";
if ($remote) {
if ($remote->{'userid'} == $u->{'userid'} || $viewall) {
$secwhere = ""; # see everything
} elsif ($remote->{'journaltype'} eq 'P') {
my $gmask = LJ::get_groupmask($u, $remote);
$secwhere = "AND (l.security='public' OR (l.security='usemask' AND l.allowmask & $gmask))"
if $gmask;
}
}
my $year = $FORM{'y'}+0;
my $month = $FORM{'m'}+0;
unless ($year =~ /^\d\d\d\d$/ && ($month >= 1 && $month <= 12)) {
my @now = localtime();
$year = $now[5] + 1900;
$month = $now[4] + 1;
}
my $monlang = LJ::Lang::month_long($month);
$title = $monlang;
$title .= ", $year - $u->{'user'}";
my $is_person = $u->{'journaltype'} eq "P";
if ($is_person) {
$body .= "{'user'}) . " in $monlang, $year. p?>";
} else {
$body .= "{'user'}) . " journal in $monlang, $year. p?>";
}
### make standout box
{
my @next = ($year, $month+1);
if ($next[1] > 12) { @next = ($year+1, 1); }
my @prev = ($year, $month-1);
if ($prev[1] < 1) { @prev = ($year-1, 12); }
my $next = " ";
my $prev = " ";
$body .= " ";
$body .= "
";
$body .= " standout?>\n";
}
$body .= "\n";
my $db = LJ::get_cluster_reader($u);
my $sth = $db->prepare("SELECT l.jitemid, l.anum, l.day, l.eventtime, l.posterid, ".
"l.replycount, l.security ".
"FROM log2 l ".
"WHERE l.journalid=$u->{'userid'} AND l.year=$year AND l.month=$month ".
"$secwhere LIMIT 2000");
my $items = $db->selectall_arrayref($sth);
# figure out what we need to load
my @itemids;
my %need_userid; # userid -> 1
foreach my $it (@$items) {
push @itemids, $it->[0];
$need_userid{$it->[4]} = 1;
}
my $lt = LJ::get_logtext2($u, @itemids);
my %u;
LJ::load_userids_multiple([map { $_ => \$u{$_} } keys %need_userid], []);
# sort on event time
my $lday = 0; # last day shown
foreach my $it (sort { $a->[3] cmp $b->[3] } @$items)
{
my ($itemid, $anum, $day, $eventtime, $posterid, $replycount, $security) = @$it;
next if $u{$posterid}->{statusvis} eq 'S' && !$viewsome;
my $subject = $lt->{$itemid}->[0];
my $poster = $u{$posterid}->{user};
if ($day != $lday) {
if ($lday) { $body .= ""; }
$lday = $day;
my $ord = LJ::Lang::day_ord($day);
my $dayview_url = sprintf("$LJ::SITEROOT/users/$u->{'user'}/%04d/%02d/%02d/",
$year, $month, $day);
$body .= "$day$ord ";
$body .= "";
}
# we need to convert the subject to UTF-8 if it's a pre-Unicode entry
# loading all the props for all the posts and checking 'unknown8bit'
# is too long. The heuristic "if it's not UTF-8, convert it" works
# well here.
if ($LJ::UNICODE && !LJ::is_utf8($subject)) {
my $error;
my $subj = LJ::text_convert($subject, $u, \$error);
$subject = $subj unless $error;
LJ::text_out(\$subject);
}
unless ($subject ne "") { $subject = "(no subject)"; }
my $h = substr($eventtime, 11, 2);
my $m = substr($eventtime, 14, 2);
my ($rep, $sec);
if ($security eq "private") {
$sec = " ";
} elsif ($security eq "usemask") {
$sec = " ";
}
if ($replycount) {
if ($replycount == 1) { $rep .= " - $replycount reply"; }
else { $rep .= " - $replycount replies"; }
}
$body .= "" . LJ::Lang::time_format(12, $h, $m, "short") . " ";
if (! $is_person) {
$body .= "" . LJ::ljuser($poster) . " ";
}
LJ::CleanHTML::clean_subject_all(\$subject);
$body .= "$subject $sec$rep \n";
}
if ($lday) { $body .= "
\n"; }
$body .= " ";
return;
_code?>
head=>
body=>
page?>
img: htdocs/img/btn_next.gif, htdocs/img/btn_prev.gif
form: htdocs/view/index.bml
link: htdocs/users, htdocs/talkread.bml
_c?>