head<= <=head body<= " unless $remote; my $authas = $GET{authas} || $remote->user; my $u = LJ::get_authas_user( $authas ); return LJ::bad_input( $ML{'error.invalidauth'} ) unless $u; my $self_uri = "/manage/moodthemes"; $self_uri .= "?authas=$authas" if $authas ne $remote->user; # Populated with all the moods later in editform my %lists; # one formauth for the whole page my $form_auth = LJ::form_auth(); my $ret = ''; my $warn = ''; #### Closure Definitions #### my $make_tree; $make_tree = sub { my ( $num, $theme ) = @_; return unless $lists{$num}; $ret .= "\n"; }; my $editform = sub { my ( $id ) = @_; my $theme = DW::Mood->new( $id ); # Get a list of all possible moods my $moods = DW::Mood->get_moods; foreach ( sort { $moods->{$a}->{name} cmp $moods->{$b}->{name} } keys %$moods ) { my $m = $moods->{$_}; push @{ $lists{ $m->{parent} } }, $m; } $make_tree->( 0, $theme ); }; #### End Closure Definitions #### if ( LJ::did_post() ) { # They actually did something, figure out what return "$ML{'Error'} $ML{'error.invalidform'}" unless LJ::check_form_auth(); my $themeid = $POST{themeid}; my $info; # Figure out if they are editing a theme and which one they are my @ids = split ',', $POST{themeids}; foreach ( @ids ) { $themeid = $_ if $POST{"edit:$_"}; } if ( ! $themeid ) { # They decided to actually use a custom theme my $use_theme; foreach ( @ids ) { $use_theme = $_ if $POST{"use:$_"}; } if ( $use_theme ) { my %update; $update{moodthemeid} = $use_theme; foreach ( keys %update ) { delete $update{$_} if $u->{$_} eq $update{$_}; } $u->update_self( \%update ); return BML::redirect( $self_uri ); } } elsif ( $POST{isnew} != 1 ) { # Make sure they can even edit this theme and fill in the $info variable for later use $info = DW::Mood->get_themes( { themeid => $themeid, ownerid => $u->id } ); return LJ::bad_input( $ML{'.error.notyourtheme'} ) unless defined $info; } # are we deleting a theme? foreach my $tid ( @ids ) { if ( $POST{"delete:$tid"} ) { # good, delete this one my $c = $u->delete_moodtheme( $tid ); return "" unless $c; return BML::redirect( $self_uri ); } } # We are either making changes to an existing theme or showing the edit form for a new theme if ( $themeid && $POST{edit} == 1 || $POST{isnew} == 1 ) { # Insert the new theme name and description into the db and grab its new themeid if ( $POST{isnew} == 1 ) { return LJ::bad_input( $ML{'.error.nonamegiven'} ) unless LJ::trim( $POST{name} ); my $err; $themeid = $u->create_moodtheme( $POST{name}, '', \$err ) or return ""; $info->{name} = $POST{name}; } $ret .= "\n LJ::ehtml( $info->{name} ) } ); $ret .= " h2?>\n"; # Make the form $ret .= "\n"; $ret .= $form_auth; $ret .= "$ML{'.editingtheme.label.name'} "; $ret .= LJ::html_text( { name => 'name', value => $info->{name}, size => 50, maxlength => 255 } ); $ret .= "

\n"; $ret .= LJ::html_hidden( 'themeid' => $themeid ) . "\n"; # Actually make the editor form $editform->( $themeid ); $ret .= LJ::html_submit( 'save' => $ML{'.btn.savechanges'} ); $ret .= " p?>\n"; } elsif ( $themeid ) { # Save their changes my $theme = DW::Mood->new( $themeid ) or return ""; # Update the name or description if needed if ( $info->{name} ne $POST{name} ) { $theme->update( 'name' => $POST{name} ) or return ""; } # The fun part of figuring out what needs to be changed in the db my @picdata; foreach my $key ( keys %POST ) { # A key that is fully numeric signifies an actual mood theme. # We then build off this id number to get other information needed # about what the user specified. if ( $key =~ /(^\d+$)/ ) { my $mid = $1; my $width = $POST{$mid.'w'} || 0; my $height = $POST{$mid.'h'} || 0; my $picurl = $POST{$key}; my $mname = DW::Mood->mood_name( $mid ); # don't update if nothing changed my %picdata; $theme->get_picture( $mid, \%picdata ); my $same = $picurl eq $picdata{pic} && $width == $picdata{w} && $height == $picdata{h}; next if $same; # allow width & height to default to that of parent if ( my $pid = $POST{$mid . 'parent'} ) { $width ||= $POST{$pid . 'w'}; $height ||= $POST{$pid . 'h'}; unless ( $width && $height ) { # check the database my %parent; $theme->get_picture( $pid, \%parent ); $width ||= $parent{w}; $height ||= $parent{h}; } } # one of these is blank, so delete the mood unless ( $picurl && $width && $height ) { push @picdata, [ $mid, {} ]; if ( $picdata{pic} ) { $ret .= BML::ml( '.mood.reset', { mood => "$mname($mid)"} ) . "
\n"; } else { $warn .= BML::ml( '.mood.notcreated', { mood => "$mname($mid)" } ) . "
\n"; } next; } # we have a picurl, width, and height. add it. if ( $picurl =~ m!^https?://[^\'\"\0\s]+$! ) { push @picdata, [ $mid, { picurl => $picurl, width => $width, height => $height } ]; $ret .= BML::ml( '.mood.setpic', { mood => "$mname($mid)", url => $picurl } ) . "
\n"; } } } # look again for inheritance # (id key for url was disabled, so no match above) foreach my $key ( keys %POST ) { if ( $key =~ /^(\d+)inherit$/ ) { my $mid = $1; next if $POST{$mid}; # already processed above next if $POST{$mid . 'oldinh'}; # no change in status # inherited, don't represent in db my $mname = DW::Mood->mood_name( $mid ); if ( $POST{$key} eq 'on' ) { push @picdata, [ $mid, {} ]; $ret .= BML::ml( '.mood.deleted', { mood => "$mname($mid)"} ) . "
\n"; } } } my $err; $theme->set_picture_multi( \@picdata, \$err ) or return ""; if ( $warn ) { $ret .= "
$ML{'.partiallysaved'}

$warn
\n"; } else { $ret .= "
$ML{'.saved'}

\n"; } } $ret .= BML::ml('Backlink', { 'link' => $self_uri, 'text' => $ML{'.back2'}, }); } else { # Show the first form to select user, which one to edit, or create a new one # user switcher $ret .= "
\n"; $ret .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'} }); $ret .= "
\n\n"; my $moodtheme_upsell = LJ::Hooks::run_hook("moodtheme_upsell"); unless ( $u->can_create_moodthemes ) { if ($moodtheme_upsell) { $ret .= $moodtheme_upsell; } else { $ret .= $ML{'.error.cantcreatethemes'}; } } else { # form to allow users to create new mood themes $ret .= "\n"; $ret .= "
\n"; $ret .= $form_auth; $ret .= LJ::html_hidden('isnew' => 1) . "\n"; $ret .= "$ML{'.createtheme.label.name'} " . LJ::html_text({ name => 'name', size => 30, maxlength => 50 }); $ret .= LJ::html_submit('create' => $ML{'.btn.create'}) . " p?>
\n"; # Make up the form to choose to edit a theme or create a new one $ret .= "\n"; # Get data to figure out if they have any themes already my @user_themes = DW::Mood->get_themes( { ownerid => $u->id } ); if (@user_themes) { # The have some custom themes already defined $ret .= "
\n"; $ret .= $form_auth; $ret .= LJ::html_hidden('edit' => 1, 'themeids' => join(",", map { $_->{moodthemeid} } @user_themes)); $ret .= ""; $ret .= ""; foreach my $theme ( @user_themes ) { my $ename = LJ::ehtml( $theme->{name} ); my $tid = $theme->{moodthemeid}; my $tobj = DW::Mood->new( $tid ); my $use_dis = 0; if ( $tid == $u->moodtheme ) { $ret .= ""; $use_dis = 1; } else { $ret .= ""; } my @head_moods = (15, 25, 2); # happy, sad, angry foreach my $moodid (@head_moods) { my %pic = (); $tobj->get_picture( $moodid, \%pic ) if $tobj; $ret .= ""; } my $confirm_delete = LJ::ejs($ML{'.yourthemes.delete.confirm'}); $ret .= ""; $ret .= ""; } $ret .= "
$ML{'.yourthemes.example.happy'}$ML{'.yourthemes.example.sad'}$ML{'.yourthemes.example.angry'}
$ename
$ename"; if (%pic) { $ret .= ""; } else { $ret .= "$ML{'.yourthemes.example.none'}"; } $ret .= "" . LJ::html_submit("edit:$tid" => $ML{'.btn.edit'}) . " " . LJ::html_submit("use:$tid", $ML{'.btn.use'}, {'disabled' => $use_dis}) . " " . LJ::html_submit("delete:$tid", $ML{'.btn.delete'}, { onclick => "return confirm('$confirm_delete');" }) . "
"; $ret .= "
\n"; } else { $ret .= "\n"; } } $ret .= " "href='$LJ::SITEROOT/customize/options?group=display'"}) . " p?>" unless $moodtheme_upsell; } return $ret; } _code?> <=body bodyopts=> onload="pageload();" page?>