24 defined(
'RVP_PHP_SDK_ACCESS' ) or die ( 'Cannot Execute Directly' );
25 require_once(dirname(__FILE__).'/rvp_php_sdk_login.class.php');
26 require_once(dirname(__FILE__).'/rvp_php_sdk_user.class.php');
27 require_once(dirname(__FILE__).'/rvp_php_sdk_place.class.php');
28 require_once(dirname(__FILE__).'/rvp_php_sdk_thing.class.php');
29 require_once(dirname(__FILE__).'/lang/common.php');
31 define('__SDK_VERSION__', '1.0.0.2000');
67 'name' =>
'search_name',
68 'tag0' =>
'search_tag0',
69 'tag1' =>
'search_tag1',
70 'tag2' =>
'search_tag2',
71 'tag3' =>
'search_tag3',
72 'tag4' =>
'search_tag4',
73 'tag5' =>
'search_tag5',
74 'tag6' =>
'search_tag6',
75 'tag7' =>
'search_tag7',
76 'tag8' =>
'search_tag8',
77 'tag9' =>
'search_tag9',
78 'description' =>
'search_description',
79 'surname' =>
'search_surname',
80 'middle_name' =>
'search_middle_name',
81 'given_name' =>
'search_given_name',
82 'nickname' =>
'search_nickname',
83 'prefix' =>
'search_prefix',
84 'suffix' =>
'search_suffix',
85 'venue' =>
'search_venue',
86 'street' =>
'search_street_address',
87 'street_address' =>
'search_street_address',
88 'extra_information' =>
'search_extra_information',
89 'city' =>
'search_town',
90 'town' =>
'search_town',
91 'county' =>
'search_county',
92 'state' =>
'search_state',
93 'province' =>
'search_state',
94 'postal_code' =>
'search_postal_code',
95 'zip_code' =>
'search_postal_code',
96 'nation' =>
'search_nation',
107 $table = static::_get_string_match_table();
109 if (isset($table[$ret]) && $table[$ret]) {
136 $method = strtoupper(trim($method));
139 $content_type = NULL;
141 $temp_file_name = NULL;
147 $file_data = base64_encode($data_input[
'data']);
149 $temp_file_name = tempnam(sys_get_temp_dir(),
'RVP');
151 $file = fopen($temp_file_name,
'w');
153 fwrite($file, $file_data, strlen($file_data));
157 $content_type = $data_input[
'type'].
':base64';
158 $file_size = filesize($temp_file_name);
160 $file = fopen($temp_file_name,
'rb');
170 curl_setopt($curl, CURLOPT_POST,
true);
174 curl_setopt($curl, CURLOPT_SAFE_UPLOAD,
true);
175 curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Expect:',
'Content-type: multipart/form-data']);
176 $post = Array(
'payload'=> curl_file_create($temp_file_name, $content_type));
177 curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
179 curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Expect:']);
184 curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Expect:']);
185 curl_setopt($curl, CURLOPT_PUT,
true);
189 curl_setopt($curl, CURLOPT_SAFE_UPLOAD,
true);
190 curl_setopt($curl, CURLOPT_INFILE, $file);
191 curl_setopt($curl, CURLOPT_INFILESIZE, $file_size);
196 curl_setopt($curl, CURLOPT_CUSTOMREQUEST,
"DELETE");
200 if (isset($this->_server_secret) && isset($this->_api_key)) {
201 curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
202 curl_setopt($curl, CURLOPT_USERPWD, $this->_server_secret.
':'.$this->_api_key);
205 if (isset($url_extension) && (
false !== strpos($url_extension,
'?'))) {
206 $url_extension .=
'&';
208 $url_extension .=
'?';
211 $url_extension .=
'login_server_secret='.urlencode($this->_server_secret).
'&login_api_key='.urlencode($this->_api_key);
214 curl_setopt($curl, CURLOPT_HEADER,
false);
215 curl_setopt($curl, CURLOPT_RETURNTRANSFER,
true);
216 curl_setopt($curl, CURLOPT_VERBOSE,
false);
217 $url = $this->_server_uri.
'/'.trim($url_extension,
'/');
218 curl_setopt($curl, CURLOPT_URL, $url);
221 if (isset($display_log) && $display_log) {
222 curl_setopt($curl, CURLOPT_HEADERFUNCTION,
function ( $curl, $header_line ) {
223 echo
"<pre>$header_line</pre>";
224 return strlen($header_line);
226 echo(
'<div style="margin:1em">');
227 echo(
"<h4>Sending REST $method CALL:</h4>");
228 echo(
'<div>URL: <code>'.htmlspecialchars($url).
'</code></div>');
230 if ($this->_api_key) {
231 echo(
'<div>API KEY:<pre>'.htmlspecialchars($this->_api_key).
'</pre></div>');
233 echo(
'<div>NO API KEY</div>');
237 $result = curl_exec($curl);
239 $this->_last_response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
244 if (isset($display_log) && $display_log) {
245 if (isset($file_data)) {
246 $len = floatval(strlen($file_data));
249 echo(
'<p><strong>ADDITIONAL DATA LENGTH IS ZERO!</strong></p>');
250 } elseif ( 1024 > $len) {
251 echo(
'<p><strong>ADDITIONAL DATA LENGTH:</strong> <big><code>'.$len.
' Bytes</code></big></p>');
252 } elseif ( (1024 * 1024) > $len) {
253 echo(
'<p><strong>ADDITIONAL DATA LENGTH:</strong> <big><code>'.($len / 1024).
' Kilobytes</code></big></p>');
254 } elseif ( (1024 * 1024 * 1024) > $len) {
255 echo(
'<p><strong>ADDITIONAL DATA LENGTH:</strong> <big><code>'.($len / (1024 * 1024)).
' Megabytes</code></big></p>');
256 } elseif ( (1024 * 1024 * 1024 * 1024) > $len) {
257 echo(
'<p><strong>ADDITIONAL DATA LENGTH:</strong> <big><code>'.($len / (1024 * 1024 * 1024)).
' Gigabytes</code></big></p>');
259 echo(
'<p><strong>ADDITIONAL DATA SHA:</strong> <big><code>'.sha1($file_data).
'</code></big></p>');
262 if (isset($httpCode) && $httpCode) {
263 echo(
'<div>HTTP CODE:<code>'.htmlspecialchars($httpCode,
true).
'</code></div>');
266 if ((2048 * 1024) <= strlen($result)) {
268 $original_file_name = dirname(dirname(__FILE__)).
'/text-dump-result';
269 $file_name = $original_file_name.
'.txt';
270 while(file_exists($file_name)) {
271 $file_name = $original_file_name.
'-'.$integer.
'.txt';
274 $file_handle = fopen($file_name,
'w');
275 fwrite($file_handle, $result);
276 fclose($file_handle);
277 echo(
'<div>RESULT SAVED TO FILE" '.$file_name.
'.</div>');
279 echo(
'<div>RESULT:<pre>'.htmlspecialchars(print_r(chunk_split($result, 1024),
true)).
'</pre></div>');
300 if (isset($in_handlers->people) && is_array($in_handlers->people) && count($in_handlers->people)) {
301 $plugin_list[
'people'] = $in_handlers->people;
303 if (isset($in_handlers->places) && is_array($in_handlers->places) && count($in_handlers->places)) {
304 $plugin_list[
'places'] = $in_handlers->places;
306 if (isset($in_handlers->things) && is_array($in_handlers->things) && count($in_handlers->things)) {
307 $plugin_list[
'things'] = $in_handlers->things;
310 if (isset($plugin_list) && is_array($plugin_list) && count($plugin_list)) {
312 foreach ($plugin_list as $plugin => $list) {
314 foreach ($list as $id) {
322 $ret[] = $new_object;
324 $this->set_error(_ERR_INTERNAL_ERR__);
332 $ret[] = $new_object;
334 $this->set_error(_ERR_INTERNAL_ERR__);
342 $ret[] = $new_object;
344 $this->set_error(_ERR_INTERNAL_ERR__);
364 $locale_dir = dirname(__FILE__).
'/lang';
365 $locale_name_array = [];
366 foreach (
new DirectoryIterator($locale_dir) as $fileInfo) {
367 if (($fileInfo->getExtension() ===
'php') && (
'index.php' != $fileInfo->getBasename()) && (
'common.php' != $fileInfo->getBasename())) {
368 $locale_name_array[] = $fileInfo->getBasename(
'.php');
372 $this->_localizations = [];
375 foreach ($locale_name_array as $locale) {
376 if ($locale != $this->_sdk_lang) {
377 $this->_localizations[] = $locale;
381 sort($this->_localizations);
382 array_unshift($this->_localizations, $this->_sdk_lang);
392 if ($this->is_logged_in()) {
393 $info = $this->fetch_data(
'json/people/logins/my_info');
395 $temp = json_decode($info);
396 if (isset($temp) && isset($temp->people) && isset($temp->people->logins) && isset($temp->people->logins->my_info)) {
397 $login_info = $temp->people->logins->my_info;
398 if (isset($login_info->user_object_id) && (1 < intval($login_info->user_object_id))) {
399 $ret = [
'login' => $login_info];
400 $info = $this->fetch_data(
'json/people/people/my_info');
402 $temp = json_decode($info);
403 if (isset($temp) && isset($temp->people) && isset($temp->people->people) && isset($temp->people->people->my_info)) {
404 $user_info = $temp->people->people->my_info;
405 $ret[
'user'] = $user_info;
407 $this->set_error(_ERR_COMM_ERR__);
410 $this->set_error(_ERR_NO_RESULTS__);
413 $ret = [
'login' => $login_info];
417 $this->set_error(_ERR_NO_RESULTS__);
431 $info = $this->fetch_data(
'json/baseline');
433 $temp = json_decode($info);
434 if (isset($temp) && isset($temp->baseline) && isset($temp->baseline->plugins) && is_array($temp->baseline->plugins)) {
435 return $temp->baseline->plugins;
437 $this->set_error(_ERR_COMM_ERR__);
440 $this->set_error(_ERR_NO_RESULTS__);
453 if ($this->_api_key) {
454 $this->_my_login_info = NULL;
455 $this->_my_user_info = NULL;
457 $info = $this->_get_my_info();
459 if (!$this->get_error()) {
460 if (isset($info[
'login'])) {
461 $this->_my_login_info =
new RVP_PHP_SDK_Login($this, $info[
'login']->
id, $info[
'login'],
true);
464 $this->set_error(_ERR_INTERNAL_ERR__);
466 $this->_api_key = NULL;
467 $this->_login_time_limit = -1;
468 $this->_my_login_info = NULL;
469 $this->_my_user_info = NULL;
474 if (isset($info[
'user'])) {
475 $this->_my_user_info =
new RVP_PHP_SDK_User($this, $info[
'user']->
id, $info[
'user'],
true);
478 $this->set_error(_ERR_INTERNAL_ERR__);
480 $this->_api_key = NULL;
481 $this->_login_time_limit = -1;
482 $this->_my_login_info = NULL;
483 $this->_my_user_info = NULL;
491 $this->_api_key = NULL;
508 $in_login_timeout = 0
510 $this->_server_uri = trim($in_server_uri,
'/');
511 $this->_server_secret = $in_server_secret;
512 $this->_api_key = NULL;
513 $this->_login_time_limit = -1;
514 $this->_login_timeout = $in_login_timeout;
515 $this->_my_login_info = NULL;
516 $this->_my_user_info = NULL;
518 $this->clear_error();
519 $this->set_lang(
'en');
521 $this->_available_plugins = $this->_get_plugins();
523 if ($this->valid()) {
524 if ($in_username && $in_password && $in_login_timeout) {
525 $this->login($in_username, $in_password, $in_login_timeout);
544 $this->_sdk_lang = $in_lang;
546 $this->_load_localizations();
559 $in_login_timeout = -1
561 if (!$this->_api_key && $this->valid()) {
562 $this->_login_time_limit = (0 < $in_login_timeout) ? (floatval($in_login_timeout) + microtime(
true)) : -1;
563 $api_key = $this->fetch_data(
'login',
'login_id='.urlencode($in_username).
'&password='.urlencode($in_password));
565 if (isset($api_key) && $api_key) {
566 $this->_api_key = $api_key;
567 return $this->_set_up_login_info();
569 $this->set_error(_ERR_INVALID_LOGIN__);
570 $this->_api_key = NULL;
571 $this->_login_time_limit = -1;
572 $this->_my_login_info = NULL;
573 $this->_my_user_info = NULL;
576 $this->set_error(_ERR_PREV_LOGIN__);
589 if ($this->is_logged_in()) {
590 $this->_call_REST_API(
'GET',
'logout');
592 if (205 == intval($this->_last_response_code)) {
593 $this->_api_key = NULL;
594 $this->_login_time_limit = -1;
595 $this->_my_login_info = NULL;
596 $this->_my_user_info = NULL;
599 $this->set_error(_ERR_COMM_ERR__);
602 $this->set_error(_ERR_NOT_LOGGED_IN__);
603 $this->_api_key = NULL;
604 $this->_login_time_limit = -1;
605 $this->_my_login_info = NULL;
606 $this->_my_user_info = NULL;
620 $message_class =
'RVP_Locale_'.$this->_sdk_lang;
621 require_once(dirname(__FILE__).
'/lang/'.$this->_sdk_lang.
'.php');
622 $ret = [
'code' => intval($this->_error)];
623 $ret[
'message'] = $message_class::get_error_message($ret[
'code']);
635 $this->_error = isset($in_code) && (0 != intval($in_code)) ? intval($in_code) : NULL;
643 $this->set_error(NULL);
651 return isset($this->_available_plugins) && is_array($this->_available_plugins) && (3 < count($this->_available_plugins));
657 function force_reload() {
658 return $this->_set_up_login_info();
666 return isset($this->_api_key) && (0 < $this->login_time_left());
674 if ($this->is_logged_in() && isset($this->_my_login_info)) {
675 return $this->_my_login_info->is_manager();
686 if ($this->is_manager() && isset($this->_my_login_info)) {
687 return $this->_my_login_info->is_main_admin();
698 if ($this->is_logged_in() && isset($this->_my_login_info)) {
699 return $this->_my_login_info->id();
710 if ($this->is_logged_in() && isset($this->_my_login_info)) {
711 return $this->_my_login_info->login_id();
724 if ($this->is_logged_in() && isset($this->_my_login_info)) {
738 if (0 < $this->_login_time_limit) {
739 return floor(100 * max($this->_login_time_limit - microtime(
true), 0)) / 100;
750 if ($this->is_logged_in() && isset($this->_my_login_info)) {
751 $ret = [
'login' => $this->_my_login_info];
753 if (isset($this->_my_user_info)) {
754 $ret[
'user'] = $this->_my_user_info;
769 if ($this->is_logged_in() && isset($this->_my_login_info)) {
770 $ret = $this->_my_login_info->security_tokens();
783 if ($this->valid()) {
784 $ret = $this->_available_plugins;
802 if ($this->is_logged_in() && !$this->is_main_admin()) {
803 $my_login_id = $this->_my_login_info->login_id();
804 $result = $this->put_data(
'json/people/logins/my_info',
'password='.urlencode($in_new_password));
806 if (isset($result)) {
807 $result = json_decode($result);
809 if (isset($result)) {
810 if (isset($result->people)) {
811 if (isset($result->people->logins)) {
812 if (isset($result->people->logins->changed_logins)) {
813 if (is_array($result->people->logins->changed_logins)) {
814 if ((1 == count($result->people->logins->changed_logins))) {
815 if (isset($result->people->logins->changed_logins[0])) {
816 if (isset($result->people->logins->changed_logins[0]->after)) {
817 if (isset($result->people->logins->changed_logins[0]->after->password)) {
818 if (($in_new_password == $result->people->logins->changed_logins[0]->after->password)) {
819 $this->_api_key = NULL;
820 $ret = $this->login($my_login_id, $in_new_password, $this->_login_timeout);
844 $in_query_args = NULL
846 if (isset($in_query_args) && trim($in_query_args)) {
847 $in_plugin_path .=
'?'.ltrim($in_query_args,
'&');
850 $response = $this->_call_REST_API(
'GET', $in_plugin_path);
864 $in_data_object = NULL
868 if ($this->is_logged_in() && isset($in_plugin_path) && trim($in_plugin_path) && isset($in_query_args) && trim($in_query_args)) {
869 $in_plugin_path .=
'?'.ltrim($in_query_args,
'&');
870 $response = $this->_call_REST_API(
'PUT', $in_plugin_path, $in_data_object);
871 } elseif ($this->is_logged_in()) {
872 $this->set_error(_ERR_NOT_AUTHORIZED__);
874 $this->set_error(_ERR_INVALID_PARAMETERS__);
889 $in_query_args = NULL,
890 $in_data_object = NULL
894 if ($this->is_logged_in() && isset($in_plugin_path) && trim($in_plugin_path)) {
895 if (isset($in_query_args) && trim($in_query_args)) {
896 $in_plugin_path .=
'?'.ltrim($in_query_args,
'&');
899 $response = $this->_call_REST_API(
'POST', $in_plugin_path, $in_data_object);
900 } elseif ($this->is_logged_in()) {
901 $this->set_error(_ERR_NOT_AUTHORIZED__);
903 $this->set_error(_ERR_INVALID_PARAMETERS__);
920 if ($this->is_logged_in() && isset($in_plugin_path) && trim($in_plugin_path)) {
921 $response = $this->_call_REST_API(
'DELETE', $in_plugin_path);
922 } elseif ($this->is_logged_in()) {
923 $this->set_error(_ERR_NOT_AUTHORIZED__);
925 $this->set_error(_ERR_INVALID_PARAMETERS__);
940 $func_args = func_get_args();
943 if (is_array($func_args) && (1 == count($func_args)) && is_array($func_args[0]) && count($func_args[0])) {
944 $func_args = $func_args[0];
949 $args = array_map(
'intval', $func_args);
950 $arg_array = array_chunk($args, 10);
952 foreach($arg_array as $args) {
953 $handlers = $this->fetch_data(
'json/baseline/handlers/'.implode(
',', $args));
954 if (isset($handlers)) {
955 $handlers = json_decode($handlers);
956 if (isset($handlers) && isset($handlers->baseline)) {
957 $results = $this->_decode_handlers($handlers->baseline);
959 if (isset($results) && is_array($results) && count($results)) {
960 $ret = array_merge($ret, $results);
964 $this->set_error(_ERR_COMM_ERR__);
969 if (isset($ret) && is_array($ret) && (1 < count($ret))) {
970 usort($ret,
function($a, $b) {
971 if ($a->id() == $b->id()) {
975 if ($a->id() < $b->id()) {
995 if ($this->is_logged_in()) {
996 $info = $this->fetch_data(
'json/people/people/'.intval($in_user_id),
'show_details');
998 $temp = json_decode($info);
999 if (isset($temp) && isset($temp->people) && isset($temp->people->people) && isset($temp->people->people[0])) {
1000 $ret =
new RVP_PHP_SDK_User($this, $temp->people->people[0]->id, $temp->people->people[0],
true);
1002 $this->set_error(_ERR_INTERNAL_ERR__);
1007 $this->set_error(_ERR_COMM_ERR__);
1022 if ($this->is_logged_in()) {
1023 $info = $this->fetch_data(
'json/people/logins/'.intval($in_login_id),
'show_details');
1025 $temp = json_decode($info);
1026 if (isset($temp) && isset($temp->people) && isset($temp->people->logins) && isset($temp->people->logins[0])) {
1027 $ret =
new RVP_PHP_SDK_Login($this, $temp->people->logins[0]->id, $temp->people->logins[0],
true);
1029 $this->set_error(_ERR_INTERNAL_ERR__);
1034 $this->set_error(_ERR_COMM_ERR__);
1049 $info = $this->fetch_data(
'json/places/'.intval($in_place_id),
'show_details');
1051 $temp = json_decode($info);
1052 if (isset($temp) && isset($temp->places) && isset($temp->places->results) && is_array($temp->places->results) && isset($temp->places->results[0])) {
1053 $ret =
new RVP_PHP_SDK_Place($this, $temp->places->results[0]->id, $temp->places->results[0],
true);
1055 $this->set_error(_ERR_INTERNAL_ERR__);
1060 $this->set_error(_ERR_COMM_ERR__);
1074 $info = $this->fetch_data(
'json/things/'.urlencode($in_thing_id),
'show_details');
1076 $temp = json_decode($info);
1077 if (isset($temp) && isset($temp->things) && isset($temp->things[0])) {
1078 $ret =
new RVP_PHP_SDK_Thing($this, $temp->things[0]->id, $temp->things[0],
true);
1080 $this->set_error(_ERR_INTERNAL_ERR__);
1085 $this->set_error(_ERR_COMM_ERR__);
1105 $in_location = NULL,
1106 $in_writeable =
false 1110 $added_parameters =
'';
1112 if (is_array($in_text_array) && count($in_text_array)) {
1113 foreach ($in_text_array as $key => $value) {
1114 $added_parameters .= urlencode(self::_get_tag_match($key)).
'='.urlencode($value);
1118 if ($in_writeable && $this->is_logged_in()) {
1119 $added_parameters .=
'&writeable';
1122 if (NULL !== $in_location) {
1123 $added_parameters .=
'&search_latitude='.floatval($in_location[
'latitude']).
'&search_longitude='.floatval($in_location[
'longitude']).
'&search_radius='.floatval($in_location[
'radius']);
1126 $handlers = $this->fetch_data(
'json/baseline/search/', $added_parameters);
1127 if (isset($handlers)) {
1128 $handlers = json_decode($handlers);
1129 if (isset($handlers) && isset($handlers->baseline)) {
1130 $ret = $this->_decode_handlers($handlers->baseline);
1132 if (isset($ret) && is_array($ret) && (0 < count($ret))) {
1133 usort($ret,
function($a, $b) {
1134 if ($a->id() == $b->id()) {
1138 if ($a->id() < $b->id()) {
1148 $this->set_error(_ERR_COMM_ERR__);
1178 $in_location = NULL,
1179 $in_get_logins_only =
false,
1180 $in_writeable =
false 1184 $added_parameters =
'';
1186 if (is_array($in_text_array) && count($in_text_array)) {
1187 foreach ($in_text_array as $key => $value) {
1188 $added_parameters .= urlencode(self::_get_tag_match($key)).
'='.urlencode($value);
1192 if ($in_get_logins_only) {
1193 $added_parameters .=
'&login_user';
1196 if ($in_writeable && $this->is_logged_in()) {
1197 $added_parameters .=
'&writeable';
1200 if (NULL !== $in_location) {
1201 $added_parameters .=
'&search_latitude='.floatval($in_location[
'latitude']).
'&search_longitude='.floatval($in_location[
'longitude']).
'&search_radius='.floatval($in_location[
'radius']);
1204 $response = $this->fetch_data(
'json/people/people/', $added_parameters);
1205 if (isset($response)) {
1206 $response = json_decode($response);
1207 if (isset($response) && isset($response->people) && isset($response->people->people)) {
1209 $people = (array)$response->people->people;
1210 foreach ($people as $person) {
1211 if (isset($person->id)) {
1212 if ($in_get_logins_only && isset($person->associated_login)) {
1213 $new_object =
new RVP_PHP_SDK_Login($this, $person->associated_login->id, $person->associated_login,
true);
1215 $ret[] = $new_object;
1217 $this->set_error(_ERR_INTERNAL_ERR__);
1220 } elseif (!$in_get_logins_only) {
1223 $ret[] = $new_object;
1225 $this->set_error(_ERR_INTERNAL_ERR__);
1232 if (isset($ret) && is_array($ret) && (0 < count($ret))) {
1233 usort($ret,
function($a, $b) {
1234 if ($a->id() == $b->id()) {
1238 if ($a->id() < $b->id()) {
1248 $this->set_error(_ERR_COMM_ERR__);
1279 $in_location = NULL,
1280 $in_writeable =
false 1284 $added_parameters =
'';
1286 if (is_array($in_text_array) && count($in_text_array)) {
1287 foreach ($in_text_array as $key => $value) {
1288 $added_parameters .= urlencode(self::_get_tag_match($key)).
'='.urlencode($value);
1292 if ($in_writeable && $this->is_logged_in()) {
1293 $added_parameters .=
'&writeable';
1296 if (NULL !== $in_location) {
1297 $added_parameters .=
'&search_latitude='.floatval($in_location[
'latitude']).
'&search_longitude='.floatval($in_location[
'longitude']).
'&search_radius='.floatval($in_location[
'radius']);
1300 $response = $this->fetch_data(
'json/places/', $added_parameters);
1301 if (isset($response)) {
1302 $response = json_decode($response);
1303 if (isset($response) && isset($response->places) && isset($response->places->results) && is_array($response->places->results) && count($response->places->results)) {
1305 foreach ($response->places->results as $place) {
1308 $ret[] = $new_object;
1310 $this->set_error(_ERR_INTERNAL_ERR__);
1315 if (isset($ret) && is_array($ret) && (0 < count($ret))) {
1316 usort($ret,
function($a, $b) {
1317 if ($a->id() == $b->id()) {
1321 if ($a->id() < $b->id()) {
1331 $this->set_error(_ERR_COMM_ERR__);
1354 $in_location = NULL,
1355 $in_writeable =
false 1359 $added_parameters =
'';
1361 if (is_array($in_text_array) && count($in_text_array)) {
1362 foreach ($in_text_array as $key => $value) {
1363 $added_parameters .= urlencode(self::_get_tag_match($key)).
'='.urlencode($value);
1367 if ($in_writeable && $this->is_logged_in()) {
1368 $added_parameters .=
'&writeable';
1371 if (NULL !== $in_location) {
1372 $added_parameters .=
'&search_latitude='.floatval($in_location[
'latitude']).
'&search_longitude='.floatval($in_location[
'longitude']).
'&search_radius='.floatval($in_location[
'radius']);
1375 $response = $this->fetch_data(
'json/things/', $added_parameters);
1376 if (isset($response)) {
1377 $response = json_decode($response);
1378 if (isset($response) && isset($response->things) && is_array($response->things) && count($response->things)) {
1380 foreach ($response->things as $thing) {
1383 $ret[] = $new_object;
1385 $this->set_error(_ERR_INTERNAL_ERR__);
1390 if (isset($ret) && is_array($ret) && (0 < count($ret))) {
1391 usort($ret,
function($a, $b) {
1392 if ($a->id() == $b->id()) {
1396 if ($a->id() < $b->id()) {
1406 $this->set_error(_ERR_COMM_ERR__);
1419 return $this->general_search(NULL, $in_location);
1427 $in_get_logins_only =
false 1429 return $this->people_search(NULL, $in_location, $in_get_logins_only);
1438 return $this->places_search(NULL, $in_location);
1447 return $this->things_search(NULL, $in_location);
1462 $in_target_number = 10,
1463 $in_search_type =
'all',
1470 $in_search_string_criteria = NULL,
1471 $in_step_size_in_km = 0.5,
1472 $in_max_width_in_km = 100,
1473 $step_callback = NULL
1490 $location = [
'latitude' => floatval($in_center_point[
'latitude']),
'longitude' => floatval($in_center_point[
'longitude']),
'radius' => $radius];
1492 while (($in_target_number > count($results)) && ($in_max_width_in_km >= ($radius + $in_step_size_in_km))) {
1493 $radius += floatval($in_step_size_in_km);
1494 $location[
'radius'] = $radius;
1495 switch (strtolower(trim($in_search_type))) {
1498 $in_search_type =
'users';
1500 $results = $this->people_search($in_search_string_criteria, $location, (
'logins' == $in_search_type));
1504 $results = $this->places_search($in_search_string_criteria, $location);
1508 $results = $this->things_search($in_search_string_criteria, $location);
1512 $in_search_type =
'all';
1513 $results = $this->general_search($in_search_string_criteria, $location);
1518 if (isset($step_callback)) {
1521 if (is_array($step_callback) && (2 == count($step_callback))) {
1522 $object = $step_callback[0];
1523 $method = $step_callback[1];
1524 if (method_exists($object, $method)) {
1525 $abort = $object->$method($this, $results, strtolower(trim($in_search_type)), $in_target_number, $in_step_size_in_km, $in_max_width_in_km, $location, $in_search_string_criteria);
1527 } elseif (function_exists($step_callback)) {
1528 $abort = $step_callback($this, $results, strtolower(trim($in_search_type)), $in_target_number, $in_step_size_in_km, $in_max_width_in_km, $location, $in_search_string_criteria);
1556 if ($this->is_main_admin()) {
1557 return json_decode($this->post_data(
'json/baseline/bulk-loader', NULL, [
'data' => $in_csv_data,
'type' =>
'text/csv']));
1559 $this->set_error(_ERR_NOT_AUTHORIZED__);
1571 if ($this->is_main_admin()) {
1572 return $this->fetch_data(
'csv/baseline/backup');
1574 $this->set_error(_ERR_NOT_AUTHORIZED__);
1586 if ($this->is_main_admin()) {
1587 $result = json_decode($this->fetch_data(
'json/baseline/serverinfo'));
1588 if (isset($result->baseline) && isset($result->baseline->serverinfo)) {
1589 return $result->baseline->serverinfo;
1592 $this->set_error(_ERR_NOT_AUTHORIZED__);
1608 $in_is_token =
false 1612 $in_id = intval($in_id);
1615 if ((1 < $in_id) || ($in_is_token && (0 <= $in_id))) {
1616 $uri =
'json/baseline/visibility/'. ($in_is_token ?
'token/' :
'');
1618 $response = $this->fetch_data($uri);
1619 if (isset($response)) {
1620 $response = json_decode($response);
1621 if (isset($response) && isset($response->baseline)) {
1622 $response = $response->baseline;
1623 if (isset($response->token) && isset($response->token->login_ids) && is_array($response->token->login_ids) && count($response->token->login_ids)) {
1624 $ret = $response->token->login_ids;
1625 } elseif (isset($response->id) && isset($response->id->id)) {
1626 $response = $response->id;
1627 $ret = [
'id' => $response->id];
1628 if (isset($response->writeable)) {
1629 $ret[
'writeable'] =
true;
1631 if (isset($response->read_login_ids) && is_array($response->read_login_ids) && count($response->read_login_ids)) {
1632 $ret[
'read_login_ids'] = $response->read_login_ids;
1634 if (isset($response->write_login_ids) && is_array($response->write_login_ids) && count($response->write_login_ids)) {
1635 $ret[
'write_login_ids'] = $response->write_login_ids;
1642 $this->set_error(_ERR_INVALID_PARAMETERS__);
1666 $need_a_write_in =
false;
1667 $login_id = (isset($in_login_id) && trim($in_login_id)) ? trim($in_login_id) : NULL;
1669 if ($this->is_manager()) {
1672 $uri =
'json/people/logins/'.$login_id.
'?test';
1673 $response = $this->fetch_data($uri);
1674 if (isset($response)) {
1675 $response = json_decode($response);
1676 if (isset($response) && isset($response->people) && isset($response->people->logins) && isset($response->people->logins->login_exists) && $response->people->logins->login_exists) {
1677 $this->set_error(_ERR_INVALID_LOGIN_ID__);
1680 if (!isset($in_tokens) || !is_array($in_tokens) || !isset($in_tokens[
'write']) || !intval($in_tokens[
'write'])) {
1681 $need_a_write_in =
true;
1685 $this->set_error(_ERR_COMM_ERR__);
1689 if (!isset($in_tokens) || !isset($in_tokens[
'write']) || (1 > intval($in_tokens[
'write'])) || !in_array(intval($in_tokens[
'write']), $this->my_tokens())) {
1690 $this->set_error(_ERR_INVALID_PARAMETERS__);
1696 $this->set_error(_ERR_NOT_AUTHORIZED__);
1701 $uri =
'json/people/people';
1704 $params .=
'&login_id='.urlencode($login_id);
1707 if (isset($in_tokens) && is_array($in_tokens) && count($in_tokens) && isset($in_tokens[
'read'])) {
1708 $params .=
'&read_token='.intval($in_tokens[
'read']);
1711 if (isset($in_tokens) && is_array($in_tokens) && count($in_tokens) && isset($in_tokens[
'write']) && (0 < intval($in_tokens[
'write']))) {
1712 $params .=
'&write_token='.intval($in_tokens[
'write']);
1715 if (isset($in_tokens) && is_array($in_tokens) && count($in_tokens) && isset($in_tokens[
'tokens'])) {
1716 $params .=
'&tokens='.implode(
',', array_map(
'intval', $in_tokens[
'tokens']));
1719 $uri .=
'/?'.trim($params,
"\&");
1721 $response = $this->post_data($uri);
1723 if (isset($response)) {
1724 $response = json_decode($response);
1726 if (isset($response) && isset($response->people) && isset($response->people->people) && isset($response->people->people->new_user)) {
1729 if (isset($response->people->people->new_user->associated_login)) {
1730 $ret[
'login_id'] = $response->people->people->new_user->associated_login->login_id;
1731 $ret[
'password'] = $response->people->people->new_user->associated_login->password;
1732 unset($response->people->people->new_user->associated_login->password);
1733 $id = $response->people->people->new_user->associated_login->id;
1734 $response->people->people->new_user->associated_login_id = $id;
1735 $ret[
'login'] =
new RVP_PHP_SDK_Login($this, $id, $response->people->people->new_user->associated_login,
true);
1736 unset($response->people->people->new_user->associated_login);
1739 $ret[
'user'] =
new RVP_PHP_SDK_User($this, $response->people->people->new_user->id, $response->people->people->new_user,
true);
1761 $in_latitude = NULL,
1762 $in_longitude = NULL,
1763 $in_fuzz_factor = NULL
1767 if ($this->is_logged_in()) {
1768 $uri =
'json/places';
1770 if ($in_place_name) {
1771 $params .=
'&name='.urlencode($in_place_name);
1775 $params .=
'&latitude='.floatval($in_latitude);
1778 if ($in_longitude) {
1779 $params .=
'&longitude='.floatval($in_longitude);
1782 if ($in_fuzz_factor) {
1783 $params .=
'&fuzz_factor='.floatval($in_fuzz_factor);
1786 if (isset($in_tokens) && is_array($in_tokens) && count($in_tokens) && isset($in_tokens[
'read'])) {
1787 $params .=
'&read_token='.intval($in_tokens[
'read']);
1790 if (isset($in_tokens) && is_array($in_tokens) && count($in_tokens) && isset($in_tokens[
'write']) && (0 < intval($in_tokens[
'write']))) {
1791 $params .=
'&write_token='.intval($in_tokens[
'write']);
1794 $params = trim($params,
"\&");
1796 $response = $this->post_data($uri, $params);
1798 if (isset($response)) {
1799 $response = json_decode($response);
1801 if (isset($response) && isset($response->places) && isset($response->places->new_place)) {
1802 $response = $response->places->new_place;
1808 $this->set_error(_ERR_NOT_AUTHORIZED__);
1828 $in_thing_name = NULL,
1829 $in_thing_description = NULL
1833 if ($this->is_logged_in() && isset($in_thing_key) && $in_thing_key && isset($in_thing_value) && $in_thing_value) {
1834 $uri =
'json/things';
1837 $in_thing_key = trim($in_thing_key);
1839 if (
false !== strpos($in_thing_key,
',')) {
1840 $in_thing_key = NULL;
1843 if ($in_thing_key) {
1844 $params .=
'&key='.urlencode($in_thing_key);
1847 if (isset($in_tokens) && is_array($in_tokens) && count($in_tokens) && isset($in_tokens[
'read'])) {
1848 $params .=
'&read_token='.intval($in_tokens[
'read']);
1851 if (isset($in_tokens) && is_array($in_tokens) && count($in_tokens) && isset($in_tokens[
'write']) && (0 < intval($in_tokens[
'write']))) {
1852 $params .=
'&write_token='.intval($in_tokens[
'write']);
1855 if ($in_thing_name) {
1856 $params .=
'&name='.urlencode($in_thing_name);
1859 if ($in_thing_description) {
1860 $params .=
'&description='.urlencode($in_thing_description);
1863 $params = trim($params,
"\&");
1865 $temp_file = tempnam(sys_get_temp_dir(),
'RVP');
1866 file_put_contents($temp_file , $in_thing_value);
1867 $finfo = finfo_open(FILEINFO_MIME_TYPE);
1868 $content_type = finfo_file($finfo, $temp_file);
1870 $payload = [
'data' => $in_thing_value,
'type' => $content_type];
1872 $response = $this->post_data($uri, $params, $payload);
1874 if (isset($response)) {
1875 $response = json_decode($response);
1877 if (isset($response) && isset($response->things) && isset($response->things->new_thing)) {
1878 $response = $response->things->new_thing;
1885 $this->set_error($this->is_logged_in() ? _ERR_INVALID_PARAMETERS__ : _ERR_NOT_AUTHORIZED__);
1903 if ($this->is_manager() && isset($in_object)) {
1908 if ($in_object->writeable()) {
1909 $user_id = $in_object->id();
1912 if ($in_object->writeable()) {
1913 $login_id = $in_object->id();
1916 $user_id = intval($in_object);
1919 if ($user_id || $login_id) {
1920 $uri =
'json/people';
1924 $response = $this->delete_data($uri.
'/people/'.$user_id);
1926 if (isset($response)) {
1927 $response = json_decode($response);
1929 if (!(isset($response) && isset($response->people->people) && isset($response->people->people->deleted_users) && is_array($response->people->people->deleted_users) && (1 == count($response->people->people->deleted_users)) && ($user_id == $response->people->people->deleted_users[0]->id))) {
1930 $this->set_error(_ERR_COMM_ERR__);
1932 } elseif (isset($response->people->people->deleted_users[0]->associated_login_id)) {
1933 $login_id = intval($response->people->people->deleted_users[0]->associated_login_id);
1934 } elseif (isset($response->people->people->deleted_users[0]->associated_login)) {
1935 $login_id = intval($response->people->people->deleted_users[0]->associated_login->id);
1938 $this->set_error(_ERR_COMM_ERR__);
1943 if ($ret && $login_id) {
1944 $response = $this->delete_data($uri.
'/logins/'.$login_id);
1946 if (isset($response)) {
1947 $response = json_decode($response);
1949 if (!(isset($response) && isset($response->people->logins) && isset($response->people->logins->deleted_logins) && is_array($response->people->logins->deleted_logins) && (1 == count($response->people->logins->deleted_logins)) && ($login_id == $response->people->logins->deleted_logins[0]->id))) {
1950 $this->set_error(_ERR_COMM_ERR__);
1954 $this->set_error(_ERR_COMM_ERR__);
1961 $this->set_error($this->is_manager() ? _ERR_INVALID_PARAMETERS__ : _ERR_NOT_AUTHORIZED__);
1977 if ($this->is_logged_in() && isset($in_object)) {
1981 $place_id = $in_object->id();
1983 $place_id = intval($in_object);
1987 if (isset($this->test_visibility($place_id)[
'writeable'])) {
1988 $uri =
'json/places/'.$place_id;
1990 $response = $this->delete_data($uri);
1992 if (isset($response)) {
1993 $response = json_decode($response);
1995 if (!(isset($response) && isset($response->places) && isset($response->places->deleted_places) && is_array($response->places->deleted_places) && (1 == count($response->places->deleted_places)) && ($place_id == $response->places->deleted_places[0]->id))) {
1996 $this->set_error(_ERR_COMM_ERR__);
2001 $this->set_error(_ERR_NOT_AUTHORIZED__);
2006 $this->set_error($this->is_logged_in() ? _ERR_INVALID_PARAMETERS__ : _ERR_NOT_AUTHORIZED__);
2022 if ($this->is_logged_in() && isset($in_object)) {
2025 if ($in_object instanceof RVP_PHP_SDK_thing) {
2026 $thing_id = $in_object->id();
2028 $thing = $this->get_thing_info($in_object);
2029 if (isset($thing) && ($thing instanceof RVP_PHP_SDK_thing)) {
2030 $thing_id = intval($thing->id());
2035 if (isset($this->test_visibility($thing_id)[
'writeable'])) {
2036 $uri =
'json/things/'.$thing_id;
2038 $response = $this->delete_data($uri);
2040 if (isset($response)) {
2041 $response = json_decode($response);
2043 if (!(isset($response) && isset($response->things) && isset($response->things->deleted_things) && is_array($response->things->deleted_things) && (1 == count($response->things->deleted_things)))) {
2044 $this->set_error(_ERR_COMM_ERR__);
2049 $this->set_error(_ERR_NOT_AUTHORIZED__);
2054 $this->set_error($this->is_logged_in() ? _ERR_INVALID_PARAMETERS__ : _ERR_NOT_AUTHORIZED__);
get_place_info( $in_place_id)
$_server_uri
This is the URI of the BAOBAB server.
static _get_tag_match( $in_string)
fetch_data( $in_plugin_path, $in_query_args=NULL)
get_login_info( $in_login_id)
$_my_login_info
This will contain any login information for the current login (NULL if not logged in)...
thing_location_search( $in_location)
$_login_time_limit
If >0, then this is the maximum time at which the current login is valid.
new_place( $in_place_name, $in_tokens=[], $in_latitude=NULL, $in_longitude=NULL, $in_fuzz_factor=NULL)
delete_place( $in_object)
people_location_search( $in_location, $in_get_logins_only=false)
$_localizations
An array of string, with the available localizations. The first will always be the default localizati...
static _get_string_match_table()
general_search( $in_text_array=[], $in_location=NULL, $in_writeable=false)
new_user( $in_user_name, $in_tokens, $in_login_id=NULL)
get_user_info( $in_user_id)
$_error
This is supposed to be NULL. However, if we have an error, it will contain an integer code...
$_login_timeout
The actual timeout value that was originally passed in.
auto_radius_search( $in_center_point, $in_target_number=10, $in_search_type='all', $in_search_string_criteria=NULL, $in_step_size_in_km=0.5, $in_max_width_in_km=100, $step_callback=NULL)
new_thing( $in_thing_key, $in_thing_value, $in_tokens=[], $in_thing_name=NULL, $in_thing_description=NULL)
things_search( $in_text_array=[], $in_location=NULL, $in_writeable=false)
$_available_plugins
This will be an array of string, with available plugins on the server.
delete_thing( $in_object)
$_my_user_info
This will contain any login information for the current login (NULL if not logged in)...
test_visibility( $in_id, $in_is_token=false)
place_location_search( $in_location)
login( $in_username, $in_password, $in_login_timeout=-1)
_call_REST_API( $method, $url_extension, $data_input=NULL, $display_log=false)
delete_data( $in_plugin_path)
people_search( $in_text_array=[], $in_location=NULL, $in_get_logins_only=false, $in_writeable=false)
change_my_password_to( $in_new_password)
get_thing_info( $in_thing_id)
_decode_handlers( $in_handlers)
$_api_key
This is the current session API key.
places_search( $in_text_array=[], $in_location=NULL, $in_writeable=false)
bulk_upload( $in_csv_data)
__construct( $in_server_uri, $in_server_secret, $in_username=NULL, $in_password=NULL, $in_login_timeout=0)
post_data( $in_plugin_path, $in_query_args=NULL, $in_data_object=NULL)
$_localized_errors
This will be an associative array, with the loaded RVP_Local_Error_* instances for display of error m...
general_location_search( $in_location)
$_last_response_code
This will contain any response code from the last cURL call.
$_server_secret
This is the "server secret" that is specified by the admin of the BAOBAB server.
$_sdk_lang
The language specified for this SDK instance. Default is "en" (English).
put_data( $in_plugin_path, $in_query_args, $in_data_object=NULL)
current_login_id_string()