2010-03-11 01:39:22 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
/**
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
2013-01-21 06:24:24 +00:00
|
|
|
* Copyright (C) 2000-2013 Bharat Mediratta
|
2010-03-11 01:39:22 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
class EXIF_GPS_Controller extends Controller {
|
2012-06-28 00:19:46 +00:00
|
|
|
public static $xml_records_limit = 1000;
|
|
|
|
|
2012-06-19 00:00:07 +00:00
|
|
|
public function item($item_id) {
|
|
|
|
// Make sure the context callback is set to album when linking to photos from map pages.
|
|
|
|
$item = ORM::factory("item", $item_id);
|
|
|
|
access::required("view", $item);
|
|
|
|
item::set_display_context_callback("Albums_Controller::get_display_context");
|
|
|
|
url::redirect($item->abs_url());
|
|
|
|
}
|
|
|
|
|
2012-06-28 00:19:46 +00:00
|
|
|
public function xml($query_type, $query_id, $offset) {
|
2012-06-19 00:00:07 +00:00
|
|
|
// Generate an xml output of the photos to be mapped.
|
|
|
|
// $query_type can be either "album" or "user", $query_id is the id# of the album or user to map.
|
|
|
|
|
|
|
|
// If the user can't view maps, don't let them view the xml.
|
|
|
|
if ((module::get_var("exif_gps", "restrict_maps") == true) && (identity::active_user()->guest)) {
|
|
|
|
throw new Kohana_404_Exception();
|
|
|
|
}
|
|
|
|
|
|
|
|
$items = "";
|
|
|
|
if ($query_type == "user") {
|
|
|
|
$items = ORM::factory("item")
|
|
|
|
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
|
|
|
|
->where("items.owner_id", "=", $query_id)
|
|
|
|
->viewable()
|
|
|
|
->order_by("exif_coordinates.latitude", "ASC")
|
2012-06-28 00:19:46 +00:00
|
|
|
->find_all(EXIF_GPS_Controller::$xml_records_limit, $offset);
|
2012-06-19 00:00:07 +00:00
|
|
|
} elseif ($query_type == "album") {
|
|
|
|
$items = ORM::factory("item", $query_id)
|
|
|
|
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
|
|
|
|
->viewable()
|
|
|
|
->order_by("exif_coordinates.latitude", "ASC")
|
2012-06-28 00:19:46 +00:00
|
|
|
->descendants(EXIF_GPS_Controller::$xml_records_limit, $offset);
|
2012-06-19 00:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$v = new View("exif_gps_coordinates_xml.html");
|
|
|
|
$v->items = $items;
|
|
|
|
header("Content-type: text/xml; charset=utf-8");
|
|
|
|
print $v;
|
|
|
|
}
|
|
|
|
|
2010-03-16 20:27:24 +00:00
|
|
|
public function map($map_type, $type_id) {
|
2010-04-07 22:48:33 +00:00
|
|
|
// Map all items in the specified album or user.
|
2012-06-14 18:32:12 +00:00
|
|
|
// Valid values for $map_type are "album" or "user", $type_id is either an
|
|
|
|
// album id# or a user id#.
|
2010-03-11 01:39:22 +00:00
|
|
|
|
2012-06-19 00:00:07 +00:00
|
|
|
// If the user can't view maps, throw a 404 error.
|
|
|
|
if ((module::get_var("exif_gps", "restrict_maps") == true) && (identity::active_user()->guest)) {
|
|
|
|
throw new Kohana_404_Exception();
|
|
|
|
}
|
|
|
|
|
2012-06-28 00:19:46 +00:00
|
|
|
// Figure out what to display for the page title and how many items to display.
|
2010-03-16 20:27:24 +00:00
|
|
|
$map_title = "";
|
2012-06-28 00:19:46 +00:00
|
|
|
$items_count = 0;
|
2010-03-16 20:27:24 +00:00
|
|
|
if ($map_type == "album") {
|
|
|
|
$curr_album = ORM::factory("item")->where("id", "=", $type_id)->find_all();
|
2011-02-03 04:51:32 +00:00
|
|
|
$map_title = $curr_album[0]->title;
|
2012-06-28 00:19:46 +00:00
|
|
|
$items_count = ORM::factory("item", $type_id)
|
|
|
|
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
|
|
|
|
->viewable()
|
|
|
|
->order_by("exif_coordinates.latitude", "ASC")
|
|
|
|
->descendants_count();
|
2010-03-16 20:27:24 +00:00
|
|
|
} elseif ($map_type == "user") {
|
|
|
|
$curr_user = ORM::factory("user")->where("id", "=", $type_id)->find_all();
|
|
|
|
$map_title = $curr_user[0]->full_name . "'s " . t("Photos");
|
2012-06-28 00:19:46 +00:00
|
|
|
$items_count = ORM::factory("item")
|
|
|
|
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
|
|
|
|
->where("items.owner_id", "=", $type_id)
|
|
|
|
->viewable()
|
|
|
|
->order_by("exif_coordinates.latitude", "ASC")
|
|
|
|
->count_all();
|
2010-03-16 20:27:24 +00:00
|
|
|
}
|
2010-03-17 03:38:11 +00:00
|
|
|
|
2012-06-14 18:27:41 +00:00
|
|
|
// Set up breadcrumbs.
|
|
|
|
$breadcrumbs = array();
|
|
|
|
if ($map_type == "album") {
|
|
|
|
$counter = 0;
|
|
|
|
$breadcrumbs[] = Breadcrumb::instance(t("Map"), url::site("exif_gps/map/album/{$type_id}"))->set_last();
|
|
|
|
$parent_item = ORM::factory("item", $type_id);
|
|
|
|
while ($parent_item->id != 1) {
|
|
|
|
$breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url());
|
|
|
|
$parent_item = ORM::factory("item", $parent_item->parent_id);
|
|
|
|
}
|
|
|
|
$breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url())->set_first();
|
|
|
|
$breadcrumbs = array_reverse($breadcrumbs, true);
|
|
|
|
} else {
|
|
|
|
$root = item::root();
|
|
|
|
$breadcrumbs[] = Breadcrumb::instance($root->title, $root->url())->set_first();
|
|
|
|
$breadcrumbs[] = Breadcrumb::instance(t("Photo Map"), url::site("exif_gps/map/{$map_type}/{$type_id}"))->set_last();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up and display the actual page.
|
|
|
|
$template = new Theme_View("page.html", "other", "EXIF_GPS_MAP");
|
2010-03-11 01:39:22 +00:00
|
|
|
$template->page_title = t("Gallery :: Map");
|
2012-06-14 18:27:41 +00:00
|
|
|
$template->set_global(array("breadcrumbs" => $breadcrumbs));
|
2010-03-11 01:39:22 +00:00
|
|
|
$template->content = new View("exif_gps_map.html");
|
2010-03-16 20:27:24 +00:00
|
|
|
if ($map_title == "") {
|
|
|
|
$template->content->title = t("Map");
|
|
|
|
} else {
|
|
|
|
$template->content->title = t("Map of") . " " . $map_title;
|
|
|
|
}
|
2012-06-28 00:19:46 +00:00
|
|
|
|
2010-03-18 00:05:30 +00:00
|
|
|
// Figure out default map type.
|
|
|
|
$int_map_type = module::get_var("exif_gps", "largemap_maptype");
|
2012-06-19 00:00:07 +00:00
|
|
|
if ($int_map_type == 0) $map_display_type = "ROADMAP";
|
|
|
|
if ($int_map_type == 1) $map_display_type = "SATELLITE";
|
|
|
|
if ($int_map_type == 2) $map_display_type = "HYBRID";
|
|
|
|
if ($int_map_type == 3) $map_display_type = "TERRAIN";
|
|
|
|
$template->content->map_type = $map_display_type;
|
|
|
|
|
|
|
|
// These are used to set up the URL to the xml file.
|
|
|
|
$template->content->query_type = $map_type;
|
|
|
|
$template->content->query_id = $type_id;
|
2012-06-28 00:19:46 +00:00
|
|
|
$template->content->items_count = $items_count;
|
2010-03-18 00:05:30 +00:00
|
|
|
|
2010-03-11 01:39:22 +00:00
|
|
|
// Load in module preferences.
|
|
|
|
$template->content->google_map_key = module::get_var("exif_gps", "googlemap_api_key");
|
|
|
|
|
|
|
|
// Display the page.
|
|
|
|
print $template;
|
|
|
|
}
|
|
|
|
}
|