Service registration refactor, Separate widgets, support for PeerTube

This commit is contained in:
Django Doucet 2020-01-26 23:38:40 -05:00
commit 317220c9c3
13 changed files with 932 additions and 653 deletions

5
.gitignore vendored
View File

@ -1,2 +1,7 @@
#ignore system files
.DS_Store
#bootstrap slim
assets/bootstrap/*
!assets/bootstrap/css/bootstrap.min.css
!assets/bootstrap/css/bootstrap.min.css.map

View File

@ -9,293 +9,148 @@
will-change: transform;
}
.status {
padding: 8px 10px 8px 68px;
position: relative;
min-height: 54px;
border-bottom: 1px solid #c0cdd9;
cursor: default;
opacity: 1;
-webkit-animation: fade .15s linear;
animation: fade .15s linear;
.peertube-timeline__header {
width: 100vw;
overflow-x: auto;
padding-left: 15px;
padding-right: 15px;
margin-bottom: 10px;
}
.status__prepend {
margin-left: 68px;
color: #444b5d;
padding: 8px 0 2px;
font-size: 14px;
position: relative;
}
.status__prepend-icon-wrapper {
left: -26px;
position: absolute;
}
.fa-fw {
width: 1.28571429em;
text-align: center;
}
.fa {
display: inline-block;
}
.account__header {
overflow: hidden;
}
.account__header__image {
overflow: hidden;
height: 145px;
position: relative;
background: #e6ebf0;
}
.account__header__info {
position: absolute;
top: 10px;
left: 10px;
}
.account__header__image img {
object-fit: cover;
display: block;
.actor,
.actor-info {
width: 100%;
height: 100%;
margin: 0;
}
.account__header__bar {
position: relative;
background: #fff;
padding: 5px;
border-bottom: 1px solid #b3c3d1;
}
.account__header__tabs {
.actor {
display: -webkit-box;
display: flex;
align-items: flex-start;
padding: 7px 5px;
margin-top: -55px;
margin-top: 20px;
margin-bottom: 20px;
}
.account__header__bar .avatar {
display: block;
flex: 0 0 auto;
width: 94px;
margin-left: -2px;
}
.account__header__tabs .spacer {
flex: 1 1 auto;
}
.account__header__tabs__buttons .button {
margin: 0 8px;
color: #fff;
border-radius: 4px;
padding: 0px 16px;
height: 36px;
line-height: 36px;
}
.account__header__tabs__name {
padding: 5px;
}
.account__header__tabs__name h1 {
font-size: 16px;
line-height: 24px;
color: #000;
font-weight: 500;
margin: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.account__header__tabs__name h1 small {
display: block;
font-size: 14px;
color: #282c37;
font-weight: 400;
overflow: hidden;
text-overflow: ellipsis;
}
.account__header__extra {
margin-top: 4px;
}
.account__header__bio {
overflow: hidden;
margin: 0 -5px;
}
.account__header__bio .account__header__content {
padding: 20px 15px 5px;
color: #000;
}
.account__header__content {
color: #282c37;
font-size: 14px;
font-weight: 400;
overflow: hidden;
word-break: normal;
word-wrap: break-word;
}
.account__display-name,
.detailed-status__application,
.detailed-status__datetime,
.detailed-status__display-name,
.status__display-name,
.status__relative-time {
text-decoration: none;
}
.status__display-name {
color: #444b5d;
}
.status__expand {
width: 68px;
position: absolute;
left: 0;
top: 0;
height: 100%;
cursor: pointer;
}
.status__info {
font-size: 15px;
}
.status__info .status__display-name {
display: block;
max-width: 100%;
padding-right: 25px;
}
.status__avatar {
height: 48px;
left: 10px;
position: absolute;
top: 10px;
width: 48px;
}
.account__avatar {
border-radius: 4px;
background: transparent no-repeat;
background-position: 50%;
background-clip: padding-box;
position: relative;
}
.account__avatar-overlay {
width: 48px;
height: 48px;
background-size: 48px 48px;
}
.account__avatar-overlay-base {
border-radius: 4px;
background: transparent no-repeat;
background-position: 50%;
background-clip: padding-box;
width: 36px;
height: 36px;
background-size: 36px 36px;
}
.account__avatar-overlay-overlay {
border-radius: 4px;
background: transparent no-repeat;
background-position: 50%;
background-clip: padding-box;
width: 24px;
height: 24px;
background-size: 24px 24px;
position: absolute;
bottom: 0;
right: 0;
z-index: 1;
}
.display-name {
display: block;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.display-name__account {
font-size: 14px;
}
.account__display-name strong, .status__display-name strong {
color: #000;
}
.display-name__html {
font-weight: 500;
}
.notification__relative_time, .status__relative-time {
color: #444b5d;
float: right;
font-size: 14px;
}
.status-card.compact {
border-color: #ccd7e0;
}
.status-card {
display: flex;
font-size: 14px;
border: 1px solid #c0cdd9;
border-radius: 4px;
color: #444b5d;
margin-top: 14px;
text-decoration: none;
overflow: hidden;
cursor: pointer;
}
.status-card.compact .status-card__image {
flex: 0 0 60px;
}
.status-card__image {
flex: 0 0 100px;
background: #c0cdd9;
position: relative;
}
.status-card__image-image {
border-radius: 4px 0 0 4px;
display: block;
margin: 0;
width: 100%;
height: 100%;
.actor img {
-o-object-fit: cover;
object-fit: cover;
background-size: cover;
background-position: 50%;
border-radius: 50%;
width: 80px;
height: 80px;
min-width: 80px;
margin-right: 20px;
}
.status-card.compact .status-card__content {
padding: 10px 8px 8px;
.actor .actor-info {
display: -webkit-box;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
flex-direction: column;
-webkit-box-pack: center;
justify-content: center;
}
.status-card__content {
flex: 1 1 auto;
overflow: hidden;
padding: 14px 14px 14px 8px;
.actor .actor-display-link {
text-decoration: none;
}
.status-card__title {
display: block;
font-weight: 500;
.actor .actor-info .actor-names .actor-display-name {
font-size: 23px;
font-weight: 700;
}
.actor-info .actor-names .actor-name {
margin-left: 7px;
position: relative;
top: 3px;
font-size: 14px;
color: #777272;
}
.video { margin-bottom: 1.5em; }
.videos .video-miniature {
padding-right: 0;
height: auto;
width: 100%;
margin-bottom: 5px;
color: #282c37;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-decoration: none;
}
.status-card__description {
color: #282c37;
}
.status-card__host {
display: block;
margin-top: 5px;
font-size: 13px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.status__content summary {
background: #eee;
border-radius: 5px;
padding: 2px 8px;
cursor: pointer;
display: inline-block;
}
.status__content .media-gallery__item{
margin: 1em 0;
}
i.fa-retweet {
background-image: url('../img/retoot.svg');
background-position: 0 0;
height: 19px;
vertical-align: middle;
width: 22px;
color: #ccc;
opacity: .75;
z-index: 10;
.video-thumbnail {
display: -webkit-box;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
flex-direction: column;
position: relative;
border-radius: 3px;
overflow: hidden;
background-color: #ececec;
-webkit-transition: -webkit-filter .2s;
transition: -webkit-filter .2s ease;
transition: filter .2s ease;
transition: filter .2s ease,-webkit-filter .2s ease;
}
.videos .video-miniature .video-thumbnail {
margin: 0;
width: 100%;
height: auto;
border-radius: 0;
}
.videos .video-miniature .video-thumbnail img {
width: 100%;
height: auto;
}
.video-thumbnail .play-overlay {
position: absolute;
right: 0;
bottom: 0;
width: inherit;
height: inherit;
opacity: 0;
background-color: rgba(0,0,0,.7);
}
.video-thumbnail .play-overlay,
.video-thumbnail .play-overlay .icon {
-webkit-transition: .2s;
transition: all .2s ease;
}
.video-thumbnail .play-overlay .icon {
width: 0;
height: 0;
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%,-50%) scale(.5);
transform: translate(-50%,-50%) scale(.5);
border-top: 13px solid transparent;
border-bottom: 13px solid transparent;
border-left: 18px solid rgba(255,255,255,.95);
}
.video-miniature .video-bottom {
display: -webkit-box;
display: flex;
}
.video-thumbnail .video-thumbnail-duration-overlay {
display: inline-block;
background-color: rgba(0,0,0,.7);
color: #fff;
position: absolute;
right: 5px;
bottom: 5px;
padding: 0 5px;
border-radius: 3px;
font-size: 12px;
font-weight: 700;
}
.video-miniature-name{
font-weight: 600;
margin: 0 0 5px;
text-decoration: none;
text-overflow: ellipsis;
}
.video-miniature-created-at-views {
font-size: 0.75em;
}
.video-miniature-created-at-views .views::before {
content: ' - '
}
.video-miniature-account {
hite-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
font-size: 0.75em;
color: #585858;
}

View File

@ -48,25 +48,25 @@ class FediClient
return $this->instance_url.'/oauth/authorize?'.$params;
}
public function register_client($redirect_uri, $scopes = 'read') {
$response = $this->_get('/api/v1/oauth-clients/local');
if (!isset($response->client_id)){
return "ERROR";
}
$this->app = $response;
$params = http_build_query(array(
'scope' => $scopes,
'client_id' =>$this->app->client_id,
'client_secret' =>$this->app->client_secret
));
$access_token = $this->_post('/api/v1/oauth-clients/local');
// return $this->instance_url.'/users/token?'.$params;
}
// public function register_client($redirect_uri, $scopes = 'read') {
//
// $response = $this->_get('/api/v1/oauth-clients/local');
//
// if (!isset($response->client_id)){
// return "ERROR";
// }
//
// $this->app = $response;
//
// $params = http_build_query(array(
// 'scope' => $scopes,
// 'client_id' =>$this->app->client_id,
// 'client_secret' =>$this->app->client_secret
// ));
//
// $access_token = $this->_post('/api/v1/oauth-clients/local');
// // return $this->instance_url.'/users/token?'.$params;
// }
public function verify_credentials($access_token){
@ -138,26 +138,15 @@ class FediClient
return $response;
}
public function getVideos($media = 'false', $pinned = 'false', $replies = 'false', $max_id = null, $since_id = null, $min_id = null, $limit = 10, $reblogs = 'false') {
public function getVideos($account_id, $is_channel) {
$headers = array(
'Authorization'=> 'Bearer '.$this->access_token
);
$headers = array();
$account_id = self::$acct_id;
// $query = http_build_query(array(
// 'only_media' => $media,
// 'pinned' => $pinned,
// 'exclude_replies' => $replies,
// 'max_id' => $max_id,
// 'since_id' => $since_id,
// 'min_id' => $min_id,
// 'limit' => $limit,
// 'exclude_reblogs' => $reblogs
// ));
$response = $this->_get("/api/v1/accounts/{$account_id}/videos", null, $headers);
if(!is_null($is_channel)){
$response = $this->_get("/api/v1/video-channels/{$account_id}/videos", null, $headers);
} else {
$response = $this->_get("/api/v1/accounts/{$account_id}/videos", null, $headers);
}
return $response;
}

View File

@ -0,0 +1,178 @@
<?php
class FediEmbedi_Mastodon extends WP_Widget {
/**
* Sets up a new FediEmbedi widget instance.
*
* @since 2.8.0
*/
public function __construct() {
$widget_ops = array(
'classname' => 'mastodon_widget',
'description' => __( 'Display a profile timeline', 'fediembedi' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'mastodon', _x( 'Mastodon', 'fediembedi' ), $widget_ops );
}
/**
* Outputs the content for the current Search widget instance.
*
* @since 2.8.0
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance Settings for the current Search widget instance.
*/
public function widget( $args, $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
//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);
//widget options
$show_header = (!empty($instance['show_header'])) ? $instance['show_header'] : '';
$only_media = (!empty($instance['only_media'])) ? $instance['only_media'] : '';
$pinned = (!empty($instance['pinned'])) ? $instance['pinned'] : '';
$exclude_replies = (!empty($instance['exclude_replies'])) ? $instance['exclude_replies'] : '';
$exclude_reblogs = (!empty($instance['exclude_reblogs'])) ? $instance['exclude_reblogs'] : '';
$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'];
};
//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' );
echo $args['after_widget'];
}
/**
* Outputs the settings form for the Search widget.
*
* @since 2.8.0
*
* @param array $instance Current settings.
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
//Radio inputs : https://wordpress.stackexchange.com/a/276659/87622
$show_header = (!empty( $instance['show_header'])) ? $instance['show_header'] : NULL;
$only_media = (!empty( $instance['only_media'])) ? $instance['only_media'] : NULL;
$pinned = (!empty($instance['pinned'])) ? $instance['pinned'] : NULL;
$exclude_replies = (!empty($instance['exclude_replies'])) ? $instance['exclude_replies'] : NULL;
$exclude_reblogs = (!empty($instance['exclude_reblogs'])) ? $instance['exclude_reblogs'] : NULL;
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
$height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '';
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'fediembedi'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($instance['title']); ?>" />
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'show_header' ], '1' ); ?>
id="<?php echo $this->get_field_id( '1' ); ?>"
name="<?php echo $this->get_field_name('show_header'); ?>"
value="1"
/><?php _e( 'Show header', 'fediembedi' ); ?>
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'only_media' ], '1' ); ?>
id="<?php echo $this->get_field_id( '1' ); ?>"
name="<?php echo $this->get_field_name('only_media'); ?>"
value="1"
/><?php _e( 'Only show media', 'fediembedi' ); ?>
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'pinned' ], '1' ); ?>
id="<?php echo $this->get_field_id( '1' ); ?>"
name="<?php echo $this->get_field_name('pinned'); ?>"
value="1"
/><?php _e( 'Only show pinned statuses', 'fediembedi' ); ?>
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'exclude_replies' ], '1' ); ?>
id="<?php echo $this->get_field_id( '1' ); ?>"
name="<?php echo $this->get_field_name('exclude_replies'); ?>"
value="1"
/><?php _e( 'Hide replies', 'fediembedi' ); ?>
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'exclude_reblogs' ], '1' ); ?>
id="<?php echo $this->get_field_id( '1' ); ?>"
name="<?php echo $this->get_field_name('exclude_reblogs'); ?>"
value="1"
/><?php _e( 'Hide reblogs', 'fediembedi' ); ?>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to display:' ); ?><br>
<input class="tiny-text" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="number" step="1" min="1" value="<?php echo $number; ?>" size="3" />
<small>Max: 20</small>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( 'Widget height:' ); ?><br>
<input class="" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo $height; ?>" placeholder="500px" size="5" />
<small><?php _e( 'Default: 100%', 'fediembedi' ); ?></small>
</label>
</p>
<?php
}
/**
* Handles updating settings for the current Search widget instance.
*
* @since 2.8.0
*
* @param array $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array $old_instance Old settings for this instance.
* @return array Updated settings.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '' ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['show_header'] = $new_instance['show_header'];
$instance['only_media'] = $new_instance['only_media'];
$instance['pinned'] = $new_instance['pinned'];
$instance['exclude_replies'] = $new_instance['exclude_replies'];
$instance['exclude_reblogs'] = $new_instance['exclude_reblogs'];
$instance['number'] = (int) $new_instance['number'];
$instance['height'] = sanitize_text_field( $new_instance['height'] );
return $instance;
}
}

View File

@ -0,0 +1,164 @@
<?php
class FediEmbedi_PeerTube extends WP_Widget {
/**
* Sets up a new FediEmbedi widget instance.
*
* @since 2.8.0
*/
public function __construct() {
$widget_ops = array(
'classname' => 'peertube_widget',
'description' => __( 'Display a profile timeline', 'fediembedi' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'peertube', _x( 'PeerTube', 'fediembedi' ), $widget_ops );
}
/**
* Outputs the content for the current Search widget instance.
*
* @since 2.8.0
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance Settings for the current Search widget instance.
*/
public function widget( $args, $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
//fedi instance
$fedi_instance = (!empty($instance['peertube'])) ? $instance['peertube'] : '';
$actor = (!empty($instance['actor'])) ? $instance['actor'] : '';
$is_channel = (!empty($instance['channel'])) ? $instance['channel'] : null;//radio channel or account
$client = new \FediClient($fedi_instance);
//widget options
$show_header = (!empty($instance['show_header'])) ? $instance['show_header'] : null;
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
$height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '100%';
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
};
//getVideos from remote instance
$status = $client->getVideos($actor, $is_channel);
if(!is_null($is_channel)){
$account = $status->data[0]->channel;
} else {
$account = $status->data[0]->account;
}
if(WP_DEBUG_DISPLAY === true): echo '<details><summary>PeerTube</summary><pre>'; var_dump($status); echo '</pre></details>'; endif;
include(plugin_dir_path(__FILE__) . 'templates/peertube.tpl.php' );
echo $args['after_widget'];
}
/**
* Outputs the settings form for the Search widget.
*
* @since 2.8.0
*
* @param array $instance Current settings.
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
//Radio inputs : https://wordpress.stackexchange.com/a/276659/87622
$peertube = (!empty($instance['peertube'])) ? $instance['peertube'] : NULL;
$actor = (!empty($instance['actor'])) ? $instance['actor'] : NULL;
$is_channel = (!empty($instance['channel'])) ? $instance['channel'] : NULL;
$show_header = (!empty( $instance['show_header'])) ? $instance['show_header'] : NULL;
$only_media = (!empty( $instance['only_media'])) ? $instance['only_media'] : NULL;
$pinned = (!empty($instance['pinned'])) ? $instance['pinned'] : NULL;
$exclude_replies = (!empty($instance['exclude_replies'])) ? $instance['exclude_replies'] : NULL;
$exclude_reblogs = (!empty($instance['exclude_reblogs'])) ? $instance['exclude_reblogs'] : NULL;
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
$height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '';
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'fediembedi'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($instance['title']); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('peertube'); ?>"><?php _e('PeerTube instance:', 'fediembedi'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('peertube'); ?>" name="<?php echo $this->get_field_name('peertube'); ?>" type="text" value="<?php echo esc_url($peertube, 'https'); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('actor'); ?>"><?php _e('User or Channel name:', 'fediembedi'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('actor'); ?>" name="<?php echo $this->get_field_name('actor'); ?>" type="text" value="<?php echo $actor; ?>" />
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'show_header' ], '1' ); ?>
id="<?php echo $this->get_field_id( 'show_header' ); ?>"
name="<?php echo $this->get_field_name('show_header'); ?>"
value="1"
/><?php _e( 'Show header', 'fediembedi' ); ?>
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'channel' ], '1' ); ?>
id="<?php echo $this->get_field_id( 'channel' ); ?>"
name="<?php echo $this->get_field_name('channel'); ?>"
value="1"
/><?php _e( 'Is this account a Channel?', 'fediembedi' ); ?>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to display:' ); ?><br>
<input class="tiny-text" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="number" step="1" min="1" value="<?php echo $number; ?>" size="3" />
<small>Max: 20</small>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( 'Widget height:' ); ?><br>
<input class="" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo $height; ?>" placeholder="500px" size="5" />
<small><?php _e( 'Default: 100%', 'fediembedi' ); ?></small>
</label>
</p>
<?php
}
/**
* Handles updating settings for the current Search widget instance.
*
* @since 2.8.0
*
* @param array $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array $old_instance Old settings for this instance.
* @return array Updated settings.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '' ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['peertube'] = esc_url($new_instance['peertube']);
$instance['actor'] = sanitize_key($new_instance['actor']);
$instance['channel'] = $new_instance['channel'];
$instance['show_header'] = $new_instance['show_header'];
$instance['only_media'] = $new_instance['only_media'];
$instance['pinned'] = $new_instance['pinned'];
$instance['exclude_replies'] = $new_instance['exclude_replies'];
$instance['exclude_reblogs'] = $new_instance['exclude_reblogs'];
$instance['number'] = (int) $new_instance['number'];
$instance['height'] = sanitize_text_field( $new_instance['height'] );
return $instance;
}
}

View File

@ -0,0 +1,177 @@
<?php
class FediEmbedi_Pixelfed extends WP_Widget {
/**
* Sets up a new FediEmbedi widget instance.
*
* @since 2.8.0
*/
public function __construct() {
$widget_ops = array(
'classname' => 'pixelfed_widget',
'description' => __( 'Display a profile timeline', 'fediembedi' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'pixelfed', _x( 'Pixelfed', 'fediembedi' ), $widget_ops );
}
/**
* Outputs the content for the current Search widget instance.
*
* @since 2.8.0
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance Settings for the current Search widget instance.
*/
public function widget( $args, $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
//fedi instance
$instance_url = get_option('fediembedi-pixelfed-instance');
$access_token = get_option('fediembedi-pixelfed-token');
$client = new \FediClient($instance_url, $access_token);
$cred = $client->verify_credentials($access_token);
//widget options
$show_header = (!empty($instance['show_header'])) ? $instance['show_header'] : '';
$only_media = (!empty($instance['only_media'])) ? $instance['only_media'] : '';
$pinned = (!empty($instance['pinned'])) ? $instance['pinned'] : '';
$exclude_replies = (!empty($instance['exclude_replies'])) ? $instance['exclude_replies'] : '';
$exclude_reblogs = (!empty($instance['exclude_reblogs'])) ? $instance['exclude_reblogs'] : '';
$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'];
};
$status = $client->getStatus($only_media, $pinned, $exclude_replies, null, null, null, $number, $exclude_reblogs);
include(plugin_dir_path(__FILE__) . 'templates/pixelfed.tpl.php' );
echo $args['after_widget'];
}
/**
* Outputs the settings form for the Search widget.
*
* @since 2.8.0
*
* @param array $instance Current settings.
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
//Radio inputs : https://wordpress.stackexchange.com/a/276659/87622
$show_header = (!empty( $instance['show_header'])) ? $instance['show_header'] : NULL;
$only_media = (!empty( $instance['only_media'])) ? $instance['only_media'] : NULL;
$pinned = (!empty($instance['pinned'])) ? $instance['pinned'] : NULL;
$exclude_replies = (!empty($instance['exclude_replies'])) ? $instance['exclude_replies'] : NULL;
$exclude_reblogs = (!empty($instance['exclude_reblogs'])) ? $instance['exclude_reblogs'] : NULL;
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
$height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '';
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'fediembedi'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($instance['title']); ?>" />
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'show_header' ], '1' ); ?>
id="<?php echo $this->get_field_id( '1' ); ?>"
name="<?php echo $this->get_field_name('show_header'); ?>"
value="1"
/><?php _e( 'Show header', 'fediembedi' ); ?>
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'only_media' ], '1' ); ?>
id="<?php echo $this->get_field_id( '1' ); ?>"
name="<?php echo $this->get_field_name('only_media'); ?>"
value="1"
/><?php _e( 'Only show media', 'fediembedi' ); ?>
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'pinned' ], '1' ); ?>
id="<?php echo $this->get_field_id( '1' ); ?>"
name="<?php echo $this->get_field_name('pinned'); ?>"
value="1"
/><?php _e( 'Only show pinned statuses', 'fediembedi' ); ?>
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'exclude_replies' ], '1' ); ?>
id="<?php echo $this->get_field_id( '1' ); ?>"
name="<?php echo $this->get_field_name('exclude_replies'); ?>"
value="1"
/><?php _e( 'Hide replies', 'fediembedi' ); ?>
</label>
</p>
<p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'exclude_reblogs' ], '1' ); ?>
id="<?php echo $this->get_field_id( '1' ); ?>"
name="<?php echo $this->get_field_name('exclude_reblogs'); ?>"
value="1"
/><?php _e( 'Hide reblogs', 'fediembedi' ); ?>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to display:' ); ?><br>
<input class="tiny-text" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="number" step="1" min="1" value="<?php echo $number; ?>" size="3" />
<small>Max: 20</small>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( 'Widget height:' ); ?><br>
<input class="" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo $height; ?>" placeholder="500px" size="5" />
<small><?php _e( 'Default: 100%', 'fediembedi' ); ?></small>
</label>
</p>
<?php
}
/**
* Handles updating settings for the current Search widget instance.
*
* @since 2.8.0
*
* @param array $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array $old_instance Old settings for this instance.
* @return array Updated settings.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '' ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['show_header'] = $new_instance['show_header'];
$instance['only_media'] = $new_instance['only_media'];
$instance['pinned'] = $new_instance['pinned'];
$instance['exclude_replies'] = $new_instance['exclude_replies'];
$instance['exclude_reblogs'] = $new_instance['exclude_reblogs'];
$instance['number'] = (int) $new_instance['number'];
$instance['height'] = sanitize_text_field( $new_instance['height'] );
return $instance;
}
}

View File

@ -1,43 +1,68 @@
<?php
define("FEDI_CONNECTED",isset($account) && $account !== null);
define("FEDI_MSTDN_CONNECTED",isset($mastodon_account) && $mastodon_account !== null);
define("FEDI_PXLFD_CONNECTED",isset($pixelfed_account) && $pixelfed_account !== null);
?>
<div class="wrap">
<h1><?php esc_html_e( 'FediEmbedi Configuration', 'fediembedi' ); ?></h1>
<br>
<br>
<br>
<p><?php _e( 'The currently supported software are Mastodon, Pleroma, Pixelfed, PeerTube.', 'fediembedi' ); ?></p>
<form method="POST">
<?php wp_nonce_field( 'fediembedi-configuration' ); ?>
<div style="display:<?php echo !FEDI_CONNECTED ? "block":"none"?>">
<input type="text" class="widefat instance_url" id="instance" name="instance" size="80" value="<?php esc_url_raw( $instance, 'https' ); ?>" list="mInstances">
<select class="widefat instance_type" id="instance_type" name="instance_type" value="<?php sanitize_key( $instance_type ); ?>">
<option value="Mastodon">Mastodon/Pleroma</option>
<option value="Pixelfed">Pixelfed</option>
</select>
<input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Connect to your instance', 'fediembedi' ); ?>" name="save" id="save">
<br><small><?php _e( 'The currently supported software are Mastodon, Pleroma, Pixelfed.', 'fediembedi' ); ?></small><br>
<p><?php _e( "Don't have an account?", 'fediembedi' ); ?></p>
<p><span class="mastodon"></span> Visit <a href="https://joinmastodon.org/" rel="noreferrer noopener" target="_blank" class="">joinmastodon.org</a> to find an instance.</p>
<p><span class="pixelfed"></span> Visit <a href="https://pixelfed.org/join" rel="noreferrer noopener" target="_blank" class="">pixelfed.org/join</a> to find an instance.</p>
</div>
<div style="display:<?php echo FEDI_CONNECTED ? "block" : "none"?>">
<div class="account">
<a href="<?php echo $account->url ?>" target="_blank"><img class="m-avatar" src="<?php echo $account->avatar ?>"></a>
<div class="details">
<?php if(FEDI_CONNECTED): ?>
<div class="connected"><?php esc_html_e( 'Connected as', 'fediembedi' ); ?>&nbsp;<?php echo $account->username ?></div>
<a class="link" href="<?php echo $account->url ?>" target="_blank"><?php echo $account->url ?></a>
<p><a href="<?php echo $_SERVER['REQUEST_URI'] . '&disconnect' ?>" class="button"><?php esc_html_e( 'Disconnect', 'fediembedi' ); ?></a>
<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 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>
<div style="display:<?php echo FEDI_MSTDN_CONNECTED ? "block" : "none"?>">
<div class="account">
<a href="<?php echo $mastodon_account->url ?>" target="_blank"><img class="m-avatar" src="<?php echo $mastodon_account->avatar ?>"><span class="mastodon"></span></a>
<div class="details">
<?php if(FEDI_MSTDN_CONNECTED): ?>
<div class="connected"><?php echo $mastodon_account->username ?></div>
<a class="link" href="<?php echo $mastodon_account->url ?>" target="_blank"><?php echo $mastodon_account->url ?></a>
<p><a href="<?php echo $_SERVER['REQUEST_URI'] . '&fediembedi-disconnect=mastodon' ?>" class="button"><?php esc_html_e( 'Disconnect', 'fediembedi' ); ?></a>
<?php else: ?>
<div class="disconnected"><?php esc_html_e( 'Disconnected', 'fediembedi' ); ?></div>
<?php endif ?>
</div>
<div class="separator"></div>
</div>
</div><div class="clear"></div>
</div>
</form>
<form method="POST">
<?php wp_nonce_field( 'fediembedi-configuration' ); ?>
<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 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>
<div style="display:<?php echo FEDI_PXLFD_CONNECTED ? "block" : "none"?>">
<div class="account">
<a href="<?php echo $pixelfed_account->url ?>" target="_blank"><img class="m-avatar" src="<?php echo $pixelfed_account->avatar ?>"><span class="pixelfed"></span></a>
<div class="details">
<?php if(FEDI_PXLFD_CONNECTED): ?>
<div class="connected"><?php echo $pixelfed_account->username ?></div>
<a class="link" href="<?php echo $pixelfed_account->url ?>" target="_blank"><?php echo $pixelfed_account->url ?></a>
<p><a href="<?php echo $_SERVER['REQUEST_URI'] . '&fediembedi-disconnect=pixelfed' ?>" class="button"><?php esc_html_e( 'Disconnect', 'fediembedi' ); ?></a>
<?php else: ?>
<div class="disconnected"><?php esc_html_e( 'Disconnected', 'fediembedi' ); ?></div>
<?php endif ?>
</div>
<div class="separator"></div>
</div><div class="clear"></div>
</div>
<div>
<p><span class="peertube"></span> Widget ready!
Visit <a href="https://joinpeertube.org" rel="noreferrer noopener" target="_blank" class="">joinpeertube.org</a> to find an instance.</p>
</div>
<div class="clear"></div>

View File

@ -4,7 +4,7 @@
* Plugin URI: https://git.feneas.org/mediaformat/fediembedi
* Github Plugin URI: https://github.com/mediaformat/fediembedi
* Description: A widget to show your Mastodon profile timeline
* Version: 0.7.2
* Version: 0.8.0
* Author: mediaformat
* Author URI: https://mediaformat.org
* License: GPLv3
@ -21,6 +21,7 @@ class FediConfig
{
add_action('plugins_loaded', array($this, 'init'));
add_action('widgets_init', array($this, 'fediembedi_widget'));
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'));
add_action('admin_notices', array($this, 'admin_notices'));
@ -41,19 +42,39 @@ class FediConfig
//load_plugin_textdomain('fediembedi', false, $plugin_dir . '/languages');
if (isset($_GET['code'])) {
//if (isset($_GET['code']) && isset($GET['instance_type'])) {
$instance_type = $_REQUEST['instance_type'];
$code = $_GET['code'];
$client_id = get_option('fediembedi-client-id');
$client_secret = get_option('fediembedi-client-secret');
switch ($instance_type) {
case 'mastodon':
$client_id = get_option('fediembedi-mastodon-client-id');
$client_secret = get_option('fediembedi-mastodon-client-secret');
break;
case 'pixelfed':
$client_id = get_option('fediembedi-pixelfed-client-id');
$client_secret = get_option('fediembedi-pixelfed-client-secret');
break;
}
if (!empty($code) && !empty($client_id) && !empty($client_secret)) {
//echo __('Authentification, please wait', 'fediembedi') . '...';
update_option('fediembedi-token', 'nada');
$instance = get_option('fediembedi-instance');
$client = new \FediClient($instance);
$token = $client->get_bearer_token($client_id, $client_secret, $code, get_admin_url());
//$instance_info = $client->getInstance();
switch ($instance_type) {
case 'mastodon':
update_option('fediembedi-mastodon-token', 'nada');
$instance = get_option('fediembedi-mastodon-instance');
$client = new \FediClient($instance);
$token = $client->get_bearer_token($client_id, $client_secret, $code, get_admin_url() . '?instance_type=' . $instance_type);
break;
case 'pixelfed':
update_option('fediembedi-pixelfed-token', 'nada');
$instance = get_option('fediembedi-pixelfed-instance');
$client = new \FediClient($instance);
$token = $client->get_bearer_token($client_id, $client_secret, $code, get_admin_url() . '?instance_type=' . $instance_type);
break;
}
if (isset($token->error)) {
//TODO: Proper error message
@ -68,12 +89,27 @@ class FediConfig
)
);
unset($token);
update_option('fediembedi-token', '');
switch ($instance_type) {
case 'mastodon':
update_option('fediembedi-mastodon-token', '');
break;
case 'pixelfed':
update_option('fediembedi-pixelfed-token', '');
break;
}
} else {
update_option('fediembedi-client-id', '');
update_option('fediembedi-client-secret', '');
update_option('fediembedi-token', $token->access_token);
//update_option('fediembedi-instance-type', $instance_type);
switch ($instance_type) {
case 'mastodon':
update_option('fediembedi-mastodon-client-id', '');
update_option('fediembedi-mastodon-client-secret', '');
update_option('fediembedi-mastodon-token', $token->access_token);
break;
case 'pixelfed':
update_option('fediembedi-pixelfed-client-id', '');
update_option('fediembedi-pixelfed-client-secret', '');
update_option('fediembedi-pixelfed-token', $token->access_token);
break;
}
}
$redirect_url = get_admin_url() . 'options-general.php?page=fediembedi';
@ -86,7 +122,8 @@ class FediConfig
exit;
}
$token = get_option('fediembedi-token');
$mastodon_token = get_option('fediembedi-mastodon-token');
$pixelfed_token = get_option('fediembedi-pixelfed-token');
}
@ -94,28 +131,43 @@ class FediConfig
* Widget
*/
public function fediembedi_widget() {
include(plugin_dir_path(__FILE__) . 'fediembedi-widget.php' );//
register_widget( 'WP_Widget_fediembedi' );
//Mastodon
include(plugin_dir_path(__FILE__) . 'fediembedi-mastodon-widget.php' );//
register_widget( 'FediEmbedi_Mastodon' );
//Pixelfed
include(plugin_dir_path(__FILE__) . 'fediembedi-pixelfed-widget.php' );//
register_widget( 'FediEmbedi_Pixelfed' );
//PeerTube
include(plugin_dir_path(__FILE__) . 'fediembedi-peertube-widget.php' );//
register_widget( 'FediEmbedi_PeerTube' );
}
public function enqueue_styles($hook)
{
if( is_active_widget( false, false, 'fediembedi') ) {
$instance_type = get_option('fediembedi-instance-type');
switch ($instance_type) {
case 'Mastodon':
wp_enqueue_style( 'mastodon', plugin_dir_url( __FILE__ ) . 'assets/mastodon.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'assets/mastodon.css') );
break;
case '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') );
//https://css-tricks.com/lozad-js-performant-lazy-loading-images/ lazyloading for background images
break;
default:
wp_enqueue_style( 'fediembedi', plugin_dir_url( __FILE__ ) . 'assets/mastodon.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'assets/mastodon.css') );
break;
}
if( is_active_widget( false, false, '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') ) {
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') ) {
wp_enqueue_style( 'peertube', plugin_dir_url( __FILE__ ) . 'assets/peertube.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'assets/mastodon.css') );
}
}
public function enqueue_scripts($hook)
{
global $pagenow;
$infos = get_plugin_data(__FILE__);
if ($pagenow == "options-general.php") {
//We might be on settings page <-- Do you know a bette solution to get if we are in our own settings page?
$plugin_url = plugin_dir_url(__FILE__);
//wp_enqueue_script('settings_page', $plugin_url . 'assets/settings_page.js', array('jquery'), $infos['Version'], true);
}
}
/**
@ -149,39 +201,36 @@ class FediConfig
wp_enqueue_style('fediembedi-configuration', plugin_dir_url(__FILE__) . 'style.css');
if (isset($_GET['disconnect'])) {
update_option('fediembedi-token', '');
}
if (isset($_GET['fediembedi-disconnect'])) {
switch ($_GET['fediembedi-disconnect']) {
case 'mastodon':
update_option('fediembedi-mastodon-token', '');
break;
case 'pixelfed':
update_option('fediembedi-pixelfed-token', '');
break;
}
$token = get_option('fediembedi-token');
}
$mastodon_instance = null;
$mastodon_token = get_option('fediembedi-mastodon-token');
$pixelfed_instance = null;
$pixelfed_token = get_option('fediembedi-pixelfed-token');
if (isset($_POST['save'])) {
$is_valid_nonce = wp_verify_nonce($_POST['_wpnonce'], 'fediembedi-configuration');
if ($is_valid_nonce) {
$instance = esc_url($_POST['instance']);
$instance_type = esc_attr($_POST['instance_type']);
//TODO switch($instance_type) case() return $scopes
$client = new \FediClient($instance);
$redirect_url = get_admin_url();
switch ($instance_type) {
case 'Mastodon':
$auth_url = $client->register_app($redirect_url);
break;
case 'Pixelfed':
$auth_url = $client->register_app($redirect_url);
break;
case 'PeerTube':
$auth_url = $client->register_client($redirect_url, 'user');
break;
}
//$auth_url = $client->register_app($redirect_url, $scopes);
$redirect_url = get_admin_url() . '?instance_type=' . $instance_type;
$auth_url = $client->register_app($redirect_url);
if ($auth_url == "ERROR") {
//var_dump('$auth_url = ERROR'); //die;
update_option(
'fediembedi-notice',
serialize(
@ -193,9 +242,7 @@ class FediConfig
);
} else {
//var_dump($auth_url); //die;
if (empty($instance)) {
//var_dump($instance); //die;
update_option(
'fediembedi-notice',
serialize(
@ -206,12 +253,25 @@ class FediConfig
)
);
} else {
update_option('fediembedi-client-id', $client->get_client_id());
update_option('fediembedi-client-secret', $client->get_client_secret());
update_option('fediembedi-instance', $instance);
update_option('fediembedi-instance-type', $instance_type);
$account = $client->verify_credentials($token);
switch ($instance_type) {
case 'mastodon':
update_option('fediembedi-mastodon-client-id', $client->get_client_id());
update_option('fediembedi-mastodon-client-secret', $client->get_client_secret());
update_option('fediembedi-mastodon-instance', $instance);
$mastodon_account = $client->verify_credentials($mastodon_token);
$account = $mastodon_account;
break;
case 'pixelfed':
update_option('fediembedi-pixelfed-client-id', $client->get_client_id());
update_option('fediembedi-pixelfed-client-secret', $client->get_client_secret());
update_option('fediembedi-pixelfed-instance', $instance);
$pixelfed_account = $client->verify_credentials($pixelfed_token);
$account = $pixelfed_account;
break;
}
//$account = $client->verify_credentials($token);
if (is_null($account) || isset($account->error)) {
echo '<meta http-equiv="refresh" content="0; url=' . $auth_url . '" />';
@ -237,12 +297,15 @@ class FediConfig
}
}
$instance = get_option('fediembedi-instance');
$instance_type = get_option('fediembedi-instance-type');
if (!empty($token)) {
$client = new \FediClient($instance);
$account = $client->verify_credentials($token);
if (!empty($mastodon_token)) {
$mastodon_instance = get_option('fediembedi-mastodon-instance');
$client = new \FediClient($mastodon_instance);
$mastodon_account = $client->verify_credentials($mastodon_token);
}
if (!empty($pixelfed_token)) {
$pixelfed_instance = get_option('fediembedi-pixelfed-instance');
$client = new \FediClient($pixelfed_instance);
$pixelfed_account = $client->verify_credentials($pixelfed_token);
}
include 'fediembedi-settings-form.tpl.php';

View File

@ -8,11 +8,12 @@ FediEmbedi will display your Mastodon, Pleroma, or Pixelfed timeline in a widget
* Mastodon
* Pleroma
* Pixelfed
* PeerTube
### Planned supported software
* PeerTube
* *Suggestions?*
* See the [board](https://git.feneas.org/mediaformat/fediembedi/-/boards)
* [Suggestions](https://git.feneas.org/mediaformat/fediembedi/issues)?
### Development
@ -47,6 +48,10 @@ and redirected to your site with a secure token. Similar to how you would connec
## Changelog
### 0.8.0
* Support PeerTube
* Support separate Mastodon, Pixelfed and PeerTube widgets.
### 0.7.2
* Renamed some classes and constants, and reorganized file structure

View File

@ -21,10 +21,11 @@ FediEmbedi will display your Mastodon, Pleroma, or Pixelfed timeline in a widget
* Mastodon
* Pleroma
* Pixelfed
* PeerTube
= Planned supported software =
* PeerTube
* *Suggestions?*
* See the [board](https://git.feneas.org/mediaformat/fediembedi/-/boards)
* [Suggestions](https://git.feneas.org/mediaformat/fediembedi/issues)?
= Development =
@ -58,7 +59,11 @@ and redirected to your site with a secure token. Similar to how you would connec
== Changelog ==
= 0.7.2
= 0.8.0 =
* Support PeerTube
* Support separate Mastodon, Pixelfed and PeerTube widgets.
= 0.7.2 =
* Renamed some classes and constants, and reorganized file structure
= 0.7.1 =

174
style.css
View File

@ -1,49 +1,7 @@
/* .wrap{
padding:10px;
border-radius:10px;
min-height:100%;
}
.wrap h1, .wrap label, .wrap form p{
color: #000;
}
.wrap .button{
color:#2b90d9 !important;
border-color:#2b90d9 !important;
box-shadow:none !important;
text-shadow:none !important;
font-weight:bold;
}
.wrap .button:hover{
background-color:transparent;
}
.wrap input, .wrap textarea{
background-color:transparent !important;
color:#000 !important;
border-color:#000;
border-radius:4px;
}
.wrap > form{
border:solid 1px #2b90d9;
padding:1%;
background-color:#FFF;
} */
.spacer{
margin-top: 20px;
}
.account{
border: 1px solid #000;
padding: 15px;
border-radius:4px;
float:left;
}
.m-avatar{
float:left;
border-radius: 100px;
@ -55,13 +13,8 @@
float:left;
}
.details .link{
color:#000;
text-decoration: none;
}
.connected{
color: #2b90d9;
color: #000;
font-size: 16px;
font-weight:bold;
margin-bottom: 10px;
@ -74,126 +27,21 @@
width: 100%;
}
.advanced_setting{
display:none;
}
/* .wrap .button:hover{
background-color:transparent;
}
.wrap input, .wrap textarea{
background-color:transparent !important;
color:#000 !important;
border-color:#000;
border-radius:4px;
} */
.spacer{
margin-top: 20px;
}
.account{
border: 1px solid #000;
padding: 15px;
border-radius:4px;
float:left;
margin: 0 0 1em;
width: 300px;
}
.m-avatar{
float:left;
border-radius: 100px;
margin-right: 20px;
width: 60px;
}
.details{
float:left;
}
.details .link{
color:#000;
text-decoration: none;
}
.connected{
color: #2b90d9;
font-size: 16px;
font-weight:bold;
margin-bottom: 10px;
}
.disconnected{
color: #FF0000;
font-size: 16px;
text-align: center;
width: 100%;
}
.advanced_setting{
display:none;
}
label{
display:inline-block;
vertical-align: bottom;
text-align:center;
}
.messageRadioButtons label{
padding:10px;
border:dashed 2px #000;
opacity:0.5;
}
.scopeRadioButtons label{
opacity:0.5;
margin-right:1em;
}
input[type="radio"]{
display:none;
}
.github-icon{
margin-right: 10px;
text-decoration: none;
position: relative;
}
html > body .liberapay-btn{
margin-top: 3px;
position: absolute;
}
.github-icon{
margin-right: 10px;
text-decoration: none;
position: relative;
}
.modeIcon{
height:1em;
}
html > body .liberapay-btn{
margin-top: 3px;
position: absolute;
}
.tab-button{
text-align:center;
margin-bottom:-1px !important;
border-bottom:none !important;
border-radius:0 !important;
}
.tab-button.active{
background-color:#FFF !important;
margin-bottom:-0px !important;
}
.pixelfed {
background: url('img/pixelfed.svg') no-repeat 0 0;
background-size: 30px;
@ -205,6 +53,14 @@ html > body .liberapay-btn{
width: 36px;
vertical-align: middle;
}
.account span.pixelfed {
float: left;
margin-left: -41px;
background-size: 30px;
margin-top: 41px;
}
.mastodon {
background: url('img/mastodon.svg') no-repeat 1px 4px;
background-size: 28px;
@ -215,6 +71,14 @@ html > body .liberapay-btn{
width: 36px;
vertical-align: middle;
}
.account span.mastodon {
float: left;
margin-left: -41px;
background-size: 30px;
margin-top: 41px;
}
.peertube {
background: url('img/peertube.svg') no-repeat 7px 4px;
background-size: 24px;
@ -225,9 +89,11 @@ html > body .liberapay-btn{
width: 36px;
vertical-align: middle;
}
.instance_url {
max-width: 500px;
}
.instance_type.widefat {
max-width: 160px;
vertical-align: baseline;

View File

@ -2,104 +2,52 @@
<div class="scrollable" style="height: <?php echo $height; ?>;">
<div role="feed">
<?php if($show_header): ?>
<div class="account-timeline__header">
<div class="account__header">
<div class="account__header__image">
<div class="account__header__info"></div>
<?php if ($status[0]->account->header): echo "<img src=" . $status[0]->account->header . " loading='lazy'>"; endif; ?>
</div>
<div class="account__header__bar">
<div class="account__header__tabs">
<a href="<?php echo $status[0]->account->url; ?>" class="avatar" rel="noreferrer noopener" target="_blank">
<div class="account__avatar" style="width:90px; height: 90px; background-image: url('<?php echo $status[0]->account->avatar; ?>'); background-size: cover;"></div>
<div class="peertube-timeline__header">
<div class="actor">
<img class="avatar" alt="Avatar" src="<?php echo esc_url($account->host) . $account->avatar->path; ?>" loading='lazy'>
<div class="actor-info">
<div class="actor-names">
<a href="<?php echo $account->url; ?>" class="actor-display-link" rel="noreferrer noopener" target="_blank">
<div class="actor-display-name"><?php echo $account->displayName; ?></div>
</a>
<div class="spacer"></div>
<div class="account__header__tabs__buttons">
<a href="<?php echo $status[0]->account->url; ?>" rel="noreferrer noopener" class="button logo-button"><?php _e('Follow', 'fediembedi'); ?></a>
</div>
</div>
<div class="account__header__tabs__name">
<h1>
<span><?php echo $status[0]->account->display_name; ?></span>
<small><a href="" target="_blank" rel="noreferrer noopener"><?php echo $status[0]->account->url; ?></a></small>
</h1>
</div>
<div class="account__header__extra">
<div class="account__header__bio">
<div class="account__header__content">
<?php echo $status[0]->account->note; ?>
</div>
</div>
<div class="actor-name"><?php echo $account->name; ?></div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php foreach ($status as $statut) { ?>
<article>
<div tabindex="-1">
<div class="status__wrapper status__wrapper-public focusable" tabindex="0">
<div class="status__prepend">
<?php
if(!is_null($statut->reblog)): ?>
<div class="status__prepend-icon-wrapper"><i role="img" class="fa fa-retweet status__prepend-icon fa-fw"></i></div>
</div><?php
else: echo '</div>';
endif; ?>
<div class="status status-public">
<div class="status__info">
<a href="<?php if(is_null($statut->reblog)): echo $statut->url; else: echo $statut->reblog->url; endif; ?>" class="status__relative-time" target="_blank" rel="noopener">
<time datetime="<?php echo $statut->created_at; ?>"><?php
printf( _x( '%1$s ago', '%2$s = human-readable time difference', 'fediembedi' ),
human_time_diff(
wp_date("U", strtotime($statut->created_at))
)
);
?></time>
</a>
<a href="<?php if(is_null($statut->reblog)): echo $statut->account->url; else: echo $statut->reblog->account->url; endif; ?>" class="status__display-name" rel="noopener noreferrer" target="_blank">
<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>
</a>
</div>
<div class="status__content"><?php
if(!is_null($statut->reblog)):
$statut = $statut->reblog;
endif;
if(empty($statut->spoiler_text)):
echo $statut->content;
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>
<div class="status-card__content">
<strong class="status-card__title" title="<?php echo $statut->card->title; ?>"><?php echo htmlentities($statut->card->title); ?></strong>
<p class="status-card__description"><?php echo wp_trim_words(htmlentities($statut->card->description)); ?></p>
<span class="status-card__host"><?php echo $statut->card->url; ?></span>
</div>
</a>
<?php
endif;
else: echo '<details><summary>' . $statut->spoiler_text . '</summary>'. $statut->content . '</details>';
endif;
if(!empty($statut->media_attachments)):
foreach ($statut->media_attachments as $attachment) {
if (!empty($attachment->preview_url) && $attachment->type === 'image'):
echo "<img src='" . $attachment->preview_url . "' class='media-gallery__item' alt='" . $attachment->description . "' loading='lazy'>";
elseif($attachment->type === 'video'):
echo "<video src=" . $attachment->url . " controls poster='" . $attachment->preview_url . "' class='media-gallery__item' alt=" . $attachment->description . ">";
elseif($attachment->type === 'audio'):
echo "<audio src=" . $attachment->url . " controls poster='" . $attachment->preview_url . "' class='media-gallery__item' alt=" . $attachment->description . ">";
endif;
}
endif;
?></div>
<div class="videos">
<?php foreach ($status->data as $statut) : ?>
<article class="video">
<div class="video-inner">
<div class="video-miniature">
<a href="<?php echo esc_url($account->host) . '/videos/watch/' . $statut->uuid; ?>" title="<?php echo $statut->name; ?>" class="video-thumbnail" target="_blank" rel="noopener">
<img src="<?php echo esc_url($account->host) . $statut->previewPath; ?>">
<div class="video-thumbnail-duration-overlay"><?php echo ($statut->duration > 3600 ? gmdate("g:i:s", $statut->duration) : gmdate("i:s", $statut->duration)); ?></div>
<div class="play-overlay">
<div class="icon"></div>
</div>
</a>
</div>
<div class="video-bottom">
<div class="video-miniature-information">
<a class="video-miniature-name" title="<?php echo $statut->name; ?>" href="<?php echo esc_url($account->host) . '/videos/watch/' . $statut->uuid; ?>"><?php echo $statut->name; ?></a>
<div class="video-miniature-created-at-views">
<time datetime="<?php echo $statut->publishedAt; ?>"><?php
printf( _x( '%1$s ago', '%2$s = human-readable time difference', 'fediembedi' ),
human_time_diff(
wp_date("U", strtotime($statut->publishedAt))
)
);
?></time>
<span class="views"><?php printf( _x( '%1$s views', '%2$s = number of views', 'fediembedi' ), $statut->views); ?></span>
</div>
<!-- <a class="video-miniature-account" href="<?php echo esc_url($account->host) . $account->avatar->path; ?>"><?php echo $statut->account->name; ?></a> -->
</div>
</div>
</div>
</article>
<?php } ?>
<?php endforeach; ?>
</div>
</div>
</div>

View File

@ -1,5 +1,4 @@
<!-- pixelfed -->
<?php $instance_url = get_option('fediembedi-instance'); ?>
<div class="scrollable" style="height: <?php echo $height; ?>;">
<div role="feed" class="embed-card pixelfed">
<div class="pixelfed-inner card status-card-embed card-md-rounded-0 border">