> ------------------------------------------------------------------------------ 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 $maps = array(); //list of maps 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, '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') { if(isset($page['category'])) { $this->category['id']=$page['category']['id']; $this->buildMapList($page['category']['id'], 'C'); $sqlCatRestrict="AND FIND_IN_SET(".$page['category']['id'].", pct.uppercats)!=0"; } else { $this->category['id']=0; $this->buildMapList(0, 'C'); $sqlCatRestrict=""; } if(count($this->maps)>0) { $scripts=array(); // 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 $sqlCatRestrict GROUP BY paut.tagId"; $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) { /* * prepare js script for each map */ foreach($this->maps as $keyMap => $map) { $scripts[]=" { id:'iGMapsIcon', zoomLevel:".$map['zoomLevel'].", marker:true, mapType:'".$map['mapType']."', mapTypeControl:'".$map['mapTypeControl']."', navigationControl:'".$map['navigationControl']."', scaleControl:'".$map['scaleControl']."', kmlFileUrl:'".$map['kmlFileUrl']."', displayType:'".$map['displayType']."', sizeMode:'".$map['sizeMode']."', title:'".addslashes( ($map['title']=='')?l10n('gmaps_geolocation'):$map['title'] )."', markers:[], fitToBounds:true }"; 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) return(false); if(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']); $metadata=array ( 'TITLE' => l10n('gmaps_geolocation'), '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(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; if(is_null($jpegMD->getTag('magic.GPS.LatitudeNum')) or is_null($jpegMD->getTag('magic.GPS.LongitudeNum')) or $page['section']!='categories') return(false); $this->picture['geolocated']=true; $this->picture['coords']['lat']=$jpegMD->getTag('magic.GPS.LatitudeNum')->getValue(); $this->picture['coords']['lng']=$jpegMD->getTag('magic.GPS.LongitudeNum')->getValue(); if(isset($page['category'])) { $this->buildMapList($page['category']['id'], 'P'); } else { $this->buildMapList(0, 'P'); } foreach($this->maps as $map) { 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'], 'mode' => $map['displayType'] ); $this->picture['properties'][]=" { id:'iGMaps".(($map['displayType']=='IP')?'Icon':$map['id'])."', zoomLevel:".$map['zoomLevel'].", marker:true, mapType:'".$map['mapType']."', mapTypeControl:'".$map['mapTypeControl']."', navigationControl:'".$map['navigationControl']."', scaleControl:'".$map['scaleControl']."', kmlFileUrl:'".$map['kmlFileUrl']."', displayType:'".$map['displayType']."', sizeMode:'".$map['sizeMode']."', title:'".addslashes( ($map['title']=='')?l10n('gmaps_geolocation'):$map['title'] )."' }"; } } } //class ?>