login. p?>" unless $remote; my @journals = ($remote->{'user'}); push @journals, LJ::get_shared_journals($remote); my $journal = $GET{'journal'} || $remote->{'user'}; unless (grep { $_ eq $journal } @journals) { return BML::redirect("/customize/"); } my $u = $remote; $u = LJ::load_user($journal) unless $journal eq $remote->{'user'}; my $userid = $u->{'userid'}; LJ::load_user_props($u, "stylesys", "s2_style"); $body = ""; $title = "Customize"; $js = ""; my $err = sub { $title = "Error"; $body = shift; return; }; my ($style, $layer); my $save_arg; my $save_redir; # when given 'w' argument, load user's current style, and edit the user layer. # this is the mode redirected to from /customize/ (the simple customization UI) if ($GET{'w'} eq "user" && $u->{'stylesys'} == 2) { $style = LJ::S2::load_style($u->{'s2_style'}); return $err->("Style not found.") unless $style && $style->{'userid'} == $u->{'userid'}; $layer = LJ::S2::load_layer($dbh, $style->{'layer'}->{'user'}); # if the b2lid of this layer has been remapped to a new layerid # then update the b2lid mapping for this layer my $b2lid = $layer->{b2lid}; if ($b2lid && $LJ::S2LID_REMAP{$b2lid}) { LJ::S2::b2lid_remap($u, $style->{'layer'}->{'user'}, $b2lid); $layer->{b2lid} = $LJ::S2LID_REMAP{$b2lid}; } $save_arg = "w=user&journal=$journal"; $save_redir = "/customize/?journal=$journal"; } return BML::redirect("/customize/") unless $layer; return $err->("Layer belongs to another user.") unless $layer->{'userid'} == $u->{'userid'}; return $err->("Layer isn't of type user or theme.") unless $layer->{'type'} eq "user" || $layer->{'type'} eq "theme"; my $lyr_layout = LJ::S2::load_layer($dbh, $layer->{'b2lid'}); return $err->("Layout layer for this $layer->{'type'} layer not found.") unless $lyr_layout; my $lyr_core = LJ::S2::load_layer($dbh, $lyr_layout->{'b2lid'}); return $err->("Core layer for layout not found.") unless $lyr_core; $lyr_layout->{'uniq'} = $dbh->selectrow_array("SELECT value FROM s2info WHERE s2lid=? AND infokey=?", undef, $lyr_layout->{'s2lid'}, "redist_uniq"); my ($lid_i18nc, $lid_theme, $lid_i18n); $lid_i18nc = $style->{'layer'}->{'i18nc'}; $lid_theme = $style->{'layer'}->{'theme'}; $lid_i18n = $style->{'layer'}->{'i18n'}; my $layerid = $layer->{'s2lid'}; my @layers; push @layers, ([ 'core' => $lyr_core->{'s2lid'} ], [ 'i18nc' => $lid_i18nc ], [ 'layout' => $lyr_layout->{'s2lid'} ], [ 'i18n' => $lid_i18n ]); if ($layer->{'type'} eq "user" && $lid_theme) { push @layers, [ 'theme' => $lid_theme ]; } push @layers, [ $layer->{'type'} => $layer->{'s2lid'} ]; my @layerids = grep { $_ } map { $_->[1] } @layers; LJ::S2::load_layers(@layerids); my %layerinfo; # load the language and layout choices for core. LJ::S2::load_layer_info(\%layerinfo, \@layerids); # action path if (LJ::did_post()) { # prevent spoofing: return BML::redirect("/customize") unless $POST{'userid'} == $u->{'userid'}; my %override; foreach my $prop (S2::get_properties($lyr_layout->{'s2lid'})) { $prop = S2::get_property($lyr_core->{'s2lid'}, $prop) unless ref $prop; next unless ref $prop; next if $prop->{'noui'}; my $name = $prop->{'name'}; next unless $POST{"$name:override"}; next unless LJ::S2::can_use_prop($u, $lyr_layout->{'uniq'}, $name); $override{$name} = [ $prop, $POST{"${name}_value"} ]; } if (LJ::S2::layer_compile_user($layer, \%override)) { return BML::redirect($save_redir) if $save_redir; $body = "Saved."; return; } else { my $error = LJ::last_error(); $body = "Error saving layer:
$error"; } return; } $body .= ""; return; } _code?> body=> head<= <=head page?>