Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geolocation support for CSV Import #20

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
103 changes: 96 additions & 7 deletions GeolocationPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public function hookInstall()
set_option('geolocation_per_page', GEOLOCATION_DEFAULT_LOCATIONS_PER_PAGE);
set_option('geolocation_add_map_to_contribution_form', '1');
set_option('geolocation_use_metric_distances', '1');
set_option('geolocation_default_loc_set', 'Dublin Core');
set_option('geolocation_default_loc_field', 'Coverage');
set_option('geolocation_use_in_import','0');
set_option('geolocation_use_coordinates','0');
}

public function hookUninstall()
Expand All @@ -92,10 +96,18 @@ public function hookUninstall()
delete_option('geolocation_per_page');
delete_option('geolocation_add_map_to_contribution_form');
delete_option('geolocation_use_metric_distances');
delete_option('geolocation_use_coordinates');

// This is for older versions of Geolocation, which used to store a Google Map API key.
delete_option('geolocation_gmaps_key');

// CSV import Geolocation support

delete_option('geolocation_default_loc_set');
delete_option('geolocation_default_loc_field');
delete_option('geolocation_use_in_import');


// Drop the Location table
$db = get_db();
$db->query("DROP TABLE IF EXISTS `$db->Location`");
Expand Down Expand Up @@ -136,6 +148,11 @@ public function hookConfig($args)
set_option('geolocation_link_to_nav', $_POST['geolocation_link_to_nav']);
set_option('geolocation_use_metric_distances', $_POST['geolocation_use_metric_distances']);
set_option('geolocation_map_type', $_POST['map_type']);
set_option('geolocation_default_loc_set', $_POST['geolocation_default_loc_set']);
set_option('geolocation_default_loc_field', $_POST['geolocation_default_loc_field']);
set_option('geolocation_use_in_import', $_POST['geolocation_use_in_import']);
set_option('geolocation_use_coordinates',$_POST['geolocation_use_coordinates']);

}

public function hookDefineAcl($args)
Expand Down Expand Up @@ -169,13 +186,28 @@ public function hookDefineRoutes($args)

public function hookAfterSaveItem($args)
{
if (!($post = $args['post'])) {
return;
// Let's check if there's CSV import process going on and are we willing to use
// Geolocation in current import
$db = Zend_Registry::get('bootstrap')->getResource('db');
$table = $db->getTable('CsvImport_Import');
$sql = $table->getSelectForCount()->where('`status` = ?');
$importInProgress = $db->fetchOne($sql, 'in_progress');
$useCoords = get_option('geolocation_use_in_import');
if ($importInProgress && $useCoords ) {
$geolocation_with_csv = true;
$item = $args['record'];
$coordinates_or_address = metadata($item, array(get_option('geolocation_default_loc_set'), get_option('geolocation_default_loc_field')));
debug(array(get_option('geolocation_default_loc_set'), get_option('geolocation_default_loc_field')));

}

if (!($post = $args['post']) && !($geolocation_with_csv)) {
return;
}

$item = $args['record'];
// If we don't have the geolocation form on the page, don't do anything!
if (!$post['geolocation']) {
if (!$post['geolocation'] && !($geolocation_with_csv)) {
return;
}

Expand All @@ -194,9 +226,66 @@ public function hookAfterSaveItem($args)
}
$location->setPostData($geolocationPost);
$location->save();
// If the form is empty, then we want to delete whatever location is
// currently stored
} else {

} elseif ($geolocation_with_csv && !empty($coordinates_or_address)){
$coordinates_or_address = metadata($item, array(get_option('geolocation_default_loc_set'), get_option('geolocation_default_loc_field')));
if (get_option('geolocation_use_coordinates')) {
$rawCoordinates = explode(',', $coordinates_or_address);
$latitude = substr($rawCoordinates[0],4);
$longitude = substr($rawCoordinates[1],0,-1);
$location = new Location; // Create new location object for this new item
$location->item_id = $item->id;
$location->latitude = $latitude;
$location->longitude = $longitude;
$location->address = $latitude .'.'.$longitude;
$location->zoom_level = get_option('geolocation_default_zoom_level'); // use the default zoom level
$location->map_type = "Google Maps v".GOOGLE_MAPS_API_VERSION;
$location->save();
}
else {
try {
// Get the value of the default location element of this item.
$address = metadata($item, array(get_option('geolocation_default_loc_set'), get_option('geolocation_default_loc_field')));

if ($address != "") {
// Make a request to the Google Geocoding API
$client = new Zend_Http_Client('http://maps.googleapis.com/maps/api/geocode/xml?address='.urlencode($address).'&sensor=false');
$response = $client->request();

if ($response->isSuccessful()) {
$body = $response->getBody();
$data = simplexml_load_string($body);

if ($data->status == "OK") {
$lat = $data->result->geometry->location->lat;
$lng = $data->result->geometry->location->lng;
// Get lat and lng from XML results

$location = new Location; // Create new location object for this new item
$location->item_id = $item->id;
$location->latitude = $lat;
$location->longitude = $lng;
$location->address = $address;
$location->zoom_level = get_option('geolocation_default_zoom_level'); // use the default zoom level
$location->map_type = "Google Maps v".GOOGLE_MAPS_API_VERSION;

$location->save();
}
}
}
} catch (Exception $e) {
// Invalid field for this item, or some other issue. So, just don't do anything.
}

}

}


// If the form is empty, then we want to delete whatever location is
// currently stored

else {
if ($location) {
$location->delete();
}
Expand Down Expand Up @@ -257,7 +346,7 @@ public function hookPublicItemsShow($args)
$width = get_option('geolocation_item_map_width') ? get_option('geolocation_item_map_width') : '';
$height = get_option('geolocation_item_map_height') ? get_option('geolocation_item_map_height') : '300px';
$html = "<div id='geolocation'>";
$html .= '<h2>Geolocation</h2>';
$html .= '<h2>'.__('Geolocation').'</h2>';
$html .= $view->itemGoogleMap($item, $width, $height);
$html .= "</div>";
echo $html;
Expand Down
46 changes: 46 additions & 0 deletions config_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,49 @@
</div>
</div>
</div>

<div class="field">
<div class="two columns alpha">
<label for="geolocation_link_to_nav"><?php echo __('Use Geolocation in CSV import'); ?></label>
</div>
<div class="inputs five columns omega">
<p class="explanation"><?php echo __('Geolocate items during CSV import.'); ?></p>
<div class="input-block">
<?php echo get_view()->formCheckbox('geolocation_use_in_import', true,
array('checked'=>(boolean)get_option('geolocation_use_in_import'))); ?>
</div>
</div>
</div>

<div class="field">
<div class="two columns alpha">
<label for="default_location"><?php echo __('Location field'); ?></label>
</div>
<div class="inputs five columns omega">
<div class="input-block">
<select class="textinput" name="geolocation_default_loc_set" id="geolocation_default_loc_set">
<option value="Dublin Core"
<?php if (get_option('geolocation_default_loc_set') == "Dublin Core") echo "selected='selected'"; ?>
>Dublin Core</option>
<option value="Item Type Metadata"
<?php if (get_option('geolocation_default_loc_set') == "Item Type Metadata") echo "selected='selected'"; ?>
><?php echo __('Item Type Metadata');?></option>
</select>

<input type="text" class="textinput" name="geolocation_default_loc_field" size="30" value="<?php echo get_option('geolocation_default_loc_field'); ?>" id="geolocation_default_loc_field" />
</div>
</div>
</div>
<div class="field">
<div class="two columns alpha">
<label for="geolocation_link_to_nav"><?php echo __('Use WGS84 coordinates'); ?></label>
</div>
<div class="inputs five columns omega">
<p class="explanation"><?php echo __('Instead of address or place name, the location field contains WGS84-coordinates saved in format POS(68.073611,29.315278).'); ?></p>
<div class="input-block">
<?php echo get_view()->formCheckbox('geolocation_use_coordinates', true,
array('checked'=>(boolean)get_option('geolocation_use_coordinates'))); ?>
</div>
</div>
</div>

Binary file modified languages/fi_FI.mo
Binary file not shown.
104 changes: 91 additions & 13 deletions languages/fi_FI.po
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
# Translation for the Geolocation plugin for Omeka.
# Copyright (C) 2011 Roy Rosenzweig Center for History and New Media
# This file is distributed under the same license as the Omeka package.
#
#
# Translators:
# Matti Lassila <matti.lassila@gmail.com>, 2013
msgid ""
msgstr ""
"Project-Id-Version: Omeka\n"
"Report-Msgid-Bugs-To: http://github.com/omeka/plugin-Geolocation/issues\n"
"POT-Creation-Date: 2012-01-09 21:49-0500\n"
"PO-Revision-Date: 2013-06-09 08:34+0000\n"
"PO-Revision-Date: 2014-06-03 21:08+0200\n"
"Last-Translator: Matti Lassila <matti.lassila@gmail.com>\n"
"Language-Team: Finnish (Finland) (http://www.transifex.com/projects/p/omeka/language/fi_FI/)\n"
"Language-Team: Finnish (Finland) (http://www.transifex.com/projects/p/omeka/"
"language/fi_FI/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: fi_FI\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.5.7\n"

#: GeolocationPlugin.php:334 GeolocationPlugin.php:340
#: GeolocationPlugin.php:364
msgid "Map"
msgstr "Kartta"

#: GeolocationPlugin.php:349
msgid "Geolocation"
msgstr "Kartta"

#: GeolocationPlugin.php:373 views/public/map/browse.php:23
msgid "Browse Map"
msgstr "Selaa karttaa"
Expand All @@ -47,7 +53,8 @@ msgstr "Sijainteja sivua kohti"
msgid ""
"The number of locations displayed per page when browsing the map. (Maximum "
"is "
msgstr "Kerralla näytettyjen sijaintien määrä karttaselausnäkymässä. (Enimmäismäärä "
msgstr ""
"Kerralla näytettyjen sijaintien määrä karttaselausnäkymässä. (Enimmäismäärä "

#: config_form.php:16
msgid "Default Latitude"
Expand All @@ -57,7 +64,9 @@ msgstr "Pohjoiskoordinaatti"
msgid ""
"Latitude of the map's initial center point, in degrees. Must be between -90 "
"and 90."
msgstr "Kartan aloitusnäkymän koordinaattikeskipiste asteina. Arvon tulee olla välillä -90 ja 90."
msgstr ""
"Kartan aloitusnäkymän koordinaattikeskipiste asteina. Arvon tulee olla "
"välillä -90 ja 90."

#: config_form.php:28
msgid "Default Longitude"
Expand All @@ -67,7 +76,9 @@ msgstr "Itäkoordinaatti"
msgid ""
"Longitude of the map's initial center point, in degrees. Must be between "
"-180 and 180."
msgstr "Kartan aloitusnäkymän koordinaattikeskipiste asteina. Arvon tulee olla välillä -180 ja 180."
msgstr ""
"Kartan aloitusnäkymän koordinaattikeskipiste asteina. Arvon tulee olla "
"välillä -180 ja 180."

#: config_form.php:40
msgid "Default Zoom Level"
Expand All @@ -77,17 +88,46 @@ msgstr "Zoomausaste"
msgid ""
"An integer greater than or equal to 0, where 0 represents the most zoomed "
"out scale."
msgstr "Aloitusnäkymän zoomausaste. Arvon tulee olla nolla tai sitä suurempi kokonaisluku. Arvolla nolla kartta on zoomattu kauimpaan asetukseensa."
msgstr ""
"Aloitusnäkymän zoomausaste. Arvon tulee olla välillä 0-18. Arvolla nolla "
"kartta on zoomattu kauimpaan asetukseensa. Mitä suurempi luku, sen "
"yksityiskohtaisempi kartta näytetään."

#: config_form.php:52
msgid "Width for Item Map"
msgstr "Aineistonäkymän kartan leveys"

#: config_form.php:52
msgid "Map Type"
msgstr "Kartan tyyppi"

#: config_form.php:52
msgid "The type of map to display"
msgstr "Karttanäkymän karttatyyppi"

#: config_form.php:52
msgid "Roadmap"
msgstr "Maantiekartta"

#: config_form.php:52
msgid "Satellite"
msgstr "Ilmakuva"

#: config_form.php:52
msgid "Hybrid"
msgstr "Yhdistelmä"

#: config_form.php:52
msgid "Terrain"
msgstr "Maasto"

#: config_form.php:55
msgid ""
"The width of the map displayed on your items/show page. If left blank, the "
"default width of 100% will be used."
msgstr "Karttanäkymän leveys aineistosivulla. Oletuksena kartta näytetään sivupohjan suhteen täysleveänä (100%)."
msgstr ""
"Karttanäkymän leveys aineistosivulla. Oletuksena kartta näytetään sivupohjan "
"suhteen täysleveänä (100%)."

#: config_form.php:64
msgid "Height for Item Map"
Expand All @@ -105,7 +145,9 @@ msgstr "Käytä mittayksikkönä kilometrejä"

#: config_form.php:79
msgid "Use metric distances in proximity search."
msgstr "Käytä läheisyyteen perustuvassa haussa yksikkönä kilometrejä. Oletuksena mittayksikkö on maili."
msgstr ""
"Käytä läheisyyteen perustuvassa haussa yksikkönä kilometrejä. Oletuksena "
"mittayksikkö on maili."

#: config_form.php:89
msgid "Add Link to Map on Items/Browse Navigation"
Expand All @@ -121,10 +163,46 @@ msgstr "Lisää kartta julkiselle tallennuslomakkeelle"

#: config_form.php:106
msgid ""
"If the Contribution plugin is installed and activated, Geolocation will add"
" a geolocation map field to the contribution form to associate a location to"
" a contributed item."
msgstr "Jos Contribution-lisäosa on asennettuna, julkisella tallennuslomakkeella voidaan näyttää karttanäkymä sijaintitietoa varten."
"If the Contribution plugin is installed and activated, Geolocation will add "
"a geolocation map field to the contribution form to associate a location to "
"a contributed item."
msgstr ""
"Jos Contribution-lisäosa on asennettuna, julkisella tallennuslomakkeella "
"voidaan näyttää karttanäkymä sijaintitietoa varten."

#: config_form.php:136
msgid "Use Geolocation in CSV import"
msgstr "Käytä sijaintitietoja CSV-tuonnissa"

#: config_form.php:139
msgid "Geolocate items during CSV import."
msgstr ""
"Lisää aineistoihin sijaintitiedot CSV-taulukkoon tallennetun paikan nimen "
"tai koordinaatin perusteella."

#: config_form.php:149
msgid "Location field"
msgstr "Sijaintitietokenttä"

#: config_form.php:163
msgid ""
"The location of new items will automatically be set to the position in this "
"field."
msgstr ""
"Aineistojen sijainniksi määritetään kentässä annettu koordinaattipiste tai "
"paikannimi."

#: config_form.php:169
msgid "Use WGS84 coordinates"
msgstr "Käytä WGS84 koordinaatteja"

#: config_form.php:172
msgid ""
"Instead of address or place name, the location field contains WGS84-"
"coordinates saved in format POS(68.073611,29.315278)."
msgstr ""
"Sijaintitietokenttä sisältää WGS84-koordinaatin tallennettuna muodossa POS"
"(68.073611,29.315278)."

#: helpers/ItemGoogleMap.php:47
msgid "This item has no location info associated with it."
Expand Down