$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 .= "$theme->{name}" . "\n"; } else { $ret .= "\n"; } } $ret .= ""; $ret .= BML::ml('Actionlink', { 'link' => "$ML{'.nav.viewall'}" }); $ret .= ""; }; $ret .= "
\n"; $ret .= LJ::html_hidden("page", $items{page}); $ret .= ""; # Create the table columns for each mood my $mname; my $n = 1; foreach $mname (@show_moods) { $ret .= "\n"; $n++; } $ret .= "\n"; if (@special_themes && $items{page} == 1) { $ret .= ""; $ret .= ""; $ret .= ""; foreach my $theme (@special_themes) { $mood_theme_table->($theme, 1); } } my %special_themeids = map { $_->{moodthemeid} => 1 } @special_themes; foreach my $theme (@show_themes) { next if $special_themeids{$theme->{moodthemeid}}; $mood_theme_table->($theme, 0); } $ret .= "
" . LJ::html_select({'name' => "theme$n", 'selected' => "$mname", 'style' => "text-align: center"}, map {$_->{name}, $_->{name}} @mlist) . "

$ML{'.specialthemes.header'}


$navbar
"; }; 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 .= "
"; } else { my @opts = ((map {$_->{moodthemeid}, $_->{name}} @themes), (@user_themes ? (0, "---") : ()), (map {$_->{moodthemeid}, $_->{name}} @user_themes)); $ret .= "
"; $ret .= LJ::html_select({'name' => "moodtheme", 'selected' => "$themeid"}, @opts); $ret .= " "; $ret .= "$ML{'.view.tree'}
"; } # 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 .= ""; } else { $ret .= ""; } } $ret .= ""; } $ret .= "
"; if ($GET{'ownerid'}) { $ret .= "
"; $ret .= LJ::ehtml(@user_themes[0]->{name}) . ' - '; $ret .= LJ::ljuser(LJ::get_username($GET{'ownerid'})); $ret .= "
" . "$m->{name}" . "
$mood
" . "$mood" . "
"; }; my $do_mood_tree = sub { my $self = shift; my $num = shift; return unless $lists{$num}; $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 .= LJ::html_select({'name' => "moodtheme", 'selected' => "$GET{moodtheme}"}, @opts); $ret .= " "; $ret .= LJ::html_hidden('mode' => 'tree'); $ret .= "
"; $ret .= "$ML{'.view.table'}
"; } $ret .= "