2 # Write data from an HTML editor
4 require './file-lib.pl';
5 $disallowed_buttons{'edit'} && &error($text{'ebutton'});
7 &error_setup($text{'html_err'});
9 # Get the original file contents, in case we need to preserve the head
11 &switch_acl_uid_and_chroot();
12 $olddata = &read_file_contents($p);
14 ($oldhead, $oldbody, $oldfoot) = &html_extract_head_body($olddata);
17 # Try to write the file
18 if ($access{'ro'} || !&can_access($p)) {
19 &popup_error(&text('edit_eaccess', $p));
21 elsif (-l $p && !&must_follow($p)) {
22 &popup_error(&text('edit_efollow', $p));
24 elsif (!&open_tempfile(FILE, ">$p", 1)) {
28 # Fix up HTML head, and write it out
29 $in{'body'} =~ s/\r//g;
30 $in{'body'} =~ s/^\s+//g;
31 $in{'body'} =~ s/\s+$//g;
32 if ($oldhead && $in{'body'} !~ /<body[\000-\377]*>/i) {
33 &print_tempfile(FILE, $oldhead.$in{'body'}.$oldfoot);
36 &print_tempfile(FILE, $in{'body'});
38 &close_tempfile(FILE);
40 # Show JS to close page
41 &popup_header($text{'html_title'});
43 $info = &file_info_line($p);
45 print "opener.document.FileManager.",
46 "upload_notify(\"$p\", \"$info\");\n";