2 //=======================================================================
3 // File: JPGRAPH_FLAGS.PHP
4 // Description: Class Jpfile. Handles plotmarks
6 // Author: Johan Persson (johanp@aditus.nu)
7 // Ver: $Id: jpgraph_flags.php,v 1.2.2.5 2003/08/24 11:15:02 aditus Exp $
9 // License: This code is released under QPL 1.0
10 // Copyright (C) 2003 Johan Persson
11 //========================================================================
13 //------------------------------------------------------------
14 // Defines for the different basic sizes of flags
15 //------------------------------------------------------------
16 DEFINE('FLAGSIZE1',1);
17 DEFINE('FLAGSIZE2',2);
18 DEFINE('FLAGSIZE3',3);
19 DEFINE('FLAGSIZE4',4);
23 var $iCountryNameMap = array(
24 'Afghanistan' => 'afgh',
25 'Republic of Angola' => 'agla',
26 'Republic of Albania' => 'alba',
28 'Democratic and Popular Republic of Algeria' => 'alge',
29 'Territory of American Samoa' => 'amsa',
30 'Principality of Andorra' => 'andr',
31 'British Overseas Territory of Anguilla' => 'angu',
32 'Antarctica' => 'anta',
33 'Argentine Republic' => 'arge',
34 'League of Arab States' => 'arle',
35 'Republic of Armenia' => 'arme',
37 'Commonwealth of Australia' => 'astl',
38 'Republic of Austria' => 'aust',
39 'Azerbaijani Republic' => 'azer',
40 'British Antarctic Territory' => 'bant',
41 'Kingdom of Belgium' => 'belg',
42 'British Overseas Territory of Bermuda' => 'berm',
43 'Commonwealth of the Bahamas' => 'bhms',
44 'Kingdom of Bahrain' => 'bhrn',
45 'Republic of Belarus' => 'blru',
46 'Republic of Bolivia' => 'blva',
48 'Republic of Benin' => 'bnin',
49 'Republic of Botswana' => 'bots',
50 'Federative Republic of Brazil' => 'braz',
52 'British Indian Ocean Territory' => 'brin',
53 'Brunei Darussalam' => 'brun',
54 'Republic of Burkina' => 'bufa',
55 'Republic of Bulgaria' => 'bulg',
56 'Republic of Burundi' => 'buru',
57 'Overseas Territory of the British Virgin Islands' => 'bvis',
58 'Central African Republic' => 'cafr',
59 'Kingdom of Cambodia' => 'camb',
60 'Republic of Cameroon' => 'came',
61 'Dominion of Canada' => 'cana',
62 'Caribbean Community' => 'cari',
63 'Republic of Cape Verde' => 'cave',
64 'Republic of Chad' => 'chad',
65 'Republic of Chile' => 'chil',
66 'Territory of Christmas Island' => 'chms',
67 'Commonwealth of Independent States' => 'cins',
68 'Cook Islands' => 'ckis',
69 'Republic of Colombia' => 'clmb',
70 'Territory of Cocos Islands' => 'cois',
71 'Commonwealth' => 'comn',
72 'Union of the Comoros' => 'como',
73 'Republic of the Congo' => 'cong',
74 'Republic of Costa Rica' => 'corc',
75 'Republic of Croatia' => 'croa',
76 'Republic of Cuba' => 'cuba',
77 'British Overseas Territory of the Cayman Islands' => 'cyis',
78 'Republic of Cyprus' => 'cypr',
79 'The Czech Republic' => 'czec',
80 'Kingdom of Denmark' => 'denm',
81 'Republic of Djibouti' => 'djib',
82 'Commonwealth of Dominica' => 'domn',
83 'Dominican Republic' => 'dore',
84 'Republic of Ecuador' => 'ecua',
85 'Arab Republic of Egypt' => 'egyp',
86 'Republic of El Salvador' => 'elsa',
88 'Republic of Equatorial Guinea' => 'eqgu',
89 'State of Eritrea' => 'erit',
90 'Republic of Estonia' => 'estn',
92 'European Union' => 'euun',
93 'British Overseas Territory of the Falkland Islands' => 'fais',
94 'International Federation of Vexillological Associations' => 'fiav',
95 'Republic of Fiji' => 'fiji',
96 'Republic of Finland' => 'finl',
97 'Territory of French Polynesia' => 'fpol',
98 'French Republic' => 'fran',
99 'Overseas Department of French Guiana' => 'frgu',
100 'Gabonese Republic' => 'gabn',
101 'Republic of the Gambia' => 'gamb',
102 'Republic of Georgia' => 'geor',
103 'Federal Republic of Germany' => 'germ',
104 'Republic of Ghana' => 'ghan',
105 'Gibraltar' => 'gibr',
106 'Hellenic Republic' => 'grec',
107 'State of Grenada' => 'gren',
108 'Overseas Department of Guadeloupe' => 'guad',
109 'Territory of Guam' => 'guam',
110 'Republic of Guatemala' => 'guat',
111 'The Bailiwick of Guernsey' => 'guer',
112 'Republic of Guinea' => 'guin',
113 'Republic of Haiti' => 'hait',
114 'Hong Kong Special Administrative Region' => 'hokn',
115 'Republic of Honduras' => 'hond',
116 'Republic of Hungary' => 'hung',
117 'Republic of Iceland' => 'icel',
118 'International Committee of the Red Cross' => 'icrc',
119 'Republic of India' => 'inda',
120 'Republic of Indonesia' => 'indn',
121 'Republic of Iraq' => 'iraq',
122 'Republic of Ireland' => 'irel',
123 'Organization of the Islamic Conference' => 'isco',
124 'Isle of Man' => 'isma',
125 'State of Israel' => 'isra',
126 'Italian Republic' => 'ital',
129 'The Bailiwick of Jersey' => 'jers',
130 'Hashemite Kingdom of Jordan' => 'jord',
131 'Republic of Kazakhstan' => 'kazk',
132 'Republic of Kenya' => 'keny',
133 'Republic of Kiribati' => 'kirb',
134 'State of Kuwait' => 'kuwa',
135 'Kyrgyz Republic' => 'kyrg',
136 'Republic of Latvia' => 'latv',
137 'Lebanese Republic' => 'leba',
138 'Kingdom of Lesotho' => 'lest',
139 'Republic of Liberia' => 'libe',
140 'Principality of Liechtenstein' => 'liec',
141 'Republic of Lithuania' => 'lith',
142 'Grand Duchy of Luxembourg' => 'luxe',
143 'Macao Special Administrative Region' => 'maca',
144 'Republic of Macedonia' => 'mace',
145 'Republic of Madagascar' => 'mada',
146 'Republic of the Marshall Islands' => 'mais',
147 'Republic of Mali' => 'mali',
148 'Federation of Malaysia' => 'mals',
149 'Republic of Malta' => 'malt',
150 'Republic of Malawi' => 'malw',
151 'Overseas Department of Martinique' => 'mart',
152 'Islamic Republic of Mauritania' => 'maur',
153 'Territorial Collectivity of Mayotte' => 'mayt',
154 'United Mexican States' => 'mexc',
155 'Federated States of Micronesia' => 'micr',
156 'Midway Islands' => 'miis',
157 'Republic of Moldova' => 'mold',
158 'Principality of Monaco' => 'mona',
159 'Republic of Mongolia' => 'mong',
160 'British Overseas Territory of Montserrat' => 'mont',
161 'Kingdom of Morocco' => 'morc',
162 'Republic of Mozambique' => 'moza',
163 'Republic of Mauritius' => 'mrts',
164 'Union of Myanmar' => 'myan',
165 'Republic of Namibia' => 'namb',
166 'North Atlantic Treaty Organization' => 'nato',
167 'Republic of Nauru' => 'naur',
168 'Turkish Republic of Northern Cyprus' => 'ncyp',
169 'Netherlands Antilles' => 'nean',
170 'Kingdom of Nepal' => 'nepa',
171 'Kingdom of the Netherlands' => 'neth',
172 'Territory of Norfolk Island' => 'nfis',
173 'Federal Republic of Nigeria' => 'ngra',
174 'Republic of Nicaragua' => 'nica',
175 'Republic of Niger' => 'nigr',
177 'Commonwealth of the Northern Mariana Islands' => 'nmar',
178 'Province of Northern Ireland' => 'noir',
179 'Nordic Council' => 'nord',
180 'Kingdom of Norway' => 'norw',
181 'Territory of New Caledonia and Dependencies' => 'nwca',
182 'New Zealand' => 'nwze',
183 'Organization of American States' => 'oast',
184 'Organization of African Unity' => 'oaun',
185 'International Olympic Committee' => 'olym',
186 'Sultanate of Oman' => 'oman',
187 'Islamic Republic of Pakistan' => 'paks',
188 'Republic of Palau' => 'pala',
189 'Independent State of Papua New Guinea' => 'pang',
190 'Republic of Paraguay' => 'para',
191 'Republic of the Philippines' => 'phil',
192 'British Overseas Territory of the Pitcairn Islands' => 'piis',
193 'Republic of Poland' => 'pola',
194 'Republic of Portugal' => 'port',
195 'Commonwealth of Puerto Rico' => 'purc',
196 'State of Qatar' => 'qata',
197 'Russian Federation' => 'russ',
198 'Republic of Rwanda' => 'rwan',
199 'Kingdom of Saudi Arabia' => 'saar',
200 'Republic of San Marino' => 'sama',
201 'Nordic Sami Conference' => 'sami',
203 'Scotland' => 'scot',
204 'Principality of Seborga' => 'sebo',
205 'Republic of Sierra Leone' => 'sile',
206 'Republic of Singapore' => 'sing',
207 'Republic of Korea' => 'skor',
208 'Republic of Slovenia' => 'slva',
209 'Somali Republic' => 'smla',
210 'Republic of Somaliland' => 'smld',
211 'Republic of South Africa' => 'soaf',
212 'Solomon Islands' => 'sois',
213 'Kingdom of Spain' => 'span',
214 'Secretariat of the Pacific Community' => 'spco',
215 'Democratic Socialist Republic of Sri Lanka' => 'srla',
216 'Saint Lucia' => 'stlu',
217 'Republic of the Sudan' => 'suda',
218 'Republic of Suriname' => 'surn',
219 'Slovak Republic' => 'svka',
220 'Kingdom of Sweden' => 'swdn',
221 'Swiss Confederation' => 'swit',
222 'Syrian Arab Republic' => 'syra',
223 'Kingdom of Swaziland' => 'szld',
224 'Republic of China' => 'taiw',
225 'Republic of Tajikistan' => 'tajk',
226 'United Republic of Tanzania' => 'tanz',
227 'Kingdom of Thailand' => 'thal',
228 'Autonomous Region of Tibet' => 'tibe',
229 'Turkmenistan' => 'tkst',
230 'Togolese Republic' => 'togo',
232 'Kingdom of Tonga' => 'tong',
233 'Tristan da Cunha' => 'trdc',
234 'Tromelin' => 'tris',
235 'Republic of Tunisia' => 'tuns',
236 'Republic of Turkey' => 'turk',
238 'United Arab Emirates' => 'uaem',
239 'Republic of Uganda' => 'ugan',
241 'United Kingdom of Great Britain' => 'unkg',
242 'United Nations' => 'unna',
243 'United States of America' => 'unst',
244 'Oriental Republic of Uruguay' => 'urgy',
245 'Virgin Islands of the United States' => 'usvs',
246 'Republic of Uzbekistan' => 'uzbk',
247 'State of the Vatican City' => 'vacy',
248 'Republic of Vanuatu' => 'vant',
249 'Bolivarian Republic of Venezuela' => 'venz',
250 'Republic of Yemen' => 'yemn',
251 'Democratic Republic of Congo' => 'zare',
252 'Republic of Zimbabwe' => 'zbwe' ) ;
255 var $iFlagCount = -1;
256 var $iFlagSetMap = array(
257 FLAGSIZE1 => 'flags_thumb35x35',
258 FLAGSIZE2 => 'flags_thumb60x60',
259 FLAGSIZE3 => 'flags_thumb100x100',
264 var $iOrdIdx=array();
266 function FlagImages($aSize=FLAGSIZE1) {
272 $file = dirname(__FILE__).'/'.$this->iFlagSetMap[$aSize].'.dat';
273 $fp = fopen($file,'rb');
274 $rawdata = fread($fp,filesize($file));
275 $this->iFlagData = unserialize($rawdata);
278 JpGraphError::Raise('Unknown flag size. ('.$aSize.')');
281 $this->iFlagCount = count($this->iCountryNameMap);
285 return $this->iFlagCount;
288 function GetImgByIdx($aIdx) {
289 if( array_key_exists($aIdx,$this->iFlagData) ) {
290 $d = $this->iFlagData[$aIdx][1];
291 return Image::CreateFromString($d);
294 JpGraphError::Raise("Flag index \" $aIdx\" does not exist.");
298 function GetIdxByOrdinal($aOrd,&$outFullName) {
300 $n = count($this->iOrdIdx);
302 reset($this->iCountryNameMap);
303 $this->iOrdIdx=array();
305 while( list($key,$val) = each($this->iCountryNameMap) ) {
306 $this->iOrdIdx[$i++] = array($val,$key);
308 $tmp=$this->iOrdIdx[$aOrd];
309 $outFullName = $tmp[1];
313 elseif( $aOrd >= 0 && $aOrd < $n ) {
314 $tmp=$this->iOrdIdx[$aOrd];
315 $outFullName = $tmp[1];
319 JpGraphError::Raise('Invalid ordinal number specified for flag index.');
323 function GetIdxByName($aName,&$outFullName) {
325 if( is_integer($aName) ) {
326 $idx = $this->GetIdxByOrdinal($aName,$outFullName);
331 $aName = strtolower($aName);
332 $nlen = strlen($aName);
333 reset($this->iCountryNameMap);
334 // Match partial full country name or exact idx name
335 while( list($key,$val) = each($this->iCountryNameMap) ) {
336 if( strpos(strtolower($key), $aName) !== false ||
337 ($nlen == strlen($val) && $val == $aName) ) {
347 JpGraphError::Raise("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\".");