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

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

Pre-Version 2.0

File size: 5.8 KB
Line 
1<?php
2/*
3Plugin Name: Psli-BingMaps
4Author: psli
5*/
6
7// Chech whether we are indeed included by Piwigo.
8if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
9
10// Get configuration
11global $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
24add_event_handler('render_category_description', 'PSLIBINGMAPS_Process_Album');
25
26/********************************************************************************************/
27// Process data when album is shown
28/********************************************************************************************/
29function 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; }</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>
69psli_g_BingKey = "'.$conf[PSLI_CONF_KEY].'";
70psli_g_zoomInitial = '.$zoom_initiale.';
71psli_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 .= '
107var 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 .= '
110function 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 .= '
118var psli_t_Child'.$entity['id'].' = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location('.$entity['lat'].','.$entity['lon'].'));'."\n";
119
120                                                $desc_function_mouse_over .= '
121function psli_MapsMouseOver_'.$entity['id'].' (e) {
122  document.getElementById("Coordonates").innerHTML = "'.l10n('Click to show pictures of')." ".$entity['title'].'";
123}'."\n";
124                                        }
125                                       
126                                        $desc_data .= '
127Microsoft.Maps.Events.addHandler(psli_t_Child'.$entity['id'].', "mouseover", psli_MapsMouseOver_'.$entity['id'].');
128Microsoft.Maps.Events.addHandler(psli_t_Child'.$entity['id'].', "mouseout", psli_MapsMouseOut);
129Microsoft.Maps.Events.addHandler(psli_t_Child'.$entity['id'].', "click", psli_MapsClick_'.$entity['id'].');'."\n";
130               
131                                        switch ($entity['action'])
132                                        {
133                                                case 1: 
134                                                        $desc_function_click .= '
135function psli_MapsClick_'.$entity['id'].' (e) {
136        psli_g_Map.setView({zoom:'.$entity['id_action'].', center: new Microsoft.Maps.Location('.$entity['lat'].', '.$entity['lon'].')});
137}'."\n";
138                                                        break;
139                                                case 2:
140                                                        $desc_function_click .= '
141function psli_MapsClick_'.$entity['id'].' (e) {
142        document.location.href=\'index.php?/category/'.$entity['id_action'].'\';
143}'."\n";
144                                                        break;
145                                                case 3:
146                                                        $desc_function_click .= '
147function psli_MapsClick_'.$entity['id'].' (e) {
148  document.location.href=\'picture.php?/'.$entity['id_action'].'\';
149}'."\n";
150                                                        break;                         
151                                        }
152                               
153                                        for ($i = $entity['zoomMin']; $i <= $entity['zoomMax']; $i++)
154                                        {
155                                                $desc_data .= 'psli_g_ZoomEntity['.($i - 1).'].push(psli_t_Child'.$entity['id'].');'."\n";
156                                        }
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.