]> git.mxchange.org Git - friendica.git/commitdiff
Issue 14491: CSS class for pictures with or without alt descriptions
authorMichael <heluecht@pirati.ca>
Sun, 27 Oct 2024 15:48:06 +0000 (15:48 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 27 Oct 2024 15:48:06 +0000 (15:48 +0000)
src/Content/Text/BBCode.php
view/templates/content/image/single.tpl
view/templates/content/image/single_with_height_allocation.tpl

index 367ecf18110606bba66c5481fa0f0140fa489d79..2eb4e62f16561936a298a0ad13de0e6883b37c98 100644 (file)
@@ -686,7 +686,7 @@ class BBCode
                        // to the last element
                        $newbody = str_replace(
                                '[$#saved_image' . $cnt . '#$]',
-                               '<img src="' . self::proxyUrl($image, self::INTERNAL, $uriid) . '" alt="' . DI::l10n()->t('Image/photo') . '" class="empty-description"/>',
+                               '<img src="' . self::proxyUrl($image, self::INTERNAL, $uriid) . '" alt="" class="empty-description"/>',
                                $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", '<img src="$3" style="width: $1px;" >', $text);
-               $text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '<img class="zrl" src="$3" style="width: $1px;" >', $text);
+               $text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '<img src="$3" style="width: $1px;" alt="" class="empty-description">', $text);
+               $text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '<img class="zrl" src="$3" style="width: $1px;" alt="" class="empty-description">', $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 '<img src="' . $matches[1] . '" alt="' . $alt . '" title="' . $alt . '">';
+                                       return '<img src="' . $matches[1] . '" alt="' . $alt . '" title="' . $alt . '" class="' . (empty($alt) ? 'empty-description' : 'has-alt-description') . '">';
                                } else {
                                        return '<img src="' . $matches[1] . '" alt="' . $alt . '">';
                                }
@@ -1859,8 +1860,8 @@ class BBCode
                        $text
                );
 
-               $text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . DI::l10n()->t('Image/photo') . '" class="empty-description"/>', $text);
-               $text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img src="$1" alt="' . DI::l10n()->t('Image/photo') . '" class="empty-description" />', $text);
+               $text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="" class="empty-description"/>', $text);
+               $text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img src="$1" alt="" class="empty-description" />', $text);
 
                $text = self::convertImages($text, $simple_html, $uriid);
 
index 3b7c81e323b8a22cc7b3d899d19405157c2b794b..a4c5f0c92b05ea47f6a1350eef73e24e41873811 100644 (file)
@@ -5,10 +5,10 @@
   * SPDX-License-Identifier: AGPL-3.0-or-later
   *}}
 {{if $image->preview}}
-<a data-fancybox="{{$image->uriId}}" href="{{$image->url}}"><img src="{{$image->preview}}" alt="{{$image->description}}" title="{{$image->description}}" loading="lazy"></a>
+<a data-fancybox="{{$image->uriId}}" href="{{$image->url}}"><img src="{{$image->preview}}" alt="{{$image->description}}" title="{{$image->description}}" {{if $image->description}}class="has-alt-description"{{else}}class="empty-description"{{/if}} loading="lazy"></a>
 {{else}}
 <figure>
-       <img src="{{$image->url}}" alt="{{$image->description}}" title="{{$image->description}}" loading="lazy">
+       <img src="{{$image->url}}" alt="{{$image->description}}" title="{{$image->description}}" {{if $image->description}}class="has-alt-description"{{else}}class="empty-description"{{/if}} loading="lazy">
        {{if $image->description}}
        <figcaption>{{$image->description}}</figcaption>
     {{/if}}
index adc41d718921a63e7c7a68df5dedddbd84abdd72..c16672fe11871ed84edb387c0ca55988b178252a 100644 (file)
 <figure class="img-allocated-height" style="width: {{$allocated_width|default:"auto"}}; padding-bottom: {{$allocated_height}}">
     {{if $image->preview}}
                <a data-fancybox="uri-id-{{$image->uriId}}" href="{{$image->url}}">
-                       <img src="{{$image->preview}}" alt="{{$image->description}}" title="{{$image->description}}" loading="lazy">
+                       <img src="{{$image->preview}}" alt="{{$image->description}}" title="{{$image->description}}" {{if $image->description}}class="has-alt-description"{{else}}class="empty-description"{{/if}} loading="lazy">
                </a>
     {{else}}
-               <img src="{{$image->url}}" alt="{{$image->description}}" title="{{$image->description}}" loading="lazy">
+               <img src="{{$image->url}}" alt="{{$image->description}}" title="{{$image->description}}" {{if $image->description}}class="has-alt-description"{{else}}class="empty-description"{{/if}} loading="lazy">
         {{if $image->description}}
                    <figcaption>{{$image->description}}</figcaption>
         {{/if}}