chg: [UI] Use IconHelper for flag icons

pull/6414/head
Jakub Onderka 2020-10-09 23:21:18 +02:00
parent 813a475f4a
commit 8ab97c074b
5 changed files with 34 additions and 4 deletions

View File

@ -38,7 +38,7 @@
} else if($cluster_field['key'] == 'country') {
$value = array();
foreach ($cluster_field['value'] as $k => $v) {
$value[] = '<div class="famfamfam-flag-' . strtolower(h($v)) . '" ></div>&nbsp;' . h($v);
$value[] = $this->Icon->countryFlag($v) . '&nbsp;' . h($v);
}
$dataValue .= nl2br(implode("\n", $value));
} else {

View File

@ -45,7 +45,7 @@
} else if($cluster_field['key'] == 'country') {
$value = array();
foreach ($cluster_field['value'] as $k => $v) {
$value[] = '<span class="famfamfam-flag-' . strtolower(h($v)) . '" ></span>&nbsp;' . h($v);
$value[] = $this->Icon->countryFlag($v) . '&nbsp;' . h($v);
}
$value_contents = nl2br(implode("\n", $value));
} else {

View File

@ -0,0 +1,30 @@
<?php
App::uses('AppHelper', 'View/Helper');
class IconHelper extends AppHelper {
/**
* @param string $countryCode ISO 3166-1 alpha-2 two-letter country code
* @return string
*/
public function countryFlag($countryCode)
{
if (strlen($countryCode) !== 2) {
return '';
}
return '<span class="famfamfam-flag-' . strtolower(h($countryCode)) . '" ></span>';
/* Unicode version
$output = '';
foreach (str_split(strtolower($countryCode)) as $letter) {
$letterCode = ord($letter);
if ($letterCode < 97 || $letterCode > 122) {
return ''; // invalid letter
}
// UTF-8 representation
$output .= "\xF0\x9F\x87" . chr(0xa6 + ($letterCode - 97));
}
return $output;*/
}
}

View File

@ -119,7 +119,7 @@ foreach ($orgs as $org): ?>
<td ondblclick="document.location.href ='<?php echo $baseurl . "/organisations/view/" . $org['Organisation']['id'];?>'"><?php echo h($org['Organisation']['description']); ?></td>
<td class="short" ondblclick="document.location.href ='<?php echo $baseurl . "/organisations/view/" . $org['Organisation']['id'];?>'"><?php
if (isset($org['Organisation']['country_code'])) {
echo '<span class="famfamfam-flag-' . strtolower(h($org['Organisation']['country_code'])) . '" ></span>&nbsp;';
echo $this->Icon->countryFlag($org['Organisation']['country_code']) . '&nbsp;';
}
if ($org['Organisation']['nationality'] !== 'Not specified') {
echo h($org['Organisation']['nationality']);

View File

@ -33,7 +33,7 @@
if (!empty(trim($org['Organisation']['nationality']))) {
$html = '';
if (isset($org['Organisation']['country_code'])) {
$html .= '<span class="famfamfam-flag-' . strtolower(h($org['Organisation']['country_code'])) . '" ></span>&nbsp;';
$html .= $this->Icon->countryFlag($org['Organisation']['country_code']) . '&nbsp;';
}
$html .= trim(h($org['Organisation']['nationality']));
$table_data[] = array(