Skip to content

Commit

Permalink
fix: Use png images in daily mails (#1055)
Browse files Browse the repository at this point in the history
Closes #1054
  • Loading branch information
kumy authored Aug 31, 2024
1 parent 4e4882a commit 86e0010
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
10 changes: 5 additions & 5 deletions website/app-templates/smarty/emails/daily-mail.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<small>{$geokret->gkid}</small>
</td>
<td nowrap>
{if !is_null($geokret->lat) and !is_null($geokret->lon)}{$geokret->country|country:'html' nofilter}{/if}
{if !is_null($geokret->lat) and !is_null($geokret->lon)}{$geokret->country|country:'html_email' nofilter}{/if}
{$geokret->last_position|cachelink nofilter}
</td>
<td>
Expand Down Expand Up @@ -87,14 +87,14 @@
{foreach from=$moves item=move}
<tr>
<td>
{$move|logicon nofilter}
{$move|logicon:false:'html_email' nofilter}
</td>
<td>
{$move->geokret|gklink nofilter}<br>
<small>{$move->geokret->gkid}</small>
</td>
<td nowrap>
{if !is_null($move->lat) and !is_null($move->lon)}{$move->country|country:'html' nofilter}{/if}
{if !is_null($move->lat) and !is_null($move->lon)}{$move->country|country:'html_email' nofilter}{/if}
{$move|cachelink nofilter}
</td>
<td>
Expand Down Expand Up @@ -133,14 +133,14 @@
{foreach from=$watched item=move}
<tr>
<td>
{$move|logicon nofilter}
{$move|logicon:false:'html_email' nofilter}
</td>
<td>
{$move->geokret|gklink nofilter}<br>
<small>{$move->geokret->gkid}</small>
</td>
<td nowrap>
{if !is_null($move->lat) and !is_null($move->lon)}{$move->country|country:'html' nofilter}{/if}
{if !is_null($move->lat) and !is_null($move->lon)}{$move->country|country:'html_email' nofilter}{/if}
<small>{$move|cachelink nofilter}</small>
</td>
<td>
Expand Down
30 changes: 22 additions & 8 deletions website/app-templates/smarty/extension/SmartyGeokretyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ function computeLocationType($logType): string {
return $logType == '' ? '9' : $logType;
}

/**
* Return '.png' suffix to be added to an svg image url if the output type is set to html_email.
*
* @param string $output The output type
*
* @return string The suffix to add, can be '.png' or empty string
*/
function svg2png(string $output): string {
return $output === 'html_email' ? '.png' : '';
}

class SmartyGeokretyExtension extends Smarty\Extension\Base {
public static function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true) {
$modifier = GeoKrety\Service\Smarty::getSmarty()->getModifierCallback('escape');
Expand Down Expand Up @@ -299,10 +310,11 @@ public function smarty_modifier_country(?string $countryCode, string $output = '
}
$countryCode = self::smarty_modifier_escape($countryCode);
// TODO localize country name in title
if ($output === 'css') {
return sprintf('<span class="flag-icon flag-icon-%s" title="%s"></span>', $countryCode, $countryCode);
} elseif ($output === 'html') {
return sprintf('<img src="%s/flags/4x3/%s.svg" class="w-4 d-inline-block" width="16" title="%s">', GK_CDN_SERVER_URL, $countryCode, $countryCode);
switch ($output) {
case 'css':
return sprintf('<span class="flag-icon flag-icon-%s" title="%s"></span>', $countryCode, $countryCode);
default:
return sprintf('<img src="%s/flags/4x3/%s.svg%s" class="w-4 d-inline-block" width="16" title="%s">', GK_CDN_SERVER_URL, $countryCode, svg2png($output), $countryCode);
}
throw new Exception('smarty_modifier_country(): Unsupported output mode');
}
Expand Down Expand Up @@ -377,11 +389,12 @@ public function smarty_modifier_gkavatar(Geokret $geokret): string {
/**
* Purpose: outputs a geokrety icon based on gk type.
*/
public function smarty_modifier_gkicon(Geokret $geokret): string {
public function smarty_modifier_gkicon(Geokret $geokret, string $output = 'html'): string {
return sprintf(
'<img src="%s/log-icons/%s/icon.svg" class="img-fluid w-3" alt="%s" title="%s" data-gk-type="%s" width="25px" height="25px">',
'<img src="%s/log-icons/%s/icon.svg%s" class="img-fluid w-3" alt="%s" title="%s" data-gk-type="%s" width="25px" height="25px">',
GK_CDN_IMAGES_URL,
$geokret->type->getTypeId(),
svg2png($output),
_('GK type icon'),
$geokret->type->getTypeString(),
$geokret->type->getTypeId()
Expand Down Expand Up @@ -432,17 +445,18 @@ public function smarty_modifier_extlink(string $url, ?string $textString = null,
/**
* Purpose: outputs a position icon.
*/
public function smarty_modifier_logicon(?GeoKrety\Model\Move $move, bool $showSmall = false): string {
public function smarty_modifier_logicon(?GeoKrety\Model\Move $move, bool $showSmall = false, string $output = 'html'): string {
if (is_null($move)) {
return '';
}
$gkType = $move->geokret->type->getTypeId();

$url = GK_SITE_BASE_SERVER_URL.Base::instance()->alias('geokret_details', '@gkid='.$move->geokret->gkid);
$img = sprintf(
'<img src="%s/log-icons/0/%s.svg" title="%s" data-gk-move-type="%s" data-gk-move-id="%s" width="%dpx" height="%dpx">',
'<img src="%s/log-icons/0/%s.svg%s" title="%s" data-gk-move-type="%s" data-gk-move-id="%s" width="%dpx" height="%dpx">',
GK_CDN_IMAGES_URL,
$move->move_type->getLogTypeId(),
svg2png($output),
sprintf('%d: %s', $move->id, $move->move_type->getLogTypeString()),
$move->move_type->getLogTypeId(),
$move->id,
Expand Down

0 comments on commit 86e0010

Please sign in to comment.