[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/views/ -> ViewWorldMap.class.php (source)

   1  <?php
   2  /* 
   3   * phpMyVisites : website statistics and audience measurements
   4   * Copyright (C) 2002 - 2006
   5   * http://www.phpmyvisites.net/ 
   6   * phpMyVisites is free software (license GNU/GPL)
   7   * Authors : phpMyVisites team
   8  */
   9  
  10  // $Id: ViewWorldMap.class.php 95 2006-09-29 06:25:31Z cmil $
  11  
  12  require_once  INCLUDE_PATH."/core/include/ViewModule.class.php";
  13  require_once  INCLUDE_PATH."/core/datas/countryMap.php";
  14  
  15  class ViewWorldMap extends ViewModule
  16  {
  17      var $m_idDetailsCont = "";
  18      
  19  	function ViewWorldMap( $o_data = null )
  20      {
  21          parent::ViewModule("source", $o_data );
  22      }
  23      
  24  
  25  	function showAll()
  26      {
  27          $this->_initDatas();
  28          
  29          //dump_exit($this->request->getContinentZoom());
  30          if ($this->m_idDetailsCont != "") {
  31              $idDetailsContinent = $this->m_idDetailsCont;
  32          }
  33          else {
  34              $idDetailsContinent = $this->request->getContinentZoom();
  35          }
  36          
  37          if($idDetailsContinent != "")
  38          {
  39              $sumContinent = $this->getDataMethod(
  40                      array(
  41                          "continentcountries" => array( $idDetailsContinent ),
  42                          ),
  43                      true
  44                  );
  45              $sumContinent = $sumContinent['continentcountries'];
  46              $this->tpl->assign("continent_asked", $idDetailsContinent);
  47          }
  48          else
  49          {
  50              $sumWorld = $this->getDataMethod(
  51                      array(
  52                              "continentcountries" => array()
  53                              ),
  54                      true
  55                  );
  56              $sumWorld = $sumWorld['continentcountries'];
  57              //$this->tpl->assign('map',true);
  58          }
  59          
  60          if(isset($sumWorld))
  61          {
  62              $image = $this->_computeWorldImage($sumWorld);
  63          }
  64          else
  65          {
  66              //print("<hr>");printDebug($sumContinent);print("<hr>");
  67              $image = $this->_computeContinentImage($sumContinent, $idDetailsContinent, $this->urlMaps[$idDetailsContinent]);
  68          }
  69  
  70          header('Content-type: image/png');
  71          imagepng($image);
  72      }
  73      
  74      
  75      /*****************************************************************
  76       * Private computing methods
  77       */
  78  	function _initDatas()
  79      {
  80          $this->urlScale = DIR_IMG_MAPS . "/scale.png";
  81          $this->urlWorldMap = DIR_IMG_MAPS . "/worldmap.png";
  82          
  83          $this->colorNb = 20;
  84          $this->countriesLocation = $GLOBALS['countryList'];
  85          $this->continentLocation = array(
  86              "eur" => array(296,137,279,107,278,157,287,163,234,95),
  87              "amn" => array(73,114,162,81,178,32,215,55),
  88              "ams" => array(144,225,137,199,126,196,169,341),
  89              "afr" => array(300,219,348,270),
  90              "asi" => array(425,147,504,160,478,190,481,204,470,235,511,243),
  91              "oce" => array(499,289,522,246,513,330,564,326),
  92              "generique_inconnu" => array()
  93          );
  94          
  95          // cartes vierges
  96          $this->urlMaps = array(
  97          'eur' => DIR_IMG_MAPS . "/europe.png",
  98          'afr' => DIR_IMG_MAPS . "/africa.png",
  99          'amn' => DIR_IMG_MAPS . "/north_america.png",
 100          'ams' => DIR_IMG_MAPS . "/south_and_central_america.png",
 101          'asi' => DIR_IMG_MAPS . "/asia.png",
 102          'oce' => DIR_IMG_MAPS . "/oceania.png"
 103          );
 104          
 105          // continents
 106          $this->continent = array('eur','afr','asi','oce','ams','amn');
 107  
 108  
 109          $this->oceansLocation = array(
 110                  array($GLOBALS['lang']['oc_pac'], 18, 272),
 111                  array($GLOBALS['lang']['oc_atl'], 154, 164),
 112                  array($GLOBALS['lang']['oc_ind'], 386, 284)
 113              );    
 114          
 115          // Donn?s encadr?blanc labels
 116          $tb_bgtxt = array(
 117              array("-1","-1"),
 118              array("+1","-1"),
 119              array("+1","+1"),
 120              array("-1","+1")
 121          );
 122          
 123          // Coordonn?s listes pays/continent
 124          $this->textLegendLocation = array(
 125                                              "amn" => array(10,225),
 126                                              "ams" => array(10,120),
 127                                              "eur" => array(10,100),
 128                                              "afr" => array(10,255,115,388,16),
 129                                              "oce" => array(10,295),
 130                                              "asi" => array(100,244,475,155,11),
 131                  );
 132  
 133          $this->labelsCountriesLocation = $GLOBALS['labelsCountriesLocation'];
 134          $fontSet = Lang::getFontName();
 135          
 136          $this->fontType = INCLUDE_PATH . "/libs/artichow/font/".$fontSet;
 137          $this->_initColors();
 138      }
 139      
 140      
 141  	function _initColors()
 142      {
 143          $im = imagecreatefrompng( $this->urlScale);
 144          $size = getimagesize( $this->urlScale );
 145          $width=$size[0];
 146          $height=$size[1];
 147          
 148          $go=1;
 149  
 150          //print("$height et $width");
 151          $step=(int) (($width - $this->colorNb) / $this->colorNb);
 152          
 153          while($go < $width)
 154          {
 155              $rgb = ImageColorAt($im, $go, $height-3);
 156              $go += $step;
 157              $rgb=imagecolorsforindex($im, $rgb); // RGB
 158              
 159              $tcomposantes[] = array(
 160                          $rgb['red'],
 161                          $rgb['green'],
 162                          $rgb['blue']
 163                          );
 164          }
 165          
 166          $this->colorScaleInfo = $tcomposantes;
 167          $this->fontSize = 8;
 168      }
 169      
 170      
 171  	function _computeContinentImage($sumContinent, $idContinent, $urlImage)
 172      {
 173          $image = imagecreatefrompng($urlImage);
 174          
 175          $image = $this->_colourInBorder($sumContinent, $image, false);
 176      
 177      
 178          // Labels Pays - 20050111
 179          $this->fontSize = 8;
 180          //$bg_color= imageColorAllocate($image, 254, 254, 254);
 181          $txt_color= imageColorAllocate($image, 0,0,0);
 182      
 183          $X_list = $this->textLegendLocation[$idContinent][0];
 184          $Y_list = $this->textLegendLocation[$idContinent][1];
 185          foreach( $GLOBALS['lang']['domaines'] as $iso_p => $value)
 186          {
 187              
 188              if(        isset($this->countriesLocation[$iso_p][0])
 189                   && $this->countriesLocation[$iso_p][0] == $idContinent
 190                   )
 191              {
 192                  
 193                  if(    isset($this->labelsCountriesLocation[$iso_p][1]) 
 194                  &&     is_numeric($this->labelsCountriesLocation[$iso_p][1])) 
 195                  {
 196      
 197                      $label =  trim($GLOBALS['lang']['domaines'][$iso_p]);
 198                      $tbtmp = explode(" ",$label);
 199                      $X = $this->labelsCountriesLocation[$iso_p][1];
 200                      $Y =  $this->labelsCountriesLocation[$iso_p][2];
 201                      
 202                      // countries with several words
 203                      if(    isset($tbtmp[0]) 
 204                      && isset($tbtmp[1]) 
 205                      && strlen($label)>8
 206                      ) 
 207                      {
 208                          $space = strpos($label," ");
 209                          $long = strlen($label);
 210                          
 211                          $diff=imagettfbbox($this->fontSize, 0, $this->fontType, substr($label,0,$space));
 212                          $long1 = (($diff[4] + $diff[2]) / 2) - (($diff[6] + $diff[0]) / 2);
 213                          
 214                          $diff=imagettfbbox($this->fontSize, 0, $this->fontType, substr($label,$space+1,$long));
 215                          $long2 = (($diff[4] + $diff[2]) / 2) - (($diff[6] + $diff[0]) / 2);
 216                          
 217                          if($long1 - $long2 > 0)
 218                          {
 219                              $d1 = 0;
 220                              $d2 = abs(floor(($long1 - $long2)/2));
 221                              $max = $long1/2;
 222                          } 
 223                          elseif($long1 - $long2 < 0)
 224                          {
 225                              $d1 = abs(floor(($long1 - $long2)/2));
 226                              $d2 = 0;
 227                              $max = $long2/2;
 228                          } 
 229                          else
 230                          {
 231                              $d1=0;
 232                              $d2 = 0;
 233                              $max = $long2/2;
 234                          }
 235                          
 236                          imagettftext($image, $this->fontSize, 0, $X+$d1-$max, $Y, $txt_color, $this->fontType, substr($label,0,$space));
 237                          imagettftext($image, $this->fontSize, 0, $X+$d2-$max, $Y+$this->fontSize+4, $txt_color, $this->fontType, substr($label,$space+1,$long));
 238                      }
 239                      // countries in one word
 240                      else
 241                      {
 242                          $diff=imagettfbbox($this->fontSize, 0, $this->fontType, $label);
 243                          $long = (($diff[4] + $diff[2]) / 2) - (($diff[6] + $diff[0]) / 2);
 244                          imagettftext($image, $this->fontSize, 0, $X-$long/2, $Y, $txt_color, $this->fontType, $label);
 245                      }
 246                  } 
 247                  else if(    isset($this->labelsCountriesLocation[$iso_p][1]) 
 248                          &&     $this->labelsCountriesLocation[$iso_p][1] == "l"
 249                          )
 250                  {
 251                      $tb_liste[$this->labelsCountriesLocation[$iso_p][2]] = $GLOBALS['lang']['domaines'][$iso_p];
 252                      imagettftext($image, $this->fontSize, 0, $this->labelsCountriesLocation[$iso_p][3], $this->labelsCountriesLocation[$iso_p][4], $txt_color, $this->fontType, $this->labelsCountriesLocation[$iso_p][2]);
 253                  }
 254              }
 255              
 256          }
 257          
 258          // Cr?tion de la liste des pays ?gauche
 259          if(isset($tb_liste) && is_array($tb_liste))
 260          {
 261              ksort($tb_liste);
 262              $h = 1;
 263              for($i=1;$i<count($tb_liste)+1;$i++)
 264              {
 265                  $label =  trim($tb_liste[$i]);
 266                  $tbtmp = explode(" ",$label);
 267                  if(isset($this->textLegendLocation[$idContinent][2]) && isset($this->textLegendLocation[$idContinent][3]) && $i<$this->textLegendLocation[$idContinent][4]) 
 268                  {
 269                      $Y = $Y_list+$h*($this->fontSize+4);
 270                      $X = $X_list;
 271                  } elseif(isset($this->textLegendLocation[$idContinent][2]) && isset($this->textLegendLocation[$idContinent][3]) && $i>=$this->textLegendLocation[$idContinent][4]) 
 272                  {
 273                      if($i==$this->textLegendLocation[$idContinent][4]) $h = 1;
 274                      $Y = $this->textLegendLocation[$idContinent][3]+$h*($this->fontSize+4);
 275                      $X = $this->textLegendLocation[$idContinent][2];
 276                  } else
 277                  {
 278                      $Y = $Y_list+$h*($this->fontSize+4);
 279                      $X = $X_list;
 280                  }
 281                  
 282                  
 283                  if(isset($tbtmp[0]) && isset($tbtmp[1]) && strlen($tbtmp[0])>8) 
 284                  {
 285                      $space = strpos($label," ");
 286                      $long = strlen($label);
 287                      imagettftext($image, $this->fontSize, 0, $X, $Y, $txt_color, $this->fontType, $i." : ".substr($label,0,$space));
 288                      $diff=imagettfbbox($this->fontSize, 0, $this->fontType, $i." : ");
 289                      $long = (($diff[4] + $diff[2]) / 2) - (($diff[6] + $diff[0]) / 2);
 290                      imagettftext($image, $this->fontSize, 0, $X+$long, $Y+$this->fontSize+4, $txt_color, $this->fontType, substr($label,$space+1,$long));
 291                      $h += 2;
 292                  }else
 293                  {
 294                      imagettftext($image, $this->fontSize, 0, $X, $Y, $txt_color, $this->fontType, $i." : ".$label);
 295                      $h++;
 296                  }
 297              }
 298          }
 299          return $image;
 300      }
 301      
 302  	function _colourInBorder( $sum, $image, $worldMapOrContinent)
 303      {
 304          $tcomposantes = $this->colorScaleInfo;
 305          
 306          // liste des couleurs
 307          for($i=0;$i<sizeof($tcomposantes);$i++)
 308          {
 309              $tcouleur[] = imagecolorallocate($image, $tcomposantes[$i][0], $tcomposantes[$i][1], $tcomposantes[$i][2]);
 310          }
 311          
 312          $t = $this->data->getContent('nb_vis');
 313          
 314          foreach($sum as $id => $info)
 315          {
 316  //            printDebug($info);exit;
 317  
 318              if(!empty($worldMapOrContinent))
 319              {
 320                  $nom = $info['continent'];
 321                  $allLocation = $this->continentLocation;
 322                  $u = 0;
 323              }
 324              else
 325              {
 326                  $nom = substr($info['img'], 0, strpos($info['img'], '.'));
 327                  $allLocation = $this->countriesLocation;
 328                  $u = 1;
 329              }
 330              $hits = $info['sum'];
 331              
 332              $couleur= (integer) (( $hits / $t ) * $this->colorNb);
 333              
 334              //print("$nom couleur : ".$hits/$t." $couleur<br>");
 335              
 336              $height = count( $allLocation[$nom]);
 337              //print("$nom : nb loc = $height<br>");
 338      
 339              // offset
 340              if ($couleur>=$this->colorNb)
 341              {
 342                  $couleur=$this->colorNb;
 343              }
 344              
 345              // colour in each portion
 346              
 347              while ($u<$height)
 348              {
 349                  //printDebug($allLocation[$nom]);
 350                  imagefill(
 351                          $image,
 352                          $allLocation[$nom][$u],
 353                          $allLocation[$nom][$u+1],
 354                          $tcouleur[$couleur]
 355                      );
 356                      
 357                  $u+=2;
 358              }
 359          }    
 360          return $image;
 361      }
 362      
 363  	function _computeWorldImage($sumWorld)
 364      {
 365          $image = imagecreatefrompng( $this->urlWorldMap );
 366          
 367          $image = $this->_colourInBorder($sumWorld, $image, true);
 368          
 369          $text_color= imageColorAllocate($image,42,102,145);
 370          $endGo = count($this->oceansLocation);
 371          
 372  
 373          for($oc=0; $oc < $endGo; $oc++)
 374          {
 375              // Centrage des 2 lignes
 376              $tb_label = explode(" ",trim(strtoupper($this->oceansLocation[$oc][0])));
 377              
 378              if(isset($tb_label[0]) && isset($tb_label[1]))
 379              {
 380                  $mes1=imagettfbbox($this->fontSize, 0, $this->fontType, $tb_label[0]);
 381                  $mes2=imagettfbbox($this->fontSize, 0, $this->fontType, $tb_label[1]);
 382                  
 383                  $long1 = (($mes1[4] + $mes1[2]) / 2) - (($mes1[6] + $mes1[0]) / 2);  
 384                  $long2 = (($mes2[4] + $mes2[2]) / 2) - (($mes2[6] + $mes2[0]) / 2);  
 385                  
 386                  $diff = $long1 - $long2;
 387                  $d1 = 0; $d2 = 0;
 388                  
 389                  if($diff>0) 
 390                  {
 391                      $d2 = floor(abs($diff/2));
 392                  } 
 393                  elseif($diff<0) 
 394                  {
 395                      $d1 = floor(abs($diff/2));
 396                  }
 397                  
 398                  imagettftext($image, $this->fontSize, 0, $this->oceansLocation[$oc][1]+$d1, $this->oceansLocation[$oc][2], $text_color, $this->fontType, $tb_label[0]);
 399                  imagettftext($image, $this->fontSize, 0, $this->oceansLocation[$oc][1]+$d2, $this->oceansLocation[$oc][2]+$this->fontSize+3, $text_color, $this->fontType, $tb_label[1]);
 400              } 
 401              else 
 402              {
 403                  imagettftext($image, $this->fontSize, 0, $this->oceansLocation[$oc][1], $this->oceansLocation[$oc][2], $text_color, $this->fontType, trim(strtoupper($this->oceansLocation[$oc][0])));
 404              }
 405          }
 406          return $image;
 407      }
 408  }
 409  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics