diff --git a/lightbox-photoswipe.php b/lightbox-photoswipe.php index d2b5032..ea4d334 100644 --- a/lightbox-photoswipe.php +++ b/lightbox-photoswipe.php @@ -3,7 +3,7 @@ Plugin Name: Lightbox with PhotoSwipe Plugin URI: https://wordpress.org/plugins/lightbox-photoswipe/ Description: Lightbox with PhotoSwipe -Version: 5.2.5 +Version: 5.2.6 Author: Arno Welzel Author URI: http://arnowelzel.de Text Domain: lightbox-photoswipe diff --git a/readme.txt b/readme.txt index 762759d..3fa58aa 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Contributors: awelzel Tags: lightbox, photoswipe, attachments, images, gallery Requires at least: 5.3 Tested up to: 6.4 -Stable tag: 5.2.5 +Stable tag: 5.2.6 Donate link: https://paypal.me/ArnoWelzel License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -151,9 +151,13 @@ If you change any of the stylesheets or frontend scripts in `src/js` or `src/lib == Changelog == += 5.2.6 = + +* Additional workarounds to deal with image links and captions in JetPack tiled galleries. + = 5.2.5 = -* Fixed handling of image rotation when using original size images using the option . +* Fixed handling of image rotation when using original size images using the option. = 5.2.4 = diff --git a/src/LightboxPhotoSwipe/LightboxPhotoSwipe.php b/src/LightboxPhotoSwipe/LightboxPhotoSwipe.php index 45d5868..f40f16d 100644 --- a/src/LightboxPhotoSwipe/LightboxPhotoSwipe.php +++ b/src/LightboxPhotoSwipe/LightboxPhotoSwipe.php @@ -10,7 +10,7 @@ */ class LightboxPhotoSwipe { - const VERSION = '5.2.5'; + const VERSION = '5.2.6'; const SLUG = 'lightbox-photoswipe'; const META_VERSION = '18'; const CACHE_EXPIRE_IMG_DETAILS = 86400; @@ -421,19 +421,30 @@ public function callbackProperties(array $matches) $file = $realFile; } - // Keep original file name for metadata retrieval + // Keep original file name variations for metadata retrieval $fileOriginal = $file; + $fileOriginalNoScaled = $file; + $fileOriginalNoSize = $file; + $fileOriginalScaled = $file; // If the "fix image links" option is set, try to remove size parameters from the image link. // For example: "image-1024x768.jpg" will become "image.jpg" $sizeMatcher = '/(-[0-9]+x[0-9]+\.)(?:.(?!-[0-9]+x[0-9]+\.)).+$/'; + $fileFixed = preg_filter($sizeMatcher, '.', $file); + if ($fileFixed !== null && $fileFixed !== $file) { + $fileOriginalScaled = substr($fileFixed, 0, -1) . '-scaled.' . $extension; + } if ('1' === $this->optionsManager->getOption('fix_links')) { - $fileFixed = preg_filter($sizeMatcher, '.', $file); if ($fileFixed !== null && $fileFixed !== $file) { $file = $fileFixed . $extension; $matches[2] = preg_filter($sizeMatcher, '.', $matches[2]) . $extension; + + if ($file !== $fileOriginal) { + $fileOriginalNoSize = $file; + } } } + // If the "fix scaled image links" option is set, try to remove "-scaled" from the image link. // For example: "image-scaled.jpg" will become "image.jpg" $scaledMatcher = '/(-scaled\.).+$/'; @@ -442,6 +453,10 @@ public function callbackProperties(array $matches) if ($fileFixed !== null && $fileFixed !== $file) { $file = $fileFixed . $extension; $matches[2] = preg_filter($scaledMatcher, '.', $matches[2]) . $extension; + + if ($file !== $fileOriginal) { + $fileOriginalNoScaled = $file; + } } } @@ -449,8 +464,11 @@ public function callbackProperties(array $matches) if ('1' === $this->optionsManager->getOption('usepostdata') && '1' === $this->optionsManager->getOption('show_caption')) { $imgId = $wpdb->get_col( $wpdb->prepare( - 'SELECT post_id FROM '.$wpdb->postmeta.' WHERE meta_key = "_wp_attached_file" and meta_value = %s;', - str_replace ($uploadDir . '/', '', $fileOriginal) + 'SELECT post_id FROM '.$wpdb->postmeta.' WHERE meta_key = "_wp_attached_file" and meta_value in (%s, %s, %s, %s);', + str_replace ($uploadDir . '/', '', $fileOriginal), + str_replace ($uploadDir . '/', '', $fileOriginalNoSize), + str_replace ($uploadDir . '/', '', $fileOriginalNoScaled), + str_replace ($uploadDir . '/', '', $fileOriginalScaled), ) ); if (isset($imgId[0])) {