summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/inc/locationinfo.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2024-11-14 11:54:19 +0100
committerSimon Rettberg2024-11-14 11:54:19 +0100
commit5bb86e9dfa62ba1061a0da77ec3353aa509f8776 (patch)
treeaaeba0305be4084688d565d7b0dd4618381a5956 /modules-available/locationinfo/inc/locationinfo.inc.php
parent[locationinfo] BRAINDEAD (diff)
downloadslx-admin-5bb86e9dfa62ba1061a0da77ec3353aa509f8776.tar.gz
slx-admin-5bb86e9dfa62ba1061a0da77ec3353aa509f8776.tar.xz
slx-admin-5bb86e9dfa62ba1061a0da77ec3353aa509f8776.zip
[locationinfo] Put upgrade/cleanup code in distinct function and extend
Diffstat (limited to 'modules-available/locationinfo/inc/locationinfo.inc.php')
-rw-r--r--modules-available/locationinfo/inc/locationinfo.inc.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/modules-available/locationinfo/inc/locationinfo.inc.php b/modules-available/locationinfo/inc/locationinfo.inc.php
index 1165164d..a46208c6 100644
--- a/modules-available/locationinfo/inc/locationinfo.inc.php
+++ b/modules-available/locationinfo/inc/locationinfo.inc.php
@@ -237,4 +237,41 @@ class LocationInfo
return '';
}
+
+ /**
+ * Transform legacy url filter config if found, remove no-op filter setups.
+ * @param array $config The configuration array to be cleaned up. By reference.
+ */
+ public static function cleanupUrlFilter(array &$config): void
+ {
+ // First, simple trimming of white-space around the list, and making sure the keys exist
+ $config['blacklist'] = trim($config['blacklist'] ?? '');
+ $config['whitelist'] = trim($config['whitelist'] ?? '');
+ if (empty($config['blacklist']) && empty($config['whitelist'])) {
+ // Mangle non-upgraded configurations: They only have one list and a bool specifying if it's a black- or whitelist
+ if (!empty($config['urllist'])) {
+ if ($config['iswhitelist'] ?? false) {
+ $config['whitelist'] = str_replace(' ', "\n", $config['urllist']);
+ } else {
+ $config['blacklist'] = str_replace(' ', "\n", $config['urllist']);
+ }
+ unset($config['urllist'], $config['iswhitelist']);
+ }
+ } elseif ((empty($config['blacklist']) || self::isAnyUrlMatch($config['blacklist']))
+ && self::isAnyUrlMatch($config['whitelist'])) {
+ // Blocking everything/nothing and allowing everything is a no-op for all three browsers, so clear both lists
+ $config['blacklist'] = '';
+ $config['whitelist'] = '';
+ }
+ }
+
+ /**
+ * Check if the given pattern would be interpreted as matching any URL.
+ * @param string $url The URL to check
+ */
+ private static function isAnyUrlMatch(string $url): bool
+ {
+ return $url === '*' || $url === '*://*' || $url === '*://*/' || $url === '*://*/*';
+ }
+
}