Commit 352ff0ea authored by MediaFormat's avatar MediaFormat

Refactor and Fix widget title

parent 43f7a926
<?php
/**
* The Client class contains all the methods to
* connect to your fediverse instance
*/
class Client
{
private $instance_url;
......@@ -20,12 +23,12 @@ class Client
return self::$acct_id;
}
public function register_app($redirect_uri) {
public function register_app($redirect_uri, $scopes = 'read') {
$response = $this->_post('/api/v1/apps', array(
'client_name' => 'FediEmbedi for WordPress',
'redirect_uris' => $redirect_uri,
'scopes' => 'read',
'scopes' => $scopes,
'website' => get_site_url()
));
......@@ -38,7 +41,7 @@ class Client
$params = http_build_query(array(
'response_type' => 'code',
'redirect_uri' => $redirect_uri,
'scope' => 'read',
'scope' => $scopes,
'client_id' =>$this->app->client_id
));
......@@ -131,47 +134,6 @@ class Client
return $response;
}
public function postStatus($status, $mode, $media = '', $spoiler_text = '') {
$headers = array(
'Authorization'=> 'Bearer '.$this->access_token
);
$response = $this->_post('/api/v1/statuses', array(
'status' => $status,
'visibility' => $mode,
'spoiler_text' => $spoiler_text,
'media_ids[]' => $media
), $headers);
return $response;
}
public function create_attachment($media_path) {
$filename =basename($media_path);
$mime_type = mime_content_type($media_path);
$boundary ='hlx'.time();
$headers = array (
'Authorization'=> 'Bearer '.$this->access_token,
'Content-Type' => 'multipart/form-data; boundary='. $boundary,
);
$nl = "\r\n";
$data = '--'.$boundary.$nl;
$data .= 'Content-Disposition: form-data; name="file"; filename="'.$filename.'"'.$nl;
$data .= 'Content-Type: '. $mime_type .$nl.$nl;
$data .= file_get_contents($media_path) .$nl;
$data .= '--'.$boundary.'--';
$response = $this->_post('/api/v1/media', $data, $headers);
return $response;
}
private function _post($url, $data = array(), $headers = array()) {
return $this->post($this->instance_url.$url, $data, $headers);
}
......
......@@ -12,13 +12,16 @@ define("ADVANCED_VIEW",false);
<form method="POST">
<?php wp_nonce_field( 'fediembedi-configuration' ); ?>
<div style="display:<?php echo !ACCOUNT_CONNECTED ? "block":"none"?>">
<input type="text" id="instance" name="instance" size="80" value="<?php esc_attr_e( $instance ); ?>" list="mInstances">
<select class="" id="instance_type" name="instance_type" value="<?php esc_attr_e( $instance_type ); ?>">
<input type="text" class="widefat instance_url" id="instance" name="instance" size="80" value="<?php esc_attr_e( $instance ); ?>" list="mInstances">
<select class="widefat instance_type" id="instance_type" name="instance_type" value="<?php esc_attr_e( $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>The currently supported software are Mastodon, Pleroma, Pixelfed.</small>
<br><small>The currently supported software are Mastodon, Pleroma, Pixelfed.</small><br>
<p>Don't have an account?</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 ACCOUNT_CONNECTED ? "block" : "none"?>">
<div class="account">
......
<?php
//fedi instance
$fedi_instance = get_option('fediembedi-instance');
$access_token = get_option('fediembedi-token');
$client = new \Client($fedi_instance, $access_token);
$cred = $client->verify_credentials($access_token);
//$profile = $client->getAccount();
//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%';
//Default query
$query = http_build_query(array(
'only_media' => $only_media,
'pinned' => $pinned,
'exclude_replies' => $exclude_replies,
'limit' => 5,
'exclude_reblogs' => $exclude_reblogs
));
$status = $client->getStatus($only_media, $pinned, $exclude_replies, null, null, null, $number, $exclude_reblogs);
$instance_type = get_option('fediembedi-instance-type');
switch ($instance_type) {
case 'Mastodon':
include(plugin_dir_path(__FILE__) . 'fediembedi-mastodon.tpl.php' );
break;
case 'Pixelfed':
include(plugin_dir_path(__FILE__) . 'fediembedi-pixelfed.tpl.php' );
break;
default:
include(plugin_dir_path(__FILE__) . 'fediembedi-mastodon.tpl.php' );
break;
} ?>
......@@ -3,7 +3,7 @@
class WP_Widget_fediembedi extends WP_Widget {
/**
* Sets up a new Search widget instance.
* Sets up a new FediEmbedi widget instance.
*
* @since 2.8.0
*/
......@@ -26,7 +26,44 @@ class WP_Widget_fediembedi extends WP_Widget {
* @param array $instance Settings for the current Search widget instance.
*/
public function widget( $args, $instance ) {
include(plugin_dir_path(__FILE__) . 'fediembedi-widget-template.php' );//fediembedi_widget_template
$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
//fedi instance
$fedi_instance = get_option('fediembedi-instance');
$access_token = get_option('fediembedi-token');
$client = new \Client($fedi_instance, $access_token);
$cred = $client->verify_credentials($access_token);
//$profile = $client->getAccount();
//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%';
//getStatus from remote instance
$status = $client->getStatus($only_media, $pinned, $exclude_replies, null, null, null, $number, $exclude_reblogs);
$instance_type = get_option('fediembedi-instance-type');
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
};
switch ($instance_type) {
case 'Mastodon':
include(plugin_dir_path(__FILE__) . 'mastodon/fediembedi-mastodon.tpl.php' );
break;
case 'Pixelfed':
include(plugin_dir_path(__FILE__) . 'pixelfed/fediembedi-pixelfed.tpl.php' );
break;
default:
include(plugin_dir_path(__FILE__) . 'mastodon/fediembedi-mastodon.tpl.php' );
break;
}
echo $args['after_widget'];
}
/**
......@@ -111,12 +148,16 @@ class WP_Widget_fediembedi extends WP_Widget {
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of items to show:' ); ?></label>
<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" />
<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:' ); ?></label>
<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" />
<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>Default: 100%</small>
</label>
</p>
<?php
}
......
......@@ -4,10 +4,11 @@
* Plugin URI: https://git.feneas.org/mediaformat/fediembedi
* Github Plugin URI: https://git.feneas.org/mediaformat/fediembedi
* Description: A widget to show your Mastodon profile timeline
* Version: 0.5.0
* Version: 0.6.0
* Author: mediaformat
* Author URI: https://mediaformat.org
* License: GPL2
* License: GPLv3
* License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
* Text Domain: fediembedi
* Domain Path: /languages
*/
......@@ -55,8 +56,7 @@ class FediConfig
//$instance_info = $client->getInstance();
if (isset($token->error)) {
//print_r($token);
//TODO: Propper error message
//TODO: Proper error message
update_option(
'fediembedi-notice',
serialize(
......@@ -87,17 +87,6 @@ class FediConfig
}
$token = get_option('fediembedi-token');
// if (empty($token)) {
// update_option(
// 'fediembedi-notice',
// serialize(
// array(
// 'message' => '<strong>FediEmbedi</strong> : ' . __('Please login to your account!', 'fediembedi') . '<a href="' . get_admin_url() . 'options-general.php?page=fediembedi"> ' . __('Go to FediEmbedi configuration', 'fediembedi') . '</a>',
// 'class' => 'error',
// )
// )
// );
// }
}
......@@ -113,12 +102,18 @@ class FediConfig
{
if( is_active_widget( false, false, 'fediembedi') ) {
$instance_type = get_option('fediembedi-instance-type');
if ($instance_type === 'Mastodon') {
wp_enqueue_style( 'fediembedi', plugin_dir_url( __FILE__ ) . 'mastodon.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'mastodon.css') );
} else {
//https://css-tricks.com/lozad-js-performant-lazy-loading-images/ lazyloading for background images
wp_enqueue_style( 'fediembedi', plugin_dir_url( __FILE__ ) . 'pixelfed.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'pixelfed.css') );
}
switch ($instance_type) {
case 'Mastodon':
wp_enqueue_style( 'fediembedi', plugin_dir_url( __FILE__ ) . 'mastodon/mastodon.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'mastodon/mastodon.css') );
break;
case 'Pixelfed':
wp_enqueue_style( 'fediembedi', plugin_dir_url( __FILE__ ) . 'pixelfed/pixelfed.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'pixelfed/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__ ) . 'mastodon/mastodon.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'mastodon/mastodon.css') );
break;
}
}
}
......@@ -166,10 +161,12 @@ class FediConfig
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 \Client($instance);
$redirect_url = get_admin_url();
$auth_url = $client->register_app($redirect_url);
//$auth_url = $client->register_app($redirect_url, $scopes);
if ($auth_url == "ERROR") {
//var_dump('$auth_url = ERROR'); //die;
......@@ -236,7 +233,7 @@ class FediConfig
$account = $client->verify_credentials($token);
}
include 'form.tpl.php';
include 'fediembedi-settings-form.tpl.php';
}
/**
......
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 216.4144 232.00976"><path d="M211.80734 139.0875c-3.18125 16.36625-28.4925 34.2775-57.5625 37.74875-15.15875 1.80875-30.08375 3.47125-45.99875 2.74125-26.0275-1.1925-46.565-6.2125-46.565-6.2125 0 2.53375.15625 4.94625.46875 7.2025 3.38375 25.68625 25.47 27.225 46.39125 27.9425 21.11625.7225 39.91875-5.20625 39.91875-5.20625l.8675 19.09s-14.77 7.93125-41.08125 9.39c-14.50875.7975-32.52375-.365-53.50625-5.91875C9.23234 213.82 1.40609 165.31125.20859 116.09125c-.365-14.61375-.14-28.39375-.14-39.91875 0-50.33 32.97625-65.0825 32.97625-65.0825C49.67234 3.45375 78.20359.2425 107.86484 0h.72875c29.66125.2425 58.21125 3.45375 74.8375 11.09 0 0 32.975 14.7525 32.975 65.0825 0 0 .41375 37.13375-4.59875 62.915" fill="#3088d4"/><path d="M177.50984 80.077v60.94125h-24.14375v-59.15c0-12.46875-5.24625-18.7975-15.74-18.7975-11.6025 0-17.4175 7.5075-17.4175 22.3525v32.37625H96.20734V85.42325c0-14.845-5.81625-22.3525-17.41875-22.3525-10.49375 0-15.74 6.32875-15.74 18.7975v59.15H38.90484V80.077c0-12.455 3.17125-22.3525 9.54125-29.675 6.56875-7.3225 15.17125-11.07625 25.85-11.07625 12.355 0 21.71125 4.74875 27.8975 14.2475l6.01375 10.08125 6.015-10.08125c6.185-9.49875 15.54125-14.2475 27.8975-14.2475 10.6775 0 19.28 3.75375 25.85 11.07625 6.36875 7.3225 9.54 17.22 9.54 29.675" fill="#fff"/></svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="svg4485"
width="209.00002"
height="334"
viewBox="0 0 209.00002 334"
sodipodi:docname="pleroma_logo_vector_nobg_nopad.svg"
inkscape:version="0.92.1 r15371">
<metadata
id="metadata4491">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs4489" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2560"
inkscape:window-height="1387"
id="namedview4487"
showgrid="false"
inkscape:zoom="2"
inkscape:cx="49.747283"
inkscape:cy="227.83408"
inkscape:window-x="1912"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="svg4485" />
<g
id="g4612"
transform="translate(-152,-89)">
<path
sodipodi:nodetypes="cccccc"
inkscape:connector-curvature="0"
id="path4495"
d="M 235,89 V 423 H 152 V 115 l 26,-26 z"
style="opacity:1;fill:#fba457;fill-opacity:1;stroke:#009bff;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.17587938" />
<circle
r="26"
cx="178"
cy="115"
id="path4497"
style="opacity:1;fill:#fba457;fill-opacity:1;stroke:#009bff;stroke-width:0;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.17587938" />
<circle
r="26"
cx="335"
cy="230"
id="path4497-0"
style="opacity:1;fill:#fba457;fill-opacity:1;stroke:#009bff;stroke-width:0;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.17587938" />
<path
sodipodi:nodetypes="cccccc"
inkscape:connector-curvature="0"
id="path4516"
d="M 277,256 V 89 l 84,3e-6 L 361.00002,230 335,256 Z"
style="fill:#fba457;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<circle
r="26"
cx="335"
cy="397"
id="path4497-0-6"
style="opacity:1;fill:#fba457;fill-opacity:1;stroke:#009bff;stroke-width:0;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.17587938" />
<path
sodipodi:nodetypes="cccccc"
inkscape:connector-curvature="0"
id="path4516-5"
d="m 277,423 v -83 h 84 l 2e-5,57 L 335,423 Z"
style="opacity:1;fill:#fba457;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
</svg>
This diff is collapsed.
This diff is collapsed.
......@@ -289,7 +289,7 @@
margin: 1em 0;
}
i.fa-retweet {
background-image: url('img/retoot.svg');
background-image: url('../img/retoot.svg');
background-position: 0 0;
height: 19px;
vertical-align: middle;
......
......@@ -291,7 +291,7 @@
margin: 1em 0;
}
i.fa-retweet {
background-image: url('img/retoot.svg');
background-image: url('../img/retoot.svg');
background-position: 0 0;
height: 19px;
vertical-align: middle;
......@@ -301,3 +301,7 @@ i.fa-retweet {
z-index: 10;
position: relative;
}
/**
* Pixelfed Styles
*/
# FediEmbedi
Display your Fediverse timeline in a widget
## Description
> FediEmbedi is beta software.
TLDR; Display your Fediverse timeline in a widget
FediEmbedi will display your Mastodon, Pleroma, or Pixelfed timeline in a widget, with various display options.
......@@ -22,7 +17,7 @@ FediEmbedi will display your Mastodon, Pleroma, or Pixelfed timeline in a widget
### Development
For the time being development will happen on [git.feneas.org](https://git.feneas.org/mediaformat/fediembedi) .
For the time being development will happen on [git.feneas.org](https://git.feneas.org/mediaformat/fediembedi).
### Updates
......@@ -78,8 +73,7 @@ and redirected to your site with a secure token. Similar to how you would connec
### Mastodon Autopost
The App registration, oAuth connection and portions of the Mastodon API code is based on [Mastodon Autopost](https://wordpress.org/plugins/autopost-to-mastodon/).
The client connection code is based on [Mastodon Autopost](https://wordpress.org/plugins/autopost-to-mastodon/).
### Mastodon
The CSS and SVG icon come from the Mastodon project
### FediEmbedi
The name FediEmbedi was contributed by [@liaizon@wake.st](https://social.wake.st/@liaizon)
=== Plugin Name ===
Contributors: dj_angola
Donate link: https://paypal.me/MediaFormat
Tags: mastodon, pixelfed, fediverse
Tags: mastodon, pixelfed, fediverse, activitypub, widget
Requires at least: 5.1
Tested up to: 5.3.2
Requires PHP: 7.2
......@@ -58,6 +58,12 @@ and redirected to your site with a secure token. Similar to how you would connec
== Changelog ==
= 0.6.0 =
* TODO: Copy Changelog to readme.md
* TODO: Style/Script for Pixelfed
* Updated settings page, with links for finding an instance to join/register
* Clarify widget options
= 0.5.0 =
* Mirror plugin on Github for use with [Github Updater](https://github.com/afragen/github-updater)
......@@ -79,7 +85,7 @@ and redirected to your site with a secure token. Similar to how you would connec
== Credits ==
= Mastodon Autopost =
The App registration, oAuth connection and portions of the Mastodon API code are based on [Mastodon Autopost](https://wordpress.org/plugins/autopost-to-mastodon/).
The client connection code is based on [Mastodon Autopost](https://wordpress.org/plugins/autopost-to-mastodon/).
= Mastodon =
The CSS and SVG icon come from the Mastodon project
= FediEmbedi =
The name FediEmbedi was contributed by [@liaizon@wake.st](https://social.wake.st/@liaizon).
......@@ -194,3 +194,31 @@ html > body .liberapay-btn{
background-color:#FFF !important;
margin-bottom:-0px !important;
}
.pixelfed {
background: url('img/pixelfed.svg') no-repeat 0 0;
background-size: 30px;
border: none;
border-radius: 50%;
color: transparent;
display: inline-block;
height: 32px;
width: 36px;
vertical-align: middle;
}
.mastodon {
background: url('img/mastodon.svg') no-repeat 3px 4px;
background-size: 28px;
border: none;
color: transparent;
display: inline-block;
height: 36px;
width: 36px;
vertical-align: middle;
}
.instance_url {
max-width: 500px;
}
.instance_type.widefat {
max-width: 160px;
vertical-align: baseline;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment