> ------------------------------------------------------------------------------ See main.inc.php for release information GMaps_PIP : classe to manage plugin public pages --------------------------------------------------------------------------- */ include_once('gmaps_root.class.inc.php'); class GMaps_PIP extends GMaps_root { protected $category=array( 'id' => 0, 'bounds' => array( 'N' => -90, 'S' => 90, 'E' => -180, 'W' => 180 ), 'icon' => array( 'style' => true, 'file' => '', 'width' => -1, 'height' => -1 ) ); protected $picture=array( 'geolocated' => false, 'forceDisplay' => false, 'coords' => array('lat' => 0, 'lng' => 0), 'content' => array( 'I' => array(), // icon display mode 'M' => array(), // meta display mode ), 'properties' => array(), 'icon' => array( 'style' => true, 'file' => '', 'width' => -1, 'height' => -1 ) ); protected $css2; public function __construct($prefixeTable, $filelocation) { parent::__construct($prefixeTable, $filelocation); $this->css2 = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles()."2.css"); $this->loadConfig(); $this->initEvents(); $this->load_lang(); } public function __destruct() { unset($maps); unset($picture); parent::__destruct(); } /* load language file */ public function load_lang() { global $lang; load_language('plugin.lang', GMAPS_PATH); } /* initialize events call for the plugin */ public function initEvents() { parent::initEvents(); add_event_handler('loc_begin_index', array(&$this, 'displayCategoryPageMap')); add_event_handler('loc_begin_picture', array(&$this, 'displayPicturePageMap'), 55); add_event_handler('amd_jpegMD_loaded', array(&$this, 'preparePictureMaps')); add_event_handler('loc_end_page_header', array(&$this->css2, 'applyCSS')); } /* ------------------------------------------------------------------------- FUNCTIONS TO MANAGE GMAPS ------------------------------------------------------------------------- */ /** * this function display the map on the category page */ public function displayCategoryPageMap() { global $page, $prefixeTable, $template, $user, $conf; if($page['section']=='categories' or $page['section']=='tags') { if(isset($page['category'])) { $this->category['id']=$page['category']['id']; $this->buildMapList($page['category']['id'], 'C'); // check if there is picture with gps tag in the selected category $sql="SELECT paut.tagId, MAX(CAST(pait.value AS DECIMAL(20,17))) AS maxValue, MIN(CAST(pait.value AS DECIMAL(20,17))) AS minValue FROM (((".USER_CACHE_CATEGORIES_TABLE." pucc LEFT JOIN ".CATEGORIES_TABLE." pct ON pucc.cat_id = pct.id) LEFT JOIN ".IMAGE_CATEGORY_TABLE." pic ON pic.category_id = pucc.cat_id) LEFT JOIN ".$prefixeTable."amd_images_tags pait ON pait.imageId = pic.image_id) LEFT JOIN ".$prefixeTable."amd_used_tags paut ON pait.numId = paut.numId WHERE pucc.user_id = '".$user['id']."' AND (paut.tagId = 'magic.GPS.LatitudeNum' OR paut.tagId = 'magic.GPS.LongitudeNum') AND pic.image_id IS NOT NULL AND FIND_IN_SET(".$page['category']['id'].", pct.uppercats)!=0 GROUP BY paut.tagId"; } elseif(isset($page['items'])) { if(count($page['items'])==0) return(false); // 'tags' $sql="SELECT paut.tagId, MAX(CAST(pait.value AS DECIMAL(20,17))) AS maxValue, MIN(CAST(pait.value AS DECIMAL(20,17))) AS minValue FROM ".$prefixeTable."amd_images_tags pait LEFT JOIN ".$prefixeTable."amd_used_tags paut ON pait.numId = paut.numId WHERE (paut.tagId = 'magic.GPS.LatitudeNum' OR paut.tagId = 'magic.GPS.LongitudeNum') AND pait.imageId IN (".implode(',', $page['items']).") GROUP BY paut.tagId"; $this->category['id']=0; $this->buildMapList(0, 'C'); } else { // 'home' $this->category['id']=0; $this->buildMapList(0, 'C'); // check if there is picture with gps tag in the selected category $sql="SELECT paut.tagId, MAX(CAST(pait.value AS DECIMAL(20,17))) AS maxValue, MIN(CAST(pait.value AS DECIMAL(20,17))) AS minValue FROM (((".USER_CACHE_CATEGORIES_TABLE." pucc LEFT JOIN ".CATEGORIES_TABLE." pct ON pucc.cat_id = pct.id) LEFT JOIN ".IMAGE_CATEGORY_TABLE." pic ON pic.category_id = pucc.cat_id) LEFT JOIN ".$prefixeTable."amd_images_tags pait ON pait.imageId = pic.image_id) LEFT JOIN ".$prefixeTable."amd_used_tags paut ON pait.numId = paut.numId WHERE pucc.user_id = '".$user['id']."' AND (paut.tagId = 'magic.GPS.LatitudeNum' OR paut.tagId = 'magic.GPS.LongitudeNum') AND pic.image_id IS NOT NULL GROUP BY paut.tagId"; } if(count($this->maps)>0) { $scripts=array(); $result=pwg_query($sql); if($result) { $nb=0; while($row=pwg_db_fetch_assoc($result)) { switch($row['tagId']) { case 'magic.GPS.LatitudeNum': $this->category['bounds']['N']=$row['maxValue']; $this->category['bounds']['S']=$row['minValue']; break; case 'magic.GPS.LongitudeNum': $this->category['bounds']['E']=$row['maxValue']; $this->category['bounds']['W']=$row['minValue']; break; } $nb++; } if($nb>0 or $this->forceDisplay>0) { /* * prepare js script for each map */ foreach($this->maps as $keyMap => $map) { if($nb>0 or $map['forceDisplay']=='y' and ($map['kmlFileUrl']!='' or $map['kmlFileId']!=0) ) { $scripts[]=" { id:'iGMapsIcon', zoomLevel:".$map['zoomLevel'].", markerImg:'".$map['marker']."', mapType:'".$map['mapType']."', mapTypeControl:'".$map['mapTypeControl']."', navigationControl:'".$map['navigationControl']."', scaleControl:'".$map['scaleControl']."', streetViewControl:'".$map['streetViewControl']."', kmlFileUrl:'".$map['kmlFileUrl']."', displayType:'".$map['displayType']."', sizeMode:'".$map['sizeMode']."', title:'".addslashes( ($map['title']=='')?l10n('gmaps_geolocation'):$map['title'] )."', markers:[], fitToBounds:true, zoomLevelMaxActivated:".($map['zoomLevelMaxActivated']=='y'?'true':'false')." }"; preg_match('/^i(\d+)x(\d+).*/i', basename($map['icon']), $result); $this->category['icon']['iconStyle']=$map['iconStyle']; $this->category['icon']['file']=$map['icon']; $this->category['icon']['width']=isset($result[1])?$result[1]:-1; $this->category['icon']['height']=isset($result[2])?$result[2]:-1; } } $template->assign('maps', $this->maps); $template->set_filename('gmapsCatMap', dirname($this->getFileLocation()).'/templates/gmaps_category.tpl'); $template->append('footer_elements', $template->parse('gmapsCatMap', true), false); if(is_array($this->category['icon'])) { $template->assign('mapIcon', $this->category['icon']); $template->set_filename('gmapsIconButton', dirname($this->getFileLocation()).'/templates/gmaps_category_iconbutton.tpl'); $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('gmapsIconButton', true), false); $template->assign('mapIcon'); } $template->append('head_elements', "", false); } } } } } /** * this function display the map on the picture page * * the 'amd_jpegMD_loaded' event is triggered before the 'loc_begin_picture' * event so, when this function is called the $this->picture var was already * initialized */ public function displayPicturePageMap() { global $page, $template; if($this->picture['geolocated']==false and $this->picture['forceDisplay']==false) return(false); if(isset($this->picture['content']['MP']) and count($this->picture['content']['MP'])>0) { // there is maps in meta display mode $template->set_filename('gmapsMeta', dirname($this->getFileLocation()).'/templates/gmaps_picture_meta.tpl'); $template->assign('maps', $this->picture['content']['MP']); $metaTitle=''; foreach($this->picture['content']['MP'] as $map) { if($metaTitle=='') $metaTitle=$map['title']; } $metadata=array ( 'TITLE' => ($metaTitle=='')?l10n('gmaps_geolocation'):$metaTitle, 'lines' => array( /* is a trick to display raw data in tabs * for the gally template * * on the default template, the displayed content is done * normally */ '' => $template->parse('gmapsMeta', true) ) ); $template->append('metadata', $metadata, false); } if(isset($this->picture['content']['IP']) and count($this->picture['content']['IP'])>0) { // there is maps in icon display mode $template->assign('map', $this->picture['content']['IP'][0]); $template->assign('mapIcon', $this->picture['icon']); $template->set_filename('gmapsIconMap', dirname($this->getFileLocation()).'/templates/gmaps_picture_icon.tpl'); $template->append('footer_elements', $template->parse('gmapsIconMap', true), false); $template->set_filename('gmapsIconButton', dirname($this->getFileLocation()).'/templates/gmaps_picture_iconbutton.tpl'); $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('gmapsIconButton', true), false); } if(count($this->picture['properties'])>0) { $template->append('head_elements', "", false); } } /** * prepare the maps for the picture page * * this function is called when the plugin AdvancedMetadata has finished to * read the metadata ; if picture is not geolocated, there is no map to display * * @param JpegMetadata $jpegMD : a JpegMetadata object */ public function preparePictureMaps($jpegMD) { global $template, $page, $user; $isGeolocated=true; if(is_null($jpegMD->getTag('magic.GPS.LatitudeNum')) or is_null($jpegMD->getTag('magic.GPS.LongitudeNum'))) $isGeolocated=false; if(isset($page['category'])) { $this->buildMapList($page['category']['id'], 'P'); } else { $sql="SELECT GROUP_CONCAT(pict.category_id) FROM ".IMAGE_CATEGORY_TABLE." pict WHERE pict.image_id=".$page['image_id']; if($user['forbidden_categories']!='') $sql.=" AND pict.category_id NOT IN (".$user['forbidden_categories'].")"; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_row($result)) { $cats=explode(',', $row[0]); } } $cats[]=0; $i=0; while(count($this->maps)==0 and $ibuildMapList($cats[$i], 'P'); $i++; } } if($this->forceDisplay==0 and !$isGeolocated) return(false); $this->picture['geolocated']=$isGeolocated; $this->picture['forceDisplay']=!$isGeolocated; if($isGeolocated) { $this->picture['coords']['lat']=$jpegMD->getTag('magic.GPS.LatitudeNum')->getValue(); $this->picture['coords']['lng']=$jpegMD->getTag('magic.GPS.LongitudeNum')->getValue(); } foreach($this->maps as $map) { if($isGeolocated or $map['forceDisplay']=='y' and ($map['kmlFileUrl']!='' or $map['kmlFileId']!=0) ) { if($map['displayType']=='IP') { preg_match('/^i(\d+)x(\d+).*/i', basename($map['icon']), $result); $this->picture['icon']=array( 'iconStyle' => $map['iconStyle'], 'file' => $map['icon'], 'width' => isset($result[1])?$result[1]:-1, 'height' => isset($result[2])?$result[2]:-1 ); } $this->picture['content'][$map['displayType']][]=array( 'id' => $map['id'], 'width' => $map['width'], 'height' => $map['height'], 'style' => $map['style'], 'displayType' => $map['displayType'], 'title' => $map['title'], ); $this->picture['properties'][]=" { id:'iGMaps".(($map['displayType']=='IP')?'Icon':$map['id'])."', zoomLevel:".$map['zoomLevel'].", markerImg:'".$map['marker']."', mapType:'".$map['mapType']."', mapTypeControl:'".$map['mapTypeControl']."', navigationControl:'".$map['navigationControl']."', scaleControl:'".$map['scaleControl']."', streetViewControl:'".$map['streetViewControl']."', kmlFileUrl:'".$map['kmlFileUrl']."', displayType:'".$map['displayType']."', sizeMode:'".$map['sizeMode']."', title:'".addslashes( ($map['title']=='')?l10n('gmaps_geolocation'):$map['title'] )."' }"; } } } } //class ?>