Changeset 265 for trunk/client/modules/Elezioni/grafici/jpgraph_flags.php
- Timestamp:
- Apr 13, 2019, 8:05:15 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/modules/Elezioni/grafici/jpgraph_flags.php
r2 r265 1 1 <?php 2 2 //======================================================================= 3 // File: 4 // Description: 5 // Created: 6 // Ver: $Id: jpgraph_flags.php 957 2007-12-01 14:00:29Z ljp $3 // File: JPGRAPH_FLAGS.PHP 4 // Description: Class Jpfile. Handles plotmarks 5 // Created: 2003-06-28 6 // Ver: $Id: jpgraph_flags.php 1106 2009-02-22 20:16:35Z ljp $ 7 7 // 8 // Copyright (c) A ditus Consulting. All rights reserved.8 // Copyright (c) Asial Corporation. All rights reserved. 9 9 //======================================================================== 10 10 … … 259 259 private $iFlagCount = -1; 260 260 private $iFlagSetMap = array( 261 262 263 264 265 261 FLAGSIZE1 => 'flags_thumb35x35', 262 FLAGSIZE2 => 'flags_thumb60x60', 263 FLAGSIZE3 => 'flags_thumb100x100', 264 FLAGSIZE4 => 'flags' 265 ); 266 266 267 267 private $iFlagData ; 268 268 private $iOrdIdx=array(); 269 269 270 function FlagImages($aSize=FLAGSIZE1) {271 272 273 274 275 276 277 278 279 280 281 282 283 //('Unknown flag size. ('.$aSize.')');284 285 270 function __construct($aSize=FLAGSIZE1) { 271 switch($aSize) { 272 case FLAGSIZE1 : 273 case FLAGSIZE2 : 274 case FLAGSIZE3 : 275 case FLAGSIZE4 : 276 $file = dirname(__FILE__).'/'.$this->iFlagSetMap[$aSize].'.dat'; 277 $fp = fopen($file,'rb'); 278 $rawdata = fread($fp,filesize($file)); 279 $this->iFlagData = unserialize($rawdata); 280 break; 281 default: 282 JpGraphError::RaiseL(5001,$aSize); 283 //('Unknown flag size. ('.$aSize.')'); 284 } 285 $this->iFlagCount = count($this->iCountryNameMap); 286 286 } 287 287 288 288 function GetNum() { 289 289 return $this->iFlagCount; 290 290 } 291 291 292 292 function GetImgByName($aName,&$outFullName) { 293 294 293 $idx = $this->GetIdxByName($aName,$outFullName); 294 return $this->GetImgByIdx($idx); 295 295 } 296 296 297 297 function GetImgByIdx($aIdx) { 298 299 $d = $this->iFlagData[$aIdx][1]; 300 return Image::CreateFromString($d); 301 302 303 304 //("Flag index \"$aIdx\" does not exist.");305 298 if( array_key_exists($aIdx,$this->iFlagData) ) { 299 $d = $this->iFlagData[$aIdx][1]; 300 return Image::CreateFromString($d); 301 } 302 else { 303 JpGraphError::RaiseL(5002,$aIdx); 304 //("Flag index \"ï¿œ$aIdx\" does not exist."); 305 } 306 306 } 307 307 308 308 function GetIdxByOrdinal($aOrd,&$outFullName) { 309 $aOrd--; 310 $n = count($this->iOrdIdx); 311 if( $n == 0 ) { 312 reset($this->iCountryNameMap); 313 $this->iOrdIdx=array(); 314 $i=0; 315 while( list($key,$val) = each($this->iCountryNameMap) ) { 316 $this->iOrdIdx[$i++] = array($val,$key); 317 } 318 $tmp=$this->iOrdIdx[$aOrd]; 319 $outFullName = $tmp[1]; 320 return $tmp[0]; 321 322 } 323 elseif( $aOrd >= 0 && $aOrd < $n ) { 324 $tmp=$this->iOrdIdx[$aOrd]; 325 $outFullName = $tmp[1]; 326 return $tmp[0]; 327 } 328 else { 329 JpGraphError::RaiseL(5003,$aOrd); 330 //('Invalid ordinal number specified for flag index.'); 331 } 309 $aOrd--; 310 $n = count($this->iOrdIdx); 311 if( $n == 0 ) { 312 $this->iOrdIdx=array(); 313 $i=0; 314 foreach( $this->iCountryNameMap as $key => $val ) { 315 $this->iOrdIdx[$i++] = array($val,$key); 316 } 317 $tmp=$this->iOrdIdx[$aOrd]; 318 $outFullName = $tmp[1]; 319 return $tmp[0]; 320 321 } 322 elseif( $aOrd >= 0 && $aOrd < $n ) { 323 $tmp=$this->iOrdIdx[$aOrd]; 324 $outFullName = $tmp[1]; 325 return $tmp[0]; 326 } 327 else { 328 JpGraphError::RaiseL(5003,$aOrd); 329 //('Invalid ordinal number specified for flag index.'); 330 } 332 331 } 333 332 334 333 function GetIdxByName($aName,&$outFullName) { 335 334 336 if( is_integer($aName) ) { 337 $idx = $this->GetIdxByOrdinal($aName,$outFullName); 338 return $idx; 339 } 340 341 $found=false; 342 $aName = strtolower($aName); 343 $nlen = strlen($aName); 344 reset($this->iCountryNameMap); 345 // Start by trying to match exact index name 346 while( list($key,$val) = each($this->iCountryNameMap) ) { 347 if( $nlen == strlen($val) && $val == $aName ) { 348 $found=true; 349 break; 350 } 351 } 352 if( !$found ) { 353 reset($this->iCountryNameMap); 354 // If the exact index doesn't work try a (partial) full name 355 while( list($key,$val) = each($this->iCountryNameMap) ) { 356 if( strpos(strtolower($key), $aName) !== false ) { 357 $found=true; 358 break; 359 } 360 } 361 } 362 if( $found ) { 363 $outFullName = $key; 364 return $val; 365 } 366 else { 367 JpGraphError::RaiseL(5004,$aName); 368 //("The (partial) country name \"$aName\" does not have a cooresponding flag image. The flag may still exist but under another name, e.g. insted of \"usa\" try \"united states\"."); 369 } 335 if( is_integer($aName) ) { 336 $idx = $this->GetIdxByOrdinal($aName,$outFullName); 337 return $idx; 338 } 339 340 $found=false; 341 $aName = strtolower($aName); 342 $nlen = strlen($aName); 343 // Start by trying to match exact index name 344 foreach( $this->iCountryNameMap as $key => $val ) { 345 if( $nlen == strlen($val) && $val == $aName ) { 346 $found=true; 347 break; 348 } 349 } 350 if( !$found ) { 351 // If the exact index doesn't work try a (partial) full name 352 foreach( $this->iCountryNameMap as $key => $val ) { 353 if( strpos(strtolower($key), $aName) !== false ) { 354 $found=true; 355 break; 356 } 357 } 358 } 359 if( $found ) { 360 $outFullName = $key; 361 return $val; 362 } 363 else { 364 JpGraphError::RaiseL(5004,$aName); 365 //("The (partial) country name \"$aName\" does not have a cooresponding flag image. The flag may still exist but under another name, e.g. insted of \"usa\" try \"united states\"."); 366 } 370 367 } 371 368 }
Note:
See TracChangeset
for help on using the changeset viewer.