Generate the fullpath to the cache file based on the passed filename.

@param string $filename The filename specified to store the cache in

@return string
519875
public static function path($filename)
    {
        if ($filename[0] != "/") {
            $filename = static::$path . "/" . $filename;
        }

        if (substr($filename, -5) != ".json") {
            $filename .= ".json";
        }

        $path = pathinfo($filename, PATHINFO_DIRNAME);

        # Ensure the cache directory exists
        if (!is_dir($path)) {
            if (!mkdir($path, 0777, true)) {
                throw new \Exception("Unable to create cache directory (" . $path . ")");
            }
        }

        # Ensure directory is writable
        if (!is_writable($path)) {
            if (!chmod($path, 0777)) {
                throw new \Exception("Cache directory (" . $path . ") is not writable");
            }
        }

        return $filename;
    }
891892
public static function filename2url($filename)
    {
        $filename = realpath($filename);
        if (!$filename) {
            return null;
        }

        // Filter files outside of the webroot
        $base = realpath(BASE_PATH);
        $baseLength = strlen($base);
        if (substr($filename, 0, $baseLength) !== $base) {
            return null;
        }

        $relativePath = ltrim(substr($filename, $baseLength), '/\\');
        return Director::absoluteURL($relativePath);
    }
519154
private function getSubPath($filename)
    {
        $subpath = '';
        $rule = $this->subName;
        if ($this->autoSub && !empty($rule)) {
            $subpath = $this->getName($rule, $filename) . '/';
            if (!empty($subpath) && !$this->uploader->mkdir($this->savePath . $subpath)) {
                $this->error = $this->uploader->getError();

                return false;
            }
        }

        return $subpath;
    }
132343
public function getFile($filename)
    {
        $filename = $this->outDir.DIRECTORY_SEPARATOR.$filename;
        $this->mkdir(dirname($filename));
        if (is_file($filename) && $this->backup) {
            @rename($filename, sprintf('%s.bak', $filename));
        }

        return $filename;
    }
1012052
protected function extensionOfName($fileName)
    {
        if (mb_strpos($fileName, '.') === false) {
            return mb_strtolower($fileName);
        }

        return mb_strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
    }
882590
private function generateNewTmpPath($fileName)
    {
        $folder = sys_get_temp_dir().DIRECTORY_SEPARATOR."tmp".md5($fileName. uniqid('', true)).DIRECTORY_SEPARATOR;

        if (!file_exists($folder)) {
            mkdir($folder);
        }

        $this->tmpDir = $folder;
    }
885466
private function buildFilePath($fileName)
    {
        $digest = md5($fileName);

        $path = $this->basePath . '/' . substr($digest, 0, 1) . '/' . substr($digest, 1, 1);

        if (!is_dir($path)) {
            mkdir($path, 0777, true);
        }

        return $path . '/' . $fileName;
    }
1246179
private function getDirectoryPathByHash($filename)
    {
        //get 2 number
        $val1 = ord($filename[1]);
        $val2 = ord($filename[3]);

        //normalize to 99
        $val1 %= 99;
        $val2 %= 99;
        return $val1 . '/' . $val2 . '/';
    }
897845
public function getTemplatePath($templateName)
    {
        $fileName = "$templateName.php";
        foreach ($this->paths as $path) {
            $fullPath = $path . DIRECTORY_SEPARATOR . $fileName;
            if (is_file($fullPath)) {
                return $fullPath;
            }
        }
        return false;
    }
440645
private function createPublicCacheFile(string $fileName, string $content): string
    {
        $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
        if (empty($extension)) {
            $extension = 'cache';
        }

        $name = pathinfo($fileName, PATHINFO_FILENAME);
        $checksum = sha1($fileName . $content);
        $cacheFile = $this->directory . '/' . $name . '.' . $checksum . '.' . $extension;

        file_put_contents($cacheFile, $content);

        if ($this->chmod > -1) {
            chmod($cacheFile, $this->chmod);
        }

        return $cacheFile;
    }
1213116
public function getMediaPath($fileName)
    {
        // If this is an external link to a media file, just return string
        if (stripos($fileName, 'http') === 0 || empty($fileName)) {
            return $fileName;
        }

        return ($this->container->filePath)($fileName) . $fileName;
    }
202327
public function filename($filename = null)
    {
        if ($filename === null) {
            return $this->_filename;
        }
        $this->_filename = $filename;
    }
86989
protected function _fileNameToId($fileName)
    {
        $instance = self::getInstance();
        $prefix = $instance->_options['file_name_prefix'];
        return preg_replace('/^' . $prefix . '---(.*)$/', '$1', $fileName);
    }
728389
protected function getContent(string $filename): string
    {
        return \file_get_contents($this->getSafepath($this->rootDir . DIRECTORY_SEPARATOR . $filename));
    }
985569
private function getFilePath()
    {
        $fullname = $this->fullName;
        $rootPath = $_SERVER['DOCUMENT_ROOT'];

        if (substr($fullname, 0, 1) != '/') {
            $fullname = '/' . $fullname;
        }

        return $rootPath . $fullname;
    }
114340
public function buildThumbFilename($filename)
	{
		$extension = pathinfo($filename, PATHINFO_EXTENSION);

		if (! $extension) {

			$filename .= '.' . pathinfo($this->relative, PATHINFO_EXTENSION);
		}

		return $this->getThumbFolder() . '/' . $filename;
	}
1148772
protected function createFullFilePath($fileName)
    {
        $tempPath = $this->documentConfig->getTempPath();

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

        return sprintf('%s/%s', $tempPath, $fileName);
    }