1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* JPGraph v4.0.3 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Amenadiel\JpGraph\Image; |
8
|
|
|
|
9
|
|
|
use Amenadiel\JpGraph\Util; |
10
|
|
|
|
11
|
|
|
/* |
12
|
|
|
* File: JPGRAPH_FLAGS.PHP |
13
|
|
|
* // Description: Class Jpfile. Handles plotmarks |
14
|
|
|
* // Created: 2003-06-28 |
15
|
|
|
* // Ver: $Id: jpgraph_flags.php 1106 2009-02-22 20:16:35Z ljp $ |
16
|
|
|
* // |
17
|
|
|
* // Copyright (c) Asial Corporation. All rights reserved. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/* |
21
|
|
|
* Defines for the different basic sizes of flags |
22
|
|
|
*/ |
23
|
1 |
|
define('FLAGSIZE1', 1); |
24
|
1 |
|
define('FLAGSIZE2', 2); |
25
|
1 |
|
define('FLAGSIZE3', 3); |
26
|
1 |
|
define('FLAGSIZE4', 4); |
27
|
|
|
|
28
|
|
|
class FlagImages |
29
|
|
|
{ |
30
|
|
|
public $iCountryNameMap = [ |
31
|
|
|
'Afghanistan' => 'afgh', |
32
|
|
|
'Republic of Angola' => 'agla', |
33
|
|
|
'Republic of Albania' => 'alba', |
34
|
|
|
'Alderney' => 'alde', |
35
|
|
|
'Democratic and Popular Republic of Algeria' => 'alge', |
36
|
|
|
'Territory of American Samoa' => 'amsa', |
37
|
|
|
'Principality of Andorra' => 'andr', |
38
|
|
|
'British Overseas Territory of Anguilla' => 'angu', |
39
|
|
|
'Antarctica' => 'anta', |
40
|
|
|
'Argentine Republic' => 'arge', |
41
|
|
|
'League of Arab States' => 'arle', |
42
|
|
|
'Republic of Armenia' => 'arme', |
43
|
|
|
'Aruba' => 'arub', |
44
|
|
|
'Commonwealth of Australia' => 'astl', |
45
|
|
|
'Republic of Austria' => 'aust', |
46
|
|
|
'Azerbaijani Republic' => 'azer', |
47
|
|
|
'Bangladesh' => 'bngl', |
48
|
|
|
'British Antarctic Territory' => 'bant', |
49
|
|
|
'Kingdom of Belgium' => 'belg', |
50
|
|
|
'British Overseas Territory of Bermuda' => 'berm', |
51
|
|
|
'Commonwealth of the Bahamas' => 'bhms', |
52
|
|
|
'Kingdom of Bahrain' => 'bhrn', |
53
|
|
|
'Republic of Belarus' => 'blru', |
54
|
|
|
'Republic of Bolivia' => 'blva', |
55
|
|
|
'Belize' => 'blze', |
56
|
|
|
'Republic of Benin' => 'bnin', |
57
|
|
|
'Republic of Botswana' => 'bots', |
58
|
|
|
'Federative Republic of Brazil' => 'braz', |
59
|
|
|
'Barbados' => 'brbd', |
60
|
|
|
'British Indian Ocean Territory' => 'brin', |
61
|
|
|
'Brunei Darussalam' => 'brun', |
62
|
|
|
'Republic of Burkina' => 'bufa', |
63
|
|
|
'Republic of Bulgaria' => 'bulg', |
64
|
|
|
'Republic of Burundi' => 'buru', |
65
|
|
|
'Overseas Territory of the British Virgin Islands' => 'bvis', |
66
|
|
|
'Central African Republic' => 'cafr', |
67
|
|
|
'Kingdom of Cambodia' => 'camb', |
68
|
|
|
'Republic of Cameroon' => 'came', |
69
|
|
|
'Dominion of Canada' => 'cana', |
70
|
|
|
'Caribbean Community' => 'cari', |
71
|
|
|
'Republic of Cape Verde' => 'cave', |
72
|
|
|
'Republic of Chad' => 'chad', |
73
|
|
|
'Republic of Chile' => 'chil', |
74
|
|
|
'Peoples Republic of China' => 'chin', |
75
|
|
|
'Territory of Christmas Island' => 'chms', |
76
|
|
|
'Commonwealth of Independent States' => 'cins', |
77
|
|
|
'Cook Islands' => 'ckis', |
78
|
|
|
'Republic of Colombia' => 'clmb', |
79
|
|
|
'Territory of Cocos Islands' => 'cois', |
80
|
|
|
'Commonwealth' => 'comn', |
81
|
|
|
'Union of the Comoros' => 'como', |
82
|
|
|
'Republic of the Congo' => 'cong', |
83
|
|
|
'Republic of Costa Rica' => 'corc', |
84
|
|
|
'Republic of Croatia' => 'croa', |
85
|
|
|
'Republic of Cuba' => 'cuba', |
86
|
|
|
'British Overseas Territory of the Cayman Islands' => 'cyis', |
87
|
|
|
'Republic of Cyprus' => 'cypr', |
88
|
|
|
'The Czech Republic' => 'czec', |
89
|
|
|
'Kingdom of Denmark' => 'denm', |
90
|
|
|
'Republic of Djibouti' => 'djib', |
91
|
|
|
'Commonwealth of Dominica' => 'domn', |
92
|
|
|
'Dominican Republic' => 'dore', |
93
|
|
|
'Republic of Ecuador' => 'ecua', |
94
|
|
|
'Arab Republic of Egypt' => 'egyp', |
95
|
|
|
'Republic of El Salvador' => 'elsa', |
96
|
|
|
'England' => 'engl', |
97
|
|
|
'Republic of Equatorial Guinea' => 'eqgu', |
98
|
|
|
'State of Eritrea' => 'erit', |
99
|
|
|
'Republic of Estonia' => 'estn', |
100
|
|
|
'Ethiopia' => 'ethp', |
101
|
|
|
'European Union' => 'euun', |
102
|
|
|
'British Overseas Territory of the Falkland Islands' => 'fais', |
103
|
|
|
'International Federation of Vexillological Associations' => 'fiav', |
104
|
|
|
'Republic of Fiji' => 'fiji', |
105
|
|
|
'Republic of Finland' => 'finl', |
106
|
|
|
'Territory of French Polynesia' => 'fpol', |
107
|
|
|
'French Republic' => 'fran', |
108
|
|
|
'Overseas Department of French Guiana' => 'frgu', |
109
|
|
|
'Gabonese Republic' => 'gabn', |
110
|
|
|
'Republic of the Gambia' => 'gamb', |
111
|
|
|
'Republic of Georgia' => 'geor', |
112
|
|
|
'Federal Republic of Germany' => 'germ', |
113
|
|
|
'Republic of Ghana' => 'ghan', |
114
|
|
|
'Gibraltar' => 'gibr', |
115
|
|
|
'Hellenic Republic' => 'grec', |
116
|
|
|
'State of Grenada' => 'gren', |
117
|
|
|
'Overseas Department of Guadeloupe' => 'guad', |
118
|
|
|
'Territory of Guam' => 'guam', |
119
|
|
|
'Republic of Guatemala' => 'guat', |
120
|
|
|
'The Bailiwick of Guernsey' => 'guer', |
121
|
|
|
'Republic of Guinea' => 'guin', |
122
|
|
|
'Republic of Haiti' => 'hait', |
123
|
|
|
'Hong Kong Special Administrative Region' => 'hokn', |
124
|
|
|
'Republic of Honduras' => 'hond', |
125
|
|
|
'Republic of Hungary' => 'hung', |
126
|
|
|
'Republic of Iceland' => 'icel', |
127
|
|
|
'International Committee of the Red Cross' => 'icrc', |
128
|
|
|
'Republic of India' => 'inda', |
129
|
|
|
'Republic of Indonesia' => 'indn', |
130
|
|
|
'Republic of Iraq' => 'iraq', |
131
|
|
|
'Republic of Ireland' => 'irel', |
132
|
|
|
'Organization of the Islamic Conference' => 'isco', |
133
|
|
|
'Isle of Man' => 'isma', |
134
|
|
|
'State of Israel' => 'isra', |
135
|
|
|
'Italian Republic' => 'ital', |
136
|
|
|
'Jamaica' => 'jama', |
137
|
|
|
'Japan' => 'japa', |
138
|
|
|
'The Bailiwick of Jersey' => 'jers', |
139
|
|
|
'Hashemite Kingdom of Jordan' => 'jord', |
140
|
|
|
'Republic of Kazakhstan' => 'kazk', |
141
|
|
|
'Republic of Kenya' => 'keny', |
142
|
|
|
'Republic of Kiribati' => 'kirb', |
143
|
|
|
'State of Kuwait' => 'kuwa', |
144
|
|
|
'Kyrgyz Republic' => 'kyrg', |
145
|
|
|
'Republic of Latvia' => 'latv', |
146
|
|
|
'Lebanese Republic' => 'leba', |
147
|
|
|
'Kingdom of Lesotho' => 'lest', |
148
|
|
|
'Republic of Liberia' => 'libe', |
149
|
|
|
'Principality of Liechtenstein' => 'liec', |
150
|
|
|
'Republic of Lithuania' => 'lith', |
151
|
|
|
'Grand Duchy of Luxembourg' => 'luxe', |
152
|
|
|
'Macao Special Administrative Region' => 'maca', |
153
|
|
|
'Republic of Macedonia' => 'mace', |
154
|
|
|
'Republic of Madagascar' => 'mada', |
155
|
|
|
'Republic of the Marshall Islands' => 'mais', |
156
|
|
|
'Republic of Mali' => 'mali', |
157
|
|
|
'Federation of Malaysia' => 'mals', |
158
|
|
|
'Republic of Malta' => 'malt', |
159
|
|
|
'Republic of Malawi' => 'malw', |
160
|
|
|
'Overseas Department of Martinique' => 'mart', |
161
|
|
|
'Islamic Republic of Mauritania' => 'maur', |
162
|
|
|
'Territorial Collectivity of Mayotte' => 'mayt', |
163
|
|
|
'United Mexican States' => 'mexc', |
164
|
|
|
'Federated States of Micronesia' => 'micr', |
165
|
|
|
'Midway Islands' => 'miis', |
166
|
|
|
'Republic of Moldova' => 'mold', |
167
|
|
|
'Principality of Monaco' => 'mona', |
168
|
|
|
'Republic of Mongolia' => 'mong', |
169
|
|
|
'British Overseas Territory of Montserrat' => 'mont', |
170
|
|
|
'Kingdom of Morocco' => 'morc', |
171
|
|
|
'Republic of Mozambique' => 'moza', |
172
|
|
|
'Republic of Mauritius' => 'mrts', |
173
|
|
|
'Union of Myanmar' => 'myan', |
174
|
|
|
'Republic of Namibia' => 'namb', |
175
|
|
|
'North Atlantic Treaty Organization' => 'nato', |
176
|
|
|
'Republic of Nauru' => 'naur', |
177
|
|
|
'Turkish Republic of Northern Cyprus' => 'ncyp', |
178
|
|
|
'Netherlands Antilles' => 'nean', |
179
|
|
|
'Kingdom of Nepal' => 'nepa', |
180
|
|
|
'Kingdom of the Netherlands' => 'neth', |
181
|
|
|
'Territory of Norfolk Island' => 'nfis', |
182
|
|
|
'Federal Republic of Nigeria' => 'ngra', |
183
|
|
|
'Republic of Nicaragua' => 'nica', |
184
|
|
|
'Republic of Niger' => 'nigr', |
185
|
|
|
'Niue' => 'niue', |
186
|
|
|
'Commonwealth of the Northern Mariana Islands' => 'nmar', |
187
|
|
|
'Province of Northern Ireland' => 'noir', |
188
|
|
|
'Nordic Council' => 'nord', |
189
|
|
|
'Kingdom of Norway' => 'norw', |
190
|
|
|
'Territory of New Caledonia and Dependencies' => 'nwca', |
191
|
|
|
'New Zealand' => 'nwze', |
192
|
|
|
'Organization of American States' => 'oast', |
193
|
|
|
'Organization of African Unity' => 'oaun', |
194
|
|
|
'International Olympic Committee' => 'olym', |
195
|
|
|
'Sultanate of Oman' => 'oman', |
196
|
|
|
'Islamic Republic of Pakistan' => 'paks', |
197
|
|
|
'Republic of Palau' => 'pala', |
198
|
|
|
'Independent State of Papua New Guinea' => 'pang', |
199
|
|
|
'Republic of Paraguay' => 'para', |
200
|
|
|
'Republic of Peru' => 'peru', |
201
|
|
|
'Republic of the Philippines' => 'phil', |
202
|
|
|
'British Overseas Territory of the Pitcairn Islands' => 'piis', |
203
|
|
|
'Republic of Poland' => 'pola', |
204
|
|
|
'Republic of Portugal' => 'port', |
205
|
|
|
'Commonwealth of Puerto Rico' => 'purc', |
206
|
|
|
'State of Qatar' => 'qata', |
207
|
|
|
'Russian Federation' => 'russ', |
208
|
|
|
'Romania' => 'rmna', |
209
|
|
|
'Republic of Rwanda' => 'rwan', |
210
|
|
|
'Kingdom of Saudi Arabia' => 'saar', |
211
|
|
|
'Republic of San Marino' => 'sama', |
212
|
|
|
'Nordic Sami Conference' => 'sami', |
213
|
|
|
'Sark' => 'sark', |
214
|
|
|
'Scotland' => 'scot', |
215
|
|
|
'Principality of Seborga' => 'sebo', |
216
|
|
|
'Republic of Serbia' => 'serb', |
217
|
|
|
'Republic of Sierra Leone' => 'sile', |
218
|
|
|
'Republic of Singapore' => 'sing', |
219
|
|
|
'Republic of Korea' => 'skor', |
220
|
|
|
'Republic of Slovenia' => 'slva', |
221
|
|
|
'Somali Republic' => 'smla', |
222
|
|
|
'Republic of Somaliland' => 'smld', |
223
|
|
|
'Republic of South Africa' => 'soaf', |
224
|
|
|
'Solomon Islands' => 'sois', |
225
|
|
|
'Kingdom of Spain' => 'span', |
226
|
|
|
'Secretariat of the Pacific Community' => 'spco', |
227
|
|
|
'Democratic Socialist Republic of Sri Lanka' => 'srla', |
228
|
|
|
'Saint Lucia' => 'stlu', |
229
|
|
|
'Republic of the Sudan' => 'suda', |
230
|
|
|
'Republic of Suriname' => 'surn', |
231
|
|
|
'Slovak Republic' => 'svka', |
232
|
|
|
'Kingdom of Sweden' => 'swdn', |
233
|
|
|
'Swiss Confederation' => 'swit', |
234
|
|
|
'Syrian Arab Republic' => 'syra', |
235
|
|
|
'Kingdom of Swaziland' => 'szld', |
236
|
|
|
'Republic of China' => 'taiw', |
237
|
|
|
'Taiwan' => 'taiw', |
238
|
|
|
'Republic of Tajikistan' => 'tajk', |
239
|
|
|
'United Republic of Tanzania' => 'tanz', |
240
|
|
|
'Kingdom of Thailand' => 'thal', |
241
|
|
|
'Autonomous Region of Tibet' => 'tibe', |
242
|
|
|
'Turkmenistan' => 'tkst', |
243
|
|
|
'Togolese Republic' => 'togo', |
244
|
|
|
'Tokelau' => 'toke', |
245
|
|
|
'Kingdom of Tonga' => 'tong', |
246
|
|
|
'Tristan da Cunha' => 'trdc', |
247
|
|
|
'Tromelin' => 'tris', |
248
|
|
|
'Republic of Tunisia' => 'tuns', |
249
|
|
|
'Republic of Turkey' => 'turk', |
250
|
|
|
'Tuvalu' => 'tuva', |
251
|
|
|
'United Arab Emirates' => 'uaem', |
252
|
|
|
'Republic of Uganda' => 'ugan', |
253
|
|
|
'Ukraine' => 'ukrn', |
254
|
|
|
'United Kingdom of Great Britain' => 'unkg', |
255
|
|
|
'United Nations' => 'unna', |
256
|
|
|
'United States of America' => 'unst', |
257
|
|
|
'Oriental Republic of Uruguay' => 'urgy', |
258
|
|
|
'Virgin Islands of the United States' => 'usvs', |
259
|
|
|
'Republic of Uzbekistan' => 'uzbk', |
260
|
|
|
'State of the Vatican City' => 'vacy', |
261
|
|
|
'Republic of Vanuatu' => 'vant', |
262
|
|
|
'Bolivarian Republic of Venezuela' => 'venz', |
263
|
|
|
'Republic of Yemen' => 'yemn', |
264
|
|
|
'Democratic Republic of Congo' => 'zare', |
265
|
|
|
'Republic of Zimbabwe' => 'zbwe', ]; |
266
|
|
|
|
267
|
|
|
private $iFlagCount = -1; |
268
|
|
|
private $iFlagSetMap = [ |
269
|
|
|
FLAGSIZE1 => 'flags_thumb35x35', |
270
|
|
|
FLAGSIZE2 => 'flags_thumb60x60', |
271
|
|
|
FLAGSIZE3 => 'flags_thumb100x100', |
272
|
|
|
FLAGSIZE4 => 'flags', |
273
|
|
|
]; |
274
|
|
|
|
275
|
|
|
private $iFlagData; |
276
|
|
|
private $iOrdIdx = []; |
277
|
|
|
|
278
|
2 |
|
public function __construct($aSize = FLAGSIZE1) |
279
|
|
|
{ |
280
|
|
|
switch ($aSize) { |
281
|
2 |
|
case FLAGSIZE1: |
282
|
1 |
|
case FLAGSIZE2: |
283
|
1 |
|
case FLAGSIZE3: |
284
|
1 |
|
case FLAGSIZE4: |
285
|
2 |
|
$file = __DIR__ . '/../flags/' . $this->iFlagSetMap[$aSize] . '.dat'; |
286
|
2 |
|
$fp = fopen($file, 'rb'); |
287
|
2 |
|
$rawdata = fread($fp, filesize($file)); |
288
|
2 |
|
$this->iFlagData = unserialize($rawdata); |
289
|
|
|
|
290
|
2 |
|
break; |
291
|
|
|
default: |
292
|
|
|
Util\JpGraphError::RaiseL(5001, $aSize); |
293
|
|
|
//('Unknown flag size. ('.$aSize.')'); |
294
|
|
|
} |
295
|
2 |
|
$this->iFlagCount = safe_count($this->iCountryNameMap); |
296
|
2 |
|
} |
297
|
|
|
|
298
|
|
|
public function GetNum() |
299
|
|
|
{ |
300
|
|
|
return $this->iFlagCount; |
301
|
|
|
} |
302
|
|
|
|
303
|
1 |
|
public function GetImgByName($aName, &$outFullName) |
304
|
|
|
{ |
305
|
1 |
|
$idx = $this->GetIdxByName($aName, $outFullName); |
306
|
|
|
|
307
|
1 |
|
return $this->GetImgByIdx($idx); |
308
|
|
|
} |
309
|
|
|
|
310
|
2 |
|
public function GetImgByIdx($aIdx) |
311
|
|
|
{ |
312
|
2 |
|
if (array_key_exists($aIdx, $this->iFlagData)) { |
313
|
2 |
|
$d = $this->iFlagData[$aIdx][1]; |
314
|
|
|
|
315
|
2 |
|
return Image::CreateFromString($d); |
316
|
|
|
} |
317
|
|
|
Util\JpGraphError::RaiseL(5002, $aIdx); |
318
|
|
|
//("Flag index \"�$aIdx\" does not exist."); |
319
|
|
|
} |
320
|
|
|
|
321
|
1 |
|
public function GetIdxByOrdinal($aOrd, &$outFullName) |
322
|
|
|
{ |
323
|
1 |
|
--$aOrd; |
324
|
1 |
|
$n = safe_count($this->iOrdIdx); |
325
|
1 |
|
if ($n == 0) { |
326
|
1 |
|
reset($this->iCountryNameMap); |
327
|
1 |
|
$this->iOrdIdx = []; |
328
|
1 |
|
$i = 0; |
329
|
1 |
|
foreach ($this->iCountryNameMap as $key => $val) { |
330
|
1 |
|
$this->iOrdIdx[$i++] = [$val, $key]; |
331
|
|
|
} |
332
|
1 |
|
$tmp = $this->iOrdIdx[$aOrd]; |
333
|
1 |
|
$outFullName = $tmp[1]; |
334
|
|
|
|
335
|
1 |
|
return $tmp[0]; |
336
|
|
|
} |
337
|
1 |
|
if ($aOrd >= 0 && $aOrd < $n) { |
338
|
1 |
|
$tmp = $this->iOrdIdx[$aOrd]; |
339
|
1 |
|
$outFullName = $tmp[1]; |
340
|
|
|
|
341
|
1 |
|
return $tmp[0]; |
342
|
|
|
} |
343
|
|
|
Util\JpGraphError::RaiseL(5003, $aOrd); |
344
|
|
|
//('Invalid ordinal number specified for flag index.'); |
345
|
|
|
} |
346
|
|
|
|
347
|
2 |
|
public function GetIdxByName($aName, &$outFullName) |
348
|
|
|
{ |
349
|
2 |
|
if (is_integer($aName)) { |
350
|
1 |
|
$idx = $this->GetIdxByOrdinal($aName, $outFullName); |
351
|
|
|
|
352
|
1 |
|
return $idx; |
353
|
|
|
} |
354
|
|
|
|
355
|
2 |
|
$found = false; |
356
|
2 |
|
$aName = strtolower($aName); |
357
|
2 |
|
$nlen = strlen($aName); |
358
|
2 |
|
reset($this->iCountryNameMap); |
359
|
|
|
// Start by trying to match exact index name |
360
|
2 |
|
foreach ($this->iCountryNameMap as $key => $val) { |
361
|
2 |
|
if ($nlen == strlen($val) && $val == $aName) { |
362
|
1 |
|
$found = true; |
363
|
|
|
|
364
|
2 |
|
break; |
365
|
|
|
} |
366
|
|
|
} |
367
|
2 |
|
if (!$found) { |
368
|
1 |
|
reset($this->iCountryNameMap); |
369
|
|
|
// If the exact index doesn't work try a (partial) full name |
370
|
1 |
|
foreach ($this->iCountryNameMap as $key => $val) { |
371
|
1 |
|
if (strpos(strtolower($key), $aName) !== false) { |
372
|
1 |
|
$found = true; |
373
|
|
|
|
374
|
1 |
|
break; |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
} |
378
|
2 |
|
if ($found) { |
379
|
2 |
|
$outFullName = $key; |
|
|
|
|
380
|
|
|
|
381
|
2 |
|
return $val; |
|
|
|
|
382
|
|
|
} |
383
|
|
|
Util\JpGraphError::RaiseL(5004, $aName); |
384
|
|
|
//("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\"."); |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
|