Browse Source

add getDirectoryPathByUri, getDirectoryUriByPath methods

main
ghost 10 months ago
parent
commit
dbd5820c92
  1. 2
      README.md
  2. 63
      src/Dokuwiki/Filesystem.php

2
README.md

@ -136,6 +136,7 @@ var_dump (
) )
``` ```
#### Filesystem::getDirectoryPathByUri
#### Filesystem::getPagePathByUri #### Filesystem::getPagePathByUri
Return absolute path to stored page file Return absolute path to stored page file
@ -148,6 +149,7 @@ var_dump (
) )
``` ```
#### Filesystem::getDirectoryUriByPath
#### Filesystem::getPageUriByPath #### Filesystem::getPageUriByPath
Return page URI in `dokuwiki:format` Return page URI in `dokuwiki:format`

63
src/Dokuwiki/Filesystem.php

@ -68,7 +68,7 @@ class Filesystem
'%s/pages/', '%s/pages/',
$this->_path $this->_path
), ),
null, '',
$path $path
); );
@ -93,9 +93,68 @@ class Filesystem
$path $path
); );
return urlencode( return $path;
}
public function getDirectoryPathByUri(string $uri = ''): ?string
{
$path = rtrim(
sprintf(
'%s/pages/%s',
$this->_path,
str_replace(
':',
'/',
mb_strtolower(
urldecode(
$uri
)
)
)
),
'/'
);
if (!isset($this->_tree[$path]) || !is_dir($path) || !is_readable($path))
{
return null;
}
return $path;
}
public function getDirectoryUriByPath(string $path): ?string
{
if (!isset($this->_tree[$path]) || !is_dir($path) || !is_readable($path))
{
return null;
}
$path = str_replace(
sprintf(
'%s/pages/',
$this->_path
),
'',
$path
);
$path = trim(
$path,
'/'
);
$path = str_replace(
[
'/'
],
[
':'
],
$path $path
); );
return $path;
} }
private function _index(string $path): void private function _index(string $path): void

Loading…
Cancel
Save