improve support for using original filenames (still not ready)

This commit is contained in:
Uwe Steinmann 2020-06-24 16:22:28 +02:00
parent 6d634a0f18
commit 994b207f2b

View File

@ -51,12 +51,26 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
/**
* Set to true if original file shall be used instead of document name
* This can lead to duplicate file names in a directory because the original
* file name is not unique. You can enforce uniqueness by setting $prefixorgfilename
* to true which will add the document id and version in front of the original
* filename.
*
* @access private
* @var boolean
*/
var $useorgfilename = false;
/**
* Set to true if original file is used and you want to prefix each filename
* by its document id and version, e.g. 12345-1-somefile.pdf
* This is option is only used fi $useorgfilename is set to true.
*
* @access private
* @var boolean
*/
var $prefixorgfilename = true;
/**
* Serve a webdav request
*
@ -209,9 +223,18 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$this->logger->log('reverseLookup: found folder '.$root->getName().' ('.$root->getID().')', PEAR_LOG_DEBUG);
return $root;
} else {
if($this->useorgfilename)
$document = $this->dms->getDocumentByOriginalFilename($docname, $root);
else
if($this->useorgfilename) {
if($this->prefixorgfilename) {
$tmp = explode('-', $docname, 3);
if(ctype_digit($tmp[0])) {
$document = $this->dms->getDocument((int) $tmp[0]);
} else {
$document = null;
}
} else {
$document = $this->dms->getDocumentByOriginalFilename($docname, $root);
}
} else
$document = $this->dms->getDocumentByName($docname, $root);
if($document) {
if($this->logger)
@ -230,9 +253,18 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
}
if($folder) {
if($docname) {
if($this->useorgfilename)
$document = $this->dms->getDocumentByOriginalFilename($docname, $folder);
else
if($this->useorgfilename) {
if($this->prefixorgfilename) {
$tmp = explode('-', $docname, 3);
if(ctype_digit($tmp[0])) {
$document = $this->dms->getDocument((int) $tmp[0]);
} else {
$document = null;
}
} else {
$document = $this->dms->getDocumentByOriginalFilename($docname, $folder);
}
} else
$document = $this->dms->getDocumentByName($docname, $folder);
if($document) {
if($this->logger)
@ -454,6 +486,8 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$options['mtime'] = $content->getDate();
$fspath = $this->dms->contentDir.'/'.$content->getPath();
if(!file_exists($fspath))
return false;
// detect resource size
$options['size'] = filesize($fspath);
@ -517,11 +551,9 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$_fullpath .= $last->getName().'/';
}
foreach ($objs as $obj) {
$filename = $obj->getName();
$fullpath = $_fullpath.$filename;
if(get_class($obj) == $this->dms->getClassname('folder')) {
$fullpath .= '/';
$filename .= '/';
$fullpath = $_fullpath.$obj->getName().'/';
$displayname = $obj->getName().'/';
$filesize = 0;
$mtime = $obj->getDate();
} else {
@ -532,16 +564,31 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$mtime = $content->getDate();
$fspath = $this->dms->contentDir.'/'.$content->getPath();
$filesize = filesize($fspath);
if($this->useorgfilename)
$filename = $content->getOriginalFileName();;
if(file_exists($fspath))
$filesize = filesize($fspath);
else
$filesize = 0;
if($this->useorgfilename) {
/* Add the document id and version to the display name.
* I doesn't harm because for
* accessing the document the full path is used by the browser
*/
if($this->prefixorgfilename) {
$displayname = $obj->getID()."-".$content->getVersion()."-".$content->getOriginalFileName();
$fullpath = $_fullpath.$obj->getID()."-".$content->getVersion()."-".$content->getOriginalFileName();
} else {
$displayname = $content->getOriginalFileName();
$fullpath = $_fullpath.$content->getOriginalFileName();
}
} else {
$displayname = $obj->getName();
$fullpath = $_fullpath.$displayname;
}
}
// $name = htmlspecialchars($filename);
$name = $filename;
printf($format,
number_format($filesize),
strftime("%Y-%m-%d %H:%M:%S", $mtime),
"<a href=\"".$_SERVER['SCRIPT_NAME'].htmlspecialchars($fullpath)."\">".htmlspecialchars($name, ENT_QUOTES)."</a>");
"<a href=\"".$_SERVER['SCRIPT_NAME'].htmlspecialchars($fullpath)."\">".htmlspecialchars($displayname, ENT_QUOTES)."</a>");
}
echo "</pre>";
@ -609,9 +656,18 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$this->logger->log('PUT: file is of type '.$mimetype, PEAR_LOG_INFO);
/* First check whether there is already a file with the same name */
if($this->useorgfilename)
$document = $this->dms->getDocumentByOriginalFilename($name, $folder);
else
if($this->useorgfilename) {
if($this->prefixorgfilename) {
$tmp = explode('-', $name, 3);
if(ctype_digit($tmp[0])) {
$document = $this->dms->getDocument((int) $tmp[0]);
} else {
$document = null;
}
} else {
$document = $this->dms->getDocumentByOriginalFilename($name, $folder);
}
} else
$document = $this->dms->getDocumentByName($name, $folder);
if($document) {
if($this->logger)