From 8f8b7878577f44660c3e86c39633981f25ab690c Mon Sep 17 00:00:00 2001 From: rWatcher Date: Tue, 16 Mar 2010 14:30:47 +0800 Subject: [PATCH] Display location block on tag pages. --- modules/exif_gps/helpers/exif_gps_block.php | 118 +++++++++++++------- 1 file changed, 75 insertions(+), 43 deletions(-) diff --git a/modules/exif_gps/helpers/exif_gps_block.php b/modules/exif_gps/helpers/exif_gps_block.php index 466f465a..89a7b1cf 100644 --- a/modules/exif_gps/helpers/exif_gps_block.php +++ b/modules/exif_gps/helpers/exif_gps_block.php @@ -25,54 +25,86 @@ static function get_site_list() { static function get($block_id, $theme) { $block = ""; - // Make sure the current page belongs to an item. - if (!$theme->item()) { - return; - } - switch ($block_id) { case "exif_gps_map": - // 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; - } elseif (module::is_active("tagsmap") && module::is_active("tag")) { - // If there are no exif coordinates, check for tagsmap coordinates instead. - $tagsItem = ORM::factory("tag") - ->join("items_tags", "tags.id", "items_tags.tag_id") - ->where("items_tags.item_id", "=", $theme->item->id) - ->find_all(); - if (count($tagsItem) > 0) { - 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"); - $block->content = new View("exif_gps_sidebar.html"); - $block->content->latitude = $tagsGPS->latitude; - $block->content->longitude = $tagsGPS->longitude; - break; + 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; + } elseif (module::is_active("tagsmap") && module::is_active("tag")) { + // If there are no exif coordinates, check for tagsmap coordinates instead. + $tagsItem = ORM::factory("tag") + ->join("items_tags", "tags.id", "items_tags.tag_id") + ->where("items_tags.item_id", "=", $theme->item->id) + ->find_all(); + if (count($tagsItem) > 0) { + 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; + break; + } } } } + } elseif ( ($theme->tag()) && (module::is_active("tagsmap") && module::is_active("tag")) ) { + // 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; + } } break; }