mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Simplify code to bound integer values
Suggested-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
parent
a48739508c
commit
cf4ea0171e
3 changed files with 19 additions and 20 deletions
|
@ -21,19 +21,13 @@ if (!isset($base_id)) {
|
|||
|
||||
/* Sanitize paging variables. */
|
||||
if (isset($_GET['O'])) {
|
||||
$_GET['O'] = intval($_GET['O']);
|
||||
if ($_GET['O'] < 0)
|
||||
$_GET['O'] = 0;
|
||||
$_GET['O'] = max(intval($_GET['O']), 0);
|
||||
} else {
|
||||
$_GET['O'] = 0;
|
||||
}
|
||||
|
||||
if (isset($_GET["PP"])) {
|
||||
$_GET["PP"] = intval($_GET["PP"]);
|
||||
if ($_GET["PP"] < 50)
|
||||
$_GET["PP"] = 50;
|
||||
else if ($_GET["PP"] > 250)
|
||||
$_GET["PP"] = 250;
|
||||
$_GET["PP"] = bound(intval($_GET["PP"]), 50, 250);
|
||||
} else {
|
||||
$_GET["PP"] = 50;
|
||||
}
|
||||
|
|
|
@ -584,3 +584,16 @@ function array_pkgbuild_merge($pkgbase_info, $section_info) {
|
|||
}
|
||||
return $pi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bound an integer value between two values
|
||||
*
|
||||
* @param int $n Integer value to bound
|
||||
* @param int $min Lower bound
|
||||
* @param int $max Upper bound
|
||||
*
|
||||
* @return int Bounded integer value
|
||||
*/
|
||||
function bound($n, $min, $max) {
|
||||
return min(max($n, $min), $max);
|
||||
}
|
||||
|
|
|
@ -519,22 +519,14 @@ function pkg_search_page($SID="") {
|
|||
|
||||
/* Sanitize paging variables. */
|
||||
if (isset($_GET['O'])) {
|
||||
$_GET['O'] = intval($_GET['O']);
|
||||
if ($_GET['O'] < 0)
|
||||
$_GET['O'] = 0;
|
||||
}
|
||||
else {
|
||||
$_GET['O'] = max(intval($_GET['O']), 0);
|
||||
} else {
|
||||
$_GET['O'] = 0;
|
||||
}
|
||||
|
||||
if (isset($_GET["PP"])) {
|
||||
$_GET["PP"] = intval($_GET["PP"]);
|
||||
if ($_GET["PP"] < 50)
|
||||
$_GET["PP"] = 50;
|
||||
else if ($_GET["PP"] > 250)
|
||||
$_GET["PP"] = 250;
|
||||
}
|
||||
else {
|
||||
$_GET["PP"] = bound(intval($_GET["PP"]), 50, 250);
|
||||
} else {
|
||||
$_GET["PP"] = 50;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue