27 defined(
'LGV_BASALT_CATCHER' ) or die ( 'Cannot Execute Directly' );
33 static protected $_s_cached_list = NULL;
44 if (!isset(self::$_s_cached_list) || !is_array(self::$_s_cached_list) || !count(self::$_s_cached_list)) {
45 self::$_s_cached_list = [];
46 $plugin_dirs = CO_Config::plugin_dirs();
48 foreach ($plugin_dirs as $plugin_dir) {
49 if (isset($plugin_dir) && is_dir($plugin_dir)) {
50 $plugin_name = basename($plugin_dir);
51 $plugin_classname =
'CO_'.$plugin_name.
'_Basalt_Plugin';
52 $plugin_filename = strtolower($plugin_classname).
'.class.php';
53 $plugin_file = $plugin_dir.
'/'.$plugin_filename;
54 include_once($plugin_file);
55 $class_list = $plugin_classname::classes_managed();
56 self::$_s_cached_list[$plugin_classname] = $class_list;
61 foreach (self::$_s_cached_list as $plugin_name => $class_list) {
62 if (in_array($in_classname, $class_list)) {
63 $plugin_name = substr($plugin_name, 3, -14);
76 $port = intval ( $_SERVER[
'SERVER_PORT'] );
79 $https = (isset($_SERVER[
'HTTPS']) && !empty($_SERVER[
'HTTPS'] && (($_SERVER[
'HTTPS'] !==
'off') || ($port == 443)))) ?
true :
false;
81 $url_path = $_SERVER[
'SERVER_NAME'];
84 if (!$https && ($port != 80)) {
85 $url_path .=
":$port";
86 } elseif ($https && ($port != 443)) {
87 $url_path .=
":$port";
90 return 'http'.($https ?
's' :
'').
'://'.$url_path.$_SERVER[
'SCRIPT_NAME'];
102 foreach ($in_array as $name => $value) {
103 $plurality = is_int($name);
104 $name = $plurality ?
'value' : htmlspecialchars(trim($name));
108 $output .=
'<'.$name.
' sequence_index="'.strval ( $index++ ).
'">';
110 $output .=
'<'.$name.
'>';
113 if (is_array($value)) {
114 $output .= self::_array2xml($value);
116 $output .= htmlspecialchars(strval($value));
119 $output .=
'</'.$name.
'>';
134 $ret = Array(
'id' => $in_object->id());
136 $name = $in_object->name;
138 if (isset($name) && trim($name)) {
139 $ret [
'name'] = $name;
142 $lang = $in_object->get_lang();
145 $ret [
'lang'] =
$lang;
149 if (method_exists($in_object,
'longitude')) {
150 $raw_lat = $in_object->raw_latitude();
151 $raw_lng = $in_object->raw_longitude();
153 $latitude = $raw_lat ? $raw_lat : $in_object->latitude();
154 $longitude = $raw_lng ? : $in_object->longitude();
156 if (isset($longitude) && is_float($longitude) && isset($latitude) && is_float($latitude)) {
157 $ret[
'coords'] = sprintf(
"%f,%f", $latitude, $longitude);
160 if (isset($in_object->distance)) {
161 $ret[
'distance_in_km'] = floatval($in_object->distance);
175 $in_show_parents =
false
177 $ret = $this->_get_short_description($in_object);
180 $my_ids = $in_object->get_access_object()->get_security_ids();
181 $read_item = intval($in_object->read_security_id);
182 $write_item = intval($in_object->write_security_id);
185 if ((((2 > $read_item) || $in_object->get_access_object()->god_mode() || in_array($read_item, $my_ids)) && count($my_ids)) && $in_object->get_access_object()->security_db_available()) {
186 $ret[
'read_token'] = $read_item;
189 if (((2 > $read_item) || $in_object->get_access_object()->god_mode() || in_array($write_item, $my_ids) && count($my_ids)) && $in_object->get_access_object()->security_db_available()) {
190 $ret[
'write_token'] = $write_item;
193 if (isset($in_object->last_access)) {
194 $ret[
'last_access'] = date(
'Y-m-d H:i:s', $in_object->last_access);
197 if ($in_object->user_can_write()) {
198 $ret[
'writeable'] =
true;
201 if (method_exists($in_object,
'owner_id')) {
202 if (0 < intval($in_object->owner_id())) {
203 $ret[
'owner_id'] = intval($in_object->owner_id());
207 if (method_exists($in_object,
'longitude') && isset($ret[
'coords'])) {
209 $coords = array_map(
'floatval', explode(
',', $ret[
'coords']));
210 $latitude = $coords[0];
211 $longitude = $coords[1];
213 if (isset($longitude) && is_float($longitude) && isset($latitude) && is_float($latitude)) {
214 $ret[
'latitude'] = floatval($latitude);
215 $ret[
'longitude'] = floatval($longitude);
218 if ($in_object->is_fuzzy()) {
219 $ret[
'fuzzy'] =
true;
221 $cansee = intval($in_object->can_see_through_the_fuzz());
224 $ret[
'can_see_through_the_fuzz'] = $cansee;
228 if ($in_object->i_can_see_clearly_now()) {
229 $ret[
'raw_latitude'] = floatval($in_object->raw_latitude());
230 $ret[
'raw_longitude'] = floatval($in_object->raw_longitude());
231 $ret[
'fuzz_factor'] = $in_object->fuzz_factor();
236 if (method_exists($in_object,
'children')) {
237 $child_objects = $this->_get_child_ids($in_object);
238 if (0 < count($child_objects)) {
239 $ret[
'children'] = $this->_get_child_handler_data($in_object);
243 if ($in_show_parents && method_exists($in_object,
'who_are_my_parents')) {
244 $parent_objects = $in_object->who_are_my_parents();
245 if (isset($parent_objects) && is_array($parent_objects) && count($parent_objects)) {
246 foreach ($parent_objects as $instance) {
247 $class_name = get_class($instance);
250 $handler = self::_get_handler($class_name);
251 $ret[
'parents'][$handler][] = $instance->id();
257 if (method_exists($in_object,
'get_payload')) {
258 $payload = $in_object->get_payload();
261 $temp_file = tempnam(sys_get_temp_dir(),
'RVP');
262 file_put_contents($temp_file , $payload);
263 $finfo = finfo_open(FILEINFO_MIME_TYPE);
264 $content_type = finfo_file($finfo, $temp_file);
265 $ret[
'payload_type'] = $content_type.
';base64';
266 $ret[
'payload'] = base64_encode($payload);
280 $ret =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
281 $xsd_uri = self::_server_url().
'/xsd/'.$this->plugin_name();
282 $ret .=
'<'.$this->plugin_name().
" xsi:schemaLocation=\"".self::_server_url().
" $xsd_uri\" xmlns=\"".self::_server_url().
"\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">";
294 $ret =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
295 $xsd_uri = self::_server_url().
'/xsd/'.$this->plugin_name();
296 $ret .=
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:b='".self::_server_url().
"' elementFormDefault='qualified' targetNamespace='".self::_server_url().
"'>";
311 $schema_file = file_get_contents($in_schema_file_path);
314 $ret = $this->_get_xsd_header().
"$schema_file</xs:schema>";
327 $in_response_as_associative_array = NULL
331 if (
'xml' == $in_response_type) {
332 $header = $this->_get_xml_header();
333 $body = self::_array2xml($in_response_as_associative_array);
334 $footer =
'</'.$this->plugin_name().
'>';
335 $ret =
"$header$body$footer";
336 } elseif (
'xsd' == $in_response_type) {
337 $ret = $this->_get_xsd();
339 $ret = json_encode(Array($this->plugin_name() => $in_response_as_associative_array));
355 if (method_exists($in_object,
'children') && (0 < $in_object->count())) {
356 $ret = $in_object->children_ids();
372 $id_list = $this->_get_child_ids($in_object);
373 $access_object = $in_object->get_access_object();
375 if (isset($access_object) && is_array($id_list) && count($id_list)) {
376 foreach ($id_list as $id) {
377 $class_name = $access_object->get_data_access_class_by_id($id);
379 $handler = self::_get_handler($class_name);
380 $ret[$handler][] = $id;
398 if (isset($in_query) && is_array($in_query)) {
401 if (isset($in_query[
'child_ids']) && trim($in_query[
'child_ids'])) {
402 $child_item_list = [];
403 $delete_child_item_list = [];
405 $child_id_list = array_map(
'intval', explode(
',', trim($in_query[
'child_ids'])));
408 if (isset($child_id_list) && is_array($child_id_list) && count($child_id_list)) {
410 foreach ($child_id_list as $id) {
412 $item = $in_andisol_instance->get_single_data_record_by_id($id);
414 $child_item_list[] = $id;
416 $item = $in_andisol_instance->get_single_data_record_by_id(-$id);
417 $delete_child_item_list[] = -$id;
422 $child_item_list = array_unique($child_item_list);
423 $delete_child_item_list = array_unique($delete_child_item_list);
426 sort($child_item_list);
427 sort($delete_child_item_list);
433 if (isset($child_item_list) && is_array($child_item_list) && count($child_item_list)) {
434 if (!isset($ret[
'child_ids'])) {
435 $ret[
'child_ids'] = Array(
'add' => [],
'remove' => []);
437 $ret[
'child_ids'][
'add'] = $child_item_list;
441 if (isset($delete_child_item_list) && is_array($delete_child_item_list) && count($delete_child_item_list)) {
442 if (!isset($ret[
'child_ids'])) {
443 $ret[
'child_ids'] = Array(
'add' => [],
'remove' => []);
445 $ret[
'child_ids'][
'remove'] = $delete_child_item_list;
447 } elseif (isset($in_query[
'child_ids']) && !trim($in_query[
'child_ids'])) {
448 $ret[
'child_ids'] =
'DELETE-ALL';
451 if (isset($in_query[
'name'])) {
452 $ret[
'name'] = trim($in_query[
'name']);
455 if (isset($in_query[
'read_token'])) {
456 $token = intval($in_query[
'read_token']);
457 if ($in_andisol_instance->i_have_this_token($token)) {
458 $ret[
'read_token'] = intval($in_query[
'read_token']);
462 if (isset($in_query[
'write_token'])) {
463 $token = intval($in_query[
'write_token']);
464 if ($in_andisol_instance->i_have_this_token($token)) {
465 $ret[
'write_token'] = intval($in_query[
'write_token']);
469 if (isset($in_query[
'longitude'])) {
470 $ret[
'longitude'] = floatval($in_query[
'longitude']);
473 if (isset($in_query[
'latitude'])) {
474 $ret[
'latitude'] = floatval($in_query[
'latitude']);
477 if (isset($in_query[
'fuzz_factor'])) {
478 $ret[
'fuzz_factor'] = floatval($in_query[
'fuzz_factor']);
481 if (isset($in_query[
'can_see_through_the_fuzz'])) {
482 $ret[
'can_see_through_the_fuzz'] = intval($in_query[
'can_see_through_the_fuzz']);
486 if (isset($in_query[
'owner_id'])) {
487 $ret[
'owner_id'] = abs(intval(trim($in_query[
'owner_id'])));
491 if (isset($in_query[
'lang'])) {
492 $ret[
'lang'] = trim(strval($in_query[
'lang']));
496 if (isset($in_query[
'remove_payload'])) {
497 $ret[
'remove_payload'] =
true;
498 } elseif (isset($in_query[
'payload'])) {
500 if (base64_encode(base64_decode($in_query[
'payload'])) == $in_query[
'payload']) {
501 $in_query[
'payload'] = base64_decode($in_query[
'payload']);
503 $ret[
'payload'] = $in_query[
'payload'];
_process_parameters( $in_andisol_instance, $in_query)
_condition_response( $in_response_type, $in_response_as_associative_array=NULL)
static _array2xml( $in_array)
static _get_handler( $in_classname)
_get_long_description( $in_object, $in_show_parents=false)
process_command( $in_andisol_instance, $in_http_method, $in_response_type, $in_path=[], $in_query=[])
_get_child_ids( $in_object)
_process_xsd( $in_schema_file_path)
_get_short_description( $in_object)
_get_child_handler_data( $in_object)