Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions application/libraries/Qrz.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
Controls the interaction with the QRZ.com Subscription based XML API.
Expand All @@ -12,7 +12,7 @@ public function session($username, $password) {
// URL to the XML Source
$ci = & get_instance();
$xml_feed_url = 'https://xmldata.qrz.com/xml/current/?username='.$username.';password='.urlencode($password).';agent=wavelog';

// CURL Functions
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
Expand All @@ -23,22 +23,22 @@ public function session($username, $password) {
curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog/'.$ci->optionslib->get_option('version'));
$xml = curl_exec($ch);
curl_close($ch);

// Create XML object
$xml = simplexml_load_string($xml);

// Return Session Key
return (string) $xml->Session->Key;
}

// Set Session Key session.
public function set_session($username, $password) {

$ci = & get_instance();

// URL to the XML Source
$xml_feed_url = 'https://xmldata.qrz.com/xml/current/?username='.$username.';password='.urlencode($password).';agent=wavelog';

// CURL Functions
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
Expand All @@ -49,14 +49,14 @@ public function set_session($username, $password) {
curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog/'.$ci->optionslib->get_option('version'));
$xml = curl_exec($ch);
curl_close($ch);

// Create XML object
$xml = simplexml_load_string($xml);

$key = (string) $xml->Session->Key;

$ci->session->set_userdata('qrz_session_key', $key);

return true;
}

Expand All @@ -78,15 +78,19 @@ public function search($callsign, $key, $use_fullname = false, $reduced = false)
curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog/'.$ci->optionslib->get_option('version'));
$xml = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode != 200) {
$message = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
log_message('debug', 'QRZ.com search for callsign: ' . $callsign . ' returned message: ' . $message . ' HTTP code: ' . $httpcode);
curl_close($ch);
return $data['error'] = 'Problems with qrz.com communication'; // Exit function if no 200. If request fails, 0 is returned
}
curl_close($ch);
if ($httpcode != 200) return $data['error'] = 'Problems with qrz.com communication'; // Exit function if no 200. If request fails, 0 is returned

// Create XML object
$xml = simplexml_load_string($xml);
if (!empty($xml->Session->Error)) {
return $data['error'] = $xml->Session->Error;
}

// Return Required Fields
$data['callsign'] = (string)$xml->Callsign->call;

Expand Down