1
0
mirror of https://git.feneas.org/mediaformat/fediembedi synced 2024-12-13 07:56:23 +01:00

Merge branch 'feature/emoji'

* feature/emoji:
  Hide pixelfed widget when oauth fails
  Add emoji support

# Conflicts:
#	fediembedi-mastodon-widget.php
#	templates/mastodon.tpl.php
#	templates/pixelfed.tpl.php
This commit is contained in:
Django Doucet 2020-03-06 01:10:19 -05:00
commit 4cf3f9654a
7 changed files with 39 additions and 18 deletions

View File

@ -306,6 +306,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;
}

View File

@ -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 '<details><summary>'. $instance_type .'</summary><pre>'; var_dump($status); echo '</pre></details>'; endif;
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
@ -52,8 +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);
//if(WP_DEBUG_DISPLAY === true): echo '<details><summary>Mastodon</summary><pre>'; var_dump($status); echo '</pre></details>'; endif;
$account = $status[0]->account;
include(plugin_dir_path(__FILE__) . 'templates/mastodon.tpl.php' );
include(plugin_dir_path(__FILE__) . 'templates/mastodon.tpl.php' );
echo $args['after_widget'];
}

View File

@ -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'];

View File

@ -12,7 +12,7 @@ define("FEDI_PXLFD_CONNECTED",isset($pixelfed_account) && $pixelfed_account !==
<div style="display:<?php echo !FEDI_MSTDN_CONNECTED ? "block":"none"?>">
<p><span class="mastodon"></span>
<input type="hidden" name="instance_type" value="mastodon">
<input type="text" class="widefat instance_url" id="mastodon_instance" name="instance" size="60" value="<?php esc_url_raw( $mastodon_instance, 'https' ); ?>">
<input type="text" class="widefat instance_url" id="mastodon_instance" name="instance" size="60" value="<?php !isset($mastodon_instance)?: esc_url_raw( $mastodon_instance, 'https' ); ?>">
<input class="button button-primary" type="submit" value="<?php _e( 'Connect to your instance to enable the widget', 'fediembedi' ); ?>" name="save" id="save_mastodon"><br></p>
<p><?php _e( "Don't have an account?", 'fediembedi' ); ?> Visit <a href="https://joinmastodon.org/" rel="noreferrer noopener" target="_blank" class="">joinmastodon.org</a> to find an instance.</p>
</div>
@ -39,7 +39,7 @@ define("FEDI_PXLFD_CONNECTED",isset($pixelfed_account) && $pixelfed_account !==
<div style="display:<?php echo !FEDI_PXLFD_CONNECTED ? "block":"none"?>">
<p><span class="pixelfed"></span>
<input type="hidden" name="instance_type" value="pixelfed">
<input type="text" class="widefat instance_url" id="pixlefed_instance" name="instance" size="60" value="<?php esc_url_raw( $pixlefed_instance, 'https' ); ?>">
<input type="text" class="widefat instance_url" id="pixlefed_instance" name="instance" size="60" value="<?php !isset($pixlefed_instance)?: esc_url_raw( $pixlefed_instance, 'https' ); ?>">
<input class="button button-primary" type="submit" value="<?php _e( 'Connect to your instance to enable the widget', 'fediembedi' ); ?>" name="save" id="save_pixelfed"></p>
<p><?php _e( "Don't have an account?", 'fediembedi' ); ?> Visit <a href="https://pixelfed.org/join" rel="noreferrer noopener" target="_blank" class="">pixelfed.org/join</a> to find an instance.</p>
</div>

View File

@ -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'));
}
@ -150,6 +151,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, "<img draggable=\"false\" role=\"img\" class=\"emoji\" src=\"{$emoji->static_url}\">", $string);
}
return $string;
}
public function enqueue_styles($hook)
{
if( is_active_widget( false, false, 'mastodon') || is_active_widget( false, false, 'pixelfed') ) {

View File

@ -20,14 +20,14 @@
</div>
<div class="account__header__tabs__name">
<h1>
<span><?php echo $account->display_name; ?></span>
<small><a href="" target="_blank" rel="noreferrer noopener"><?php echo $account->url; ?></a></small>
<span><?php echo apply_filters('fedi_emoji', $account->display_name, $account->emojis); ?></span>
<small><a href="<?php echo $account->url; ?>" target="_blank" rel="noreferrer noopener"><?php echo $account->url; ?></a></small>
</h1>
</div>
<div class="account__header__extra">
<div class="account__header__bio">
<div class="account__header__content">
<?php echo $account->note; ?>
<?php echo apply_filters('fedi_emoji', $account->note, $account->emojis); ?>
</div>
</div>
</div>
@ -62,7 +62,7 @@
<div class="status__avatar">
<div class="account__avatar" style="background-image: url(<?php if(is_null($statut->reblog)): echo $statut->account->avatar; else: echo $statut->reblog->account->avatar; endif; ?>); background-size: 40px; width: 40px; height: 40px;"></div>
</div>
<span class="display-name"><?php if(is_null($statut->reblog)): echo $statut->account->display_name; else: echo $statut->reblog->account->display_name; endif; ?></span>
<span class="display-name"><?php if(is_null($statut->reblog)): echo apply_filters('fedi_emoji', $statut->account->display_name, $statut->account->emojis); else: echo apply_filters('fedi_emoji', $statut->reblog->account->display_name, $statut->reblog->account->emojis); endif; ?></span>
</a>
</div>
<div class="status__content"><?php
@ -70,7 +70,7 @@
$statut = $statut->reblog;
endif;
if(empty($statut->spoiler_text)):
echo $statut->content;
echo apply_filters('fedi_emoji', $statut->content, $statut->emojis);
if(!is_null($statut->card)): ?>
<a href="<?php echo $statut->card->url; ?>" class="status-card compact" target="_blank" rel="noopener noreferrer">
<div class="status-card__image"><div class="status-card__image-image" style="background-image: url(<?php echo $statut->card->image; ?>);"></div></div>
@ -82,7 +82,7 @@
</a>
<?php
endif;
else: echo '<details><summary>' . $statut->spoiler_text . '</summary>'. $statut->content . '</details>';
else: echo '<details><summary>' . apply_filters('fedi_emoji', $statut->spoiler_text, $statut->emojis) . '</summary>'. apply_filters('fedi_emoji', $statut->content, $statut->emojis) . '</details>';
endif;
if(!empty($statut->media_attachments)):
foreach ($statut->media_attachments as $attachment) {

View File

@ -4,9 +4,9 @@
<div class="pixelfed-inner card status-card-embed card-md-rounded-0 border">
<?php if($show_header): ?>
<div class="pixelfed-header card-header d-inline-flex align-items-center justify-content-between bg-white">
<div class="pixelfed-account">
<img src="<?php echo $status[0]->account->avatar; ?>" height="32px" width="32px" style="border-radius: 32px;">
<a href="<?php echo $status[0]->account->url; ?>" class="username font-weight-bold pl-2 text-dark" rel="noreferrer noopener" target="_blank"><?php echo $status[0]->account->username; ?></a>
<div>
<img src="<?php echo $account->avatar; ?>" height="32px" width="32px" style="border-radius: 32px;">
<a href="<?php echo $account->url; ?>" class="username font-weight-bold pl-2 text-dark" rel="noreferrer noopener" target="_blank"><?php echo $account->username; ?></a>
</div>
<div class="pixelfed-instance">
<a class="small font-weight-bold text-muted pr-1" href="<?php echo $instance_url; ?>"><?php echo parse_url($instance_url, PHP_URL_HOST); ?></a>
@ -17,20 +17,20 @@
<div class="pixelfed-body card-body pb-1">
<div class="pixelfed-meta d-flex justify-content-between align-items-center">
<div class="text-center">
<p class="mb-0 font-weight-bold prettyCount"><?php echo $status[0]->account->statuses_count; ?></p>
<p class="mb-0 font-weight-bold prettyCount"><?php echo $account->statuses_count; ?></p>
<p class="mb-0 text-muted text-uppercase small font-weight-bold"><?php _e('Posts', 'fediembedi'); ?></p>
</div>
<div class="text-center">
<p class="mb-0 font-weight-bold prettyCount"><?php echo $status[0]->account->followers_count; ?></p>
<p class="mb-0 font-weight-bold prettyCount"><?php echo $account->followers_count; ?></p>
<p class="mb-0 text-muted text-uppercase small font-weight-bold"><?php _e('Followers', 'fediembedi'); ?></p>
</div>
<div class="text-center">
<p class="mb-0 font-weight-bold prettyCount"><?php echo $status[0]->account->following_count; ?></p>
<p class="mb-0 font-weight-bold prettyCount"><?php echo $account->following_count; ?></p>
<p class="mb-0 text-muted text-uppercase small font-weight-bold"><?php _e('Following', 'fediembedi'); ?></p>
</div>
<div class="text-center">
<p class="mb-0">
<a href="<?php echo $instance_url . '/i/intent/follow?user='. $status[0]->account->acct; ?>" class="pixelfed-follow btn btn-primary btn-sm py-1 px-4 text-uppercase font-weight-bold" target="_blank"><?php _e('Follow', 'fediembedi'); ?></a>
<a href="<?php echo $instance_url . '/i/intent/follow?user='. $account->acct; ?>" class="pixelfed-follow btn btn-primary btn-sm py-1 px-4 text-uppercase font-weight-bold" target="_blank"><?php _e('Follow', 'fediembedi'); ?></a>
</p>
</div>
</div>