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 | const CAT_ID_HOME = 0; |
---|
21 | const CAT_ID_TAGS = -1; |
---|
22 | |
---|
23 | protected $category=array( |
---|
24 | 'id' => 0, |
---|
25 | 'bounds' => array( |
---|
26 | 'N' => -90, |
---|
27 | 'S' => 90, |
---|
28 | 'E' => -180, |
---|
29 | 'W' => 180 |
---|
30 | ), |
---|
31 | 'icon' => array( |
---|
32 | 'style' => true, |
---|
33 | 'file' => '', |
---|
34 | 'width' => -1, |
---|
35 | 'height' => -1 |
---|
36 | ) |
---|
37 | ); |
---|
38 | protected $picture=array( |
---|
39 | 'geolocated' => false, |
---|
40 | 'forceDisplay' => false, |
---|
41 | 'coords' => array('lat' => 0, 'lng' => 0), |
---|
42 | 'content' => array( |
---|
43 | 'I' => array(), // icon display mode |
---|
44 | 'M' => array(), // meta display mode |
---|
45 | ), |
---|
46 | 'properties' => array(), |
---|
47 | 'icon' => array( |
---|
48 | 'style' => true, |
---|
49 | 'file' => '', |
---|
50 | 'width' => -1, |
---|
51 | 'height' => -1 |
---|
52 | ) |
---|
53 | ); |
---|
54 | |
---|
55 | public function __construct($prefixeTable, $filelocation) |
---|
56 | { |
---|
57 | parent::__construct($prefixeTable, $filelocation); |
---|
58 | $this->loadConfig(); |
---|
59 | $this->initEvents(); |
---|
60 | $this->load_lang(); |
---|
61 | } |
---|
62 | |
---|
63 | public function __destruct() |
---|
64 | { |
---|
65 | unset($maps); |
---|
66 | unset($picture); |
---|
67 | parent::__destruct(); |
---|
68 | } |
---|
69 | |
---|
70 | /* |
---|
71 | load language file |
---|
72 | */ |
---|
73 | public function load_lang() |
---|
74 | { |
---|
75 | global $lang; |
---|
76 | |
---|
77 | load_language('plugin.lang', GMAPS_PATH); |
---|
78 | } |
---|
79 | |
---|
80 | /* |
---|
81 | initialize events call for the plugin |
---|
82 | */ |
---|
83 | public function initEvents() |
---|
84 | { |
---|
85 | parent::initEvents(); |
---|
86 | add_event_handler('loc_begin_index', array(&$this, 'displayCategoryPageMap')); |
---|
87 | if(!isset($_GET['slideshow'])) add_event_handler('loc_begin_picture', array(&$this, 'displayPicturePageMap'), EVENT_HANDLER_PRIORITY_NEUTRAL+5); |
---|
88 | add_event_handler('amd_jpegMD_loaded', array(&$this, 'preparePictureMaps')); |
---|
89 | add_event_handler('render_category_description', array(&$this, 'categoryMarkup'), EVENT_HANDLER_PRIORITY_NEUTRAL-5, 2); |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | public function loadCSS() |
---|
94 | { |
---|
95 | //parent::loadCSS(); // -- do not call ancestor! |
---|
96 | GPCCore::addHeaderCSS('gmaps.css2', 'plugins/'.$this->getDirectory().'/'.$this->getPluginNameFiles()."2.css"); |
---|
97 | } |
---|
98 | |
---|
99 | /* ------------------------------------------------------------------------- |
---|
100 | FUNCTIONS TO MANAGE GMAPS |
---|
101 | ------------------------------------------------------------------------- */ |
---|
102 | |
---|
103 | |
---|
104 | /** |
---|
105 | * this function display maps defined as markup in the categories description |
---|
106 | * [gmaps=id:999;with:999;height:999;kmlId:999;kmlUrl:"xxx";kmlZoom:y|n;markerImg:xxx;markerVisible:y|n;allowBubble:y|n;] |
---|
107 | * |
---|
108 | * the function is called on the 'render_category_description' event |
---|
109 | * maps are displayed only for 'main_page_category_description' page |
---|
110 | * |
---|
111 | * @param String $desc : category description |
---|
112 | * @param String $param : category page (expected value: 'main_page_category_description') |
---|
113 | * @return String : the modified description |
---|
114 | */ |
---|
115 | public function categoryMarkup($desc, $param='') |
---|
116 | { |
---|
117 | global $template, $page; |
---|
118 | |
---|
119 | $mapParams=array(); |
---|
120 | if(preg_match_all('/\[gmaps=(?:id:(?P<id>\d+);|width:(?P<width>\d+);|height:(?P<height>\d+);|markerImg:(?P<markerImg>[a-z0-9\-\._]+);|kmlId:(?P<kmlId>\d+);|kmlUrl:"(?P<kmlUrl>.+)";|allowBubble:(?P<allowBubble>y|n);|kmlZoom:(?P<kmlZoom>y|n);|markerVisible:(?P<markerVisible>y|n);)+\]/i',$desc,$mapParams,PREG_SET_ORDER)>0) |
---|
121 | { |
---|
122 | if($param!='main_page_category_description') |
---|
123 | { |
---|
124 | // if not main page, just remove the [gmaps] markup |
---|
125 | $desc = preg_replace('/\[gmaps=(?:.*)\]/i','',$desc); |
---|
126 | return($desc); |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | GPCCore::addHeaderJS("jquery", "themes/default/js/jquery.js"); |
---|
131 | GPCCore::addHeaderJS("jquery.ui", "themes/default/js/ui/jquery.ui.core.js", array('jquery')); |
---|
132 | GPCCore::addHeaderJS("jquery.ui.widget", "themes/default/js/ui/jquery.ui.widget.js", array('jquery.ui')); |
---|
133 | |
---|
134 | GPCCore::addHeaderJS("maps.google.com/api", "http://maps.google.com/maps/api/js?sensor=false"); |
---|
135 | GPCCore::addHeaderJS('gmaps.infoWindow', GMAPS_PATH.'js/gmapsInfoWindow.js', array('jquery')); |
---|
136 | GPCCore::addHeaderJS("gmaps.markup", "plugins/GMaps/js/gmapsMarkup.js", array('jquery')); |
---|
137 | |
---|
138 | $desc = preg_replace( |
---|
139 | '/\[gmaps=(?:id:(?P<id>\d+);|width:(?P<width>\d+);|height:(?P<height>\d+);|markerImg:(?P<markerImg>[a-z0-9\-\._]+);|kmlId:(?P<kmlId>\d+);|kmlUrl:"(?P<kmlUrl>.+)";|allowBubble:(?P<allowBubble>y|n);|kmlZoom:(?P<kmlZoom>y|n);|markerVisible:(?P<markerVisible>y|n);)+\]/i', |
---|
140 | "<div class='gmapsMarkup' id='gmapsMarkupId$1'></div>", $desc); |
---|
141 | |
---|
142 | $scripts=array(); |
---|
143 | |
---|
144 | foreach($mapParams as $mapParam) |
---|
145 | { |
---|
146 | $nb=$this->prepareCategoryMap($page['category']['id'], $mapParam['id']); |
---|
147 | |
---|
148 | if(!isset($mapParam['allowBubble'])) $mapParam['allowBubble']='y'; |
---|
149 | if(!isset($mapParam['kmlZoom'])) $mapParam['kmlZoom']='n'; |
---|
150 | if(!isset($mapParam['width'])) $mapParam['width']=''; |
---|
151 | if(!isset($mapParam['height'])) $mapParam['height']=''; |
---|
152 | if(!isset($mapParam['markerImg']) or $mapParam['markerImg']=='') $mapParam['markerImg']='mS01_11.png'; |
---|
153 | if(!isset($mapParam['markerVisible']) or $mapParam['markerVisible']=='') $mapParam['markerVisible']='y'; |
---|
154 | if(isset($mapParam['kmlId']) and $mapParam['kmlId']!='') |
---|
155 | { |
---|
156 | $sql="SELECT file |
---|
157 | FROM ".$this->tables['kmlfiles']." |
---|
158 | WHERE id=".$mapParam['kmlId']; |
---|
159 | $result=pwg_query($sql); |
---|
160 | if($result) |
---|
161 | { |
---|
162 | while($row=pwg_db_fetch_assoc($result)) |
---|
163 | { |
---|
164 | $mapParam['kmlUrl']=get_absolute_root_url().PWG_LOCAL_DIR.self::KML_DIRECTORY.$row['file']; |
---|
165 | } |
---|
166 | } |
---|
167 | } |
---|
168 | if(!isset($mapParam['kmlUrl'])) $mapParam['kmlUrl']=''; |
---|
169 | |
---|
170 | foreach($this->maps as $map) |
---|
171 | { |
---|
172 | $scripts[]=" |
---|
173 | { |
---|
174 | id:'gmapsMarkupId".$mapParam['id']."', |
---|
175 | mapId:".$mapParam['id'].", |
---|
176 | zoomLevel:".$map['zoomLevel'].", |
---|
177 | markerImg:'".$mapParam['markerImg']."', |
---|
178 | markerVisible:".($mapParam['markerVisible']=='y'?'true':'false').", |
---|
179 | mapType:'".$map['mapType']."', |
---|
180 | mapTypeControl:'".$map['mapTypeControl']."', |
---|
181 | navigationControl:'".$map['navigationControl']."', |
---|
182 | scaleControl:'".$map['scaleControl']."', |
---|
183 | streetViewControl:'".$map['streetViewControl']."', |
---|
184 | kmlFileUrl:'".$mapParam['kmlUrl']."', |
---|
185 | displayType:'".$map['displayType']."', |
---|
186 | width:".($mapParam['width']==''?$map['width']:$mapParam['width']).", |
---|
187 | height:".($mapParam['height']==''?$map['height']:$mapParam['height']).", |
---|
188 | markers:[], |
---|
189 | fitToBounds:true, |
---|
190 | zoomLevelMaxActivated:".($map['zoomLevelMaxActivated']=='y'?'true':'false').", |
---|
191 | mapBounds: |
---|
192 | { |
---|
193 | north:".$this->category['bounds']['N'].", |
---|
194 | south:".$this->category['bounds']['S'].", |
---|
195 | east:".$this->category['bounds']['E'].", |
---|
196 | west:".$this->category['bounds']['W']." |
---|
197 | }, |
---|
198 | geolocated:".($nb>0?'true':'false').", |
---|
199 | kmlZoom:".($mapParam['kmlZoom']=='y'?'true':'false').", |
---|
200 | allowBubble:".($mapParam['allowBubble']=='y'?'true':'false')." |
---|
201 | } |
---|
202 | "; |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | $template->append('head_elements', |
---|
207 | "<script type=\"text/javascript\"> |
---|
208 | var gmapsMarkup = |
---|
209 | { |
---|
210 | categoryId:".$page['category']['id'].", |
---|
211 | maps: |
---|
212 | [".implode(',', $scripts)."] |
---|
213 | }, |
---|
214 | gmaps = |
---|
215 | { |
---|
216 | token:'".get_pwg_token()."', |
---|
217 | lang:{ |
---|
218 | boundmap:'".l10n('gmaps_i_boundmap')."', |
---|
219 | boundkml:'".l10n('gmaps_i_boundkml')."', |
---|
220 | loading:'".l10n('gmaps_loading')."', |
---|
221 | gmaps_i_show_this_picture_in:'".l10n('gmaps_i_show_this_picture_in')."' |
---|
222 | } |
---|
223 | }; |
---|
224 | </script>", false); |
---|
225 | } |
---|
226 | return($desc); |
---|
227 | } |
---|
228 | |
---|
229 | |
---|
230 | |
---|
231 | /** |
---|
232 | * this function display the map on the category page |
---|
233 | */ |
---|
234 | public function displayCategoryPageMap() |
---|
235 | { |
---|
236 | global $page, $prefixeTable, $template, $user, $conf; |
---|
237 | |
---|
238 | if($page['section']=='categories' or $page['section']=='tags') |
---|
239 | { |
---|
240 | if(isset($page['category'])) |
---|
241 | { |
---|
242 | $nb=$this->prepareCategoryMap($page['category']['id'], null); |
---|
243 | } |
---|
244 | else |
---|
245 | { |
---|
246 | $nb=$this->prepareCategoryMap(0, null); |
---|
247 | } |
---|
248 | |
---|
249 | if(count($this->maps)>0) |
---|
250 | { |
---|
251 | $scripts=array(); |
---|
252 | |
---|
253 | if($nb>0 or $this->forceDisplay>0) |
---|
254 | { |
---|
255 | /* |
---|
256 | * prepare js script for each map |
---|
257 | */ |
---|
258 | |
---|
259 | foreach($this->maps as $keyMap => $map) |
---|
260 | { |
---|
261 | if($nb>0 or |
---|
262 | $map['forceDisplay']=='y' and ($map['kmlFileUrl']!='' or $map['kmlFileId']!=0) |
---|
263 | ) |
---|
264 | { |
---|
265 | $scripts[]=" |
---|
266 | { |
---|
267 | id:'iGMapsIcon', |
---|
268 | zoomLevel:".$map['zoomLevel'].", |
---|
269 | markerImg:'".$map['marker']."', |
---|
270 | mapType:'".$map['mapType']."', |
---|
271 | mapTypeControl:'".$map['mapTypeControl']."', |
---|
272 | navigationControl:'".$map['navigationControl']."', |
---|
273 | scaleControl:'".$map['scaleControl']."', |
---|
274 | streetViewControl:'".$map['streetViewControl']."', |
---|
275 | kmlFileUrl:'".$map['kmlFileUrl']."', |
---|
276 | displayType:'".$map['displayType']."', |
---|
277 | sizeMode:'".$map['sizeMode']."', |
---|
278 | title:'".addslashes( ($map['title']=='')?l10n('gmaps_geolocation'):$map['title'] )."', |
---|
279 | markers:[], |
---|
280 | fitToBounds:true, |
---|
281 | zoomLevelMaxActivated:".($map['zoomLevelMaxActivated']=='y'?'true':'false')." |
---|
282 | }"; |
---|
283 | |
---|
284 | preg_match('/^i(\d+)x(\d+).*/i', basename($map['icon']), $result); |
---|
285 | $this->category['icon']['iconStyle']=$map['iconStyle']; |
---|
286 | $this->category['icon']['file']=$map['icon']; |
---|
287 | $this->category['icon']['width']=isset($result[1])?$result[1]:-1; |
---|
288 | $this->category['icon']['height']=isset($result[2])?$result[2]:-1; |
---|
289 | } |
---|
290 | } |
---|
291 | |
---|
292 | $template->assign('maps', $this->maps); |
---|
293 | $template->set_filename('gmapsCatMap', |
---|
294 | dirname($this->getFileLocation()).'/templates/gmaps_category.tpl'); |
---|
295 | $template->append('footer_elements', $template->parse('gmapsCatMap', true), false); |
---|
296 | |
---|
297 | if(is_array($this->category['icon'])) |
---|
298 | { |
---|
299 | $template->assign('mapIcon', $this->category['icon']); |
---|
300 | $template->set_filename('gmapsIconButton', |
---|
301 | dirname($this->getFileLocation()).'/templates/gmaps_category_iconbutton.tpl'); |
---|
302 | $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('gmapsIconButton', true), false); |
---|
303 | $template->assign('mapIcon'); |
---|
304 | } |
---|
305 | |
---|
306 | $template->append('head_elements', |
---|
307 | "<script type=\"text/javascript\"> |
---|
308 | var gmaps = |
---|
309 | { |
---|
310 | token:'".get_pwg_token()."', |
---|
311 | geolocated:".($nb>0?'true':'false').", |
---|
312 | forceDisplay:".($nb==0?'true':'false').", |
---|
313 | lang:{ |
---|
314 | boundmap:'".l10n('gmaps_i_boundmap')."', |
---|
315 | boundkml:'".l10n('gmaps_i_boundkml')."', |
---|
316 | loading:'".l10n('gmaps_loading')."', |
---|
317 | gmaps_i_show_this_picture_in:'".l10n('gmaps_i_show_this_picture_in')."' |
---|
318 | }, |
---|
319 | requestId:'', |
---|
320 | categoryId:".$this->category['id'].", |
---|
321 | bounds: |
---|
322 | { |
---|
323 | north:".$this->category['bounds']['N'].", |
---|
324 | south:".$this->category['bounds']['S'].", |
---|
325 | east:".$this->category['bounds']['E'].", |
---|
326 | west:".$this->category['bounds']['W']." |
---|
327 | }, |
---|
328 | maps: |
---|
329 | [".implode(',', $scripts)."], |
---|
330 | popupAutomaticSize:".$this->config['popupAutomaticSize']." |
---|
331 | }; |
---|
332 | </script>", false); |
---|
333 | |
---|
334 | GPCCore::addHeaderJS('gmaps.infoWindow', GMAPS_PATH.'js/gmapsInfoWindow.js', array('jquery')); |
---|
335 | GPCCore::addHeaderJS('gmaps.category', GMAPS_PATH.'js/gmapsCategory.js', array('jquery', 'gmaps.infoWindow')); |
---|
336 | } |
---|
337 | } |
---|
338 | } |
---|
339 | } |
---|
340 | |
---|
341 | |
---|
342 | /** |
---|
343 | * this function prepare data ($this->category var) for a category map |
---|
344 | * $this->maps must be initialized |
---|
345 | * |
---|
346 | * if a map id is given, datas are prepared for the given map otherwise maps |
---|
347 | * are automatically searched from the current category |
---|
348 | * |
---|
349 | * @param Integer $catId : category id |
---|
350 | * @param Integer $mapId : mapId if already know ; otherwise null |
---|
351 | * @return Integer : number |
---|
352 | */ |
---|
353 | private function prepareCategoryMap($catId, $mapId=null) |
---|
354 | { |
---|
355 | global $page, $prefixeTable, $template, $user, $conf; |
---|
356 | |
---|
357 | if($catId>0) |
---|
358 | { |
---|
359 | $this->category['id']=$catId; |
---|
360 | |
---|
361 | if($mapId!=null) |
---|
362 | { |
---|
363 | $this->buildMapList($mapId, 'C', self::ID_MODE_MAP); |
---|
364 | } |
---|
365 | else |
---|
366 | { |
---|
367 | $this->buildMapList($catId, 'C', self::ID_MODE_CATEGORY); |
---|
368 | } |
---|
369 | |
---|
370 | // check if there is picture with gps tag in the selected category |
---|
371 | $sql="SELECT paut.tagId, MAX(CAST(pait.value AS DECIMAL(20,17))) AS maxValue, MIN(CAST(pait.value AS DECIMAL(20,17))) AS minValue |
---|
372 | FROM (((".USER_CACHE_CATEGORIES_TABLE." pucc |
---|
373 | LEFT JOIN ".CATEGORIES_TABLE." pct ON pucc.cat_id = pct.id) |
---|
374 | LEFT JOIN ".IMAGE_CATEGORY_TABLE." pic ON pic.category_id = pucc.cat_id) |
---|
375 | LEFT JOIN ".$prefixeTable."amd_images_tags pait ON pait.imageId = pic.image_id) |
---|
376 | LEFT JOIN ".$prefixeTable."amd_used_tags paut ON pait.numId = paut.numId |
---|
377 | WHERE pucc.user_id = '".$user['id']."' |
---|
378 | AND (paut.tagId = 'magic.GPS.LatitudeNum' OR paut.tagId = 'magic.GPS.LongitudeNum') |
---|
379 | AND pic.image_id IS NOT NULL |
---|
380 | AND FIND_IN_SET(".$catId.", pct.uppercats)!=0 |
---|
381 | GROUP BY paut.tagId"; |
---|
382 | } |
---|
383 | elseif($catId==self::CAT_ID_TAGS and isset($page['items'])) |
---|
384 | { |
---|
385 | if(count($page['items'])==0) return(false); |
---|
386 | // 'tags' |
---|
387 | $sql="SELECT paut.tagId, MAX(CAST(pait.value AS DECIMAL(20,17))) AS maxValue, MIN(CAST(pait.value AS DECIMAL(20,17))) AS minValue |
---|
388 | FROM ".$prefixeTable."amd_images_tags pait |
---|
389 | LEFT JOIN ".$prefixeTable."amd_used_tags paut ON pait.numId = paut.numId |
---|
390 | WHERE (paut.tagId = 'magic.GPS.LatitudeNum' OR paut.tagId = 'magic.GPS.LongitudeNum') |
---|
391 | AND pait.imageId IN (".implode(',', $page['items']).") |
---|
392 | GROUP BY paut.tagId"; |
---|
393 | $this->category['id']=0; |
---|
394 | $this->buildMapList(0, 'C', self::ID_MODE_CATEGORY); |
---|
395 | } |
---|
396 | elseif($catId==self::CAT_ID_HOME) |
---|
397 | { |
---|
398 | // 'home' |
---|
399 | $this->category['id']=0; |
---|
400 | $this->buildMapList(0, 'C', self::ID_MODE_CATEGORY); |
---|
401 | // check if there is picture with gps tag in the selected category |
---|
402 | $sql="SELECT paut.tagId, MAX(CAST(pait.value AS DECIMAL(20,17))) AS maxValue, MIN(CAST(pait.value AS DECIMAL(20,17))) AS minValue |
---|
403 | FROM (((".USER_CACHE_CATEGORIES_TABLE." pucc |
---|
404 | LEFT JOIN ".CATEGORIES_TABLE." pct ON pucc.cat_id = pct.id) |
---|
405 | LEFT JOIN ".IMAGE_CATEGORY_TABLE." pic ON pic.category_id = pucc.cat_id) |
---|
406 | LEFT JOIN ".$prefixeTable."amd_images_tags pait ON pait.imageId = pic.image_id) |
---|
407 | LEFT JOIN ".$prefixeTable."amd_used_tags paut ON pait.numId = paut.numId |
---|
408 | WHERE pucc.user_id = '".$user['id']."' |
---|
409 | AND (paut.tagId = 'magic.GPS.LatitudeNum' OR paut.tagId = 'magic.GPS.LongitudeNum') |
---|
410 | AND pic.image_id IS NOT NULL |
---|
411 | GROUP BY paut.tagId"; |
---|
412 | } |
---|
413 | else |
---|
414 | { |
---|
415 | return(0); |
---|
416 | } |
---|
417 | |
---|
418 | $nb=0; |
---|
419 | if(count($this->maps)>0) |
---|
420 | { |
---|
421 | $result=pwg_query($sql); |
---|
422 | if($result) |
---|
423 | { |
---|
424 | while($row=pwg_db_fetch_assoc($result)) |
---|
425 | { |
---|
426 | switch($row['tagId']) |
---|
427 | { |
---|
428 | case 'magic.GPS.LatitudeNum': |
---|
429 | $this->category['bounds']['N']=$row['maxValue']; |
---|
430 | $this->category['bounds']['S']=$row['minValue']; |
---|
431 | break; |
---|
432 | case 'magic.GPS.LongitudeNum': |
---|
433 | $this->category['bounds']['E']=$row['maxValue']; |
---|
434 | $this->category['bounds']['W']=$row['minValue']; |
---|
435 | break; |
---|
436 | } |
---|
437 | $nb++; |
---|
438 | } |
---|
439 | } |
---|
440 | } |
---|
441 | return($nb); |
---|
442 | } |
---|
443 | |
---|
444 | |
---|
445 | /** |
---|
446 | * this function display the map on the picture page |
---|
447 | * |
---|
448 | * the 'amd_jpegMD_loaded' event is triggered before the 'loc_begin_picture' |
---|
449 | * event so, when this function is called the $this->picture var was already |
---|
450 | * initialized |
---|
451 | */ |
---|
452 | public function displayPicturePageMap() |
---|
453 | { |
---|
454 | global $page, $template; |
---|
455 | |
---|
456 | if($this->picture['geolocated']==false and $this->picture['forceDisplay']==false) return(false); |
---|
457 | if(isset($this->picture['content']['MP']) and count($this->picture['content']['MP'])>0) |
---|
458 | { |
---|
459 | // there is maps in meta display mode |
---|
460 | $template->set_filename('gmapsMeta', |
---|
461 | dirname($this->getFileLocation()).'/templates/gmaps_picture_meta.tpl'); |
---|
462 | $template->assign('maps', $this->picture['content']['MP']); |
---|
463 | |
---|
464 | $metaTitle=''; |
---|
465 | foreach($this->picture['content']['MP'] as $map) |
---|
466 | { |
---|
467 | if($metaTitle=='') $metaTitle=$map['title']; |
---|
468 | } |
---|
469 | |
---|
470 | $metadata=array |
---|
471 | ( |
---|
472 | 'TITLE' => ($metaTitle=='')?l10n('gmaps_geolocation'):$metaTitle, |
---|
473 | 'lines' => |
---|
474 | array( |
---|
475 | /* <!--rawContent--> is a trick to display raw data in tabs |
---|
476 | * for the gally template |
---|
477 | * |
---|
478 | * on the default template, the displayed content is done |
---|
479 | * normally |
---|
480 | */ |
---|
481 | '<!--rawContent-->' => $template->parse('gmapsMeta', true) |
---|
482 | ) |
---|
483 | ); |
---|
484 | $template->append('metadata', $metadata, false); |
---|
485 | } |
---|
486 | |
---|
487 | if(isset($this->picture['content']['IP']) and count($this->picture['content']['IP'])>0) |
---|
488 | { |
---|
489 | // there is maps in icon display mode |
---|
490 | $template->assign('map', $this->picture['content']['IP'][0]); |
---|
491 | $template->assign('mapIcon', $this->picture['icon']); |
---|
492 | |
---|
493 | $template->set_filename('gmapsIconMap', |
---|
494 | dirname($this->getFileLocation()).'/templates/gmaps_picture_icon.tpl'); |
---|
495 | $template->append('footer_elements', $template->parse('gmapsIconMap', true), false); |
---|
496 | |
---|
497 | $template->set_filename('gmapsIconButton', |
---|
498 | dirname($this->getFileLocation()).'/templates/gmaps_picture_iconbutton.tpl'); |
---|
499 | $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('gmapsIconButton', true), false); |
---|
500 | } |
---|
501 | |
---|
502 | if(count($this->picture['properties'])>0) |
---|
503 | { |
---|
504 | $template->append('head_elements', |
---|
505 | "<script type=\"text/javascript\"> |
---|
506 | var gmaps = |
---|
507 | { |
---|
508 | token:'".get_pwg_token()."', |
---|
509 | geolocated:".($this->picture['geolocated']?'true':'false').", |
---|
510 | forceDisplay:".($this->picture['forceDisplay']?'true':'false').", |
---|
511 | lang:{ |
---|
512 | centermap:'".l10n('gmaps_i_centermap')."', |
---|
513 | boundkml:'".l10n('gmaps_i_boundkml')."' |
---|
514 | }, |
---|
515 | coords: |
---|
516 | { |
---|
517 | latitude:'".$this->picture['coords']['lat']."', |
---|
518 | longitude:'".$this->picture['coords']['lng']."' |
---|
519 | }, |
---|
520 | maps: |
---|
521 | [".implode(',', $this->picture['properties'])."], |
---|
522 | popupAutomaticSize:".$this->config['popupAutomaticSize']." |
---|
523 | }; |
---|
524 | </script>", false); |
---|
525 | } |
---|
526 | } |
---|
527 | |
---|
528 | |
---|
529 | |
---|
530 | |
---|
531 | /** |
---|
532 | * prepare the maps for the picture page |
---|
533 | * |
---|
534 | * this function is called when the plugin AdvancedMetadata has finished to |
---|
535 | * read the metadata ; if picture is not geolocated, there is no map to display |
---|
536 | * |
---|
537 | * @param JpegMetadata $jpegMD : a JpegMetadata object |
---|
538 | */ |
---|
539 | public function preparePictureMaps($jpegMD) |
---|
540 | { |
---|
541 | global $template, $page, $user; |
---|
542 | |
---|
543 | $isGeolocated=true; |
---|
544 | |
---|
545 | if(is_null($jpegMD->getTag('magic.GPS.LatitudeNum')) or |
---|
546 | is_null($jpegMD->getTag('magic.GPS.LongitudeNum'))) $isGeolocated=false; |
---|
547 | |
---|
548 | |
---|
549 | if(isset($page['category'])) |
---|
550 | { |
---|
551 | $this->buildMapList($page['category']['id'], 'P', self::ID_MODE_CATEGORY); |
---|
552 | } |
---|
553 | else |
---|
554 | { |
---|
555 | $sql="SELECT GROUP_CONCAT(pict.category_id) |
---|
556 | FROM ".IMAGE_CATEGORY_TABLE." pict |
---|
557 | WHERE pict.image_id=".$page['image_id']; |
---|
558 | if($user['forbidden_categories']!='') $sql.=" AND pict.category_id NOT IN (".$user['forbidden_categories'].")"; |
---|
559 | |
---|
560 | $result=pwg_query($sql); |
---|
561 | if($result) |
---|
562 | { |
---|
563 | while($row=pwg_db_fetch_row($result)) |
---|
564 | { |
---|
565 | $cats=explode(',', $row[0]); |
---|
566 | } |
---|
567 | } |
---|
568 | |
---|
569 | $cats[]=0; |
---|
570 | $i=0; |
---|
571 | while(count($this->maps)==0 and $i<count($cats)) |
---|
572 | { |
---|
573 | $this->buildMapList($cats[$i], 'P', self::ID_MODE_CATEGORY); |
---|
574 | $i++; |
---|
575 | } |
---|
576 | } |
---|
577 | |
---|
578 | if($this->forceDisplay==0 and !$isGeolocated) return(false); |
---|
579 | |
---|
580 | $this->picture['geolocated']=$isGeolocated; |
---|
581 | $this->picture['forceDisplay']=!$isGeolocated; |
---|
582 | if($isGeolocated) |
---|
583 | { |
---|
584 | $this->picture['coords']['lat']=$jpegMD->getTag('magic.GPS.LatitudeNum')->getValue(); |
---|
585 | $this->picture['coords']['lng']=$jpegMD->getTag('magic.GPS.LongitudeNum')->getValue(); |
---|
586 | } |
---|
587 | |
---|
588 | |
---|
589 | foreach($this->maps as $map) |
---|
590 | { |
---|
591 | if($isGeolocated or |
---|
592 | $map['forceDisplay']=='y' and ($map['kmlFileUrl']!='' or $map['kmlFileId']!=0) |
---|
593 | ) |
---|
594 | { |
---|
595 | if($map['displayType']=='IP') |
---|
596 | { |
---|
597 | preg_match('/^i(\d+)x(\d+).*/i', basename($map['icon']), $result); |
---|
598 | $this->picture['icon']=array( |
---|
599 | 'iconStyle' => $map['iconStyle'], |
---|
600 | 'file' => $map['icon'], |
---|
601 | 'width' => isset($result[1])?$result[1]:-1, |
---|
602 | 'height' => isset($result[2])?$result[2]:-1 |
---|
603 | ); |
---|
604 | } |
---|
605 | |
---|
606 | |
---|
607 | $this->picture['content'][$map['displayType']][]=array( |
---|
608 | 'id' => $map['id'], |
---|
609 | 'width' => $map['width'], |
---|
610 | 'height' => $map['height'], |
---|
611 | 'style' => $map['style'], |
---|
612 | 'displayType' => $map['displayType'], |
---|
613 | 'title' => $map['title'], |
---|
614 | ); |
---|
615 | |
---|
616 | $this->picture['properties'][]=" |
---|
617 | { |
---|
618 | id:'iGMaps".(($map['displayType']=='IP')?'Icon':$map['id'])."', |
---|
619 | zoomLevel:".$map['zoomLevel'].", |
---|
620 | markerImg:'".$map['marker']."', |
---|
621 | mapType:'".$map['mapType']."', |
---|
622 | mapTypeControl:'".$map['mapTypeControl']."', |
---|
623 | navigationControl:'".$map['navigationControl']."', |
---|
624 | scaleControl:'".$map['scaleControl']."', |
---|
625 | streetViewControl:'".$map['streetViewControl']."', |
---|
626 | kmlFileUrl:'".$map['kmlFileUrl']."', |
---|
627 | displayType:'".$map['displayType']."', |
---|
628 | sizeMode:'".$map['sizeMode']."', |
---|
629 | title:'".addslashes( ($map['title']=='')?l10n('gmaps_geolocation'):$map['title'] )."' |
---|
630 | }"; |
---|
631 | } |
---|
632 | } |
---|
633 | } |
---|
634 | |
---|
635 | |
---|
636 | |
---|
637 | |
---|
638 | } //class |
---|
639 | |
---|
640 | ?> |
---|