kopia lustrzana https://github.com/magicbug/Cloudlog
Added exception handling when qrz or hamqth is not available/accessible.
rodzic
8660d3d3ce
commit
593db48556
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,40 +56,43 @@ class Qrz {
|
|||
|
||||
public function search($callsign, $key)
|
||||
{
|
||||
$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);
|
||||
|
||||
// Create XML object
|
||||
$xml = simplexml_load_string($xml);
|
||||
|
||||
// Return Required Fields
|
||||
$data['callsign'] = (string) $xml->Callsign->call;
|
||||
$data['name'] = (string) $xml->Callsign->fname . ' '. (string) $xml->Callsign->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;
|
||||
// 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);
|
||||
|
||||
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;
|
||||
}
|
||||
// Create XML object
|
||||
$xml = simplexml_load_string($xml);
|
||||
if (empty($xml)) return;
|
||||
|
||||
|
||||
return $data;
|
||||
// Return Required Fields
|
||||
$data['callsign'] = (string)$xml->Callsign->call;
|
||||
$data['name'] = (string)$xml->Callsign->fname . ' ' . (string)$xml->Callsign->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;
|
||||
}
|
||||
} finally {
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2170,39 +2170,41 @@ class Logbook_model extends CI_Model {
|
|||
|
||||
public function loadCallBook($callsign)
|
||||
{
|
||||
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 = 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);
|
||||
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'));
|
||||
}
|
||||
|
||||
$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->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(!$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 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;
|
||||
}
|
||||
return $callbook;
|
||||
}
|
||||
|
||||
public function update_all_station_ids() {
|
||||
|
|
Ładowanie…
Reference in New Issue