Ignore:
Timestamp:
Oct 20, 2010, 10:49:29 PM (14 years ago)
Author:
grum
Message:

fix bug and implement new features
bug:1926, bug:1927, bug:1929, bug:1930, bug:1931, bug:1939, bug:1946

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/GMaps/gmaps_ajax.php

    r7177 r7308  
    7777
    7878           $_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'
    8180           )) $_REQUEST['ajaxfct']='';
    8281
     
    133132          else
    134133          {
    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                 ))
    147148            {
    148149              $_REQUEST['ajaxfct']='';
     
    187188              if(!($_REQUEST['datas']['streetViewControl']=='y' or
    188189                   $_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';
    189193            }
    190194          }
     
    204208          else
    205209          {
    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
    213217                 isset($_REQUEST['datas']['title']) ))
    214218            {
     
    262266          else
    263267          {
    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
    272277                 isset($_REQUEST['datas']['bounds']['west']) ))
    273278            {
    274279              $_REQUEST['ajaxfct']='';
    275280            }
    276             else
    277             {
    278               if(!isset($_REQUEST['datas']['levelInfo'])) $_REQUEST['datas']['levelInfo']=1;
    279 
    280               if(!($_REQUEST['datas']['levelInfo']==0 or
    281                    $_REQUEST['datas']['levelInfo']==1)) $_REQUEST['datas']['levelInfo']=1;
    282             }
    283281          }
    284282        }
     
    293291            $_REQUEST['ajaxfct']='';
    294292          }
    295 
    296 
    297         }
    298 
     293        }
    299294      }
    300295    } //checkRequest
     
    353348          $result=$this->ajax_gmaps_public_mapsGetMarkers($_REQUEST['datas']);
    354349          break;
     350        case 'public.maps.getMarkersInfos':
     351          $result=$this->ajax_gmaps_public_mapsGetMarkersInfos($_REQUEST['datas']);
     352          break;
    355353      }
    356354      GPCAjax::returnResult($result);
     
    378376      $datas=Array();
    379377
    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
    381381            FROM ".$this->tables['maps']."
    382382            ORDER BY displayType ASC, name ASC";
     
    443443                $properties['scaleControl']."', '".
    444444                $properties['streetViewControl']."', '".
    445                 mysql_escape_string($properties['style'])."');";
     445                mysql_escape_string($properties['style'])."', '".
     446                $properties['zoomLevelMaxActivated']."');";
    446447        $result=pwg_query($sql);
    447448        $id=pwg_db_insert_id();
     
    461462                $properties['scaleControl']."', streetViewControl='".
    462463                $properties['streetViewControl']."', style='".
    463                 mysql_escape_string($properties['style'])."'
     464                mysql_escape_string($properties['style'])."', zoomLevelMaxActivated='".
     465                $properties['zoomLevelMaxActivated']."'
    464466              WHERE id='$id';";
    465467        $result=pwg_query($sql);
     
    490492        'navigationControl' => 0,
    491493        'scaleControl' => 'y',
    492         'streetViewControl' => 'n'
     494        'streetViewControl' => 'n',
     495        'zoomLevelMaxActivated' => 'n',
     496        'associations' => 0,
    493497      );
    494498
    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;";
    498510      $result=pwg_query($sql);
    499511      if($result)
     
    781793        while($row=pwg_db_fetch_assoc($result))
    782794        {
    783           $row['fileSize']=$this->formatOctet($row['fileSize']);
     795          $row['fileSize']=GPCCore::formatOctet($row['fileSize']);
    784796          $datas[]=$row;
    785797        }
     
    852864        }
    853865
    854         $file=dirname(__FILE__).'/kml/'.$file;
     866        $file=GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file;
    855867
    856868        if(file_exists($file)) unlink($file);
     
    858870        {
    859871          $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']);
    861873        }
    862874
     
    933945        while($row=pwg_db_fetch_assoc($result))
    934946        {
    935           $row['fileSizeUnits']=$this->formatOctet($row['fileSize']);
     947          $row['fileSizeUnits']=GPCCore::formatOctet($row['fileSize']);
    936948          $returned=$row;
    937949        }
     
    9891001      if($result)
    9901002      {
    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);
    9941006        }
    9951007        return('ok');
     
    10921104              'latitude' => $coords[0],
    10931105              'longitude' => $coords[1],
    1094               'imageName' => mysql_escape_string($row['imageName']),
     1106              'imageName' => GPCCore::getUserLanguageDesc(mysql_escape_string($row['imageName'])),
    10951107              'imageTnFile' => dirname($row['path']).'/'.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension(basename($row['path'])).'.'.$row['tn_ext'],
    10961108              'imageCatsId' => $row['imageCatsId'],
     
    11191131     *                       'width' : width of maps in pixels
    11201132     *                       'height' : height of maps in pixels
    1121      *                       'levelInfo' : 0 = don't return pictures info (name, url, ...)
    1122      *                                     1 = return pictures informations
    11231133     * @return Array|String : a JSON string of an array of points (nbPictures, lat, lng)
    11241134     */
     
    11281138
    11291139      $returned=array(
     1140        'callId' => $datas['callId'],
    11301141        'markers' => array(),
    11311142        'datas' => array(
     
    12001211        // works with the highest ratio
    12011212        $ratio=max($ratioW, $ratioH);
    1202 
    1203 
    1204         $points=array();
     1213        $datas['distanceTreshold']=pow($datas['distanceTreshold']*$ratio,2);
     1214
     1215
    12051216        $groups=array();
    12061217
    1207         while($row=pwg_db_fetch_assoc($result))
    1208         {
    1209           $points[]=$row;
    1210         }
    12111218
    12121219        /*
    12131220         *  build groups
    12141221         */
    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
    12401230
    12411231        /*
     
    12471237          $coords=array(
    12481238            'nbImgTxt' => '',
    1249             'nbImages' => 0,
     1239            'nbImg' => 0,
    12501240            'lat' => 0,                   // 'lat' rather than 'latitude'
    12511241            'lng' => 0,                   // 'lng' rather than 'longitude'
     
    12701260                  'category' => array(
    12711261                    'id' => $id,
    1272                     'name' => $tmpCatsNames[$key],
     1262                    'name' => GPCCore::getUserLanguageDesc($tmpCatsNames[$key]),
    12731263                    'permalink' => (substr($tmpCatsPLinks[$key],0,1)=='*')?'':$tmpCatsPLinks[$key],
    12741264                  )
     
    12791269            if(count($tmpCatsId)<=1) $tmpCatsNames='';
    12801270
    1281             $coords['nbImages']++;
     1271            $coords['nbImg']++;
    12821272
    12831273            $coords['lat']+=$point['latitude'];
    12841274            $coords['lng']+=$point['longitude'];
    12851275
    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;
    12931280          }
    12941281          $coords['lat']=$coords['lat']/count($group);
    12951282          $coords['lng']=$coords['lng']/count($group);
    1296           $coords['uniqueId']=md5($coords['lat'].$coords['lng']);
    1297 
    1298           if($coords['nbImages']==1)
     1283          $coords['uId']=md5($coords['lat'].$coords['lng']);
     1284
     1285          if($coords['nbImg']==1)
    12991286          {
    13001287            $coords['nbImgTxt']=l10n('gmaps_1_picture');
     
    13021289          else
    13031290          {
    1304             $coords['nbImgTxt']=sprintf(l10n('gmaps_nb_pictures'), $coords['nbImages']);
     1291            $coords['nbImgTxt']=sprintf(l10n('gmaps_nb_pictures'), $coords['nbImg']);
    13051292          }
    13061293
    13071294          $returned['markers'][]=$coords;
    1308           $returned['datas']['nbPhotos']+=$coords['nbImages'];
     1295          $returned['datas']['nbPhotos']+=$coords['nbImg'];
    13091296        }
    13101297      }
     
    13241311
    13251312      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);
    13261335    }
    1327 
    1328 
    1329 
    1330 
    1331      /**
    1332       * formats a file size into a human readable size
    1333       *
    1334       * @param String $format : "A"  : auto
    1335       *                         "Ai" : auto (io)
    1336       *                         "O"  : o
    1337       *                         "K"  : Ko
    1338       *                         "M"  : Mo
    1339       *                         "G"  : Go
    1340       *                         "Ki" : Kio
    1341       *                         "Mi" : Mio
    1342       *                         "Gi" : Gio
    1343       * @param String $thsep : thousand separator
    1344       * @param Integer $prec : number of decimals
    1345       * @param Bool $visible : display or not the unit
    1346       * @return String : a formatted file size
    1347       */
    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        else
    1359        { $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        else
    1370        { $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 formatOctet
    1402 
    1403 
    14041336
    14051337  } //class
Note: See TracChangeset for help on using the changeset viewer.