Added a button for creating a new HTML file.
---- Changes since 1.330 ----
Replaced the HTMLarea widget for editing .html files with Xinha.
+---- Changes since 1.340 ----
+When editing an HTML file, the <head> section is preserved.
}
}
+# html_extract_head_body(html)
+# Given some HTML, extracts the header, body and stuff after the body
+sub html_extract_head_body
+{
+local ($html) = @_;
+if ($html =~ /^([\000-\377]*<body[^>]*>)([\000-\377]*)(<\/body[^>]*>[\000-\377]*)/i) {
+ return ($1, $2, $3);
+ }
+else {
+ return (undef, $html, undef);
+ }
+}
1;
&ReadParseMime();
&error_setup($text{'html_err'});
-# Try to write the file
+# Get the original file contents, in case we need to preserve the head
$p = $in{'file'};
&switch_acl_uid_and_chroot();
+$olddata = &read_file_contents($p);
+if ($olddata) {
+ ($oldhead, $oldbody, $oldfoot) = &html_extract_head_body($olddata);
+ }
+
+# Try to write the file
if ($access{'ro'} || !&can_access($p)) {
&popup_error(&text('edit_eaccess', $p));
}
&popup_error("$!");
}
else {
- &print_tempfile(FILE, $in{'body'});
+ # Fix up HTML head, and write it out
+ $in{'body'} =~ s/\r//g;
+ $in{'body'} =~ s/^\s+//g;
+ $in{'body'} =~ s/\s+$//g;
+ if ($oldhead && $in{'body'} !~ /<body.*>/i) {
+ &print_tempfile(FILE, $oldhead.$in{'body'}.$oldfoot);
+ }
+ else {
+ &print_tempfile(FILE, $in{'body'});
+ }
&close_tempfile(FILE);
# Show JS to close page