'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 PeerTube 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 PeerTube 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; $count = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; $nsfw = isset( $instance['nsfw'] ) ? $instance['nsfw'] : null; $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, $count, $nsfw); //if(WP_DEBUG_DISPLAY === true): echo '
PeerTube
'; var_dump($status); echo '
'; endif; 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']; } /** * Outputs the settings form for the PeerTube 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; $nsfw = isset( $instance['nsfw'] ) ? $instance['nsfw'] : false; $height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : ''; ?>

'' ) ); $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['nsfw'] = $new_instance['nsfw']; $instance['height'] = sanitize_text_field( $new_instance['height'] ); return $instance; } }