forked from Piwigo/piwigo-openstreetmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
picture.inc.php
162 lines (145 loc) · 5.62 KB
/
picture.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/***********************************************
* File : picture.inc.php
* Project : piwigo-openstreetmap
* Descr : Display map on right panel
*
* Created : 28.05.2013
*
* Copyright 2013-2016 <[email protected]>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
************************************************/
include_once( dirname(__FILE__) .'/include/functions_map.php');
// Do we have to show the right panel
if ($conf['osm_conf']['right_panel']['enabled'])
{
// Hook to add the div in the right menu, No idea about the number!!
add_event_handler('loc_begin_picture', 'osm_loc_begin_picture', 56);
// Hook to populate the div in the right menu, No idea about the number after!!
add_event_handler('loc_begin_picture', 'osm_render_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL+1 /*in order to have picture content*/, 2);
}
function osm_loc_begin_picture()
{
global $template;
$template->set_prefilter('picture', 'osm_insert_map');
}
function osm_insert_map($content)
{
global $conf;
load_language('plugin.lang', OSM_PATH);
/* Would be better if it could be like the Metdata but how?
$search = '#<dl id="Metadata" class="imageInfoTable">#';
$replacement = '
<dl id="map-info" class="imageInfoTable">
<h3>{\'LOCATION\'|@translate}</h3>
<div class="imageInfo">
<div id="map"></div>
</div>
</dl>
<dl id="Metadata" class="imageInfoTable">';
*/
$search = '#<div id="'. $conf['osm_conf']['right_panel']['add_before'] .'" class="imageInfo">#';
$replacement = '
{if $OSMJS}
<div id="map-info" class="imageInfo">
<dt {$OSMNAMECSS}>{$OSMNAME}</dt>
<dd>
<div id="map"></div>
<script type="text/javascript">{$OSMJS}</script>
<div id="osm_attrib" style="visibility: hidden; display: none;">
<ul>
<li>{"PLUGIN_BY"|@translate}</li>
<li><a href="http://leafletjs.com/" target="_blank">Leaflet</a></li>
<li>© {"OSM_CONTRIBUTORS"|@translate}</li>
</ul>
</div>
{if $SHOWOSM}
<a href="{$OSMLINK}" target="_blank">{"VIEW_OSM"|@translate}</a>
{/if}
{if $SHOWLATLON}
<br><span class="h-geo">{$OSMNAME} : <span class="p-latitude">{$LAT}</span>, <span class="p-longitude">{$LON}</span>
</span>
{/if}
</dd>
</div>
{/if}
<div id="'. $conf['osm_conf']['right_panel']['add_before'] .'" class="imageInfo">';
return preg_replace($search, $replacement, $content);
}
function osm_render_element_content()
{
global $template, $picture, $page, $conf;
load_language('plugin.lang', OSM_PATH);
if (empty($page['image_id']))
{
return;
}
// Load coordinates from picture
$query = 'SELECT latitude,longitude FROM '.IMAGES_TABLE.' WHERE id = \''.$page['image_id'].'\' ;';
//FIXME LIMIT 1 ?
$result = pwg_query($query);
$row = pwg_db_fetch_assoc($result);
if (!$row or !$row['latitude'] or empty($row['latitude']))
{
return;
}
$lat = $row['latitude'];
$lon = $row['longitude'];
// Load parameter, fallback to default if unset
$height = isset($conf['osm_conf']['right_panel']['height']) ? $conf['osm_conf']['right_panel']['height'] : '200';
$zoom = isset($conf['osm_conf']['right_panel']['zoom']) ? $conf['osm_conf']['right_panel']['zoom'] : '12';
$osmname = isset($conf['osm_conf']['right_panel']['link']) ? $conf['osm_conf']['right_panel']['link'] : 'Location';
$osmnamecss = isset($conf['osm_conf']['right_panel']['linkcss']) ? $conf['osm_conf']['right_panel']['linkcss'] : '';
$showosm = isset($conf['osm_conf']['right_panel']['showosm']) ? $conf['osm_conf']['right_panel']['showosm'] : 'true';
$showlatlon = isset($conf['osm_conf']['right_panel']['showlatlon']) ? $conf['osm_conf']['right_panel']['showlatlon'] : 'true';
if (strlen($osmnamecss) != 0)
{
$osmnamecss = "style='".$osmnamecss."'";
}
$osmlink="https://openstreetmap.org/?mlat=".$lat."&mlon=".$lon."&zoom=12&layers=M";
$local_conf = array();
$local_conf['contextmenu'] = 'false';
$local_conf['control'] = false;
$local_conf['img_popup'] = false;
$local_conf['popup'] = 2;
$local_conf['center_lat'] = $lat;
$local_conf['center_lng'] = $lon;
$local_conf['zoom'] = $zoom;
$js_data = osm_get_items($page);
$js = osm_get_js($conf, $local_conf, $js_data);
// Select the template
$template->set_filenames(
array('osm_content' => dirname(__FILE__)."/template/osm-picture.tpl")
);
// Assign the template variables
$template->assign(
array(
'HEIGHT' => $height,
'OSMJS' => $js,
'OSM_PATH' => embellish_url(get_gallery_home_url().OSM_PATH),
'OSMNAME' => $osmname,
'OSMNAMECSS' => $osmnamecss,
'SHOWOSM' => $showosm,
'OSMLINK' => $osmlink,
'SHOWLATLON' => $showlatlon,
'LAT' => $lat,
'LON' => $lon,
)
);
// Return the rendered html
$osm_content = $template->parse('osm_content', true);
return $osm_content;
}