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 if ($data && $data !==
'{}' && $data !==
'[]') {
425 $data = json_decode($data,
true);
426 foreach ($data as $key => $value) {
428 $ret[$key][
"json_data"] = json_encode($ret[$key][
"json_data"]);
432 $this->set_m_error_message(
'get_meeting_changes: Invalid URI (' . $uri .
')');
455 $error_message =
null;
458 $this->set_m_error_message($error_message);
463 $uri .=
'/client_interface/json/?switcher=GetFormats';
469 $this->set_m_error_message($error_message);
474 $data = json_decode($data,
true);
475 foreach ($data as $format) {
476 $ret[$format[
'id']] = $format;
479 $this->set_m_error_message(
'get_server_formats: Invalid URI (' . $uri .
')');
504 $error_message =
null;
507 $this->set_m_error_message($error_message);
512 $uri .=
'/client_interface/json/?switcher=GetServiceBodies';
518 $this->set_m_error_message($error_message);
523 $data = json_decode($data,
true);
524 foreach ($data as $serviceBody) {
525 $ret[$serviceBody[
'id']] = $serviceBody;
528 $this->set_m_error_message(
'get_server_service_bodies: Invalid URI (' . $uri .
')');
557 $error_message =
null;
560 $this->set_m_error_message($error_message);
565 $uri .=
'/client_interface/json/?switcher=GetFieldKeys';
570 $this->set_m_error_message($error_message);
574 $data = json_decode($data,
true);
575 foreach ($data as $field_key) {
576 $ret[] = $field_key[
"key"];
579 $this->set_m_error_message(
'get_server_meeting_keys: Invalid URI (' . $uri .
')');
603 $this->set_m_error_message(
null);
610 if (is_array($outgoing_parameters[$in_parameter_key]) && count($outgoing_parameters[$in_parameter_key])) {
611 $ret = $outgoing_parameters[$in_parameter_key];
614 $this->set_m_error_message(
'get_transaction_key_values: Invalid Parameter Key: "' . $in_parameter_key .
'"');
634 $ret = array_key_exists($in_parameter_key, $legal_entities);
636 if (($in_parameter_key ==
'meeting_key') && isset($in_sub_key)) {
637 $ret = $ret && array_key_exists($in_sub_key, $legal_entities[$in_parameter_key]);
653 $in_parameter_value =
null
658 $this->set_m_error_message(
null);
664 $transaction_array[$in_parameter_key] = $in_parameter_value;
667 $this->set_m_error_message(
'set_current_transaction_parameter: Invalid Parameter Key: "' . $in_parameter_key .
'"');
680 $this->m_error_message =
null;
690 $in_parameter_key_string,
691 $in_parameter_secondary_key_string =
null
696 if (!isset($this->m_outgoing_parameters[$in_parameter_key_string])) {
697 $this->set_m_error_message(
'get_m_outgoing_parameter: Invalid Key: "' . $in_parameter_key_string .
'"');
699 if (isset($in_parameter_secondary_key_string)) {
700 if (!isset($this->m_outgoing_parameters[$in_parameter_key_string][$in_parameter_secondary_key_string])) {
701 $this->set_m_error_message(
'get_m_outgoing_parameter: Invalid Secondary Key: "' . $in_parameter_secondary_key_string .
'"');
703 $ret =& $this->m_outgoing_parameters[$in_parameter_key_string][$in_parameter_secondary_key_string];
706 $ret =& $this->m_outgoing_parameters[$in_parameter_key_string];
723 $in_parameter_key_string,
724 $in_parameter_value_mixed
728 $this->set_m_error_message(
null);
730 if (isset($this->m_outgoing_parameters[$in_parameter_key_string])) {
731 if ($in_parameter_value_mixed ===
null) {
732 $in_parameter_value_mixed =
'';
734 $this->m_outgoing_parameters[$in_parameter_key_string] = $in_parameter_value_mixed;
736 $this->set_m_error_message(
'set_m_outgoing_parameter: Invalid Key: "' . $in_parameter_key_string .
'"');
744 private function set_default_outgoing()
747 $this->m_outgoing_parameters = array (
749 'weekdays' => array (),
754 'StartsBeforeH' => 0,
755 'StartsBeforeM' => 0,
764 'SearchString' =>
'',
765 'SearchStringAll' =>
false,
766 'SearchStringExact' =>
false,
769 'StringSearchIsAnAddress' =>
false,
770 'SearchStringRadius' => 0,
779 'meeting_key' => array (),
780 'meeting_key_value' =>
'',
781 'meeting_key_match_case' =>
false,
782 'meeting_key_contains' =>
false,
785 'sort_key' => array (
'weekday' =>
true,
789 'sort_dir' => array (
'asc' =>
true,
792 'sort_results_by_distance' =>
false,
795 'services' => array (),
798 'meeting_ids' => array (),
801 'formats' => array (),
807 'data_field_key' =>
null
818 $this->set_m_server_version(
null);
819 $this->set_m_current_transaction(
null);
820 $this->set_default_outgoing();
864 $error_message =
null;
867 $this->set_m_error_message($error_message);
872 $uri .=
'/client_interface/json/?switcher=GetSearchResults';
874 $serialized_list =
null;
876 if ($transaction_params = $this->build_transaction_parameter_list($serialized_list)) {
877 $uri .= $transaction_params;
883 $ret[
'serialized'] = $serialized_list;
886 $this->set_m_error_message($error_message);
891 if ($data && $data !==
'{}' && $data !==
'[]') {
892 $data = json_decode($data,
true);
893 foreach ($data as $meeting) {
894 $item = self::extract_meeting_data($meeting);
898 $ret[
'meetings'][] = $item;
903 $this->set_m_error_message(
'meeting_search: Invalid URI (' . $uri .
')');
927 $new_array = unserialize($in_serialized_list);
928 if (isset($new_array) && is_array($new_array) && count($new_array)) {
930 $this->set_m_current_transaction(
null);
931 foreach ($new_array as $param_key => $param_value) {
962 private function build_transaction_parameter_list(&$in_out_serialized_list)
969 if (is_array($transaction_array) && count($transaction_array)) {
970 foreach ($transaction_array as $param_key => &$param_value) {
972 if (is_array($transaction_array[$param_key]) && (count($transaction_array[$param_key]) > 1)) {
973 foreach ($transaction_array[$param_key] as $param) {
975 if ($param ===
true) {
978 $ret .= $param_key .
'[]=' . urlencode(trim(strval($param)));
980 } elseif ((is_array($transaction_array[$param_key]) && (count($transaction_array[$param_key]) == 1)) || (!is_array($transaction_array[$param_key]) && isset($transaction_array[$param_key]))) {
982 $param = $transaction_array[$param_key];
983 if (is_array($param)) {
986 if ($param ===
true) {
989 $ret .= $param_key .
'=' . urlencode(trim(strval($param)));
991 $this->set_m_error_message(
'build_transaction_parameter_list: Invalid Parameter Value: "' . $param_value .
'" (' . $param_key .
')');
995 $this->set_m_error_message(
'build_transaction_parameter_list: Invalid Parameter Key: "' . $param_key .
'"');
1019 return self::$m_supported_protocols;
1029 private static function extract_meeting_data($in_meeting_item)
1034 foreach ($in_meeting_item as $key => $value) {
1036 $ret[$key] = $value;
1053 &$error_message =
null,
1054 &$http_status =
null
1060 if ($error_message) {
1061 $error_message =
null;
1064 if (!extension_loaded(
'curl')) {
1066 if (isset($error_message)) {
1067 $error_message =
'call_curl: The cURL extension is not available! This code will not work on this server!';
1071 if (isset($_COOKIE[
'PHPSESSID']) && $_COOKIE[
'PHPSESSID']) {
1072 $strCookie =
'PHPSESSID=' . $_COOKIE[
'PHPSESSID'] .
'; path=/';
1074 session_write_close();
1078 $resource = curl_init();
1080 if (isset($strCookie) && $strCookie) {
1081 curl_setopt($resource, CURLOPT_COOKIE, $strCookie);
1086 curl_setopt($resource, CURLOPT_POST,
true);
1088 $spli = explode(
"?", $in_uri, 2);
1090 if (is_array($spli) && (1 < count($spli))) {
1092 $in_params = $spli[1];
1094 parse_str($in_params, $temp);
1099 $in_params = http_build_query($temp);
1101 curl_setopt($resource, CURLOPT_POSTFIELDS, $in_params);
1105 if (isset($strCookie) && $strCookie) {
1106 curl_setopt($resource, CURLOPT_COOKIE, $strCookie);
1110 curl_setopt($resource, CURLOPT_URL, $in_uri);
1113 curl_setopt($resource, CURLOPT_RETURNTRANSFER,
true);
1119 curl_setopt($resource, CURLOPT_HEADER,
false);
1126 curl_setopt($resource, CURLOPT_MAXREDIRS, 3);
1129 curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, 10);
1132 curl_setopt($resource, CURLOPT_ENCODING,
'gzip,deflate');
1135 curl_setopt($resource, CURLOPT_USERAGENT,
"cURL Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20130401 Firefox/21.0");
1138 curl_setopt($resource, CURLOPT_SSL_VERIFYPEER,
false);
1141 $content = curl_exec($resource);
1144 if ($content ===
false) {
1146 if (isset($error_message)) {
1148 $error_message =
"call_curl: curl failure calling $in_uri, " . curl_error($resource) .
"\n" . curl_errno($resource);
1155 $http_status = curl_getinfo($resource, CURLINFO_HTTP_CODE);
1159 curl_close($resource);
1162 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. *.