feat: added option to show/hide preview cards

This commit is contained in:
wolfgang101 2023-05-02 15:23:24 +02:00
parent 7b4ccd0a81
commit f2f7c7ec71
4 changed files with 17 additions and 1 deletions

View File

@ -36,6 +36,7 @@ Place the following shortcode right into the page. Either as shortcode block or
| onlyMedia | false | onlyMedia="true" | Show only statuses containing media |
| 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 |
| darkmode | false | darkmode="true" | Enable dark mode |
| text-loading | "Loading Mastodon feed..." | text-loading="Loading ⏳" | Loading text |
| text-boosted | "boosted 🚀" | text-boosted="🚀" | Boosted status indicator text |

View File

@ -43,6 +43,9 @@
// target for all links (e.g. new tab "_blank")
define('INCLUDE_MASTODON_FEED_LINKTARGET', '_self');
// show / hide preview cards
define('INCLUDE_MASTODON_FEED_SHOW_PREVIEWCARDS', true);
/*
* DEFAULT STYLES
*/

View File

@ -48,6 +48,11 @@ $constants = [
'key' => 'INCLUDE_MASTODON_FEED_LINKTARGET',
'value' => '_self',
],
[
'key' => 'INCLUDE_MASTODON_FEED_SHOW_PREVIEWCARDS',
'value' => true,
],
// set styles
[
'key' => 'INCLUDE_MASTODON_FEED_DARKMODE',
@ -524,7 +529,7 @@ function init_scripts() {
}
// handle preview card
if(showStatus.card != null) {
if(options.showPreviewCards && showStatus.card != null) {
let cardElem = mastodonFeedCreateElementPreviewCard(showStatus.card);
contentElem.appendChild(cardElem);
}
@ -584,6 +589,7 @@ function display_feed($atts) {
'onlymedia' => filter_var(esc_html(INCLUDE_MASTODON_FEED_ONLY_MEDIA), 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),
'text-loading' => INCLUDE_MASTODON_FEED_TEXT_LOADING,
'text-boosted' => INCLUDE_MASTODON_FEED_TEXT_BOOSTED,
@ -598,6 +604,7 @@ function display_feed($atts) {
'darkmode' => filter_var(esc_html(INCLUDE_MASTODON_FEED_DARKMODE), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
), $atts
);
if(false == $atts['instance']) {
return error('missing configuration: instance');
}
@ -638,6 +645,7 @@ function display_feed($atts) {
"<?php echo filter_var( $elemId, FILTER_UNSAFE_RAW ); ?>",
{
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"); ?>,
text: {
boosted: "<?php echo esc_js( $atts['text-boosted'] ); ?>",
viewOnInstance: "<?php echo esc_js( $atts['text-viewoninstance'] ); ?>",

View File

@ -54,6 +54,9 @@ No leading #, case insensitive, e.g.: tagged="tagname"
* **linkTarget**
Target for all links e.g. new tab would be "_blank" (Default: _self)
* **showPreviewCards**
Show preview cards (Default: true)
* **darkmode**
Enable dark mode (Default: false)
@ -123,6 +126,7 @@ Use the following URL to get your ID:
== Changelog ==
= 1.8.0 =
* added option to show/hide preview cards
* refactoring: introducing plugin namespace
= 1.7.0 =