Skip to content

Commit

Permalink
improve flag display
Browse files Browse the repository at this point in the history
  • Loading branch information
antedebaas committed Oct 26, 2024
1 parent 744355f commit 65fa920
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
17 changes: 14 additions & 3 deletions src/Twig/GeoIp_Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(Reader $reader)
public function getFilters(): array
{
return [
new TwigFilter('geoip_country', [$this, 'geoipCountryFilter']),
new TwigFilter('geoip_country', [$this, 'geoipCountryFilter'], ['is_safe' => ['html']]),
];
}

Expand All @@ -30,7 +30,18 @@ public function getFilters(): array
*/
public function geoipCountryFilter($ip)
{
$country = $this->reader->country($ip);
return strtolower($country->country->isoCode);
if (empty($ip)) {
return '';
}
try {

$country = $this->reader->country($ip);
$response = $ip.' <span class="flag flag-xs flag-country-'.$country->country->isoCode.'"></span>';
return $response;
}
catch (\Exception $e) {
return $ip;
}

}
}
2 changes: 1 addition & 1 deletion templates/dmarc_reports/report.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
<li class="list-group-item">
<div class="clearfix">
<span class="float-start"><b>IP Address: </b> </span>
<span class="float-end"> {{ record.sourceip }} <span class="flag flag-xs flag-country-{{ record.sourceip|geoip_country }}"></span></span>
<span class="float-end">{{ record.sourceip|geoip_country }}</span>
</div>
</li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions templates/smtptls_reports/report.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@
<li class="list-group-item">
<div class="clearfix">
<span class="float-start"><b>Sending MTA IP: </b> </span>
<span class="float-end"> {{ failuredetail.sendingmtaip }} <span class="flag flag-xs flag-country-{{ failuredetail.sendingmtaip|geoip_country }}"></span></span>
<span class="float-end">{{ failuredetail.sendingmtaip|geoip_country }}</span>
</div>
</li>
<li class="list-group-item">
<div class="clearfix">
<span class="float-start"><b>Receiving IP: </b> </span>
<span class="float-end"> {{ failuredetail.receivingip }} <span class="flag flag-xs flag-country-{{ failuredetail.sendingmtaip|geoip_country }}"></span></span>
<span class="float-end">{{ failuredetail.receivingip|geoip_country }}</span>
</div>
</li>
</ul>
Expand Down

0 comments on commit 65fa920

Please sign in to comment.