diff options
author | Florian Hülsmann <fh@cbix.de> | 2012-03-25 00:43:30 +0400 |
---|---|---|
committer | Florian Hülsmann <fh@cbix.de> | 2012-03-25 00:43:30 +0400 |
commit | 481d3a7c6f4018eaf8f5291a2f10bcb8af8ee402 (patch) | |
tree | e2e0f254bcfda1fb7af0d5cf365d237de4c202a2 /files_svgedit | |
parent | a2231d5e72110ef91236ea31e6884329ecf3d1e8 (diff) |
saving as a new file works
Diffstat (limited to 'files_svgedit')
-rw-r--r-- | files_svgedit/ajax/save.php | 68 | ||||
-rw-r--r-- | files_svgedit/js/ocsvgEditor.js | 4 |
2 files changed, 39 insertions, 33 deletions
diff --git a/files_svgedit/ajax/save.php b/files_svgedit/ajax/save.php index 512307d3c..9ac0a5b26 100644 --- a/files_svgedit/ajax/save.php +++ b/files_svgedit/ajax/save.php @@ -14,38 +14,44 @@ OC_JSON::checkLoggedIn(); $filecontents = htmlspecialchars_decode($_POST['filecontents']); $path = isset($_POST['path']) ? $_POST['path'] : ''; $mtime = isset($_POST['mtime']) ? $_POST['mtime'] : ''; +$pathParts = pathinfo($path); +$dir = $pathParts['dirname']; +$file = $pathParts['basename']; - -if($path != '' && $mtime != '') -{ - // Get file mtime - $filemtime = OC_Filesystem::filemtime($path); - if($mtime != $filemtime) - { - // Then the file has changed since opening - OC_JSON::error(); - OC_Log::write('files_svgedit',"File: ".$path." modified since opening.",OC_Log::ERROR); - } - else - { - // File same as when opened - // Save file - if(OC_Filesystem::is_writeable($path)) - { - OC_Filesystem::file_put_contents($path, $filecontents); - // Clear statcache - clearstatcache(); - // Get new mtime - $newmtime = OC_Filesystem::filemtime($path); - OC_JSON::success(array('data' => array('mtime' => $newmtime))); - } - else - { - // Not writeable! - OC_JSON::error(array('data' => array( 'message' => 'Insufficient permissions'))); - OC_Log::write('files_svgedit',"User does not have permission to write to file: ".$path,OC_Log::ERROR); - } - } +if($path != '' && $mtime != '') { + if(OC_Filesystem::file_exists($path)) { + // Get file mtime + $filemtime = OC_Filesystem::filemtime($path); + if($mtime != $filemtime) { + // Then the file has changed since opening + OC_JSON::error(); + OC_Log::write('files_svgedit',"File: ".$path." modified since opening.",OC_Log::ERROR); + } + } else { + // file doesn't exist yet, so let's create it! + if($file == '') { + OC_JSON::error(array("data" => array( "message" => "Empty Filename" ))); + exit(); + } + if(!OC_Files::newFile($dir, $file, 'file')) { + OC_JSON::error(array("data" => array("message" => "Error when creating new file!"))); + OC_Log::write('files_svgedit', "Failed to create file: " . $path, OC_Log::ERROR); + exit(); + } + } + // file should be existing now + if(OC_Filesystem::is_writeable($path)) { + OC_Filesystem::file_put_contents($path, $filecontents); + // Clear statcache + clearstatcache(); + // Get new mtime + $newmtime = OC_Filesystem::filemtime($path); + OC_JSON::success(array('data' => array('mtime' => $newmtime))); + } else { + // Not writeable! + OC_JSON::error(array('data' => array( 'message' => 'Insufficient permissions'))); + OC_Log::write('files_svgedit',"User does not have permission to write to file: ".$path,OC_Log::ERROR); + } } else { OC_JSON::error(array('data' => array( 'message' => 'File path or mtime not supplied'))); OC_Log::write('files_svgedit',"Invalid path supplied:".$path,OC_Log::ERROR); diff --git a/files_svgedit/js/ocsvgEditor.js b/files_svgedit/js/ocsvgEditor.js index b1358014f..f3e6fad1d 100644 --- a/files_svgedit/js/ocsvgEditor.js +++ b/files_svgedit/js/ocsvgEditor.js @@ -26,14 +26,14 @@ var ocsvg = { return; } else { ocsvg.setFilePath(savePath); - ocsvg.setFileContents('<?xml version="1.0"?>\n' + svgString); + ocsvg.setFileContents('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' + svgString); $.post( OC.filePath('files_svgedit','ajax','save.php'), ocsvg.currentFile, function(result) { if(result.status!='success'){ // Save failed - alert(t('files_svgedit', 'Could not save:') + "\n" + ocsvg.currentFile.path); + alert(t('files_svgedit', 'Could not save:') + "\n" + ocsvg.currentFile.path + "\n" + result.data.message); } else { // Save OK // Update mtime: |