diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-10-28 19:17:36 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-10-28 19:17:36 +0000 |
commit | 7ddd9521b3f3a397da3b0a6b56238d31414eb4be (patch) | |
tree | 6eb6a9a51db5fa0f5d3cc2ec6de29b9e258b12a1 /engine/lib/location.php | |
parent | bd3484417d170e62bc94e9db81d4ad37e8ddee6a (diff) | |
download | elgg-7ddd9521b3f3a397da3b0a6b56238d31414eb4be.tar.gz elgg-7ddd9521b3f3a397da3b0a6b56238d31414eb4be.tar.bz2 |
Standardized code in all of core, not including language files, tests, or core mods.
git-svn-id: http://code.elgg.org/elgg/trunk@7124 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/location.php')
-rw-r--r-- | engine/lib/location.php | 127 |
1 files changed, 76 insertions, 51 deletions
diff --git a/engine/lib/location.php b/engine/lib/location.php index 73f3c4dbd..f3aae709b 100644 --- a/engine/lib/location.php +++ b/engine/lib/location.php @@ -9,15 +9,19 @@ /** * Encode a location into a latitude and longitude, caching the result. * - * Works by triggering the 'geocode' 'location' plugin hook, and requires a geocoding module to be installed + * Works by triggering the 'geocode' 'location' plugin + * hook, and requires a geocoding module to be installed * activated in order to work. * * @param String $location The location, e.g. "London", or "24 Foobar Street, Gotham City" + * + * @return string */ function elgg_geocode_location($location) { global $CONFIG; - // Handle cases where we are passed an array (shouldn't be but can happen if location is a tag field) + // Handle cases where we are passed an array (shouldn't be + // but can happen if location is a tag field) if (is_array($location)) { $location = implode(', ', $location); } @@ -25,7 +29,8 @@ function elgg_geocode_location($location) { $location = sanitise_string($location); // Look for cached version - $cached_location = get_data_row("SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='$location'"); + $query = "SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='$location'"; + $cached_location = get_data_row($query); if ($cached_location) { return array('lat' => $cached_location->lat, 'long' => $cached_location->long); @@ -41,7 +46,10 @@ function elgg_geocode_location($location) { $long = (float)$return['long']; // Put into cache at the end of the page since we don't really care that much - execute_delayed_write_query("INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache (location, lat, `long`) VALUES ('$location', '{$lat}', '{$long}') ON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'"); + $query = "INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache " + . " (location, lat, `long`) VALUES ('$location', '{$lat}', '{$long}')" + . " ON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'"; + execute_delayed_write_query($query); } return $return; @@ -50,30 +58,33 @@ function elgg_geocode_location($location) { /** * Return entities within a given geographic area. * - * @param real $lat Latitude - * @param real $long Longitude - * @param real $radius The radius - * @param string $type The type of entity (eg "user", "object" etc) - * @param string $subtype The arbitrary subtype of the entity - * @param int $owner_guid The GUID of the owning user - * @param string $order_by The field to order by; by default, time_created desc - * @param int $limit The number of entities to return; 10 by default - * @param int $offset The indexing offset, 0 by default - * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false. - * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites. - * @param int|array $container_guid The container or containers to get entities from (default: all containers). + * @param float $lat Latitude + * @param float $long Longitude + * @param float $radius The radius + * @param string $type The type of entity (eg "user", "object" etc) + * @param string $subtype The arbitrary subtype of the entity + * @param int $owner_guid The GUID of the owning user + * @param string $order_by The field to order by; by default, time_created desc + * @param int $limit The number of entities to return; 10 by default + * @param int $offset The indexing offset, 0 by default + * @param boolean $count Count entities + * @param int $site_guid Site GUID. 0 for current, -1 for any + * @param int|array $container_guid Container GUID + * * @return array A list of entities. */ -function get_entities_in_area($lat, $long, $radius, $type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid) { +function get_entities_in_area($lat, $long, $radius, $type = "", $subtype = "", $owner_guid = 0, +$order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid) { + global $CONFIG; if ($subtype === false || $subtype === null || $subtype === 0) { return false; } - $lat = (real)$lat; - $long = (real)$long; - $radius = (real)$radius; + $lat = (float)$lat; + $long = (float)$long; + $radius = (float)$radius; $order_by = sanitise_string($order_by); $limit = (int)$limit; @@ -88,15 +99,18 @@ function get_entities_in_area($lat, $long, $radius, $type = "", $subtype = "", $ if (is_array($type)) { $tempwhere = ""; if (sizeof($type)) { - foreach($type as $typekey => $subtypearray) { - foreach($subtypearray as $subtypeval) { + foreach ($type as $typekey => $subtypearray) { + foreach ($subtypearray as $subtypeval) { $typekey = sanitise_string($typekey); if (!empty($subtypeval)) { $subtypeval = (int) get_subtype_id($typekey, $subtypeval); } else { $subtypeval = 0; } - if (!empty($tempwhere)) $tempwhere .= " or "; + if (!empty($tempwhere)) { + $tempwhere .= " or "; + } + $tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})"; } } @@ -112,7 +126,7 @@ function get_entities_in_area($lat, $long, $radius, $type = "", $subtype = "", $ $where[] = "e.type='$type'"; } - if ($subtype!=="") { + if ($subtype !== "") { $where[] = "e.subtype=$subtype"; } } @@ -125,7 +139,7 @@ function get_entities_in_area($lat, $long, $radius, $type = "", $subtype = "", $ } else if (sizeof($owner_guid) > 0) { $owner_array = array_map('sanitise_int', $owner_guid); // Cast every element to the owner_guid array to int - $owner_guid = implode(",",$owner_guid); // + $owner_guid = implode(",", $owner_guid); // $where[] = "e.owner_guid in ({$owner_guid})" ; // } if (is_null($container_guid)) { @@ -139,8 +153,10 @@ function get_entities_in_area($lat, $long, $radius, $type = "", $subtype = "", $ if (!is_null($container_guid)) { if (is_array($container_guid)) { - foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val; - $where[] = "e.container_guid in (" . implode(",",$container_guid) . ")"; + foreach ($container_guid as $key => $val) { + $container_guid[$key] = (int) $val; + } + $where[] = "e.container_guid in (" . implode(",", $container_guid) . ")"; } else { $container_guid = (int) $container_guid; $where[] = "e.container_guid = {$container_guid}"; @@ -198,42 +214,51 @@ function get_entities_in_area($lat, $long, $radius, $type = "", $subtype = "", $ /** * List entities in a given location * - * @param string $location Location - * @param string $type The type of entity (eg "user", "object" etc) - * @param string $subtype The arbitrary subtype of the entity - * @param int $owner_guid The GUID of the owning user - * @param int $limit The number of entities to display per page (default: 10) - * @param true|false $fullview Whether or not to display the full view (default: true) - * @param true|false $viewtypetoggle Whether or not to allow gallery view - * @param true|false $pagination Display pagination? Default: true + * @param string $location Location + * @param string $type The type of entity (eg "user", "object" etc) + * @param string $subtype The arbitrary subtype of the entity + * @param int $owner_guid The GUID of the owning user + * @param int $limit The number of entities to display per page (default: 10) + * @param bool $fullview Whether or not to display the full view (default: true) + * @param bool $viewtypetoggle Whether or not to allow gallery view + * @param bool $navigation Display pagination? Default: true + * * @return string A viewable list of entities */ -function list_entities_location($location, $type= "", $subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $navigation = true) { - return list_entities_from_metadata('location', $location, $type, $subtype, $owner_guid, $limit, $fullview, $viewtypetoggle, $navigation); +function list_entities_location($location, $type= "", $subtype = "", $owner_guid = 0, $limit = 10, +$fullview = true, $viewtypetoggle = false, $navigation = true) { + + return list_entities_from_metadata('location', $location, $type, $subtype, $owner_guid, $limit, + $fullview, $viewtypetoggle, $navigation); } /** * List items within a given geographic area. * - * @param real $lat Latitude - * @param real $long Longitude - * @param real $radius The radius - * @param string $type The type of entity (eg "user", "object" etc) - * @param string $subtype The arbitrary subtype of the entity - * @param int $owner_guid The GUID of the owning user - * @param int $limit The number of entities to display per page (default: 10) - * @param true|false $fullview Whether or not to display the full view (default: true) - * @param true|false $viewtypetoggle Whether or not to allow gallery view - * @param true|false $pagination Display pagination? Default: true + * @param real $lat Latitude + * @param real $long Longitude + * @param real $radius The radius + * @param string $type The type of entity (eg "user", "object" etc) + * @param string $subtype The arbitrary subtype of the entity + * @param int $owner_guid The GUID of the owning user + * @param int $limit The number of entities to display per page (default: 10) + * @param bool $fullview Whether or not to display the full view (default: true) + * @param bool $viewtypetoggle Whether or not to allow gallery view + * @param bool $navigation Display pagination? Default: true + * * @return string A viewable list of entities */ -function list_entities_in_area($lat, $long, $radius, $type= "", $subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $navigation = true) { +function list_entities_in_area($lat, $long, $radius, $type= "", $subtype = "", $owner_guid = 0, +$limit = 10, $fullview = true, $viewtypetoggle = false, $navigation = true) { $offset = (int) get_input('offset'); - $count = get_entities_in_area($lat, $long, $radius, $type, $subtype, $owner_guid, "", $limit, $offset, true); - $entities = get_entities_in_area($lat, $long, $radius, $type, $subtype, $owner_guid, "", $limit, $offset); + $count = get_entities_in_area($lat, $long, $radius, $type, $subtype, $owner_guid, + "", $limit, $offset, true); + $entities = get_entities_in_area($lat, $long, $radius, $type, $subtype, $owner_guid, + "", $limit, $offset); - return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $navigation); + return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, + $viewtypetoggle, $navigation); } // Some distances in degrees (approximate) |