1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Psli-BingMaps |
---|
4 | Author: psli |
---|
5 | */ |
---|
6 | |
---|
7 | // Chech whether we are indeed included by Piwigo. |
---|
8 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
9 | |
---|
10 | // Get configuration |
---|
11 | global $conf; |
---|
12 | $query = ' |
---|
13 | SELECT value |
---|
14 | FROM '.CONFIG_TABLE.' |
---|
15 | WHERE param = "'.PSLI_CONF_KEY.'";'; |
---|
16 | $result = pwg_query($query); |
---|
17 | $row = pwg_db_fetch_assoc($result); |
---|
18 | $conf[PSLI_CONF_KEY] = $row['value']; |
---|
19 | |
---|
20 | $conf['psli_already_done'] = false; |
---|
21 | |
---|
22 | |
---|
23 | // Hook to category description event |
---|
24 | add_event_handler('render_category_description', 'PSLIBINGMAPS_Process_Album'); |
---|
25 | |
---|
26 | /********************************************************************************************/ |
---|
27 | // Process data when album is shown |
---|
28 | /********************************************************************************************/ |
---|
29 | function PSLIBINGMAPS_Process_Album($desc) { |
---|
30 | global $conf, $page; |
---|
31 | |
---|
32 | // ie6 ? end here |
---|
33 | if (! (strpos($_SERVER['HTTP_USER_AGENT'],"MSIE 6.0") === FALSE)) |
---|
34 | return $desc; |
---|
35 | |
---|
36 | if (isset($page['category']['id'])) |
---|
37 | { |
---|
38 | $query = ' |
---|
39 | SELECT id, lat, lon, zoom |
---|
40 | FROM '.PSLI_MAPS_TABLE.' |
---|
41 | WHERE id_category = '.$page['category']['id'].';'; |
---|
42 | $result = pwg_query($query); |
---|
43 | } |
---|
44 | |
---|
45 | // First test album to control availabilty of the map |
---|
46 | if ((isset($page['category']['id'])) and (pwg_db_num_rows($result) > 0) and ($conf['psli_already_done'] == false)) |
---|
47 | { |
---|
48 | // Set data for this map |
---|
49 | $row = pwg_db_fetch_assoc($result); |
---|
50 | $lon_initiale = $row['lon']; |
---|
51 | $zoom_initiale = $row['zoom']; |
---|
52 | $lat_initiale = $row['lat']; |
---|
53 | $id_initiale = $row['id']; |
---|
54 | |
---|
55 | // Language data |
---|
56 | load_language('plugin.lang', PSLI_BINGMAPS_TEMPLATE_PATH); |
---|
57 | |
---|
58 | $conf['psli_already_done'] = true; |
---|
59 | $desc .= "\n".' |
---|
60 | <!-- PSLI Bing Maps Start --> |
---|
61 | <style type="text/css">.thumbnailCategories { display:none; } .thumbnails { display:none; } </style> |
---|
62 | <div id=\'Coordonates\' style="color: #ffff80; font-size:120%; font-weight:bold; position:relative; margin-top:30px; width:100%; height:30px;"> |
---|
63 | </div> |
---|
64 | <div id=\'myMap\' style="position:relative; text-align:center; height:600px; margin-bottom:15px; margin-right:15px; margin-left:15px; border:2px solid white"> |
---|
65 | </div> |
---|
66 | <script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script> |
---|
67 | <script charset="UTF-8" type="text/javascript" src="'.PSLI_BINGMAPS_JS.'"></script> |
---|
68 | <script> |
---|
69 | psli_g_BingKey = "'.$conf[PSLI_CONF_KEY].'"; |
---|
70 | psli_g_zoomInitial = '.$zoom_initiale.'; |
---|
71 | psli_g_MapCenter = new Microsoft.Maps.Location('.$lat_initiale.', '.$lon_initiale.')'."\n"; |
---|
72 | |
---|
73 | |
---|
74 | $query_entities = ' |
---|
75 | SELECT e.id id, lat, lon, zoomMin, zoomMax, action, id_action, title, type |
---|
76 | FROM '.PSLI_ENTITIES_TABLE.' e left join '.PSLI_ENTITIES_MAPS_TABLE.' j ON e.id = j.id_entity |
---|
77 | WHERE j.id_map = '.$id_initiale.';'; |
---|
78 | $result_entities = pwg_query($query_entities); |
---|
79 | |
---|
80 | // Is there any entities ? |
---|
81 | if (pwg_db_num_rows($result_entities) > 0) |
---|
82 | { |
---|
83 | $desc_data = ""; |
---|
84 | $desc_function_mouse_over = ""; |
---|
85 | $desc_function_click = ""; |
---|
86 | |
---|
87 | // For each sub category |
---|
88 | while ($entity = pwg_db_fetch_assoc($result_entities)) |
---|
89 | { |
---|
90 | if ($entity['id_action'] != 0) |
---|
91 | { |
---|
92 | if ($entity['type'] == 2) |
---|
93 | { |
---|
94 | $query_datapoint = ' |
---|
95 | SELECT lat, lon |
---|
96 | FROM '.PSLI_DATAPOINT_TABLE.' |
---|
97 | WHERE id_entity = '.$entity['id'].' ORDER BY id;'; |
---|
98 | $result_datapoint = pwg_query($query_datapoint); |
---|
99 | if (pwg_db_num_rows($result_datapoint) > 0) |
---|
100 | { |
---|
101 | $desc_data .= 'var psli_t_Vertices'.$entity['id'].' = new Array();'."\n"; |
---|
102 | while ($row = pwg_db_fetch_assoc($result_datapoint)) |
---|
103 | { |
---|
104 | $desc_data .= 'psli_t_Vertices'.$entity['id'].'.push(new Microsoft.Maps.Location('.$row['lat'].','.$row['lon'].'));'."\n"; |
---|
105 | } |
---|
106 | $desc_data .= ' |
---|
107 | var psli_t_Child'.$entity['id'].' = new Microsoft.Maps.Polygon(psli_t_Vertices'.$entity['id'].',{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor});'."\n"; |
---|
108 | |
---|
109 | $desc_function_mouse_over .= ' |
---|
110 | function psli_MapsMouseOver_'.$entity['id'].' (e) { |
---|
111 | document.getElementById("Coordonates").innerHTML = "'.l10n('Click to zoom on')." ".$entity['title'].'"; |
---|
112 | }'."\n"; |
---|
113 | } |
---|
114 | } |
---|
115 | else |
---|
116 | { |
---|
117 | $desc_data .= ' |
---|
118 | var psli_t_Child'.$entity['id'].' = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location('.$entity['lat'].','.$entity['lon'].'));'."\n"; |
---|
119 | if ($entity['type'] == 1) |
---|
120 | { |
---|
121 | $desc_function_mouse_over .= ' |
---|
122 | function psli_MapsMouseOver_'.$entity['id'].' (e) { |
---|
123 | document.getElementById("Coordonates").innerHTML = "'.l10n('Click to show pictures of')." ".$entity['title'].'"; |
---|
124 | }'."\n"; |
---|
125 | } |
---|
126 | else |
---|
127 | { |
---|
128 | $desc_function_mouse_over .= ' |
---|
129 | function psli_MapsMouseOver_'.$entity['id'].' (e) { |
---|
130 | document.getElementById("Coordonates").innerHTML = "'.l10n('Click to show picture')." ".$entity['title'].'"; |
---|
131 | }'."\n"; |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | $desc_data .= ' |
---|
136 | Microsoft.Maps.Events.addHandler(psli_t_Child'.$entity['id'].', "mouseover", psli_MapsMouseOver_'.$entity['id'].'); |
---|
137 | Microsoft.Maps.Events.addHandler(psli_t_Child'.$entity['id'].', "mouseout", psli_MapsMouseOut); |
---|
138 | Microsoft.Maps.Events.addHandler(psli_t_Child'.$entity['id'].', "click", psli_MapsClick_'.$entity['id'].');'."\n"; |
---|
139 | |
---|
140 | switch ($entity['action']) |
---|
141 | { |
---|
142 | case 1: |
---|
143 | $desc_function_click .= ' |
---|
144 | function psli_MapsClick_'.$entity['id'].' (e) { |
---|
145 | psli_g_Map.setView({zoom:'.$entity['id_action'].', center: new Microsoft.Maps.Location('.$entity['lat'].', '.$entity['lon'].')}); |
---|
146 | }'."\n"; |
---|
147 | break; |
---|
148 | case 2: |
---|
149 | $desc_function_click .= ' |
---|
150 | function psli_MapsClick_'.$entity['id'].' (e) { |
---|
151 | document.location.href=\'index.php?/category/'.$entity['id_action'].'\'; |
---|
152 | }'."\n"; |
---|
153 | break; |
---|
154 | case 3: |
---|
155 | $desc_function_click .= ' |
---|
156 | function psli_MapsClick_'.$entity['id'].' (e) { |
---|
157 | document.location.href=\'picture.php?/'.$entity['id_action'].'\'; |
---|
158 | }'."\n"; |
---|
159 | break; |
---|
160 | } |
---|
161 | |
---|
162 | for ($i = $entity['zoomMin']; $i <= $entity['zoomMax']; $i++) |
---|
163 | { |
---|
164 | $desc_data .= 'psli_g_ZoomEntity['.($i - 1).'].push(psli_t_Child'.$entity['id'].');'."\n"; |
---|
165 | } |
---|
166 | } |
---|
167 | } |
---|
168 | $desc .= $desc_data; |
---|
169 | $desc .= $desc_function_mouse_over; |
---|
170 | $desc .= $desc_function_click; |
---|
171 | } |
---|
172 | $desc .= ' |
---|
173 | psli_InitGuestMap(); |
---|
174 | </script>'."\n"; |
---|
175 | } |
---|
176 | return $desc; |
---|
177 | } |
---|
178 | ?> |
---|