source: extensions/Psli_BingMaps/include/guest.inc.php @ 14891

Last change on this file since 14891 was 14891, checked in by psli, 12 years ago

Version 1.2 : Mise a jour de la page Admin pour simplifier le paramétrage

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