1
0
mirror of https://git.feneas.org/mediaformat/fediembedi synced 2024-12-22 15:24:20 +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;
}
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();
$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)){
$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 {
$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;

View File

@ -37,7 +37,8 @@ class FediEmbedi_PeerTube extends WP_Widget {
//widget options
$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%';
echo $args['before_widget'];
@ -46,13 +47,13 @@ class FediEmbedi_PeerTube extends WP_Widget {
};
//getVideos from remote instance
$status = $client->getVideos($actor, $is_channel);
$status = $client->getVideos($actor, $is_channel, $count, $nsfw);
if(!is_null($is_channel)){
$account = $status->data[0]->channel;
} else {
$account = $status->data[0]->account;
}
include(plugin_dir_path(__FILE__) . 'templates/peertube.tpl.php' );
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_reblogs = (!empty($instance['exclude_reblogs'])) ? $instance['exclude_reblogs'] : NULL;
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
$nsfw = isset( $instance['nsfw'] ) ? $instance['nsfw'] : false;
$height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '';
?>
@ -126,6 +128,17 @@ class FediEmbedi_PeerTube extends WP_Widget {
</label>
</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>
<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>
@ -157,6 +170,7 @@ class FediEmbedi_PeerTube extends WP_Widget {
$instance['exclude_replies'] = $new_instance['exclude_replies'];
$instance['exclude_reblogs'] = $new_instance['exclude_reblogs'];
$instance['number'] = (int) $new_instance['number'];
$instance['nsfw'] = $new_instance['nsfw'];
$instance['height'] = sanitize_text_field( $new_instance['height'] );
return $instance;
}

View File

@ -3,7 +3,7 @@
* Plugin Name: FediEmbedi
* Plugin URI: https://git.feneas.org/mediaformat/fediembedi
* Description: Widgets and shortcodes to show your Fediverse profile timeline
* Version: 0.10.4
* Version: 0.10.5
* Author: mediaformat
* Author URI: https://mediaformat.org
* License: GPLv3
@ -104,13 +104,13 @@ class FediConfig
} else {
switch ($instance_type) {
case 'mastodon':
update_option('fediembedi-mastodon-client-id', '');
update_option('fediembedi-mastodon-client-secret', '');
update_option('fediembedi-mastodon-client-id', $client_id);//
update_option('fediembedi-mastodon-client-secret', $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-client-id', $client_id);//
update_option('fediembedi-pixelfed-client-secret', $client_secret);//
update_option('fediembedi-pixelfed-token', $token->access_token);
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']);
//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'];
$account = $status[0]->account;
ob_start();
include(plugin_dir_path(__FILE__) . 'templates/pixelfed.tpl.php' );
return ob_get_clean();
if($account = $status[0]->account){
ob_start();
include(plugin_dir_path(__FILE__) . 'templates/pixelfed.tpl.php' );
return ob_get_clean();
} else {
return;
}
}
public function peertube_shortcode($atts){
@ -224,7 +227,7 @@ class FediConfig
$client = new \FediClient($atts['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'])){
$account = $status->data[0]->channel;
} else {

View File

@ -53,6 +53,9 @@ and redirected to your site with a secure token. Similar to how you would connec
## Changelog
### 0.10.5
* Bug fix: Template issues.
### 0.10.4
* 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 ==
= 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
= 0.10.3 =

View File

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

View File

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

View File

@ -1,5 +1,5 @@
<!-- 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 class="pixelfed-inner card status-card-embed card-md-rounded-0 border">
<?php if($show_header): ?>
@ -37,15 +37,16 @@
<div class="pixelfed-images row mt-4 mb-1 px-1">
<?php foreach ($status as $statut) { ?>
<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">
<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>
</a><?php
elseif($statut->media_attachments[0]->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 . ">";
elseif($attachment->type === 'video'): ?>
<video src="<?php echo $attachment->url; ?>" controls poster="<?php echo $attachment->preview_url; ?>" class='media-gallery__item' alt="<?php echo $attachment->description; ?>">;
endif; ?>
</article>
<?php } ?>
@ -53,7 +54,7 @@
</div>
<div class="pixelfed-footer card-footer bg-white">
<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>