summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2025-07-14 16:50:29 +0200
committerSimon Rettberg2025-07-14 16:50:29 +0200
commit83c4bb160cea6e7fbadbe4c0876b754f0acf24c5 (patch)
tree96b8955da109cd15998e3a84699abb11627cb2c3 /inc
parent[locationinfo] Remove debug spam (diff)
downloadslx-admin-83c4bb160cea6e7fbadbe4c0876b754f0acf24c5.tar.gz
slx-admin-83c4bb160cea6e7fbadbe4c0876b754f0acf24c5.tar.xz
slx-admin-83c4bb160cea6e7fbadbe4c0876b754f0acf24c5.zip
[locationinfo] Add UPCOMING panel type
Diffstat (limited to 'inc')
-rw-r--r--inc/dictionary.inc.php10
-rw-r--r--inc/render.inc.php18
-rw-r--r--inc/request.inc.php40
3 files changed, 68 insertions, 0 deletions
diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php
index 3a2f9c2b..f95cb384 100644
--- a/inc/dictionary.inc.php
+++ b/inc/dictionary.inc.php
@@ -283,6 +283,16 @@ class Dictionary
return $img;
}
+ /**
+ * Check if the provided language code is supported.
+ * @param string $lang Language code to check
+ * @return bool True if the language code exists in the predefined language array, false otherwise
+ */
+ public static function hasLanguage(string $lang): bool
+ {
+ return in_array($lang, self::$languages);
+ }
+
}
Dictionary::init();
diff --git a/inc/render.inc.php b/inc/render.inc.php
index a636382e..d22379bb 100644
--- a/inc/render.inc.php
+++ b/inc/render.inc.php
@@ -311,4 +311,22 @@ class Render
return sprintf("#%02x%02x%02x", ($chans[0] + $b) / 3, ($chans[1] + $b) / 3, ($chans[2] + $b) / 3);
}
+ /**
+ * Mangle fields in the params array based on the checked fields.
+ * $checked is a list of field names that will be checked for true-ness
+ * in $params, and for each matching field name, a new key named "{$field}_checked"
+ * will be added to $params with value 'checked'.
+ *
+ * @param string[] &$params The array of parameters to be modified
+ * @param string[] $checked The array of fields to check for true-ness
+ */
+ public static function mangleFields(array &$params, array $checked): void
+ {
+ foreach ($checked as $field) {
+ if (($params[$field] ?? false)) {
+ $params[$field . '_checked'] = 'checked';
+ }
+ }
+ }
+
}
diff --git a/inc/request.inc.php b/inc/request.inc.php
index 3f1d96c6..0b0600da 100644
--- a/inc/request.inc.php
+++ b/inc/request.inc.php
@@ -99,4 +99,44 @@ class Request
return $array[$key];
}
+ /**
+ * Processes post parameters based on specified limits and assigns the processed values to the output array.
+ * $params is expected to have one or more keys specifying a type (int, string, ...), and each of them
+ * an array with field name as key, and then an array as value that can have optional
+ * keys 'default', 'min' and 'max', as well as 'enum' (array of allowed values).
+ *
+ * @param array $out Reference to an array where the processed parameter values will be stored.
+ * @param array $params An array containing the parameters to be processed, their types, and limits.
+ */
+ public static function processPostParameters(array &$out, array $params, ?string $source = 'POST'): void
+ {
+ if ($source === 'GET') {
+ $input =& $_GET;
+ } elseif ($source === 'POST') {
+ $input =& $_POST;
+ } elseif ($source === 'REQUEST') {
+ $input =& $_REQUEST;
+ } elseif ($source === null) {
+ $input = [];
+ } else {
+ ErrorHandler::traceError("Invalid parameter source: '$source'");
+ }
+ foreach ($params as $type => $list) {
+ foreach ($list as $field => $limits) {
+ $default = $limits['default'] ?? false;
+ $value = self::handle($input, $field, $default, $type);
+ if (isset($limits['min']) && $value < $limits['min']) {
+ $value = $limits['min'];
+ }
+ if (isset($limits['max']) && $value > $limits['max']) {
+ $value = $limits['max'];
+ }
+ if (isset($limits['enum']) && !in_array($value, $limits['enum'])) {
+ $value = array_shift($limits['enum']);
+ }
+ $out[$field] = $value;
+ }
+ }
+ }
+
}