add function getFilenameByDocname()

This commit is contained in:
Uwe Steinmann 2022-09-07 08:56:08 +02:00
parent 769706fe9c
commit 56bbdefced

View File

@ -367,6 +367,34 @@ function utf8_basename($path, $suffix='') { /* {{{ */
return $file;
} /* }}} */
/**
* Return a valid file name
*
* This function returns a valid file name for the given document content
* or an arbitrary string. If a document content is given the name of
* the document will be used. The extension of the file name will be
* either taken from the document name or the original file. If the two
* differ the extension from the original file name will be used.
*
* @param object|string $content document content or an arbitrary string
* @return string valid file name
*/
function getFilenameByDocname($content) { /* {{{ */
if(is_string) {
$filename = $content;
} else {
$document = $content->getDocument();
$ext = pathinfo($document->getName(), PATHINFO_EXTENSION);
$oext = pathinfo($content->getOriginalFileName(), PATHINFO_EXTENSION);
if($ext == $oext)
$filename = $document->getName();
else {
$filename = $document->getName().'.'.$oext;
}
}
return mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $filename);
} /* }}} */
function getLogger($prefix='') { /* {{{ */
global $settings;