From e9064aff32589b2ea806fb62e15648b99de5cda0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 27 Oct 2024 15:48:06 +0000 Subject: [PATCH] Issue 14491: CSS class for pictures with or without alt descriptions --- src/Content/Text/BBCode.php | 13 +++++++------ view/templates/content/image/single.tpl | 4 ++-- .../content/image/single_with_height_allocation.tpl | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 367ecf1811..2eb4e62f16 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -686,7 +686,7 @@ class BBCode // to the last element $newbody = str_replace( '[$#saved_image' . $cnt . '#$]', - '' . DI::l10n()->t('Image/photo') . '', + '', $newbody ); $cnt++; @@ -849,6 +849,7 @@ class BBCode $img_str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT) . '"'; } } + $img_str .= ' ' . empty($attributes['alt']) ? 'class="empty-description"' : 'class="has-alt-description"'; return $img_str . '>'; }, $text @@ -1826,8 +1827,8 @@ class BBCode $text ); - $text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $text); - $text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '', $text); + $text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $text); + $text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '', $text); $text = preg_replace_callback( "/\[[iz]mg\=(.*?)\](.*?)\[\/[iz]mg\]/ism", @@ -1836,7 +1837,7 @@ class BBCode $alt = htmlspecialchars($matches[2], ENT_COMPAT); // Fix for Markdown problems with Diaspora, see issue #12701 if (($simple_html != self::DIASPORA) || strpos($matches[2], '"') === false) { - return '' . $alt . ''; + return '' . $alt . ''; } else { return '' . $alt . ''; } @@ -1859,8 +1860,8 @@ class BBCode $text ); - $text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . DI::l10n()->t('Image/photo') . '', $text); - $text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . DI::l10n()->t('Image/photo') . '', $text); + $text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '', $text); + $text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '', $text); $text = self::convertImages($text, $simple_html, $uriid); diff --git a/view/templates/content/image/single.tpl b/view/templates/content/image/single.tpl index 3b7c81e323..a4c5f0c92b 100644 --- a/view/templates/content/image/single.tpl +++ b/view/templates/content/image/single.tpl @@ -5,10 +5,10 @@ * SPDX-License-Identifier: AGPL-3.0-or-later *}} {{if $image->preview}} -{{$image->description}} +{{$image->description}}description}}class="has-alt-description"{{else}}class="empty-description"{{/if}} loading="lazy"> {{else}}
- {{$image->description}} + {{$image->description}}description}}class="has-alt-description"{{else}}class="empty-description"{{/if}} loading="lazy"> {{if $image->description}}
{{$image->description}}
{{/if}} diff --git a/view/templates/content/image/single_with_height_allocation.tpl b/view/templates/content/image/single_with_height_allocation.tpl index adc41d7189..c16672fe11 100644 --- a/view/templates/content/image/single_with_height_allocation.tpl +++ b/view/templates/content/image/single_with_height_allocation.tpl @@ -14,10 +14,10 @@
{{if $image->preview}} - {{$image->description}} + {{$image->description}}description}}class="has-alt-description"{{else}}class="empty-description"{{/if}} loading="lazy"> {{else}} - {{$image->description}} + {{$image->description}}description}}class="has-alt-description"{{else}}class="empty-description"{{/if}} loading="lazy"> {{if $image->description}}
{{$image->description}}
{{/if}}