Date : 2011-05-12 Remark : Die zu editierende Datei wird über den Referer übergeben. Die zu editierende Datei wird in der Datei editscript.tmp im Verzeichnis des Scriptes zwischengespeichert. */ class textFileEdit { public $filename; public $scriptFile; public $title; public $backLinkHREF; public $backLinkCaption; public $action; public $text; public $cols; public $rows; private function pageHeader() { echo "\n"; echo "\n"; echo "\n"; echo "".$this->title."\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo "backLinkHREF\">$this->backLinkCaption\n"; echo "
\n"; echo "

".$this->title."

\n"; } private function pageFooter() { echo "\n"; echo "\n"; echo ""; } private function createFile() { if (!file_exists($this->filename)) { touch($this->filename); } } private function savePageToEdit($pageToEdit) { file_put_contents("editscript.tmp", $pageToEdit); } public function loadPageToEdit() { Return file_get_contents("editscript.tmp"); } public function getPageToEdit($referer) { switch($this->action) { case "save": Return $this->loadPageToEdit(); break; case "edit"; $pageToEdit = str_replace($_SERVER["SERVER_NAME"], "", $referer); $pageToEdit = str_replace("http:///", "", $pageToEdit); $pageToEdit = $_SERVER["DOCUMENT_ROOT"].'/'.$pageToEdit; $this->savePageToEdit($pageToEdit); Return $pageToEdit; break; } } public function showTextFile() { $this->createFile(); $this->pageHeader(); echo "

\n"; echo "Letzte Änderung: ".date ("Y-m-d H:i", filemtime($this->filename))."
\n"; echo "Dateigröße: ".filesize($this->filename)." Byte
\n"; echo "scriptFile."?action=edit\">Bearbeiten\n"; echo "

\n"; if (filesize($this->filename) > 0) { $fp = @fopen($this->filename, "r") or die ("Kann Datei nicht lesen."); while($line = fgets($fp, 1024)){ echo ($line)."
"; } fclose($fp); } $this->pageFooter(); } public function showForm() { $this->createFile(); $this->pageHeader(); echo "
\n"; echo "

\n"; echo "

\n"; echo "
"; $this->pageFooter(); } public function saveToFile() { file_put_contents($this->filename, $this->text); Header("Location: $this->scriptFile?action=show"); } } $tef = new textFileEdit(); $tef->action = $_GET['action']; $tef->filename = $tef->getPageToEdit($_SERVER["HTTP_REFERER"]); $tef->scriptFile = basename($_SERVER['PHP_SELF']); $title = str_replace($_SERVER["DOCUMENT_ROOT"], "", $tef->filename); $tef->title = "Datei $title bearbeiten"; $tef->backLinkHREF = "/Admin"; $tef->backLinkCaption = "Admin"; $tef->cols = "150"; $tef->rows = "35"; $tef->text = $_POST['text']; switch($tef->action) { case "edit": $tef->showForm(); break; case "save": $tef->saveToFile(); break; case "show": $pageToShow = $tef->loadPageToEdit(); $pageToShow = str_replace($_SERVER["DOCUMENT_ROOT"], "", $pageToShow); $pageToShow = str_replace("show", "", $pageToShow); Header("Location: $pageToShow"); break; } ?>