diff --git a/includes/functions.php b/includes/functions.php index 2833564..d7ee59f 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -29,4 +29,42 @@ function userPath( return USERS_PATH . '/' . usernameToFolder($username); -} \ No newline at end of file +} + +function slug(string $value): string +{ + $value = strtolower(trim($value)); + + $value = preg_replace( + '/[^a-z0-9]+/', + '_', + $value + ); + + return trim($value, '_'); +} + +function languagePath( + string $user, + string $language +): string { + + return userPath($user) + . '/languages/' + . slug($language); +} + +function listPath( + string $user, + string $language, + string $list +): string { + + return languagePath( + $user, + $language + ) + . '/lists/' + . slug($list) + . '.json'; +}