diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 69780e777..edb100c0f 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -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;