Merge branch 'develop'

This commit is contained in:
wolfgang101 2024-11-16 01:03:50 +01:00
commit fefa5e97b4
4 changed files with 33 additions and 19 deletions

View File

@ -37,6 +37,7 @@ Place the following shortcode right into the page. Either as shortcode block or
| onlyPinned | false | onlyPinned="true" | Show only pinned statuses | | onlyPinned | false | onlyPinned="true" | Show only pinned statuses |
| onlyMedia | false | onlyMedia="true" | Show only statuses containing media | | onlyMedia | false | onlyMedia="true" | Show only statuses containing media |
| preserveImageAspectRatio | false | preserveImageAspectRatio="true" | Preserve image aspect ratio | | preserveImageAspectRatio | false | preserveImageAspectRatio="true" | Preserve image aspect ratio |
| imageSize | "preview" | imageSize="full" | Load small sized preview images or full size high quality images |
| tagged | false | tagged="tagname" | Show only statuses that are tagged with given tag name (no #!) | | tagged | false | tagged="tagname" | Show only statuses that are tagged with given tag name (no #!) |
| linkTarget | "_self" | linkTarget="_blank" | Target for all links | | linkTarget | "_self" | linkTarget="_blank" | Target for all links |
| showPreviewCards | true | showPreviewCards="false" | Show preview cards | | showPreviewCards | true | showPreviewCards="false" | Show preview cards |

View File

@ -19,7 +19,7 @@
// set a default instance // set a default instance
// can still be overriden in shortcode // can still be overriden in shortcode
// plugin will show a warning if no default is set and instance is omitted in shortcode // plugin will show a warning if no default is set and instance is omitted in shortcode
//define('INCLUDE_MASTODON_FEED_DEFAULT_INSTANCE', 'example.org'); define('INCLUDE_MASTODON_FEED_DEFAULT_INSTANCE', 'example.org');
// Maximum number of statuses // Maximum number of statuses
define('INCLUDE_MASTODON_FEED_LIMIT', 20); define('INCLUDE_MASTODON_FEED_LIMIT', 20);
@ -43,6 +43,9 @@
// can be overridden in shortcode // can be overridden in shortcode
define('INCLUDE_MASTODON_FEED_PRESERVE_IMAGE_ASPECT_RATIO', true); define('INCLUDE_MASTODON_FEED_PRESERVE_IMAGE_ASPECT_RATIO', true);
// load small sized preview images or full size high quality images
define( 'INCLUDE_MASTODON_FEED_IMAGE_SIZE', 'preview' );
// only tagged statuses // only tagged statuses
// tag name without leading #, case insensitive // tag name without leading #, case insensitive
define('INCLUDE_MASTODON_FEED_TAGGED', 'tagname'); define('INCLUDE_MASTODON_FEED_TAGGED', 'tagname');

View File

@ -48,6 +48,10 @@ $constants = [
'key' => 'INCLUDE_MASTODON_FEED_PRESERVE_IMAGE_ASPECT_RATIO', 'key' => 'INCLUDE_MASTODON_FEED_PRESERVE_IMAGE_ASPECT_RATIO',
'value' => false, 'value' => false,
], ],
[
'key' => 'INCLUDE_MASTODON_FEED_IMAGE_SIZE',
'value' => 'preview',
],
[ [
'key' => 'INCLUDE_MASTODON_FEED_TAGGED', 'key' => 'INCLUDE_MASTODON_FEED_TAGGED',
'value' => false, 'value' => false,
@ -361,24 +365,21 @@ function init_scripts() {
let mediaElem = mastodonFeedCreateElement('div', media.type); let mediaElem = mastodonFeedCreateElement('div', media.type);
if('image' == media.type) { if('image' == media.type) {
let mediaElemImgLink = mastodonFeedCreateElement('a'); let mediaElemImgLink = mastodonFeedCreateElement('a');
let imageUrl = media.url;
if('full' === options.imageSize && null !== media.remote_url) {
imageUrl = media.remote_url;
}
else if(null !== media.preview_url) {
imageUrl = media.preview_url;
}
mediaElemImgLink.href = status.url; mediaElemImgLink.href = status.url;
if(null === media.remote_url) { mediaElemImgLink.style.backgroundImage = 'url("' + imageUrl + '")';
mediaElemImgLink.style.backgroundImage = 'url("' + media.preview_url + '")';
}
else {
mediaElemImgLink.style.backgroundImage = 'url("' + media.remote_url + '")';
}
if(null !== media.description) { if(null !== media.description) {
mediaElem.title = media.description; mediaElem.title = media.description;
} }
if(options.preserveImageAspectRatio) { if(options.preserveImageAspectRatio) {
let mediaElemImgImage = mastodonFeedCreateElement('img'); let mediaElemImgImage = mastodonFeedCreateElement('img');
if(null === media.remote_url) { mediaElemImgImage.src = imageUrl;
mediaElemImgImage.src = media.preview_url;
}
else {
mediaElemImgImage.src = media.remote_url;
}
mediaElemImgLink.appendChild(mediaElemImgImage); mediaElemImgLink.appendChild(mediaElemImgImage);
} }
mediaElem.appendChild(mediaElemImgLink); mediaElem.appendChild(mediaElemImgLink);
@ -479,7 +480,6 @@ function init_scripts() {
const mastodonFeedRenderStatuses = function(statuses, rootElem, options) { const mastodonFeedRenderStatuses = function(statuses, rootElem, options) {
if(statuses.length < 1) { if(statuses.length < 1) {
console.log(options);
rootElem.innerHTML = options.text.noStatuses; rootElem.innerHTML = options.text.noStatuses;
} }
else { else {
@ -594,11 +594,13 @@ function init_scripts() {
const rootElem = document.getElementById(elementId); const rootElem = document.getElementById(elementId);
rootElem.innerHTML = ''; rootElem.innerHTML = '';
<?php if(true === INCLUDE_MASTODON_FEED_DEBUG) : ?> <?php if(true === INCLUDE_MASTODON_FEED_DEBUG) : ?>
console.log("<?php echo __NAMESPACE__; ?>", url); console.log("<?php echo __NAMESPACE__; ?>", 'url', url);
console.log("<?php echo __NAMESPACE__; ?>", 'elementId', elementId);
console.log("<?php echo __NAMESPACE__; ?>", 'options', options);
<?php endif; ?> <?php endif; ?>
if (xhr.status === 200) { if (xhr.status === 200) {
<?php if(true === INCLUDE_MASTODON_FEED_DEBUG) : ?> <?php if(true === INCLUDE_MASTODON_FEED_DEBUG) : ?>
console.log("<?php echo __NAMESPACE__; ?>", xhr.response); console.log("<?php echo __NAMESPACE__; ?>", 'response', xhr.response);
<?php endif; ?> <?php endif; ?>
if(options.excludeConversationStarters && statuses.length > 0) { if(options.excludeConversationStarters && statuses.length > 0) {
const filteredStatuses = []; const filteredStatuses = [];
@ -625,7 +627,7 @@ function init_scripts() {
} }
else { else {
<?php if(true === INCLUDE_MASTODON_FEED_DEBUG) : ?> <?php if(true === INCLUDE_MASTODON_FEED_DEBUG) : ?>
console.log("<?php echo __NAMESPACE__; ?>", xhr); console.log("<?php echo __NAMESPACE__; ?>", 'response error', xhr);
<?php endif; ?> <?php endif; ?>
rootElem.appendChild(document.createTextNode(xhr.response.error)); rootElem.appendChild(document.createTextNode(xhr.response.error));
} }
@ -651,6 +653,7 @@ function display_feed($atts) {
'onlypinned' => filter_var(esc_html(INCLUDE_MASTODON_FEED_ONLY_PINNED), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE), 'onlypinned' => filter_var(esc_html(INCLUDE_MASTODON_FEED_ONLY_PINNED), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
'onlymedia' => filter_var(esc_html(INCLUDE_MASTODON_FEED_ONLY_MEDIA), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE), '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), '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,
'tagged' => INCLUDE_MASTODON_FEED_TAGGED, 'tagged' => INCLUDE_MASTODON_FEED_TAGGED,
'linktarget' => INCLUDE_MASTODON_FEED_LINKTARGET, 'linktarget' => INCLUDE_MASTODON_FEED_LINKTARGET,
'showpreviewcards' => filter_var(esc_html(INCLUDE_MASTODON_FEED_SHOW_PREVIEWCARDS), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE), 'showpreviewcards' => filter_var(esc_html(INCLUDE_MASTODON_FEED_SHOW_PREVIEWCARDS), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
@ -720,6 +723,7 @@ function display_feed($atts) {
showPreviewCards: <?php echo (filter_var( $atts['showpreviewcards'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?>, showPreviewCards: <?php echo (filter_var( $atts['showpreviewcards'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?>,
excludeConversationStarters: <?php echo (filter_var( $atts['excludeconversationstarters'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?>, excludeConversationStarters: <?php echo (filter_var( $atts['excludeconversationstarters'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?>,
preserveImageAspectRatio: <?php echo (filter_var( $atts['preserveimageaspectratio'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?>, preserveImageAspectRatio: <?php echo (filter_var( $atts['preserveimageaspectratio'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?>,
imageSize: "<?php echo ( "full" === $atts['imagesize'] ? "full" : "preview" ); ?>",
content: { content: {
hideStatusMeta: <?php echo (filter_var( $atts['hidestatusmeta'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?>, hideStatusMeta: <?php echo (filter_var( $atts['hidestatusmeta'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?>,
hideDateTime: <?php echo (filter_var( $atts['hidedatetime'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?> hideDateTime: <?php echo (filter_var( $atts['hidedatetime'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?>

View File

@ -3,9 +3,9 @@ Contributors: wolfgang101
Donate link: https://www.buymeacoffee.com/w101 Donate link: https://www.buymeacoffee.com/w101
Tags: mastodon, status, feed Tags: mastodon, status, feed
Requires at least: 6.0 Requires at least: 6.0
Tested up to: 6.5 Tested up to: 6.7
Requires PHP: 7.4 Requires PHP: 7.4
Stable tag: 1.9.4 Stable tag: 1.9.5
License: Expat License License: Expat License
License URI: https://directory.fsf.org/wiki/License:Expat License URI: https://directory.fsf.org/wiki/License:Expat
@ -56,6 +56,9 @@ Show only statuses containing media (Default: false)
* **preserveImageAspectRatio** * **preserveImageAspectRatio**
Preserve image aspect ratio (Default: false) Preserve image aspect ratio (Default: false)
* **imageSize**
Load small sized preview images or full size high quality images (Default: preview, full)
* **tagged** * **tagged**
Show only statuses that are tagged with given tag name (Default: false) Show only statuses that are tagged with given tag name (Default: false)
No leading #, case insensitive, e.g.: tagged="tagname" No leading #, case insensitive, e.g.: tagged="tagname"
@ -148,6 +151,9 @@ Use the following URL to get your ID:
== Changelog == == Changelog ==
= 1.9.5 =
* added option to load large image versions instead of medea previews (preview still default)
= 1.9.4 = = 1.9.4 =
* added option to hide status meta information and date/time (thank you @PaulKingtiger@dice.camp) * added option to hide status meta information and date/time (thank you @PaulKingtiger@dice.camp)
* added tag support - you can now embed tag feeds (thank you @martin@openedtech.social) * added tag support - you can now embed tag feeds (thank you @martin@openedtech.social)