head<=
<=head
body<=
{'user'};
my $u = LJ::get_authas_user($authas);
return LJ::bad_input("You could not be authenticated as the specified user.")
unless $u;
return $LJ::MSG_READONLY_USER if LJ::get_cap($remote, "readonly");
### user is now authenticated ###
my $dbr = LJ::get_db_reader();
my $sth;
my $capstyles = LJ::get_cap($u, "styles");
LJ::load_user_props($u, "opt_usesharedpic",
"s1_lastn_style", "s1_calendar_style",
"s1_day_style", "s1_friends_style",
"stylesys", "journaldomain");
# if a POST, update their info
if (LJ::did_post()) {
return "" unless LJ::text_in(\%POST);
# database error reporting
my $dberr = sub {
return "@_[0] p?>";
};
my $dbh = LJ::get_db_writer();
# setup what we're gonna update in the user table:
my %update = ();
# what userprops we'll be setting.
my %uprop;
# journal domains
my $dom_cap = LJ::get_cap($u, 'userdomain');
if ((exists $POST{'journaldomain'} && $u->{'journaldomain'} ne $POST{'journaldomain'}) ||
(! $dom_cap && $POST{'journaldomain_del'}))
{
$POST{'journaldomain'} =~ s!^(http://)?(www\.)?!!;
my $dom = lc($POST{'journaldomain'});
if (($dom_cap && ! $dom) || (! $dom_cap && $POST{'journaldomain_del'})) {
$dbh->do("DELETE FROM domains WHERE userid=?", undef, $u->{'userid'});
} else {
$dbh->do("INSERT INTO domains VALUES (?, ?)", undef, $dom, $u->{'userid'});
if ($dbh->err) {
my $otherid = $dbh->selectrow_array("SELECT userid FROM domains WHERE domain=?",
undef, $dom);
return LJ::bad_input($ML{'.error.dupdomainalias'}) if $otherid != $u->{'userid'};
}
if ($u->{'journaldomain'}) {
$dbh->do("DELETE FROM domains WHERE userid=? AND domain <> ?",
undef, $u->{'userid'}, $dom);
}
}
# set journaldomain prop if it's been changed
$uprop{'journaldomain'} = $dom
unless $POST{'journaldomain'} eq $u->{'journaldomain'};
}
# validate moodthemeid
# mood theme, make sure they're allowed to use it
my $moodthemeid = $POST{'moodthemeid'}+0;
if ($moodthemeid) {
my ($mownerid, $mpublic) = $dbr->selectrow_array("SELECT ownerid, is_public FROM moodthemes ".
"WHERE moodthemeid=?", undef, $moodthemeid);
$moodthemeid = 0 unless $mpublic eq 'Y' || $mownerid == $u->{'userid'};
}
$update{'moodthemeid'} = $moodthemeid;
$update{'opt_forcemoodtheme'} = $POST{'opt_forcemoodtheme'} ? "Y" : "N";
# all of these options should only be processed for S1 users
if ($u->{'stylesys'} != 2) {
# color themes
$update{'themeid'} = $POST{'themetype'} eq "custom" ? 0 : $POST{'themeid'};
if ($POST{'themetype'} eq "custom") {
my $dig = Digest::MD5::md5_hex(join(",", map { $POST{"theme_cust:$_"} }
map { $_->[0] } @LJ::S1::themecoltypes));
if ($dig ne $POST{'themecolors_dig'}) {
my %cols;
foreach my $col (@LJ::S1::themecoltypes) {
my $val = $POST{"theme_cust:$col->[0]"};
next if length($val) > 20;
next unless ($val =~ /^\#[a-f0-9]{6,6}$/i ||
$val !~ /[^\s\w]/);
$cols{$col->[0]} = $val;
}
return $ML{"error.nodb"} unless $u->writer;
$u->do("INSERT IGNORE INTO s1usercache (userid) VALUES (?)", undef, $u->{'userid'});
$u->do("UPDATE s1usercache SET color_stor=? WHERE userid=?", undef,
Storable::nfreeze(\%cols), $u->{'userid'});
LJ::MemCache::delete([$u->{'userid'}, "s1uc:$u->{'userid'}"]);
$dbh->do("DELETE FROM themecustom WHERE user=?", undef, $u->{'user'})
if $dbh->selectrow_array("SELECT user FROM themecustom ".
"WHERE user=? LIMIT 1", undef, $u->{'user'});
}
}
# update 'overrides' table
if ($POST{'overrides'} !~ /\S/) {
LJ::S1::clear_overrides($u);
$update{'useoverrides'} = "N";
} else {
my $oldoverrides = "";
if ($u->{'useoverrides'} eq "Y") {
$oldoverrides = LJ::S1::get_overrides($u);
}
# This allows users to keep their current illegal overrides,
# but they may not create new ones nor edit the ones they already have.
# They may only delete or keep illegal overrides.
my %overrides = ();
my %newoverrides = ();
LJ::parse_vars(\$oldoverrides,\%overrides);
LJ::parse_vars(\$POST{'overrides'},\%newoverrides);
# head overrides should only have valid head elements in them
foreach my $a (qw(GLOBAL LASTN FRIENDS CALENDAR DAY)) {
my $sec = "${a}_HEAD";
next unless $newoverrides{$sec} ne $overrides{$sec};
my $testtag = sub {
my $tag = lc(shift);
return "<$tag" if ($tag eq "title" || $tag eq "base" ||
$tag eq "style" || $tag eq "link" ||
$tag eq "meta" || $tag eq "xx");
return "($1)/eig;
$newoverrides{$sec} =~ s/\<\/head/\<\/xx-head/ig;
}
# load all the properties to see which ones are overridable
my @vars;
LJ::load_objects_from_file("vars.dat", \@vars);
foreach my $v (@vars) {
my $ov = $v->{'props'}->{'override'};
if ($ov eq "yes" || $ov eq "only" || $capstyles) {
my $name = $v->{'name'};
if (defined $newoverrides{$name}) {
$overrides{$name} = $newoverrides{$name};
}
}
}
# make the new override code we'll put in the database
my $overr='';
foreach (keys %overrides) {
if ($newoverrides{$_}) {
if ($overrides{$_} =~ /\n/) {
$overr .= "$_<=\n".$overrides{$_}."\n<=$_\n\n";
} else {
$overr .= "$_=>".$overrides{$_}."\n\n";
}
}
}
# no value, delete overrides
if ($overr !~ /\S/) {
LJ::S1::clear_overrides($u);
$update{'useoverrides'} = "N";
# have a value, update overrides
} else {
LJ::S1::save_overrides($u, $overr);
$update{'useoverrides'} = "Y";
}
}
# friends view shared pic option for s1
$uprop{'opt_usesharedpic'} = $POST{'opt_usesharedpic'} ? "1" : "0";
# set all the styles
{
my @picked = ();
foreach my $view (@LJ::views) {
my $sid = $POST{"s1_${view}_style"}+0;
if ($sid) {
$uprop{"s1_${view}_style"} = $sid;
push @picked, $sid;
}
}
# verify they haven't forged the style numbers
unless ($capstyles) {
# just load whole structure since it should be cached
my $pubstyles = LJ::S1::get_public_styles();
my $userstyles = LJ::S1::get_user_styles($u);
foreach (@picked) {
my $type = $userstyles->{$_}->{'type'};
return LJ::bad_input($ML{'.error.stylenotavailable'})
unless exists $pubstyles->{$_} ||
exists $userstyles->{$_} &&
($capstyles || $_ == $u->{"s1_${type}_style"});
}
}
}
}
# update 'user' table
foreach (keys %update) {
delete $update{$_} if $u->{$_} eq $update{$_};
}
LJ::update_user($u, \%update) if %update;
# change any of the userprops ?
foreach my $uprop (keys %uprop) {
next if $POST{$uprop} eq $u->{$uprop};
LJ::set_userprop($u, $uprop, $uprop{$uprop});
}
# tell the user all is well
return " LJ::journal_base($u) . "/" })." p?>";
}
# not submitting a post, show edit form
my $ret;
# user switcher
$ret .= "\n\n";
### journal style
$ret .= "\n\n\n";
###
### LAYOUT OPTIONS
###
$ret .= "\n";
return $ret;
}
_code?>
<=body
page?>
link: htdocs/moodlist.bml, htdocs/developer/index.bml, htdocs/developer/varlist.bml, htdocs/styles/create.bml
post: htdocs/modify_do.bml
_c?>