[Callbook] Added qrz.ru support

This commit is contained in:
Andreas Kristiansen
2025-02-03 10:06:07 +01:00
parent d9a7ad2768
commit 024f2e0aff
2 changed files with 164 additions and 0 deletions

View File

@@ -40,6 +40,13 @@ class Callbook {
}
return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign);
break;
case 'qrzru':
if ($this->ci->config->item('qrzru_username') == null || $this->ci->config->item('qrzru_password') == null) {
$callbook['error'] = 'Lookup not configured. Please review configuration.';
return $callbook;
}
return $this->qrzru($this->ci->config->item('qrzru_username'), $this->ci->config->item('qrzru_password'), $callsign);
break;
default:
$callbook['error'] = 'No callbook defined. Please review configuration.';
return $callbook;
@@ -134,6 +141,38 @@ class Callbook {
return $callbook;
}
function qrzru($username, $password, $callsign) {
if (!$this->ci->load->is_loaded('qrzcq')) {
$this->ci->load->library('qrzru');
}
if (!$this->ci->session->userdata('qrzru_session_key')) {
$result = $this->ci->qrzru->session($username, $password);
if ($result[0] == 0) {
$this->ci->session->set_userdata('qrzru_session_key', $result[1]);
} else {
$data['error'] = __("QRZ.RU Error").": ".$result[1];
return $data;
}
}
$callbook = $this->ci->qrztu->search($callsign, $this->ci->session->userdata('qrzru_session_key'));
if ($callbook['error'] ?? '' == 'Invalid session key') {
$qrzru_session_key = $this->ci->qrzru->session($username, $password);
$this->ci->session->set_userdata('qrzru_session_key', $qrzru_session_key);
$callbook = $this->ci->qrzru->search($callsign, $this->ci->session->userdata('qrzru_session_key'));
}
if (strpos($callbook['error'] ?? '', 'Callsign not found') !== false && strpos($callsign, "/") !== false) {
$plaincall = $this->get_plaincall($callsign);
// Now try again but give back reduced data, as we can't validate location and stuff (true at the end)
$callbook = $this->ci->qrzru->search($plaincall, $this->ci->session->userdata('qrzru_session_key'), true);
}
return $callbook;
}
function get_plaincall($callsign) {
$split_callsign = explode('/', $callsign);
if (count($split_callsign) == 1) { // case F0ABC --> return cel 0 //