Skip to content

Commit 8ab97c0

Browse files
committed
chg: [UI] Use IconHelper for flag icons
1 parent 813a475 commit 8ab97c0

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

app/View/Elements/galaxyQuickView.ctp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
} else if($cluster_field['key'] == 'country') {
3939
$value = array();
4040
foreach ($cluster_field['value'] as $k => $v) {
41-
$value[] = '<div class="famfamfam-flag-' . strtolower(h($v)) . '" ></div>&nbsp;' . h($v);
41+
$value[] = $this->Icon->countryFlag($v) . '&nbsp;' . h($v);
4242
}
4343
$dataValue .= nl2br(implode("\n", $value));
4444
} else {

app/View/Elements/galaxyQuickViewMini.ctp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
} else if($cluster_field['key'] == 'country') {
4646
$value = array();
4747
foreach ($cluster_field['value'] as $k => $v) {
48-
$value[] = '<span class="famfamfam-flag-' . strtolower(h($v)) . '" ></span>&nbsp;' . h($v);
48+
$value[] = $this->Icon->countryFlag($v) . '&nbsp;' . h($v);
4949
}
5050
$value_contents = nl2br(implode("\n", $value));
5151
} else {

app/View/Helper/IconHelper.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
App::uses('AppHelper', 'View/Helper');
3+
4+
class IconHelper extends AppHelper {
5+
/**
6+
* @param string $countryCode ISO 3166-1 alpha-2 two-letter country code
7+
* @return string
8+
*/
9+
public function countryFlag($countryCode)
10+
{
11+
if (strlen($countryCode) !== 2) {
12+
return '';
13+
}
14+
15+
return '<span class="famfamfam-flag-' . strtolower(h($countryCode)) . '" ></span>';
16+
/* Unicode version
17+
$output = '';
18+
foreach (str_split(strtolower($countryCode)) as $letter) {
19+
$letterCode = ord($letter);
20+
if ($letterCode < 97 || $letterCode > 122) {
21+
return ''; // invalid letter
22+
}
23+
24+
// UTF-8 representation
25+
$output .= "\xF0\x9F\x87" . chr(0xa6 + ($letterCode - 97));
26+
}
27+
28+
return $output;*/
29+
}
30+
}

app/View/Organisations/index.ctp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ foreach ($orgs as $org): ?>
119119
<td ondblclick="document.location.href ='<?php echo $baseurl . "/organisations/view/" . $org['Organisation']['id'];?>'"><?php echo h($org['Organisation']['description']); ?></td>
120120
<td class="short" ondblclick="document.location.href ='<?php echo $baseurl . "/organisations/view/" . $org['Organisation']['id'];?>'"><?php
121121
if (isset($org['Organisation']['country_code'])) {
122-
echo '<span class="famfamfam-flag-' . strtolower(h($org['Organisation']['country_code'])) . '" ></span>&nbsp;';
122+
echo $this->Icon->countryFlag($org['Organisation']['country_code']) . '&nbsp;';
123123
}
124124
if ($org['Organisation']['nationality'] !== 'Not specified') {
125125
echo h($org['Organisation']['nationality']);

app/View/Organisations/view.ctp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
if (!empty(trim($org['Organisation']['nationality']))) {
3434
$html = '';
3535
if (isset($org['Organisation']['country_code'])) {
36-
$html .= '<span class="famfamfam-flag-' . strtolower(h($org['Organisation']['country_code'])) . '" ></span>&nbsp;';
36+
$html .= $this->Icon->countryFlag($org['Organisation']['country_code']) . '&nbsp;';
3737
}
3838
$html .= trim(h($org['Organisation']['nationality']));
3939
$table_data[] = array(

0 commit comments

Comments
 (0)