Skip to content

Commit

Permalink
Updated included PHRETS version. Fixes #2 - thanks @kevin1024
Browse files Browse the repository at this point in the history
  • Loading branch information
troydavisson committed Jul 3, 2014
1 parent 5e3286d commit 4298eb3
Showing 1 changed file with 55 additions and 19 deletions.
74 changes: 55 additions & 19 deletions phrets.php
Expand Up @@ -4,9 +4,10 @@ class phRETS {

/**
* PHRETS - PHP library for RETS
* version 1.0rc3 (release candidate 3) please send error reports and/or feedback to troy.davisson@gmail.com
* version 1.0.1
* http://troda.com/projects/phrets/
* Copyright (C) 2007-2011 Troy Davisson
* Copyright (C) 2007-2014 Troy Davisson
* please submit problem or error reports to https://github.com/troydavisson/PHRETS/issues
*
* All rights reserved.
* Permission is hereby granted, free of charge, to use, copy or modify this software. Use at your own risk.
Expand All @@ -17,7 +18,6 @@ class phRETS {
*
*/

public $err;
public $capability_url = array();
private $ch;
private $server_hostname;
Expand Down Expand Up @@ -66,6 +66,8 @@ class phRETS {
private $disable_encoding_fix = false;
private $offset_support = false;
private $override_offset_protection = false;
private $use_post_method = false;
private $search_data = array();



Expand Down Expand Up @@ -474,6 +476,9 @@ public function FetchRow($pointer_id) {
$this_row[$name] = $field_data[$key];
}
}
else {
$this->FreeResult($pointer_id);
}
}

return $this_row;
Expand Down Expand Up @@ -530,11 +535,11 @@ public function SearchQuery($resource, $class, $query = "", $optional_params = a
}

// setup additional, optional request arguments
$search_arguments['Count'] = empty($optional_params['Count']) ? 1 : $optional_params['Count'];
$search_arguments['Count'] = (!array_key_exists('Count', $optional_params)) ? 1 : $optional_params['Count'];
$search_arguments['Format'] = empty($optional_params['Format']) ? "COMPACT-DECODED" : $optional_params['Format'];
$search_arguments['Limit'] = empty($optional_params['Limit']) ? 99999999 : $optional_params['Limit'];

if (!empty($optional_params['Offset'])) {
if (isset($optional_params['Offset'])) {
$search_arguments['Offset'] = $optional_params['Offset'];
}
elseif ($this->offset_support && empty($optional_params['Offset'])) {
Expand Down Expand Up @@ -695,7 +700,7 @@ public function GetAllLookupValues($resource) {
$this_lookup = array();

$lookup_xml_array = array();
if ($this->server_version == "RETS/1.7.2") {
if (!empty($key->LookupType)) {
$lookup_xml_array = $key->LookupType;
}
else {
Expand Down Expand Up @@ -771,7 +776,7 @@ public function GetLookupValues($resource, $lookupname) {
if ($xml->METADATA && $xml->METADATA->{'METADATA-LOOKUP_TYPE'}) {

$lookup_xml_array = array();
if ($this->server_version == "RETS/1.7.2") {
if (!empty($xml->METADATA->{'METADATA-LOOKUP_TYPE'}->LookupType)) {
$lookup_xml_array = $xml->METADATA->{'METADATA-LOOKUP_TYPE'}->LookupType;
}
else {
Expand Down Expand Up @@ -1266,6 +1271,8 @@ public function GetServerInformation() {
$system_id = "";
$system_description = "";
$system_comments = "";
$system_version = "";
$timezone_offset = "";

if ($this->is_server_version("1_5_or_below")) {
if (isset($xml->METADATA->{'METADATA-SYSTEM'}->System->SystemID)) {
Expand All @@ -1274,7 +1281,6 @@ public function GetServerInformation() {
if (isset($xml->METADATA->{'METADATA-SYSTEM'}->System->SystemDescription)) {
$system_description = "{$xml->METADATA->{'METADATA-SYSTEM'}->System->SystemDescription}";
}
$timezone_offset = "";
}
else {
if (isset($xml->METADATA->{'METADATA-SYSTEM'}->SYSTEM->attributes()->SystemID)) {
Expand All @@ -1291,12 +1297,16 @@ public function GetServerInformation() {
if (isset($xml->METADATA->{'METADATA-SYSTEM'}->SYSTEM->Comments)) {
$system_comments = "{$xml->METADATA->{'METADATA-SYSTEM'}->SYSTEM->Comments}";
}
if (isset($xml->METADATA->{'METADATA-SYSTEM'}->attributes()->Version)) {
$system_version = (string) $xml->METADATA->{'METADATA-SYSTEM'}->attributes()->Version;
}

return array(
'SystemID' => $system_id,
'SystemDescription' => $system_description,
'TimeZoneOffset' => $timezone_offset,
'Comments' => $system_comments
'Comments' => $system_comments,
'Version' => $system_version
);
}

Expand Down Expand Up @@ -1357,7 +1367,7 @@ public function Connect($login_url, $username, $password, $ua_pwd = "") {
// chop up Login URL to use for later requests
$url_parts = parse_url($login_url);
$this->server_hostname = $url_parts['host'];
$this->server_port = (empty($url_parts['port'])) ? 80 : $url_parts['port'];
$this->server_port = (empty($url_parts['port'])) ? (($url_parts['scheme'] == 'https') ? 443 : 80) : $url_parts['port'];
$this->server_protocol = $url_parts['scheme'];

$this->capability_url['Login'] = $url_parts['path'];
Expand Down Expand Up @@ -1480,11 +1490,19 @@ public function Connect($login_url, $username, $password, $ua_pwd = "") {

// if 'Action' capability URL is provided, we MUST request it following the successful Login
if (isset($this->capability_url['Action']) && !empty($this->capability_url['Action'])) {
$previous_reply_code = $this->last_request['ReplyCode'];
$previous_reply_text = $this->last_request['ReplyText'];

$result = $this->RETSRequest($this->capability_url['Action']);
if (!$result) {
return false;
}
list($headers,$body) = $result;
list($headers, $body) = $result;

// there are no formatting restrictions on the response from an Action transaction, so don't try to parse
// and just carry over the previous codes
$this->last_request['ReplyCode'] = $previous_reply_code;
$this->last_request['ReplyText'] = $previous_reply_text;
}

if ($this->compression_enabled == true) {
Expand Down Expand Up @@ -1527,10 +1545,13 @@ public function ParseXMLResponse($data = "") {

if (!empty($data)) {
// parse XML function. ability to replace SimpleXML with something later fairly easily
$xml = @simplexml_load_string($data);
if (defined('LIBXML_PARSEHUGE')) {
$xml = @simplexml_load_string($data, 'SimpleXMLElement', LIBXML_PARSEHUGE);
} else {
$xml = @simplexml_load_string($data);
}
if (!is_object($xml)) {
$this->set_error_info("xml", -1, "XML parsing error: {$data}");
$this->err = "XML Parsing error: {$data}";
return false;
}
return $xml;
Expand All @@ -1545,7 +1566,7 @@ public function ParseXMLResponse($data = "") {
public function RETSRequest($action, $parameters = "") {
$this->reset_error_info();

$this->err = "";
$this->last_request = array();
$this->last_response_headers = array();
$this->last_response_headers_raw = "";
$this->last_remembered_header = "";
Expand All @@ -1569,12 +1590,24 @@ public function RETSRequest($action, $parameters = "") {
// build query string from arguments
$request_arguments = "";
if (is_array($parameters)) {
$request_arguments = http_build_query($parameters);
$request_arguments = http_build_query($parameters, '', '&');
}

// build entire URL if needed
if (!empty($request_arguments)) {
$request_url = $request_url .'?'. $request_arguments;
// update request method on each request
if ($this->use_post_method) {
// setup cURL for POST requests
curl_setopt($this->ch, CURLOPT_POST, true);

// assign the POST data for this request
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $request_arguments);
} else {
// setup cURL for GET requests
curl_setopt($this->ch, CURLOPT_HTTPGET, true);

// build entire URL if needed
if (!empty($request_arguments)) {
$request_url = $request_url .'?'. $request_arguments;
}
}

// build headers to pass in cURL
Expand Down Expand Up @@ -1714,7 +1747,7 @@ private function is_server_version($check_version) {
}
}
if ($check_version == "1_7_or_higher") {
if ($this->GetServerVersion() == "RETS/1.7" || $this->GetServerVersion() == "RETS/1.7.1" || $this->GetServerVersion() == "RETS/1.7.2") {
if ($this->GetServerVersion() == "RETS/1.7" || $this->GetServerVersion() == "RETS/1.7.1" || $this->GetServerVersion() == "RETS/1.7.2" || $this->GetServerVersion() == "RETS/1.8") {
return true;
}
else {
Expand Down Expand Up @@ -1789,6 +1822,9 @@ public function SetParam($name, $value) {
case "override_offset_protection":
$this->override_offset_protection = $value;
break;
case "use_post_method":
$this->use_post_method = $value;
break;
default:
return false;
}
Expand Down

0 comments on commit 4298eb3

Please sign in to comment.