Index: branches/RC/core/units/general/helpers/filenames_helper.php =================================================================== diff -u -N -r10098 -r10906 --- branches/RC/core/units/general/helpers/filenames_helper.php (.../filenames_helper.php) (revision 10098) +++ branches/RC/core/units/general/helpers/filenames_helper.php (.../filenames_helper.php) (revision 10906) @@ -1,23 +1,78 @@ _escapeChar = $this->Application->ConfigValue('FilenameSpecialCharReplacement'); + + $language =& $this->Application->recallObject('lang.current'); + /* @var $language kDBItem */ + + $replacements = $language->GetDBField('FilenameReplacements'); + if ($replacements) { + $replacements = explode("\r\n", $replacements); + foreach ($replacements as $replacement) { + list ($replace_from, $replace_to) = explode('=', $replacement); + $this->_filenameReplaceFrom[] = trim($replace_from); + $this->_filenameReplaceTo[] = trim($replace_to); + } + } + } + + function replaceSequences($filename) + { + $not_allowed = Array ( + ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`', + '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~', + '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ',', "\r", "\n" + ); + + if ($this->_filenameReplaceFrom) { + // replace predefined sequences + $filename = str_replace($this->_filenameReplaceFrom, $this->_filenameReplaceTo, $filename); + } + + $filename = str_replace($not_allowed, $this->_escapeChar, $filename); + $filename = preg_replace('/(' . $this->_escapeChar . '+)/', $this->_escapeChar, $filename); + return trim($filename, $this->_escapeChar); // remove trailing escape chars + } + + /** * replace not allowed symbols with "_" chars + remove duplicate "_" chars in result * * @param string $string * @return string */ function stripDisallowed($table, $id_field, $item_id, $filename) { - $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`', - '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~', - '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ',', "\r", "\n"); + $filename = $this->replaceSequences($filename); - $filename = str_replace($not_allowed, '_', $filename); - $filename = preg_replace('/(_+)/', '_', $filename); - $filename = $this->checkAutoFilename($table, $id_field, $item_id, $filename); - - return $filename; + return $this->checkAutoFilename($table, $id_field, $item_id, $filename); } function checkAutoFilename($table, $id_field, $item_id, $filename)