Pimcore\File::getValidFilename PHP Method

getValidFilename() public static method

public static getValidFilename ( $tmpFilename, null $language = null ) : string
$tmpFilename
$language null
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;
    }

Usage Example

Example #1
0
 /**
  * @param $body
  * @return mixed
  */
 public static function processHtml($body)
 {
     $processedPaths = array();
     preg_match_all("@\\<link[^>]*(rel=\"stylesheet/less\")[^>]*\\>@msUi", $body, $matches);
     if (is_array($matches)) {
         foreach ($matches[0] as $tag) {
             preg_match("/href=\"([^\"]+)*\"/", $tag, $href);
             if (array_key_exists(1, $href) && !empty($href[1])) {
                 $source = $href[1];
                 $source = preg_replace("/\\?_dc=[\\d]+/", "", $source);
                 if (is_file(PIMCORE_ASSET_DIRECTORY . $source)) {
                     $path = PIMCORE_ASSET_DIRECTORY . $source;
                 } else {
                     if (is_file(PIMCORE_DOCUMENT_ROOT . $source)) {
                         $path = PIMCORE_DOCUMENT_ROOT . $source;
                     }
                 }
                 // add the same file only one time
                 if (in_array($path, $processedPaths)) {
                     continue;
                 }
                 $newFile = PIMCORE_TEMPORARY_DIRECTORY . "/less___" . File::getValidFilename(str_replace(".less", "", $source)) . "-" . filemtime($path) . ".css";
                 if (!is_file($newFile)) {
                     $compiledContent = self::compile($path, $source);
                     File::put($newFile, $compiledContent);
                 }
                 $body = str_replace($tag, str_replace("stylesheet/less", "stylesheet", str_replace($source, str_replace(PIMCORE_DOCUMENT_ROOT, "", $newFile), $tag)), $body);
             }
         }
     }
     return $body;
 }
All Usage Examples Of Pimcore\File::getValidFilename