Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 211 additions & 0 deletions actions/amap_maps_api/nearby_search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<?php
/**
* Elgg Maps of Groups plugin
* @package groupsmap
*/

if (!elgg_is_xhr()) {
register_error('Sorry, Ajax only!');
forward(REFERRER);
}

if (!elgg_is_active_plugin("amap_maps_api")) {
register_error(elgg_echo("groupsmap:settings:amap_maps_api:disabled"));
forward(REFERER);
}

elgg_load_library('elgg:groupsmap');
elgg_load_library('elgg:amap_maps_api');
elgg_load_library('elgg:amap_maps_api_geo');

// get variables
$s_location = get_input("s_location");
$s_radius = (int) get_input('s_radius', 0);
$s_keyword = get_input("s_keyword");
$showradius = get_input("showradius");
$initial_load = get_input("initial_load");

if ($s_radius > 0)
$search_radius_txt = amap_ma_get_radius_string($s_radius);
else
$search_radius_txt = amap_ma_get_default_radius_search_string();

$s_radius = amap_ma_get_default_radius_search($s_radius);

// retrieve coords of location asked, if any
$coords = amap_ma_geocode_location($s_location);

$title = elgg_echo('groupsmap:all');


$options = array(
"type" => "group",
"full_view" => FALSE,
'limit' => get_input('limit', 0),
'offset' => get_input('proximity_offset', 0),
'count' => false
);


$options['metadata_name_value_pairs'][] = array('name' => 'location', 'value' => '', 'operand' => '!=');
$options['metadata_name_value_pairs'][] = array('name' => 'country', 'value' => '', 'operand' => '!=');
$options['metadata_name_value_pairs_operator'] = 'OR';

if ($initial_load) {
if ($initial_load == 'newest') {
$options['limit'] = amap_ma_get_initial_limit('groupsmap');
$title = elgg_echo('groupsmap:groups:newest', array($options['limit']));
} else if ($initial_load == 'location') {
// retrieve coords of location asked, if any
$user = elgg_get_logged_in_user_entity();
if ($user->location) {
$s_lat = $user->getLatitude();
$s_long = $user->getLongitude();

if ($s_lat && $s_long) {
$s_radius = amap_ma_get_initial_radius('groupsmap');
$search_radius_txt = $s_radius;
$s_radius = amap_ma_get_default_radius_search($s_radius);
$options = add_order_by_proximity_clauses($options, $s_lat, $s_long);
$options = add_distance_constraint_clauses($options, $s_lat, $s_long, $s_radius);

$title = elgg_echo('groupsmap:groups:nearby:search', array($user->location));
}
}
}
} else {
if ($s_keyword) {
$db_prefix = elgg_get_config("dbprefix");
$query = sanitise_string($s_keyword);

$options["joins"] = array("JOIN {$db_prefix}groups_entity ge ON e.guid = ge.guid");
$where = "(ge.name LIKE '%$query%' OR ge.description LIKE '%$query%')";
$options["wheres"] = array($where);
}

if ($coords) {
$search_location_txt = $s_location;
$s_lat = $coords['lat'];
$s_long = $coords['long'];

if ($s_lat && $s_long) {
$options = add_order_by_proximity_clauses($options, $s_lat, $s_long);
$options = add_distance_constraint_clauses($options, $s_lat, $s_long, $s_radius);
}
$title = elgg_echo('groupsmap:groups:nearby:search', array($search_location_txt));
}
}

$groups = elgg_get_entities_from_metadata($options);

$users = array();
if (amap_ma_check_if_membersmap_gm_enabled()) {
$options1 = array('type' => 'user', 'full_view' => false);
$options1['limit'] =0;
$options1['metadata_name_value_pairs'] = array(array('name' => 'location', 'value' => '', 'operand' => '!='));
$users = elgg_get_entities_from_metadata($options1);
$indextable .= elgg_view('input/checkbox', array(
'name' => 'chbx_user',
'id' => 'chbx_user',
'checked' => true,
)).'<label for="chbx_user">'.elgg_echo('amap_maps_api:members').'</label>';

if ($users) {
foreach ($users as $entity) {
$entity = amap_ma_set_entity_additional_info($entity, 'name', 'description', $entity->location);
}
}
}

$pages = array();
if (amap_ma_check_if_pagesmap_gm_enabled()) {
$array4 = array();
$options4 = array(
'type' => 'object',
'subtype' => array('page','page_top'),
'full_view' => false,
'limit' => 0,
);
$pages = elgg_get_entities($options4);

if ($pages) {
foreach ($pages as $entity) {
$entity = amap_ma_set_entity_additional_info($entity, 'title', 'description', $entity->location);
}
}

$indextable .= elgg_view('input/checkbox', array(
'name' => 'chbx_pages',
'id' => 'chbx_pages',
'checked' => true,
)).'<label for="chbx_pages">'.elgg_echo('amap_maps_api:pages').'</label>';
}


$entities1 = array_merge($users, $groups);
$entities = array_merge($entities1, $pages);


$map_objects = array();
if ($entities) {

foreach ($entities as $entity) {
$entity = amap_ma_set_entity_additional_info($entity, 'name', 'briefdescription', groupsmap_get_group_location_str($entity));
}


foreach ($entities as $e) {
if ($e->getLatitude() && $e->getLongitude()) {
$object_x = array();
$object_x['guid'] = $e->getGUID();
$object_x['title'] = amap_ma_remove_shits($e->getVolatileData('m_title'));;
$object_x['description'] = amap_ma_get_entity_description($e->getVolatileData('m_description'));
$object_x['location'] = elgg_echo('amap_maps_api:location', array(amap_ma_remove_shits($e->getVolatileData('m_location'))));
$object_x['lat'] = $e->getLatitude();
$object_x['lng'] = $e->getLongitude();
$object_x['icon'] = $e->getVolatileData('m_icon');
$object_x['type'] = $e->getType().$e->getSubtype();
$object_x['other_info'] = $e->getVolatileData('m_other_info');
$object_x['map_icon'] = $e->getVolatileData('m_map_icon');
$object_x['info_window'] = $object_x['icon'].' '.$object_x['title'];
$object_x['info_window'] .= ($object_x['location']?'<br/>'.$object_x['location']:'');
$object_x['info_window'] .= ($object_x['other_info']?'<br/>'.$object_x['other_info']:'');
$object_x['info_window'] .= ($object_x['description']?'<br/>'.$object_x['description']:'');
array_push($map_objects, $object_x);
}
}

$sidebar = '';
if (amap_ma_check_if_add_sidebar_list('groupsmap')) {
$box_color_flag = true;
foreach ($entities as $entity) {
$sidebar .= elgg_view('groupsmap/sidebar', array('entity' => $entity, 'box_color' => ($box_color_flag ? 'box_even' : 'box_odd')));
$box_color_flag = !$box_color_flag;
}
}
}
else {
$content = elgg_echo('amap_maps_api:search:personalized:empty');
}

$result = array(
'error' => false,
'title' => $title,
'location' => $search_location_txt,
'radius' => $search_radius_txt,
's_radius' => amap_ma_get_default_radius_search($s_radius, true),
's_radius_no' => $s_radius,
'content' => $content,
'map_objects' => json_encode($map_objects),
's_location_lat' => ($s_lat? $s_lat: ''),
's_location_lng' => ($s_long? $s_long: ''),
's_location_txt' => $search_location_txt,
'sidebar' => $sidebar,
);

// release variables
unset($entities);
unset($map_objects);

echo json_encode($result);
exit;
32 changes: 16 additions & 16 deletions lib/amap_maps_api.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* Elgg AgoraMap Maps Api plugin
* @package amap_maps_api
* @package amap_maps_api
*/

// Based on object location, save his coords.
// Based on object location, save his coords.
function amap_ma_save_object_coords($location, $object, $pluginname, $lat_g = '', $lng_g = '') {
if ($lat_g && $lng_g) {
$lat = $lat_g;
Expand Down Expand Up @@ -66,11 +66,11 @@ function amap_ma_geocode_location($location) {
}

// get online users
function amap_ma_get_online_users_map(array $options = array()) {
function amap_ma_get_online_users_map(array $options = array()) {
//$count = find_active_users(600, 10, 0, true);
$options = array_merge(array(
'seconds' => 600,
), $options);
), $options);
$objects = find_active_users($options, 0, 0);

return $objects;
Expand Down Expand Up @@ -349,7 +349,7 @@ function amap_ma_not_permit_public_access() {
return false;
}

// Check if membersmap is enabled for global map
// Check if membersmap is enabled for global map
function amap_ma_check_if_membersmap_gm_enabled() {
$gm_membersmap = trim(elgg_get_plugin_setting('gm_membersmap', AMAP_MA_PLUGIN_ID));

Expand All @@ -360,7 +360,7 @@ function amap_ma_check_if_membersmap_gm_enabled() {
return false;
}

// Check if groupsmap is enabled for global map
// Check if groupsmap is enabled for global map
function amap_ma_check_if_groupsmap_gm_enabled() {
$gm_groupsmap = trim(elgg_get_plugin_setting('gm_groupsmap', AMAP_MA_PLUGIN_ID));

Expand All @@ -371,7 +371,7 @@ function amap_ma_check_if_groupsmap_gm_enabled() {
return false;
}

// Check if agora is enabled for global map
// Check if agora is enabled for global map
function amap_ma_check_if_agora_gm_enabled() {
$gm_agora = trim(elgg_get_plugin_setting('gm_agora', AMAP_MA_PLUGIN_ID));

Expand All @@ -382,7 +382,7 @@ function amap_ma_check_if_agora_gm_enabled() {
return false;
}

// Check if pagesmap is enabled for global map
// Check if pagesmap is enabled for global map
function amap_ma_check_if_pagesmap_gm_enabled() {
$gm_pagesmap = trim(elgg_get_plugin_setting('gm_pagesmap', AMAP_MA_PLUGIN_ID));

Expand All @@ -406,7 +406,7 @@ function amap_ma_get_entity_description($desc) {
$entity_description = preg_replace('/[^(\x20-\x7F)]*/', '', $desc);
$entity_description = amap_ma_remove_shits($entity_description);

// code below replace the &quot; with " from href of a tag.
// code below replace the &quot; with " from href of a tag.
// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
// Check if there is a url in the text
Expand Down Expand Up @@ -450,10 +450,10 @@ function amap_ma_get_entity_icon($u) {
$user_icon = amap_ma_get_marker_icon('membersmap');
if ($user_icon == 'user_icon_tiny.png') {
$entity_icon = $u->getIconURL('tiny');
}
}
else if ($user_icon == 'user_icon_small.png') {
$entity_icon = $u->getIconURL('small');
}
}
else {
$entity_icon = elgg_get_site_url() . "mod/membersmap/graphics/{$user_icon}";
}
Expand All @@ -469,12 +469,12 @@ function amap_ma_get_entity_icon($u) {
}
else if (elgg_instanceof($u, 'object', 'lcourt')) {
$entity_icon = elgg_get_simplecache_url('leaguemanager/icon/icons/stadium.png');
}
}
else if (elgg_instanceof($u, 'object', 'page') || elgg_instanceof($u, 'object', 'page_top')) {
//$entity_icon = elgg_get_site_url() . 'mod/pagesmap/graphics/' . amap_ma_get_marker_icon('pagesmap');
$entity_icon = elgg_get_simplecache_url('pagesmap/icon/' . amap_ma_get_marker_icon('pagesmap'));
}

return $entity_icon;
}

Expand Down Expand Up @@ -544,15 +544,15 @@ function amap_ma_get_initial_radius($pluginname) {

/**
* Assign to entity additional information for showing on map
*
*
* @param type $entity
* @param type $etitle
* @param type $edescription
* @param type $elocation
* @param type $eotherinfo
* @param type $m_icon_light: if need to give entity map icon opacity, set this to true
* @param type $eurl: if need to use other URL than standard entity URL, set this to true
*
*
* @return Elgg Entity as given
*/
function amap_ma_set_entity_additional_info($entity, $etitle, $edescription, $elocation = null, $eotherinfo = null, $m_icon_light = false, $eurl = false) {
Expand Down Expand Up @@ -611,7 +611,7 @@ function amap_ma_set_entity_additional_info($entity, $etitle, $edescription, $el
$entity->setVolatileData('m_other_info', $eotherinfo);
}
$entity->setVolatileData('m_icon_light', $m_icon_light);

/* hide at the moment as the distance displayed is not well calculated
if ($user->getLatitude() && $user->getLongitude()) {
$distance = get_distance($entity->getLatitude(), $entity->getLongitude(), $user->getLatitude(), $user->getLongitude()); // distance in metres
Expand Down
Loading