45 private static $m_supported_protocols = array (
53 private $m_root_uri_string =
null;
54 private $m_error_message =
null;
63 private $m_outgoing_parameters =
null;
68 private $m_server_version =
null;
69 private $m_current_transaction =
null;
83 if ($in_root_uri_string) {
92 if ($in_root_uri_string) {
96 $version_int = intval(str_replace(
'.',
'', $version));
97 if ($version_int > 185) {
98 if (!extension_loaded(
'curl')) {
99 $this->set_m_error_message(
'__construct: The cURL extension is not available! This code will not work on this server!');
104 $this->set_m_error_message(
'__construct: The root server at (' . $in_root_uri_string .
') is too old (it is version ' . $version .
')! It needs to be at least Version 1.8.6!');
122 $in_skip_flush =
false
126 if (!$in_skip_flush && strcmp($in_root_uri_string, $this->m_root_uri_string ??
'')) {
130 $this->m_root_uri_string = $in_root_uri_string;
143 $ret_string = $this->m_root_uri_string;
145 $protocol = $protocols[0];
151 if (preg_match(
'|^(.*?):\/\/(.*?)/?$|', $ret_string, $matches)) {
152 $protocol = strtolower($matches[1]);
154 if (!in_array($protocol, $protocols)) {
155 $protocol = $protocols[0];
161 preg_match(
'|^(.*?)\/?$|', $ret_string, $matches);
168 $ret_string = $protocol .
'://' . $uri;
177 private function set_m_server_version($in_version)
180 $this->m_server_version = $in_version;
189 private function get_m_server_version()
192 return $this->m_server_version;
199 private function set_m_error_message($in_error_message)
202 $this->m_error_message = $in_error_message;
214 return $this->m_error_message;
221 private function set_m_current_transaction($in_current_transaction)
224 $this->m_current_transaction = $in_current_transaction;
236 return $this->m_current_transaction;
248 return $this->m_outgoing_parameters;
271 $error_message =
null;
274 $this->set_m_error_message($error_message);
276 if ($in_force_refresh || !$this->get_m_server_version()) {
279 $uri .=
'/client_interface/json/?switcher=GetServerInfo';
285 $this->set_m_error_message($error_message);
289 $info = json_decode($data,
true);
290 $ret = $info[0][
"version"];
291 $this->set_m_server_version($ret);
295 $this->set_m_error_message(
'get_server_version: Invalid URI (' . $uri .
')');
298 $ret = $this->get_m_server_version();
322 $error_message =
null;
325 $this->set_m_error_message($error_message);
330 $uri .=
'/client_interface/json/?switcher=GetServerInfo';
336 $this->set_m_error_message($error_message);
342 $data = json_decode($data,
true);
343 $langs = explode(
",", $data[0][
"langs"]);
344 $default_lang = $data[0][
"nativeLang"];
345 foreach ($langs as $lang) {
346 $ret[$lang][
'name'] = $lang;
347 $ret[$lang][
'default'] = $lang === $default_lang ? true :
false;
353 $this->set_m_error_message(
'get_server_langs: Invalid URI (' . $uri .
')');
382 $in_start_date =
null,
384 $in_meeting_id =
null,
385 $in_service_body_id =
null
390 $error_message =
null;
393 $this->set_m_error_message($error_message);
397 $uri .=
'/client_interface/json/?switcher=GetChanges';
399 if (intval($in_start_date)) {
400 $uri .=
'&start_date=' . date(
'Y-m-d', intval($in_start_date));
403 if (intval($in_end_date)) {
404 $uri .=
'&end_date=' . date(
'Y-m-d', intval($in_end_date));
407 if (intval($in_meeting_id)) {
408 $uri .=
'&meeting_id=' . intval($in_meeting_id);
411 if (intval($in_service_body_id)) {
412 $uri .=
'&service_body_id=' . intval($in_service_body_id);
419 $this->set_m_error_message($error_message);
423 $info_file =
new DOMDocument();
424 if ($data && $data !==
'{}' && $data !==
'[]') {
426 $data = json_decode($data,
true);
427 foreach ($data as $key => $value) {
429 $ret[$key][
"json_data"] = json_encode($ret[$key][
"json_data"]);
433 $this->set_m_error_message(
'get_meeting_changes: Invalid URI (' . $uri .
')');
456 $error_message =
null;
459 $this->set_m_error_message($error_message);
464 $uri .=
'/client_interface/json/?switcher=GetFormats';
470 $this->set_m_error_message($error_message);
475 $data = json_decode($data,
true);
476 foreach ($data as $format) {
477 $ret[$format[
'id']] = $format;
480 $this->set_m_error_message(
'get_server_formats: Invalid URI (' . $uri .
')');
505 $error_message =
null;
508 $this->set_m_error_message($error_message);
513 $uri .=
'/client_interface/json/?switcher=GetServiceBodies';
519 $this->set_m_error_message($error_message);
524 $data = json_decode($data,
true);
525 foreach ($data as $serviceBody) {
526 $ret[$serviceBody[
'id']] = $serviceBody;
529 $this->set_m_error_message(
'get_server_service_bodies: Invalid URI (' . $uri .
')');
558 $error_message =
null;
561 $this->set_m_error_message($error_message);
566 $uri .=
'/client_interface/json/?switcher=GetFieldKeys';
571 $this->set_m_error_message($error_message);
575 $data = json_decode($data,
true);
576 foreach ($data as $field_key) {
577 $ret[] = $field_key[
"key"];
580 $this->set_m_error_message(
'get_server_meeting_keys: Invalid URI (' . $uri .
')');
604 $this->set_m_error_message(
null);
611 if (is_array($outgoing_parameters[$in_parameter_key]) && count($outgoing_parameters[$in_parameter_key])) {
612 $ret = $outgoing_parameters[$in_parameter_key];
615 $this->set_m_error_message(
'get_transaction_key_values: Invalid Parameter Key: "' . $in_parameter_key .
'"');
635 $ret = array_key_exists($in_parameter_key, $legal_entities);
637 if (($in_parameter_key ==
'meeting_key') && isset($in_sub_key)) {
638 $ret = $ret && array_key_exists($in_sub_key, $legal_entities[$in_parameter_key]);
654 $in_parameter_value =
null
659 $this->set_m_error_message(
null);
665 $transaction_array[$in_parameter_key] = $in_parameter_value;
668 $this->set_m_error_message(
'set_current_transaction_parameter: Invalid Parameter Key: "' . $in_parameter_key .
'"');
681 $this->m_error_message =
null;
691 $in_parameter_key_string,
692 $in_parameter_secondary_key_string =
null
697 if (!isset($this->m_outgoing_parameters[$in_parameter_key_string])) {
698 $this->set_m_error_message(
'get_m_outgoing_parameter: Invalid Key: "' . $in_parameter_key_string .
'"');
700 if (isset($in_parameter_secondary_key_string)) {
701 if (!isset($this->m_outgoing_parameters[$in_parameter_key_string][$in_parameter_secondary_key_string])) {
702 $this->set_m_error_message(
'get_m_outgoing_parameter: Invalid Secondary Key: "' . $in_parameter_secondary_key_string .
'"');
704 $ret =& $this->m_outgoing_parameters[$in_parameter_key_string][$in_parameter_secondary_key_string];
707 $ret =& $this->m_outgoing_parameters[$in_parameter_key_string];
724 $in_parameter_key_string,
725 $in_parameter_value_mixed
729 $this->set_m_error_message(
null);
731 if (isset($this->m_outgoing_parameters[$in_parameter_key_string])) {
732 if ($in_parameter_value_mixed ===
null) {
733 $in_parameter_value_mixed =
'';
735 $this->m_outgoing_parameters[$in_parameter_key_string] = $in_parameter_value_mixed;
737 $this->set_m_error_message(
'set_m_outgoing_parameter: Invalid Key: "' . $in_parameter_key_string .
'"');
745 private function set_default_outgoing()
748 $this->m_outgoing_parameters = array (
750 'weekdays' => array (),
755 'StartsBeforeH' => 0,
756 'StartsBeforeM' => 0,
765 'SearchString' =>
'',
766 'SearchStringAll' =>
false,
767 'SearchStringExact' =>
false,
770 'StringSearchIsAnAddress' =>
false,
771 'SearchStringRadius' => 0,
780 'meeting_key' => array (),
781 'meeting_key_value' =>
'',
782 'meeting_key_match_case' =>
false,
783 'meeting_key_contains' =>
false,
786 'sort_key' => array (
'weekday' =>
true,
790 'sort_dir' => array (
'asc' =>
true,
793 'sort_results_by_distance' =>
false,
796 'services' => array (),
799 'meeting_ids' => array (),
802 'formats' => array (),
808 'data_field_key' =>
null
819 $this->set_m_server_version(
null);
820 $this->set_m_current_transaction(
null);
821 $this->set_default_outgoing();
865 $error_message =
null;
868 $this->set_m_error_message($error_message);
873 $uri .=
'/client_interface/json/?switcher=GetSearchResults';
875 $serialized_list =
null;
877 if ($transaction_params = $this->build_transaction_parameter_list($serialized_list)) {
878 $uri .= $transaction_params;
884 $ret[
'serialized'] = $serialized_list;
887 $this->set_m_error_message($error_message);
892 if ($data && $data !==
'{}' && $data !==
'[]') {
893 $data = json_decode($data,
true);
894 foreach ($data as $meeting) {
895 $item = self::extract_meeting_data($meeting);
899 $ret[
'meetings'][] = $item;
904 $this->set_m_error_message(
'meeting_search: Invalid URI (' . $uri .
')');
928 $new_array = unserialize($in_serialized_list);
929 if (isset($new_array) && is_array($new_array) && count($new_array)) {
931 $this->set_m_current_transaction(
null);
932 foreach ($new_array as $param_key => $param_value) {
963 private function build_transaction_parameter_list(&$in_out_serialized_list)
970 if (is_array($transaction_array) && count($transaction_array)) {
971 foreach ($transaction_array as $param_key => &$param_value) {
973 if (is_array($transaction_array[$param_key]) && (count($transaction_array[$param_key]) > 1)) {
974 foreach ($transaction_array[$param_key] as $param) {
976 if ($param ===
true) {
979 $ret .= $param_key .
'[]=' . urlencode(trim(strval($param)));
981 } elseif ((is_array($transaction_array[$param_key]) && (count($transaction_array[$param_key]) == 1)) || (!is_array($transaction_array[$param_key]) && isset($transaction_array[$param_key]))) {
983 $param = $transaction_array[$param_key];
984 if (is_array($param)) {
987 if ($param ===
true) {
990 $ret .= $param_key .
'=' . urlencode(trim(strval($param)));
992 $this->set_m_error_message(
'build_transaction_parameter_list: Invalid Parameter Value: "' . $param_value .
'" (' . $param_key .
')');
996 $this->set_m_error_message(
'build_transaction_parameter_list: Invalid Parameter Key: "' . $param_key .
'"');
1020 return self::$m_supported_protocols;
1030 private static function extract_meeting_data($in_meeting_item)
1035 foreach ($in_meeting_item as $key => $value) {
1037 $ret[$key] = $value;
1054 &$error_message =
null,
1055 &$http_status =
null
1061 if ($error_message) {
1062 $error_message =
null;
1065 if (!extension_loaded(
'curl')) {
1067 if (isset($error_message)) {
1068 $error_message =
'call_curl: The cURL extension is not available! This code will not work on this server!';
1072 if (isset($_COOKIE[
'PHPSESSID']) && $_COOKIE[
'PHPSESSID']) {
1073 $strCookie =
'PHPSESSID=' . $_COOKIE[
'PHPSESSID'] .
'; path=/';
1075 session_write_close();
1079 $resource = curl_init();
1081 if (isset($strCookie) && $strCookie) {
1082 curl_setopt($resource, CURLOPT_COOKIE, $strCookie);
1087 curl_setopt($resource, CURLOPT_POST,
true);
1089 $spli = explode(
"?", $in_uri, 2);
1091 if (is_array($spli) && (1 < count($spli))) {
1093 $in_params = $spli[1];
1095 parse_str($in_params, $temp);
1100 $in_params = http_build_query($temp);
1102 curl_setopt($resource, CURLOPT_POSTFIELDS, $in_params);
1106 if (isset($strCookie) && $strCookie) {
1107 curl_setopt($resource, CURLOPT_COOKIE, $strCookie);
1111 curl_setopt($resource, CURLOPT_URL, $in_uri);
1114 curl_setopt($resource, CURLOPT_RETURNTRANSFER,
true);
1120 curl_setopt($resource, CURLOPT_HEADER,
false);
1127 curl_setopt($resource, CURLOPT_MAXREDIRS, 3);
1130 curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, 10);
1133 curl_setopt($resource, CURLOPT_ENCODING,
'gzip,deflate');
1136 curl_setopt($resource, CURLOPT_USERAGENT,
"cURL Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20130401 Firefox/21.0");
1139 curl_setopt($resource, CURLOPT_SSL_VERIFYPEER,
false);
1142 $content = curl_exec($resource);
1145 if ($content ===
false) {
1147 if (isset($error_message)) {
1149 $error_message =
"call_curl: curl failure calling $in_uri, " . curl_error($resource) .
"\n" . curl_errno($resource);
1156 $http_status = curl_getinfo($resource, CURLINFO_HTTP_CODE);
1160 curl_close($resource);
1163 if ($content !==
false) {
Provides low-level communication to the BMLT Root Server.
& get_m_current_transaction()
Accessor -Return a reference to the class transaction "bucket." * *.
is_legal_transaction_key( $in_parameter_key, $in_sub_key=null)
See if a given parameter key is valid for an outgoing parameter. * *.
& get_m_outgoing_parameter( $in_parameter_key_string, $in_parameter_secondary_key_string=null)
Return a value from the transaction stimuli array. * *.
& get_m_outgoing_parameters()
Accessor -Return the transaction stimulus array. * *.
get_transaction_key_values($in_parameter_key)
See if a given parameter key is valid for an outgoing parameter. *This will set or clear the error me...
get_server_service_bodies($in_force_refresh=false)
Return the server's Service bodies, in hierarchical fashion. *This will cache the response in the out...
get_server_meeting_keys($in_force_refresh=false)
Return a list of the supported meeting_key values.. *Each root server can define its own meeting data...
get_server_version($in_force_refresh=false)
Test the stored URI to see if it points to a valid root server, and return * the server version....
set_m_root_uri( $in_root_uri_string, $in_skip_flush=false)
Accessor -Set the value of the Root URI. *NOTE: If the server URI changes, the parameters are flushed...
meeting_search()
Execute a meeting search transaction * *.
set_current_transaction_parameter( $in_parameter_key, $in_parameter_value=null)
Add a transaction parameter to a transaction being built. *This will set or clear the error message....
get_m_error_message()
Accessor -Return the value of the class error message (if any). * *.
load_standard_outgoing_parameters()
Read all the standard parameters from the server *This will set or clear the internal $m_error_messag...
get_serialized_transaction()
Return the query parameter list for the next transaction in a serialized * string....
static get_m_supported_protocols()
Accessor -Return the array of supported protocols. * *.
get_server_formats($in_force_refresh=false)
Return the server supported formats. *This will cache the response in the outgoing parameters ('forma...
__construct($in_root_uri_string=null)
Constructor -Set the value of the Root URI. * If a URI is passed in, then the object establishes and ...
static call_curl( $in_uri, $in_post=false, &$error_message=null, &$http_status=null)
This is a function that returns the results of an HTTP call to a URI. * It is a lot more secure than ...
get_meeting_changes( $in_start_date=null, $in_end_date=null, $in_meeting_id=null, $in_service_body_id=null)
Return meeting changes between two dates. *This requires that the server be version 1....
apply_serialized_transaction($in_serialized_list)
Unserialize a serialized transaction. *This allows you to save a transaction, and re-use it....
flush_parameters()
Flush all the parameters, and the dynamically-filled outgoing ones. *.
get_m_root_uri()
Accessor -Return the value of the Root URI. Perform "cleaning" if necessary. * *.
get_server_langs($in_force_refresh=false)
Return the server supported languages. *This will cache the response in the outgoing parameters ('lan...
set_m_outgoing_parameter( $in_parameter_key_string, $in_parameter_value_mixed)
Set a parameter value to the transaction stimulus array. *The outgoing array is "pre-keyed" with the ...
clear_m_error_message()
Clear the Error Message. *.