mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Implemented reduced call
This commit is contained in:
@@ -18,32 +18,38 @@ class Callbook {
|
||||
// Implement the following:
|
||||
// - Implement callsign reduced logic
|
||||
public function getCallbookData($callsign) {
|
||||
$reduced = false;
|
||||
|
||||
if (strpos($callsign, "/") !== false) {
|
||||
$reduced = true;
|
||||
}
|
||||
|
||||
switch ($this->ci->config->item('callbook')) {
|
||||
case 'qrz':
|
||||
if ($this->ci->config->item('qrz_username') == null || $this->ci->config->item('qrz_password') == null) {
|
||||
$callbook['error'] = 'Lookup not configured. Please review configuration.';
|
||||
return $callbook;
|
||||
}
|
||||
return $this->qrz($this->ci->config->item('qrz_username'), $this->ci->config->item('qrz_password'), $callsign, $this->ci->config->item('use_fullname'));
|
||||
return $this->qrz($this->ci->config->item('qrz_username'), $this->ci->config->item('qrz_password'), $callsign, $this->ci->config->item('use_fullname'), $reduced);
|
||||
break;
|
||||
case 'qrzcq':
|
||||
if ($this->ci->config->item('qrzcq_username') == null || $this->ci->config->item('qrzcq_password') == null) {
|
||||
$callbook['error'] = 'Lookup not configured. Please review configuration.';
|
||||
return $callbook;
|
||||
}
|
||||
return $this->qrzcq($this->ci->config->item('qrzcq_username'), $this->ci->config->item('qrzcq_password'), $callsign);
|
||||
return $this->qrzcq($this->ci->config->item('qrzcq_username'), $this->ci->config->item('qrzcq_password'), $callsign, $reduced);
|
||||
break;
|
||||
case 'hamqth':
|
||||
if ($this->ci->config->item('hamqth_username') == null || $this->ci->config->item('hamqth_password') == null) {
|
||||
$callbook['error'] = 'Lookup not configured. Please review configuration.';
|
||||
return $callbook;
|
||||
}
|
||||
return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign);
|
||||
return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign, $reduced);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function qrz($username, $password, $callsign, $fullname) {
|
||||
function qrz($username, $password, $callsign, $fullname, $reduced) {
|
||||
if (!$this->ci->load->is_loaded('qrz')) {
|
||||
$this->ci->load->library('qrz');
|
||||
}
|
||||
@@ -53,18 +59,24 @@ class Callbook {
|
||||
$this->ci->session->set_userdata('qrz_session_key', $qrz_session_key);
|
||||
}
|
||||
|
||||
$callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname);
|
||||
$callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname, $reduced);
|
||||
|
||||
if ($callbook['error'] ?? '' == 'Invalid session key') {
|
||||
$qrz_session_key = $this->ci->qrz->session($username, $password);
|
||||
$this->ci->session->set_userdata('qrz_session_key', $qrz_session_key);
|
||||
$callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname);
|
||||
$callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname, $reduced);
|
||||
}
|
||||
|
||||
if (strpos($callbook['error'] ?? '', '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->qrz->search($plaincall, $this->ci->session->userdata('qrz_session_key'), $fullname, true);
|
||||
}
|
||||
|
||||
return $callbook;
|
||||
}
|
||||
|
||||
function qrzcq($username, $password, $callsign) {
|
||||
function qrzcq($username, $password, $callsign, $reduced) {
|
||||
if (!$this->ci->load->is_loaded('qrzcq')) {
|
||||
$this->ci->load->library('qrzcq');
|
||||
}
|
||||
@@ -74,18 +86,24 @@ class Callbook {
|
||||
$this->ci->session->set_userdata('qrzcq_session_key', $qrzcq_session_key);
|
||||
}
|
||||
|
||||
$callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key'));
|
||||
$callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key'), $reduced);
|
||||
|
||||
if ($callbook['error'] ?? '' == 'Invalid session key') {
|
||||
$qrzcq_session_key = $this->ci->qrzcq->session($username, $password);
|
||||
$this->ci->session->set_userdata('qrzcq_session_key', $qrzcq_session_key);
|
||||
$callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key'));
|
||||
$callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key'), $reduced);
|
||||
}
|
||||
|
||||
if (strpos($callbook['error'] ?? '', '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->qrzcq->search($plaincall, $this->ci->session->userdata('qrzcq_session_key'), true);
|
||||
}
|
||||
|
||||
return $callbook;
|
||||
}
|
||||
|
||||
function hamqth($username, $password, $callsign) {
|
||||
function hamqth($username, $password, $callsign, $reduced) {
|
||||
// Load the HamQTH library
|
||||
if (!$this->ci->load->is_loaded('hamqth')) {
|
||||
$this->ci->load->library('hamqth');
|
||||
@@ -96,66 +114,39 @@ class Callbook {
|
||||
$this->ci->session->set_userdata('hamqth_session_key', $hamqth_session_key);
|
||||
}
|
||||
|
||||
$callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key'));
|
||||
$callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key'), $reduced);
|
||||
|
||||
// If HamQTH session has expired, start a new session and retry the search.
|
||||
if ($callbook['error'] == "Session does not exist or expired") {
|
||||
$hamqth_session_key = $this->ci->hamqth->session($username, $password);
|
||||
$this->ci->session->set_userdata('hamqth_session_key', $hamqth_session_key);
|
||||
$callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key'));
|
||||
$callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key'), $reduced);
|
||||
}
|
||||
|
||||
if (strpos($callbook['error'] ?? '', '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->hamqth->search($plaincall, $this->ci->session->userdata('hamqth_session_key'), true);
|
||||
}
|
||||
|
||||
return $callbook;
|
||||
}
|
||||
|
||||
function get_plaincall($callsign) {
|
||||
$split_callsign = explode('/', $callsign);
|
||||
if (count($split_callsign) == 1) { // case F0ABC --> return cel 0 //
|
||||
$lookupcall = $split_callsign[0];
|
||||
} else if (count($split_callsign) == 3) { // case EA/F0ABC/P --> return cel 1 //
|
||||
$lookupcall = $split_callsign[1];
|
||||
} else { // case F0ABC/P --> return cel 0 OR case EA/FOABC --> retunr 1 (normaly not exist) //
|
||||
if (in_array(strtoupper($split_callsign[1]), array('P', 'M', 'MM', 'QRP', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))) {
|
||||
$lookupcall = $split_callsign[0];
|
||||
} else if (strlen($split_callsign[1]) > 3) { // Last Element longer than 3 chars? Take that as call
|
||||
$lookupcall = $split_callsign[1];
|
||||
} else { // Last Element up to 3 Chars? Take first element as Call
|
||||
$lookupcall = $split_callsign[0];
|
||||
}
|
||||
}
|
||||
return $lookupcall;
|
||||
}
|
||||
}
|
||||
|
||||
// This is the one that needs to be implemented above:
|
||||
// if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) {
|
||||
// // Lookup using QRZ
|
||||
// $this->load->library('qrz');
|
||||
|
||||
// if (!$this->session->userdata('qrz_session_key')) {
|
||||
// $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password'));
|
||||
// $this->session->set_userdata('qrz_session_key', $qrz_session_key);
|
||||
// }
|
||||
|
||||
// $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'), $use_fullname);
|
||||
|
||||
// // We need to handle, if the sessionkey is invalid
|
||||
// if ($callbook['error'] ?? '' == 'Invalid session key') {
|
||||
// $this->qrz->set_session($this->config->item('qrz_username'), $this->config->item('qrz_password'));
|
||||
// $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'), $use_fullname);
|
||||
// }
|
||||
|
||||
// // If the callsign contains a slash we have a pre- or suffix. If then the result is "Not found" we can try again with the plain call
|
||||
// if (strpos($callbook['error'] ?? '', '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->qrz->search($plaincall, $this->session->userdata('qrz_session_key'), $use_fullname, true);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) {
|
||||
// // Load the HamQTH library
|
||||
// $this->load->library('hamqth');
|
||||
|
||||
// if (!$this->session->userdata('hamqth_session_key')) {
|
||||
// $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password'));
|
||||
// $this->session->set_userdata('hamqth_session_key', $hamqth_session_key);
|
||||
// }
|
||||
|
||||
// // if the callsign contains a pre- or suffix we only give back reduced data to avoid wrong data (location and other things are not valid then)
|
||||
// if (strpos($callsign, "/") !== false) {
|
||||
// $reduced = true;
|
||||
// } else {
|
||||
// $reduced = false;
|
||||
// }
|
||||
// $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'), $reduced);
|
||||
|
||||
// // If HamQTH session has expired, start a new session and retry the search.
|
||||
// if ($callbook['error'] == "Session does not exist or expired") {
|
||||
// $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password'));
|
||||
// $this->session->set_userdata('hamqth_session_key', $hamqth_session_key);
|
||||
// $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'));
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -61,7 +61,7 @@ class Qrzcq {
|
||||
}
|
||||
|
||||
|
||||
public function search($callsign, $key, $use_fullname = false, $reduced = false) {
|
||||
public function search($callsign, $key, $reduced = false) {
|
||||
$data = null;
|
||||
$ci = & get_instance();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user