PhonePost transcription body<= {userid} == $u->{userid}; my $bid = $dppid >> 8; my $ppe = LJ::PhonePost::get_phonepost_entry($u, $bid); return "Invalid phone post entry." unless $ppe && $ppe->{jitemid} && $ppe->{anum} == $dppid % 256; # check security of item my $logrow = LJ::get_log2_row($u, $ppe->{jitemid}); return "Invalid phone post entry. (Phone post exists, entry has been deleted.)" unless $logrow; unless ($logrow->{security} eq "public") { my $remote = LJ::get_remote(); return "Access denied." unless LJ::can_view($remote, $logrow); } my $jlink = LJ::item_link($u, $logrow->{jitemid}, $logrow->{anum}); my $may_trans = LJ::PhonePost::may_transcribe($u, $remote); return "Database unavailable." unless $u->writer; my @trans_log; my $max_revid = 0; my $sth = $u->prepare("SELECT revid,posterid,posttime,subject,body " . "FROM phoneposttrans WHERE journalid=? AND blobid=?"); $sth->execute($u->{userid}, $bid); while (my $r = $sth->fetchrow_hashref) { push @trans_log, $r; # Once the owner has transcribed, no one else is allowed to. $may_trans = 0 if $r->{posterid} == $u->{userid} && !$is_owner; # Everyone but the owner can only transcribe once. $may_trans = 0 if $remote && $remote->{userid} != $u->{userid} && $r->{posterid} == $remote->{userid}; $max_revid = $r->{revid} > $max_revid ? $r->{revid} : $max_revid; } @trans_log = sort { $b->{revid} <=> $a->{revid} } @trans_log; # The last revision 'slot' is reserved for the owner. $may_trans = 0 if $max_revid >= $MAX_REVS - 1 && !$is_owner; # Save new revision. my $midair; if (LJ::did_post() && $may_trans) { # Sanity check the rev id, make sure someone isn't faking it. my $revid = $POST{revid} + 0; my $new_revid = $max_revid + 1; return "Invalid revision ID." unless $revid >= 1 && $revid <= $new_revid && $revid <= $MAX_REVS; return "Last revision reserved for owner." if $revid == $MAX_REVS && !$is_owner; my $body = LJ::trim($POST{body}); my $subject = LJ::trim($POST{subj}); return LJ::bad_input('Empty transcription') unless $body =~ /\S/; return LJ::bad_input('Invalid encoding') unless LJ::is_utf8($body) && LJ::is_utf8($subject); return LJ::bad_input('Subject too long.') if length($subject) > 200; return LJ::bad_input('Body too long.') if length($body) > 4096; my $verb = 'INSERT'; $verb = 'REPLACE' if $revid == $MAX_REVS && $is_owner; my $rv = $u->do("$verb IGNORE INTO phoneposttrans SET " . "revid=?, posterid=?, posttime=UNIX_TIMESTAMP(), subject=?, body=?, " . "journalid=?, blobid=?", undef, $new_revid, $remote->{userid}, $subject, $body, $u->{userid}, $bid); # Duplicate revision numbers. Force user to review. $midair = $new_revid unless $rv > 0; my $newr = { 'revid'=>$new_revid, 'posterid'=>$remote->{userid}, 'subject'=>$subject, 'body'=>$body }; unless ($midair) { # Add post to display. unshift @trans_log, $newr; $may_trans = 0 unless $is_owner; # Modify journal subject. $u->do("UPDATE logtext2 SET subject=? WHERE journalid=? AND jitemid=?", undef, LJ::ehtml("Phone Post: $subject"), $u->{userid}, $logrow->{jitemid}); my $memkey = [ $u->{userid}, "logtext:$u->{clusterid}:$u->{userid}:$logrow->{jitemid}" ]; LJ::MemCache::delete($memkey); # and delete the latest info $memkey = [$u->{userid},"ppelt:$u->{userid}:$bid"]; LJ::MemCache::delete($memkey); $memkey = [$u->{userid},"ppetu:$u->{userid}:$bid"]; LJ::MemCache::delete($memkey); } } $ret .= "