diff --git a/src/TwigMisuzu.php b/src/TwigMisuzu.php index 71b189f..2271fd5 100644 --- a/src/TwigMisuzu.php +++ b/src/TwigMisuzu.php @@ -32,7 +32,6 @@ final class TwigMisuzu extends AbstractExtension { return [ new TwigFunction('url_construct', 'url_construct'), new TwigFunction('url', 'url'), - new TwigFunction('html_avatar', 'html_avatar'), new TwigFunction('forum_may_have_children', 'forum_may_have_children'), new TwigFunction('forum_may_have_topics', 'forum_may_have_topics'), new TwigFunction('csrf_token', fn() => CSRF::token()), diff --git a/templates/macros.twig b/templates/macros.twig index 98b4988..b4ca0dd 100644 --- a/templates/macros.twig +++ b/templates/macros.twig @@ -85,6 +85,16 @@ {% endmacro %} -{% macro avatar(user_id, resolution, alt_text, attributes) %} -{{ html_avatar(user_id, resolution, alt_text|default(''), attributes|default([]))|raw }} +{% macro avatar(user_id, resolution, alt_text, attrs) %} +{% apply spaceless %} + {{ alt_text|default('') }} +{% endapply %} {% endmacro %} diff --git a/utility.php b/utility.php index afc6dc8..687740a 100644 --- a/utility.php +++ b/utility.php @@ -33,14 +33,6 @@ function clamp($num, int $min, int $max): int { return max($min, min($max, (int)$num)); } -function starts_with(string $string, string $text): bool { - return str_starts_with($string, $text); -} - -function ends_with(string $string, string $text): bool { - return str_ends_with($string, $text); -} - function first_paragraph(string $text, string $delimiter = "\n"): string { $index = mb_strpos($text, $delimiter); return $index === false ? $text : mb_substr($text, 0, $index); @@ -110,10 +102,6 @@ function render_info(?string $message, int $httpCode, string $template = 'errors $template = sprintf($template, $httpCode); - /*if(!tpl_exists($template)) { - $template = 'errors.master'; - }*/ - return \Misuzu\Template::renderRaw(sprintf($template, $httpCode)); } @@ -136,40 +124,6 @@ function html_colour(?int $colour, $attribs = '--user-colour'): string { return $css; } -function html_avatar(?int $userId, int $resolution, string $altText = '', array $attributes = []): string { - $attributes['src'] = url('user-avatar', ['user' => $userId ?? 0, 'res' => $resolution * 2]); - $attributes['alt'] = $altText; - $attributes['class'] = trim('avatar ' . ($attributes['class'] ?? '')); - - if(!isset($attributes['width'])) - $attributes['width'] = $resolution; - if(!isset($attributes['height'])) - $attributes['height'] = $resolution; - - return html_tag('img', $attributes); -} - -function html_tag(string $name, array $atrributes = [], ?bool $close = null, string $content = ''): string { - $html = '<' . $name; - - foreach($atrributes as $key => $value) { - $html .= ' ' . $key; - - if(!empty($value)) - $html .= '="' . $value . '"'; - } - - if($close === false) - $html .= '/'; - - $html .= '>'; - - if($close === true) - $html .= $content . ''; - - return $html; -} - function msz_server_timing(\Index\Performance\Timings $timings): string { $laps = $timings->getLaps(); $timings = [];