From c75582ca6bf0650979b6af2c0ec7e0a4ad6bcd38 Mon Sep 17 00:00:00 2001 From: wolfgang101 Date: Sat, 16 Nov 2024 02:10:14 +0100 Subject: [PATCH] feat: added imageLink parameter --- README.md | 1 + config-example.php | 3 +++ plugin.php | 19 +++++++++++++++---- readme.txt | 6 +++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a9f4dfd..cf5840d 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ Place the following shortcode right into the page. Either as shortcode block or | onlyMedia | false | onlyMedia="true" | Show only statuses containing media | | preserveImageAspectRatio | false | preserveImageAspectRatio="true" | Preserve image aspect ratio | | imageSize | "preview" | imageSize="full" | Load small sized preview images or full size high quality images | +| imageLink | "status" | imageLink="image" | Link image to status or image | | tagged | false | tagged="tagname" | Show only statuses that are tagged with given tag name (no #!) | | linkTarget | "_self" | linkTarget="_blank" | Target for all links | | showPreviewCards | true | showPreviewCards="false" | Show preview cards | diff --git a/config-example.php b/config-example.php index 2e4b08d..529b1fc 100644 --- a/config-example.php +++ b/config-example.php @@ -46,6 +46,9 @@ // load small sized preview images or full size high quality images define( 'INCLUDE_MASTODON_FEED_IMAGE_SIZE', 'preview' ); + // link image to status or image + define( 'INCLUDE_MASTODON_FEED_IMAGE_LINK', 'status' ); + // only tagged statuses // tag name without leading #, case insensitive define('INCLUDE_MASTODON_FEED_TAGGED', 'tagname'); diff --git a/plugin.php b/plugin.php index 2978a29..d747e1f 100644 --- a/plugin.php +++ b/plugin.php @@ -52,6 +52,10 @@ $constants = [ 'key' => 'INCLUDE_MASTODON_FEED_IMAGE_SIZE', 'value' => 'preview', ], + [ + 'key' => 'INCLUDE_MASTODON_FEED_IMAGE_LINK', + 'value' => 'status', + ], [ 'key' => 'INCLUDE_MASTODON_FEED_TAGGED', 'value' => false, @@ -366,18 +370,21 @@ function init_scripts() { if('image' == media.type) { let mediaElemImgLink = mastodonFeedCreateElement('a'); let imageUrl = media.url; - if('full' === options.imageSize && null !== media.remote_url) { + if('full' === options.images.size && null !== media.remote_url) { imageUrl = media.remote_url; } else if(null !== media.preview_url) { imageUrl = media.preview_url; } mediaElemImgLink.href = status.url; + if('image' === options.images.link) { + mediaElemImgLink.href = media.remote_url ?? media.url; + } mediaElemImgLink.style.backgroundImage = 'url("' + imageUrl + '")'; if(null !== media.description) { mediaElem.title = media.description; } - if(options.preserveImageAspectRatio) { + if(options.images.preserveImageAspectRatio) { let mediaElemImgImage = mastodonFeedCreateElement('img'); mediaElemImgImage.src = imageUrl; mediaElemImgLink.appendChild(mediaElemImgImage); @@ -654,6 +661,7 @@ function display_feed($atts) { 'onlymedia' => filter_var(esc_html(INCLUDE_MASTODON_FEED_ONLY_MEDIA), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE), 'preserveimageaspectratio' => filter_var(esc_html(INCLUDE_MASTODON_FEED_PRESERVE_IMAGE_ASPECT_RATIO), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE), 'imagesize' => INCLUDE_MASTODON_FEED_IMAGE_SIZE, + 'imagelink' => INCLUDE_MASTODON_FEED_IMAGE_LINK, 'tagged' => INCLUDE_MASTODON_FEED_TAGGED, 'linktarget' => INCLUDE_MASTODON_FEED_LINKTARGET, 'showpreviewcards' => filter_var(esc_html(INCLUDE_MASTODON_FEED_SHOW_PREVIEWCARDS), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE), @@ -722,12 +730,15 @@ function display_feed($atts) { linkTarget: "", showPreviewCards: , excludeConversationStarters: , - preserveImageAspectRatio: , - imageSize: "", content: { hideStatusMeta: , hideDateTime: }, + images: { + preserveImageAspectRatio: , + size: "", + link: "", + }, text: { boosted: "", noStatuses: "", diff --git a/readme.txt b/readme.txt index 3093db0..5f1a03a 100644 --- a/readme.txt +++ b/readme.txt @@ -59,6 +59,9 @@ Preserve image aspect ratio (Default: false) * **imageSize** Load small sized preview images or full size high quality images (Default: preview, full) +* **imageLink** +Link image to status or image (Default: status, image) + * **tagged** Show only statuses that are tagged with given tag name (Default: false) No leading #, case insensitive, e.g.: tagged="tagname" @@ -152,7 +155,8 @@ Use the following URL to get your ID: == Changelog == = 1.9.5 = -* added option to load large image versions instead of medea previews (preview still default) +* added option to either display smaller image media attachment previews (default) or large image versions +* added option to point image media attachment links to either status (default) or image = 1.9.4 = * added option to hide status meta information and date/time (thank you @PaulKingtiger@dice.camp)