Changeset 7308 for extensions/GMaps/gmaps_ajax.php
- Timestamp:
- Oct 20, 2010, 10:49:29 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/GMaps/gmaps_ajax.php
r7177 r7308 77 77 78 78 $_REQUEST['ajaxfct']=='public.maps.init' or 79 $_REQUEST['ajaxfct']=='public.maps.getMarkers' //or 80 //$_REQUEST['ajaxfct']=='public.maps.getMarkerInfos' 79 $_REQUEST['ajaxfct']=='public.maps.getMarkers' 81 80 )) $_REQUEST['ajaxfct']=''; 82 81 … … 133 132 else 134 133 { 135 if(!(isset($_REQUEST['datas']['displayType']) && 136 isset($_REQUEST['datas']['sizeMode']) && 137 isset($_REQUEST['datas']['name']) && 138 isset($_REQUEST['datas']['width']) && 139 isset($_REQUEST['datas']['height']) && 140 isset($_REQUEST['datas']['zoomLevel']) && 141 isset($_REQUEST['datas']['mapType']) && 142 isset($_REQUEST['datas']['mapTypeControl']) && 143 isset($_REQUEST['datas']['navigationControl']) && 144 isset($_REQUEST['datas']['scaleControl']) && 145 isset($_REQUEST['datas']['streetViewControl']) && 146 isset($_REQUEST['datas']['style']))) 134 if(!(isset($_REQUEST['datas']['displayType']) and 135 isset($_REQUEST['datas']['sizeMode']) and 136 isset($_REQUEST['datas']['name']) and 137 isset($_REQUEST['datas']['width']) and 138 isset($_REQUEST['datas']['height']) and 139 isset($_REQUEST['datas']['zoomLevel']) and 140 isset($_REQUEST['datas']['mapType']) and 141 isset($_REQUEST['datas']['mapTypeControl']) and 142 isset($_REQUEST['datas']['navigationControl']) and 143 isset($_REQUEST['datas']['scaleControl']) and 144 isset($_REQUEST['datas']['streetViewControl']) and 145 isset($_REQUEST['datas']['style']) and 146 isset($_REQUEST['datas']['zoomLevelMaxActivated']) 147 )) 147 148 { 148 149 $_REQUEST['ajaxfct']=''; … … 187 188 if(!($_REQUEST['datas']['streetViewControl']=='y' or 188 189 $_REQUEST['datas']['streetViewControl']=='n')) $_REQUEST['datas']['streetViewControl']='n'; 190 191 if(!($_REQUEST['datas']['zoomLevelMaxActivated']=='y' or 192 $_REQUEST['datas']['zoomLevelMaxActivated']=='n')) $_REQUEST['datas']['zoomLevelMaxActivated']='n'; 189 193 } 190 194 } … … 204 208 else 205 209 { 206 if(!(isset($_REQUEST['datas']['categoryId']) &&207 isset($_REQUEST['datas']['mapId']) &&208 isset($_REQUEST['datas']['applySubCat']) &&209 isset($_REQUEST['datas']['kmlFileId']) &&210 isset($_REQUEST['datas']['kmlFileUrl']) &&211 isset($_REQUEST['datas']['icon']) &&212 isset($_REQUEST['datas']['marker']) &&210 if(!(isset($_REQUEST['datas']['categoryId']) and 211 isset($_REQUEST['datas']['mapId']) and 212 isset($_REQUEST['datas']['applySubCat']) and 213 isset($_REQUEST['datas']['kmlFileId']) and 214 isset($_REQUEST['datas']['kmlFileUrl']) and 215 isset($_REQUEST['datas']['icon']) and 216 isset($_REQUEST['datas']['marker']) and 213 217 isset($_REQUEST['datas']['title']) )) 214 218 { … … 262 266 else 263 267 { 264 if(!(isset($_REQUEST['datas']['requestId']) && 265 isset($_REQUEST['datas']['bounds']) && 266 isset($_REQUEST['datas']['width']) && 267 isset($_REQUEST['datas']['height']) && 268 isset($_REQUEST['datas']['distanceTreshold']) && 269 isset($_REQUEST['datas']['bounds']['north']) && 270 isset($_REQUEST['datas']['bounds']['south']) && 271 isset($_REQUEST['datas']['bounds']['east']) && 268 if(!(isset($_REQUEST['datas']['requestId']) and 269 isset($_REQUEST['datas']['callId']) and 270 isset($_REQUEST['datas']['bounds']) and 271 isset($_REQUEST['datas']['width']) and 272 isset($_REQUEST['datas']['height']) and 273 isset($_REQUEST['datas']['distanceTreshold']) and 274 isset($_REQUEST['datas']['bounds']['north']) and 275 isset($_REQUEST['datas']['bounds']['south']) and 276 isset($_REQUEST['datas']['bounds']['east']) and 272 277 isset($_REQUEST['datas']['bounds']['west']) )) 273 278 { 274 279 $_REQUEST['ajaxfct']=''; 275 280 } 276 else277 {278 if(!isset($_REQUEST['datas']['levelInfo'])) $_REQUEST['datas']['levelInfo']=1;279 280 if(!($_REQUEST['datas']['levelInfo']==0 or281 $_REQUEST['datas']['levelInfo']==1)) $_REQUEST['datas']['levelInfo']=1;282 }283 281 } 284 282 } … … 293 291 $_REQUEST['ajaxfct']=''; 294 292 } 295 296 297 } 298 293 } 299 294 } 300 295 } //checkRequest … … 353 348 $result=$this->ajax_gmaps_public_mapsGetMarkers($_REQUEST['datas']); 354 349 break; 350 case 'public.maps.getMarkersInfos': 351 $result=$this->ajax_gmaps_public_mapsGetMarkersInfos($_REQUEST['datas']); 352 break; 355 353 } 356 354 GPCAjax::returnResult($result); … … 378 376 $datas=Array(); 379 377 380 $sql="SELECT id, name, displayType, sizeMode, width, height, zoomLevel, mapType, mapTypeControl, navigationControl, scaleControl, streetViewControl 378 $sql="SELECT id, name, displayType, sizeMode, width, height, zoomLevel, 379 mapType, mapTypeControl, navigationControl, scaleControl, 380 streetViewControl, zoomLevelMaxActivated 381 381 FROM ".$this->tables['maps']." 382 382 ORDER BY displayType ASC, name ASC"; … … 443 443 $properties['scaleControl']."', '". 444 444 $properties['streetViewControl']."', '". 445 mysql_escape_string($properties['style'])."');"; 445 mysql_escape_string($properties['style'])."', '". 446 $properties['zoomLevelMaxActivated']."');"; 446 447 $result=pwg_query($sql); 447 448 $id=pwg_db_insert_id(); … … 461 462 $properties['scaleControl']."', streetViewControl='". 462 463 $properties['streetViewControl']."', style='". 463 mysql_escape_string($properties['style'])."' 464 mysql_escape_string($properties['style'])."', zoomLevelMaxActivated='". 465 $properties['zoomLevelMaxActivated']."' 464 466 WHERE id='$id';"; 465 467 $result=pwg_query($sql); … … 490 492 'navigationControl' => 0, 491 493 'scaleControl' => 'y', 492 'streetViewControl' => 'n' 494 'streetViewControl' => 'n', 495 'zoomLevelMaxActivated' => 'n', 496 'associations' => 0, 493 497 ); 494 498 495 $sql="SELECT id, displayType, sizeMode, name, width, height, zoomLevel, mapType, mapTypeControl, navigationControl, scaleControl, streetViewControl 496 FROM ".$this->tables['maps']." 497 WHERE id='$id';"; 499 $sql="SELECT pgmm.id, pgmm.displayType, pgmm.sizeMode, pgmm.name, 500 pgmm.width, pgmm.height, pgmm.zoomLevel, pgmm.mapType, 501 pgmm.mapTypeControl, pgmm.navigationControl, 502 pgmm.scaleControl, pgmm.streetViewControl, 503 pgmm.zoomLevelMaxActivated, 504 COUNT(pgcm.id) AS nbAssoc 505 FROM ".$this->tables['maps']." pgmm 506 LEFT JOIN ".$this->tables['category_maps']." pgcm 507 ON pgcm.mapId=pgmm.id 508 WHERE pgmm.id='$id' 509 GROUP BY pgmm.id;"; 498 510 $result=pwg_query($sql); 499 511 if($result) … … 781 793 while($row=pwg_db_fetch_assoc($result)) 782 794 { 783 $row['fileSize']= $this->formatOctet($row['fileSize']);795 $row['fileSize']=GPCCore::formatOctet($row['fileSize']); 784 796 $datas[]=$row; 785 797 } … … 852 864 } 853 865 854 $file= dirname(__FILE__).'/kml/'.$file;866 $file=GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file; 855 867 856 868 if(file_exists($file)) unlink($file); … … 858 870 { 859 871 $currentInfo=$this->ajax_gmaps_admin_kmlFilesGetFile($id, false); 860 if(file_exists( dirname(__FILE__).'/kml/'.$currentInfo['file'])) unlink(dirname(__FILE__).'/kml/'.$currentInfo['file']);872 if(file_exists(self::KML_DIRECTORY.$currentInfo['file'])) unlink(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$currentInfo['file']); 861 873 } 862 874 … … 933 945 while($row=pwg_db_fetch_assoc($result)) 934 946 { 935 $row['fileSizeUnits']= $this->formatOctet($row['fileSize']);947 $row['fileSizeUnits']=GPCCore::formatOctet($row['fileSize']); 936 948 $returned=$row; 937 949 } … … 989 1001 if($result) 990 1002 { 991 if($file!='' and file_exists( dirname(__FILE__).'/kml/'.$file))992 { 993 unlink( dirname(__FILE__).'/kml/'.$file);1003 if($file!='' and file_exists(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file)) 1004 { 1005 unlink(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file); 994 1006 } 995 1007 return('ok'); … … 1092 1104 'latitude' => $coords[0], 1093 1105 'longitude' => $coords[1], 1094 'imageName' => mysql_escape_string($row['imageName']),1106 'imageName' => GPCCore::getUserLanguageDesc(mysql_escape_string($row['imageName'])), 1095 1107 'imageTnFile' => dirname($row['path']).'/'.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension(basename($row['path'])).'.'.$row['tn_ext'], 1096 1108 'imageCatsId' => $row['imageCatsId'], … … 1119 1131 * 'width' : width of maps in pixels 1120 1132 * 'height' : height of maps in pixels 1121 * 'levelInfo' : 0 = don't return pictures info (name, url, ...)1122 * 1 = return pictures informations1123 1133 * @return Array|String : a JSON string of an array of points (nbPictures, lat, lng) 1124 1134 */ … … 1128 1138 1129 1139 $returned=array( 1140 'callId' => $datas['callId'], 1130 1141 'markers' => array(), 1131 1142 'datas' => array( … … 1200 1211 // works with the highest ratio 1201 1212 $ratio=max($ratioW, $ratioH); 1202 1203 1204 $points=array(); 1213 $datas['distanceTreshold']=pow($datas['distanceTreshold']*$ratio,2); 1214 1215 1205 1216 $groups=array(); 1206 1217 1207 while($row=pwg_db_fetch_assoc($result))1208 {1209 $points[]=$row;1210 }1211 1218 1212 1219 /* 1213 1220 * build groups 1214 1221 */ 1215 while(count($points)>0) 1216 { 1217 $currentGroup=array(); 1218 $currentGroup[]=array_shift($points); 1219 1220 $i=0; 1221 while($i<count($points)) 1222 { 1223 $dist=sqrt(pow($points[$i]['latitude']-$currentGroup[0]['latitude'],2) + pow($points[$i]['longitude']-$currentGroup[0]['longitude'],2))/$ratio; 1224 1225 if($dist <= $datas['distanceTreshold']) 1226 { 1227 $tmp=array_splice($points, $i, 1); 1228 $currentGroup[]=$tmp[0]; 1229 $points=array_values($points); // reset array index... 1230 } 1231 else 1232 { 1233 $i++; 1234 } 1235 } 1236 1237 $groups[]=$currentGroup; 1238 unset($currentGroup); 1239 } 1222 while($row=pwg_db_fetch_assoc($result)) 1223 { 1224 if(!$this->checkInGroup($row, $groups, $datas['distanceTreshold'])) 1225 { 1226 $groups[]=array($row); 1227 } 1228 } 1229 1240 1230 1241 1231 /* … … 1247 1237 $coords=array( 1248 1238 'nbImgTxt' => '', 1249 'nbIm ages' => 0,1239 'nbImg' => 0, 1250 1240 'lat' => 0, // 'lat' rather than 'latitude' 1251 1241 'lng' => 0, // 'lng' rather than 'longitude' … … 1270 1260 'category' => array( 1271 1261 'id' => $id, 1272 'name' => $tmpCatsNames[$key],1262 'name' => GPCCore::getUserLanguageDesc($tmpCatsNames[$key]), 1273 1263 'permalink' => (substr($tmpCatsPLinks[$key],0,1)=='*')?'':$tmpCatsPLinks[$key], 1274 1264 ) … … 1279 1269 if(count($tmpCatsId)<=1) $tmpCatsNames=''; 1280 1270 1281 $coords['nbIm ages']++;1271 $coords['nbImg']++; 1282 1272 1283 1273 $coords['lat']+=$point['latitude']; 1284 1274 $coords['lng']+=$point['longitude']; 1285 1275 1286 if($datas['levelInfo']==1) 1287 { 1288 $coords['imgTn'][]=substr($point['imageTnFile'],12); 1289 $coords['imgCatsNames'][]=$tmpCatsNames; 1290 $coords['imgName'][]=$point['imageName']; 1291 $coords['imgCatsUrl'][]=$tmpCatsUrl; 1292 } 1276 $coords['imgTn'][]=substr($point['imageTnFile'],12); 1277 $coords['imgCatsNames'][]=$tmpCatsNames; 1278 $coords['imgName'][]=GPCCore::getUserLanguageDesc($point['imageName']); 1279 $coords['imgCatsUrl'][]=$tmpCatsUrl; 1293 1280 } 1294 1281 $coords['lat']=$coords['lat']/count($group); 1295 1282 $coords['lng']=$coords['lng']/count($group); 1296 $coords['u niqueId']=md5($coords['lat'].$coords['lng']);1297 1298 if($coords['nbIm ages']==1)1283 $coords['uId']=md5($coords['lat'].$coords['lng']); 1284 1285 if($coords['nbImg']==1) 1299 1286 { 1300 1287 $coords['nbImgTxt']=l10n('gmaps_1_picture'); … … 1302 1289 else 1303 1290 { 1304 $coords['nbImgTxt']=sprintf(l10n('gmaps_nb_pictures'), $coords['nbIm ages']);1291 $coords['nbImgTxt']=sprintf(l10n('gmaps_nb_pictures'), $coords['nbImg']); 1305 1292 } 1306 1293 1307 1294 $returned['markers'][]=$coords; 1308 $returned['datas']['nbPhotos']+=$coords['nbIm ages'];1295 $returned['datas']['nbPhotos']+=$coords['nbImg']; 1309 1296 } 1310 1297 } … … 1324 1311 1325 1312 return(json_encode($returned)); 1313 } //ajax_gmaps_public_mapsGetMarkers 1314 1315 /** 1316 * check if a point is inside an existing group, and add it 1317 * @param Array $point : the point 1318 * @param Array &$groups : the groups 1319 * @param Float $maxDist : maximum distance to be inside group 1320 * @return Bool : true if added in a group, otherwise false 1321 */ 1322 private function checkInGroup($point, &$groups, $maxDist) 1323 { 1324 foreach($groups as $key=>$group) 1325 { 1326 $dist=pow($point['latitude']-$group[0]['latitude'],2) + pow($point['longitude']-$group[0]['longitude'],2); 1327 1328 if($dist<=$maxDist) 1329 { 1330 $groups[$key][]=$point; 1331 return(true); 1332 } 1333 } 1334 return(false); 1326 1335 } 1327 1328 1329 1330 1331 /**1332 * formats a file size into a human readable size1333 *1334 * @param String $format : "A" : auto1335 * "Ai" : auto (io)1336 * "O" : o1337 * "K" : Ko1338 * "M" : Mo1339 * "G" : Go1340 * "Ki" : Kio1341 * "Mi" : Mio1342 * "Gi" : Gio1343 * @param String $thsep : thousand separator1344 * @param Integer $prec : number of decimals1345 * @param Bool $visible : display or not the unit1346 * @return String : a formatted file size1347 */1348 private function formatOctet($octets, $format="Ai", $thsep="", $prec=2, $visible=true)1349 {1350 if($format=="Ai")1351 {1352 if($octets<1024)1353 { $format="O"; }1354 elseif($octets<1024000)1355 { $format="Ki"; }1356 elseif($octets<1024000000)1357 { $format="Mi"; }1358 else1359 { $format="Gi"; }1360 }1361 elseif($format=="A")1362 {1363 if($octets<1000)1364 { $format="O"; }1365 elseif($octets<1000000)1366 { $format="Ki"; }1367 elseif($octets<1000000000)1368 { $format="Mi"; }1369 else1370 { $format="Gi"; }1371 }1372 1373 switch($format)1374 {1375 case "O":1376 $unit="o"; $div=1;1377 break;1378 case "K":1379 $unit="Ko"; $div=1000;1380 break;1381 case "M":1382 $unit="Mo"; $div=1000000;1383 break;1384 case "G":1385 $unit="Go"; $div=1000000000;1386 break;1387 case "Ki":1388 $unit="Kio"; $div=1024;1389 break;1390 case "Mi":1391 $unit="Mio"; $div=1024000;1392 break;1393 case "Gi":1394 $unit="Gio"; $div=1024000000;1395 break;1396 }1397 1398 $returned=number_format($octets/$div, $prec, '.', $thsep);1399 if($visible) $returned.=' '.$unit;1400 return($returned);1401 } //function formatOctet1402 1403 1404 1336 1405 1337 } //class
Note: See TracChangeset
for help on using the changeset viewer.