$LJ::SITENAMESHORT}); _code?>
head<=
<=head
body<=
{'user'};
my $u = LJ::load_user($journal);
my $add_header = sub {
$ret .= " $LJ::SITENAME}) . " p?> "href='$LJ::SITEROOT/customize/style.bml'"}) . " p?>";
};
# Get a list of all possible moods
my $moods = LJ::get_moods();
my @mlist = ();
my %lists = {};
foreach (sort { $moods->{$a}->{'name'} cmp $moods->{$b}->{'name'} } keys %$moods) {
my $m = $moods->{$_};
push @mlist, $m;
}
# FIXME: cache this. it's small.
$sth = $dbr->prepare("SELECT moodthemeid, name, is_public FROM moodthemes WHERE is_public='Y'");
$sth->execute;
my @themes = ();
while (my $moodtheme = $sth->fetchrow_hashref) {
my $is_active = LJ::run_hook("mood_theme_is_active", $moodtheme->{moodthemeid});
next unless !defined $is_active || $is_active;
push @themes, $moodtheme;
}
@themes = sort { lc($a->{name}) cmp lc($b->{name}) } @themes;
my @special_themes = LJ::run_hook('modify_mood_theme_list', \@themes, user => $u);
my $do_mood_list = sub {
# Setup the paging bar
my $perpage = 15;
my $start;
my $self_link;
my %items = BML::paging(\@themes, $GET{'page'} || 1, $perpage);
my $navbar = LJ::paging_bar($items{'page'}, $items{'pages'}, { 'self_link' => $self_link });
if ($items{'page'} == 1) {
$start = 0;
} else {
$start = ($items{'page'} - 1) * $perpage;
}
my @show_themes = splice (@themes, $start, $perpage);
# See if the user changed the shown moods
my @show_moods;
if($GET{'theme1'} && $GET{'theme2'} &&$ GET{'theme3'} && $GET{'theme4'}) {
@show_moods = ($GET{'theme1'}, $GET{'theme2'}, $GET{'theme3'}, $GET{'theme4'});
} else {
@show_moods = ('happy', 'sad', 'angry', 'tired');
}
my $mood_theme_table = sub {
my $theme = shift;
my $special = shift;
if ($special) {
my $author = LJ::run_hook("mood_theme_author", $theme->{moodthemeid});
$ret .= "
$theme->{'name'}";
$ret .= " " . BML::ml('.moodtheme.byauthor', {'author' => $author}) . "" if $author;
$ret .= " | \n";
} else {
$ret .= "
| $theme->{'name'} | \n";
}
LJ::load_mood_theme($theme->{'moodthemeid'});
# Output each of the displayed moods
foreach my $mood (@show_moods) {
if (LJ::get_mood_picture($theme->{'moodthemeid'}, LJ::mood_id($mood), \ my %pic)) {
$ret .= " " .
" | \n";
} else {
$ret .= " | \n";
}
}
$ret .= "";
$ret .= BML::ml('Actionlink', {
'link' => "$ML{'.nav.viewall'}"
});
$ret .= " | ";
};
$ret .= "";
};
my @user_themes;
# Determine the action depending on the GET arguments, or lack thereof
if (defined $GET{'moodtheme'}) {
$ret .= BML::ml('Backlink', {
'link'=>"$LJ::SITEROOT/moodlist.bml",
'text'=>$ML{'.back2'},
}). "
";
$add_header->();
# Check if the user is logged in and didn't specify an owner. If so append their private mood themes
my $sth;
if ($remote && ! $GET{'ownerid'}) {
# FIXME: cache this. it's small.
$sth = $dbr->prepare("SELECT moodthemeid, name, is_public FROM moodthemes WHERE ownerid=?");
$sth->execute($remote->{userid});
@user_themes = ();
push @user_themes, $_ while $_ = $sth->fetchrow_hashref;
} elsif ($GET{'ownerid'}) {
# FIXME: cache this. it's small.
$sth = $dbr->prepare("SELECT moodthemeid, name, is_public FROM moodthemes WHERE ownerid=? AND moodthemeid=?");
$sth->execute($GET{'ownerid'}, $GET{'moodtheme'});
@user_themes = ();
push @user_themes, $_ while $_ = $sth->fetchrow_hashref;
}
# Sort the user themes
@user_themes = sort { lc($a->{name}) cmp lc($b->{name}) } @user_themes;
my $do_theme_detail = sub {
my ($themeid) = @_;
$ret .= "
| ";
if ($GET{'ownerid'}) {
$ret .= " ";
$ret .= LJ::ehtml(@user_themes[0]->{name}) . ' - ';
$ret .= LJ::ljuser(LJ::get_username($GET{'ownerid'}));
$ret .= " |
";
} else {
my @opts = ((map {$_->{moodthemeid}, $_->{name}} @themes),
(@user_themes ? (0, "---") : ()),
(map {$_->{moodthemeid}, $_->{name}} @user_themes));
$ret .= "";
}
# Output all the moods
while (@mlist) {
$ret .= "";
# Show five moods in a row
for (my $i = 0; $i < 5; $i++) {
my $m = shift @mlist;
my $mood = $m->{name};
my %pic;
if (LJ::get_mood_picture($themeid, $m->{id}, \%pic)) {
$ret .= "" .
" " .
" $mood
| ";
} else {
$ret .= "" .
"$mood" .
"
| ";
}
}
$ret .= "
";
}
$ret .= "
";
};
my $do_mood_tree = sub {
my $self = shift;
my $num = shift;
return unless $lists{$num};
$ret .= "\n";
foreach my $mood (@{$lists{$num}}) {
$ret .= "- " . BML::ml('.moodname', {'name' => "{'name'}\" target='dict'>$mood->{'name'}", 'id' => $mood->{'id'}}) . "
\n";
my %pic;
if (LJ::get_mood_picture($GET{moodtheme}, $mood->{'id'}, \%pic)) {
unless ($GET{'hidederived'} && $pic{'moodid'} != $mood->{'id'}) {
$ret .= "
\n";
}
if ($GET{'details'} && ($pic{'moodid'} != $mood->{'id'})) {
$ret .= " $ML{'.moodname.fromparent'}";
}
} else {
if ($GET{'details'}) {
$ret .= "" . BML::ml('.moodname.nopicfortheme', {'id' => $GET{moodtheme}}) . "";
}
}
$self->($self, $mood->{'id'});
}
$ret .= "
\n";
};
# See if the user can even view this theme
my $theme = (grep { $_->{moodthemeid} == $GET{moodtheme} } (@themes, @user_themes))[0];
if (! $theme) {
# It isn't theirs, or they aren't logged in, and it isn't public and it actually exists
return LJ::bad_input($ML{'.error.cantviewtheme'});
} elsif ( defined $GET{mode} && $GET{mode} == 'tree') {
if ($GET{'ownerid'}) {
$ret .= "";
$ret .= LJ::ehtml(@user_themes[0]->{name}) . ' - ';
$ret .= LJ::ljuser(LJ::get_username($GET{'ownerid'}));
$ret .= "
";
} else {
my @opts = ((map {$_->{moodthemeid}, $_->{name}} @themes),
(@user_themes ? (0, "---") : ()),
(map {$_->{moodthemeid}, $_->{name}} @user_themes));
$ret .= "";
}
$ret .= "\n";
foreach (sort { $moods->{$a}->{'name'} cmp $moods->{$b}->{'name'} } keys %$moods) {
my $m = $moods->{$_};
push @{$lists{$m->{'parent'}}}, $m;
}
$do_mood_tree->($do_mood_tree, 0);
} else {
$do_theme_detail->($GET{'moodtheme'});
}
} else {
$add_header->();
$do_mood_list->();
}
return $ret;
}
_code?>
<=body
page?>
form: htdocs/moodlist.bml
link: htdocs/customize/style.bml
_c?>