1 | <?php |
---|
2 | //======================================================================= |
---|
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 | // |
---|
8 | // Copyright (c) Asial Corporation. All rights reserved. |
---|
9 | //======================================================================== |
---|
10 | |
---|
11 | //------------------------------------------------------------ |
---|
12 | // Defines for the different basic sizes of flags |
---|
13 | //------------------------------------------------------------ |
---|
14 | DEFINE('FLAGSIZE1',1); |
---|
15 | DEFINE('FLAGSIZE2',2); |
---|
16 | DEFINE('FLAGSIZE3',3); |
---|
17 | DEFINE('FLAGSIZE4',4); |
---|
18 | |
---|
19 | class FlagImages { |
---|
20 | |
---|
21 | public $iCountryNameMap = array( |
---|
22 | 'Afghanistan' => 'afgh', |
---|
23 | 'Republic of Angola' => 'agla', |
---|
24 | 'Republic of Albania' => 'alba', |
---|
25 | 'Alderney' => 'alde', |
---|
26 | 'Democratic and Popular Republic of Algeria' => 'alge', |
---|
27 | 'Territory of American Samoa' => 'amsa', |
---|
28 | 'Principality of Andorra' => 'andr', |
---|
29 | 'British Overseas Territory of Anguilla' => 'angu', |
---|
30 | 'Antarctica' => 'anta', |
---|
31 | 'Argentine Republic' => 'arge', |
---|
32 | 'League of Arab States' => 'arle', |
---|
33 | 'Republic of Armenia' => 'arme', |
---|
34 | 'Aruba' => 'arub', |
---|
35 | 'Commonwealth of Australia' => 'astl', |
---|
36 | 'Republic of Austria' => 'aust', |
---|
37 | 'Azerbaijani Republic' => 'azer', |
---|
38 | 'Bangladesh' => 'bngl', |
---|
39 | 'British Antarctic Territory' => 'bant', |
---|
40 | 'Kingdom of Belgium' => 'belg', |
---|
41 | 'British Overseas Territory of Bermuda' => 'berm', |
---|
42 | 'Commonwealth of the Bahamas' => 'bhms', |
---|
43 | 'Kingdom of Bahrain' => 'bhrn', |
---|
44 | 'Republic of Belarus' => 'blru', |
---|
45 | 'Republic of Bolivia' => 'blva', |
---|
46 | 'Belize' => 'blze', |
---|
47 | 'Republic of Benin' => 'bnin', |
---|
48 | 'Republic of Botswana' => 'bots', |
---|
49 | 'Federative Republic of Brazil' => 'braz', |
---|
50 | 'Barbados' => 'brbd', |
---|
51 | 'British Indian Ocean Territory' => 'brin', |
---|
52 | 'Brunei Darussalam' => 'brun', |
---|
53 | 'Republic of Burkina' => 'bufa', |
---|
54 | 'Republic of Bulgaria' => 'bulg', |
---|
55 | 'Republic of Burundi' => 'buru', |
---|
56 | 'Overseas Territory of the British Virgin Islands' => 'bvis', |
---|
57 | 'Central African Republic' => 'cafr', |
---|
58 | 'Kingdom of Cambodia' => 'camb', |
---|
59 | 'Republic of Cameroon' => 'came', |
---|
60 | 'Dominion of Canada' => 'cana', |
---|
61 | 'Caribbean Community' => 'cari', |
---|
62 | 'Republic of Cape Verde' => 'cave', |
---|
63 | 'Republic of Chad' => 'chad', |
---|
64 | 'Republic of Chile' => 'chil', |
---|
65 | 'Peoples Republic of China' => 'chin', |
---|
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', |
---|
87 | 'England' => 'engl', |
---|
88 | 'Republic of Equatorial Guinea' => 'eqgu', |
---|
89 | 'State of Eritrea' => 'erit', |
---|
90 | 'Republic of Estonia' => 'estn', |
---|
91 | 'Ethiopia' => 'ethp', |
---|
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', |
---|
127 | 'Jamaica' => 'jama', |
---|
128 | 'Japan' => 'japa', |
---|
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', |
---|
176 | 'Niue' => 'niue', |
---|
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 Peru' => 'peru', |
---|
192 | 'Republic of the Philippines' => 'phil', |
---|
193 | 'British Overseas Territory of the Pitcairn Islands' => 'piis', |
---|
194 | 'Republic of Poland' => 'pola', |
---|
195 | 'Republic of Portugal' => 'port', |
---|
196 | 'Commonwealth of Puerto Rico' => 'purc', |
---|
197 | 'State of Qatar' => 'qata', |
---|
198 | 'Russian Federation' => 'russ', |
---|
199 | 'Romania' => 'rmna', |
---|
200 | 'Republic of Rwanda' => 'rwan', |
---|
201 | 'Kingdom of Saudi Arabia' => 'saar', |
---|
202 | 'Republic of San Marino' => 'sama', |
---|
203 | 'Nordic Sami Conference' => 'sami', |
---|
204 | 'Sark' => 'sark', |
---|
205 | 'Scotland' => 'scot', |
---|
206 | 'Principality of Seborga' => 'sebo', |
---|
207 | 'Republic of Serbia' => 'serb', |
---|
208 | 'Republic of Sierra Leone' => 'sile', |
---|
209 | 'Republic of Singapore' => 'sing', |
---|
210 | 'Republic of Korea' => 'skor', |
---|
211 | 'Republic of Slovenia' => 'slva', |
---|
212 | 'Somali Republic' => 'smla', |
---|
213 | 'Republic of Somaliland' => 'smld', |
---|
214 | 'Republic of South Africa' => 'soaf', |
---|
215 | 'Solomon Islands' => 'sois', |
---|
216 | 'Kingdom of Spain' => 'span', |
---|
217 | 'Secretariat of the Pacific Community' => 'spco', |
---|
218 | 'Democratic Socialist Republic of Sri Lanka' => 'srla', |
---|
219 | 'Saint Lucia' => 'stlu', |
---|
220 | 'Republic of the Sudan' => 'suda', |
---|
221 | 'Republic of Suriname' => 'surn', |
---|
222 | 'Slovak Republic' => 'svka', |
---|
223 | 'Kingdom of Sweden' => 'swdn', |
---|
224 | 'Swiss Confederation' => 'swit', |
---|
225 | 'Syrian Arab Republic' => 'syra', |
---|
226 | 'Kingdom of Swaziland' => 'szld', |
---|
227 | 'Republic of China' => 'taiw', |
---|
228 | 'Taiwan' => 'taiw', |
---|
229 | 'Republic of Tajikistan' => 'tajk', |
---|
230 | 'United Republic of Tanzania' => 'tanz', |
---|
231 | 'Kingdom of Thailand' => 'thal', |
---|
232 | 'Autonomous Region of Tibet' => 'tibe', |
---|
233 | 'Turkmenistan' => 'tkst', |
---|
234 | 'Togolese Republic' => 'togo', |
---|
235 | 'Tokelau' => 'toke', |
---|
236 | 'Kingdom of Tonga' => 'tong', |
---|
237 | 'Tristan da Cunha' => 'trdc', |
---|
238 | 'Tromelin' => 'tris', |
---|
239 | 'Republic of Tunisia' => 'tuns', |
---|
240 | 'Republic of Turkey' => 'turk', |
---|
241 | 'Tuvalu' => 'tuva', |
---|
242 | 'United Arab Emirates' => 'uaem', |
---|
243 | 'Republic of Uganda' => 'ugan', |
---|
244 | 'Ukraine' => 'ukrn', |
---|
245 | 'United Kingdom of Great Britain' => 'unkg', |
---|
246 | 'United Nations' => 'unna', |
---|
247 | 'United States of America' => 'unst', |
---|
248 | 'Oriental Republic of Uruguay' => 'urgy', |
---|
249 | 'Virgin Islands of the United States' => 'usvs', |
---|
250 | 'Republic of Uzbekistan' => 'uzbk', |
---|
251 | 'State of the Vatican City' => 'vacy', |
---|
252 | 'Republic of Vanuatu' => 'vant', |
---|
253 | 'Bolivarian Republic of Venezuela' => 'venz', |
---|
254 | 'Republic of Yemen' => 'yemn', |
---|
255 | 'Democratic Republic of Congo' => 'zare', |
---|
256 | 'Republic of Zimbabwe' => 'zbwe' ) ; |
---|
257 | |
---|
258 | |
---|
259 | private $iFlagCount = -1; |
---|
260 | private $iFlagSetMap = array( |
---|
261 | FLAGSIZE1 => 'flags_thumb35x35', |
---|
262 | FLAGSIZE2 => 'flags_thumb60x60', |
---|
263 | FLAGSIZE3 => 'flags_thumb100x100', |
---|
264 | FLAGSIZE4 => 'flags' |
---|
265 | ); |
---|
266 | |
---|
267 | private $iFlagData ; |
---|
268 | private $iOrdIdx=array(); |
---|
269 | |
---|
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); |
---|
286 | } |
---|
287 | |
---|
288 | function GetNum() { |
---|
289 | return $this->iFlagCount; |
---|
290 | } |
---|
291 | |
---|
292 | function GetImgByName($aName,&$outFullName) { |
---|
293 | $idx = $this->GetIdxByName($aName,$outFullName); |
---|
294 | return $this->GetImgByIdx($idx); |
---|
295 | } |
---|
296 | |
---|
297 | 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 | } |
---|
306 | } |
---|
307 | |
---|
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 | } |
---|
332 | } |
---|
333 | |
---|
334 | function GetIdxByName($aName,&$outFullName) { |
---|
335 | |
---|
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 | } |
---|
370 | } |
---|
371 | } |
---|
372 | |
---|
373 | |
---|
374 | |
---|
375 | |
---|
376 | ?> |
---|