2007-04-12 19:28:29 +00:00
|
|
|
#!/usr/local/bin/perl
|
|
|
|
# Show an HTML editor window
|
|
|
|
|
2008-02-15 00:08:08 +00:00
|
|
|
$trust_unknown_referers = 1;
|
2007-04-12 19:28:29 +00:00
|
|
|
require './file-lib.pl';
|
|
|
|
do '../ui-lib.pl';
|
|
|
|
$disallowed_buttons{'edit'} && &error($text{'ebutton'});
|
|
|
|
&ReadParse();
|
2007-05-04 21:10:03 +00:00
|
|
|
|
|
|
|
# Work out editing mode
|
2007-08-05 19:49:04 +00:00
|
|
|
if ($in{'text'} || $in{'file'} && !&is_html_file($in{'file'})) {
|
2007-05-04 21:10:03 +00:00
|
|
|
$text_mode = 1;
|
|
|
|
}
|
|
|
|
|
2014-09-10 19:26:00 -07:00
|
|
|
if ($in{'file'} ne '' && !&can_access($in{'file'})) {
|
2012-07-10 11:01:59 -07:00
|
|
|
# ACL rules prevent access to file
|
2014-09-10 19:26:00 -07:00
|
|
|
&error(&text('view_eaccess', &html_escape($in{'file'})));
|
2012-07-10 11:01:59 -07:00
|
|
|
}
|
|
|
|
|
2007-04-12 19:28:29 +00:00
|
|
|
&popup_header($in{'file'} ? $text{'html_title'} : $text{'html_title2'},
|
2010-11-12 17:07:55 -08:00
|
|
|
undef, $text_mode ? undef : "onload='xinha_init()'");
|
2007-04-12 19:28:29 +00:00
|
|
|
|
|
|
|
# Output HTMLarea init code
|
|
|
|
print <<EOF;
|
|
|
|
<script type="text/javascript">
|
2021-09-28 16:30:05 +03:00
|
|
|
_editor_url = "@{[&get_webprefix()]}/$module_name/xinha/";
|
2007-04-12 19:28:29 +00:00
|
|
|
_editor_lang = "en";
|
|
|
|
</script>
|
2010-11-12 17:07:55 -08:00
|
|
|
<script type="text/javascript" src="xinha/XinhaCore.js"></script>
|
2007-04-12 19:28:29 +00:00
|
|
|
|
|
|
|
<script type="text/javascript">
|
2010-11-12 17:07:55 -08:00
|
|
|
xinha_init = function()
|
|
|
|
{
|
|
|
|
xinha_editors = [ "body" ];
|
|
|
|
xinha_plugins = [ ];
|
|
|
|
xinha_config = new Xinha.Config();
|
|
|
|
xinha_editors = Xinha.makeEditors(xinha_editors, xinha_config, xinha_plugins);
|
|
|
|
Xinha.startEditors(xinha_editors);
|
2007-04-12 19:28:29 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Read the file
|
|
|
|
&switch_acl_uid_and_chroot();
|
|
|
|
$data = &read_file_contents($in{'file'});
|
|
|
|
|
|
|
|
# Output text area
|
|
|
|
print &ui_form_start("save_html.cgi", "form-data");
|
2007-05-04 21:10:03 +00:00
|
|
|
print &ui_hidden("text", $text_mode);
|
2007-04-12 19:28:29 +00:00
|
|
|
if ($in{'file'}) {
|
|
|
|
# Editing existing file
|
2007-05-04 21:10:03 +00:00
|
|
|
print &ui_hidden("file", $in{'file'});
|
2007-04-12 19:28:29 +00:00
|
|
|
$pc = 95;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# Creating new, so prompt for path
|
|
|
|
print $text{'edit_filename'}," ",
|
|
|
|
&ui_textbox("file", $in{'dir'}, 70),"<br>\n";
|
|
|
|
$pc = 90;
|
|
|
|
}
|
2007-05-04 21:10:03 +00:00
|
|
|
if ($text_mode) {
|
|
|
|
# Show plain textarea
|
|
|
|
print "<textarea rows=20 cols=80 style='width:100%;height:$pc%' name=body>";
|
|
|
|
print &html_escape($data);
|
|
|
|
print "</textarea>\n";
|
|
|
|
print &ui_submit($text{'html_save'});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# Show HTML editor
|
|
|
|
print "<textarea rows=20 cols=80 style='width:100%;height:$pc%' name=body id=body>";
|
|
|
|
print &html_escape($data);
|
|
|
|
print "</textarea>\n";
|
|
|
|
print "<table width=100%><tr>\n";
|
|
|
|
print "<td>",&ui_submit($text{'html_save'}),"</td>\n";
|
|
|
|
print "<td align=right><a href='edit_html.cgi?file=".
|
|
|
|
&urlize($in{'file'})."&text=1'>$text{'edit_textmode'}</a></td>\n";
|
|
|
|
print "</tr> </table>\n";
|
|
|
|
}
|
2007-04-12 19:28:29 +00:00
|
|
|
print &ui_form_end();
|
|
|
|
|
|
|
|
&popup_footer();
|
|
|
|
|
2007-08-05 19:49:04 +00:00
|
|
|
sub is_html_file
|
|
|
|
{
|
|
|
|
local ($file) = @_;
|
|
|
|
local @exts = split(/\s+/, $userconfig{'htmlexts'} || $config{'htmlexts'});
|
|
|
|
@exts = ( ".htm", ".html", ".shtml" ) if (!@exts);
|
|
|
|
foreach my $e (@exts) {
|
|
|
|
return 1 if ($file =~ /\Q$e\E$/i);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|