> ------------------------------------------------------------------------------ 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 { protected $css; /** * 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); return($amdConfig['amd_InterfaceMode']); } } 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', 'kmlfiles')); $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css"); } public function __destruct() { parent::__destruct(); } public function initEvents() { } /* surchage of CommonPlugin->saveConfig function */ public function saveConfig() { if(parent::saveConfig()) { return(true); } return(false); } /* surchage of CommonPlugin->saveConfig function */ public function loadConfig() { parent::loadConfig(); } /* intialize default values */ public function initConfig() { //global $user; $this->config=array( ); } /** * */ 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 Array $categories : array of categories id (cat + parent list) * @param String $page : 'P' for picture page, 'C' for category page */ protected function buildMapList($category, $page) { global $template ; 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.navigationControl, pgmm.style, IF(pgcm.categoryId=0, 0, pct.global_rank) AS priorityRank 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($category!=0) { $sql.=" AND pct.id = '$category' "; } else { $sql.=" AND pgcm.categoryId = 0 "; } $sql.=" AND pgcm.applySubCat='y' ORDER BY priorityRank DESC, pgmm.displayType ASC, pgcm.categoryId ASC, pgcm.imgSort ASC;"; $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']=dirname($_SERVER['SCRIPT_URI']).'/plugins/GMaps/kml/'.$row['kmlFileUrlId']; if($row['displayType']!='MP') { $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; } } } } } } //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 ?>