> ------------------------------------------------------------------------------ See main.inc.php for release information GMaps_root : common classe for admin and public classes --------------------------------------------------------------------------- */ include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php'); class GMaps_root extends CommonPlugin { const KML_DIRECTORY='plugins/GMaps/kml/'; const ID_MODE_CATEGORY = 'C'; const ID_MODE_MAP='M'; protected $maps=array(); protected $forceDisplay=0; /** * check the available AMD release */ static public function checkAMDRelease() { if(!defined('AMD_VERSION')) return(false); $currentAMDRelease = explode(".", GPC_VERSION); $neededAMDRelease=explode('.', GMAPS_AMD_NEEDED); $major=$neededAMDRelease[0]; $minor=$neededAMDRelease[1]; $minor2=$neededAMDRelease[2]; if(($currentAMDRelease[0]>$major) || ($currentAMDRelease[0]==$major)&&($currentAMDRelease[1]>$minor) || ($currentAMDRelease[0]==$major)&&($currentAMDRelease[1]==$minor)&&($currentAMDRelease[2]>=$minor2)) { return(true); } return(false); } /** * check if AMD plugin is activated and mode * * @return String : 'none' if plugin is not installed * 'inactive' if plugin is not active * 'basic' if plugin active in basic mode * 'advanced' if plugin active in advanced mode */ static public function checkAMDActivated() { if(!self::checkAMDRelease()) return('none'); $sql="SELECT state FROM ".PLUGINS_TABLE." WHERE id='AMetaData';"; $result=pwg_query($sql); if($result) { $row=pwg_db_fetch_assoc($result); if(!(isset($row['state']) and $row['state']='active')) return('inactive'); $amdConfig=array(); GPCCore::loadConfig('amd', $amdConfig); if($amdConfig['newInstall']=='n') return($amdConfig['amd_InterfaceMode']); } return('none'); } public function __construct($prefixeTable, $filelocation) { $this->setPluginName('GMaps'); $this->setPluginNameFiles("gmaps"); parent::__construct($prefixeTable, $filelocation); $this->section_name=$this->getPluginNameFiles(); $this->setTablesList(array('maps', 'category_maps', 'cache', 'cache_id', 'kmlfiles')); } public function loadCSS() { global $template; parent::loadCSS(); GPCCore::addUI('gpcCSS'); GPCCore::addHeaderCSS('gmaps.css', 'plugins/'.$this->getDirectory().'/'.$this->getPluginNameFiles().".css"); GPCCore::addHeaderCSS('gmaps.cssT', 'plugins/'.$this->getDirectory().'/'.$this->getPluginNameFiles().'_'.$template->get_themeconf('name').".css"); } /* intialize default values */ public function initConfig() { //global $user; $this->config=array( 'popupAutomaticSize' => 0.8 ); } /** * */ protected function configForTemplate() { global $template; $template->assign('gmapsConfig', $this->config); } public function getAdminLink($mode='') { if($mode=='ajax') { return('plugins/'.basename(dirname($this->getFileLocation())).'/gmaps_ajax.php'); } else { return(parent::getAdminLink()); } } protected function displayResult($action_msg, $result) { global $page; if($result) { array_push($page['infos'], $action_msg); } else { array_push($page['errors'], $action_msg); } } /* --------------------------------------------------------------------------- --------------------------------------------------------------------------- */ /** * update the given bound with the given coords * * @param &Array $bounds : the bounds (N,S,E,W) * @param Array $coords : coords (0=>lat, 1=>lng) */ protected function updateBounds(&$bounds, $coords) { if($bounds['E']<$coords['lng']) $bounds['E']=$coords['lng']; if($bounds['N']<$coords['lat']) $bounds['N']=$coords['lat']; if($bounds['W']>$coords['lng']) $bounds['W']=$coords['lng']; if($bounds['S']>$coords['lat']) $bounds['S']=$coords['lat']; } /** * build the list of maps (initialize the $this->maps var) * * used by GMaps_ajax & GMaps_pip classes * * @param String $category : id of categories id * @param String $page : 'P' for picture page, 'C' for category page * @param String $mode : self::ID_MODE_CATEGORY = given id is a category id * self::ID_MODE_MAP = given id is a map id */ protected function buildMapList($id, $page, $mode) { global $template ; $this->maps=array(); $this->forceDisplay=0; if($mode==self::ID_MODE_CATEGORY) { if($page=='C') { $where=" displayType='IC' "; } else { $where=" (displayType='IP' or displayType='MP') "; } /* * sql request select all possible association, sorted from the highest to * the lowest priority */ $sql="SELECT DISTINCT pgcm.id, pgcm.categoryId, pgcm.imgSort, pgcm.applySubCat, pgcm.kmlFileUrl, pgcm.kmlFileId, pgkf.file AS kmlFileUrlId, pgcm.icon, pgcm.title, pgcm.marker, pgmm.displayType, pgmm.sizeMode, pgmm.width, pgmm.height, pgmm.zoomLevel, pgmm.mapType, pgmm.mapTypeControl, pgmm.scaleControl, pgmm.streetViewControl, pgmm.navigationControl, pgmm.style, pgmm.zoomLevelMaxActivated, IF(pgcm.categoryId=0, 0, pct.global_rank) AS priorityRank, pgcm.forceDisplay FROM ((".$this->tables['category_maps']." pgcm LEFT JOIN ".$this->tables['maps']." pgmm ON pgcm.mapId = pgmm.id) LEFT JOIN ".CATEGORIES_TABLE." pct ON (FIND_IN_SET(pgcm.categoryId, pct.uppercats)!=0 OR pgcm.categoryId=0)) LEFT JOIN ".$this->tables['kmlfiles']." pgkf ON pgkf.id = pgcm.kmlFileId WHERE $where "; if($id!=0) { $sql.=" AND (pgcm.categoryId ='$id' or pct.id!='$id' AND pgcm.applySubCat='y') "; } else { $sql.=" AND pgcm.categoryId = 0 AND pgcm.applySubCat='y' "; } $sql.=" ORDER BY priorityRank DESC, pgmm.displayType ASC, pgcm.categoryId ASC, pgcm.imgSort ASC;"; } elseif($mode==self::ID_MODE_MAP) { $sql="SELECT DISTINCT pgmm.displayType, pgmm.sizeMode, pgmm.width, pgmm.height, pgmm.zoomLevel, pgmm.mapType, pgmm.mapTypeControl, pgmm.scaleControl, pgmm.streetViewControl, pgmm.navigationControl, pgmm.style, pgmm.zoomLevelMaxActivated, '' AS kmlFileUrl, 0 AS kmlFileId, 'y' AS forceDisplay FROM ".$this->tables['maps']." pgmm WHERE pgmm.id=$id"; } else { return(false); } $result=pwg_query($sql); if($result) { // for each found row, choose the highest only $pcat=''; $displayType=array( 'IC' => true, 'IP' => true, 'MP' => true, ); while($row=pwg_db_fetch_assoc($result)) { // if an kml file id is given, apply the url of the file (needs to give the complete URI for google) if($row['kmlFileId']>0 and $row['kmlFileUrlId']!='') $row['kmlFileUrl']=get_absolute_root_url().PWG_LOCAL_DIR.self::KML_DIRECTORY.rawurlencode($row['kmlFileUrlId']); if($row['displayType']!='MP' and $mode==self::ID_MODE_CATEGORY) { $themeConf=$template->get_template_vars('themeconf'); $fileName=preg_replace('/^([i|c]\d+x\d+)(?:_\d+){0,1}(\..*)/i', '$1$2', $row['icon']); if(file_exists(PHPWG_ROOT_PATH.$themeConf['icon_dir'].'/gmaps/'.$fileName)) { $row['icon']=$themeConf['icon_dir'].'/gmaps/'.$fileName; $row['iconStyle']=false; } else { $row['icon']='plugins/GMaps/img/'.$row['icon']; $row['iconStyle']=true; } } if($displayType[$row['displayType']]) { if($row['displayType']=='MP') { if($displayType['MP'] and ($row['categoryId']==$pcat or $pcat=='')) $this->maps[]=$row; if($displayType['MP'] and $row['categoryId']!=$pcat and $pcat!='') $displayType['MP']=false; $pcat=$row['categoryId']; } else { $this->maps[]=$row; $displayType[$row['displayType']]=false; if($row['forceDisplay']=='y' and ($row['kmlFileUrl']!='' or $row['kmlFileId']!=0)) $this->forceDisplay++; } } } } } /** * returns a new requestId for the cache */ protected function getCacheRequestId() { global $user; $returned=0; // new requestId $sql="INSERT INTO ".$this->tables['cache_id']." VALUES ('', '".$user['id']."', '".date('Y-m-d H:i:s')."');"; $result=pwg_query($sql); if($result) { $returned=pwg_db_insert_id(); } return($returned); } /** * update date for a cache requestId */ protected function updateCacheRequestId($requestId) { global $user; // new requestId $sql="UPDATE ".$this->tables['cache_id']." SET `date` = '".date('Y-m-d H:i:s')."' WHERE requestId='$requestId';"; pwg_query($sql); } /** * clean the cache : cache values older than given number of second are * deleted * * @param Integer $time : number of second */ protected function cleanCache($time=300) { $date=date('Y-m-d H:i:s', time()-$time); $sql="DELETE FROM ".$this->tables['cache']." USING ".$this->tables['cache']." JOIN ".$this->tables['cache_id']." pgci ON ".$this->tables['cache'].".requestId = pgci.requestId WHERE pgci.`date` < '$date';"; pwg_query($sql); $sql="DELETE FROM ".$this->tables['cache_id']." WHERE `date` < '$date';"; pwg_query($sql); } } //class class GMaps_functions { static private $tables = Array(); static private $config = Array(); /** * initialise the class * * @param String $prefixeTable : the piwigo prefixe used on tables name * @param String $pluginNameFile : the plugin name used for tables name */ static public function init($prefixeTable) { GPCCore::loadConfig(GMaps_root::$pluginNameFile, self::$config); $list=GMaps_root::$pluginTables; for($i=0;$iset_filename('gmaps_choose', dirname(__FILE__).'/templates/gmaps_dialog_area_choose.tpl'); $datas=Array(); $template->assign('datas', $datas); return($template->parse('gmaps_choose', true)); } /** * convert a decimal degree to D°M'S' * * @param Float $value : the value to convert * @return String : value converted in DMS */ static public function DDtoDMS($value) { $degrees=(int)$value; $value=($value-$degrees)*60; $minutes=(int)$value; $seconds=($value-$minutes)*60; return(sprintf('%d° %d\' %.2f"', $degrees, $minutes, $seconds)); } } //GMaps_functions ?>