Makes the file name safe to use

@param   string  $file        The name of the file [not full path]
@param   array   $stripChars  Array of regex (by default will remove any leading periods)

@return  string  The sanitised string

@since   1.0
512604
public static function makeSafe($file, array $stripChars = array('#^\.#'))
	{
		$regex = array_merge(array('#(\.){2,}#', '#[^A-Za-z0-9\.\_\- ]#'), $stripChars);

		$file = preg_replace($regex, '', $file);

		// Remove any trailing dots, as those aren't ever valid file names.
		$file = rtrim($file, '.');

		return $file;
	}
457449
protected function _replaceAttrLinks($file, $str)
    {
        return preg_replace_callback('#(\s+(?:href|src|data-src|action)=["\'])([\w-/:.]+)#', function ($match) use ($file) {
            return $match[1] . $this->_completeRelativeLinks($file, $match[2]);
        }, $str);
    }
988206
public function ascii($file = null)
    {
        $file = $file ? $file : $this->cacheFileName;

        $asciiArt = new CAsciiArt();
        $asciiArt->setOptions($this->asciiOptions);
        return $asciiArt->createFromFile($file);
    }
1051903
protected final function resolveResource($file)
	{
		if(0 === strpos($file, './') || 0 === strpos($file, '../'))
		{
			$file = rtrim(dirname($this->getResource()), '/\\') . '/' . $file;
		}
		elseif(!preg_match("'^/|(?:[^:]+://)|(?:[a-z]:[\\\\/])'i", $file))
		{
			$dir = rtrim(dirname($this->getResource()), '/\\');
			$file = $dir . '/' . ltrim($file, '/\\');
		}
		
		return (string)$file;
	}
758459
public function get_mime($file){
        $type = $this->get_content_type($file);
        if( $type ){
            $type = array_map('trim', explode(';', $type));
            return $type[0];
        }else{
            return '';
        }
    }
1152899
private function getMaskedFileName($file, $format = '.php')
    {
        return $this->getConfig('cache_folder') .  self::cacheFilePrefix . '.' . $this->fileName . strtoupper(substr(md5($file), -19)) . $format;
    }
1047749
public function sanitize_filename($str, $relative_path = FALSE) {
		$bad = array("../", "<!--", "-->", "<", ">", "'", '"', '&', '$', '#', '{', '}', '[', ']', '=', ';', '?', "%20", "%22", "%3c", 		// <
		"%253c", 		// <
		"%3e", 		// >
		"%0e", 		// >
		"%28", 		// (
		"%29", 		// )
		"%2528", 		// (
		"%26", 		// &
		"%24", 		// $
		"%3f", 		// ?
		"%3b", 		// ;
		"%3d")		// =
		;
		
		if (!$relative_path) {
			$bad[] = './';
			$bad[] = '/';
		}
		
		$str = $this->remove_invisible_characters($str, FALSE);
		return stripslashes(str_replace($bad, '', $str));
	}
888266
public static function safeFilename($filename)
    {
        Deprecated::method(3.0);

        $filename = rawurlencode($filename); // Use 'rawurlencode', because we prefer '%20' over '+' for spaces.
        $filename = str_replace('%2F', '/', $filename);

        if (substr($filename, 0, 1) == '/') {
            $filename = substr($filename, 1);
        }

        return $filename;
    }
106424
public static function stripQueryString($path)
    {
        $qMark = strpos($path, '?');

        if ($qMark !== false) {
            return substr($path, 0, $qMark);
        }

        return $path;
    }
822243
public static function reglace(String $file, $pattern, $replace) : String
    {
        $file = Info::rpath($file);

        if( ! is_file($file))
        {
            throw new Exception\FileNotFoundException(NULL, $file);
        }

        $contents        = file_get_contents($file);
        $replaceContents = Regex::replace($pattern, $replace, $contents);

        if( $contents !== $replaceContents )
        {
            file_put_contents($file, $replaceContents);
        }

        return $replaceContents;
    }
971609
public static function trimFileName($path)
    {
        $name = static::nameFromPath($path);

        return substr($path, 0, strlen($path) - strlen($name));
    }
552317
public function withFile($file, $reset=false)
    {
        $file = str_replace('\\', '/', $file);
        if ($pos = strripos($file, $this->getOption('file_ext'))) {
            $file = substr($file, 0, $pos-1);
        }
        $dir = dirname($file);
        if (!isset(static::$instances[$dir])) {
            $instance = new static($this->options);
            $instance->setOption('file', $file);
            static::$instances[$dir] = $instance;
        }
        
        if ($reset) {
            $key = static::$instances[$dir]->getOption('file');
            static::$instances[$dir]->remove($key);
            static::$instances[$dir]->remove($key . '.error');
        }
        
        return static::$instances[$dir];
    }
497023
public static function getExtension($file){

		$file = trim($file);
		$extension = strtolower(substr(strrchr($file, '.'), 1));

		if($extension == $file){

			return '';
		}
		else{

			return $extension;
		}
	}
932749
private function getRealFilename(string $file): string
    {
        if (strpos($file, 'vfs://') !== false) {
            return $file;
        }

        return $this->loader->getSourceContext($file)->getPath();
    }
406779
public static function filename($file, $last = true) {
        $pos = false;
        if ($last) {
            $pos = strrpos($file, '.');
        }
        else {
            $pos = strpos($file, '.');
        }
        if ($pos === false) {
            return $file;
        }
        return substr($file, 0, $pos);
    }
876771
public function sanitizeFilename()
	{
		// Regex for replacing special chars
		$filename = $this->filename;
		$filename = preg_replace('/\s+/', '_', $filename);
		$filename = preg_replace('/[^a-z1-9\.\-\_]/i', '', $filename);
		// removes any dots except the last one.
		$filename = preg_replace('/\.(?=.*?\.)/', '', $filename);
		$this->filename = $filename;

		return $this;
	}
720420
public function addFile($file, $strip = true)
    {
        $realfile = realpath($this->path . DIRECTORY_SEPARATOR . $file);
        $this->files[$file] = [$realfile, (bool) $strip];
    }