source: extensions/piwigo-openstreetmap/osmmap.php @ 30232

Last change on this file since 30232 was 24677, checked in by ddtddt, 11 years ago

[extensions] - piwigo-openstreetmap - add file for translate

File size: 10.6 KB
Line 
1<?php
2/***********************************************
3* File      :   osmmap.php
4* Project   :   piwigo-openstreetmap
5* Descr     :   Display a world map
6*
7* Created   :   28.05.2013
8*
9* Copyright 2013 <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
26if ( !defined('PHPWG_ROOT_PATH') )
27  define('PHPWG_ROOT_PATH','../../');
28
29include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
30include_once( dirname(__FILE__) .'/include/functions.php');
31include_once( dirname(__FILE__) .'/include/functions_map.php');
32
33$osm_dir = "piwigo-openstreetmap";
34
35check_status(ACCESS_GUEST);
36//if (!isset($osm_dir))
37//  access_denied( 'Plugin not installed' );
38
39osm_load_language();
40load_language('plugin.lang', OSM_PATH);
41
42$section = '';
43if ( $conf['question_mark_in_urls']==false and isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) )
44{
45        $section = $_SERVER["PATH_INFO"];
46        $section = str_replace('//', '/', $section);
47        $path_count = count( explode('/', $section) );
48        $page['root_path'] = PHPWG_ROOT_PATH.str_repeat('../', $path_count-1);
49        if ( strncmp($page['root_path'], './', 2) == 0 )
50        {
51                $page['root_path'] = substr($page['root_path'], 2);
52        }
53}
54else
55{
56        foreach ($_GET as $key=>$value)
57        {
58                if (!strlen($value)) $section=$key;
59                break;
60        }
61}
62
63// deleting first "/" if displayed
64$tokens = explode('/', preg_replace('#^/#', '', $section));
65$next_token = 0;
66$result = osm_parse_map_data_url($tokens, $next_token);
67$page = array_merge( $page, $result );
68
69if (isset($page['category']))
70        check_restrictions($page['category']['id']);
71
72// Fetch data with lat and lon
73
74$forbidden = get_sql_condition_FandF(
75        array
76        (
77                'forbidden_categories' => 'category_id',
78                'visible_categories' => 'category_id',
79                'visible_images' => 'id'
80        ),
81        "\n AND"
82);
83
84//$query="SELECT `lat`, `lon`, `name`, `path` FROM ".IMAGES_TABLE." WHERE `lat` IS NOT NULL AND `lon` IS NOT NULL;";
85// SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', 1) full path without filename extension
86// SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', -1) full path with only filename extension
87
88$query="SELECT `lat`, `lon`, `name`,
89IF(`representative_ext` IS NULL,
90        CONCAT(SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', 1 ), '-sq.', SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', -1 )),
91        TRIM(LEADING '.' FROM
92                REPLACE(`path`, `file`,
93                                CONCAT('pwg_representative/',
94                                        CONCAT(
95                                                TRIM(TRAILING '.' FROM SUBSTRING_INDEX(`file`, '.', 1 )),
96                                                CONCAT('-sq.', `representative_ext`)
97                                        )
98                                )
99                        )
100                )
101) AS pathurl,
102TRIM(TRAILING '/' FROM CONCAT( `id`, '/category/', IFNULL(`storage_category_id`, '') ) ) as imgurl,
103IFNULL(`comment`, '') AS `comment`,
104IFNULL(`author`, '') AS `author`,
105`width`
106        FROM ".IMAGES_TABLE." AS i
107            INNER JOIN ".IMAGE_CATEGORY_TABLE." AS ic ON id = ic.image_id
108            WHERE `lat` IS NOT NULL AND `lon` IS NOT NULL ".$forbidden." group by `name`;";
109//echo $query;
110$php_data = array_from_query($query);
111//print_r($php_data);
112$js_data = array();
113foreach($php_data as $array)
114{
115        // MySQL did all the job
116        //print_r($array);
117        $js_data[] = array((double)$array['lat'],
118                           (double)$array['lon'],
119                           $array['name'],
120                           $array['pathurl'],
121                           $array['imgurl'],
122                           $array['comment'],
123                           $array['author'],
124                           (int)$array['width']
125                           );
126}
127
128// Load parameter, fallback to default if unset
129$linkname = isset($conf['osm_conf']['left_menu']['link']) ? $conf['osm_conf']['left_menu']['link'] : 'OS World Map';
130$popup = isset($conf['osm_conf']['left_menu']['popup']) ? $conf['osm_conf']['left_menu']['popup'] : 0;
131$popupinfo_name = isset($conf['osm_conf']['left_menu']['popupinfo_name']) ? $conf['osm_conf']['left_menu']['popupinfo_name'] : 0;
132$popupinfo_img = isset($conf['osm_conf']['left_menu']['popupinfo_img']) ? $conf['osm_conf']['left_menu']['popupinfo_img'] : 0;
133$popupinfo_link = isset($conf['osm_conf']['left_menu']['popupinfo_link']) ? $conf['osm_conf']['left_menu']['popupinfo_link'] : 0;
134$popupinfo_comment = isset($conf['osm_conf']['left_menu']['popupinfo_comment']) ? $conf['osm_conf']['left_menu']['popupinfo_comment'] : 0;
135$popupinfo_author  = isset($conf['osm_conf']['left_menu']['popupinfo_author']) ? $conf['osm_conf']['left_menu']['popupinfo_author'] : 0;
136$baselayer = isset($conf['osm_conf']['map']['baselayer']) ? $conf['osm_conf']['map']['baselayer'] : 'mapnik';
137$custombaselayer = isset($conf['osm_conf']['map']['custombaselayer']) ? $conf['osm_conf']['map']['custombaselayer'] : '';
138$custombaselayerurl = isset($conf['osm_conf']['map']['custombaselayerurl']) ? $conf['osm_conf']['map']['custombaselayerurl'] : '';
139$noworldwarp = isset($conf['osm_conf']['map']['noworldwarp']) ? $conf['osm_conf']['map']['noworldwarp'] : 'false';
140$attrleaflet = isset($conf['osm_conf']['map']['attrleaflet']) ? $conf['osm_conf']['map']['attrleaflet'] : 'false';
141$attrimagery = isset($conf['osm_conf']['map']['attrimagery']) ? $conf['osm_conf']['map']['attrimagery'] : 'false';
142$attrmodule = isset($conf['osm_conf']['map']['attrplugin']) ? $conf['osm_conf']['map']['attrplugin'] : 'false';
143
144$OSMCOPYRIGHT='Map data &copy; <a href="http://www.openstreetmap.org" target="_blank">OpenStreetMap</a> (<a href="http://www.openstreetmap.org/copyright" target="_blank">ODbL</a>)';
145
146// Load baselayerURL
147// Key1 BC9A493B41014CAABB98F0471D759707
148if     ($baselayer == 'mapnik')         $baselayerurl = 'http://tile.openstreetmap.org/{z}/{x}/{y}.png';
149else if($baselayer == 'mapquest')       $baselayerurl = 'http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png';
150else if($baselayer == 'cloudmade')      $baselayerurl = 'http://{s}.tile.cloudmade.com/7807cc60c1354628aab5156cfc1d4b3b/997/256/{z}/{x}/{y}.png';
151else if($baselayer == 'mapnikde')       $baselayerurl = 'http://www.toolserver.org/tiles/germany/{z}/{x}/{y}.png';
152else if($baselayer == 'mapnikfr')       $baselayerurl = 'http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png';
153else if($baselayer == 'custom')         $baselayerurl = $custombaselayerurl;
154
155// Generate Javascript
156// ----------------------------------------
157// no worldWarp (no world copies, restrict the view to one world)
158if($noworldwarp)
159{
160        $nowarp = "noWrap: true, ";
161        $worldcopyjump = "worldCopyJump: false, maxBounds: [ [82, -180], [-82, 180] ]";
162}
163else
164{
165        $nowarp = "noWrap: false, ";
166        $worldcopyjump = "worldCopyJump: true";
167}
168
169//$js = "\nvar addressPoints = ". json_encode($js_data, JSON_UNESCAPED_SLASHES) .";\n";
170$js = "\nvar addressPoints = ". str_replace("\/","/",json_encode($js_data)) .";\n";
171
172/*
173// Icons
174$js .= "
175var LeafIcon = L.Icon.extend({
176        options: {
177                shadowUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-shadow.png',
178                iconSize:     [38, 95],
179                shadowSize:   [50, 64],
180                iconAnchor:   [22, 94],
181                shadowAnchor: [4, 62],
182                popupAnchor:  [-3, -76]
183        }
184});
185
186var mapIcon = L.Icon.extend({
187        options: {
188                shadowUrl: 'plugins/piwigo-openstreetmap/leaflet/images/mapicons-shadow.png',
189                iconSize:     [32, 37],
190                shadowSize:   [51, 37],
191                iconAnchor:   [19, 38],
192                shadowAnchor: [-20, 33],
193                popupAnchor:  [-2, -10]
194        }
195});
196
197var greenIcon = new LeafIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-green.png'}),
198        redIcon = new LeafIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-red.png'}),
199        orangeIcon = new LeafIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-orange.png'});
200
201var bluemapicons = new mapIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/mapicons-blue.png'}),
202        greenmapicons = new mapIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/mapicons-green.png'});
203";
204*/
205
206// Create the map and get a new map instance attached and element with id="tile-map"
207$js .= "\nvar Url = '".$baselayerurl."',
208        Attribution = '".$OSMCOPYRIGHT."',
209        TileLayer = new L.TileLayer(Url, {maxZoom: 18, attribution: Attribution}),
210        latlng = new L.LatLng(0, 0);\n";
211$js .= "var map = new L.Map('map', {center: latlng, zoom: 2, layers: [TileLayer]});\n";
212$js .= "map.attributionControl.setPrefix('');\n";
213$js .= "var markers = new L.MarkerClusterGroup();\n";
214$js .= "for (var i = 0; i < addressPoints.length; i++) {
215        var a = addressPoints[i];
216        var title = a[2];
217        var pathurl = '". get_absolute_root_url() ."i.php?'+a[3];
218        var imgurl = '". get_absolute_root_url() ."picture.php?/'+a[4];
219        var comment = a[5];
220        var author = a[6];
221        var width = a[7];
222        var latlng = new L.LatLng(a[0], a[1]);
223        var marker = new L.Marker(latlng, { title: title });
224        ";
225
226// create Popup
227if ($popup < 2)
228{
229        $openpopup = ".openPopup()";
230        $myinfo = "'<p>";
231        if($popupinfo_name)
232        {
233                $myinfo .= "'+title+'";
234        }
235        if($popupinfo_img and !$popupinfo_link)
236        {
237                $myinfo .= "<br /><img src=\"'+pathurl+'\">";
238        }
239        else if($popupinfo_img and $popupinfo_link)
240        {
241                $myinfo .= "<br /><a href=\"'+imgurl+'\"><img src=\"'+pathurl+'\"></a>";
242        }
243        if($popupinfo_comment)
244        {
245                $myinfo .= "<br />'+comment+'";
246        }
247        if($popupinfo_author)
248        {
249                $myinfo .= "<br />'+author+'";
250        }
251        $myinfo .= "</p>'";
252        $js .= "marker.bindPopup(".$myinfo.", {minWidth: '+width+'}).openPopup();";
253}
254
255$js .= "\n      markers.addLayer(marker);
256}";
257$js .= "\nmap.addLayer(markers);\n";
258
259// Attribution Credit and Copyright
260if($attrleaflet){ $js .= "map.attributionControl.addAttribution('".l10n('POWERBY')." <a href=\"http://leafletjs.com/\" target=\"_blank\">Leaflet</a>');\n"; }
261if($attrimagery){ $js .= "map.attributionControl.addAttribution('".l10n('IMAGERYBY')." ". imagery($baselayer, $custombaselayer)."');\n"; }
262if($attrmodule){ $js .= "map.attributionControl.addAttribution('".l10n('PLUGINBY')." <a href=\"https://github.com/xbgmsharp/piwigo-openstreetmap\" target=\"_blank\">xbgmsharp</a>');\n"; }
263
264$template->set_filename('map', dirname(__FILE__).'/template/osm-map.tpl' );
265
266$template->assign($conf['osm_conf']);
267$template->assign(
268        array(
269                'CONTENT_ENCODING'      => get_pwg_charset(),
270                'OSM_PATH'              => OSM_PATH,
271                'PLUGIN_ROOT_URL'       => get_absolute_root_url().'plugins/'.$osm_dir,
272                'PLUGIN_LOCATION'       => 'plugins/'.$osm_dir,
273                'GALLERY_TITLE'         => $linkname .' - '. $conf['gallery_title'],
274                'HOME'                  => make_index_url(),
275                'HOME_PREV'             => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : get_absolute_root_url(),
276                'HOME_NAME'             => l10n("Home"),
277                'HOME_PREV_NAME'        => l10n("Previous"),
278                'TOTAL'                 => sprintf( l10n('%d photos'), count($php_data) ),
279                'OSMJS'                 => $js,
280        )
281);
282
283$template->pparse('map');
284$template->p();
285?>
Note: See TracBrowser for help on using the repository browser.