1
0
mirror of https://git.feneas.org/mediaformat/fediembedi synced 2024-12-22 20:08:10 +01:00

Fix count on peertube widget, add nsfw option

This commit is contained in:
Django Doucet 2020-10-20 22:55:07 -04:00
parent aa239d24bc
commit db2bb224c1
8 changed files with 71 additions and 33 deletions

View File

@ -138,14 +138,28 @@ class FediClient
return $response; return $response;
} }
public function getVideos($account_id, $is_channel) { public function getVideos($account_id, $is_channel, $count, $nsfw = false) {
//https://docs.joinpeertube.org/api-rest-reference.html#tag/Video
$headers = array(); $headers = array();
$query = http_build_query(array(
//'categoryOneOf' => $categoryID,
'count' => $count,
//'filter' => $filter,
//'languageOneOf' => $lang,
//'licenceOneOf' => $licence,
'nsfw' => $nsfw,
//'skipCount' => $skipCount,
//'sort' => $sort,
//'start' => $offset,
//'tagsAllOf' => $tagsAllOf,//videos where all tags are present
//'tagsOneOf' => $tags
));
if(!is_null($is_channel)){ if(!is_null($is_channel)){
$response = $this->_get("/api/v1/video-channels/{$account_id}/videos", null, $headers); $response = $this->_get("/api/v1/video-channels/{$account_id}/videos?{$query}", null, $headers);
} else { } else {
$response = $this->_get("/api/v1/accounts/{$account_id}/videos", null, $headers); $response = $this->_get("/api/v1/accounts/{$account_id}/videos?{$query}", null, $headers);
} }
return $response; return $response;

View File

@ -37,7 +37,8 @@ class FediEmbedi_PeerTube extends WP_Widget {
//widget options //widget options
$show_header = (!empty($instance['show_header'])) ? $instance['show_header'] : null; $show_header = (!empty($instance['show_header'])) ? $instance['show_header'] : null;
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; $count = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
$nsfw = isset( $instance['nsfw'] ) ? $instance['nsfw'] : false;
$height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '100%'; $height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '100%';
echo $args['before_widget']; echo $args['before_widget'];
@ -46,13 +47,13 @@ class FediEmbedi_PeerTube extends WP_Widget {
}; };
//getVideos from remote instance //getVideos from remote instance
$status = $client->getVideos($actor, $is_channel); $status = $client->getVideos($actor, $is_channel, $count, $nsfw);
if(!is_null($is_channel)){ if(!is_null($is_channel)){
$account = $status->data[0]->channel; $account = $status->data[0]->channel;
} else { } else {
$account = $status->data[0]->account; $account = $status->data[0]->account;
} }
include(plugin_dir_path(__FILE__) . 'templates/peertube.tpl.php' ); include(plugin_dir_path(__FILE__) . 'templates/peertube.tpl.php' );
echo $args['after_widget']; echo $args['after_widget'];
@ -79,6 +80,7 @@ class FediEmbedi_PeerTube extends WP_Widget {
$exclude_replies = (!empty($instance['exclude_replies'])) ? $instance['exclude_replies'] : NULL; $exclude_replies = (!empty($instance['exclude_replies'])) ? $instance['exclude_replies'] : NULL;
$exclude_reblogs = (!empty($instance['exclude_reblogs'])) ? $instance['exclude_reblogs'] : NULL; $exclude_reblogs = (!empty($instance['exclude_reblogs'])) ? $instance['exclude_reblogs'] : NULL;
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
$nsfw = isset( $instance['nsfw'] ) ? $instance['nsfw'] : false;
$height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : ''; $height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '';
?> ?>
@ -126,6 +128,17 @@ class FediEmbedi_PeerTube extends WP_Widget {
</label> </label>
</p> </p>
<p> <p>
<label>
<input
type="checkbox"
<?php checked( $instance[ 'nsfw' ], '0' ); ?>
id="<?php echo $this->get_field_id( 'nsfw' ); ?>"
name="<?php echo $this->get_field_name('nsfw'); ?>"
value="0"
/><?php _e( 'Show NSFW videos?', 'fediembedi' ); ?>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( 'Widget height:' ); ?><br> <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" /> <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> <small><?php _e( 'Default: 100%', 'fediembedi' ); ?></small>
@ -157,6 +170,7 @@ class FediEmbedi_PeerTube extends WP_Widget {
$instance['exclude_replies'] = $new_instance['exclude_replies']; $instance['exclude_replies'] = $new_instance['exclude_replies'];
$instance['exclude_reblogs'] = $new_instance['exclude_reblogs']; $instance['exclude_reblogs'] = $new_instance['exclude_reblogs'];
$instance['number'] = (int) $new_instance['number']; $instance['number'] = (int) $new_instance['number'];
$instance['nsfw'] = $new_instance['nsfw'];
$instance['height'] = sanitize_text_field( $new_instance['height'] ); $instance['height'] = sanitize_text_field( $new_instance['height'] );
return $instance; return $instance;
} }

View File

@ -3,7 +3,7 @@
* Plugin Name: FediEmbedi * Plugin Name: FediEmbedi
* Plugin URI: https://git.feneas.org/mediaformat/fediembedi * Plugin URI: https://git.feneas.org/mediaformat/fediembedi
* Description: Widgets and shortcodes to show your Fediverse profile timeline * Description: Widgets and shortcodes to show your Fediverse profile timeline
* Version: 0.10.4 * Version: 0.10.5
* Author: mediaformat * Author: mediaformat
* Author URI: https://mediaformat.org * Author URI: https://mediaformat.org
* License: GPLv3 * License: GPLv3
@ -104,13 +104,13 @@ class FediConfig
} else { } else {
switch ($instance_type) { switch ($instance_type) {
case 'mastodon': case 'mastodon':
update_option('fediembedi-mastodon-client-id', ''); update_option('fediembedi-mastodon-client-id', $client_id);//
update_option('fediembedi-mastodon-client-secret', ''); update_option('fediembedi-mastodon-client-secret', $client_secret);//
update_option('fediembedi-mastodon-token', $token->access_token); update_option('fediembedi-mastodon-token', $token->access_token);
break; break;
case 'pixelfed': case 'pixelfed':
update_option('fediembedi-pixelfed-client-id', ''); update_option('fediembedi-pixelfed-client-id', $client_id);//
update_option('fediembedi-pixelfed-client-secret', ''); update_option('fediembedi-pixelfed-client-secret', $client_secret);//
update_option('fediembedi-pixelfed-token', $token->access_token); update_option('fediembedi-pixelfed-token', $token->access_token);
break; break;
} }
@ -205,10 +205,13 @@ class FediConfig
$status = $client->getStatus($atts['only_media'], $atts['pinned'], $atts['exclude_replies'], null, null, null, $atts['limit'], $atts['exclude_reblogs']); $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 '<details><summary>Mastodon</summary><pre>'; var_dump($client->getStatus($atts)); echo '</pre></details>'; endif; //if(WP_DEBUG_DISPLAY === true): echo '<details><summary>Mastodon</summary><pre>'; var_dump($client->getStatus($atts)); echo '</pre></details>'; endif;
$show_header = $atts['show_header']; $show_header = $atts['show_header'];
$account = $status[0]->account; if($account = $status[0]->account){
ob_start(); ob_start();
include(plugin_dir_path(__FILE__) . 'templates/pixelfed.tpl.php' ); include(plugin_dir_path(__FILE__) . 'templates/pixelfed.tpl.php' );
return ob_get_clean(); return ob_get_clean();
} else {
return;
}
} }
public function peertube_shortcode($atts){ public function peertube_shortcode($atts){
@ -224,7 +227,7 @@ class FediConfig
$client = new \FediClient($atts['instance']); $client = new \FediClient($atts['instance']);
//getVideos from remote instance //getVideos from remote instance
$status = $client->getVideos($atts['actor'], $atts['is_channel']); $status = $client->getVideos($atts['actor'], $atts['is_channel'], $atts['limit'], $atts['nsfw'] );
if(!is_null($atts['is_channel'])){ if(!is_null($atts['is_channel'])){
$account = $status->data[0]->channel; $account = $status->data[0]->channel;
} else { } else {

View File

@ -53,6 +53,9 @@ and redirected to your site with a secure token. Similar to how you would connec
## Changelog ## Changelog
### 0.10.5
* Bug fix: Template issues.
### 0.10.4 ### 0.10.4
* Bug fix: Embed included in post edit screen, causing post save issues. * Bug fix: Embed included in post edit screen, causing post save issues.

View File

@ -64,7 +64,10 @@ and redirected to your site with a secure token. Similar to how you would connec
== Changelog == == Changelog ==
= 0.10.3 = = 0.10.5 =
* Bug fix: Template issues.
= 0.10.4 =
* Bug fix: Embed included in post edit screen, causing post save issues * Bug fix: Embed included in post edit screen, causing post save issues
= 0.10.3 = = 0.10.3 =

View File

@ -1,5 +1,5 @@
<!-- mastodon --> <!-- mastodon -->
<div class="scrollable" style="height: <?php echo $height; ?>;"> <div class="scrollable" <?php if ($height) : echo 'style="height: $height;"'; ?>>
<div role="feed"> <div role="feed">
<?php if($show_header): ?> <?php if($show_header): ?>
<div class="account-timeline__header"> <div class="account-timeline__header">
@ -95,13 +95,13 @@
endif; endif;
if(!empty($statut->media_attachments)): if(!empty($statut->media_attachments)):
foreach ($statut->media_attachments as $attachment) { foreach ($statut->media_attachments as $attachment) {
if (!empty($attachment->preview_url) && $attachment->type === 'image'): if (!empty($attachment->preview_url) && $attachment->type === 'image'): ?>
echo "<img src='" . $attachment->preview_url . "' class='media-gallery__item' alt='" . $attachment->description . "' loading='lazy'>"; <img src="<?php echo $attachment->preview_url; ?>" class="media-gallery__item" alt="<?php echo $attachment->description; ?>" loading="lazy">;
elseif($attachment->type === 'video'): <?php elseif($attachment->type === 'video'): ?>
echo "<video src=" . $attachment->url . " controls poster='" . $attachment->preview_url . "' class='media-gallery__item' alt=" . $attachment->description . ">"; <video src="<?php echo $attachment->url; ?>" controls poster="<?php echo $attachment->preview_url; ?>" class='media-gallery__item' alt="<?php echo $attachment->description; ?>">;
elseif($attachment->type === 'audio'): <?php elseif($attachment->type === 'audio'): ?>
echo "<audio src=" . $attachment->url . " controls poster='" . $attachment->preview_url . "' class='media-gallery__item' alt=" . $attachment->description . ">"; <audio src="<?php echo $attachment->url; ?>" controls poster="<?php echo $attachment->preview_url; ?>" class='media-gallery__item' alt="<?php echo $attachment->description; ?>">;
endif; <?php endif;
} }
endif; endif;
?></div> ?></div>

View File

@ -1,5 +1,5 @@
<!-- peertube --> <!-- peertube -->
<div class="scrollable" style="height: <?php echo $height; ?>;"> <div class="scrollable" <?php if ($height) : echo 'style="height: $height;"'; ?>>
<div role="feed"> <div role="feed">
<?php if($show_header): ?> <?php if($show_header): ?>
<div class="peertube-timeline__header"> <div class="peertube-timeline__header">

View File

@ -1,5 +1,5 @@
<!-- pixelfed --> <!-- pixelfed -->
<div class="scrollable" style="height: <?php echo $height; ?>;"> <div class="scrollable" <?php if ($height) : echo 'style="height: $height;"'; ?>>
<div role="feed" class="embed-card pixelfed"> <div role="feed" class="embed-card pixelfed">
<div class="pixelfed-inner card status-card-embed card-md-rounded-0 border"> <div class="pixelfed-inner card status-card-embed card-md-rounded-0 border">
<?php if($show_header): ?> <?php if($show_header): ?>
@ -37,15 +37,16 @@
<div class="pixelfed-images row mt-4 mb-1 px-1"> <div class="pixelfed-images row mt-4 mb-1 px-1">
<?php foreach ($status as $statut) { ?> <?php foreach ($status as $statut) { ?>
<article class="col-4 mt-2 px-0"><?php <article class="col-4 mt-2 px-0"><?php
if (!empty($statut->media_attachments[0]->preview_url) && $statut->media_attachments[0]->type === 'image'): ?> $attachment = $statut->media_attachments[0];
if (!empty($attachment->preview_url) && $attachment->type === 'image'): ?>
<a href="<?php echo $statut->url; ?>" class="card info-overlay card-md-border-0 px-1 shadow-none" target="_blank" rel="noopener"> <a href="<?php echo $statut->url; ?>" class="card info-overlay card-md-border-0 px-1 shadow-none" target="_blank" rel="noopener">
<div class="square"> <div class="square">
<div style='background-image: url(<?php echo $statut->media_attachments[0]->preview_url; ?>);' class='square-content' alt='<?php $statut->media_attachments[0]->description; ?>'></div> <div style='background-image: url(<?php echo $attachment->preview_url; ?>);' class='square-content' alt='<?php $attachment->description; ?>'></div>
<div class="info-text-overlay"></div> <div class="info-text-overlay"></div>
</div> </div>
</a><?php </a><?php
elseif($statut->media_attachments[0]->type === 'video'): elseif($attachment->type === 'video'): ?>
echo "<video src=" . $attachment->url . " controls poster='" . $statut->media_attachments[0]->preview_url . "' class='media-gallery__item' alt=" . $statut->media_attachments[0]->description . ">"; <video src="<?php echo $attachment->url; ?>" controls poster="<?php echo $attachment->preview_url; ?>" class='media-gallery__item' alt="<?php echo $attachment->description; ?>">;
endif; ?> endif; ?>
</article> </article>
<?php } ?> <?php } ?>
@ -53,7 +54,7 @@
</div> </div>
<div class="pixelfed-footer card-footer bg-white"> <div class="pixelfed-footer card-footer bg-white">
<div class="text-center mb-0"> <div class="text-center mb-0">
<a href="<?php echo $status[0]->account->url; ?>" class="font-weight-bold" target="_blank" rel="noreferrer noopener"><?php _e('View More Posts', 'fediembedi'); ?></a> <a href="<?php echo $account->url; ?>" class="font-weight-bold" target="_blank" rel="noreferrer noopener"><?php _e('View More Posts', 'fediembedi'); ?></a>
</div> </div>
</div> </div>
</div> </div>