{ 'des'=>'Personal Information: name, biography, friend groups\' names', 'browse'=>\&browse_personals, 'save'=>\&save_personals, }, 'interests'=>{ 'des'=>'Personal information: interests', 'browse'=>\&browse_interests, 'save'=>\&save_interests, }, 'keywords'=>{ 'des'=>'Picture keywords', 'browse'=>\&browse_pickwd, 'save'=>\&save_pickwd, }, 'memories'=>{ 'des'=>'Text of memory descriptions', 'browse'=>\&browse_memories, 'save'=>\&save_memories, }, 'polls'=>{ 'des'=>'Text of questions/answers for polls you created', 'browse'=>\&browse_polls, 'save'=>\&save_polls, }, 'styles'=>{ 'des'=>'Text of styles and overrides belonging to you', 'browse'=>\&browse_styles, 'save'=>\&save_styles, }, ); unless ($LJ::UNICODE) { $body .= ""; return; } my $remote = LJ::get_remote(); unless ($remote) { $body .= "login. p?>"; return; } my $authas = $GET{'authas'} || $remote->{'user'}; my $u = LJ::get_authas_user($authas); unless ($u) { $body .= LJ::bad_input($ML{'error.invalidauth'}); return; } # extra arguments for get requests my $getextra = $authas ne $remote->{'user'} ? "?authas=$authas" : ''; my $getextra_amp = $getextra ? "&authas=$authas" : ''; my $dbcm = LJ::get_cluster_master($u); my $dbh = LJ::get_db_writer(); my $sth; # avva, kinda improper usage of load_codes, but works i guess -brad LJ::load_codes({ "encname" => \%LJ::CACHE_ENCNAMES } ) unless %LJ::CACHE_ENCNAMES; LJ::load_codes({ "encoding" => \%LJ::CACHE_ENCODINGS } ) unless %LJ::CACHE_ENCODINGS; # check arguments. There are three: mode, area, encid my $mode = $POST{'mode'} || $GET{'mode'}; my $area = $POST{'area'} || $GET{'area'}; my $encid = ($POST{'encid'} || $GET{'encid'}) + 0; # authas switcher form $body .= "
\n"; $body .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'} }) . "\n"; $body .= "
\n\n"; $mode = 'overview' unless defined $mode; if ( ($mode =~ m/^save.*/) && !$encid) { $body .= ""; return; } if ($mode eq 'overview') { $body .= ""; $body .= ""; $body .= "Personal Info page. However, various types of miscellaneous information, such as picture keywords, your name, names of your friend groups, your interests, etc. must be explicitly converted. And this is the purpose of this page. p?>"; $body .= "If your journal is written in English, you always use English for communication in LiveJournal and never use even accent symbols of other West European languages, you do not need to use this page. p?>"; $body .= ""; if ($u->{'oldenc'}) { $body .= "$LJ::CACHE_ENCNAMES{$u->{'oldenc'}} on your personal info page. You can choose to mass-convert all your miscellaneous information to UTF-8 under the assumption that it is all stored in this encoding. Do not choose this option if you might have used some other encoding in the past (anywhere besides your entries and comments) while using LiveJournal. If you are not sure, use the Conversion by Area option below. p?>"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= ""; $body .= " p?>"; } $body .= ""; $body .= ""; unless ($encid) { $encid = ($u->{'oldenc'} ? $u->{'oldenc'} : '1'); }; foreach (@areanames) { $body .= "$areas{$_}->{'des'} p?>"; } } if ($mode eq 'browse') { # need to display the data in given encoding, if it is not UTF-8 $body .= "$areas{$area}->{'des'}: p?>"; my $browse = $areas{$area}->{'browse'}; my ($valid, $disp) = $browse->($u, $encid); if ($valid && !defined($GET{'forceview'})) { $body .= ""; $body .= "return to the area list or force the information to be shown anyway. p?>"; } else { $body .= ""; $body .= "$LJ::CACHE_ENCNAMES{$encid}. If it appears correct, press Save to convert and store it in the database. If some or all characters are displayed corrupted, you probably should choose another encoding from the list below and press Browse to see it displayed in that encoding. p?>"; $body .= ""; $body .= $disp; $body .= ""; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= ""; $body .= " p?>"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= LJ::html_select({'name'=>'encid', 'selected'=>$encid}, %LJ::CACHE_ENCNAMES); $body .= ""; $body .= " p?>"; $body .= "go back to the area list. p?>"; }; } if ($mode eq 'save') { $body .= "

$areas{$area}->{'des'}

$LJ::CACHE_ENCNAMES{$encid}. p?>"; $body .= "$LJ::CACHE_ENCNAMES{$encid} (the technical name of which is $LJ::CACHE_ENCODINGS{$encid}). If you chose a wrong encoding, the text will display incorrectly after the conversion. p?>"; $body .= ""; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= ""; $body .= ""; $body .= "
\n"; $body .= ""; $body .= "
p?>"; } if ($mode eq 'saveall') { $body .= "$LJ::CACHE_ENCNAMES{$encid}. p?>"; $body .= "$LJ::CACHE_ENCNAMES{$encid} (the technical name of which is $LJ::CACHE_ENCODINGS{$encid}). If you chose a wrong encoding, the text will display incorrectly after the conversion. p?>"; $body .= ""; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= ""; $body .= ""; $body .= "
\n"; $body .= ""; $body .= "
p?>"; } if ($mode eq 'save_do') { $body .= "$areas{$area}->{'des'}... p?>"; my $save = $areas{$area}->{'save'}; my ($success, $message) = $save->($u, $encid); if ($success) { $body .= ""; $body .= $message; } else { $body .= ""; } } if ($mode eq 'saveall_do') { $body .= ""; foreach (@areanames) { $body .= "$areas{$_}->{'des'}... p?>"; my $save = $areas{$_}->{'save'}; my ($success, $message) = $save->($u, $encid); if ($success) { $body .= ""; $body .= $message; } else { $body .= ""; } } } return; sub browse_personals { my ($u, $encid) = @_; my $ret = ""; my ($name, $bio, $groups); LJ::load_user_props($u, qw(url urlname)); $name = $u->{'name'}; if ($u->{'has_bio'} eq "Y") { $bio = $dbcm->selectrow_array("SELECT bio FROM userbio WHERE userid=$u->{'userid'}"); }; $groups = ""; $sth = $dbh->prepare("SELECT groupname FROM friendgroup WHERE userid=$u->{'userid'}"); $sth->execute; while (($_) = $sth->fetchrow_array) { $groups .= $_ . ' '; }; my $valid = LJ::is_utf8($name . ' ' . $u->{'url'} . ' ' . $u->{'urlname'} . ' ' . $bio . ' ' . $groups); convert(\$name, $encid); convert(\$u->{'url'}, $encid); convert(\$u->{'urlname'}, $encid); convert(\$bio, $encid) if $bio; convert(\$groups, $encid); $ret = "Name: $name
"; $ret .= "Website URL: $u->{'url'}
"; $ret .= "URL name: $u->{'urlname'}
"; $ret .= "Bio: $bio
" if $bio; $ret .= "Names of friend groups: $groups
"; return $valid, $ret; } sub browse_interests { my ($u, $encid) = @_; my $ret = ""; my $interests = ""; my $sth = $dbh->prepare("SELECT i.interest FROM interests i, userinterests ui WHERE i.intid=ui.intid AND ui.userid=$u->{'userid'}"); $sth->execute; while($_ = $sth->fetchrow_array) { $interests .= $_ . ' '; } my $valid = LJ::is_utf8($interests); convert(\$interests, $encid); $ret = "Interests: $interests
"; return $valid, $ret; } sub browse_pickwd { my ($u, $encid) = @_; my $ret = ""; my $kwds = ""; my $sth = $dbh->prepare("SELECT k.keyword FROM keywords k, userpicmap up WHERE k.kwid=up.kwid AND up.userid=$u->{'userid'}"); $sth->execute; while($_ = $sth->fetchrow_array) { $kwds .= $_ . ' '; } my $valid = LJ::is_utf8($kwds); convert(\$kwds, $encid); $ret = "Picture keywords: $kwds
"; return $valid, $ret; } sub browse_polls { my ($u, $encid) = @_; my $sth; my $ret = ""; my $valid = 1; # first get some of the pollids of this user my @pollids; $sth = $dbh->prepare("SELECT pollid FROM poll WHERE posterid=$u->{'userid'} ". "LIMIT 50"); $sth->execute; while (my ($pid) = $sth->fetchrow_array) { push @pollids, $pid; } unless (@pollids) { $ret .= "You have no polls defined."; return 1, $ret; } my $pids = join(',', @pollids); my @strings; my $limit = 5; my $nlimit = 10; $sth = $dbh->prepare("SELECT name FROM poll WHERE pollid IN ($pids)"); $sth->execute; while (my ($name) = $sth->fetchrow_array) { push @strings, $name if LJ::is_utf8($name) and --$limit >=0; push @strings, $name if !LJ::is_utf8($name) and --$nlimit >=0; $valid = 0 unless LJ::is_utf8($name); } $ret .= "Sample poll names: p?>"; } $ret .= "p?>"; $limit = 5; $nlimit = 10; @strings = (); $sth = $dbh->prepare("SELECT qtext FROM pollquestion WHERE pollid IN ($pids)"); $sth->execute; while (my ($question) = $sth->fetchrow_array) { push @strings, $question if LJ::is_utf8($question) and --$limit >=0; push @strings, $question if !LJ::is_utf8($question) and --$nlimit >=0; $valid = 0 unless LJ::is_utf8($question); } $ret .= "Sample poll questions: p?>"; } $ret .= "p?>"; $limit = 5; $nlimit = 10; @strings = (); $sth = $dbh->prepare("SELECT item FROM pollitem WHERE pollid IN ($pids)"); $sth->execute; while (my ($item) = $sth->fetchrow_array) { push @strings, $item if LJ::is_utf8($item) and --$limit >=0; push @strings, $item if !LJ::is_utf8($item) and --$nlimit >=0; $valid = 0 unless LJ::is_utf8($item); } $ret .= "Sample poll answer choices: p?>"; } $ret .= "p?>"; $limit = 5; $nlimit = 10; @strings = (); $sth = $dbh->prepare("SELECT value FROM pollresult WHERE pollid IN ($pids)"); $sth->execute; while (my ($res) = $sth->fetchrow_array) { push @strings, $res if LJ::is_utf8($res) and --$limit >=0; push @strings, $res if !LJ::is_utf8($res) and --$nlimit >=0; $valid = 0 unless LJ::is_utf8($res); } $ret .= "Sample poll answers: p?>"; } $ret .= "p?>"; return $valid, $ret; } sub browse_styles { my ($u, $encid) = @_; my $ret = ""; my $anystyles = 0; my $valid = 1; my $sth = $dbh->prepare("SELECT styleid, styledes, formatdata FROM style WHERE user=?"); $sth->execute($u->{'user'}); while (my ($styleid, $styledes, $fdata) = $sth->fetchrow_array) { $anystyles = 1; $valid = 0 unless LJ::is_utf8($styledes) && LJ::is_utf8($fdata); my $utfdata = LJ::is_utf8($fdata); convert(\$styledes, $encid); convert(\$fdata, $encid); $ret .= "Style number: $styleid
"; $ret .= "Description: $styledes
"; if ($utfdata) { $ret .= "Format data: valid UTF-8
"; } else { $ret .= "Format data: contains non-Unicode characters (too large to display)
"; } $ret .= "p?>"; } unless ($anystyles) { $ret .= ""; } my ($overrides) = $dbh->selectrow_array("SELECT override FROM overrides WHERE user=?", undef, $u->{'user'}); if ($overrides) { $valid = 0 unless LJ::is_utf8($overrides); convert(\$overrides, $encid); $ret .= ""; $ret .= ""; } else { $ret .= ""; } return $valid, $ret; } sub browse_memories { my ($u, $encid) = @_; my $ret = ""; my $valid = 1; $ret .= ""; $ret .= "{des}; $valid = 0 unless LJ::is_utf8($des); convert(\$des, $encid); $ret .= $des . "
" if --$limit >= 0; } $ret .= " p?>"; return $valid, $ret; } sub save_personals { my ($u, $encid) = @_; my $success = 1; my $message = ""; my $sth; my ($name, $bio, $groups); my $userid = $u->{'userid'}; # convert name $name = $u->{'name'}; unless (LJ::is_utf8($name)) { convert(\$name, $encid); LJ::update_user($userid, { name => $name }); $message .= ""; } # convert url/urlname LJ::load_user_props($u, qw(url urlname)); foreach my $prop (qw(url urlname)) { unless(LJ::is_utf8($u->{$prop})) { convert(\$u->{$prop}, $encid); LJ::set_userprop($u->{'userid'}, $prop, $u->{$prop}); $message .= ""; } } # convert bio if ($u->{'has_bio'} eq "Y") { $bio = $dbcm->selectrow_array("SELECT bio FROM userbio WHERE userid=$userid"); unless (LJ::is_utf8($bio)) { convert(\$bio, $encid); $u->do("UPDATE userbio SET bio=? WHERE userid=$userid", undef, $bio); if ($u->err) { return 0, "Database error: " . $u->errstr; } LJ::MemCache::delete([$userid, "bio:$userid"]); $message .= ""; } } # convert groups $groups = {}; $sth = $dbh->prepare("SELECT groupnum, groupname FROM friendgroup WHERE userid=$userid ORDER BY sortorder"); $sth->execute; if ($dbh->err) { return 0, ("Database error: " . $dbh->errstr); } while ($_ = $sth->fetchrow_hashref) { $groups->{$_->{'groupnum'}} = $_->{'groupname'}; } my $converted_groups = 0; foreach (keys %$groups) { unless(LJ::is_utf8($groups->{$_})) { my $name = $groups->{$_}; convert(\$name, $encid); $dbh->do("UPDATE friendgroup SET groupname=? WHERE userid=$userid AND groupnum=$_", undef, $name); if ($dbh->err) { return 0, "Database error: $dbh->errstr"; } $converted_groups = 1; } } if ($converted_groups) { $message .= ""; } return $success, $message; } sub save_interests { my ($u, $encid) = @_; my $success = 1; my $message = ""; my $sth; $sth = $dbh->prepare("SELECT i.interest, i.intid FROM interests i, userinterests ui ". "WHERE i.intid=ui.intid AND ui.userid=$u->{'userid'}"); $sth->execute; my %interests = (); while ($_ = $sth->fetchrow_hashref) { $interests{$_->{'interest'}} = $_->{'intid'}; } my @ints; my $changed = 0; foreach(keys %interests) { unless (LJ::is_utf8($_)) { convert(\$_, $encid); $changed = 1; } push @ints, $_; } if ($changed) { LJ::set_interests($u, \%interests, \@ints); } $message = "Converted interests" if $changed; return 1, $message; } sub save_pickwd { my ($u, $encid) = @_; my $success = 1; my $message = ""; my $sth; my $userid = $u->{'userid'}; my %kwds; my $sth = $dbh->prepare("SELECT k.keyword, k.kwid FROM keywords k, userpicmap up ". "WHERE k.kwid=up.kwid AND up.userid=$userid"); $sth->execute; while($_ = $sth->fetchrow_hashref) { $kwds{$_->{'keyword'}} = $_->{'kwid'}; } my $changed = 0; foreach my $keyword (keys %kwds) { next if LJ::is_utf8($keyword); $changed = 1; my $kw = $keyword; convert(\$kw, $encid); my $newid = LJ::get_keyword_id($kw); $dbh->do("UPDATE userpicmap SET kwid=$newid WHERE userid=$userid AND kwid=$kwds{$keyword}"); } if ($changed) { $message = ""; } return 1, $message; } sub save_polls { my ($u, $encid) = @_; my $success = 1; my $message = ""; my $sth; my $changed = 0; # convert poll names my @pollids; $sth = $dbh->prepare("SELECT pollid, name FROM poll WHERE posterid=$u->{'userid'}"); $sth->execute; while (my ($pid,$name) = $sth->fetchrow_array) { push @pollids, $pid; next if LJ::is_utf8($name); convert(\$name, $encid); my $qname = $dbh->quote($name); $dbh->do("UPDATE poll SET name=$qname WHERE pollid=$pid"); $changed = 1; } if ($changed) { $message .= ""; } my $pids = join(',', @pollids); # convert poll questions $changed = 0; $sth = $dbh->prepare("SELECT pollid, pollqid, qtext FROM pollquestion WHERE pollid IN ($pids)"); $sth->execute; while (my ($pid, $pqid, $text) = $sth->fetchrow_array) { next if LJ::is_utf8($text); convert(\$text, $encid); my $qtext = $dbh->quote($text); $dbh->do("UPDATE pollquestion SET qtext=$qtext WHERE pollid=$pid AND pollqid=$pqid"); $changed = 1; } if ($changed) { $message .= ""; } # convert poll items $changed = 0; $sth = $dbh->prepare("SELECT pollid, pollqid, pollitid, item FROM pollitem WHERE pollid IN ($pids)"); $sth->execute; while (my ($pid, $pqid, $pitid, $item) = $sth->fetchrow_array) { next if LJ::is_utf8($item); convert(\$item, $encid); my $qitem = $dbh->quote($item); $dbh->do("UPDATE pollitem SET item=$qitem WHERE pollid=$pid AND pollqid=$pqid AND pollitid=$pitid"); $changed = 1; } if ($changed) { $message .= ""; } # convert poll results $changed = 0; $sth = $dbh->prepare("SELECT pollid, pollqid, userid, value FROM pollresult WHERE pollid IN ($pids)"); $sth->execute; while (my ($pid, $pqid, $userid, $res) = $sth->fetchrow_array) { next if LJ::is_utf8($res); convert(\$res, $encid); my $qres = $dbh->quote($res); $dbh->do("UPDATE pollresult SET value=$qres WHERE pollid=$pid AND pollqid=$pqid AND userid=$userid"); $changed = 1; } if ($changed) { $message .= ""; } return 1, $message; } sub save_styles { my ($u, $encid) = @_; my $success = 1; my $message = ""; my $sth; my $changed = 0; my $quser = $dbh->quote($u->{'user'}); my $sth = $dbh->prepare("SELECT styleid, styledes, formatdata FROM style WHERE user=$quser"); $sth->execute; while (my ($styleid, $styledes, $fdata) = $sth->fetchrow_array) { next if LJ::is_utf8($styledes) && LJ::is_utf8($fdata); convert(\$styledes, $encid); convert(\$fdata, $encid); my $newdes = $dbh->quote($styledes); my $newdata = $dbh->quote($fdata); $dbh->do("UPDATE style SET styledes=$newdes, formatdata=$newdata WHERE styleid=$styleid"); $changed =1; } if ($changed) { $message .= ""; } my ($overrides) = $dbh->selectrow_array("SELECT override FROM overrides WHERE user=$quser"); if ($overrides && !LJ::is_utf8($overrides)) { convert(\$overrides, $encid); my $qoverrides = $dbh->quote($overrides); $dbh->do("UPDATE overrides SET override=$qoverrides WHERE user=$quser"); $message .= ""; } return 1, $message; } sub save_memories { my ($u, $encid) = @_; my $success = 1; my $message = ""; my $changed = 0; my $userid = $u->{'userid'}; my $keywords = LJ::Memories::get_keywords($u); my %kwds = ( map { $keywords->{$_} => $_ } keys %{$keywords || {}} ); foreach my $keyword (keys %kwds) { next if LJ::is_utf8($keyword); $changed = 1; my $kw = $keyword; convert(\$kw, $encid); my $newid = LJ::get_keyword_id($u, $kw); # not an API because this is the only place this happens, and it's very rare if ($u->{dversion} > 5) { $u->do("UPDATE memkeyword2 SET kwid = ? WHERE userid = ? kwid = ?", undef, $newid, $u->{userid}, $kwds{$keyword}); } else { $dbh->do("UPDATE memkeyword SET kwid=$newid WHERE kwid=$kwds{$keyword}"); } } if ($changed) { $message .= ""; } # now the memory descriptions $changed = 0; my $memories = LJ::Memories::get_by_user($u); foreach my $memory (values %{$memories || {}}) { my $des = $memory->{des}; next if LJ::is_utf8($des); $changed = 1; convert(\$des, $encid); LJ::Memories::update_memory($u, $memory->{memid}, { des => $des }); } if ($changed) { $message .= ""; } return 1, $message; } sub convert { my ($rtext, $encid) = @_; if ($encid && !LJ::is_utf8($$rtext)) { my $enc = $LJ::CACHE_ENCODINGS{$encid}; unless (lc($enc) eq "utf-8") { $$rtext = Unicode::MapUTF8::to_utf8({-string=>$$rtext, -charset=>$enc}); } LJ::text_out($rtext); } } } _code?> body=> page?>