From e4aa0e344a8fcba866160a0b794019f7d4a60c74 Mon Sep 17 00:00:00 2001 From: Django Doucet Date: Fri, 6 Mar 2020 01:01:42 -0500 Subject: [PATCH 1/2] Add emoji support --- assets/mastodon.css | 6 ++++++ fediembedi-mastodon-widget.php | 6 +++--- fediembedi.php | 12 ++++++++++++ templates/mastodon.tpl.php | 20 ++++++++++---------- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/assets/mastodon.css b/assets/mastodon.css index a229e1e..39d87f9 100644 --- a/assets/mastodon.css +++ b/assets/mastodon.css @@ -285,6 +285,12 @@ cursor: pointer; display: inline-block; } +.status__content span.invisible{ + display: none; +} +.status__content span.ellipsis:after{ + content: '\2026'; +} .status__content .media-gallery__item{ margin: 1em 0; } diff --git a/fediembedi-mastodon-widget.php b/fediembedi-mastodon-widget.php index b3bb95c..92ca0d0 100644 --- a/fediembedi-mastodon-widget.php +++ b/fediembedi-mastodon-widget.php @@ -43,8 +43,6 @@ class FediEmbedi_Mastodon extends WP_Widget { $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; $height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '100%'; - //if(WP_DEBUG_DISPLAY === true): echo '
'. $instance_type .'
'; var_dump($status); echo '
'; endif; - echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; @@ -52,7 +50,9 @@ class FediEmbedi_Mastodon extends WP_Widget { //getStatus from remote instance $status = $client->getStatus($only_media, $pinned, $exclude_replies, null, null, null, $number, $exclude_reblogs); - include(plugin_dir_path(__FILE__) . 'templates/mastodon.tpl.php' ); + //if(WP_DEBUG_DISPLAY === true): echo '
Mastodon
'; var_dump($status); echo '
'; endif; + $account = $status[0]->account; + include(plugin_dir_path(__FILE__) . 'templates/mastodon.tpl.php' ); echo $args['after_widget']; } diff --git a/fediembedi.php b/fediembedi.php index 4fb6ed6..24f5e5c 100644 --- a/fediembedi.php +++ b/fediembedi.php @@ -25,6 +25,7 @@ class FediConfig add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); add_action('admin_menu', array($this, 'configuration_page')); add_action('admin_notices', array($this, 'admin_notices')); + add_filter('fedi_emoji', array($this, 'convert_emoji'), 10, 2); add_filter('plugin_action_links_'.plugin_basename(__FILE__), array($this, 'fediembedi_add_plugin_page_settings_link')); } @@ -144,6 +145,17 @@ class FediConfig register_widget( 'FediEmbedi_PeerTube' ); } + public function convert_emoji($string, $emojis){ + if(is_null($emojis) || !is_array($emojis)){ + return $string; + } + foreach($emojis as $emoji){ + $match = '/:' . $emoji->shortcode .':/'; + $string = preg_replace($match, "static_url}\">", $string); + } + return $string; + } + public function enqueue_styles($hook) { if( is_active_widget( false, false, 'mastodon') ) { diff --git a/templates/mastodon.tpl.php b/templates/mastodon.tpl.php index c7b305c..b636d79 100644 --- a/templates/mastodon.tpl.php +++ b/templates/mastodon.tpl.php @@ -6,28 +6,28 @@
reblog; endif; if(empty($statut->spoiler_text)): - echo $statut->content; + echo apply_filters('fedi_emoji', $statut->content, $statut->emojis); if(!is_null($statut->card)): ?>
@@ -82,7 +82,7 @@
' . $statut->spoiler_text . ''. $statut->content . ''; + else: echo '
' . apply_filters('fedi_emoji', $statut->spoiler_text, $statut->emojis) . ''. apply_filters('fedi_emoji', $statut->content, $statut->emojis) . '
'; endif; if(!empty($statut->media_attachments)): foreach ($statut->media_attachments as $attachment) { From 34540d783fe7db9f644434fe7d2698792a982c14 Mon Sep 17 00:00:00 2001 From: Django Doucet Date: Fri, 6 Mar 2020 01:03:04 -0500 Subject: [PATCH 2/2] Hide pixelfed widget when oauth fails --- fediembedi-pixelfed-widget.php | 4 ++++ fediembedi-settings-form.tpl.php | 4 ++-- templates/pixelfed.tpl.php | 12 ++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/fediembedi-pixelfed-widget.php b/fediembedi-pixelfed-widget.php index 7ee8037..be88df9 100644 --- a/fediembedi-pixelfed-widget.php +++ b/fediembedi-pixelfed-widget.php @@ -33,6 +33,9 @@ class FediEmbedi_Pixelfed extends WP_Widget { $access_token = get_option('fediembedi-pixelfed-token'); $client = new \FediClient($instance_url, $access_token); $cred = $client->verify_credentials($access_token); + if (!$cred){ + return; + } //widget options $show_header = (!empty($instance['show_header'])) ? $instance['show_header'] : ''; @@ -51,6 +54,7 @@ class FediEmbedi_Pixelfed extends WP_Widget { }; $status = $client->getStatus($only_media, $pinned, $exclude_replies, null, null, null, $number, $exclude_reblogs); + $account = $status[0]->account; include(plugin_dir_path(__FILE__) . 'templates/pixelfed.tpl.php' ); echo $args['after_widget']; diff --git a/fediembedi-settings-form.tpl.php b/fediembedi-settings-form.tpl.php index afc59eb..abdcdaa 100644 --- a/fediembedi-settings-form.tpl.php +++ b/fediembedi-settings-form.tpl.php @@ -12,7 +12,7 @@ define("FEDI_PXLFD_CONNECTED",isset($pixelfed_account) && $pixelfed_account !==
">

- +

Visit joinmastodon.org to find an instance.

@@ -39,7 +39,7 @@ define("FEDI_PXLFD_CONNECTED",isset($pixelfed_account) && $pixelfed_account !==
">

- +

Visit pixelfed.org/join to find an instance.

diff --git a/templates/pixelfed.tpl.php b/templates/pixelfed.tpl.php index 59c31dc..0ac3cbb 100644 --- a/templates/pixelfed.tpl.php +++ b/templates/pixelfed.tpl.php @@ -5,8 +5,8 @@
@@ -17,20 +17,20 @@
-

account->statuses_count; ?>

+

statuses_count; ?>

-

account->followers_count; ?>

+

followers_count; ?>

-

account->following_count; ?>

+

following_count; ?>

- +