Skip to content

Commit b98bb38

Browse files
author
Emmanuel Garette
committed
add leaflet-omnivore extension and gpx, csv, kml, wkt, topojson, geojson support
1 parent 205564a commit b98bb38

14 files changed

Lines changed: 179 additions & 3 deletions

admin/admin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@
4141
$template->set_filename('plugin_admin_content', dirname(__FILE__).'/admin.tpl');
4242

4343
if (!isset($_GET['tab']))
44-
$page['tab'] = 'config';
44+
$page['tab'] = 'gps';
4545
else
4646
$page['tab'] = $_GET['tab'];
4747

4848
$my_base_url = get_admin_plugin_menu_link(__FILE__);
4949

5050
$tabsheet = new tabsheet();
51+
$tabsheet->add( 'gps', '<span class="icon-cog"></span>' . l10n('Upload GPS file'), add_url_params( $my_base_url, array('tab'=>'gps') ) );
5152
$tabsheet->add( 'config', '<span class="icon-cog"></span>' . l10n('Configuration'), add_url_params( $my_base_url, array('tab'=>'config') ) );
5253
$tabsheet->select($page['tab']);
5354

admin/admin_gps.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/***********************************************
3+
* File : admin_config.php
4+
* Project : piwigo-openstreetmap
5+
* Descr : Install / Uninstall method
6+
*
7+
* Created : 28.05.2013
8+
*
9+
* Copyright 2013-2014 <xbgmsharp@gmail.com>
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation, either version 3 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
************************************************/
25+
26+
// Check whether we are indeed included by Piwigo.
27+
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
28+
29+
// Check access and exit when user status is not ok
30+
check_status(ACCESS_ADMINISTRATOR);
31+
32+
// Setup plugin Language
33+
load_language('plugin.lang', OSM_PATH);
34+
35+
36+
if (isset($_POST['submit'])) {
37+
$uploaded_errors = array();
38+
$upload_file = array();
39+
40+
if($_FILES['file_uploaded']['size'] != 0) {
41+
$upload_file = gps_upload_file(pwg_db_real_escape_string($_FILES['file_uploaded']));
42+
if(count($upload_file['errors']) != 0)
43+
$uploaded_errors['file'] = $upload_file['errors'];
44+
} else {
45+
$uploaded_errors['file']['no_file'] = l10n('Specify a file to upload');
46+
}
47+
48+
if (count($uploaded_errors) == 0) {
49+
$file_path = pwg_db_real_escape_string($upload_file['destination']);
50+
$category = pwg_db_real_escape_string($_POST['category']);
51+
$query="INSERT INTO ".$prefixeTable."gps ( `category_id`, `path` ) VALUES ('$category', '$file_path');";
52+
pwg_query($query);
53+
array_push($page['infos'], l10n('File uploaded and synchronized'));
54+
} else {
55+
array_push($page['errors'], l10n('There have been errors. See below'));
56+
$template->assign('uploaded_errors', $uploaded_errors);
57+
}
58+
}
59+
60+
function gps_upload_file($uploaded_file) {
61+
$uploaded_galleries_dir = PHPWG_ROOT_PATH.'galleries/gps/';
62+
$uploaded_file_tmp = $uploaded_file['tmp_name'];
63+
$uploaded_file_name = preg_replace('/[^a-zA-Z0-9s.]/', '_', $uploaded_file['name']);
64+
$uploaded_file_destination = $uploaded_galleries_dir . '/' . $uploaded_file_name;
65+
$ext = pathinfo($uploaded_file_name)['extension']
66+
$uploaded_errors = array();
67+
if(!in_array($ext, array('csv', 'gpx', 'kml', 'wkt', 'topojson', 'geojson'))) {
68+
$uploaded_errors['upload_error'] = l10n('Extension not supported');
69+
} else if ($uploaded_file['error'] !== UPLOAD_ERR_OK) {
70+
switch ($_FILES['file_uploaded']['error']) {
71+
case UPLOAD_ERR_INI_SIZE:
72+
$uploaded_errors['upload_error'] = l10n('File exceeds the upload_max_filesize directive in php.ini');
73+
break;
74+
case UPLOAD_ERR_PARTIAL:
75+
$uploaded_errors['upload_error'] = l10n('File was only partially uploaded');
76+
break;
77+
case UPLOAD_ERR_NO_FILE:
78+
$uploaded_errors['upload_error'] = l10n('No file to upload');
79+
break;
80+
case UPLOAD_ERR_NO_TMP_DIR:
81+
$uploaded_errors['upload_error'] = l10n('Missing a temporary folder');
82+
break;
83+
case UPLOAD_ERR_CANT_WRITE:
84+
$uploaded_errors['upload_error'] = l10n('Failed to write file to disk');
85+
break;
86+
case UPLOAD_ERR_EXTENSION:
87+
$uploaded_errors['upload_error'] = l10n('File upload stopped by extension');
88+
break;
89+
default:
90+
$uploaded_errors['upload_error'] = l10n('Upload error');
91+
}
92+
} else if (file_exists($uploaded_file_destination)) {
93+
$uploaded_errors['already_exist'] = l10n('file_uploader_error_already_exist');
94+
} else if (!move_uploaded_file($uploaded_file_tmp, $uploaded_file_destination)) {
95+
$uploaded_errors['move_uploaded_file'] = l10n('Can\'t upload file to galleries directory');
96+
}
97+
$return['errors'] = $uploaded_errors;
98+
$return['destination'] = $uploaded_file_destination;
99+
return $return;
100+
}
101+
102+
//Categories
103+
$query = 'SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.';';
104+
display_select_cat_wrapper($query, array(), 'category_gps');
105+

admin/admin_gps.tpl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{html_head}
2+
<link rel="stylesheet" href="{$OSM_PATH}fontello/css/osm.css" />
3+
<style>
4+
{literal}
5+
.osm_layout {
6+
text-align: left;
7+
border: 2px solid rgb(221, 221, 221);
8+
padding: 1em;
9+
margin: 1em;
10+
}
11+
{/literal}
12+
</style>
13+
{/html_head}
14+
15+
<div class="osm_layout">
16+
<form method="post" enctype="multipart/form-data">
17+
<p>
18+
<label>
19+
<span class="property">{'File to upload:'|@translate}</span>
20+
</label>
21+
<input name="file_uploaded" type="file" value=""{if isset($uploaded_errors.file)} class="file_uploader_error"{/if} />
22+
{foreach from=$uploaded_errors.file item=error_description}<p class="gps_error_description">{$error_description}</ip>{/foreach}
23+
</p>
24+
<p>
25+
<label>
26+
<span class="property">{'Album:'|@translate}</span>
27+
</label>
28+
<select style="width:400px" name="category" size="1">
29+
{html_options options=$category_gps}
30+
</select>
31+
</p>
32+
<p>
33+
<input class="submit" name="submit" type="submit" value="{'Submit'|@translate}" />
34+
</p>
35+
</form>
36+
</div>

include/functions_map.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ function osmcopyright($attrleaflet, $attrimagery, $attrmodule, $bl, $custombasel
5151
return $return;
5252
}
5353

54+
function osm_get_gps($page)
55+
{
56+
global $prefixeTable;
57+
if (isset($page['category'])) {
58+
$category = $page['category']['id'];
59+
$query = "SELECT `path` FROM ".$prefixeTable."gps AS g INNER JOIN ".CATEGORIES_TABLE." AS c ON g.category_id = c.id WHERE FIND_IN_SET(".$category.", c.uppercats);";
60+
} else {
61+
$query = "SELECT `path` FROM ".$prefixeTable."gps;";
62+
}
63+
return array_from_query($query, 'path');
64+
}
65+
5466
function osm_get_items($page)
5567
{
5668
// Limit search by category, by tag, by smartalbum
@@ -379,6 +391,12 @@ function osm_get_js($conf, $local_conf, $js_data)
379391
\t " . $divname . ".addLayer(marker);
380392
\tMarkerClusterList.push(marker);
381393
\t}";
394+
if (isset($local_conf['paths'])) {
395+
foreach ($local_conf['paths'] as $path) {
396+
$ext = pathinfo($path)['extension'];
397+
$js .= "\nomnivore.".$ext."('".$path."').addTo(".$divname.");";
398+
}
399+
}
382400
$js .= "\nif (typeof L.MarkerClusterGroup === 'function')\n";
383401
$js .= " " . $divname . ".addLayer(markers);\n";
384402
if (isset($local_conf['auto_center']) and $local_conf['auto_center'] === 0 ) {

index.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function osm_render_category_description()
5858
$local_conf['center_lng'] = 0;
5959
$local_conf['zoom'] = 2;
6060
$local_conf['auto_center'] = 0;
61+
$local_conf['paths'] = osm_get_gps($page);
6162
$height = isset($conf['osm_conf']['category_description']['height']) ? $conf['osm_conf']['category_description']['height'] : '200';
6263
$width = isset($conf['osm_conf']['category_description']['width']) ? $conf['osm_conf']['category_description']['width'] : 'auto';
6364
$js = osm_get_js($conf, $local_conf, $js_data);

leaflet/leaflet-omnivore.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

maintain.inc.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
function plugin_install()
2929
{
30+
global $prefixeTable;
3031
if (!defined('OSM_PATH'))
3132
define('OSM_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)).'/');
3233

@@ -97,6 +98,13 @@ function plugin_install()
9798

9899
$q = 'UPDATE '.CONFIG_TABLE.' SET `comment` = "Configuration settings for piwigo-openstreetmap plugin" WHERE `param` = "osm_conf";';
99100
pwg_query( $q );
101+
$q = "CREATE TABLE ".$prefixeTable."gps (
102+
`id` int(11) NOT NULL auto_increment,
103+
`category_id` smallint(5) unsigned NOT NULL,
104+
`path` varchar(255) NOT NULL,
105+
PRIMARY KEY (`id`)
106+
) DEFAULT CHARACTER SET ".DB_CHARSET." COLLATE utf8_general_ci;";
107+
pwg_query( $q );
100108

101109
// Create world map link
102110
$dir_name = basename( dirname(__FILE__) );
@@ -134,6 +142,7 @@ function plugin_uninstall()
134142
function plugin_activate()
135143
{
136144
global $conf;
145+
pwg_query( $q );
137146

138147
if ( (!isset($conf['osm_conf']))
139148
or (count($conf['osm_conf'], COUNT_RECURSIVE) != 25))

menu.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function osm_apply_menu($menu_ref_arr)
6969
$local_conf['zoom'] = 2;
7070
$local_conf['auto_center'] = 0;
7171
$local_conf['divname'] = 'mapmenu';
72+
$local_conf['paths'] = osm_get_gps($page);
7273
$height = isset($conf['osm_conf']['main_menu']['height']) ? $conf['osm_conf']['main_menu']['height'] : '200';
7374
$js = osm_get_js($conf, $local_conf, $js_data);
7475
$template->set_template_dir(dirname(__FILE__).'/template/');

osmmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
$local_conf['available_pin'] = '';
7777
$local_conf['control'] = false;
7878
$local_conf['img_popup'] = false;
79+
$local_conf['paths'] = osm_get_gps($page);
7980

8081
$js_data = osm_get_items($page);
8182
$js = osm_get_js($conf, $local_conf, $js_data);

osmmap2.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
);
9797
$local_conf['control'] = true;
9898
$local_conf['img_popup'] = true;
99+
$local_conf['paths'] = osm_get_gps($page);
99100

100101
$js_data = osm_get_items($page);
101102
$js = osm_get_js($conf, $local_conf, $js_data);

0 commit comments

Comments
 (0)