27 defined(
'LGV_BASALT_CATCHER' ) or die ( 'Cannot Execute Directly' );
29 if (!defined('LGV_CHAMELEON_UTILS_CATCHER')) {
30 define(
'LGV_CHAMELEON_UTILS_CATCHER', 1);
33 require_once(CO_Config::chameleon_main_class_dir().
'/co_chameleon_utils.class.php');
47 $in_region_bias = NULL
49 if (isset(CO_Config::$allow_address_lookup) && CO_Config::$allow_address_lookup && CO_Config::$google_api_key) {
50 $in_address_string = urlencode($in_address_string);
51 $in_region_bias = urlencode(strtolower(trim(substr($in_region_bias, 0, 3))));
52 $bias = (NULL != $in_region_bias) ?
'region='.$in_region_bias.
'&' :
'';
56 $uri =
'https://maps.googleapis.com/maps/api/geocode/json?'.$bias.
'key='.CO_Config::$google_api_key.
'&address='.$in_address_string;
59 if (isset($resulting_json) && $resulting_json &&isset($resulting_json->results) && is_array($resulting_json->results) && count($resulting_json->results)) {
60 if (isset($resulting_json->results[0]->geometry) && isset($resulting_json->results[0]->geometry->location) && isset($resulting_json->results[0]->geometry->location->lng) && isset($resulting_json->results[0]->geometry->location->lat)) {
61 return Array(
'longitude' => floatval($resulting_json->results[0]->geometry->location->lng),
'latitude' => floatval($resulting_json->results[0]->geometry->location->lat));
77 $ret = parent::_get_short_description($in_object);
79 $address = trim($in_object->get_readable_address());
81 if (isset($address) && $address) {
82 $ret[
'address'] = $address;
95 $in_show_parents =
false
97 $ret = parent::_get_long_description($in_place_object, $in_show_parents);
99 $address_elements = $in_place_object->get_address_elements();
101 if (isset($address_elements) && is_array($address_elements) && (0 < count($address_elements))) {
102 $ret[
'address_elements'] = $address_elements;
105 if (isset($in_place_object->tags()[8]) && trim($in_place_object->tags()[8])) {
106 $ret[
'tag8'] = trim($in_place_object->tags()[8]);
109 if (isset($in_place_object->tags()[9]) && trim($in_place_object->tags()[9])) {
110 $ret[
'tag9'] = trim($in_place_object->tags()[9]);
121 return $this->
_process_xsd(dirname(__FILE__).
'/schema.xsd');
133 $ret = parent::_process_parameters($in_andisol_instance, $in_query);
135 if (isset($in_query) && is_array($in_query)) {
137 if (isset($in_query[
'geocode'])) {
139 } elseif (isset($in_query[
'reverse-geocode'])) {
140 $ret[
'geocode'] = -1;
145 if (isset($in_query[
'address_venue'])) {
146 $ret[
'address_venue'] = trim($in_query[
'address_venue']);
149 if (isset($in_query[
'address_street_address'])) {
150 $ret[
'address_street_address'] = trim($in_query[
'address_street_address']);
153 if (isset($in_query[
'address_extra_information'])) {
154 $ret[
'address_extra_information'] = trim($in_query[
'address_extra_information']);
157 if (isset($in_query[
'address_town'])) {
158 $ret[
'address_town'] = trim($in_query[
'address_town']);
161 if (isset($in_query[
'address_county'])) {
162 $ret[
'address_county'] = trim($in_query[
'address_county']);
165 if (isset($in_query[
'address_state'])) {
166 $ret[
'address_state'] = trim($in_query[
'address_state']);
169 if (isset($in_query[
'address_postal_code'])) {
170 $ret[
'address_postal_code'] = trim($in_query[
'address_postal_code']);
173 if (isset($in_query[
'address_nation'])) {
174 $ret[
'address_nation'] = trim($in_query[
'address_nation']);
178 if (isset($in_query[
'tag8'])) {
179 $ret[
'tag8'] = trim(strval($in_query[
'tag8']));
182 if (isset($in_query[
'tag9'])) {
183 $ret[
'tag9'] = trim(strval($in_query[
'tag9']));
197 $in_object_list = [],
200 $in_show_parents =
false
204 if ($in_andisol_instance->logged_in()) {
205 if (isset($in_object_list) && is_array($in_object_list) && (0 < count($in_object_list))) {
206 foreach ($in_object_list as $place) {
208 if ($place->user_can_write() && $place->delete_from_db()) {
209 $ret[
'deleted_places'][] = $to_be_deleted;
214 header(
'HTTP/1.1 403 Forbidden');
233 if ($in_andisol_instance->logged_in()) {
234 $new_record = $in_andisol_instance->create_general_data_item(0, NULL,
'CO_Place_Collection');
237 if (isset($in_query) && is_array($in_query) && count($in_query)) {
238 $temp = $this->
_process_place_put($in_andisol_instance, [$new_record], $in_path, $in_query);
239 if (isset($temp) && is_array($temp) && count($temp)) {
240 $ret[
'new_place'] = $temp[
'changed_places'][0][
'after'];
242 $new_record-delete_from_db();
243 header(
'HTTP/1.1 400 Resource Not Created');
250 header(
'HTTP/1.1 400 Resource Not Created');
254 header(
'HTTP/1.1 403 Forbidden');
268 $in_object_list = [],
271 $in_show_parents =
false
273 if ($in_andisol_instance->logged_in()) {
274 $ret = [
'changed_places' => []];
275 $fuzz_factor = isset($in_query) && is_array($in_query) && isset($in_query[
'fuzz_factor']) ? floatval($in_query[
'fuzz_factor']) : 0;
278 if (isset($parameters) && is_array($parameters) && count($parameters) && isset($in_object_list) && is_array($in_object_list) && count($in_object_list)) {
286 $change_reports = [];
288 foreach ($in_object_list as $place) {
289 if ($place->user_can_write()) {
290 $place->set_batch_mode();
295 if ($result && isset($parameters[
'name'])) {
296 $result = $place->set_name($parameters[
'name']);
299 if ($result && isset($parameters[
'write_token'])) {
300 $result = $place->set_write_security_id($parameters[
'write_token']);
303 if ($result && isset($parameters[
'lang'])) {
304 $result = $place->set_lang($parameters[
'lang']);
307 if (isset($parameters[
'longitude'])) {
308 $result = $place->set_longitude($parameters[
'longitude']);
311 if ($result && isset($parameters[
'latitude'])) {
312 $result = $place->set_latitude($parameters[
'latitude']);
315 if ($result && isset($parameters[
'fuzz_factor'])) {
316 $result = $place->set_fuzz_factor($parameters[
'fuzz_factor']);
319 if ($result && isset($parameters[
'address_venue'])) {
320 $result = $place->set_address_element(0, $parameters[
'address_venue']);
323 if ($result && isset($parameters[
'address_street_address'])) {
324 $result = $place->set_address_element(1, $parameters[
'address_street_address']);
327 if ($result && isset($parameters[
'address_extra_information'])) {
328 $result = $place->set_address_element(2, $parameters[
'address_extra_information']);
331 if ($result && isset($parameters[
'address_town'])) {
332 $result = $place->set_address_element(3, $parameters[
'address_town']);
335 if ($result && isset($parameters[
'address_county'])) {
336 $result = $place->set_address_element(4, $parameters[
'address_county']);
339 if ($result && isset($parameters[
'address_state'])) {
340 $result = $place->set_address_element(5, $parameters[
'address_state']);
343 if ($result && isset($parameters[
'address_postal_code'])) {
344 $result = $place->set_address_element(6, $parameters[
'address_postal_code']);
347 if ($result && isset($parameters[
'can_see_through_the_fuzz'])) {
348 $result = $place->set_can_see_through_the_fuzz($parameters[
'can_see_through_the_fuzz']);
351 if ($result && isset($parameters[
'address_nation'])) {
352 $test = $place->set_address_element(7, $parameters[
'address_nation']);
354 $changed_place[
'nation_not_changed'] =
true;
359 if ($result && isset($parameters[
'geocode']) && (0 != intval($parameters[
'geocode']))) {
360 if (1 == intval($parameters[
'geocode'])) {
361 $long_lat = $place->lookup_address();
363 if (isset($long_lat) && is_array($long_lat) && 1 < count($long_lat)) {
364 $result = $place->set_longitude(floatval($long_lat[
'longitude']));
366 $result = $place->set_latitude(floatval($long_lat[
'latitude']));
370 $address_elements = $place->geocode_long_lat();
371 if (isset($address_elements) && is_array($address_elements) && count($address_elements)) {
372 $result = $place->set_address_elements($address_elements);
377 if ($result && isset($parameters[
'tag8'])) {
378 $result = $place->set_tag(8, $parameters[
'tag8']);
381 if ($result && isset($parameters[
'tag9'])) {
382 $result = $place->set_tag(9, $parameters[
'tag9']);
385 if ($result && isset($parameters[
'remove_payload'])) {
386 $result = $place->set_payload(NULL);
387 } elseif ($result && isset($parameters[
'payload'])) {
388 $result = $place->set_payload($parameters[
'payload']);
392 if ($result && isset($parameters[
'child_ids'])) {
393 $add = $parameters[
'child_ids'][
'add'];
394 $remove = $parameters[
'child_ids'][
'remove'];
396 foreach ($remove as $id) {
397 if ($id != $place->id()) {
398 $child = $in_andisol_instance->get_single_data_record_by_id($id);
400 $result = $place->deleteThisElement($child);
410 foreach ($add as $id) {
411 if ($id != $place->id()) {
412 $child = $in_andisol_instance->get_single_data_record_by_id($id);
414 $result = $place->appendElement($child);
426 if ($result && isset($parameters[
'read_token'])) {
427 $result = $place->set_read_security_id($parameters[
'read_token']);
432 $change_reports[] = [
'object' => $place,
'report' => $changed_place];
438 if ($result && count($change_reports)) {
439 $ret[
'changed_places'] = [];
440 foreach ($change_reports as $value) {
441 $result = $value[
'object']->clear_batch_mode();
443 $ret[
'changed_places'][] = $value[
'report'];
451 header(
'HTTP/1.1 403 Forbidden');
464 $in_object_list = [],
465 $in_show_details =
false,
466 $in_show_parents =
false,
467 $in_search_count_only =
false,
468 $in_search_ids_only =
false,
474 if ($in_search_count_only) {
475 $ret[
'count'] = intval($in_object_list);
476 } elseif (isset($in_object_list) && is_array($in_object_list) && (0 < count($in_object_list))) {
477 if ($in_search_ids_only) {
478 $ret[
'ids'] = $in_object_list;
480 foreach ($in_object_list as $place) {
481 if ($in_show_details) {
508 return [
'CO_Place_Collection',
'CO_US_Place_Collection',
'CO_Place',
'CO_US_Place',
'CO_LL_Location'];
525 if (
'POST' == $in_http_method) {
528 $show_parents = isset($in_query) && is_array($in_query) && isset($in_query[
'show_parents']);
529 $show_details = $show_parents || (isset($in_query) && is_array($in_query) && isset($in_query[
'show_details']));
530 $writeable = isset($in_query) && is_array($in_query) && isset($in_query[
'writeable']);
531 $search_count_only = isset($in_query) && is_array($in_query) && isset($in_query[
'search_count_only']);
532 $search_ids_only = isset($in_query) && is_array($in_query) && isset($in_query[
'search_ids_only']);
533 $search_page_size = isset($in_query) && is_array($in_query) && isset($in_query[
'search_page_size']) ? abs(intval($in_query[
'search_page_size'])) : 0;
534 $search_page_number = isset($in_query) && is_array($in_query) && isset($in_query[
'search_page_number']) ? abs(intval($in_query[
'search_page_number'])) : 0;
535 $search_name = isset($in_query) && is_array($in_query) && isset($in_query[
'search_name']) ? trim($in_query[
'search_name']) : NULL;
538 if (0 == count($in_path)) {
539 $radius = isset($in_query) && is_array($in_query) && isset($in_query[
'search_radius']) && (0.0 < floatval($in_query[
'search_radius'])) ? floatval($in_query[
'search_radius']) : NULL;
540 $longitude = isset($in_query) && is_array($in_query) && isset($in_query[
'search_longitude']) ? floatval($in_query[
'search_longitude']) : NULL;
541 $latitude = isset($in_query) && is_array($in_query) && isset($in_query[
'search_latitude']) ? floatval($in_query[
'search_latitude']) : NULL;
542 $search_region_bias = isset($in_query) && is_array($in_query) && isset($in_query[
'search_region_bias']) ? strtolower(trim($search_region_bias)) : CO_Config::$default_region_bias;
543 $search_address = isset($in_query) && is_array($in_query) && isset($in_query[
'search_address']) && trim($in_query[
'search_address']) ? trim($in_query[
'search_address']) : NULL;
549 for ($count = 0; $count < 8; $count++) {
550 $eval_line =
'$parameter_name = CO_CHAMELEON_Lang_Common::$chameleon_co_place_tag_'.$count.
';';
552 $parameter_name =
'search_'.$parameter_name;
553 if (isset($in_query) && is_array($in_query) && isset($in_query[$parameter_name])) {
554 $parameter_value = strval(trim($in_query[$parameter_name]));
555 $tags_temp[] = $parameter_value;
562 if (isset($in_query) && is_array($in_query) && isset($in_query[
'search_tag8'])) {
563 $tags_temp[] = trim($in_query[
'search_tag8']);
568 if (isset($in_query) && is_array($in_query) && isset($in_query[
'search_tag9'])) {
569 $tags_temp[] = trim($in_query[
'search_tag9']);
575 if(array_reduce($tags_temp,
function($prev, $current) {
return $prev || (NULL !== $current) ?
true : $prev; },
false)) {
583 if (isset(CO_Config::$allow_address_lookup) && CO_Config::$allow_address_lookup && CO_Config::$google_api_key) {
584 $address = isset($in_query) && is_array($in_query) && isset($in_query[
'search_address']) && trim($in_query[
'search_address']) ? trim($in_query[
'search_address']) : NULL;
585 if (isset($search_address) && $search_address && !(isset($longitude) && isset($latitude))) {
586 if (CO_Config::$allow_general_address_lookup || $in_andisol_instance->logged_in()) {
589 if ($result && is_array($result) && (1 < count($result))) {
590 $longitude = $result[
'longitude'];
591 $latitude = $result[
'latitude'];
594 header(
'HTTP/1.1 400 Improper Distance Search (Login Required)');
598 } elseif ($search_address) {
599 header(
'HTTP/1.1 400 Incomplete Distance Search');
603 $location_search = NULL;
606 if (isset($radius) && isset($longitude) && isset($latitude)) {
607 $location_search = Array(
'radius' => $radius,
'longitude' => $longitude,
'latitude' => $latitude);
608 } elseif (isset($radius) || isset($longitude) || isset($latitude)) {
609 header(
'HTTP/1.1 400 Incomplete Distance Search');
613 $class_search = Array(
'%_Place_Collection',
'use_like' => 1);
614 $search_array[
'access_class'] = $class_search;
619 $tags[
'use_like'] = 1;
620 $search_array[
'tags'] = $tags;
623 if (isset($location_search)) {
624 $search_array[
'location'] = $location_search;
625 if (isset($search_address) && $search_address && !(isset($longitude) && isset($latitude))) {
626 $search_array[
'location'][
'address'] = $search_address;
630 if (isset($search_name)) {
631 $search_array[
'name'] = Array($search_name,
'use_like' => 1);
634 $placelist = $in_andisol_instance->generic_search($search_array,
false, $search_page_size, $search_page_number, $writeable, $search_count_only, $search_ids_only);
636 if (
'GET' == $in_http_method) {
637 $ret = $this->
_process_place_get($in_andisol_instance, $placelist, $show_details, $show_parents, $search_count_only, $search_ids_only, $in_path, $in_query);
638 $ret = Array(
'results' => $ret);
639 } elseif (
'PUT' == $in_http_method) {
640 $ret = $this->
_process_place_put($in_andisol_instance, $placelist, $in_path, $in_query, $show_parents);
641 } elseif (
'DELETE' == $in_http_method) {
642 $ret = $this->
_process_place_delete($in_andisol_instance, $placelist, $in_path, $in_query, $show_parents);
645 if ($location_search && !$search_count_only) {
646 $ret[
'search_location'] = $location_search;
649 $first_directory = $in_path[0];
652 $single_place_id = (ctype_digit($first_directory) && (1 < intval($first_directory))) ? intval($first_directory) : NULL;
656 $place_id_list = explode(
',', $first_directory);
659 if ($single_place_id || (1 < count($place_id_list))) {
660 $place_id_list = ($single_place_id ? [$single_place_id] : array_unique(array_map(
'intval', $place_id_list)));
663 foreach ($place_id_list as $id) {
665 $place = $in_andisol_instance->get_single_data_record_by_id($id);
666 if (isset($place) && ($place instanceof
CO_Place)) {
667 $placelist[] = $place;
672 if (
'GET' == $in_http_method) {
673 $ret = $this->
_process_place_get($in_andisol_instance, $placelist, $show_details, $show_parents, $search_count_only, $search_ids_only, $in_path, $in_query);
674 $ret = Array(
'results' => $ret);
675 } elseif (
'PUT' == $in_http_method) {
676 $ret = $this->
_process_place_put($in_andisol_instance, $placelist, $in_path, $in_query, $show_parents);
677 } elseif (
'DELETE' == $in_http_method) {
678 $ret = $this->
_process_place_delete($in_andisol_instance, $placelist, $in_path, $in_query, $show_parents);
if(!defined( 'LGV_CHAMELEON_UTILS_CATCHER'))
_condition_response( $in_response_type, $in_response_as_associative_array=NULL)
_process_xsd( $in_schema_file_path)
_process_place_put( $in_andisol_instance, $in_object_list=[], $in_path=[], $in_query=[], $in_show_parents=false)
_process_place_delete( $in_andisol_instance, $in_object_list=[], $in_path=[], $in_query=[], $in_show_parents=false)
_get_short_description( $in_object)
_process_place_post( $in_andisol_instance, $in_path=[], $in_query=[])
_get_long_place_description( $in_place_object, $in_show_parents=false)
process_command( $in_andisol_instance, $in_http_method, $in_response_type, $in_path=[], $in_query=[])
_process_parameters( $in_andisol_instance, $in_query)
_process_place_get( $in_andisol_instance, $in_object_list=[], $in_show_details=false, $in_show_parents=false, $in_search_count_only=false, $in_search_ids_only=false, $in_path=[], $in_query=[])
static _lookup_address( $in_address_string, $in_region_bias=NULL)
static call_curl( $in_uri, $in_post=false, &$http_status=NULL, &$content_failure_note=NULL)
This is a function that returns the results of an HTTP call to a URI. It is a lot more secure than fi...