Edit Style body<= {'user'}; my $u = LJ::get_authas_user($authas); return LJ::bad_input("You could not be authenticated as the specified user") unless $u; # check styles cap return LJ::bad_input("Your account type doesn't permit you to modify styles.") unless LJ::get_cap($u, "styles"); # get a style object my $styleid = $POST{'styleid'}+0; my $style = LJ::S1::get_style($styleid); return LJ::bad_input("The requested style does not exist.") unless $style; # some static data my @style_opts = ( { 'code' => "is_public", 'title' => 'Public?', 'des' => "Mark this style public if you want other people to be able to use it or copy it." }, { 'code' => "is_embedded", 'title' => 'Embedded?', 'des' => "Is this style designed to be embedded in somebody's homepage? Check if so, otherwise it's a full page style." }, { 'code' => "is_colorfree", 'title' => 'Color Free?', 'des' => "A style is color-free if it does not contain any hard-coded color tags, but only uses the generic color codes listed in the table below." }, ); my @style_transforms = ( { 'trans' => 'lc', 'des' => "Lower case." }, { 'trans' => 'uc', 'des' => "Upper case." }, { 'trans' => 'ue', 'des' => "URL-Encode. Turn spaces to +, and all weird characters to %hh, the hex representation. This is useful for building data files to be used in Flash-4 movies." }, { 'trans' => 'xe', 'des' => "XML-Encode. Makes value acceptable for use in an XML attribute or element. Escapes ampersands, angle brackets, and both types of quotes. Does not however, escape ]]>, so don't use CDATA elements." }, { 'trans' => 'color', 'des' => "A weird transform that handles color codes. See the color code table." }, { 'trans' => 'cons', 'des' => "Access site constants. Currently supported are 'siteroot', 'sitename', and 'img' (the image root). Example use: %%cons:img%%/icon_protected.gif" }, { 'trans' => 'ljuser', 'des' => "Transform the variable as if it were surrounded by <lj user=%%variable%%>. ex: %%ljuser:username%%" }, { 'trans' => 'ljcomm', 'des' => "Transform the variable as if it were surrounded by <lj comm=%%variable%%>. ex: %%ljcomm:username%%" }, { 'trans' => 'userurl', 'des' => 'Takes in a username and transforms it into a link to their journal.' }, ); # construct ide and mode variables my $ide = $POST{'ide'}; my $mode = $POST{'mode'} || 'editstyle'; if ($mode eq 'editstyle') { if ($ide eq 'delete') { $mode = 'delete'; } else { $ide = $ide eq 'v1' ? 'v1' : 'v2'; $mode = 'editstyle'; } } ### start of output my $ret = ""; # pass authas arguments in forms if necessary my $getextra = "?authas=$authas" if $authas ne $remote->{'user'}; # delete confirmation if ($mode eq "delete") { $ret .= "$style->{'styledes'}? If so, press the button below. This will temporarily break your journal if you're using this style, until you select a different style to use. p?>"; $ret .= "
"; $ret .= LJ::html_hidden("mode", "delete_confirm", "styleid", $styleid); $ret .= "

" . LJ::html_submit(undef, "Yes, delete it!") . "

\n"; return $ret; } # process delete if ($mode eq "delete_confirm") { LJ::S1::delete_style($styleid); return "here. p?>"; } # editing a style if ($mode eq "editstyle") { $ret .= "\n"; $ret .= "
"; $ret .= LJ::html_hidden("mode", "savechanges", "styleid", $styleid, "ide", $ide); $ret .= "\n"; $ret .= "\n"; $ret .= "\n"; $ret .= "\n"; $ret .= "\n"; $ret .= "
Style View Type:$LJ::viewinfo{$style->{'type'}}->{'des'} -- $style->{'type'}
Style ID Number:$style->{'styleid'}"; my $extravars = "&nocache=1" if $style->{'opt_cache'} eq "Y"; if ($style->{'type'} eq 'day') { my ($curmday, $curmon, $curyear) = (localtime(time))[3..5]; $extravars .= sprintf("&day=%02d&month=%02d&year=%04d", $curmday, $curmon+1, $curyear+1900); } $ret .= " {'user'}&styleid=$styleid$extravars\">[Preview Current Style] (must save below to see your changes, keep this window open and reload it whenever you save)"; $ret .= "
Style Description:"; $ret .= LJ::html_text({ 'name' => 'styledes', 'value' => $style->{'styledes'}, 'size' => '50', 'maxlength' => '50' }); $ret .= "
Style Options:\n"; foreach my $opt (@style_opts) { $ret .= ""; } $ret .= "
"; $ret .= LJ::html_check({ 'type' => 'check','name' => $opt->{'code'}, 'id' => $opt->{'code'}, 'selected' => $style->{$opt->{'code'}} eq 'Y' }); $ret .= "
$opt->{'des'}
\n"; # color code instructions $ret .= "The following color codes can be used in any variable below that contains HTML: p?>"; $ret .= "

\n"; foreach my $col (@LJ::S1::themecoltypes) { $ret .= "\n"; } $ret .= "
CodeDescription
%%color:$col->[0]%%$col->[1]

\n"; # transform instructions $ret .= "%%monlong%% (March, April, May, etc...) but you don't like that the default has those upper case initial letters. You can apply the lc (lowercase) transform to it: %%lc:monlong%%. Transform are applied in order from the right to the left, so if you went %%a:b:c:d:property%%, d would be applied first. Here are a list of the supported transforms: p?>"; $ret .= "

\n"; foreach (@style_transforms) { $ret .= "\n"; } $ret .= "
TransformDescription
$_->{'trans'}$_->{'des'}

\n"; ### customizable vars section # load variables from file my @vars; LJ::load_objects_from_file("vars.dat", \@vars); # build hash of relevant variables my %var; foreach my $v (sort { $a->{'name'} cmp $b->{'name'} } @vars) { next unless ($v->{'props'}->{'scope'} =~ /\b$style->{'type'}\b/); $var{$v->{'name'}} = $v; } # ide version 2 section if ($ide eq "v2") { # closure to make variable edit fields my $make_edit_fields = sub { my ($self, $vars, $marked, @fields) = @_; foreach my $f (@fields) { next if ($marked->{$f}++); my $prop = $vars->{$f}->{'props'}; $self->($self, $vars, $marked, split(/\s*,\s*/, $prop->{'deps'})); my $des = $prop->{'des'}; $des =~ s/\[var\[(\S+?)\]\]/$1<\/a>/g; $des =~ s/\[view\[(\S+?)\]\]/$1/g; $des =~ s/%%\S+?%%/$&<\/tt>/g; $ret .= "

$f
$des

\n"; if (defined $prop->{'props'}) { $ret .= "

\n"; foreach my $p (@{$prop->{'props'}}) { $p->{'props'}->{'des'} =~ s/\[var\[(\S+?)\]\]/$1<\/a>/g; $p->{'props'}->{'des'} =~ s/\[view\[(\S+?)\]\]/$1/g; $p->{'props'}->{'des'} =~ s/%%\S+?%%/$&<\/tt>/g; $ret .= "\n"; $ret .= "\n"; } $ret .= "
$p->{'name'}$p->{'props'}->{'des'} "; if ($p->{'props'}->{'min'} > 0) { $ret .= "[required]"; } $ret .= "

\n"; } my $editrows = $prop->{'editrows'} || 5; my $editcols = $prop->{'editcols'} || 70; $ret .= "

"; if ($vars->{$f}->{'props'}->{'override'} eq "only") { $ret .= "Override only. Only end-users may override this. You cannot define it in a style."; } else { my %stylevar = (); LJ::parse_vars(\$style->{'formatdata'}, \%stylevar); if ($editrows == 1) { $ret .= LJ::html_text({ 'name' => "var:$f", 'value' => $stylevar{$f}, 'size' => $editcols, 'maxlength' => '255' }); } else { $ret .= LJ::html_textarea({ 'name' => "var:$f", 'value' => $stylevar{$f}, 'wrap' => 'soft', 'rows' => $editrows, 'cols' => $editcols, 'style' => 'width: 100%;' }); } } $ret .= "

"; $ret .= "\n"; } }; # end closure # display edit form $ret .= ""; my %mark = (); $make_edit_fields->($make_edit_fields, \%var, \%mark, uc("$style->{'type'}_PAGE"), keys %var); } # ide version 1 section if ($ide eq "v1") { # show a big textarea for them to use $ret .= "

Style Variables: (reference information)

\n"; $ret .= LJ::html_textarea({ 'name' => 'formatdata', 'value' => $style->{'formatdata'}, 'rows' => '30', 'cols' => '80', 'wrap' => 'off', 'style' => 'width: 100%;' }) . "\n"; } # save button $ret .= "

" . LJ::html_submit(undef, 'Save Style') . "

\n"; $ret .= "
"; # convenience links at bottom if ($ide eq 'v2') { $ret .= " "; } return $ret; } # save changes from a previous edit form if ($mode eq "savechanges") { my $formatdata; # process form from ide v1 if ($ide eq "v1") { $POST{'formatdata'} =~ s/\r//; # carriage returns shouldn't be necessary $formatdata = $POST{'formatdata'}; # process form from ide v2 } elsif ($ide eq "v2") { $formatdata = ""; foreach (grep { /^var:.+/ } keys %POST) { /^var:(.+)$/; my ($key, $var) = ($&, $1); $POST{$key} =~ s/\r//; # carriage returns shouldn't be necessary if ($POST{$key} =~ /\n/) { $formatdata .= "$var<=\n$POST{$key}\n<=$var\n\n"; } else { $formatdata .= "$var=>$POST{$key}\n\n"; } } } # update style LJ::S1::update_style($styleid, { 'formatdata' => $formatdata, 'styledes' => $POST{'styledes'}, map { $_->{'code'} => $POST{$_->{'code'}} ? "Y" : "N" } @style_opts }); my $extravars; if ($style->{'type'} eq 'day') { my ($curmday, $curmon, $curyear) = (localtime(time))[3..5]; $extravars = sprintf("&day=%02d&month=%02d&year=%04d", $curmday, $curmon+1, $curyear+1900); } # all good return "{'user'}" . "&styleid=$styleid$extravars\">here. p?>"; } # this should never happen return LJ::bad_input("Unknown mode: $mode."); } _code?> <=body page?> link: htdocs/styles/edit.bml, htdocs/developer/views.bml, htdocs/customview.cgi file: htdocs/vars.dat post: htdocs/styles/edit_do.bml _c?>