Ignore:
Timestamp:
Apr 13, 2019, 8:05:15 PM (5 years ago)
Author:
roby
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/modules/Elezioni/grafici/jpgraph_flags.php

    r2 r265  
    11<?php
    22//=======================================================================
    3 // File:        JPGRAPH_FLAGS.PHP
    4 // Description: Class Jpfile. Handles plotmarks
    5 // Created:     2003-06-28
    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 $
    77//
    8 // Copyright (c) Aditus Consulting. All rights reserved.
     8// Copyright (c) Asial Corporation. All rights reserved.
    99//========================================================================
    1010
     
    259259    private $iFlagCount = -1;
    260260    private $iFlagSetMap = array(
    261         FLAGSIZE1 => 'flags_thumb35x35',
    262         FLAGSIZE2 => 'flags_thumb60x60',
    263         FLAGSIZE3 => 'flags_thumb100x100',
    264         FLAGSIZE4 => 'flags'
    265         );
     261    FLAGSIZE1 => 'flags_thumb35x35',
     262    FLAGSIZE2 => 'flags_thumb60x60',
     263    FLAGSIZE3 => 'flags_thumb100x100',
     264    FLAGSIZE4 => 'flags'
     265    );
    266266
    267267    private $iFlagData ;
    268268    private $iOrdIdx=array();
    269269
    270     function FlagImages($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);
     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);
    286286    }
    287287
    288288    function GetNum() {
    289         return $this->iFlagCount;
     289        return $this->iFlagCount;
    290290    }
    291291
    292292    function GetImgByName($aName,&$outFullName) {
    293         $idx = $this->GetIdxByName($aName,$outFullName);
    294         return $this->GetImgByIdx($idx);
     293        $idx = $this->GetIdxByName($aName,$outFullName);
     294        return $this->GetImgByIdx($idx);
    295295    }
    296296
    297297    function GetImgByIdx($aIdx) {
    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         }
     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        }
    306306    }
    307307
    308308    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        }
    332331    }
    333332
    334333    function GetIdxByName($aName,&$outFullName) {
    335334
    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        }
    370367    }
    371368}
Note: See TracChangeset for help on using the changeset viewer.