BLUE DRAGON PHP SDK
All Classes Functions Variables Pages
RVP_PHP_SDK Class Reference

Public Member Functions

 __construct ( $in_server_uri, $in_server_secret, $in_username=NULL, $in_password=NULL, $in_login_timeout=0)
 
 __destruct ()
 
 set_lang ( $in_lang)
 
 login ( $in_username, $in_password, $in_login_timeout=-1)
 
 logout ()
 
 get_error ()
 
 set_error ( $in_code)
 
 clear_error ()
 
 valid ()
 
 force_reload ()
 
 is_logged_in ()
 
 is_manager ()
 
 is_main_admin ()
 
 current_login_id ()
 
 current_login_id_string ()
 
 current_login_object ()
 
 login_time_left ()
 
 my_info ()
 
 my_tokens ()
 
 plugins ()
 
 change_my_password_to ( $in_new_password)
 
 fetch_data ( $in_plugin_path, $in_query_args=NULL)
 
 put_data ( $in_plugin_path, $in_query_args, $in_data_object=NULL)
 
 post_data ( $in_plugin_path, $in_query_args=NULL, $in_data_object=NULL)
 
 delete_data ( $in_plugin_path)
 
 get_objects ()
 
 get_user_info ( $in_user_id)
 
 get_login_info ( $in_login_id)
 
 get_place_info ( $in_place_id)
 
 get_thing_info ( $in_thing_id)
 
 general_search ( $in_text_array=[], $in_location=NULL, $in_writeable=false)
 
 people_search ( $in_text_array=[], $in_location=NULL, $in_get_logins_only=false, $in_writeable=false)
 
 places_search ( $in_text_array=[], $in_location=NULL, $in_writeable=false)
 
 things_search ( $in_text_array=[], $in_location=NULL, $in_writeable=false)
 
 general_location_search ( $in_location)
 
 people_location_search ( $in_location, $in_get_logins_only=false)
 
 place_location_search ( $in_location)
 
 thing_location_search ( $in_location)
 
 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)
 
 bulk_upload ( $in_csv_data)
 
 backup ()
 
 get_serverinfo ()
 
 test_visibility ( $in_id, $in_is_token=false)
 
 new_user ( $in_user_name, $in_tokens, $in_login_id=NULL)
 
 new_place ( $in_place_name, $in_tokens=[], $in_latitude=NULL, $in_longitude=NULL, $in_fuzz_factor=NULL)
 
 new_thing ( $in_thing_key, $in_thing_value, $in_tokens=[], $in_thing_name=NULL, $in_thing_description=NULL)
 
 delete_user ( $in_object)
 
 delete_place ( $in_object)
 
 delete_thing ( $in_object)
 

Protected Member Functions

 _call_REST_API ( $method, $url_extension, $data_input=NULL, $display_log=false)
 
 _decode_handlers ( $in_handlers)
 
 _load_localizations ()
 
 _get_my_info ()
 
 _get_plugins ()
 
 _set_up_login_info ()
 

Static Protected Member Functions

static _get_string_match_table ()
 
static _get_tag_match ( $in_string)
 

Protected Attributes

 $_server_uri
 This is the URI of the BAOBAB server.
 
 $_sdk_lang
 The language specified for this SDK instance. Default is "en" (English).
 
 $_server_secret
 This is the "server secret" that is specified by the admin of the BAOBAB server.
 
 $_api_key
 This is the current session API key.
 
 $_login_timeout
 The actual timeout value that was originally passed in.
 
 $_login_time_limit
 If >0, then this is the maximum time at which the current login is valid.
 
 $_error
 This is supposed to be NULL. However, if we have an error, it will contain an integer code.
 
 $_my_login_info
 This will contain any login information for the current login (NULL if not logged in).
 
 $_my_user_info
 This will contain any login information for the current login (NULL if not logged in).
 
 $_last_response_code
 This will contain any response code from the last cURL call.
 
 $_available_plugins
 This will be an array of string, with available plugins on the server.
 
 $_localizations
 An array of string, with the available localizations. The first will always be the default localization.
 
 $_localized_errors
 This will be an associative array, with the loaded RVP_Local_Error_* instances for display of error messages.
 

Detailed Description

This is the central SDK class for connecting a PHP application to a BAOBAB server.

Upon instantiation, a valid server base URI and secret need to be provided.

Optionally, you can also provide login credentials.

This object should be used to manage all connections to the server.

Definition at line 43 of file rvp_php_sdk.class.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $in_server_uri,
  $in_server_secret,
  $in_username = NULL,
  $in_password = NULL,
  $in_login_timeout = 0 
)

The basic constructor, which includes a validity test and a possible login.

Parameters
$in_server_uriREQUIRED: The URI of the BAOBAB Server
$in_server_secretREQUIRED: The "server secret" for the BAOBAB Server.
$in_usernameOPTIONAL: The Login Username, if we are doing an immediate login.
$in_passwordOPTIONAL: The password, if we are doing an immediate login.
$in_login_timeoutOPTIONAL/REQUIRED: The login timeout, in seconds (integer). This must be provided if there is a login/password.

Definition at line 504 of file rvp_php_sdk.class.php.

509  {
510  $this->_server_uri = trim($in_server_uri, '/'); // This is the server's base URI.
511  $this->_server_secret = $in_server_secret; // This is the secret that we need to provide with authentication.
512  $this->_api_key = NULL; // If we log in, this will be non-NULL, and will contain the active API key for this instance.
513  $this->_login_time_limit = -1; // No timeout to start.
514  $this->_login_timeout = $in_login_timeout; // Save this for posterity.
515  $this->_my_login_info = NULL; // If we have logged in, we have the info for our login here.
516  $this->_my_user_info = NULL; // If we have logged in, we have the info for our user (if available) here.
517 
518  $this->clear_error(); // Start off clean.
519  $this->set_lang('en'); // Set to default (English). The implementor should call this after instantiation to change.
520 
521  $this->_available_plugins = $this->_get_plugins();
522 
523  if ($this->valid()) {
524  if ($in_username && $in_password && $in_login_timeout) {
525  $this->login($in_username, $in_password, $in_login_timeout);
526  }
527  }
528  }
login( $in_username, $in_password, $in_login_timeout=-1)
set_lang( $in_lang)

◆ __destruct()

__destruct ( )

The basic destructor. We make sure that we log out.

Definition at line 534 of file rvp_php_sdk.class.php.

534  {
535  $this->logout(); // Don't bother checking for current login. Just call logout().
536  }

Member Function Documentation

◆ _get_string_match_table()

static _get_string_match_table ( )
staticprotected
Returns
an associative array, with a matching table for short names to their "search_*" equivalents.

Definition at line 65 of file rvp_php_sdk.class.php.

65  {
66  return [
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',
97  ];
98  }

◆ _get_tag_match()

static _get_tag_match (   $in_string)
staticprotected
Returns
the "search_*" equivalent of the short name that is presented.
Parameters
$in_stringREQUIRED: The name of the field that is to be translated to a tag.

Definition at line 104 of file rvp_php_sdk.class.php.

105  {
106  $ret = $in_string;
107  $table = static::_get_string_match_table();
108 
109  if (isset($table[$ret]) && $table[$ret]) {
110  $ret = $table[$ret];
111  }
112 
113  return $ret;
114  }

◆ _call_REST_API()

_call_REST_API (   $method,
  $url_extension,
  $data_input = NULL,
  $display_log = false 
)
protected

This is the function that is used by the SDK to make REST calls to the BAOBAB server.

Returns
the resulting transfer from the server, as a string of bytes.
Parameters
$methodREQUIRED: This is the method to call. It should be one of:
  • 'GET' This is considered the default, but should be provided anyway, in order to ensure that the intent is clear.
  • 'POST' This means that the resource needs to be created.
  • 'PUT' This means that the resource is to be modified.
  • 'DELETE' This means that the resource is to be deleted.
$url_extensionREQIRED: This is the query section of the URL for the call. It can be empty, but you probably won't get much, if it is.
$data_inputOPTIONAL: Default is NULL. This is an associative array, containing a collection of data, and a MIME type ("data" and "type") to data to be uploaded to the server, along with the URL. This will be Base64-encoded, so it is not necessary for it to be already encoded.
$display_logOPTIONAL: Default is false. If true, then the function will echo detailed debug information.

Definition at line 125 of file rvp_php_sdk.class.php.

134  {
135 
136  $method = strtoupper(trim($method)); // Make sure the method is always uppercase.
137  // Initialize function local variables.
138  $file = NULL; // This will be a file handle, for uploads.
139  $content_type = NULL; // This is used to signal the content-type for uploaded files.
140  $file_size = 0; // This is the size, in bytes, of uploaded files.
141  $temp_file_name = NULL; // This is a temporary file that is used to hold files before they are sent to the server.
142  $file_data = NULL;
143 
144  // If data is provided by the caller, we read it into a temporary location, and Base64-encode it.
145  if ($data_input) {
146 
147  $file_data = base64_encode($data_input['data']);
148 
149  $temp_file_name = tempnam(sys_get_temp_dir(), 'RVP');
150 
151  $file = fopen($temp_file_name, 'w');
152 
153  fwrite($file, $file_data, strlen($file_data));
154 
155  fclose($file);
156 
157  $content_type = $data_input['type'].':base64';
158  $file_size = filesize($temp_file_name);
159 
160  $file = fopen($temp_file_name, 'rb');
161  }
162 
163  $curl = curl_init(); // Initialize the cURL handle.
164 
165  // Different methods require different ways of dealing with any file that has been passed in.
166  // The file is ignored for GET and DELETE.
167  // We ask the server not to send us EXPECT (HTTP 100) calls for POST and PUT.
168  switch ($method) {
169  case "POST":
170  curl_setopt($curl, CURLOPT_POST, true);
171 
172  // POST sends the file as a standard multipart/form-data item.
173  if ($file) {
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);
178  } else {
179  curl_setopt($curl, CURLOPT_HTTPHEADER, ['Expect:']);
180  }
181  break;
182 
183  case "PUT":
184  curl_setopt($curl, CURLOPT_HTTPHEADER, ['Expect:']);
185  curl_setopt($curl, CURLOPT_PUT, true);
186 
187  // PUT requires a direct inline file transfer.
188  if ($file) {
189  curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
190  curl_setopt($curl, CURLOPT_INFILE, $file);
191  curl_setopt($curl, CURLOPT_INFILESIZE, $file_size);
192  }
193  break;
194 
195  case "DELETE":
196  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
197  }
198 
199  // Authentication. We provide the Server Secret and the API key here.
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);
203 
204  // This is because some servers may intercept the auth headers, so we also supply the credentials as URL query arguments.
205  if (isset($url_extension) && (false !== strpos($url_extension, '?'))) { // See if we need to append, or begin a new query.
206  $url_extension .= '&';
207  } else {
208  $url_extension .= '?';
209  }
210 
211  $url_extension .= 'login_server_secret='.urlencode($this->_server_secret).'&login_api_key='.urlencode($this->_api_key);
212  }
213 
214  curl_setopt($curl, CURLOPT_HEADER, false); // Do not return any headers, please.
215  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Please return to sender as a function response.
216  curl_setopt($curl, CURLOPT_VERBOSE, false); // Let's keep this thing simple.
217  $url = $this->_server_uri.'/'.trim($url_extension, '/');
218  curl_setopt($curl, CURLOPT_URL, $url); // This is the URL we are calling.
219 
220  // This is if we want to see a display log (echoed directly).
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);
225  });
226  echo('<div style="margin:1em">');
227  echo("<h4>Sending REST $method CALL:</h4>");
228  echo('<div>URL: <code>'.htmlspecialchars($url).'</code></div>');
229 
230  if ($this->_api_key) {
231  echo('<div>API KEY:<pre>'.htmlspecialchars($this->_api_key).'</pre></div>');
232  } else {
233  echo('<div>NO API KEY</div>');
234  }
235  }
236 
237  $result = curl_exec($curl); // Do it to it.
238 
239  $this->_last_response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
240 
241  curl_close($curl); // Bye, now.
242 
243  // More reportage.
244  if (isset($display_log) && $display_log) {
245  if (isset($file_data)) {
246  $len = floatval(strlen($file_data));
247 
248  if (0 == $len) {
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>');
258  }
259  echo('<p><strong>ADDITIONAL DATA SHA:</strong> <big><code>'.sha1($file_data).'</code></big></p>');
260  }
261 
262  if (isset($httpCode) && $httpCode) {
263  echo('<div>HTTP CODE:<code>'.htmlspecialchars($httpCode, true).'</code></div>');
264  }
265 
266  if ((2048 * 1024) <= strlen($result)) { // Anything over 2MB gets spewed to a file.
267  $integer = 1;
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';
272  $integer++;
273  }
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>');
278  } else {
279  echo('<div>RESULT:<pre>'.htmlspecialchars(print_r(chunk_split($result, 1024), true)).'</pre></div>');
280  }
281  echo("</div>");
282  }
283 
284  // If we had a file open for transfer, we close it now.
285  if ($file) {
286  fclose($file);
287  }
288 
289  return $result;
290  }

◆ _decode_handlers()

_decode_handlers (   $in_handlers)
protected
Returns
an array of unresolved objects (of any kind) that meet the ID requirements. NOTE: If the current user does not have permission to view resources, or the resources don't exist, they will not be returned.
Parameters
$in_handlersREQUIRED: An associative array ('people' => array of int, 'places' => array of int, 'things' => array of int), with lists of IDs for various resources.

Definition at line 296 of file rvp_php_sdk.class.php.

297  {
298  $ret = NULL;
299  $plugin_list = [];
300  if (isset($in_handlers->people) && is_array($in_handlers->people) && count($in_handlers->people)) {
301  $plugin_list['people'] = $in_handlers->people;
302  }
303  if (isset($in_handlers->places) && is_array($in_handlers->places) && count($in_handlers->places)) {
304  $plugin_list['places'] = $in_handlers->places;
305  }
306  if (isset($in_handlers->things) && is_array($in_handlers->things) && count($in_handlers->things)) {
307  $plugin_list['things'] = $in_handlers->things;
308  }
309 
310  if (isset($plugin_list) && is_array($plugin_list) && count($plugin_list)) {
311  $ret = [];
312  foreach ($plugin_list as $plugin => $list) {
313  sort($list);
314  foreach ($list as $id) {
315  $id = intval($id);
316 
317  if (1 < $id) {
318  switch ($plugin) {
319  case 'people':
320  $new_object = new RVP_PHP_SDK_User($this, $id);
321  if (isset($new_object) && ($new_object instanceof RVP_PHP_SDK_User)) {
322  $ret[] = $new_object;
323  } else {
324  $this->set_error(_ERR_INTERNAL_ERR__);
325  return NULL;
326  }
327  break;
328 
329  case 'places':
330  $new_object = new RVP_PHP_SDK_Place($this, $id);
331  if (isset($new_object) && ($new_object instanceof RVP_PHP_SDK_Place)) {
332  $ret[] = $new_object;
333  } else {
334  $this->set_error(_ERR_INTERNAL_ERR__);
335  return NULL;
336  }
337  break;
338 
339  case 'things':
340  $new_object = new RVP_PHP_SDK_Thing($this, $id);
341  if (isset($new_object) && ($new_object instanceof RVP_PHP_SDK_Thing)) {
342  $ret[] = $new_object;
343  } else {
344  $this->set_error(_ERR_INTERNAL_ERR__);
345  return NULL;
346  }
347  break;
348  }
349  }
350  }
351  }
352  }
353 
354  return $ret;
355  }
set_error( $in_code)

◆ _load_localizations()

_load_localizations ( )
protected

This loads the localization objects for this instance.

Returns
an array of string, with each of the localizations loaded.

Definition at line 363 of file rvp_php_sdk.class.php.

363  {
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');
369  }
370  }
371 
372  $this->_localizations = [];
373 
374  // Read each available file, and add it to our list.
375  foreach ($locale_name_array as $locale) {
376  if ($locale != $this->_sdk_lang) {
377  $this->_localizations[] = $locale;
378  }
379  }
380 
381  sort($this->_localizations); // Simple alpha-sort.
382  array_unshift($this->_localizations, $this->_sdk_lang); // Make sure the first one is always our default.
383  }

◆ _get_my_info()

_get_my_info ( )
protected
Returns
an associative array ('login' => login JSON object, 'user' => user JSON object), with the current information for any valid login.

Definition at line 389 of file rvp_php_sdk.class.php.

389  {
390  $ret = NULL;
391 
392  if ($this->is_logged_in()) {
393  $info = $this->fetch_data('json/people/logins/my_info');
394  if ($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');
401  if ($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;
406  } else {
407  $this->set_error(_ERR_COMM_ERR__);
408  }
409  } else {
410  $this->set_error(_ERR_NO_RESULTS__);
411  }
412  } else {
413  $ret = ['login' => $login_info];
414  }
415  }
416  } else {
417  $this->set_error(_ERR_NO_RESULTS__);
418  }
419  }
420 
421  return $ret;
422  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ _get_plugins()

_get_plugins ( )
protected
Returns
an array of string, with all the available plugins on the server.

Definition at line 428 of file rvp_php_sdk.class.php.

428  {
429  $ret = NULL;
430 
431  $info = $this->fetch_data('json/baseline');
432  if ($info) {
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;
436  } else {
437  $this->set_error(_ERR_COMM_ERR__);
438  }
439  } else {
440  $this->set_error(_ERR_NO_RESULTS__);
441  }
442 
443  return $ret;
444  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ _set_up_login_info()

_set_up_login_info ( )
protected

This sets up the internal "my info" objects.

Returns
true, if the operation succeeded.

Definition at line 452 of file rvp_php_sdk.class.php.

452  {
453  if ($this->_api_key) {
454  $this->_my_login_info = NULL;
455  $this->_my_user_info = NULL;
456 
457  $info = $this->_get_my_info();
458 
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);
462 
463  if (!($this->_my_login_info instanceof RVP_PHP_SDK_Login)) {
464  $this->set_error(_ERR_INTERNAL_ERR__);
465  $this->logout();
466  $this->_api_key = NULL;
467  $this->_login_time_limit = -1;
468  $this->_my_login_info = NULL;
469  $this->_my_user_info = NULL;
470  return false;
471  }
472  }
473 
474  if (isset($info['user'])) {
475  $this->_my_user_info = new RVP_PHP_SDK_User($this, $info['user']->id, $info['user'], true);
476 
477  if (!($this->_my_user_info instanceof RVP_PHP_SDK_User)) {
478  $this->set_error(_ERR_INTERNAL_ERR__);
479  $this->logout();
480  $this->_api_key = NULL;
481  $this->_login_time_limit = -1;
482  $this->_my_login_info = NULL;
483  $this->_my_user_info = NULL;
484  return false;
485  }
486  }
487 
488  return true;
489  }
490 
491  $this->_api_key = NULL;
492  }
493 
494  return false;
495  }
set_error( $in_code)

◆ set_lang()

set_lang (   $in_lang)

This simply sets the SDK language, and also reloads the localizations.

Parameters
$in_langREQUIRED: The lang code to set as the default for the SDK instance.

Definition at line 542 of file rvp_php_sdk.class.php.

543  {
544  $this->_sdk_lang = $in_lang;
545 
546  $this->_load_localizations();
547  }

◆ login()

login (   $in_username,
  $in_password,
  $in_login_timeout = -1 
)

This executes a login to the server.

Upon successful login, the "my_info" queries are made to the login, and, if applicable, the user.

Returns
true, if the login was successful.
Parameters
$in_usernameREQUIRED: The Login Username
$in_passwordREQUIRED: The password.
$in_login_timeoutOPTIONAL: If we have a known login timeout, we provide it here. Default is -1 (no timeout).

Definition at line 557 of file rvp_php_sdk.class.php.

560  {
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));
564 
565  if (isset($api_key) && $api_key) { // If we logged in, then we get our info.
566  $this->_api_key = $api_key;
567  return $this->_set_up_login_info();
568  } else {
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;
574  }
575  } else {
576  $this->set_error(_ERR_PREV_LOGIN__);
577  }
578 
579  return false;
580  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ logout()

logout ( )

Logs the current user out, and resets the object to a "connection-only" state.

Returns
true, if the logout was successful.

Definition at line 588 of file rvp_php_sdk.class.php.

588  {
589  if ($this->is_logged_in()) {
590  $this->_call_REST_API('GET', 'logout'); // We call this directly, because we will not be using a return type.
591 
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;
597  return true;
598  } else {
599  $this->set_error(_ERR_COMM_ERR__);
600  }
601  } else {
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;
607  }
608 
609  return false;
610  }
set_error( $in_code)
_call_REST_API( $method, $url_extension, $data_input=NULL, $display_log=false)

◆ get_error()

get_error ( )
Returns
any error we may have, in an associative array ('code' => integer, 'message' => string). The localization will be dependent upon the SDK localization. NULL, if no error.

Definition at line 616 of file rvp_php_sdk.class.php.

616  {
617  $ret = NULL;
618 
619  if ($this->_error) {
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']);
624  }
625 
626  return $ret;
627  }

◆ set_error()

set_error (   $in_code)

Sets the internal error code.

Parameters
$in_codeREQUIRED: This is an integer error code. It can be NULL or 0 to clear the error.

Definition at line 633 of file rvp_php_sdk.class.php.

634  {
635  $this->_error = isset($in_code) && (0 != intval($in_code)) ? intval($in_code) : NULL;
636  }

◆ clear_error()

clear_error ( )

Resets the internal error to NULL.

Definition at line 642 of file rvp_php_sdk.class.php.

642  {
643  $this->set_error(NULL);
644  }
set_error( $in_code)

◆ valid()

valid ( )
Returns
true, if we are pointing at a valid server.

Definition at line 650 of file rvp_php_sdk.class.php.

650  {
651  return isset($this->_available_plugins) && is_array($this->_available_plugins) && (3 < count($this->_available_plugins));
652  }

◆ is_logged_in()

is_logged_in ( )
Returns
true, if we are currently logged in.

Definition at line 665 of file rvp_php_sdk.class.php.

665  {
666  return isset($this->_api_key) && (0 < $this->login_time_left());
667  }

◆ is_manager()

is_manager ( )
Returns
true, if we are currently logged in as a manager.

Definition at line 673 of file rvp_php_sdk.class.php.

673  {
674  if ($this->is_logged_in() && isset($this->_my_login_info)) {
675  return $this->_my_login_info->is_manager();
676  }
677 
678  return false;
679  }

◆ is_main_admin()

is_main_admin ( )
Returns
true, if we are currently logged in as a main admin.

Definition at line 685 of file rvp_php_sdk.class.php.

685  {
686  if ($this->is_manager() && isset($this->_my_login_info)) {
687  return $this->_my_login_info->is_main_admin();
688  }
689 
690  return false;
691  }

◆ current_login_id()

current_login_id ( )
Returns
an integer, with the current login ID. NULL, if not logged in.

Definition at line 697 of file rvp_php_sdk.class.php.

697  {
698  if ($this->is_logged_in() && isset($this->_my_login_info)) {
699  return $this->_my_login_info->id();
700  }
701 
702  return NULL;
703  }

◆ current_login_id_string()

current_login_id_string ( )
Returns
a string, with the current login ID. NULL, if not logged in.

Definition at line 709 of file rvp_php_sdk.class.php.

709  {
710  if ($this->is_logged_in() && isset($this->_my_login_info)) {
711  return $this->_my_login_info->login_id();
712  }
713 
714  return NULL;
715  }

◆ current_login_object()

current_login_object ( )
Returns
a string, with the current login ID. NULL, if not logged in.

Definition at line 721 of file rvp_php_sdk.class.php.

721  {
722  $ret = NULL;
723 
724  if ($this->is_logged_in() && isset($this->_my_login_info)) {
725  $ret = new RVP_PHP_SDK_Login($this, $this->_my_login_info->login_id());
726  }
727 
728  return $ret;
729  }

◆ login_time_left()

login_time_left ( )

If we logged in with a known time limit, we report how mucg time we have left.

Returns
the number of seconds (float) we have left in our current login.

Definition at line 737 of file rvp_php_sdk.class.php.

737  {
738  if (0 < $this->_login_time_limit) {
739  return floor(100 * max($this->_login_time_limit - microtime(true), 0)) / 100;
740  }
741 
742  return 0;
743  }

◆ my_info()

my_info ( )
Returns
an associative array ('login' => login object, 'user' => user object), with our information.

Definition at line 749 of file rvp_php_sdk.class.php.

749  {
750  if ($this->is_logged_in() && isset($this->_my_login_info)) {
751  $ret = ['login' => $this->_my_login_info];
752 
753  if (isset($this->_my_user_info)) {
754  $ret['user'] = $this->_my_user_info;
755  }
756 
757  return $ret;
758  } else {
759  return NULL;
760  }
761  }
$_my_login_info
This will contain any login information for the current login (NULL if not logged in)...
$_my_user_info
This will contain any login information for the current login (NULL if not logged in)...

◆ my_tokens()

my_tokens ( )
Returns
an array of integer, with the current tokens "owned" by this login (including 1, and the login ID). NULL, if not logged in.

Definition at line 767 of file rvp_php_sdk.class.php.

767  {
768  $ret = NULL;
769  if ($this->is_logged_in() && isset($this->_my_login_info)) {
770  $ret = $this->_my_login_info->security_tokens();
771  }
772 
773  return $ret;
774  }

◆ plugins()

plugins ( )
Returns
an array of strings, with the available plugins.

Definition at line 780 of file rvp_php_sdk.class.php.

780  {
781  $ret = [];
782 
783  if ($this->valid()) {
785  }
786 
787  return $ret;
788  }
$_available_plugins
This will be an array of string, with available plugins on the server.

◆ change_my_password_to()

change_my_password_to (   $in_new_password)

Allows a logged-in user to change their password. The "God" user cannot change their password. This will re-log in after changing the password (which logs you out).

Returns
true, if the change was successful.
Parameters
$in_new_passwordREQUIRED: The new password, in cleartext. It must be at least the minimum password length

Definition at line 798 of file rvp_php_sdk.class.php.

799  {
800  $ret = NULL;
801 
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));
805 
806  if (isset($result)) {
807  $result = json_decode($result);
808  // The reason for this crazy Fabergé egg, is because it's easier to debug a nested set of comparisons.
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);
821  }
822  }
823  }
824  }
825  }
826  }
827  }
828  }
829  }
830  }
831  }
832  }
833 
834  return $ret;
835  }
login( $in_username, $in_password, $in_login_timeout=-1)
put_data( $in_plugin_path, $in_query_args, $in_data_object=NULL)

◆ fetch_data()

fetch_data (   $in_plugin_path,
  $in_query_args = NULL 
)

This method will initiate and complete a data GET connection to the server. It takes care of any authentication.

Returns
whatever data was returned. Usually JSON.
Parameters
$in_plugin_pathREQUIRED: The plugin path to append to the base URI. This is a string.
$in_query_argsOPTIONAL: Any query arguments to be attached after a question mark. This is a string.

Definition at line 843 of file rvp_php_sdk.class.php.

845  {
846  if (isset($in_query_args) && trim($in_query_args)) {
847  $in_plugin_path .= '?'.ltrim($in_query_args, '&');
848  }
849 
850  $response = $this->_call_REST_API('GET', $in_plugin_path);
851 
852  return $response;
853  }
_call_REST_API( $method, $url_extension, $data_input=NULL, $display_log=false)

◆ put_data()

put_data (   $in_plugin_path,
  $in_query_args,
  $in_data_object = NULL 
)

This method will initiate and complete a data PUT connection to the server. It takes care of any authentication. You must be logged in to perform this operation.

Returns
whatever data was returned. Usually JSON.
Parameters
$in_plugin_pathREQUIRED: The plugin path to append to the base URI. This is a string, and should include the resource designation.
$in_query_argsREQUIRED: Any query arguments to be attached after a question mark. This is a string.
$in_data_objectOPTIONAL: If supplied, this will be attached payload data. It should not be base64-encoded.

Definition at line 862 of file rvp_php_sdk.class.php.

865  {
866  $response = NULL;
867 
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__);
873  } else {
874  $this->set_error(_ERR_INVALID_PARAMETERS__);
875  }
876 
877  return $response;
878  }
set_error( $in_code)
_call_REST_API( $method, $url_extension, $data_input=NULL, $display_log=false)

◆ post_data()

post_data (   $in_plugin_path,
  $in_query_args = NULL,
  $in_data_object = NULL 
)

This method will initiate and complete a data POST connection to the server. It takes care of any authentication. You must be logged in to perform this operation. You cannot select a resource for this. The plugin should be specified.

Returns
whatever data was returned. Usually JSON.
Parameters
$in_plugin_pathREQUIRED: The plugin path to append to the base URI. This is a string, and should NOT include any resource designation.
$in_query_argsOPTIONAL: Any query arguments to be attached after a question mark. This is a string.
$in_data_objectOPTIONAL: If supplied, this will be attached payload data. It should not be base64-encoded.

Definition at line 888 of file rvp_php_sdk.class.php.

891  {
892  $response = NULL;
893 
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, '&');
897  }
898 
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__);
902  } else {
903  $this->set_error(_ERR_INVALID_PARAMETERS__);
904  }
905 
906  return $response;
907  }
set_error( $in_code)
_call_REST_API( $method, $url_extension, $data_input=NULL, $display_log=false)

◆ delete_data()

delete_data (   $in_plugin_path)

This method will initiate and complete a data DELETE connection to the server. It takes care of any authentication. You must be logged in to perform this operation.

Returns
whatever data was returned. Usually JSON.
Parameters
$in_plugin_pathREQUIRED: The plugin path to append to the base URI. This is a string, and should include the resource designation.

Definition at line 916 of file rvp_php_sdk.class.php.

917  {
918  $response = NULL;
919 
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__);
924  } else {
925  $this->set_error(_ERR_INVALID_PARAMETERS__);
926  }
927 
928  return $response;
929  }
set_error( $in_code)
_call_REST_API( $method, $url_extension, $data_input=NULL, $display_log=false)

◆ get_objects()

get_objects ( )

This requires an array of integers be passed in. These are IDs of the objects that you want to fetch.

You can pass the IDs as a simple integer array in a single parameter.

Returns
new user, place and/or thing objects (or NULL) for the given integer ID[s]. These will be "unresolved" objects, sorted by ID.

Definition at line 939 of file rvp_php_sdk.class.php.

939  {
940  $func_args = func_get_args();
941 
942  // If they passed an array as the only argument, then we switch to that.
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];
945  }
946 
947  $ret = [];
948 
949  $args = array_map('intval', $func_args);
950  $arg_array = array_chunk($args, 10); // Split into groups of 10, so we don't create too large a GET request.
951 
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);
958 
959  if (isset($results) && is_array($results) && count($results)) {
960  $ret = array_merge($ret, $results);
961  }
962  }
963  } else {
964  $this->set_error(_ERR_COMM_ERR__);
965  return NULL;
966  }
967  }
968 
969  if (isset($ret) && is_array($ret) && (1 < count($ret))) {
970  usort($ret, function($a, $b) {
971  if ($a->id() == $b->id()) {
972  return 0;
973  }
974 
975  if ($a->id() < $b->id()) {
976  return -1;
977  }
978 
979  return 1;
980  }
981  );
982  }
983 
984  return $ret;
985  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)
_decode_handlers( $in_handlers)

◆ get_user_info()

get_user_info (   $in_user_id)
Returns
a new user object (or NULL) for the given integer ID.
Parameters
$in_user_idREQUIRED: The integer ID of the user we want to examine. If we don't have rights to the user, or the user does not exist, we get nothing.

Definition at line 991 of file rvp_php_sdk.class.php.

992  {
993  $ret = NULL;
994 
995  if ($this->is_logged_in()) {
996  $info = $this->fetch_data('json/people/people/'.intval($in_user_id), 'show_details');
997  if ($info) {
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);
1001  if (!isset($ret) || !($ret instanceof RVP_PHP_SDK_User)) {
1002  $this->set_error(_ERR_INTERNAL_ERR__);
1003  $ret = NULL;
1004  }
1005  }
1006  } else {
1007  $this->set_error(_ERR_COMM_ERR__);
1008  }
1009  }
1010 
1011  return $ret;
1012  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ get_login_info()

get_login_info (   $in_login_id)
Returns
a new login object (or NULL) for the given integer ID.
Parameters
$in_login_idREQUIRED: The integer ID of the login we want to examine. If we don't have rights to the login, or the login does not exist, we get nothing.

Definition at line 1018 of file rvp_php_sdk.class.php.

1019  {
1020  $ret = NULL;
1021 
1022  if ($this->is_logged_in()) {
1023  $info = $this->fetch_data('json/people/logins/'.intval($in_login_id), 'show_details');
1024  if ($info) {
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);
1028  if (!isset($ret) || !($ret instanceof RVP_PHP_SDK_Login)) {
1029  $this->set_error(_ERR_INTERNAL_ERR__);
1030  $ret = NULL;
1031  }
1032  }
1033  } else {
1034  $this->set_error(_ERR_COMM_ERR__);
1035  }
1036  }
1037 
1038  return $ret;
1039  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ get_place_info()

get_place_info (   $in_place_id)
Returns
a new place object (or NULL) for the given integer ID.
Parameters
$in_place_idREQUIRED: The integer ID of the place we want to examine. If we don't have rights to the place, or the place does not exist, we get nothing.

Definition at line 1045 of file rvp_php_sdk.class.php.

1046  {
1047  $ret = NULL;
1048 
1049  $info = $this->fetch_data('json/places/'.intval($in_place_id), 'show_details');
1050  if ($info) {
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);
1054  if (!isset($ret) || !($ret instanceof RVP_PHP_SDK_Place)) {
1055  $this->set_error(_ERR_INTERNAL_ERR__);
1056  $ret = NULL;
1057  }
1058  }
1059  } else {
1060  $this->set_error(_ERR_COMM_ERR__);
1061  }
1062 
1063  return $ret;
1064  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ get_thing_info()

get_thing_info (   $in_thing_id)
Returns
a new thing object (or NULL) for the given integer ID.
Parameters
$in_thing_idREQUIRED: The integer ID, or string key, of the thing we want to examine. If we don't have rights to the thing, or the thing does not exist, we get nothing.

Definition at line 1070 of file rvp_php_sdk.class.php.

1071  {
1072  $ret = NULL;
1073 
1074  $info = $this->fetch_data('json/things/'.urlencode($in_thing_id), 'show_details');
1075  if ($info) {
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);
1079  if (!isset($ret) || !($ret instanceof RVP_PHP_SDK_Thing)) {
1080  $this->set_error(_ERR_INTERNAL_ERR__);
1081  $ret = NULL;
1082  }
1083  }
1084  } else {
1085  $this->set_error(_ERR_COMM_ERR__);
1086  }
1087 
1088  return $ret;
1089  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ general_search()

general_search (   $in_text_array = [],
  $in_location = NULL,
  $in_writeable = false 
)

This is a baseline plugin text search.

The searched columns are the "object_name" column, or tags 0-9.

Returns
an array of objects (of any kind) that have the requested text in the fields supplied. SQL-style wildcards (%) are applicable.
Parameters
$in_text_arrayOPTIONAL: An associative array, laying out which text fields to search, and the search text. The key is the name of the field to search, and the value is the text to search for. You can use SQL-style wildcards (%). Available keys:
  • 'name' Searches the 'object_name' column.
  • 'tag0' - 'tag9' Searches the tag indicated. It should be noted that different plugins use these tags for different fixed purposes.
$in_locationOPTIONAL: An associative array ('latitude' => float, 'longitude' => float, 'radius' => float), with the long/lat (in degrees), and the radius of the location search (in Kilometers).
$in_writeableOPTIONAL: If true, then only places the current login can edit are returned. Ignored if not logged in.

Definition at line 1098 of file rvp_php_sdk.class.php.

1107  {
1108  $ret = [];
1109 
1110  $added_parameters = '';
1111 
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);
1115  }
1116  }
1117 
1118  if ($in_writeable && $this->is_logged_in()) { // We ignore writeable if we are not logged in.
1119  $added_parameters .= '&writeable';
1120  }
1121 
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']);
1124  }
1125 
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);
1131 
1132  if (isset($ret) && is_array($ret) && (0 < count($ret))) {
1133  usort($ret, function($a, $b) {
1134  if ($a->id() == $b->id()) {
1135  return 0;
1136  }
1137 
1138  if ($a->id() < $b->id()) {
1139  return -1;
1140  }
1141 
1142  return 1;
1143  }
1144  );
1145  }
1146  }
1147  } else {
1148  $this->set_error(_ERR_COMM_ERR__);
1149  return [];
1150  }
1151 
1152  return $ret;
1153  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)
_decode_handlers( $in_handlers)

◆ people_search()

people_search (   $in_text_array = [],
  $in_location = NULL,
  $in_get_logins_only = false,
  $in_writeable = false 
)

This is a people plugin text search.

The searched columns are the "object_name" column, or tags 0-9 (since this is a fixed-purpose plugin, these will be accessed by name, not tag name).

Returns
an array of people objects that have the requested text in the fields supplied. SQL-style wildcards (%) are applicable.
Parameters
$in_text_arrayOPTIONAL: An associative array, laying out which text fields to search, and the search text. The key is the name of the field to search, and the value is the text to search for. You can use SQL-style wildcards (%). Available keys:
  • 'name' Searches the 'object_name' column.
  • 'surname' Searches the surname tag.
  • 'middle_name' Searches the middle name tag.
  • 'given_name' Searches the first (given) name tag.
  • 'nickname' Searches the first (given) name tag.
  • 'prefix' Searches the prefix tag.
  • 'suffix' Searches the suffix tag.
  • 'tag7' Searches tag 7.
  • 'tag8' Searches tag 8.
  • 'tag9' Searches tag 9.
$in_locationOPTIONAL: An associative array ('latitude' => float, 'longitude' => float, 'radius' => float), with the long/lat (in degrees), and the radius of the location search (in Kilometers).
$in_get_logins_onlyOPTIONAL: If true (Default is false), then only login objects associated with the user objects that fall within the search will be returned.
$in_writeableOPTIONAL: If true, then only places the current login can edit are returned. Ignored if not logged in.

Definition at line 1163 of file rvp_php_sdk.class.php.

1181  {
1182  $ret = [];
1183 
1184  $added_parameters = '';
1185 
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);
1189  }
1190  }
1191 
1192  if ($in_get_logins_only) {
1193  $added_parameters .= '&login_user';
1194  }
1195 
1196  if ($in_writeable && $this->is_logged_in()) { // We ignore writeable if we are not logged in.
1197  $added_parameters .= '&writeable';
1198  }
1199 
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']);
1202  }
1203 
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)) {
1208  $ret = [];
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);
1214  if (isset($new_object) && ($new_object instanceof RVP_PHP_SDK_Login)) {
1215  $ret[] = $new_object;
1216  } else {
1217  $this->set_error(_ERR_INTERNAL_ERR__);
1218  return [];
1219  }
1220  } elseif (!$in_get_logins_only) {
1221  $new_object = new RVP_PHP_SDK_User($this, $person->id, $person);
1222  if (isset($new_object) && ($new_object instanceof RVP_PHP_SDK_User)) {
1223  $ret[] = $new_object;
1224  } else {
1225  $this->set_error(_ERR_INTERNAL_ERR__);
1226  return [];
1227  }
1228  }
1229  }
1230  }
1231 
1232  if (isset($ret) && is_array($ret) && (0 < count($ret))) {
1233  usort($ret, function($a, $b) {
1234  if ($a->id() == $b->id()) {
1235  return 0;
1236  }
1237 
1238  if ($a->id() < $b->id()) {
1239  return -1;
1240  }
1241 
1242  return 1;
1243  }
1244  );
1245  }
1246  }
1247  } else {
1248  $this->set_error(_ERR_COMM_ERR__);
1249  return [];
1250  }
1251 
1252  return $ret;
1253  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ places_search()

places_search (   $in_text_array = [],
  $in_location = NULL,
  $in_writeable = false 
)

This is a places plugin text search.

The searched columns are the "object_name" column, or tags 0-9 (since this is a fixed-purpose plugin, these will be accessed by name, not tag name).

Returns
an array of place objects that have the requested text in the fields supplied. SQL-style wildcards (%) are applicable.
Parameters
$in_text_arrayOPTIONAL: An associative array, laying out which text fields to search, and the search text. The key is the name of the field to search, and the value is the text to search for. You can use SQL-style wildcards (%). Available keys:
  • 'name' Searches the 'object_name' column.
  • 'venue' Searches the venue name tag.
  • 'street_address' Searches the street address tag.
  • 'extra_information' Searches the extra information tag.
  • 'city' or 'town' Searches the town tag.
  • 'county' Searches the county tag.
  • 'state' or 'province' Searches the state tag.
  • 'postal_code' or 'zip_code' Searches the zip code field.
  • 'nation' Searches the nation tag.
  • 'tag8' Searches tag 8.
  • 'tag9' Searches tag 9.
$in_locationOPTIONAL: An associative array ('latitude' => float, 'longitude' => float, 'radius' => float), with the long/lat (in degrees), and the radius of the location search (in Kilometers).
$in_writeableOPTIONAL: If true, then only places the current login can edit are returned. Ignored if not logged in.

Definition at line 1263 of file rvp_php_sdk.class.php.

1281  {
1282  $ret = [];
1283 
1284  $added_parameters = '';
1285 
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);
1289  }
1290  }
1291 
1292  if ($in_writeable && $this->is_logged_in()) { // We ignore writeable if we are not logged in.
1293  $added_parameters .= '&writeable';
1294  }
1295 
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']);
1298  }
1299 
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)) {
1304  $ret = [];
1305  foreach ($response->places->results as $place) {
1306  $new_object = new RVP_PHP_SDK_Place($this, $place->id, $place);
1307  if (isset($new_object) && ($new_object instanceof RVP_PHP_SDK_Place)) {
1308  $ret[] = $new_object;
1309  } else {
1310  $this->set_error(_ERR_INTERNAL_ERR__);
1311  return [];
1312  }
1313  }
1314 
1315  if (isset($ret) && is_array($ret) && (0 < count($ret))) {
1316  usort($ret, function($a, $b) {
1317  if ($a->id() == $b->id()) {
1318  return 0;
1319  }
1320 
1321  if ($a->id() < $b->id()) {
1322  return -1;
1323  }
1324 
1325  return 1;
1326  }
1327  );
1328  }
1329  }
1330  } else {
1331  $this->set_error(_ERR_COMM_ERR__);
1332  return [];
1333  }
1334 
1335  return $ret;
1336  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ things_search()

things_search (   $in_text_array = [],
  $in_location = NULL,
  $in_writeable = false 
)

This is a things plugin text search.

The searched columns are the "object_name" column, or tags 0-9 (since this is a fixed-purpose plugin, a couple of these will be accessed by name, not tag name).

Returns
an array of thing objects that have the requested text in the fields supplied. SQL-style wildcards (%) are applicable.
Parameters
$in_text_arrayOPTIONAL: An associative array, laying out which text fields to search, and the search text. The key is the name of the field to search, and the value is the text to search for. You can use SQL-style wildcards (%). Available keys:
  • 'name' Searches the 'object_name' column.
  • 'description' Searches the thing description tag.
  • 'tag2' - 'tag9' Searches the tag indicated.
$in_locationOPTIONAL: An associative array ('latitude' => float, 'longitude' => float, 'radius' => float), with the long/lat (in degrees), and the radius of the location search (in Kilometers).
$in_writeableOPTIONAL: If true, then only places the current login can edit are returned. Ignored if not logged in.

Definition at line 1346 of file rvp_php_sdk.class.php.

1356  {
1357  $ret = [];
1358 
1359  $added_parameters = '';
1360 
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);
1364  }
1365  }
1366 
1367  if ($in_writeable && $this->is_logged_in()) { // We ignore writeable if we are not logged in.
1368  $added_parameters .= '&writeable';
1369  }
1370 
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']);
1373  }
1374 
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)) {
1379  $ret = [];
1380  foreach ($response->things as $thing) {
1381  $new_object = new RVP_PHP_SDK_Thing($this, $thing->id, $thing);
1382  if (isset($new_object) && ($new_object instanceof RVP_PHP_SDK_Thing)) {
1383  $ret[] = $new_object;
1384  } else {
1385  $this->set_error(_ERR_INTERNAL_ERR__);
1386  return [];
1387  }
1388  }
1389 
1390  if (isset($ret) && is_array($ret) && (0 < count($ret))) {
1391  usort($ret, function($a, $b) {
1392  if ($a->id() == $b->id()) {
1393  return 0;
1394  }
1395 
1396  if ($a->id() < $b->id()) {
1397  return -1;
1398  }
1399 
1400  return 1;
1401  }
1402  );
1403  }
1404  }
1405  } else {
1406  $this->set_error(_ERR_COMM_ERR__);
1407  return [];
1408  }
1409 
1410  return $ret;
1411  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ general_location_search()

general_location_search (   $in_location)
Returns
an array of objects (of any kind) that fall within the search radius. NOTE: If the objects don't have an assigned long/lat, they will not be returned in this search.
Parameters
$in_locationREQUIRED: An associative array ('latitude' => float, 'longitude' => float, 'radius' => float), with the long/lat (in degrees), and the radius of the location search (in Kilometers).

Definition at line 1417 of file rvp_php_sdk.class.php.

1418  {
1419  return $this->general_search(NULL, $in_location);
1420  }
general_search( $in_text_array=[], $in_location=NULL, $in_writeable=false)

◆ people_location_search()

people_location_search (   $in_location,
  $in_get_logins_only = false 
)
Returns
an array of user (or login) objects that fall within the search radius. NOTE: If the objects don't have an assigned long/lat, they will not be returned in this search.
Parameters
$in_locationREQUIRED: An associative array ('latitude' => float, 'longitude' => float, 'radius' => float), with the long/lat (in degrees), and the radius of the location search (in Kilometers).
$in_get_logins_onlyOPTIONAL: If true (Default is false), then only login objects associated with the user objects that fall within the search will be returned.

Definition at line 1426 of file rvp_php_sdk.class.php.

1428  {
1429  return $this->people_search(NULL, $in_location, $in_get_logins_only);
1430  }
people_search( $in_text_array=[], $in_location=NULL, $in_get_logins_only=false, $in_writeable=false)

◆ place_location_search()

place_location_search (   $in_location)
Returns
an array of place objects that fall within the search radius. NOTE: If the objects don't have an assigned long/lat, they will not be returned in this search.
Parameters
$in_locationREQUIRED: An associative array ('latitude' => float, 'longitude' => float, 'radius' => float), with the long/lat (in degrees), and the radius of the location search (in Kilometers).

Definition at line 1436 of file rvp_php_sdk.class.php.

1437  {
1438  return $this->places_search(NULL, $in_location);
1439  }
places_search( $in_text_array=[], $in_location=NULL, $in_writeable=false)

◆ thing_location_search()

thing_location_search (   $in_location)
Returns
an array of thing objects that fall within the search radius. NOTE: If the objects don't have an assigned long/lat, they will not be returned in this search.
Parameters
$in_locationREQUIRED: An associative array ('latitude' => float, 'longitude' => float, 'radius' => float), with the long/lat (in degrees), and the radius of the location search (in Kilometers).

Definition at line 1445 of file rvp_php_sdk.class.php.

1446  {
1447  return $this->things_search(NULL, $in_location);
1448  }
things_search( $in_text_array=[], $in_location=NULL, $in_writeable=false)

◆ auto_radius_search()

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 
)

This is an "auto-radius" search. The way that it works, is that you specify a center point, and any search criteria. You specify the minimum number of resources that you want to find, what types of resources you want, any string filters, as well as the search step size and maximum (give up) radius. This can be a lengthy process. The way it works, is that successive radius search queries are made, using the filters and types, until AT LEAST the number of requested results are returned. Each successive search widens the radius by the step size. The first radius is one step size, and the last radius is the width of the "give up" threshold, or less, if the last step was beyond the threshold.

Returns
an array of thing objects that fall within the search radius. NOTE: If the objects don't have an assigned long/lat, they will not be returned in this search.
Parameters
$in_center_pointREQUIRED: This is the starting (center) point of the auto-radius search. It is an associative array ('longitude' => float, 'latitude' => float).
$in_target_numberOPTIONAL: An integer. The minimum number of resources to find. Default is 10.
$in_search_typeOPTIONAL: The type of search. It can be:
  • 'all' (or NULL/blank). This is all types of resources. This is the default.
  • 'users' or 'people' This is user objects.
  • 'logins' This is logins, associated with users (you cannot search for standalone logins this way).
  • 'places' This is places.
  • 'things' This is thing objects.
$in_search_string_criteriaOPTIONAL: This is an associative array (keys are field names, and values are what you are looking for. You can use SQL-style wildcards "%").
$in_step_size_in_kmOPTIONAL: This is the size of steps that we will take in the search. Default is 0.5 km (500m).
$in_max_width_in_kmOPTIONAL: The maximum radius in kilometers. Default is 100km.
$step_callbackOPTIONAL: This is a lmbda/closure/callback function that you provide, and will be called after each step, with the current results. This can either be a global-scope function, or an array, with the first element being an object instance, and the second element being the name of the method. The signature for the function/method is: function callback( $in_sdk_instance, // The SDK instance (this) $in_results, // The current results array (of instances). $in_type, // The search type ('all', 'users', 'logins, 'places', 'things'). $in_target_number, // This is the number of results (minimum) that will satisfy the search. $in_step_size, // The step size, in kilometers. $in_max_radius, // The maximum radius for the search, in kilometers. $in_location, // The current location (associative array ['latitude' => float, 'longitude' => float, 'radius' => float]). $in_search_criteria // An associative array with teh current text filter search criteria. ); The function should return either true, or false. If it returns true, then the search should be stopped at that point, and the current results returned.

Definition at line 1461 of file rvp_php_sdk.class.php.

1487  {
1488  $radius = 0.0;
1489  $results = [];
1490  $location = ['latitude' => floatval($in_center_point['latitude']), 'longitude' => floatval($in_center_point['longitude']), 'radius' => $radius];
1491 
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))) {
1496  case 'people':
1497  case 'users':
1498  $in_search_type = 'users';
1499  case 'logins':
1500  $results = $this->people_search($in_search_string_criteria, $location, ('logins' == $in_search_type));
1501  break;
1502 
1503  case 'places':
1504  $results = $this->places_search($in_search_string_criteria, $location);
1505  break;
1506 
1507  case 'things':
1508  $results = $this->things_search($in_search_string_criteria, $location);
1509  break;
1510 
1511  default:
1512  $in_search_type = 'all';
1513  $results = $this->general_search($in_search_string_criteria, $location);
1514  break;
1515  }
1516 
1517  // The user can provide a callback that gets a report, and can abort the search.
1518  if (isset($step_callback)) {
1519  $abort = false;
1520 
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);
1526  }
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);
1529  }
1530 
1531  if ($abort) {
1532  break;
1533  }
1534  }
1535  }
1536 
1537  return $results;
1538  }
general_search( $in_text_array=[], $in_location=NULL, $in_writeable=false)
things_search( $in_text_array=[], $in_location=NULL, $in_writeable=false)
people_search( $in_text_array=[], $in_location=NULL, $in_get_logins_only=false, $in_writeable=false)
places_search( $in_text_array=[], $in_location=NULL, $in_writeable=false)

◆ bulk_upload()

bulk_upload (   $in_csv_data)

This is the "bulk-import" for the BAOBAB server. It requires that the API key be for a "God" admin, and that the CO_Config::$enable_bulk_upload flag be set to true on the server.

You supply a CSV file, in the following format:

id,api_key,login_id,access_class,last_access,read_security_id,write_security_id,object_name,access_class_context,owner,longitude,latitude,tag0,tag1,tag2,tag3,tag4,tag5,tag6,tag7,tag8,tag9,ids,payload

Depending on the class in the 'access_class' column, either the security or data databes will be affected by a given row. Note that columns correspond to BOTH databases, so some columns will be ignored.

If you put 'NULL' in as a column value, that will be translated to NULL in the database.

Returns
a list of translations; from the integer 'id' column in the data file, to the id used in the server. remember that we are dealing with two databases here, so it is up to you to understand which database is being affected.
Parameters
$in_csv_dataREQUIRED: This is the CSV content (in our required schema) to be uploaded to the server.

Definition at line 1554 of file rvp_php_sdk.class.php.

1555  {
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']));
1558  } else {
1559  $this->set_error(_ERR_NOT_AUTHORIZED__);
1560  return NULL;
1561  }
1562  }
set_error( $in_code)
post_data( $in_plugin_path, $in_query_args=NULL, $in_data_object=NULL)

◆ backup()

backup ( )

This method is only available to "God" logins. It fetches the entire database as a CSV string.

Returns
the entire database, in a bulk-upload-format CSV string. NULL, if not authorized.

Definition at line 1570 of file rvp_php_sdk.class.php.

1570  {
1571  if ($this->is_main_admin()) {
1572  return $this->fetch_data('csv/baseline/backup');
1573  } else {
1574  $this->set_error(_ERR_NOT_AUTHORIZED__);
1575  return NULL;
1576  }
1577  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ get_serverinfo()

get_serverinfo ( )

This method is only available to "God" logins. It fetches the server information structure.

Returns
the serverinfo object.

Definition at line 1585 of file rvp_php_sdk.class.php.

1585  {
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;
1590  }
1591  } else {
1592  $this->set_error(_ERR_NOT_AUTHORIZED__);
1593  }
1594 
1595  return NULL;
1596  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ test_visibility()

test_visibility (   $in_id,
  $in_is_token = false 
)

This is a test of resource IDs or security tokens. It returns Login IDs (security DB), not User IDs (data DB). You give it the ID of a resource (data DB), and what you get back is a list of the login IDs that can see that resource, and those that can modify it (each is listed in a separate array). If you set the second (optional) parameter to true, then the ID that you send in is interpreted as a security token, and the response contains the IDs of logins that have that token. It should be noted that only login IDs that the current user can see will be returned. Additionally, the current user must have at least read permission for any resource ID, and must have access to the token.

Returns
either a straight-up simple array of integer ($in_is_token is true), containing the IDs of logins that have the token, or an associative array ('read_login_ids' => array of int, 'write_login_ids' => array of int), with the IDs of the logins with access to the resource, and what kind of access they have. Write access also grants read. NULL if no login IDs are available.
Parameters
$in_idREQUIRED: The ID or token to test. This is an integer. This should be 1 or greater (for tokens), or 2 or greater (for IDs).
$in_is_tokenOPTIONAL: If true (Default is false), then the ID is actually a security token.

Definition at line 1607 of file rvp_php_sdk.class.php.

1609  {
1610  $ret = NULL;
1611 
1612  $in_id = intval($in_id); // Make sure that we're an integer.
1613 
1614  // We have our basic standards.
1615  if ((1 < $in_id) || ($in_is_token && (0 <= $in_id))) {
1616  $uri = 'json/baseline/visibility/'. ($in_is_token ? 'token/' : '');
1617  $uri .= $in_id;
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;
1630  }
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;
1633  }
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;
1636  }
1637  }
1638  }
1639  } else {
1640  }
1641  } else {
1642  $this->set_error(_ERR_INVALID_PARAMETERS__);
1643  return NULL;
1644  }
1645 
1646  return $ret;
1647  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)

◆ new_user()

new_user (   $in_user_name,
  $in_tokens,
  $in_login_id = NULL 
)

This requires that the current login be a manager. This creates one user people object, and, possibly, an associated login. NOTE: The login ID and password are returned as part of the response, but the password is not included in the new user object. If not retained after this call, the password will be lost.

Returns
an associative array ('login_id' => string, 'password' => string, 'user' => object, 'login' => object), containing the login ID (if requested), password (if requested), the user object, and the login object (if requested). The user will be completely "sparse," with no additional information, beyond the general name and any associated login ID.
Parameters
$in_user_nameREQUIRED: The name of the user object (not one of the tag names)
$in_tokensREQUIRED: An associative array, ['read' => integer, 'write' => integer, 'tokens' => [integer]]
  • 'read' is optional. If not supplied, the user read will be set to '1' (only logged0in user can see)
  • 'write' is optional if $in_login_id is set (the login ID will be used). If $in_login_id is not supplied, then this is required, and must be an integer greater than 0 (and which the current manager has). If supplied, and not "owned" by the manager, then it will be ignored. If $in_login_id is not set, and the write token is invalid, then the operation will abort. Remember that setting this to 1 means that ALL logins can read and write the user.
  • 'tokens' is optional, and will only be considered if $in_login_id is set. This will be an array of int, and the manager performing this should have all the tokens. If unqualified tokens are provided, they will not be set, but the operation will not be aborted.
$in_login_id/< OPTIONAL: This is a string, with a requested login ID. If supplied, then a new login will be created, along with the user. The login ID must be a unique string in the security DB, and the operation will fail, if a login ID is supplied, but is already in use. A random password will be generated, and returned in the function return object.

Definition at line 1657 of file rvp_php_sdk.class.php.

1664  {
1665  $ret = NULL;
1666  $need_a_write_in = false; // This will be true, if we need to force a write token.
1667  $login_id = (isset($in_login_id) && trim($in_login_id)) ? trim($in_login_id) : NULL; // See if we have a login ID.
1668 
1669  if ($this->is_manager()) { // Must be a manager.
1670  if ($login_id) { // some prerequisites.
1671  // We test to see if the login they want is already in use.
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__);
1678  return NULL;
1679  } else {
1680  if (!isset($in_tokens) || !is_array($in_tokens) || !isset($in_tokens['write']) || !intval($in_tokens['write'])) { // If a valid write token was not supplied, we'll need to add one.
1681  $need_a_write_in = true;
1682  }
1683  }
1684  } else {
1685  $this->set_error(_ERR_COMM_ERR__);
1686  return NULL;
1687  }
1688  } else { // If we are not creating a login, then we are required to have a valid write token.
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__);
1691  return NULL;
1692  }
1693  }
1694 
1695  } else {
1696  $this->set_error(_ERR_NOT_AUTHORIZED__);
1697  return NULL;
1698  }
1699 
1700  // If we got here, then we're clear, so far.
1701  $uri = 'json/people/people';
1702  $params = '';
1703  if ($login_id) {
1704  $params .= '&login_id='.urlencode($login_id);
1705  }
1706 
1707  if (isset($in_tokens) && is_array($in_tokens) && count($in_tokens) && isset($in_tokens['read'])) {
1708  $params .= '&read_token='.intval($in_tokens['read']);
1709  }
1710 
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']);
1713  }
1714 
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']));
1717  }
1718 
1719  $uri .= '/?'.trim($params, "\&");
1720 
1721  $response = $this->post_data($uri);
1722 
1723  if (isset($response)) {
1724  $response = json_decode($response);
1725 
1726  if (isset($response) && isset($response->people) && isset($response->people->people) && isset($response->people->people->new_user)) {
1727  $ret = [];
1728 
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);
1737  }
1738 
1739  $ret['user'] = new RVP_PHP_SDK_User($this, $response->people->people->new_user->id, $response->people->people->new_user, true);
1740  }
1741  }
1742 
1743  return $ret;
1744  }
fetch_data( $in_plugin_path, $in_query_args=NULL)
set_error( $in_code)
post_data( $in_plugin_path, $in_query_args=NULL, $in_data_object=NULL)

◆ new_place()

new_place (   $in_place_name,
  $in_tokens = [],
  $in_latitude = NULL,
  $in_longitude = NULL,
  $in_fuzz_factor = NULL 
)

This creates a new, blank place object. The user must be logged in (being a manager is not required), and you can optionally assign a longitude/latitude location. BOTH longitude and latitude must be supplied in order to assign any value to either. You can also supply a "fuzz factor" immediately. The response will have a read token of 0 (everyone can read), and a write token of the ID of the creating login.

Returns
a new place object. The object will be basically uninitialized. NULL, if the create failed.
Parameters
$in_place_nameREQUIRED: A general name for the place (different from the venue name).
$in_tokensOPTIONAL: Default is an empty array. An associative array, ['read' => integer, 'write' => integer]
  • 'read' is optional. If not supplied, the user read will be set to '0' (all can see)
  • 'write' is optional and must be an integer greater than 0 (and which the current manager has). If supplied, and not "owned" by the manager, then it will be ignored. If the write token is invalid, then the operation will abort. Remember that setting this to 1 means that ALL logins can read and write the record.
$in_latitudeOPTIONAL: Default is NULL. If supplied, should be a floating-point value, in degrees latitude, of the place location. Must be supplied with valid $in_longitude value.
$in_longitudeOPTIONAL: Default is NULL. If supplied, should be a floating-point value, in degrees longitude, of the place location. Must be supplied with valid $in_latitude value.
$in_fuzz_factorOPTIONAL: Default is NULL. If supplied, should contain a floating-point number, with a "fuzz factor" distance, in Kilometers.

Definition at line 1756 of file rvp_php_sdk.class.php.

1764  {
1765  $ret = NULL;
1766 
1767  if ($this->is_logged_in()) { // Must be logged in.
1768  $uri = 'json/places';
1769  $params = '';
1770  if ($in_place_name) {
1771  $params .= '&name='.urlencode($in_place_name);
1772  }
1773 
1774  if ($in_latitude) {
1775  $params .= '&latitude='.floatval($in_latitude);
1776  }
1777 
1778  if ($in_longitude) {
1779  $params .= '&longitude='.floatval($in_longitude);
1780  }
1781 
1782  if ($in_fuzz_factor) {
1783  $params .= '&fuzz_factor='.floatval($in_fuzz_factor);
1784  }
1785 
1786  if (isset($in_tokens) && is_array($in_tokens) && count($in_tokens) && isset($in_tokens['read'])) {
1787  $params .= '&read_token='.intval($in_tokens['read']);
1788  }
1789 
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']);
1792  }
1793 
1794  $params = trim($params, "\&");
1795 
1796  $response = $this->post_data($uri, $params);
1797 
1798  if (isset($response)) {
1799  $response = json_decode($response);
1800 
1801  if (isset($response) && isset($response->places) && isset($response->places->new_place)) {
1802  $response = $response->places->new_place;
1803 
1804  $ret = new RVP_PHP_SDK_Place($this, $response->id, $response, true);
1805  }
1806  }
1807  } else {
1808  $this->set_error(_ERR_NOT_AUTHORIZED__);
1809  return NULL;
1810  }
1811 
1812  return $ret;
1813  }
set_error( $in_code)
post_data( $in_plugin_path, $in_query_args=NULL, $in_data_object=NULL)

◆ new_thing()

new_thing (   $in_thing_key,
  $in_thing_value,
  $in_tokens = [],
  $in_thing_name = NULL,
  $in_thing_description = NULL 
)

This creates a new, blank thing object. The user must be logged in (being a manager is not required).

Returns
a new thing object. The object will be basically uninitialized. NULL, if the create failed.
Parameters
$in_thing_keyREQUIRED: A key for the thing (must be a unique key). If this is not completely unique in the server, the operation will fail.
$in_thing_valueREQUIRED: This is a binary value to be associated with the thing.
$in_tokensOPTIONAL: Default is an empty array. An associative array, ['read' => integer, 'write' => integer]
  • 'read' is optional. If not supplied, the user read will be set to '0' (all can see)
  • 'write' is optional and must be an integer greater than 0 (and which the current manager has). If supplied, and not "owned" by the manager, then it will be ignored. If the write token is invalid, then the operation will abort. Remember that setting this to 1 means that ALL logins can read and write the record.
$in_thing_nameOPTIONAL: Default is NULL. If supplied, will be a general name for the thing.
$in_thing_descriptionOPTIONAL: Default is NULL. If supplied, this should be a string up to 255 characters long, describing the thing.

Definition at line 1822 of file rvp_php_sdk.class.php.

1830  {
1831  $ret = NULL;
1832 
1833  if ($this->is_logged_in() && isset($in_thing_key) && $in_thing_key && isset($in_thing_value) && $in_thing_value) { // Must be logged in, and we must have the required parameters.
1834  $uri = 'json/things';
1835  $params = '';
1836 
1837  $in_thing_key = trim($in_thing_key);
1838 
1839  if (false !== strpos($in_thing_key, ',')) { // Cannot have commas in the key.
1840  $in_thing_key = NULL;
1841  }
1842 
1843  if ($in_thing_key) {
1844  $params .= '&key='.urlencode($in_thing_key);
1845  }
1846 
1847  if (isset($in_tokens) && is_array($in_tokens) && count($in_tokens) && isset($in_tokens['read'])) {
1848  $params .= '&read_token='.intval($in_tokens['read']);
1849  }
1850 
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']);
1853  }
1854 
1855  if ($in_thing_name) {
1856  $params .= '&name='.urlencode($in_thing_name);
1857  }
1858 
1859  if ($in_thing_description) {
1860  $params .= '&description='.urlencode($in_thing_description);
1861  }
1862 
1863  $params = trim($params, "\&");
1864 
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);
1869  unlink($temp_file);
1870  $payload = ['data' => $in_thing_value, 'type' => $content_type];
1871 
1872  $response = $this->post_data($uri, $params, $payload);
1873 
1874  if (isset($response)) {
1875  $response = json_decode($response);
1876 
1877  if (isset($response) && isset($response->things) && isset($response->things->new_thing)) {
1878  $response = $response->things->new_thing;
1879 
1880  $ret = new RVP_PHP_SDK_Thing($this, $response->id, $response, true);
1881  }
1882  }
1883  } else {
1884  // If they are logged in, then they are authorized, but they don't have required parameters.
1885  $this->set_error($this->is_logged_in() ? _ERR_INVALID_PARAMETERS__ : _ERR_NOT_AUTHORIZED__);
1886  return NULL;
1887  }
1888 
1889  return $ret;
1890  }
set_error( $in_code)
post_data( $in_plugin_path, $in_query_args=NULL, $in_data_object=NULL)

◆ delete_user()

delete_user (   $in_object)

Deletes a user and associated login. The caller must be a manager or main admin.

Returns
true, if the deletion succeeded.
Parameters
$in_objectREQUIRED: This can be a user object, a login object, or an integer (user ID). If a user object, and if that object has an associated login, then both objects will be deleted. If a login object, then only the login will be deleted. An integer ID will always be considered to be a user object ID.

Definition at line 1899 of file rvp_php_sdk.class.php.

1900  {
1901  $ret = false;
1902 
1903  if ($this->is_manager() && isset($in_object)) { // Must be at least a manager.
1904  $user_id = 0;
1905  $login_id = 0;
1906 
1907  if ($in_object instanceof RVP_PHP_SDK_User) {
1908  if ($in_object->writeable()) { // Have to be able to edit.
1909  $user_id = $in_object->id();
1910  }
1911  } elseif ($in_object instanceof RVP_PHP_SDK_Login) {
1912  if ($in_object->writeable()) { // Have to be able to edit.
1913  $login_id = $in_object->id();
1914  }
1915  } else {
1916  $user_id = intval($in_object);
1917  }
1918 
1919  if ($user_id || $login_id) { // We need to have something to proceed.
1920  $uri = 'json/people';
1921  $ret = true;
1922 
1923  if ($user_id) {
1924  $response = $this->delete_data($uri.'/people/'.$user_id);
1925 
1926  if (isset($response)) {
1927  $response = json_decode($response);
1928 
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__);
1931  $ret = false;
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);
1936  }
1937  } else {
1938  $this->set_error(_ERR_COMM_ERR__);
1939  $ret = false;
1940  }
1941  }
1942 
1943  if ($ret && $login_id) {
1944  $response = $this->delete_data($uri.'/logins/'.$login_id);
1945 
1946  if (isset($response)) {
1947  $response = json_decode($response);
1948 
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__);
1951  $ret = false;
1952  }
1953  } else {
1954  $this->set_error(_ERR_COMM_ERR__);
1955  $ret = false;
1956  }
1957  }
1958  }
1959  } else {
1960  // If they are logged in as a manager, then they are authorized, but they don't have required parameters.
1961  $this->set_error($this->is_manager() ? _ERR_INVALID_PARAMETERS__ : _ERR_NOT_AUTHORIZED__);
1962  }
1963 
1964  return $ret;
1965  }
set_error( $in_code)
delete_data( $in_plugin_path)

◆ delete_place()

delete_place (   $in_object)

Deletes a place object.

Returns
true, if the deletion succeeded.
Parameters
$in_objectREQUIRED: This can be a place object, or an integer (place ID).

Definition at line 1973 of file rvp_php_sdk.class.php.

1974  {
1975  $ret = false;
1976 
1977  if ($this->is_logged_in() && isset($in_object)) { // Must be logged in.
1978  $place_id = 0;
1979 
1980  if ($in_object instanceof RVP_PHP_SDK_Place) {
1981  $place_id = $in_object->id();
1982  } else {
1983  $place_id = intval($in_object);
1984  }
1985 
1986  if ($place_id) { // Assuming that we have an ID...
1987  if (isset($this->test_visibility($place_id)['writeable'])) { // We must be able to write.
1988  $uri = 'json/places/'.$place_id;
1989  $ret = true;
1990  $response = $this->delete_data($uri);
1991 
1992  if (isset($response)) {
1993  $response = json_decode($response);
1994 
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__);
1997  $ret = false;
1998  }
1999  }
2000  } else {
2001  $this->set_error(_ERR_NOT_AUTHORIZED__);
2002  }
2003  }
2004  } else {
2005  // If they are logged in, then they are authorized, but they don't have required parameters.
2006  $this->set_error($this->is_logged_in() ? _ERR_INVALID_PARAMETERS__ : _ERR_NOT_AUTHORIZED__);
2007  }
2008 
2009  return $ret;
2010  }
set_error( $in_code)
test_visibility( $in_id, $in_is_token=false)
delete_data( $in_plugin_path)

◆ delete_thing()

delete_thing (   $in_object)

Deletes a thing object.

Returns
true, if the deletion succeeded.
Parameters
$in_objectREQUIRED: This can be a thing object, a string (key), or an integer (thing ID).

Definition at line 2018 of file rvp_php_sdk.class.php.

2019  {
2020  $ret = false;
2021 
2022  if ($this->is_logged_in() && isset($in_object)) { // Must be logged in.
2023  $thing_id = 0;
2024 
2025  if ($in_object instanceof RVP_PHP_SDK_thing) {
2026  $thing_id = $in_object->id();
2027  } else { // This is how we resolve string keys. Just fetch the damn object, and extract its 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());
2031  }
2032  }
2033 
2034  if ($thing_id) { // Assuming that we have an ID...
2035  if (isset($this->test_visibility($thing_id)['writeable'])) { // We must be able to write.
2036  $uri = 'json/things/'.$thing_id;
2037  $ret = true;
2038  $response = $this->delete_data($uri);
2039 
2040  if (isset($response)) {
2041  $response = json_decode($response);
2042 
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__);
2045  $ret = false;
2046  }
2047  }
2048  } else {
2049  $this->set_error(_ERR_NOT_AUTHORIZED__);
2050  }
2051  }
2052  } else {
2053  // If they are logged in, then they are authorized, but they don't have required parameters.
2054  $this->set_error($this->is_logged_in() ? _ERR_INVALID_PARAMETERS__ : _ERR_NOT_AUTHORIZED__);
2055  }
2056 
2057  return $ret;
2058  }
set_error( $in_code)
test_visibility( $in_id, $in_is_token=false)
delete_data( $in_plugin_path)
get_thing_info( $in_thing_id)

The documentation for this class was generated from the following file: