Files
woordjes/includes/functions.php
T
2026-06-15 12:06:16 +02:00

84 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
function sanitize(string $value): string
{
return htmlspecialchars(
trim($value),
ENT_QUOTES,
'UTF-8'
);
}
function usernameToFolder(
string $username
): string {
return preg_replace(
'/[^a-zA-Z0-9_-]/',
'',
strtolower($username)
);
}
function userPath(
string $username
): string {
return USERS_PATH .
'/' .
usernameToFolder($username);
}
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';
}
function calculateNextInterval(array $word, bool $correct): int
{
$correctCount = $word['correct'] ?? 0;
if (!$correct) {
return 1;
}
// gecontroleerde groei (SM-lite)
$interval = 1 + ($correctCount * 2);
return min(30, $interval);
}