]> git.mxchange.org Git - friendica-addons.git/commitdiff
Changes added because of good remarks by hypolite@friendica.mrpetovan.com
authorGrischa Brockhaus <github@brockha.us>
Mon, 5 Dec 2022 11:46:18 +0000 (12:46 +0100)
committerGrischa Brockhaus <github@brockha.us>
Mon, 5 Dec 2022 11:46:18 +0000 (12:46 +0100)
fancybox/asset/fancybox/fancybox.config.js
fancybox/fancybox.php

index 6ac5d9c55cd5c204658d20ee2ef184835eeb430b..2b9c4f418c21f9f1b09c954b7a26b87950ae7131 100644 (file)
@@ -1,4 +1,5 @@
 $(document).ready(function() {
     $.fancybox.defaults.loop = "true";
+    // this disables the colorbox hook found in frio/js/modal.js:34
     $("body").off("click", ".wall-item-body a img");
 });
\ No newline at end of file
index 1400a75c63d5e13ad25356a9e7743cdbd5f02527..43219103b37d67993bfa2c98513b1135ebd466e6 100644 (file)
@@ -28,43 +28,33 @@ function fancybox_footer(App $a, string &$str)
        DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/fancybox.config.js');
 }
 
-function fancybox_render($a, array &$b){
+function fancybox_render(App $a, array &$b){
        $gallery = 'gallery-' . $b['item']['uri-id'] ?? random_int(1000000, 10000000);
 
-       // prevent urls in <div class="type-link"> to be replaced
-       $b['html'] = preg_replace_callback(
+       // performWithEscapedBlocks escapes block defined with 2nd par pattern that won't be processed.
+       // We don't want to touch images in class="type-link":
+       $b['html'] = \Friendica\Util\Strings::performWithEscapedBlocks(
+               $b['html'],
                '#<div class="type-link">.*?</div>#s',
-               function ($matches) use ($gallery) {
-                       return str_replace('<a href', '<a data-nofancybox="" href', $matches[0]);
-               },
-               $b['html']
-       );
-
-       // This processes images inlined in posts
-       // Frio / Vier hooks für lightbox are un-hooked in fancybox-config.js. So this works for them, too!
-       //if (!in_array($a->getCurrentTheme(),['vier','frio']))
-       {
-               // normal post inline linked images
-               $b['html'] = preg_replace_callback(
-                       '#<a[^>]*href="([^"]*)"[^>]*>(<img[^>]*src="[^"]*"[^>]*>)</a>#',
-                       function ($matches)  use ($gallery) {
-                               // don't touch URLS marked as not "fancyable".. ;-)
-                               if (preg_match('#data-nofancybox#', $matches[0]))
-                               {
-                                       return $matches[0];
-                               }
-                               return '<a data-fancybox="' . $gallery . '" href="'. $matches[1] .'">' . $matches[2] .'</a>';
-                       },
-                       $b['html']
-               );
-       }
-
-       // Local content images attached:
-       $b['html'] = preg_replace_callback(
-               '#<div class="body-attach">.*?</div>#s',
-               function ($matches) use ($gallery) {
-                       return str_replace('<a href', '<a data-fancybox="' . $gallery . '" href', $matches[0]);
-               },
-               $b['html']
+               function ($text) use ($gallery) {
+                       // This processes images inlined in posts
+                       // Frio / Vier hooks für lightbox are un-hooked in fancybox-config.js. So this works for them, too!
+                       //if (!in_array($a->getCurrentTheme(),['vier','frio']))
+                       $text = preg_replace(
+                               '#<a[^>]*href="([^"]*)"[^>]*>(<img[^>]*src="[^"]*"[^>]*>)</a>#',
+                               '<a data-fancybox="' . $gallery . '" href="$1">$2</a>',
+                               $text);
+
+                       // Local content images attached:
+                       $text = preg_replace_callback(
+                               '#<div class="body-attach">.*?</div>#s',
+                               function ($matches) use ($gallery) {
+                                       return str_replace('<a href', '<a data-fancybox="' . $gallery . '" href', $matches[0]);
+                               },
+                               $text
+                       );
+
+                       return $text;
+               }
        );
 }