1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : GMaps |
---|
4 | Author : Grum |
---|
5 | email : grum@piwigo.org |
---|
6 | website : http://photos.grum.fr |
---|
7 | |
---|
8 | << May the Little SpaceFrog be with you ! >> |
---|
9 | ------------------------------------------------------------------------------ |
---|
10 | See main.inc.php for release information |
---|
11 | |
---|
12 | GMaps_PIP : classe to manage plugin public pages |
---|
13 | |
---|
14 | --------------------------------------------------------------------------- */ |
---|
15 | |
---|
16 | include_once('gmaps_root.class.inc.php'); |
---|
17 | |
---|
18 | class GMaps_PIP extends GMaps_root |
---|
19 | { |
---|
20 | protected $coords = array(); |
---|
21 | protected $maps = array(); |
---|
22 | protected $content = ''; |
---|
23 | protected $pictureGeolocated; |
---|
24 | |
---|
25 | public function __construct($prefixeTable, $filelocation) |
---|
26 | { |
---|
27 | parent::__construct($prefixeTable, $filelocation); |
---|
28 | $this->loadConfig(); |
---|
29 | |
---|
30 | $this->initEvents(); |
---|
31 | $this->load_lang(); |
---|
32 | |
---|
33 | $this->pictureGeolocated=false; |
---|
34 | $this->coords['lat']=0; |
---|
35 | $this->coords['lng']=0; |
---|
36 | |
---|
37 | $this->loadMaps(); |
---|
38 | } |
---|
39 | |
---|
40 | public function __destruct() |
---|
41 | { |
---|
42 | unset($section_page); |
---|
43 | parent::__destruct(); |
---|
44 | } |
---|
45 | |
---|
46 | /* |
---|
47 | load language file |
---|
48 | */ |
---|
49 | public function load_lang() |
---|
50 | { |
---|
51 | global $lang; |
---|
52 | |
---|
53 | load_language('plugin.lang', GMAPS_PATH); |
---|
54 | } |
---|
55 | |
---|
56 | /* |
---|
57 | initialize events call for the plugin |
---|
58 | */ |
---|
59 | public function initEvents() |
---|
60 | { |
---|
61 | parent::initEvents(); |
---|
62 | |
---|
63 | //add_event_handler('loc_end_page_header', array(&$this, 'loadJS')); |
---|
64 | add_event_handler('amd_jpegMD_loaded', array(&$this, 'prepareMap')); |
---|
65 | add_event_handler('loc_begin_picture', array(&$this, 'applyMap'), 55); |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | /* ------------------------------------------------------------------------- |
---|
71 | FUNCTIONS TO MANAGE GMAPS |
---|
72 | ------------------------------------------------------------------------- */ |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | /** |
---|
77 | * build the maps |
---|
78 | */ |
---|
79 | public function prepareMap($jpegMD) |
---|
80 | { |
---|
81 | global $template; |
---|
82 | |
---|
83 | if(is_null($jpegMD->getTag('magic.GPS.LatitudeNum')) or |
---|
84 | is_null($jpegMD->getTag('magic.GPS.LongitudeNum'))) return(false); |
---|
85 | |
---|
86 | $this->coords['lat']=$jpegMD->getTag('magic.GPS.LatitudeNum')->getValue(); |
---|
87 | $this->coords['lng']=$jpegMD->getTag('magic.GPS.LongitudeNum')->getValue(); |
---|
88 | |
---|
89 | $this->pictureGeolocated=true; |
---|
90 | |
---|
91 | $mapsProperties=''; |
---|
92 | foreach($this->maps as $val) |
---|
93 | { |
---|
94 | $this->content.="<div id='iGMaps".$val['id']."' style='width:".$val['width'].";height:".$val['height'].";".$val['style']."'></div>"; |
---|
95 | |
---|
96 | if($mapsProperties!='') $mapsProperties.=','; |
---|
97 | $mapsProperties.=" |
---|
98 | { |
---|
99 | id:'iGMaps".$val['id']."', |
---|
100 | zoomLevel:".$val['zoomLevel'].", |
---|
101 | displayMarker:".(($val['displayMarker']=='Y')?'true':'false').", |
---|
102 | mapTypeId:'".$val['mode']."', |
---|
103 | } |
---|
104 | "; |
---|
105 | } |
---|
106 | $this->content="<div id='iGMapContent' style='text-align:center;'>".$this->content."</div>"; |
---|
107 | |
---|
108 | $template->append('head_elements', |
---|
109 | "<script type=\"text/javascript\"> |
---|
110 | gmaps = |
---|
111 | { |
---|
112 | coords: |
---|
113 | { |
---|
114 | latitude:'".$this->coords['lat']."', |
---|
115 | longitude:'".$this->coords['lng']."', |
---|
116 | }, |
---|
117 | maps: |
---|
118 | [$mapsProperties], |
---|
119 | } |
---|
120 | </script>"); |
---|
121 | |
---|
122 | |
---|
123 | if(!isset($template->known_scripts)) $template->known_scripts=Array(); |
---|
124 | |
---|
125 | if(!array_key_exists('jquery', $template->known_scripts)) |
---|
126 | { |
---|
127 | $template->known_scripts['jquery']='themes/default/js/jquery.packed.js'; |
---|
128 | $template->block_html_head(null, '<script type="text/javascript" src="themes/default/js/jquery.packed.js"></script>', $template->smarty, $false); |
---|
129 | } |
---|
130 | |
---|
131 | $template->known_scripts['maps.google.com/api']='http://maps.google.com/maps/api/js?sensor=false'; |
---|
132 | $template->block_html_head(null, '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>', $template->smarty, $false); |
---|
133 | |
---|
134 | $template->known_scripts['gmaps.gmaps']='plugins/'.basename(dirname(__FILE__)).'/js/gmaps.js'; |
---|
135 | $template->block_html_head(null, '<script type="text/javascript" src="plugins/'.basename(dirname(__FILE__)).'/js/gmaps.js"></script>', $template->smarty, $false); |
---|
136 | |
---|
137 | |
---|
138 | //$template->append('head_elements', '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>'); |
---|
139 | //$template->append('head_elements', '<script type="text/javascript" src="plugins/'.basename(dirname(__FILE__)).'/js/gmaps.js"></script>'); |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | /** |
---|
144 | * add the maps container to the page |
---|
145 | */ |
---|
146 | public function applyMap() |
---|
147 | { |
---|
148 | global $template; |
---|
149 | |
---|
150 | if(!$this->pictureGeolocated) return(false); |
---|
151 | |
---|
152 | $metadata=$template->get_template_vars('metadata'); |
---|
153 | |
---|
154 | $metadata[]=array |
---|
155 | ( |
---|
156 | 'TITLE' => l10n('gmaps_geolocation'), |
---|
157 | 'lines' => |
---|
158 | array( |
---|
159 | '<!--rawContent-->' => $this->content |
---|
160 | ) |
---|
161 | ); |
---|
162 | $template->assign('metadata', $metadata); |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | /** |
---|
167 | * loads the maps list |
---|
168 | */ |
---|
169 | private function loadMaps() |
---|
170 | { |
---|
171 | $sql="SELECT id, width, height, zoomLevel, displayMarker, mode, style |
---|
172 | FROM ".$this->tables['maps']." |
---|
173 | ORDER BY id"; |
---|
174 | $result=pwg_query($sql); |
---|
175 | if($result) |
---|
176 | { |
---|
177 | while($row=pwg_db_fetch_assoc($result)) |
---|
178 | { |
---|
179 | $this->maps[]=$row; |
---|
180 | } |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | } //class |
---|
186 | |
---|
187 | ?> |
---|