From df5b8b9cd159c96085611d286a47718e4ce82e26 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Tue, 16 Mar 2010 14:41:32 +0800 Subject: [PATCH] That was some ugly code. Rewritten. --- modules/exif_gps/helpers/exif_gps_block.php | 86 ++++++++------------- 1 file changed, 32 insertions(+), 54 deletions(-) diff --git a/modules/exif_gps/helpers/exif_gps_block.php b/modules/exif_gps/helpers/exif_gps_block.php index 89a7b1cf..dc06713d 100644 --- a/modules/exif_gps/helpers/exif_gps_block.php +++ b/modules/exif_gps/helpers/exif_gps_block.php @@ -27,28 +27,16 @@ class exif_gps_block_Core { switch ($block_id) { case "exif_gps_map": + + // Look for coordinates to display. + $latitude = ""; + $longitude = ""; if ($theme->item()) { // Check and see if the item has exif coordinates associated with it. $record = ORM::factory("exif_coordinate")->where("item_id", "=", $theme->item->id)->find(); if ($record->loaded()) { - $block = new Block(); - $block->css_id = "g-exif-gps-sidebar"; - $block->title = t("Location"); - if (module::get_var("exif_gps", "sidebar_mapformat") == 1) { - $block->content = new View("exif_gps_dynamic_sidebar.html"); - if (module::get_var("exif_gps", "sidebar_maptype") == 0) $block->content->sidebar_map_type = "ROADMAP"; - if (module::get_var("exif_gps", "sidebar_maptype") == 1) $block->content->sidebar_map_type = "SATELLITE"; - if (module::get_var("exif_gps", "sidebar_maptype") == 2) $block->content->sidebar_map_type = "HYBRID"; - if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "TERRAIN"; - } else { - $block->content = new View("exif_gps_static_sidebar.html"); - if (module::get_var("exif_gps", "sidebar_maptype") == 0) $block->content->sidebar_map_type = "roadmap"; - if (module::get_var("exif_gps", "sidebar_maptype") == 1) $block->content->sidebar_map_type = "satellite"; - if (module::get_var("exif_gps", "sidebar_maptype") == 2) $block->content->sidebar_map_type = "hybrid"; - if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "terrain"; - } - $block->content->latitude = $record->latitude; - $block->content->longitude = $record->longitude; + $latitude = $record->latitude; + $longitude = $record->longitude; } elseif (module::is_active("tagsmap") && module::is_active("tag")) { // If there are no exif coordinates, check for tagsmap coordinates instead. $tagsItem = ORM::factory("tag") @@ -59,24 +47,8 @@ class exif_gps_block_Core { foreach ($tagsItem as $oneTag) { $tagsGPS = ORM::factory("tags_gps")->where("tag_id", "=", $oneTag->id)->find(); if ($tagsGPS->loaded()) { - $block = new Block(); - $block->css_id = "g-exif-gps-sidebar"; - $block->title = t("Location"); - if (module::get_var("exif_gps", "sidebar_mapformat") == 1) { - $block->content = new View("exif_gps_dynamic_sidebar.html"); - if (module::get_var("exif_gps", "sidebar_maptype") == 0) $block->content->sidebar_map_type = "ROADMAP"; - if (module::get_var("exif_gps", "sidebar_maptype") == 1) $block->content->sidebar_map_type = "SATELLITE"; - if (module::get_var("exif_gps", "sidebar_maptype") == 2) $block->content->sidebar_map_type = "HYBRID"; - if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "TERRAIN"; - } else { - $block->content = new View("exif_gps_static_sidebar.html"); - if (module::get_var("exif_gps", "sidebar_maptype") == 0) $block->content->sidebar_map_type = "roadmap"; - if (module::get_var("exif_gps", "sidebar_maptype") == 1) $block->content->sidebar_map_type = "satellite"; - if (module::get_var("exif_gps", "sidebar_maptype") == 2) $block->content->sidebar_map_type = "hybrid"; - if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "terrain"; - } - $block->content->latitude = $tagsGPS->latitude; - $block->content->longitude = $tagsGPS->longitude; + $latitude = $tagsGPS->latitude; + $longitude = $tagsGPS->longitude; break; } } @@ -86,26 +58,32 @@ class exif_gps_block_Core { // If the current page belongs to a tag, check and see if the tag has GPS coordinates. $tagsGPS = ORM::factory("tags_gps")->where("tag_id", "=", $theme->tag()->id)->find(); if ($tagsGPS->loaded()) { - $block = new Block(); - $block->css_id = "g-exif-gps-sidebar"; - $block->title = t("Location"); - if (module::get_var("exif_gps", "sidebar_mapformat") == 1) { - $block->content = new View("exif_gps_dynamic_sidebar.html"); - if (module::get_var("exif_gps", "sidebar_maptype") == 0) $block->content->sidebar_map_type = "ROADMAP"; - if (module::get_var("exif_gps", "sidebar_maptype") == 1) $block->content->sidebar_map_type = "SATELLITE"; - if (module::get_var("exif_gps", "sidebar_maptype") == 2) $block->content->sidebar_map_type = "HYBRID"; - if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "TERRAIN"; - } else { - $block->content = new View("exif_gps_static_sidebar.html"); - if (module::get_var("exif_gps", "sidebar_maptype") == 0) $block->content->sidebar_map_type = "roadmap"; - if (module::get_var("exif_gps", "sidebar_maptype") == 1) $block->content->sidebar_map_type = "satellite"; - if (module::get_var("exif_gps", "sidebar_maptype") == 2) $block->content->sidebar_map_type = "hybrid"; - if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "terrain"; - } - $block->content->latitude = $tagsGPS->latitude; - $block->content->longitude = $tagsGPS->longitude; + $latitude = $tagsGPS->latitude; + $longitude = $tagsGPS->longitude; } } + + // If coordinates were found, create the block. + if ($latitude != "" && $longitude != "") { + $block = new Block(); + $block->css_id = "g-exif-gps-sidebar"; + $block->title = t("Location"); + if (module::get_var("exif_gps", "sidebar_mapformat") == 1) { + $block->content = new View("exif_gps_dynamic_sidebar.html"); + if (module::get_var("exif_gps", "sidebar_maptype") == 0) $block->content->sidebar_map_type = "ROADMAP"; + if (module::get_var("exif_gps", "sidebar_maptype") == 1) $block->content->sidebar_map_type = "SATELLITE"; + if (module::get_var("exif_gps", "sidebar_maptype") == 2) $block->content->sidebar_map_type = "HYBRID"; + if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "TERRAIN"; + } else { + $block->content = new View("exif_gps_static_sidebar.html"); + if (module::get_var("exif_gps", "sidebar_maptype") == 0) $block->content->sidebar_map_type = "roadmap"; + if (module::get_var("exif_gps", "sidebar_maptype") == 1) $block->content->sidebar_map_type = "satellite"; + if (module::get_var("exif_gps", "sidebar_maptype") == 2) $block->content->sidebar_map_type = "hybrid"; + if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "terrain"; + } + $block->content->latitude = $latitude; + $block->content->longitude = $longitude; + } break; } return $block;