Shorten a filename for display.

@param string $filename

@return string
505603
private function getShortPath($filename)
    {
        if (getcwd() === dirname($filename)) {
            return basename($filename);
        }
        $homeDir = Filesystem::getHomeDirectory();
        if (strpos($filename, $homeDir) === 0) {
            return str_replace($homeDir, '~', $filename);
        }

        return $filename;
    }
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;
    }
1148772
protected function createFullFilePath($fileName)
    {
        $tempPath = $this->documentConfig->getTempPath();

        if (!is_dir($tempPath)) {
            mkdir($tempPath, 777, true);
        }

        return sprintf('%s/%s', $tempPath, $fileName);
    }
540830
public static function split($fileName)
    {
        $ext = pathinfo($fileName);
        return [
            $ext['dirname'],
            $ext['filename'],
            empty($ext['extension']) ? '' : $ext['extension']
        ];
    }
35821
protected function getTitleFromFilename(string $filename)
    {
        $withoutExtension = pathinfo($filename, PATHINFO_FILENAME);
        return $withoutExtension !== '' ? $withoutExtension : $filename;
    }
787457
protected function shortName($name)
    {
        $name = str_replace('_', ' ', $name);
        $name = ucwords($name);

        return str_replace(' ', '', $name);
    }
46813
public function typeOfName($fileName)
    {
        $this->loadBaseSetIfNotLoaded();
        $extension = $this->extensionOfName($fileName);

        if (isset($this->typeByExtension[$extension])) {
            return $this->typeByExtension[$extension];
        }

        if ($this->extendedSetLoaded) {
            return '';
        }

        $this->loadExtendedSet();

        $this->extendedSetLoaded = true;

        return $this->typeOfName($fileName);
    }
506807
public function getPathFromFile($filename)
	{
		$i = strrpos($filename, self::getSlash());

		if ($i!== false)
		{
			return substr($filename, 0, $i);
		}
		else
		{
			return $filename;
		}
	}
86989
protected function _fileNameToId($fileName)
    {
        $instance = self::getInstance();
        $prefix = $instance->_options['file_name_prefix'];
        return preg_replace('/^' . $prefix . '---(.*)$/', '$1', $fileName);
    }
499912
public static function append_suffix($filename) {
        debugging('The function repository::append_suffix() has been deprecated. Use repository::get_unused_filename() instead.',
            DEBUG_DEVELOPER);
        $pathinfo = pathinfo($filename);
        if (empty($pathinfo['extension'])) {
            return $filename . RENAME_SUFFIX;
        } else {
            return $pathinfo['filename'] . RENAME_SUFFIX . '.' . $pathinfo['extension'];
        }
    }
832912
public static function sanitize_filename($filename, $max_length = 50) {
		$parts = pathinfo($filename);
		$slugify = new \Cocur\Slugify\Slugify();
		$basename = $slugify->slugify($parts['filename']);
		if (isset($parts['extension'])) {
			$extension = $slugify->slugify($parts['extension']);
			$filename = substr($basename, 0, $max_length-strlen($extension)) . '.' . $extension;
		} else {
			$filename = $basename;
		}
		return $filename;
	}
253015
public function get_short_filename($str, $maxlength) {
        if (core_text::strlen($str) >= $maxlength) {
            return trim(core_text::substr($str, 0, $maxlength)).'...';
        } else {
            return $str;
        }
    }
1114454
public function getUniqueFilename($filename)
    {
        $info = pathinfo($filename);
        $name = $info['filename'];
        $ext = isset($info['extension']) ? '.'.$info['extension'] : '';
        for ($i = 1; file_exists($info['dirname'].'/'.$name.$ext); ++$i) {
            $name = $info['filename'].'['.$i.']';
        }

        return $info['dirname'].'/'.$name.$ext;
    }
874681
public function getFileDirPrefix($filename)
    {
        if (empty($filename)) {
            throw new InvalidArgumentException('Invalid filename argument');
        }

        $path = array();
        $parts = explode('.', $filename);

        for ($i = 0; $i < min(strlen($parts[0]), $this->prefixSize); $i++) {
            $path[] = $filename[$i];
        }

        $path = $this->getPath($path);

        return $path;
    }
493130
public function sanitizeFilename($filename)
    {
        // Remove blacklisted caharacters
        $blacklist = ['/', '\\', '\0', '*', ':', '?', '"', '<', '>', '|', '#', '&', '!', '`', ' '];
        $filename  = str_replace($blacklist, '_', $filename);

        // Avoid hidden file
        $filename = ltrim($filename, '.');

        return $filename;
    }
588921
public function shortName($name = null)
    {
        if ($name === null) {
            return $this->_nameShort;
        }
        $this->_nameShort = $name;

        return $this;
    }
1205321
public function getFullPath($filename = null)
    {
        if (!$filename) {
            $filename = $this->Filename;
        }
        return DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $this->Folder . DIRECTORY_SEPARATOR . $filename;
    }