hjælp til redigering af php fil
Jeg har en online editor en såkaldt wysiwyg editor. jeg skal have ændret nogle indstillinger i den. (www.disappear.dk/rediger.htm) Jeg skal have ændret tekst feltet fra Gem, så jeg i stedet kan benytte en dropdownbox som i åben delen. koden til denne ene fil er som følger:<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_magic_quotes_runtime(0);
include ("./Page.phpclass");
include ("./Conf.phpclass");
$Ide = new Ide;
class Ide {
var $code, $alert_message, $success_message;
var $IDE_homepage_url = "http://www.ekenberg.se/php/ide/";
var $GPL_link = "<A HREF='http://www.gnu.org/copyleft/gpl.html'>GNU General Public License</A>";
var $PHP_link = "<A HREF='http://www.php.net'>PHP</A>";
var $IDE_version = "1 . 5";
function Ide() {
global $HTTP_POST_VARS, $HTTP_GET_VARS;
$this->Conf = new Conf;
$this->Out = new Page;
/*
** Remove slashes if necessary, put code in $this->code
*/
if (isset($HTTP_POST_VARS['code'])) {
if (get_magic_quotes_gpc()) {
$this->code = stripslashes($HTTP_POST_VARS['code']);
}
else {
$this->code = $HTTP_POST_VARS['code'];
}
}
/*
** Get code from code file if not submitted through form.
*/
if ((! isset($this->code)) && (file_exists($this->Conf->Code_file))) {
$this->code = join ("", (file ($this->Conf->Code_file)) );
}
/*
** Since the code is displayed in a <TEXTAREA>, it can't contain the tag </TEXTAREA>,
** since that would break our editor :/ Thus we replace it with </ideTEXTAREA>
** and put it in $this->textarea_safe_code. The reverse substitution is first
** performed on $this->code, to restore any previous replacements.
*/
$this->code = eregi_replace("</ide(TEXTAREA)>", "</\\1>", $this->code);
$this->textarea_safe_code = $this->make_textarea_safe($this->code);
/*
** Htmlentities are not literally shown inside TEXTAREA in some (all?) browsers.
*/
if ($this->Conf->Protect_entities)
$this->code = eregi_replace("(&)+&", "&", $this->code);
/*
** Remove \r\f if desired, needed for cgi on UNIX
*/
if ($this->Conf->Unix_newlines) {
$this->code = preg_replace("/[\r\f]/", "", $this->code);
}
/*
** What file are we working with?
*/
$this->Conf->Current_file = $HTTP_POST_VARS['Current_file'] ? $HTTP_POST_VARS['Current_file'] : $this->Conf->Tmp_file;
/*
** Check our environment.
*/
if ($error = $this->Conf->Is_bad_environment()) {
print $this->Out->html_top();
print "<H3><BLOCKQUOTE>$error</BLOCKQUOTE></H2>\n";
print $this->Out->html_bottom();
exit;
}
/*
** These options are saved every time
*/
$this->Conf->save_to_file(array('Eval_suffix'));
/*
** Print top of page
*/
print $this->Out->html_top();
/*
** Act according to 'action'
*/
if ($HTTP_POST_VARS['action'] == "eval") {
print $this->js_open_code_window ($this->Conf->Tmp_file);
}
elseif ($HTTP_POST_VARS['action'] == "save_as") {
if (! strlen($HTTP_POST_VARS['save_as_filename'])) {
$this->alert_message = "Du kan ikke gemme filen uden at skrive filnavnet. Du kan prøve at teste siden for at se hvad for en prisliste der er åben og så gemme filen som enten: prislistesandvig.htm eller prislistedueodde.htm!!";
}
elseif ((! $HTTP_POST_VARS['overwrite_ok']) && (file_exists("{$this->Conf->Data_dir}/{$HTTP_POST_VARS['save_as_filename']}"))) {
$this->alert_message = "Ændringerne er <b>IKKE</b> gemt. Sæt venligst flueben i \"Overskriv\" og tryk herefter på gem igen.";
}
else {
if ($FH_SAVEAS = @fopen ("{$this->Conf->Data_dir}/{$HTTP_POST_VARS['save_as_filename']}", "w")) {
fputs ($FH_SAVEAS, $this->code);
fclose ($FH_SAVEAS);
$this->success_message = "Filen er hermed gemt i filen: <B>{$this->Conf->Data_dir}/{$HTTP_POST_VARS['save_as_filename']}</B>!";
}
else {
$this->alert_message = "Kunne ikke gemme filen, prøv venligst igen. $php_errormsg";
}
$this->Conf->Current_file = "{$this->Conf->Data_dir}/{$HTTP_POST_VARS['save_as_filename']}";
}
}
elseif ($HTTP_POST_VARS['action'] == "open_file") {
$this->textarea_safe_code = join ("", (file ("{$this->Conf->Data_dir}/{$HTTP_POST_VARS['code_file_name']}")));
if (get_magic_quotes_runtime()) $this->textarea_safe_code = stripslashes($this->textarea_safe_code);
$this->textarea_safe_code = $this->make_textarea_safe($this->textarea_safe_code);
$this->Conf->Current_file = "{$this->Conf->Data_dir}/{$HTTP_POST_VARS['code_file_name']}";
$HTTP_POST_VARS['save_as_filename'] = $HTTP_POST_VARS['code_file_name'];
}
/*
** Print the main page and exit
*/
print $this->main_page();
print $this->Out->html_bottom();
exit;
}
/*
** Functions
*/
function main_page() {
global $HTTP_POST_VARS;
$suffix_list_selected[$this->Conf->Eval_suffix] = "SELECTED";
while (list(,$suffix) = each($this->Conf->Eval_suffix_list)) {
$suffix_select_options .= "<OPTION VALUE='$suffix' {$suffix_list_selected[$suffix]}>$suffix\n";
}
$ret .= "<DIV ALIGN='CENTER'>\n";
$ret .= "<H2>Redigering af Prislister</H2></DIV>\n";
$ret .= "<FORM NAME='main_form' METHOD='POST' ACTION='{$_SERVER['PHP_SELF']}'>\n";
$ret .= "<INPUT TYPE='hidden' NAME='action' VALUE=''>\n";
$ret .= "<INPUT TYPE='hidden' NAME='Current_file' VALUE='{$this->Conf->Current_file}'>\n";
$ret .= $this->Out->begin_invisible_table("", array("CELLPADDING='1'", "CELLSPACING='0'", "ALIGN='center'"));
$ret .= "<TR><TD>\n";
$ret .= "<FONT COLOR='{$this->Conf->Alert_message_color}' FACE='MS Sans Serif, Arial'>{$this->alert_message}</FONT>\n";
$ret .= "<FONT COLOR='{$this->Conf->Success_message_color}' FACE='MS Sans Serif, Arial'>{$this->success_message}</FONT>\n";
$ret .= "</TD</TR>\n";
$ret .= "<TR><TD>\n";
$ret .= $this->Out->start_box_table();
$ret .= "<TR BGCOLOR='#D1DBC3'><TD>\n";
$ret .= "<TD ALIGN='right' COLSPAN='10'>\n";
$ret .= "<SELECT NAME='code_file_name'>\n";
$data_dir_obj = dir ($this->Conf->Data_dir);
$selected[$this->Conf->Current_file] = "SELECTED";
while (false !== ($entry = $data_dir_obj->read())) $my_files[] = $entry;
sort($my_files);
while (strlen($file=next($my_files))) {
if (ereg("^\.{1,2}$", $file)) continue;
$my_fullname = "{$data_dir_obj->path}/$file";
$ret .= "<OPTION VALUE='$file' {$selected[$my_fullname]}>$my_fullname</OPTION>\n";
}
$data_dir_obj->close();
$ret .= "</SELECT></TD></TR>\n";
$ret .= "<TR BGCOLOR='#D1DBC3'><TD COLSPAN='5' CLASS='netscapesucks'>\n";
$ret .= "<INPUT TYPE='submit' VALUE='Gem' onClick='main_form.action.value=\"save_as\"; main_form.submit()'>\n";
$ret .= "{$this->Conf->Data_dir}/<INPUT TYPE='text' NAME='save_as_filename' VALUE='{$HTTP_POST_VARS['save_as_filename']}'>\n";
$ret .= "Overskriv: <INPUT TYPE='CHECKBOX' NAME='overwrite_ok' VALUE='CHECKED' {$HTTP_POST_VARS['overwrite_ok']}></TD>\n";
$ret .= "<TD ALIGN='right' COLSPAN='2'>\n";
$ret .= "<INPUT TYPE='submit' VALUE='Åben' onClick='main_form.action.value=\"open_file\"'>\n";
$ret .= "</TD></TR>\n";
$ret .= "<TR BGCOLOR='#D1DBC3'><TD COLSPAN='7'>\n";
$ret .= "<TEXTAREA COLS='{$this->Conf->Code_cols}' ROWS='{$this->Conf->Code_rows}' NAME='code'>{$this->textarea_safe_code}</TEXTAREA>\n";
$ret .= $this->Out->end_box_table();
$ret .= "</TD></TR>\n";
$ret .= $this->Out->end_invisible_table();
$ret .= "</FORM>\n";
return ($ret);
}
function make_textarea_safe($code) {
$safe_code = eregi_replace("</(TEXTAREA)>", "</ide\\1>", $code);
if ($this->Conf->Protect_entities)
$safe_code = eregi_replace("&", "&", $safe_code);
return $safe_code;
}
function js_open_code_window ($url) {
$ret = "";
$ret .= "<SCRIPT LANGUAGE='JavaScript'>\n";
$ret .= "var eval_window = window.open('$url','Foo');\n";
$ret .= "eval_window.focus();\n";
$ret .= "</SCRIPT>\n";
return $ret;
}
}?>
tak for hjælpen
