diff --git a/webapp/src/Twig/TwigExtension.php b/webapp/src/Twig/TwigExtension.php index f233757237..9c5a42834d 100644 --- a/webapp/src/Twig/TwigExtension.php +++ b/webapp/src/Twig/TwigExtension.php @@ -31,6 +31,8 @@ use Symfony\Component\Intl\Countries; use Symfony\Component\Intl\Exception\MissingResourceException; use Symfony\Component\PropertyAccess\PropertyAccess; +use Symfony\Component\Routing\Generator\UrlGenerator; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -126,6 +128,7 @@ public function getFilters(): array new TwigFilter('medalType', $this->awards->medalType(...)), new TwigFilter('numTableActions', $this->numTableActions(...)), new TwigFilter('extensionToMime', $this->extensionToMime(...)), + new TwigFilter('relativePath', $this->relativePath(...), ['is_safe' => ['html']]), ]; } @@ -363,7 +366,7 @@ public static function statusIcon(string $status): string $status); } - public function countryFlag(?string $alpha3CountryCode, bool $showFullname = false): string + public function countryFlag(?string $alpha3CountryCode, bool $showFullname = false, bool $relative = false): string { if (empty($alpha3CountryCode)) { return ''; @@ -376,6 +379,7 @@ public function countryFlag(?string $alpha3CountryCode, bool $showFullname = fal } $assetFunction = $this->twig->getFunction('asset')->getCallable(); $countryFlagUrl = call_user_func($assetFunction, sprintf('flags/4x3/%s.svg', $countryAlpha2)); + $countryFlagUrl = $this->relativePath($countryFlagUrl, $relative); $countryName = Countries::getAlpha3Name($alpha3CountryCode); @@ -387,11 +391,12 @@ public function countryFlag(?string $alpha3CountryCode, bool $showFullname = fal $countryFlagUrl, $alpha3CountryCode, $countryName); } - public function affiliationLogo(string $affiliationId, string $shortName): string + public function affiliationLogo(string $affiliationId, string $shortName, bool $relative = false): string { if ($asset = $this->dj->assetPath($affiliationId, 'affiliation')) { $assetFunction = $this->twig->getFunction('asset')->getCallable(); $assetUrl = call_user_func($assetFunction, $asset); + $assetUrl = $this->relativePath($assetUrl, $relative); return sprintf('', htmlspecialchars($assetUrl), htmlspecialchars($shortName)); } @@ -1195,7 +1200,7 @@ public function problemBadgeMaybe( } $submissionsUrl = $static - ? $this->router->generate('public_submissions_data') + ? $this->router->generate('public_submissions_data', referenceType: UrlGeneratorInterface::RELATIVE_PATH) : $this->router->generate('public_submissions_data_cell', [ 'teamId' => $score->team->getExternalid(), 'problemId' => $problem->getExternalId(), @@ -1381,4 +1386,14 @@ public function extensionToMime(string $extension): string { return DOMJudgeService::EXTENSION_TO_MIMETYPE[$extension]; } + + public function relativePath(string $path, bool $relative = true) : string + { + if (!$relative) { + return $path; + } + return UrlGenerator::getRelativePath( + $this->router->getContext()->getBaseUrl() + . $this->router->getContext()->getPathInfo(), $path); + } } diff --git a/webapp/templates/base.html.twig b/webapp/templates/base.html.twig index e953356b67..4cf737cdba 100644 --- a/webapp/templates/base.html.twig +++ b/webapp/templates/base.html.twig @@ -1,33 +1,35 @@ +{% if static is not defined %} + {% set static = false %} +{% endif %} - {% block title %}DOMjudge{% endblock %} - + {% block title %}DOMjudge {% endblock %} + + + + + + + - - - - - - - - + {% for file in customAssetFiles('js') %} - + {% endfor %} {% block extrahead %} - + {{ extrahead | default('') }} {% endblock %} {% for file in customAssetFiles('css') %} - + {% endfor %} - + {% block menu %}{% endblock %} {% block body %}
diff --git a/webapp/templates/partials/scoreboard.html.twig b/webapp/templates/partials/scoreboard.html.twig index 34af99a59b..2d544b4c82 100644 --- a/webapp/templates/partials/scoreboard.html.twig +++ b/webapp/templates/partials/scoreboard.html.twig @@ -75,12 +75,12 @@ {% endif %}
  • {% if showFlags and affiliation.country is defined %} - {{ affiliation.country|countryFlag }} + {{ affiliation.country|countryFlag(false, static) }} {% endif %} {% set affiliationLogo = affiliation.id | assetPath('affiliation') %} {% if affiliationLogo %} {% endif %} {{ affiliation.name }} diff --git a/webapp/templates/partials/scoreboard_table.html.twig b/webapp/templates/partials/scoreboard_table.html.twig index 71b074da1d..c70f8f5246 100644 --- a/webapp/templates/partials/scoreboard_table.html.twig +++ b/webapp/templates/partials/scoreboard_table.html.twig @@ -188,10 +188,10 @@ {% if score.team.affiliation %} {% set link = null %} {% if jury %} - {% set link = path('jury_team_affiliation', {'affilId': score.team.affiliation.affilid}) %} + {% set link = path('jury_team_affiliation', {'affilId': score.team.affiliation.affilid}, relative = static) %} {% endif %} - {{ score.team.affiliation.country|countryFlag }} + {{ score.team.affiliation.country|countryFlag(false, static) }} {% endif %} {% endif %} @@ -201,14 +201,14 @@ {% if score.team.affiliation %} {% set link = null %} {% if jury %} - {% set link = path('jury_team_affiliation', {'affilId': score.team.affiliation.affilid}) %} + {% set link = path('jury_team_affiliation', {'affilId': score.team.affiliation.affilid}, relative = static) %} {% endif %} {% set affiliationId = score.team.affiliation.externalid %} {% set affiliationImage = affiliationId | assetPath('affiliation') %} {% if affiliationImage %} {% else %} {{ affiliationId }} @@ -325,7 +325,7 @@ {% set link = path('jury_team', {teamId: score.team.teamid, restrict: restrict}) %} {% elseif static %} {% set link = '#' %} - {% set extra = 'data-submissions-url="' ~ path('public_submissions_data') ~ '"' %} + {% set extra = 'data-submissions-url="' ~ path('public_submissions_data', relative = true) ~ '"' %} {% set extra = extra ~ ' data-team-id="' ~ score.team.externalid ~ '"' %} {% set extra = extra ~ ' data-problem-id="' ~ problem.externalid ~ '"' %} {% elseif public %} @@ -466,7 +466,7 @@ {% set link = path('jury_team_affiliation', {'affilId': score.team.affiliation.affilid}) %} {% endif %} - {{ score.team.affiliation.country|countryFlag }} + {{ score.team.affiliation.country|countryFlag(false, static) }} {% endif %} {% endif %} @@ -483,7 +483,7 @@ {% set affiliationImage = affiliationId | assetPath('affiliation') %} {% if affiliationImage %} {{ score.team.affiliation.name }} {% else %} {{ affiliationId }} diff --git a/webapp/templates/partials/team.html.twig b/webapp/templates/partials/team.html.twig index 6bb371d8a0..8b0b685558 100644 --- a/webapp/templates/partials/team.html.twig +++ b/webapp/templates/partials/team.html.twig @@ -1,3 +1,6 @@ +{% if static is not defined %} + {% set static = false %} +{% endif %} {% if team is empty %}
    No team found by this id. @@ -28,7 +31,7 @@ {% set affiliationId = team.affiliation.externalid %} {% set affiliationLogo = affiliationId | assetPath('affiliation') %} {% if affiliationLogo %} - {% endif %} {{ team.affiliation.name }} @@ -37,7 +40,7 @@ Country - {{ team.affiliation.country | countryFlag(true) }} + {{ team.affiliation.country | countryFlag(true, static) }} {% endif %}