diff --git a/README.md b/README.md index 4d5bea5..24da7a4 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,18 @@ var_dump ( ); ``` +#### Filesystem::getMediaPathByUri + +Return absolute path to stored media file + +``` +var_dump ( + $filesystem->getMediaPathByUri( + 'hello:world' + ) +); +``` + #### Filesystem::getData Return file content if path match storage item diff --git a/src/Dokuwiki/Filesystem.php b/src/Dokuwiki/Filesystem.php index 6972e36..49c7d5b 100644 --- a/src/Dokuwiki/Filesystem.php +++ b/src/Dokuwiki/Filesystem.php @@ -163,7 +163,31 @@ class Filesystem return $path; } - public function getData(string $path): ?string + public function getMediaPathByUri(string $uri): ?string + { + $path = sprintf( + '%s/media/%s', + $this->_path, + str_replace( + ':', + '/', + mb_strtolower( + urldecode( + $uri + ) + ) + ) + ); + + if (!in_array($path, $this->_list) || !is_file($path) || !is_readable($path)) + { + return null; + } + + return $path; + } + + public function getData(?string $path): ?string { if (in_array($path, $this->_list) && is_file($path) || is_readable($path)) {