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