head<= <=head body<= {'user'}; my $u = LJ::get_authas_user($authas); return LJ::bad_input($ML{'error.invalidauth'}) unless $u; my $userid = $u->{'userid'}; my $has_cap = LJ::get_cap($u, "s2styles"); return $LJ::MSG_READONLY_USER if LJ::get_cap($u, "readonly"); my $ret; # authas switcher form $ret .= "
\n"; $ret .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'} || $GET{'journal'} }) . "\n"; $ret .= "
\n\n"; LJ::load_user_props($u, "stylesys", "s2_style"); $u->{'stylesys'} ||= 1; my $pub = LJ::S2::get_public_layers(); my $userlay = LJ::S2::get_layers_of_user($u); my %style = LJ::S2::get_style($u, "verify"); my $get_lang = sub { my $styleid = shift; foreach ($userlay, $pub) { return $_->{$styleid}->{'langcode'} if $_->{$styleid} && $_->{$styleid}->{'langcode'}; } return undef; }; my $langcode = $get_lang->($style{'i18n'}) || $get_lang->($style{'i18nc'}); if ($POST{'save:stylesys'}) { my $num = $POST{'stylesys'} == 2 ? 2 : 1; LJ::set_userprop($u, "stylesys", $num); return BML::redirect("/customize/?journal=$u->{'user'}"); } my $implicit_style_create = sub { # create new style if necessary unless ($u->{'s2_style'}) { my $layid = $style{'layout'}; my $lay = $pub->{$layid} || $userlay->{$layid}; my $uniq = (split("/", $lay->{'uniq'}))[0] || $lay->{'s2lid'}; unless ($u->{'s2_style'} = LJ::S2::create_style($u, "wizard-$uniq")) { die ""; } LJ::set_userprop($u, "s2_style", $u->{'s2_style'}); } # save values in %style to db LJ::S2::set_style_layers($u, $u->{'s2_style'}, %style); }; if ($POST{'save:layout'}) { my $layid = $POST{'layoutid'}+0; return BML::redirect("/customize/?journal=$u->{'user'}") if $layid == $style{'layout'}; my $lay = $pub->{$layid}; return "" if ! $lay and $lay ||= $userlay->{$layid} and ! $has_cap; return "" unless $lay && LJ::S2::can_use_layer($u, $lay->{'uniq'}); my $coreid = $lay->{'b2lid'}; return "" unless $coreid; # delete s2_style and replace it with a new # or existing style for this layout delete $u->{'s2_style'}; my $uniq = (split("/", $lay->{'uniq'}))[0] || $lay->{'s2lid'}; my $usersty = LJ::S2::load_user_styles($u); foreach (keys %$usersty) { next unless $usersty->{$_} eq "wizard-$uniq"; $u->{'s2_style'} = $_; LJ::set_userprop($u, "s2_style", $u->{'s2_style'}); # now we have to populate %style from this style, but not core and layout, # as those are reset below my $stylay = LJ::S2::get_style_layers($u, $u->{'s2_style'}); foreach my $layer (qw(user theme i18nc i18n)) { $style{$layer} = exists $stylay->{$layer} ? $stylay->{$layer} : 0; } last; } # no existing style found, create a new one unless ($u->{'s2_style'}) { $style{'user'} = $style{'theme'} = $style{'i18nc'} = $style{'i18n'} = 0; } # even if we're using an existing style that we found by name (uniq), we need to # set layout and core layers to make sure the style still has the proper layout $style{'layout'} = $layid; $style{'core'} = $coreid; $implicit_style_create->(); return BML::redirect("/customize/?journal=$u->{'user'}"); } if ($POST{'action:deluser'}) { LJ::S2::delete_layer($style{'user'}); LJ::S2::set_style_layers($u, $u->{'s2_style'}, "user", 0) if $style{'user'}; return BML::redirect("/customize/?journal=$u->{'user'}"); } if ($POST{'action:edituser'}) { unless ($style{'user'}) { $style{'user'} = LJ::S2::create_layer($u, $style{'layout'}, "user"); return " " unless $style{'user'}; } $implicit_style_create->(); return BML::redirect("/customize/layer.bml?w=user&journal=$authas"); } if ($POST{'save:theme'}) { my $themeid = $POST{'themeid'}+0; return BML::redirect("/customize/?journal=$u->{'user'}") if $themeid == $style{'theme'}; my $lay = $pub->{$themeid}; return "" if ! $lay and $lay ||= $userlay->{$themeid} and ! $has_cap; return "" if $themeid && ! $lay; $style{'theme'} = $themeid; $implicit_style_create->(); # TODO: conflict resolution. check if there # exists a user layer, and ask user if they want to # override it using the theme exclusively. return BML::redirect("/customize/?journal=$u->{'user'}"); } if ($POST{'save:langcode'}) { my $langcode = $POST{'langcode'}; return BML::redirect("/customize/?journal=$u->{'user'}") if $langcode eq 'custom'; my @langs = LJ::S2::get_layout_langs($pub, $style{'layout'}); my ($i18n, $i18nc); # scan for an i18n user layer foreach (values %$userlay) { last if $_->{'b2lid'} == $style{'layout'} && $_->{'type'} eq 'i18n' && $_->{'langcode'} eq $langcode && ($i18n = $_->{'s2lid'}); } # scan for i18nc public layer and i18n layer if necessary foreach (values %$pub) { last if $i18nc && $i18n; next if ! $i18nc && $_->{'type'} eq 'i18nc' && $_->{'langcode'} eq $langcode && ($i18nc = $_->{'s2lid'}); next if ! $i18n && $_->{'b2lid'} == $style{'layout'} && $_->{'type'} eq 'i18n' && $_->{'langcode'} eq $langcode && ($i18n = $_->{'s2lid'}); } $style{'i18nc'} = $i18nc; $style{'i18n'} = $i18n; $implicit_style_create->(); # TODO: conflict resolution. check if there # exists a user layer, and ask user if they want to # override it using the theme exclusively. return BML::redirect("/customize/?journal=$u->{'user'}"); } # choose style system $ret .= "
"; $ret .= ""; $ret .= "
"; $ret .= LJ::html_select({ 'name' => 'stylesys', 'selected' => $u->{'stylesys'} }, 1, "$ML{'.choose.s1'}", 2, "$ML{'.choose.s2'}"); $ret .= " "; $ret .= "
"; # no more options if they're using S1. if ($u->{'stylesys'} == 1) { $ret .= " "href='$LJ::SITEROOT/modify.bml?authas=$authas'" }); $ret .= " p?>
"; return $ret; } # choose layout my @layouts = map { $_, $pub->{$_}->{'name'} } sort { $pub->{$a}->{'name'} cmp $pub->{$b}->{'name'} } grep { my $tmp = $_; $tmp =~ /^\d+$/ && $pub->{$tmp}->{'type'} eq "layout" && LJ::S2::can_use_layer($u, $pub->{$tmp}->{'uniq'}) && ($_ = $tmp) } keys %$pub; # custom layers can will be shown in the "Custom Layers" and "Disabled Layers" groups # depending on the user's account status. if they don't have the s2styles cap, then # they will have all layers disabled, except for the one they are currently using. my $custom_layer_list = sub { my ($type, $ptype) = @_; my @layers = (); my @user = map { $_, $userlay->{$_}->{'name'} ? $userlay->{$_}->{'name'} : "\#$_" } sort { $userlay->{$a}->{'name'} cmp $userlay->{$b}->{'name'} || $a <=> $b } grep { /^\d+$/ && $userlay->{$_}->{'b2lid'} == $style{$ptype} && $userlay->{$_}->{'type'} eq $type && ($has_cap || $_ == $style{$type}) } keys %$userlay; if (@user) { push @layers, { value => "", text => "--- Custom Layers: ---", disabled => 1 }, @user; } unless ($has_cap) { my @disabled = map { { value => $_, text => $userlay->{$_}->{'name'} ? $userlay->{$_}->{'name'} : "\#$_", disabled => 1 } } sort { $userlay->{$a}->{'name'} cmp $userlay->{$b}->{'name'} || $userlay->{$a}->{'s2lid'} <=> $userlay->{$b}->{'s2lid'} } grep { /^\d+$/ && $userlay->{$_}->{'b2lid'} == $style{$ptype} && $userlay->{$_}->{'type'} eq $type && $_ != $style{$type} } keys %$userlay; if (@disabled) { push @layers, { value => "", text => "--- Disabled Layers: ---", disabled => 1 }, @disabled; } } return @layers; }; # add user/disabled ones push @layouts, $custom_layer_list->('layout', 'core'); $ret .= ""; $ret .= "
"; $ret .= LJ::html_select({ 'name' => 'layoutid', 'selected' => $style{'layout'}, }, @layouts); $ret .= " {'user'}\">$ML{'.previews'}"; $ret .= "
"; # pick other stuff $ret .= ""; $ret .= ""; # langauge my @langs = LJ::S2::get_layout_langs($pub, $style{'layout'}); # they have set a custom i18n layer if ($style{'i18n'} && ($style{'i18nc'} != $style{'i18n'} || ! defined $pub->{$style{'i18n'}})) { push @langs, 'custom', $ML{'.s2.customize.language.custom'}; $langcode = 'custom'; } $ret .= ""; $ret .= "
"; $ret .= LJ::html_select({ 'name' => 'langcode', 'selected' => $langcode, }, 0 => $ML{'.s2.customize.language.default'}, @langs); $ret .= " "; $ret .= "
"; # theme my @themes = LJ::S2::get_layout_themes_select([$pub], $style{'layout'}); # add user/disabled ones push @themes, $custom_layer_list->('theme', 'layout'); $ret .= ""; $ret .= "
"; $ret .= LJ::html_select({ 'name' => 'themeid', 'selected' => $style{'theme'}, }, '0' => $ML{'.s2.customize.themes.default'}, @themes); $ret .= " {'user'}\">$ML{'.previews'}"; $ret .= "
"; # customize $ret .= ""; $ret .= "
"; if ($style{'user'}) { $ret .= LJ::html_submit('action:edituser', $ML{'.s2.customize.settings.edit'}); $ret .= LJ::html_submit('action:deluser', $ML{'.s2.customize.settings.delete'}, { 'onclick' => "return confirm('" . LJ::ejs($ML{'.s2.customize.settings.delete.confirm'}) . "')" }); } else { $ret .= "\n"; } $ret .= "
"; $ret .= ""; $ret .= ""; $ret .= "
$ML{'.s2.advanced.header'}
"; $ret .= $has_cap ? $ML{'.s2.advanced.permitted'} : $ML{'.s2.advanced.denied'}; $ret .= "
$ML{'/manage/links.bml.title'}
$ML{'.s2.related.links.about'}
"; $ret .= "
$ML{'/modify.bml.title'}
$ML{'.s2.related.modify.about'}
"; $ret .= "
$ML{'/editinfo.bml.title'}
$ML{'.s2.related.editinfo.about'}
"; return $ret; } _code?> <=body head<= <=head page?>