> ------------------------------------------------------------------------------ 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 { const CAT_ID_HOME = 0; const CAT_ID_TAGS = -1; 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')); if(!isset($_GET['slideshow'])) add_event_handler('loc_begin_picture', array(&$this, 'displayPicturePageMap'), EVENT_HANDLER_PRIORITY_NEUTRAL+5); add_event_handler('amd_jpegMD_loaded', array(&$this, 'preparePictureMaps')); add_event_handler('loc_end_page_header', array(&$this->css2, 'applyCSS')); add_event_handler('render_category_description', array(&$this, 'categoryMarkup'), EVENT_HANDLER_PRIORITY_NEUTRAL-5, 2); } /* ------------------------------------------------------------------------- FUNCTIONS TO MANAGE GMAPS ------------------------------------------------------------------------- */ /** * this function display maps defined as markup in the categories description * [gmaps=id:999;with:999;height:999;kmlId:999;kmlUrl:"xxx";kmlZoom:y|n;markerImg:xxx;markerVisible:y|n;allowBubble:y|n;] * * the function is called on the 'render_category_description' event * maps are displayed only for 'main_page_category_description' page * * @param String $desc : category description * @param String $param : category page (expected value: 'main_page_category_description') * @return String : the modified description */ public function categoryMarkup($desc, $param='') { global $template, $page; $mapParams=array(); if(preg_match_all('/\[gmaps=(?:id:(?P\d+);|width:(?P\d+);|height:(?P\d+);|markerImg:(?P[a-z0-9\-\._]+);|kmlId:(?P\d+);|kmlUrl:"(?P.+)";|allowBubble:(?Py|n);|kmlZoom:(?Py|n);|markerVisible:(?Py|n);)+\]/i',$desc,$mapParams,PREG_SET_ORDER)>0) { if($param!='main_page_category_description') { // if not main page, just remove the [gmaps] markup $desc = preg_replace('/\[gmaps=(?:.*)\]/i','',$desc); return($desc); } GPCCore::addHeaderJS("jquery", "themes/default/js/jquery.min.js"); GPCCore::addHeaderJS("maps.google.com/api", "http://maps.google.com/maps/api/js?sensor=false"); GPCCore::addHeaderJS("gmaps.markup", "plugins/GMaps/js/gmapsMarkup".GPCCore::getMinified().".js", array('jquery')); $desc = preg_replace( '/\[gmaps=(?:id:(?P\d+);|width:(?P\d+);|height:(?P\d+);|markerImg:(?P[a-z0-9\-\._]+);|kmlId:(?P\d+);|kmlUrl:"(?P.+)";|allowBubble:(?Py|n);|kmlZoom:(?Py|n);|markerVisible:(?Py|n);)+\]/i', "
", $desc); $scripts=array(); foreach($mapParams as $mapParam) { $nb=$this->prepareCategoryMap($page['category']['id'], $mapParam['id']); if(!isset($mapParam['allowBubble'])) $mapParam['allowBubble']='y'; if(!isset($mapParam['kmlZoom'])) $mapParam['kmlZoom']='n'; if(!isset($mapParam['width'])) $mapParam['width']=''; if(!isset($mapParam['height'])) $mapParam['height']=''; if(!isset($mapParam['markerImg']) or $mapParam['markerImg']=='') $mapParam['markerImg']='mS01_11.png'; if(!isset($mapParam['markerVisible']) or $mapParam['markerVisible']=='') $mapParam['markerVisible']='y'; if(isset($mapParam['kmlId']) and $mapParam['kmlId']!='') { $sql="SELECT file FROM ".$this->tables['kmlfiles']." WHERE id=".$mapParam['kmlId']; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_assoc($result)) { $mapParam['kmlUrl']=get_absolute_root_url().PWG_LOCAL_DIR.self::KML_DIRECTORY.$row['file']; } } } if(!isset($mapParam['kmlUrl'])) $mapParam['kmlUrl']=''; foreach($this->maps as $map) { $scripts[]=" { id:'gmapsMarkupId".$mapParam['id']."', mapId:".$mapParam['id'].", zoomLevel:".$map['zoomLevel'].", markerImg:'".$mapParam['markerImg']."', markerVisible:".($mapParam['markerVisible']=='y'?'true':'false').", mapType:'".$map['mapType']."', mapTypeControl:'".$map['mapTypeControl']."', navigationControl:'".$map['navigationControl']."', scaleControl:'".$map['scaleControl']."', streetViewControl:'".$map['streetViewControl']."', kmlFileUrl:'".$mapParam['kmlUrl']."', displayType:'".$map['displayType']."', width:".($mapParam['width']==''?$map['width']:$mapParam['width']).", height:".($mapParam['height']==''?$map['height']:$mapParam['height']).", markers:[], fitToBounds:true, zoomLevelMaxActivated:".($map['zoomLevelMaxActivated']=='y'?'true':'false').", mapBounds: { north:".$this->category['bounds']['N'].", south:".$this->category['bounds']['S'].", east:".$this->category['bounds']['E'].", west:".$this->category['bounds']['W']." }, geolocated:".($nb>0?'true':'false').", kmlZoom:".($mapParam['kmlZoom']=='y'?'true':'false').", allowBubble:".($mapParam['allowBubble']=='y'?'true':'false')." } "; } } $template->append('head_elements', "", false); } return($desc); } /** * 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'])) { $nb=$this->prepareCategoryMap($page['category']['id'], null); } else { $nb=$this->prepareCategoryMap(0, null); } if(count($this->maps)>0) { $scripts=array(); 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); GPCCore::addHeaderJS('gmaps.infoWindow', GMAPS_PATH.'js/gmapsInfoWindow'.GPCCore::getMinified().'.js', array('jquery')); GPCCore::addHeaderJS('gmaps.category', GMAPS_PATH.'js/gmapsCategory'.GPCCore::getMinified().'.js', array('jquery', 'gmaps.infoWindow')); } } } } /** * this function prepare data ($this->category var) for a category map * $this->maps must be initialized * * if a map id is given, datas are prepared for the given map otherwise maps * are automatically searched from the current category * * @param Integer $catId : category id * @param Integer $mapId : mapId if already know ; otherwise null * @return Integer : number */ private function prepareCategoryMap($catId, $mapId=null) { global $page, $prefixeTable, $template, $user, $conf; if($catId>0) { $this->category['id']=$catId; if($mapId!=null) { $this->buildMapList($mapId, 'C', self::ID_MODE_MAP); } else { $this->buildMapList($catId, 'C', self::ID_MODE_CATEGORY); } // 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(".$catId.", pct.uppercats)!=0 GROUP BY paut.tagId"; } elseif($catId==self::CAT_ID_TAGS and 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', self::ID_MODE_CATEGORY); } elseif($catId==self::CAT_ID_HOME) { // 'home' $this->category['id']=0; $this->buildMapList(0, 'C', self::ID_MODE_CATEGORY); // 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"; } else { return(0); } $nb=0; if(count($this->maps)>0) { $result=pwg_query($sql); if($result) { 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++; } } } return($nb); } /** * 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', self::ID_MODE_CATEGORY); } 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', self::ID_MODE_CATEGORY); $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 ?>