mirror of
https://github.com/YGGverse/gemini-dl.git
synced 2026-04-01 09:35:35 +00:00
make absolute filename in links optional and disabled by default
This commit is contained in:
parent
4c478c2e88
commit
84e3d223d5
6 changed files with 102 additions and 21 deletions
|
|
@ -174,4 +174,70 @@ class Filesystem
|
|||
$data
|
||||
);
|
||||
}
|
||||
|
||||
// Helpers
|
||||
public static function getFilenameRelativeToDirname(
|
||||
string $filename,
|
||||
string $dirname
|
||||
): string
|
||||
{
|
||||
// Validate paths
|
||||
if (empty($filename))
|
||||
{
|
||||
throw new \Exception(
|
||||
'Filename is could not be empty'
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($dirname))
|
||||
{
|
||||
throw new \Exception(
|
||||
'Dirname is could not be empty'
|
||||
);
|
||||
}
|
||||
|
||||
if (str_starts_with($filename, $dirname))
|
||||
{
|
||||
return ltrim(
|
||||
str_replace(
|
||||
$dirname,
|
||||
DIRECTORY_SEPARATOR,
|
||||
$filename
|
||||
),
|
||||
DIRECTORY_SEPARATOR
|
||||
);
|
||||
}
|
||||
|
||||
$filepath = explode(
|
||||
DIRECTORY_SEPARATOR,
|
||||
dirname(
|
||||
$filename
|
||||
)
|
||||
);
|
||||
|
||||
$segments = [];
|
||||
|
||||
foreach (
|
||||
explode(
|
||||
DIRECTORY_SEPARATOR,
|
||||
$dirname
|
||||
) as $level => $directory)
|
||||
{
|
||||
if (isset($filepath[$level]) && $filepath[$level] == $directory)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$segments[] = '..';
|
||||
}
|
||||
|
||||
$segments[] = basename(
|
||||
$filename
|
||||
);
|
||||
|
||||
return implode(
|
||||
DIRECTORY_SEPARATOR,
|
||||
$segments
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue