Hide pixelfed widget when oauth fails

This commit is contained in:
Django Doucet 2020-03-06 01:03:04 -05:00
parent e4aa0e344a
commit 34540d783f
3 changed files with 12 additions and 8 deletions

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

@ -5,8 +5,8 @@
<?php if($show_header): ?>
<div class="pixelfed-header card-header d-inline-flex align-items-center justify-content-between bg-white">
<div>
<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>
<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>
<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>