1 <?php 2 require_once __DIR__ . '/../includes/bootstrap.php'; 3 if (!$USER) json_out(['error'=>'Not logged in'],401); 4 if (!csrf_ok()) json_out(['error'=>'CSRF'],403); 5 6 $pid = (int)post('post_id'); 7 $content = sanitise(post('content')); 8 $reason = sanitise(post('reason')); 9 10 if (!$pid || !$content) json_out(['error'=>'Missing fields'],400); 11 if (strlen($content) > 20000) json_out(['error'=>'Post too long'],400); 12 13 $post = DB::row('SELECT * FROM posts WHERE id=?',[$pid]); 14 if (!$post) json_out(['error'=>'Not found'],404); 15 if ($post['user_id']!==$USER['id'] && !is_admin()) json_out(['error'=>'Forbidden'],403); 16 17 $now = DB::now(); 18 DB::run("UPDATE posts SET content=?,edited=1,edit_reason=?,updated_at=$now WHERE id=?", 19 [$content, $reason ?: null, $pid]); 20 21 json_out(['ok'=>true,'content'=>$content]);