Use validation function in Qra lib and extend by bogus grid detection

This commit is contained in:
phl0
2025-11-10 00:11:17 +01:00
parent 1e50d4c2f9
commit 15a5640e79
2 changed files with 10 additions and 0 deletions

View File

@@ -50,6 +50,11 @@ class Callbook {
if (! array_key_exists('geoloc', $callbook)) {
$callbook['geoloc'] = '';
}
// qrz.com gives AA00aa if the user deleted his grid from the profile
$this->ci->load->library('qra');
if (!$this->ci->qra->validate_grid($callbook['gridsquare'])) {
$callbook['gridsquare'] = '';
}
return $callbook;
}

View File

@@ -201,6 +201,10 @@ class Qra {
}
function validate_grid($grid) {
// (Try to) Detect placeholders like AA00aa (returned from qrz.com for example)
if (strlen($grid) == 6 && strtoupper($grid) == 'AA00AA') {
return false;
}
// Allow 6-digit locator
if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Za-z]{2}$/', $grid)) return true;
// Allow 4-digit locator
@@ -215,6 +219,7 @@ class Qra {
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Za-z]{2}[0-9]{2}$/', $grid)) return true;
// Allow 10-digit locator
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Za-z]{2}[0-9]{2}[A-Za-z]{2}$/', $grid)) return true;
return false;
}
}