2 title=><?_code return BML::ml('.title', {'sitename' => $LJ::SITENAMESHORT}); _code?>
8 .lj_moodlist_link:link {
11 .lj_moodlist_link:visited {
12 text-decoration: none;
14 .lj_moodlist_link:hover {
15 text-decoration: underline;
25 LJ::set_active_crumb('moodlist');
29 my $dbr = LJ::get_db_reader();
31 my $remote = LJ::get_remote();
32 my $journal = $GET{'journal'} || $remote->{'user'};
33 my $u = LJ::load_user($journal);
35 my $add_header = sub {
36 $ret .= "<?h1 $ML{'.moods.header'} h1?><?p " . BML::ml('.moods.intro', {'sitename' => $LJ::SITENAME}) . " p?><?p " . BML::ml('.moods.howtochange', {'aopts' => "href='$LJ::SITEROOT/customize/style.bml'"}) . " p?>";
39 # Get a list of all possible moods
40 my $moods = LJ::get_moods();
43 foreach (sort { $moods->{$a}->{'name'} cmp $moods->{$b}->{'name'} } keys %$moods) {
48 # FIXME: cache this. it's small.
49 $sth = $dbr->prepare("SELECT moodthemeid, name, is_public FROM moodthemes WHERE is_public='Y'");
52 while (my $moodtheme = $sth->fetchrow_hashref) {
53 my $is_active = LJ::run_hook("mood_theme_is_active", $moodtheme->{moodthemeid});
54 next unless !defined $is_active || $is_active;
55 push @themes, $moodtheme;
57 @themes = sort { lc($a->{name}) cmp lc($b->{name}) } @themes;
58 my @special_themes = LJ::run_hook('modify_mood_theme_list', \@themes, user => $u);
60 my $do_mood_list = sub {
61 # Setup the paging bar
65 my %items = BML::paging(\@themes, $GET{'page'} || 1, $perpage);
66 my $navbar = LJ::paging_bar($items{'page'}, $items{'pages'}, { 'self_link' => $self_link });
68 if ($items{'page'} == 1) {
71 $start = ($items{'page'} - 1) * $perpage;
73 my @show_themes = splice (@themes, $start, $perpage);
75 # See if the user changed the shown moods
77 if($GET{'theme1'} && $GET{'theme2'} &&$ GET{'theme3'} && $GET{'theme4'}) {
78 @show_moods = ($GET{'theme1'}, $GET{'theme2'}, $GET{'theme3'}, $GET{'theme4'});
80 @show_moods = ('happy', 'sad', 'angry', 'tired');
83 my $mood_theme_table = sub {
88 my $author = LJ::run_hook("mood_theme_author", $theme->{moodthemeid});
89 $ret .= "<tr class='standout-border standout-background'><td style='padding-left: 5px;'>$theme->{'name'}";
90 $ret .= "<br /><span style='font-size: smaller;'>" . BML::ml('.moodtheme.byauthor', {'author' => $author}) . "</span>" if $author;
93 $ret .= "<tr><td>$theme->{'name'}</td>\n";
96 LJ::load_mood_theme($theme->{'moodthemeid'});
98 # Output each of the displayed moods
99 foreach my $mood (@show_moods) {
100 if (LJ::get_mood_picture($theme->{'moodthemeid'}, LJ::mood_id($mood), \ my %pic)) {
101 $ret .= "<td align='center'><img align='absmiddle' alt='$theme->{name}' src=\"$pic{'pic'}\" ".LJ::mood_size_attributes(%pic)." hspace='2' vspace='2' />" .
104 $ret .= "<td></td>\n";
108 $ret .= "<td align='center'>";
109 $ret .= BML::ml('Actionlink', {
110 'link' => "<a href='$LJ::SITEROOT/moodlist.bml?moodtheme=$theme->{moodthemeid}'>$ML{'.nav.viewall'}</a>"
115 $ret .= "<form action='moodlist.bml' method='get'>\n";
116 $ret .= LJ::html_hidden("page", $items{page});
117 $ret .= "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td></td>";
119 # Create the table columns for each mood
122 foreach $mname (@show_moods) {
123 $ret .= "<td align='center'>" .
124 LJ::html_select({'name' => "theme$n", 'selected' => "$mname",
125 'style' => "text-align: center"},
126 map {$_->{name}, $_->{name}} @mlist) . "</td>\n";
130 $ret .= "<td align='center'><input type='submit' value=\"$ML{'.btn.switch'}\" /></td></tr>\n";
132 if (@special_themes && $items{page} == 1) {
133 $ret .= "<tr class='standout-border standout-background'>";
134 $ret .= "<td style='padding-left: 5px;' colspan='8'><h2>$ML{'.specialthemes.header'}</h2></td>";
136 foreach my $theme (@special_themes) {
137 $mood_theme_table->($theme, 1);
141 my %special_themeids = map { $_->{moodthemeid} => 1 } @special_themes;
142 foreach my $theme (@show_themes) {
143 next if $special_themeids{$theme->{moodthemeid}};
144 $mood_theme_table->($theme, 0);
147 $ret .= "<tr><td colspan='8' align='center'><br />$navbar</td></tr></table></form>";
151 # Determine the action depending on the GET arguments, or lack thereof
152 if (defined $GET{'moodtheme'}) {
153 $ret .= BML::ml('Backlink', {
154 'link'=>"$LJ::SITEROOT/moodlist.bml",
155 'text'=>$ML{'.back2'},
160 # Check if the user is logged in and didn't specify an owner. If so append their private mood themes
162 if ($remote && ! $GET{'ownerid'}) {
163 # FIXME: cache this. it's small.
164 $sth = $dbr->prepare("SELECT moodthemeid, name, is_public FROM moodthemes WHERE ownerid=?");
165 $sth->execute($remote->{userid});
167 push @user_themes, $_ while $_ = $sth->fetchrow_hashref;
168 } elsif ($GET{'ownerid'}) {
169 # FIXME: cache this. it's small.
170 $sth = $dbr->prepare("SELECT moodthemeid, name, is_public FROM moodthemes WHERE ownerid=? AND moodthemeid=?");
171 $sth->execute($GET{'ownerid'}, $GET{'moodtheme'});
173 push @user_themes, $_ while $_ = $sth->fetchrow_hashref;
176 # Sort the user themes
177 @user_themes = sort { lc($a->{name}) cmp lc($b->{name}) } @user_themes;
179 my $do_theme_detail = sub {
182 $ret .= "<br /><table width='100%'><tr><td colspan='5' align='center'>";
184 if ($GET{'ownerid'}) {
185 $ret .= "<div style='margin-bottom:15px; font-weight:bold'>";
186 $ret .= LJ::ehtml(@user_themes[0]->{name}) . ' - ';
187 $ret .= LJ::ljuser(LJ::get_username($GET{'ownerid'}));
188 $ret .= "</div></td></tr>";
190 my @opts = ((map {$_->{moodthemeid}, $_->{name}} @themes),
191 (@user_themes ? (0, "---") : ()),
192 (map {$_->{moodthemeid}, $_->{name}} @user_themes));
194 $ret .= "<div style='margin-bottom:15px'><form action='moodlist.bml' method='GET'>";
195 $ret .= LJ::html_select({'name' => "moodtheme", 'selected' => "$themeid"},
197 $ret .= " <input type='submit' value=\"$ML{'.btn.view'}\" /></form>";
198 $ret .= "<a href='/moodlist.bml?moodtheme=$themeid&mode=tree'>$ML{'.view.tree'}</a></div></td></tr>";
201 # Output all the moods
205 # Show five moods in a row
206 for (my $i = 0; $i < 5; $i++) {
207 my $m = shift @mlist;
208 my $mood = $m->{name};
210 if (LJ::get_mood_picture($themeid, $m->{id}, \%pic)) {
211 $ret .= "<td style='text-align:center; vertical-align:bottom'>" .
212 "<img align='absmiddle' style='margin-top:25px' alt='$m->{name}' src=\"$pic{'pic'}\" ".LJ::mood_size_attributes(%pic)." hspace='2' vspace='2' />" .
213 "<br /><a class='lj_moodlist_link' href='http://dictionary.reference.com/search?q=$mood'>$mood</a><br /></td>";
215 $ret .= "<td style='text-align:center; vertical-align:bottom'>" .
216 "<a class='lj_moodlist_link' href='http://dictionary.reference.com/search?q=$mood'>$mood</a>" .
225 my $do_mood_tree = sub {
228 return unless $lists{$num};
230 foreach my $mood (@{$lists{$num}}) {
231 $ret .= "<li>" . BML::ml('.moodname', {'name' => "<b><a href=\"http://dictionary.reference.com/search?q=$mood->{'name'}\" target='dict'>$mood->{'name'}</a></b>", 'id' => $mood->{'id'}}) . "</li>\n";
233 if (LJ::get_mood_picture($GET{moodtheme}, $mood->{'id'}, \%pic)) {
234 unless ($GET{'hidederived'} && $pic{'moodid'} != $mood->{'id'}) {
235 $ret .= "<img align='absmiddle' src=\"$pic{'pic'}\" ".LJ::mood_size_attributes(%pic)." hspace='2' vspace='2' />\n";
237 if ($GET{'details'} && ($pic{'moodid'} != $mood->{'id'})) {
238 $ret .= " $ML{'.moodname.fromparent'}";
241 if ($GET{'details'}) {
242 $ret .= "<b>" . BML::ml('.moodname.nopicfortheme', {'id' => $GET{moodtheme}}) . "</b>";
245 $self->($self, $mood->{'id'});
250 # See if the user can even view this theme
251 my $theme = (grep { $_->{moodthemeid} == $GET{moodtheme} } (@themes, @user_themes))[0];
253 # It isn't theirs, or they aren't logged in, and it isn't public and it actually exists
254 return LJ::bad_input($ML{'.error.cantviewtheme'});
255 } elsif ( defined $GET{mode} && $GET{mode} == 'tree') {
257 if ($GET{'ownerid'}) {
258 $ret .= "<div style='margin-bottom:15px; font-weight:bold' align='center'>";
259 $ret .= LJ::ehtml(@user_themes[0]->{name}) . ' - ';
260 $ret .= LJ::ljuser(LJ::get_username($GET{'ownerid'}));
261 $ret .= "</div></td></tr>";
263 my @opts = ((map {$_->{moodthemeid}, $_->{name}} @themes),
264 (@user_themes ? (0, "---") : ()),
265 (map {$_->{moodthemeid}, $_->{name}} @user_themes));
266 $ret .= "<div style='margin-bottom:15px; margin-top:30px' align='center'><form action='moodlist.bml' method='GET'>";
267 $ret .= LJ::html_select({'name' => "moodtheme", 'selected' => "$GET{moodtheme}"},
269 $ret .= " <input type='submit' value=\"$ML{'.btn.view'}\" />";
270 $ret .= LJ::html_hidden('mode' => 'tree');
272 $ret .= "<a href='/moodlist.bml?moodtheme=$theme->{moodthemeid}'>$ML{'.view.table'}</a></div>";
276 foreach (sort { $moods->{$a}->{'name'} cmp $moods->{$b}->{'name'} } keys %$moods) {
277 my $m = $moods->{$_};
278 push @{$lists{$m->{'parent'}}}, $m;
281 $do_mood_tree->($do_mood_tree, 0);
283 $do_theme_detail->($GET{'moodtheme'});
296 form: htdocs/moodlist.bml
297 link: htdocs/customize/style.bml