diff --git a/assets/mastodon.css b/assets/mastodon.css index 1c3c81a..7b014c3 100644 --- a/assets/mastodon.css +++ b/assets/mastodon.css @@ -20,6 +20,9 @@ -webkit-animation: fade .15s linear; animation: fade .15s linear; } +.status .status__content p { + font-family: inherit; +} .status__prepend { margin-left: 68px; color: #444b5d; diff --git a/fediembedi.php b/fediembedi.php index 9c6de19..73325f2 100644 --- a/fediembedi.php +++ b/fediembedi.php @@ -2,8 +2,8 @@ /** * Plugin Name: FediEmbedi * Plugin URI: https://git.feneas.org/mediaformat/fediembedi - * Description: A widget to show your Fediverse profile timeline - * Version: 0.9.3 + * Description: Widgets and shortcodes to show your Fediverse profile timeline + * Version: 0.10.0 * Author: mediaformat * Author URI: https://mediaformat.org * License: GPLv3 @@ -21,6 +21,9 @@ class FediConfig { add_action('plugins_loaded', array($this, 'init')); add_action('widgets_init', array($this, 'fediembedi_widget')); + add_shortcode('mastodon', array($this, 'mastodon_shortcode')); + add_shortcode('pixelfed', array($this, 'pixelfed_shortcode')); + add_shortcode('peertube', array($this, 'peertube_shortcode')); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); add_action('admin_menu', array($this, 'configuration_page')); @@ -125,7 +128,6 @@ class FediConfig $mastodon_token = get_option('fediembedi-mastodon-token'); $pixelfed_token = get_option('fediembedi-pixelfed-token'); - } /* @@ -151,6 +153,89 @@ class FediConfig register_widget( 'FediEmbedi_PeerTube' ); } + public function mastodon_shortcode($atts){ + //fedi instance + $fedi_instance = get_option('fediembedi-mastodon-instance'); + $access_token = get_option('fediembedi-mastodon-token'); + $client = new \FediClient($fedi_instance, $access_token); + $cred = $client->verify_credentials($access_token); + + $atts = shortcode_atts( array( + 'only_media' => false, + 'pinned' => false, + 'exclude_replies' => false, + 'max_id' => null, + 'since_id' => null, + 'min_id' => null, + 'limit' => 5, + 'exclude_reblogs' => false, + 'show_header' => true, + ), $atts, 'mastodon' ); + + //getStatus from remote instance + $status = $client->getStatus($atts['only_media'], $atts['pinned'], $atts['exclude_replies'], null, null, null, $atts['limit'], $atts['exclude_reblogs']); + //if(WP_DEBUG_DISPLAY === true): echo '
Mastodon
'; var_dump($client->getStatus($atts)); echo '
'; endif; + $show_header = $atts['show_header']; + $account = $status[0]->account; + include(plugin_dir_path(__FILE__) . 'templates/mastodon.tpl.php' ); + } + + public function pixelfed_shortcode($atts){ + //fedi instance + $fedi_instance = get_option('fediembedi-pixelfed-instance'); + $access_token = get_option('fediembedi-pixelfed-token'); + $client = new \FediClient($fedi_instance, $access_token); + $cred = $client->verify_credentials($access_token); + + $atts = shortcode_atts( array( + 'only_media' => false, + 'pinned' => false, + 'exclude_replies' => false, + 'max_id' => null, + 'since_id' => null, + 'min_id' => null, + 'limit' => 9, + 'exclude_reblogs' => false, + 'show_header' => true, + ), $atts, 'pixelfed' ); + + //getStatus from remote instance + $status = $client->getStatus($atts['only_media'], $atts['pinned'], $atts['exclude_replies'], null, null, null, $atts['limit'], $atts['exclude_reblogs']); + //if(WP_DEBUG_DISPLAY === true): echo '
Mastodon
'; var_dump($client->getStatus($atts)); echo '
'; endif; + $show_header = $atts['show_header']; + $account = $status[0]->account; + include(plugin_dir_path(__FILE__) . 'templates/pixelfed.tpl.php' ); + } + + public function peertube_shortcode($atts){ + + $atts = shortcode_atts( array( + 'instance' => null, + 'actor' => null, + 'is_channel' => null, + 'limit' => 9, + 'show_header' => true, + ), $atts, 'peertube' ); + + $client = new \FediClient($atts['instance']); + + //getVideos from remote instance + $status = $client->getVideos($atts['actor'], $atts['is_channel']); + if(!is_null($atts['is_channel'])){ + $account = $status->data[0]->channel; + } else { + $account = $status->data[0]->account; + } + + //if(WP_DEBUG_DISPLAY === true): echo '
PeerTube
'; var_dump($status); echo '
'; endif; + $show_header = $atts['show_header']; + include(plugin_dir_path(__FILE__) . 'templates/peertube.tpl.php' ); + + } + + /* + * convert_emoji + */ public function convert_emoji($string, $emojis){ if(is_null($emojis) || !is_array($emojis)){ return $string; @@ -164,19 +249,19 @@ class FediConfig public function enqueue_styles($hook) { - if( is_active_widget( false, false, 'mastodon') || is_active_widget( false, false, 'pixelfed') ) { + global $post; + if( is_active_widget( false, false, 'mastodon') || is_active_widget( false, false, 'pixelfed') || ( is_a( $post, 'WP_Post' ) && ( has_shortcode( $post->post_content, 'mastodon') || has_shortcode( $post->post_content, 'pixelfed') ) ) ) { wp_enqueue_script( 'resize-sensor', plugin_dir_url( __FILE__ ) . 'assets/ResizeSensor.js', array(), 'css-element-queries-1.2.2' ); wp_enqueue_script( 'element-queries', plugin_dir_url( __FILE__ ) . 'assets/ElementQueries.js', array('resize-sensor'), 'css-element-queries-1.2.2' ); - } - if( is_active_widget( false, false, 'mastodon') ) { + if( is_active_widget( false, false, 'mastodon') || ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'mastodon') ) ) { wp_enqueue_style( 'mastodon', plugin_dir_url( __FILE__ ) . 'assets/mastodon.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'assets/mastodon.css') ); } - if( is_active_widget( false, false, 'pixelfed') ) { + if( is_active_widget( false, false, 'pixelfed') || ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'pixelfed') ) ) { wp_enqueue_style( 'bootstrap', plugin_dir_url( __FILE__ ) . 'assets/bootstrap/css/bootstrap.min.css', array(), '4.4.1' ); wp_enqueue_style( 'pixelfed', plugin_dir_url( __FILE__ ) . 'assets/pixelfed.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'assets/pixelfed.css') ); } - if( is_active_widget( false, false, 'peertube') ) { + if( is_active_widget( false, false, 'peertube') || ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'peertube') ) ) { wp_enqueue_style( 'peertube', plugin_dir_url( __FILE__ ) . 'assets/peertube.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'assets/mastodon.css') ); } } diff --git a/readme.md b/readme.md index e039e5d..ad4edbf 100644 --- a/readme.md +++ b/readme.md @@ -4,6 +4,11 @@ FediEmbedi will display your Mastodon, Pleroma, or Pixelfed timeline in a widget, with various display options. +### How to use shortcodes +* `[mastodon exclude_reblogs="true"]` +* `[pixelfed limit="6"]` +* `[peertube instance="https://peertube.social" actor="channel_name" is_channel="true"]` + ### Currently supported software * [Mastodon](http://joinmastodon.org/) * [Pleroma](https://git.pleroma.social/pleroma) @@ -48,6 +53,9 @@ and redirected to your site with a secure token. Similar to how you would connec ## Changelog +### 0.10.0 +* Service shortcodes + ### 0.9.0 * Emoji support diff --git a/readme.txt b/readme.txt index 32a4abf..6fb6aab 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === Plugin Name === Contributors: dj_angola Donate link: https://paypal.me/MediaFormat -Tags: mastodon, pixelfed, fediverse, activitypub, widget +Tags: mastodon, pixelfed, fediverse, activitypub, widget, shortcode Requires at least: 5.1 Tested up to: 5.3.2 Requires PHP: 7.2 @@ -15,7 +15,12 @@ Display your Fediverse timeline in a widget > FediEmbedi is beta software. -FediEmbedi will display your Mastodon, Pleroma, or Pixelfed timeline in a widget, with various display options. +FediEmbedi will display your Mastodon, Pleroma, or Pixelfed timeline in a widget or with a shortcode, with various display options. + += How to use shortcodes = +* `[mastodon exclude_reblogs="true"]` +* `[pixelfed limit="6"]` +* `[peertube instance="https://peertube.social" actor="channel_name" is_channel="true"]` = Currently supported software = * [Mastodon](http://joinmastodon.org/) @@ -59,6 +64,9 @@ and redirected to your site with a secure token. Similar to how you would connec == Changelog == += 0.10.0 = +* Service shortcodes + = 0.9.0 = * Emoji support diff --git a/templates/pixelfed.tpl.php b/templates/pixelfed.tpl.php index 2cd581f..770b273 100644 --- a/templates/pixelfed.tpl.php +++ b/templates/pixelfed.tpl.php @@ -17,21 +17,21 @@
-

statuses_count; ?>

-

+
statuses_count; ?>
+
-

followers_count; ?>

-

+
followers_count; ?>
+
-

following_count; ?>

-

+
following_count; ?>
+
-

+

-

+
@@ -52,9 +52,9 @@