/** * @static * @param $tmpFilename * @param null $language * @return string */ public static function getValidFilename($tmpFilename, $language = null) { $tmpFilename = \Pimcore\Tool\Transliteration::toASCII($tmpFilename, $language); $tmpFilename = strtolower($tmpFilename); $tmpFilename = preg_replace('/[^a-z0-9\\-\\.~_]+/', '-', $tmpFilename); return $tmpFilename; }
public static function toUrl($text) { $text = \Pimcore\Tool\Transliteration::toASCII($text); $search = array('?', '\'', '"', '/', '-', '+', '.', ',', ';', '(', ')', ' ', '&', 'ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß', 'É', 'é', 'È', 'è', 'Ê', 'ê', 'E', 'e', 'Ë', 'ë', 'À', 'à', 'Á', 'á', 'Å', 'å', 'a', 'Â', 'â', 'Ã', 'ã', 'ª', 'Æ', 'æ', 'C', 'c', 'Ç', 'ç', 'C', 'c', 'Í', 'í', 'Ì', 'ì', 'Î', 'î', 'Ï', 'ï', 'Ó', 'ó', 'Ò', 'ò', 'Ô', 'ô', 'º', 'Õ', 'õ', 'Œ', 'O', 'o', 'Ø', 'ø', 'Ú', 'ú', 'Ù', 'ù', 'Û', 'û', 'U', 'u', 'U', 'u', 'Š', 'š', 'S', 's', 'Ž', 'ž', 'Z', 'z', 'Z', 'z', 'L', 'l', 'N', 'n', 'Ñ', 'ñ', '¡', '¿', 'Ÿ', 'ÿ', "_", ":"); $replace = array('', '', '', '', '-', '', '', '-', '-', '', '', '-', '', 'ae', 'oe', 'ue', 'Ae', 'Oe', 'Ue', 'ss', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'A', 'a', 'A', 'a', 'A', 'a', 'a', 'A', 'a', 'A', 'a', 'a', 'AE', 'ae', 'C', 'c', 'C', 'c', 'C', 'c', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'O', 'o', 'O', 'o', 'O', 'o', 'o', 'O', 'o', 'OE', 'O', 'o', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'S', 's', 'S', 's', 'Z', 'z', 'Z', 'z', 'Z', 'z', 'L', 'l', 'N', 'n', 'N', 'n', '', '', 'Y', 'y', "-", "-"); $value = urlencode(str_replace($search, $replace, $text)); return $value; }
/** * @static * @param $tmpFilename * @param null $language * @return string */ public static function getValidFilename($tmpFilename, $language = null) { $tmpFilename = \Pimcore\Tool\Transliteration::toASCII($tmpFilename, $language); $tmpFilename = strtolower($tmpFilename); $tmpFilename = preg_replace('/[^a-z0-9\\-\\.~_]+/', '-', $tmpFilename); $tmpFilename = ltrim($tmpFilename, "."); // files shouldn't start with a "." (=hidden file) return $tmpFilename; }
/** * @static * @param $tmpFilename * @param null $language * @return string */ public static function getValidFilename($tmpFilename, $language = null) { $tmpFilename = \Pimcore\Tool\Transliteration::toASCII($tmpFilename, $language); $tmpFilename = strtolower($tmpFilename); $tmpFilename = preg_replace('/[^a-z0-9\\-\\.~_]+/', '-', $tmpFilename); // keys shouldn't start with a "." (=hidden file) *nix operating systems // keys shouldn't end with a "." - Windows issue: filesystem API trims automatically . at the end of a folder name (no warning ... et al) $tmpFilename = trim($tmpFilename, ". "); return $tmpFilename; }
/** * @param $key * @param null $type * @return mixed|string */ public static function getValidKey($key, $type) { $results = \Pimcore::getEventManager()->trigger("system.service.preGetValidKey", null, ["key" => $key, "type" => $type]); if ($results->count()) { $key = $results->last(); } $key = \Pimcore\Tool\Transliteration::toASCII($key); if ($type == "document") { // no spaces for documents / clean URLs $key = preg_replace('/[^a-zA-Z0-9\\-\\.~_]+/', '-', $key); } else { // assets & objects including spaces $key = preg_replace('/[^a-zA-Z0-9\\-\\.~_ ]+/', '-', $key); } if ($type == "asset") { // keys shouldn't start with a "." (=hidden file) *nix operating systems // keys shouldn't end with a "." - Windows issue: filesystem API trims automatically . at the end of a folder name (no warning ... et al) $key = trim($key, ". "); } else { $key = trim($key); $key = ltrim($key, "."); } return $key; }