Merge branch 'develop' into feature/gutenberg-block
This commit is contained in:
commit
e435da4297
@ -1,6 +1,6 @@
|
||||
# Include Mastodon Feed Wordpress Plugin
|
||||
|
||||
Plugin that provides an `[include-mastodon-feed]` shortcode to easily integrate mastodon feeds into wordpress pages.
|
||||
Plugin that provides an `[include-mastodon-feed]` shortcode to easily integrate mastodon feeds into wordpress pages. Supports personal and tag feeds.
|
||||
|
||||
The plugin is written in PHP and generates native JavaScript to fetch and render the mastodon feed. No special libraries needed.
|
||||
|
||||
@ -28,6 +28,7 @@ Place the following shortcode right into the page. Either as shortcode block or
|
||||
| Attribute | Default value | Example | Description |
|
||||
| ------------------- | ----------------------------- | ------------------------- | ----------------------------------------------------------------- |
|
||||
| **account** | | id="012345678910" | (required attribute) Your account ID ([a long number](#how-do-i-find-my-account-id)) |
|
||||
| tag | | tag="travel" | use **tag** instead of **account** if you want to embed a tag feed instead of a personal feed |
|
||||
| **instance** | | instance="example.org" | (required attribute) Domain name of the instance without https:// |
|
||||
| limit | 20 | limit="10" | Maximum number of statuses |
|
||||
| excludeBoosts | false | excludeBoosts="true" | Exclude boosted statuses |
|
||||
@ -35,9 +36,12 @@ Place the following shortcode right into the page. Either as shortcode block or
|
||||
| excludeConversationStarters | false | excludeConversationStarters="true" | Exclude statuses that start with a user mention |
|
||||
| onlyPinned | false | onlyPinned="true" | Show only pinned statuses |
|
||||
| onlyMedia | false | onlyMedia="true" | Show only statuses containing media |
|
||||
| preserveImageAspectRatio | false | preserveImageAspectRatio="true" | Preserve image aspect ratio |
|
||||
| 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 |
|
||||
| hideStatusMeta | false | hideStatusMeta="true" | Hide status meta information (automatically also hides date and time) |
|
||||
| hideDateTime | false | hideDateTime="true" | Hide date and time from status meta information |
|
||||
| darkmode | false | darkmode="true" | Enable dark mode |
|
||||
| text-loading | "Loading Mastodon feed..." | text-loading="Loading ⏳" | Loading text |
|
||||
| text-noStatuses | "No statuses available" | text-noStatuses="💩" | Text if no statuses are available |
|
||||
|
@ -4,7 +4,7 @@
|
||||
* NOTE
|
||||
*
|
||||
* None, any, or all constants can be defined in the
|
||||
* config.local.php file to override default settings
|
||||
* wp-config.php file to override default settings
|
||||
*
|
||||
* default settings apply if file does not exist
|
||||
*/
|
||||
@ -39,6 +39,10 @@
|
||||
// show only statuses containing media
|
||||
define('INCLUDE_MASTODON_FEED_ONLY_MEDIA', false);
|
||||
|
||||
// preserve image aspect ratio
|
||||
// can be overridden in shortcode
|
||||
define('INCLUDE_MASTODON_FEED_PRESERVE_IMAGE_ASPECT_RATIO', true);
|
||||
|
||||
// only tagged statuses
|
||||
// tag name without leading #, case insensitive
|
||||
define('INCLUDE_MASTODON_FEED_TAGGED', 'tagname');
|
||||
@ -74,6 +78,13 @@
|
||||
// general border radius on elements
|
||||
define('INCLUDE_MASTODON_FEED_STYLE_BORDER_RADIUS', '0.25rem',);
|
||||
|
||||
// hide status meta information (automatically also hides date and time)
|
||||
define('INCLUDE_MASTODON_FEED_HIDE_STATUS_META', true)
|
||||
|
||||
// hide date and time from status meta information
|
||||
define('INCLUDE_MASTODON_FEED_HIDE_DATETIME', true)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* DEFAULT TEXTS AND LOCALIZATION
|
||||
|
86
plugin.php
86
plugin.php
@ -44,6 +44,10 @@ $constants = [
|
||||
'key' => 'INCLUDE_MASTODON_FEED_ONLY_MEDIA',
|
||||
'value' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'INCLUDE_MASTODON_FEED_PRESERVE_IMAGE_ASPECT_RATIO',
|
||||
'value' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'INCLUDE_MASTODON_FEED_TAGGED',
|
||||
'value' => false,
|
||||
@ -82,6 +86,14 @@ $constants = [
|
||||
'key' => 'INCLUDE_MASTODON_FEED_STYLE_BORDER_RADIUS',
|
||||
'value' => '0.25rem',
|
||||
],
|
||||
[
|
||||
'key' => 'INCLUDE_MASTODON_FEED_HIDE_STATUS_META',
|
||||
'value' => false,
|
||||
],
|
||||
[
|
||||
'key' => 'INCLUDE_MASTODON_FEED_HIDE_DATETIME',
|
||||
'value' => false,
|
||||
],
|
||||
// set texts and localization
|
||||
[
|
||||
'key' => 'INCLUDE_MASTODON_FEED_TEXT_LOADING',
|
||||
@ -271,11 +283,13 @@ function init_styles() {
|
||||
aspect-ratio: 1.618;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
}
|
||||
.include-mastodon-feed .media > .image a:hover {
|
||||
}
|
||||
.include-mastodon-feed .media > .image a:hover {
|
||||
filter: contrast(110%) brightness(130%) saturate(130%);
|
||||
}
|
||||
|
||||
.include-mastodon-feed .media > .image a img {
|
||||
width: 100%;
|
||||
}
|
||||
.include-mastodon-feed .media > .gifv video {
|
||||
max-width: 100%;
|
||||
}
|
||||
@ -394,6 +408,16 @@ function init_scripts() {
|
||||
if(null !== media.description) {
|
||||
mediaElem.title = media.description;
|
||||
}
|
||||
if(options.preserveImageAspectRatio) {
|
||||
let mediaElemImgImage = mastodonFeedCreateElement('img');
|
||||
if(null === media.remote_url) {
|
||||
mediaElemImgImage.src = media.preview_url;
|
||||
}
|
||||
else {
|
||||
mediaElemImgImage.src = media.remote_url;
|
||||
}
|
||||
mediaElemImgLink.appendChild(mediaElemImgImage);
|
||||
}
|
||||
mediaElem.appendChild(mediaElemImgLink);
|
||||
}
|
||||
else if('gifv' == media.type) {
|
||||
@ -482,15 +506,12 @@ function init_scripts() {
|
||||
else {
|
||||
createdInfo.appendChild(mastodonFeedCreateElementPermalink(status, new Date(status.created_at).toLocaleString(options.localization.date.locale, options.localization.date.options)));
|
||||
}
|
||||
createdInfo.innerHTML += ' ' + options.text.permalinkPost + ' ';
|
||||
if(null !== status.edited_at) {
|
||||
createdInfo.innerHTML += ' ' + options.text.edited;
|
||||
}
|
||||
createdInfo.innerHTML += ' ' + options.text.permalinkPost;
|
||||
return createdInfo;
|
||||
}
|
||||
|
||||
const mastodonFeedInjectEmoji = function(string, emoji) {
|
||||
return string.replace(':' + emoji.shortcode + ':', '<img class="emoji" src="' + emoji.url + '" title="' + emoji.shortcode + '" />');
|
||||
return string.replaceAll(':' + emoji.shortcode + ':', '<img class="emoji" src="' + emoji.url + '" title="' + emoji.shortcode + '" />');
|
||||
}
|
||||
|
||||
const mastodonFeedRenderStatuses = function(statuses, rootElem, options) {
|
||||
@ -507,17 +528,22 @@ function init_scripts() {
|
||||
let statusElem = mastodonFeedCreateElement('div', 'status');
|
||||
|
||||
// add account meta info
|
||||
let accountElem = mastodonFeedCreateElement('div', 'account');
|
||||
|
||||
if(isReblog) {
|
||||
let boosterElem = mastodonFeedCreateElement('span', 'booster');
|
||||
boosterElem.appendChild(document.createTextNode( options.text.boosted ));
|
||||
accountElem.appendChild(boosterElem);
|
||||
if(!options.content.hideStatusMeta) {
|
||||
let accountElem = mastodonFeedCreateElement('div', 'account');
|
||||
if(isReblog) {
|
||||
let boosterElem = mastodonFeedCreateElement('span', 'booster');
|
||||
boosterElem.appendChild(document.createTextNode( options.text.boosted ));
|
||||
accountElem.appendChild(boosterElem);
|
||||
}
|
||||
accountElem.appendChild(mastodonFeedCreateElementAccountLink(status.account));
|
||||
if(!options.content.hideDateTime) {
|
||||
accountElem.appendChild(mastodonFeedCreateElementTimeinfo(status, options, (isReblog ? false : status.url)));
|
||||
}
|
||||
if(null !== status.edited_at) {
|
||||
accountElem.innerHTML += ' ' + options.text.edited;
|
||||
}
|
||||
statusElem.appendChild(accountElem);
|
||||
}
|
||||
accountElem.appendChild(mastodonFeedCreateElementAccountLink(status.account));
|
||||
accountElem.appendChild(mastodonFeedCreateElementTimeinfo(status, options, (isReblog ? false : status.url)));
|
||||
|
||||
statusElem.appendChild(accountElem);
|
||||
|
||||
// prepare content rendering
|
||||
let showStatus = status;
|
||||
@ -660,16 +686,19 @@ function display_feed($atts) {
|
||||
array(
|
||||
'instance' => ( INCLUDE_MASTODON_FEED_DEFAULT_INSTANCE === false ? false : filter_var( INCLUDE_MASTODON_FEED_DEFAULT_INSTANCE, FILTER_UNSAFE_RAW ) ),
|
||||
'account' => false,
|
||||
'tag' => false,
|
||||
'limit' => INCLUDE_MASTODON_FEED_LIMIT,
|
||||
'excludeboosts' => filter_var(esc_html(INCLUDE_MASTODON_FEED_EXCLUDE_BOOSTS), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
|
||||
'excludereplies' => filter_var(esc_html(INCLUDE_MASTODON_FEED_EXCLUDE_REPLIES), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
|
||||
'excludeconversationstarters' => filter_var(esc_html(INCLUDE_MASTODON_FEED_EXCLUDE_CONVERSATIONSTARTERS), 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),
|
||||
'preserveimageaspectratio' => filter_var(esc_html(INCLUDE_MASTODON_FEED_PRESERVE_IMAGE_ASPECT_RATIO), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
|
||||
'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),
|
||||
|
||||
'hidestatusmeta' => filter_var(esc_html(INCLUDE_MASTODON_FEED_HIDE_STATUS_META), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
|
||||
'hidedatetime' => filter_var(esc_html(INCLUDE_MASTODON_FEED_HIDE_DATETIME), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
|
||||
'text-loading' => INCLUDE_MASTODON_FEED_TEXT_LOADING,
|
||||
'text-nostatuses' => INCLUDE_MASTODON_FEED_TEXT_NO_STATUSES,
|
||||
'text-boosted' => INCLUDE_MASTODON_FEED_TEXT_BOOSTED,
|
||||
@ -680,7 +709,6 @@ function display_feed($atts) {
|
||||
'text-edited' => INCLUDE_MASTODON_FEED_TEXT_EDITED,
|
||||
'date-locale' => INCLUDE_MASTODON_FEED_DATE_LOCALE,
|
||||
'date-options' => INCLUDE_MASTODON_FEED_DATE_OPTIONS,
|
||||
|
||||
'darkmode' => filter_var(esc_html(INCLUDE_MASTODON_FEED_DARKMODE), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
|
||||
), ( is_array($atts) ? array_change_key_case($atts, CASE_LOWER) : [] )
|
||||
);
|
||||
@ -688,11 +716,18 @@ function display_feed($atts) {
|
||||
if(false === filter_var($atts['instance'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)) {
|
||||
return error('missing configuration: instance');
|
||||
}
|
||||
if(false === filter_var($atts['account'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)) {
|
||||
return error('missing configuration: account id');
|
||||
if(false === filter_var($atts['account'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) && false === filter_var($atts['tag'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)) {
|
||||
return error('missing configuration: account id or tag');
|
||||
}
|
||||
|
||||
|
||||
if(false !== filter_var($atts['account'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)) {
|
||||
$apiUrl = 'https://'.urlencode($atts['instance']).'/api/v1/accounts/'.$atts['account'].'/statuses';
|
||||
}
|
||||
if(false !== filter_var($atts['tag'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)) {
|
||||
$apiUrl = 'https://'.urlencode($atts['instance']).'/api/v1/timelines/tag/'.urlencode($atts['tag']);
|
||||
}
|
||||
|
||||
$apiUrl = 'https://'.urlencode($atts['instance']).'/api/v1/accounts/'.$atts['account'].'/statuses';
|
||||
$getParams = [];
|
||||
if($atts['limit'] != 20 && $atts['limit'] > 0) {
|
||||
$getParams[] = 'limit=' . filter_var( $atts['limit'], FILTER_SANITIZE_NUMBER_INT );
|
||||
@ -727,6 +762,11 @@ function display_feed($atts) {
|
||||
linkTarget: "<?php echo filter_var( $atts['linktarget'], FILTER_UNSAFE_RAW ); ?>",
|
||||
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"); ?>,
|
||||
preserveImageAspectRatio: <?php echo (filter_var( $atts['preserveimageaspectratio'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? "true" : "false"); ?>,
|
||||
content: {
|
||||
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"); ?>
|
||||
},
|
||||
text: {
|
||||
boosted: "<?php echo esc_js( $atts['text-boosted'] ); ?>",
|
||||
noStatuses: "<?php echo esc_html( $atts['text-nostatuses'] ); ?>",
|
||||
|
22
readme.txt
22
readme.txt
@ -5,14 +5,14 @@ Tags: mastodon, status, feed
|
||||
Requires at least: 6.0
|
||||
Tested up to: 6.5
|
||||
Requires PHP: 7.4
|
||||
Stable tag: 1.9.3
|
||||
Stable tag: 1.9.4
|
||||
License: Expat License
|
||||
License URI: https://directory.fsf.org/wiki/License:Expat
|
||||
|
||||
Plugin that provides a shortcode to easily integrate mastodon feeds into wordpress pages.
|
||||
|
||||
== Description ==
|
||||
Plugin that provides an `[include-mastodon-feed]` shortcode to easily integrate mastodon feeds into wordpress pages.
|
||||
Plugin that provides an `[include-mastodon-feed]` shortcode to easily integrate mastodon feeds into wordpress pages. Supports personal and tag feeds.
|
||||
|
||||
The plugin is written in PHP and generates native JavaScript to fetch and render the mastodon feed. No special libraries needed.
|
||||
|
||||
@ -29,6 +29,9 @@ The plugin is written in PHP and generates native JavaScript to fetch and render
|
||||
* **account** (required)
|
||||
The account ID (a long number - see FAQ on how to get it)
|
||||
|
||||
* **tag**
|
||||
Use **tag** instead of **account** if you want to embed a tag feed instead of a personal feed
|
||||
|
||||
* **instance** (required)
|
||||
Domain name of the instance without https:// (e.g. example.org)
|
||||
|
||||
@ -50,6 +53,9 @@ Show only pinned statuses (Default: false)
|
||||
* **onlyMedia**
|
||||
Show only statuses containing media (Default: false)
|
||||
|
||||
* **preserveImageAspectRatio**
|
||||
Preserve image aspect ratio (Default: false)
|
||||
|
||||
* **tagged**
|
||||
Show only statuses that are tagged with given tag name (Default: false)
|
||||
No leading #, case insensitive, e.g.: tagged="tagname"
|
||||
@ -60,6 +66,12 @@ Target for all links e.g. new tab would be "_blank" (Default: _self)
|
||||
* **showPreviewCards**
|
||||
Show preview cards (Default: true)
|
||||
|
||||
* **hideStatusMeta**
|
||||
Hide status meta information, automatically also hides date and time (Default: false)
|
||||
|
||||
* **hideDateTime**
|
||||
Hide date and time from status meta information (Default: false)
|
||||
|
||||
* **darkmode**
|
||||
Enable dark mode (Default: false)
|
||||
|
||||
@ -131,6 +143,12 @@ Use the following URL to get your ID:
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.9.4 =
|
||||
* 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 option to show embedded images in original aspect ratio (thank you @beach@illo.social)
|
||||
* fix: correctly inject repeating emojis in display names and status texts (thank you @kanigsson@discuss.systems)
|
||||
|
||||
= 1.9.3 =
|
||||
* fix: improved excludeConversationStarters detection (did not work correctly)
|
||||
* fix: undid last refactor to load JS inline with markup instead footer to fix problem with JS that was added to footer even if shortcode was not visibly rendered
|
||||
|
Loading…
x
Reference in New Issue
Block a user