diff --git a/engine/logging.php b/engine/logging.php index 4d42603..d81100b 100644 --- a/engine/logging.php +++ b/engine/logging.php @@ -230,11 +230,11 @@ class DatabaseLogger extends Logger { } } -function getPHPErrorName(int $errno): string { +function getPHPErrorName(int $errno): ?string { static $errors = null; if (is_null($errors)) $errors = array_flip(array_slice(get_defined_constants(true)['Core'], 0, 15, true)); - return $errors[$errno]; + return $errors[$errno] ?? null; } function strVarDump($var, bool $print_r = false): string { diff --git a/engine/request.php b/engine/request.php index b4d160d..a610fde 100644 --- a/engine/request.php +++ b/engine/request.php @@ -223,4 +223,15 @@ function csrf_get(string $key): string { function csrf_check(string $key) { if (csrf_get($key) != ($_REQUEST['token'] ?? '')) forbidden('invalid token'); +} + +function get_page(int $per_page, ?int $count = null): array { + list($page) = input('i:page'); + $pages = $count !== null ? ceil($count / $per_page) : null; + if ($pages !== null && $page > $pages) + $page = $pages; + if ($page < 1) + $page = 1; + $offset = $per_page * ($page-1); + return [$page, $pages, $offset]; } \ No newline at end of file diff --git a/engine/router.php b/engine/router.php index 3dd1924..c1ec2ef 100644 --- a/engine/router.php +++ b/engine/router.php @@ -1,6 +1,6 @@ SkinStringModificationType::URL, 'jsonencoded' => SkinStringModificationType::JSON, 'addslashes' => SkinStringModificationType::ADDSLASHES, + 'nl2br' => SkinStringModificationType::NL2BR, default => SkinStringModificationType::HTML }; } else { @@ -222,6 +223,69 @@ class SkinContext { return '