File "edit.php"
Full Path: /home/analogde/www/filetypes/html/edit.php
File size: 12.47 KB
MIME-type: text/x-php
Charset: utf-8
<?php
/***************************************************************
* Copyright notice
*
* (c) 2003-2004 Tobias Bender (tobias@phpXplorer.org)
* All rights reserved
*
* This script is part of the phpXplorer project. The phpXplorer project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt distributed with these scripts.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
require(dirname(__FILE__) . "/../defaultActionHead.php");
$fileName = getRequestVar("fileName");
$newName = getRequestVar("newName");
$content = getRequestVar("content");
$submitAction = getRequestVar("submitAction");
$submitOverwrite = getRequestVar("submitOverwrite");
if(!isset($newName))
$newName = $fileName;
if(!isset($content)){
$content = implode("", file($currentDir . "/" . $fileName));
}else{
$content = str_replace('<', '<', $content);
$content = str_replace('>', '>', $content);
$content = str_replace('"', '"', $content);
}
if(isset($newName))
if(!(strpos($newName, "..") === FALSE))
die($PXP_languages[$PXP_language]['accessDenied'] . " (804)");
if(!(strpos($fileName, "..") === FALSE))
die($PXP_languages[$PXP_language]['accessDenied'] . " (804)");
if(isset($newName)){
$pInfoNew = checkFilePermissions($newName);
if(!$pInfoNew["allowOpen"] or !$pInfoNew["allowEdit"])
die($PXP_languages[$PXP_language]["accessDenied"] . " (809)");
}
$pInfo = checkFilePermissions($fileName);
if(!$pInfo["allowOpen"] or !$pInfo["allowEdit"])
die($PXP_languages[$PXP_language]["accessDenied"] . " (809)");
# ensure that all filenames have got an allowed extension
if(strpos($fileName, $TP_extensions[$pInfo["extKey"]][0]) === FALSE)
$fileName = $fileName . "." . $TP_extensions[$pInfo["extKey"]][0];
if(strpos($newName, ".") === FALSE)
$newName = $newName . "." . $TP_extensions[$pInfo["extKey"]][0];
# parse HTML content
#require($GC_phphtmlparser_Path . "/src/htmlparser.inc");
#function getHTML(){
# GLOBAL $parser;
#
# $c = "";
# $c .= "<" . $parser->iNodeName;
#
# foreach($parser->iNodeAttributes as $index => $value)
# $c .= " " . $index = '="' . $value . '"';
#
# $c .= ">";
#
# return $c;
#}
/* $parser->iNodeType $parser->iNodeName $parser->iNodeValue $parser->iNodeAttributes
$parser = new HtmlParser($content);
$docParts = Array();
$docParts["title"] = "";
$docParts["metaTags"] = "";
$docParts["baseTags"] = "";
$docParts["linkTags"] = "";
$docParts["scriptTags"] = "";
$docParts["bodyStartTag"] = "";
$docParts["scripts"] = Array();
$docParts["styles"] = Array();
$foundScript = false;
$foundStyle = false;
$foundTitle = false;
while($parser->parse()){
switch($parser->iNodeType){
case 0:
break;
case 1:
switch(strToLower($parser->iNodeName)){
case "title":
$foundTitle = true;
break;
case "style":
$foundStyle = true;
break;
case "script":
if(array_key_exists("src", $parser->iNodeAttributes)){
$docParts["scriptTags"] .= getHTML() . "</script>";
}else{
$foundScript = true;
}
break;
case "body":
$docParts["bodyStartTag"] = getHTML();
break;
case "meta":
$docParts["metaTags"] .= getHTML();
break;
case "base":
$docParts["baseTags"] .= getHTML();
break;
case "link":
$docParts["linkTags"] .= getHTML();
break;
}
break;
case 2:
break;
case 3:
if($foundTitle){
$docParts["title"] = $parser->iNodeValue;
$foundTitle = false;
}
break;
case 4:
if($foundStyle){
array_push($docParts["styles"], $parser->iNodeValue);
$foundStyle = false;
}
if($foundScript){
array_push($docParts["scripts"], $parser->iNodeValue);
$foundScript = false;
}
break;
case 5:
break;
}
}
$contentHead = "<html>\r\n<head>\r\n";
$contentHead .= "<title>" . $docParts["title"] . "</title>\r\n";
if($docParts["baseTags"] != "")
$contentHead .= $docParts["baseTags"] . "\r\n";
if($docParts["metaTags"] != "")
$contentHead .= $docParts["metaTags"] . "\r\n";
if($docParts["linkTags"] != "")
$contentHead .= $docParts["linkTags"] . "\r\n";
if($docParts["scriptTags"] != "")
$contentHead .= $docParts["scriptTags"] . "\r\n";
$contentHead .= '<style type="text/css">' . "\r\n";
$contentHead .= '<!--' . "\r\n";
foreach($docParts["styles"] as $style)
$contentHead .= str_replace("-->", "", str_replace("<!--", "", $style)) . "\r\n";
$contentHead .= '-->' . "\r\n";
$contentHead .= '</style>' . "\r\n";
$contentHead .= '<script type="text/javascript" language="JavaScript">' . "\r\n";
$contentHead .= '<!--' . "\r\n";
foreach($docParts["scripts"] as $script)
$contentHead .= str_replace("//-->", "", str_replace("<!--", "", $script)) . "\r\n";
$contentHead .= '//-->' . "\r\n";
$contentHead .= '</script>' . "\r\n";
$contentHead .= "</head>\r\n";
$contentHead .= $docParts["bodyStartTag"] . "\r\n";
$bodyStart = strpos($content, "<body");
$bodyStartStop = strpos($content, ">", $bodyStart) + 1;
$bodyEnd = strpos($content, "</body>");
$contentBody = substr($content, $bodyStartStop, $bodyEnd - $bodyStartStop);
*/
if($submitAction != ""){
$n = $currentDir . "/" . $fileName;
$nn = $currentDir . "/" . $newName;
$bCreateFile = false;
if($n != $nn){
if(file_exists($nn)){
if($submitOverwrite == ""){
$submitOverwrite = "overwrite";
}else{
if($submitOverwrite == "overwriteConfirm"){
$fileName = $newName;
$bCreateFile = true;
}
}
}else{
$fileName = $newName;
$bCreateFile = true;
}
}else{
$bCreateFile = true;
}
if($bCreateFile){
$handle = fopen($currentDir . "/" . $fileName, "w");
fwrite($handle, $content);
fclose($handle);
}
}
?>
<html>
<head>
<title><?php echo $PXP_languages[$PXP_language]['editProperties'] ?>: <?php echo $newName ?> (<?php echo $PXP_languages[$PXP_language]['filetype.' . $pInfo["extKey"]] ?>)</title>
<style type="text/css">
<!--
body{
margin: 1px;
padding: 0px;
border: 0px;
}
@import url(<?php echo $GC_HTMLArea_URL ?>/htmlarea.css);
-->
</style>
<link rel="stylesheet" type="text/css" href="<?php echo $PXP_url ?>/styles/<?php echo $PXP_style ?>/main.css"/>
<script language="JavaScript" type="text/javascript">
<!--
_editor_url = "<?php echo $GC_HTMLArea_URL ?>/";
//-->
</script>
<script type="text/javascript" src="<?php echo $GC_HTMLArea_URL ?>/htmlarea.js"></script>
<!--script type="text/javascript" src="<?php echo $GC_HTMLArea_URL ?>/lang/en.js"></script>
<script type="text/javascript" src="<?php echo $GC_HTMLArea_URL ?>/lang/de.js"></script-->
<script type="text/javascript" src="<?php echo $GC_HTMLArea_URL ?>/dialog.js"></script>
<script type="text/javascript" src="<?php echo $GC_HTMLArea_URL ?>/popupwin.js"></script>
<script type="text/javascript" src="<?php echo $GC_HTMLArea_URL ?>/popupdiv.js"></script>
<script language="JavaScript" type="text/javascript">
<!--
HTMLArea.I18N.lang="<?php echo $PXP_language ?>"
HTMLArea.loadPlugin("TableOperations");
//HTMLArea.loadPlugin("CSS");
HTMLArea.loadPlugin("FullPage");
var objectsToResize = new Array()
function resize_editor(){
var newHeight
var newWidth
if(document.all){
newHeight = document.body.offsetHeight - 183
newWidth = document.body.offsetWidth - 70
}else{
newHeight = window.innerHeight - 183
newWidth = window.innerWidth - 70
}
if(newHeight < 0)
newHeight = 0
for(var o = 0; o < objectsToResize.length; o++){
var obj = objectsToResize[o]
obj.style.width = newWidth + "px"
if(obj.nodeName.toLowerCase() != "input")
obj.style.height = newHeight + "px"
}
}
function validate(){
var f = document.frm1
if(!f.fileName.value != ""){
alert("<?php echo $PXP_languages[$PXP_language]['pleaseInsertValue'] ?>")
f.fileName.focus()
return false
}
return true
}
function send(a, overwrite){
if(!validate())
return false
switchButton()
var f = document.frm1
f.submitAction.value = a
f.content.value = editor.getHTML()
if(overwrite)
f.submitOverwrite.value = "overwriteConfirm"
f.submit()
}
function switchButton(){
var f = document.frm1
f.btnSave.disabled = !f.btnSave.disabled
f.btnSaveAndExit.disabled = !f.btnSaveAndExit.disabled
f.btnCancel.disabled = !f.btnCancel.disabled
}
function init(){
document.body.style.overflow = 'hidden'
<?php
if($submitOverwrite == "overwrite"){
echo "if(confirm('" . $PXP_languages[$PXP_language]["allowOverwrite"] . "?')){\r\n";
echo " send('" . $submitAction . "', true)\r\n";
echo "}else{\r\n";
echo " document.frm1.newName.focus()\r\n";
echo " document.frm1.newName.select()\r\n";
echo "}\r\n";
}else{
switch($submitAction){
case "save":
echo "opener.refreshDir()\r\n";
break;
case "saveAndExit":
echo "opener.refreshDir()\r\n";
echo "window.close()\r\n";
echo "return\r\n";
break;
}
}
?>//javascript
conf = new HTMLArea.Config()
var s = new Array("save")
conf.toolbar[0] = Array("save", "separator", "editHead", "separator").concat(conf.toolbar[0])
conf.registerButton("save", "Speichern", _editor_url + conf.imgURL + "ed_save.gif", false, function(e){document.frm1.submitter.click()})
conf.registerButton("editHead", "HTML Kopf bearbeiten", "<?php echo $PXP_url ?>/filetypes/html/dochead.gif", false, function(e){var s=document.getElementById('contentHead').style;b=editor._toolbarObjects["editHead"];if(s.visibility!=''){b.state("active", true);s.visibility='';document.frm1.contentHead.focus()}else{b.state("active", false);s.visibility='hidden'}})
editor = new HTMLArea("content")
editor.registerPlugin("TableOperations")
editor.registerPlugin("FullPage")
// editor.registerPlugin("SpellChecker");
<?php
# echo 'var css_plugin_args = {combos:[{label:"Styles",options:{"kein":""';
# if(sizeof($spans)>0)echo ",";
# foreach($spans as $key => $value)
# $spans[$key] = '"' . $value . '":"' . $value . '"';
#
# echo implode(",", $spans);
# echo "}}]};";
?>
//<script>
// editor.registerPlugin("CSS", css_plugin_args)
editor.generate("content")
editor._iframe.style.width = "100px";
editor._textArea.style.width = "100px";
objectsToResize.push(editor._textArea)
objectsToResize.push(editor._iframe)
objectsToResize.push(document.frm1.contentHead)
window.onresize = resize_editor
resize_editor()
switchButton()
}
//-->
</script>
</head>
<body onLoad="init()">
<form name="frm1" action="./edit.php" method="post" onSubmit="return false">
<input type="hidden" name="currentDir" value="<?php echo $currentDir ?>">
<input type="hidden" name="fileName" value="<?php echo $fileName ?>">
<input type="hidden" name="shareId" value="<?php echo $shareId ?>">
<input type="hidden" name="submitAction" value="<?php echo $submitAction ?>">
<input type="hidden" name="submitOverwrite" value="<?php echo $submitOverwrite ?>">
<table border="1" rules="none" cellspacing="0" bordercolor="#eeeeee">
<tr><td class="caption"><?php echo $PXP_languages[$PXP_language]['editProperties'] ?></td></tr>
<tr><td>
<table>
<tr>
<td> <?php echo $PXP_languages[$PXP_language]['name'] ?> </td>
<td><input type="text" name="newName" style="width:100%" value="<?php echo $newName ?>"></td>
</tr>
<tr>
<td valign="top"> <?php echo $PXP_languages[$PXP_language]['content'] ?> </td>
<td bgcolor="#ece9d8">
<textarea name="content" id="content" style="width:100;height:100px;display:none"><?php echo htmlspecialchars($content) ?></textarea>
<textarea name="contentHead" id="contentHead" style="position:absolute;top:129px;left:0xp;width:100;height:100px;visibility:hidden"><?php echo htmlspecialchars($contentHead); ?></textarea>
</td>
</tr>
<tr>
<td></td>
<td align="right">
<input type="button" name="btnSave" onClick="send('save')" value="<?php echo $PXP_languages[$PXP_language]['save'] ?>" disabled="disabled">
<input type="button" name="btnSaveAndExit" onClick="send('saveAndExit')" value="<?php echo $PXP_languages[$PXP_language]['saveAndExit'] ?>" disabled="disabled">
<input type="button" name="btnCancel" onClick="window.close()" value="<?php echo $PXP_languages[$PXP_language]['cancel'] ?>" disabled="disabled">
</td>
</tr>
</table></td></tr></table></form></body></html>