Merge pull request #694 from jsb2092/master

Added support for lookups in services for more detailed information when logged in
这个提交包含在:
Andreas Kristiansen 2021-10-05 20:58:48 +02:00 提交者 GitHub
当前提交 fa1bb549ee
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23
共有 5 个文件被更改,包括 143 次插入101 次删除

查看文件

@ -137,7 +137,7 @@ class Logbook extends CI_Controller {
$measurement_base = $this->session->userdata('user_measurement_base');
}
$return['callsign_name'] = $this->logbook_model->call_name($callsign);
$return['callsign_name'] = $this->logbook_model->call_name($callsign);
$return['callsign_qra'] = $this->logbook_model->call_qra($callsign);
$return['callsign_qth'] = $this->logbook_model->call_qth($callsign);
$return['callsign_iota'] = $this->logbook_model->call_iota($callsign);
@ -155,38 +155,8 @@ class Logbook extends CI_Controller {
}
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');
$callbook = $this->logbook_model->loadCallBook($callsign, $this->config->item('use_fullname'));
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'));
}
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);
}
$callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'));
// 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'));
}
}
if (isset($callbook))
{
@ -553,8 +523,14 @@ class Logbook extends CI_Controller {
$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);
}
$data= $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname'));
$data['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'));
if (empty($data['callsign']))
{
$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);
$data = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname'));
}
}
// There's no hamli integration? Disabled for now.
@ -611,7 +587,7 @@ class Logbook extends CI_Controller {
$this->session->set_userdata('qrz_session_key', $qrz_session_key);
}
$data['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'));
$data['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname'));
} else {
// Lookup using hamli
$this->load->library('hamli');

查看文件

@ -56,41 +56,44 @@ class Hamqth {
public function search($callsign, $key)
{
$data = null;
try {
// URL to the XML Source
$xml_feed_url = 'https://www.hamqth.com/xml.php?id=' . $key . '&callsign=' . $callsign . '&prg=cloudlog';
// URL to the XML Source
$xml_feed_url = 'https://www.hamqth.com/xml.php?id='.$key.'&callsign='.$callsign.'&prg=cloudlog';
// CURL Functions
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
// CURL Functions
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
// Create XML object
$xml = simplexml_load_string($xml);
if (empty($xml)) return;
// Create XML object
$xml = simplexml_load_string($xml);
// Return Required Fields
$data['callsign'] = (string)$xml->search->callsign;
$data['name'] = (string)$xml->search->nick;
$data['gridsquare'] = (string)$xml->search->grid;
$data['city'] = (string)$xml->search->adr_city;
$data['lat'] = (string)$xml->search->latitude;
$data['long'] = (string)$xml->search->longitude;
$data['iota'] = (string)$xml->search->iota;
$data['us_state'] = (string)$xml->search->us_state;
$data['us_county'] = (string)$xml->search->us_county;
$data['error'] = (string)$xml->session->error;
// Return Required Fields
$data['callsign'] = (string) $xml->search->callsign;
$data['name'] = (string) $xml->search->nick;
$data['gridsquare'] = (string) $xml->search->grid;
$data['city'] = (string) $xml->search->adr_city;
$data['lat'] = (string) $xml->search->latitude;
$data['long'] = (string) $xml->search->longitude;
$data['iota'] = (string) $xml->search->iota;
$data['us_state'] = (string) $xml->search->us_state;
$data['us_county'] = (string) $xml->search->us_county;
$data['error'] = (string) $xml->session->error;
if($xml->search->country == "United States") {
$data['state'] = (string) $xml->search->us_state;
$data['us_county'] = (string) $xml->search->us_county;
} else {
$data['state'] = null;
$data['us_county'] = null;
}
return $data;
if ($xml->search->country == "United States") {
$data['state'] = (string)$xml->search->us_state;
$data['us_county'] = (string)$xml->search->us_county;
} else {
$data['state'] = null;
$data['us_county'] = null;
}
} finally {
return $data;
}
}
}

查看文件

@ -54,42 +54,51 @@ class Qrz {
}
public function search($callsign, $key)
public function search($callsign, $key, $use_fullname)
{
$data = null;
try {
// URL to the XML Source
$xml_feed_url = 'http://xmldata.qrz.com/xml/current/?s=' . $key . ';callsign=' . $callsign . '';
// URL to the XML Source
$xml_feed_url = 'http://xmldata.qrz.com/xml/current/?s='.$key.';callsign='.$callsign.'';
// CURL Functions
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
// CURL Functions
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
// Create XML object
$xml = simplexml_load_string($xml);
if (empty($xml)) return;
// Create XML object
$xml = simplexml_load_string($xml);
// Return Required Fields
$data['callsign'] = (string)$xml->Callsign->call;
// Return Required Fields
$data['callsign'] = (string) $xml->Callsign->call;
$data['name'] = (string) $xml->Callsign->fname;
$data['gridsquare'] = (string) $xml->Callsign->grid;
$data['city'] = (string) $xml->Callsign->addr2;
$data['lat'] = (string) $xml->Callsign->lat;
$data['long'] = (string) $xml->Callsign->lon;
$data['iota'] = (string) $xml->Callsign->iota;
$data['qslmgr'] = (string) $xml->Callsign->qslmgr;
if ($use_fullname === true) {
$data['name'] = (string)$xml->Callsign->fname. ' ' . (string)$xml->Callsign->name;
} else {
$data['name'] = (string)$xml->Callsign->fname;
}
$data['name'] = trim($data['name']);
$data['gridsquare'] = (string)$xml->Callsign->grid;
$data['city'] = (string)$xml->Callsign->addr2;
$data['lat'] = (string)$xml->Callsign->lat;
$data['long'] = (string)$xml->Callsign->lon;
$data['iota'] = (string)$xml->Callsign->iota;
$data['qslmgr'] = (string)$xml->Callsign->qslmgr;
if($xml->Callsign->country == "United States") {
$data['state'] = (string) $xml->Callsign->state;
$data['us_county'] = (string) $xml->Callsign->county;
} else {
$data['state'] = null;
$data['us_county'] = null;
}
if ($xml->Callsign->country == "United States") {
$data['state'] = (string)$xml->Callsign->state;
$data['us_county'] = (string)$xml->Callsign->county;
} else {
$data['state'] = null;
$data['us_county'] = null;
}
} finally {
return $data;
return $data;
}
}
}

查看文件

@ -1594,7 +1594,7 @@ class Logbook_model extends CI_Model {
$entity = $this->get_entity($record['dxcc']);
$dxcc = array($record['dxcc'], $entity['name']);
} else {
$dxcc = NULL;
$dxcc = $this->check_dxcc_table($record['call'], $time_off);
}
} else {
$dxcc = $this->check_dxcc_table($record['call'], $time_off);
@ -1607,7 +1607,9 @@ class Logbook_model extends CI_Model {
if(isset($record['country'])) {
$country = $record['country'];
} else {
$country = ucwords(strtolower($dxcc[1]));
if (isset($dxcc[1])) {
$country = ucwords(strtolower($dxcc[1]));
}
}
// RST recevied
@ -2337,6 +2339,54 @@ class Logbook_model extends CI_Model {
}
}
public function loadCallBook($callsign, $use_fullname=false)
{
$callbook = null;
try {
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);
// if we got nothing, it's probably because our session key is invalid, try again
if (!isset($callbook['callsign']))
{
$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);
}
}
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);
}
$callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'));
// 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'));
}
}
} finally {
return $callbook;
}
}
public function update_all_station_ids() {
@ -2464,4 +2514,6 @@ function validateADIFDate($date, $format = 'Ymd')
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
?>

查看文件

@ -40,10 +40,12 @@ $config['display_freq'] = false;
|
| 'qrz_username' QRZ.com user login
| 'qrz_password' QRZ.com user password
| 'use_fullname' Get full names from QRZ, may not be GDPR compliant
*/
$config['qrz_username'] = "";
$config['qrz_password'] = "";
$config['use_fullname'] = false;
/*
|--------------------------------------------------------------------------