body<= " unless $remote; my $authas = $GET{'authas'} || $remote->{'user'}; my $u = LJ::get_authas_user($authas); return LJ::bad_input($ML{'error.authinvalid'}) unless $u; unless (LJ::get_cap($u, "styles")) { return LJ::bad_input($ML{'.error.accounttype'}); } # error check submission return LJ::bad_input($ML{'.error.invalidview'}) unless $POST{'type'} && defined $LJ::viewinfo{$POST{'type'}}; my $view = $POST{'type'}; my $base = ""; my $baseid = $POST{"base_$view"} || $POST{"basenum_$view"}; if ($baseid) { my $rec = LJ::S1::get_style($baseid); return LJ::bad_input(BML::ml('.error.stylenotfound',{ 'baseid' => $baseid, })) unless $rec && $rec->{'type'} eq $view; return LJ::bad_input(BML::ml('.error.stylenotpublic',{ 'baseid' => $baseid, })) unless $rec->{'is_public'} eq "Y" || $rec->{'user'} eq $u->{'user'}; # they're allowed to base on this style $base = $rec->{'formatdata'}; } ### start of output my $ret = ""; my $des = "$u->{'user'}-$view-new"; # let's see if they accidentally double-clicked: my $double_clicked = 0; my $new_id = 0; my $oldstyle = LJ::S1::check_dup_style($u, $view, $des); # closure to show edit form my $editform = sub { my $getextra = "?authas=$authas" if $u->{'user'} ne $remote->{'user'}; return "
\n" . LJ::html_hidden('mode', 'editstyle', 'styleid', $_[0]) . "\n" . LJ::html_submit(undef, $ML{'.editstyle'}) . "
\n"; }; if ($oldstyle) { if ($oldstyle->{'formatdata'} eq $base) { # the user double-clicked $double_clicked = 1; $new_id = $oldstyle->{'styleid'}; } else { $ret .= "" . " $des, 'view' => $view, }) . " p?>"; $ret .= $editform->($oldstyle->{'styleid'}); return $ret; } } unless ($double_clicked) { $new_id = LJ::S1::create_style($u, { 'styledes' => $des, 'type' => $view, 'formatdata' => $base }); return "" unless defined $new_id; } $ret .= " $des, }) . " p?>\n"; $ret .= $editform->($new_id); return $ret; } _code?> <=body page?> post: htdocs/styles/edit_do.bml _c?>