Commit 7970e4a7 authored by Thomas's avatar Thomas
Browse files

Prepares release 1.0.7

parent 2aaca58c
......@@ -19,7 +19,8 @@
*
*/
defined('ABSPATH') or die("No script kiddies please!");
require_once 'Mastodon_api.php';
if( !class_exists ( 'Mastodon_api'))
require_once 'Mastodon_api.php';
class CollectMastodonData {
......@@ -56,19 +57,28 @@ class CollectMastodonData {
private function filterComments($descendants, $root, &$result) {
foreach ($descendants as $d) {
if( $d['visibility'] === "public")
$result['comments'][$d['id']] = [
'author' => [
'display_name' => $d['account']['display_name'],
'avatar' => $d['account']['avatar_static'],
'url' => $d['account']['url']
],
'toot' => $d['content'],
'date' => $d['created_at'],
'url' => $d['uri'],
'reply_to' => $d['in_reply_to_id'],
'root' => $root,
];
if( $d['visibility'] === "public") {
$content = $d['content'];
if( !empty($d['emojis'])){
foreach ($d['emojis'] as $emoji){
$shortcode = $emoji['shortcode'];
$url = $emoji['url'];
$content = str_replace(":" . $shortcode . ":", "<img alt=':". $shortcode .":' width=15 src='" .$url."'/>" , $content);
}
}
$result['comments'][ $d['id'] ] = [
'author' => [
'display_name' => $d['account']['display_name'],
'avatar' => $d['account']['avatar_static'],
'url' => $d['account']['url']
],
'toot' => $content,
'date' => $d['created_at'],
'url' => $d['uri'],
'reply_to' => $d['in_reply_to_id'],
'root' => $root,
];
}
}
return $result;
......
=== Mastalab comments ===
Contributors: (this should be a list of wordpress.org userid's)
Contributors: stom79
Donate link: https://liberapay.com/tom79/
Tags: comments, Mastodon, Mastalab
Contributors: stom79
Requires at least: 4.6
Tested up to: 4.7
Requires PHP: 5.2.4
......@@ -15,11 +14,18 @@ Mastalab comments allows to display comments from Mastodon and Peertube related
== Description ==
Mastalab Comments is a plugin for Mastodon and Peertube. You will need an account on a Mastodon instance like mastodon.social.
If you don't have an account, you can pick up an instance at https://instances.social an register on it.
Mastodon is a decentralized social Network, that means it's run by several instances (host).
The plugin uses the Mastodon and Peertube API (the last one currently doesn't need credentials).
You need to connect an account to your Mastodon instance. The plugin will only uses the scope "read" to fetch toots containing your Wordpress URL.
The plugin will use an authorization code for the authentication. You will be able to disconnect or change the connected account at any time.
If you want to hide comment, use your connected account on Mastodon to mute the accounts that you don't want to see comments.
== Installation ==
This section describes how to install the plugin and get it working.
......@@ -33,6 +39,17 @@ e.g.
== Changelog ==
= 1.0.7 =
* Add custom emojis
* Fix an issue with Peertube comments and cache
* Improve README.txt
= 1.0.6 =
* Improve README.txt
= 1.0.5 =
* Improve the compatibility with WP
= 1.0.4 =
* Add a cache feature
* Use Wordpress HTTP API instead of cURL
......
......@@ -8,7 +8,8 @@
defined('ABSPATH') or die("No script kiddies please!");
@session_start();
@define('ROOTPATH', __DIR__);
require_once(ROOTPATH.'/../../../Class/Mastodon_api.php');
if( !class_exists ( 'Mastodon_api'))
require_once(ROOTPATH.'/../../../Class/Mastodon_api.php');
global $active_tab;
global $wpdb;
......
......@@ -16,7 +16,7 @@
* Plugin Name: Mastalab comments
* Plugin URI: https://mastalab.app
* Description: Display comments coming from Mastodon and Peertube related to a URL
* Version: 1.0.6
* Version: 1.0.7
* Author: Thomas Schneider
* Author URI: https://gitlab.com/tom79/mastodon-comments-for-wordpress
* License: GPL-2.0+
......@@ -35,7 +35,7 @@ if ( ! defined( 'WPINC' ) ) {
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'PLUGIN_NAME_VERSION', '1.0.6' );
define( 'PLUGIN_NAME_VERSION', 'mastalab_comments_1.0.7' );
/**
* The code that runs during plugin activation.
......
......@@ -116,13 +116,19 @@ class Mastalab_comments_Public {
wp_localize_script( $this->plugin_name, 'params', $params );
}
/**
* Get remote comments for Peertube related to its URL
* Values are cached
*
* @since 1.0.1
*/
public function prefix_ajax_mastalab_comments_getcomment_peertube(){
global $wpdb;
$result = ['comments' => [], 'stats' => ['reblogs' => 0, 'favs' => 0, 'replies' => 0, 'url' => '', 'root' => 0]];
$search = isset($_GET['search']) ? $_GET['search'] : '';
@define('ROOTPATH', __DIR__);
require_once(ROOTPATH.'/../Class/Mastodon_api.php');
if( !class_exists ( 'Mastodon_api'))
require_once(ROOTPATH.'/../Class/Mastodon_api.php');
$MastodonAPI = new Mastodon_api();
$source = isset($_GET['source']) ? $_GET['source'] : '#';
$source = str_replace("embed","watch",$source);
......@@ -154,7 +160,6 @@ class Mastalab_comments_Public {
'date' => $dateInsert->format( 'Y-m-d H:i:s' ),
'URL' => urlencode( $search ),
'cache' => json_encode( $searchResult )
)
);
} else{ //Update cache
......@@ -162,7 +167,7 @@ class Mastalab_comments_Public {
$wpdb->prefix . "mastalab_comments_cache",
array(
'date' => $dateInsert->format( 'Y-m-d H:i:s' ),
'cache' => json_encode( $result )
'cache' => json_encode( $searchResult )
),
array( 'URL' => urlencode( $search ))
);
......@@ -201,6 +206,13 @@ class Mastalab_comments_Public {
}
/**
* Get remote comments from Mastodon related to a URL
* Values are cached
*
* @since 1.0.0
*/
public function prefix_ajax_mastalab_comments_getcomment(){
......
......@@ -43,15 +43,14 @@
var targeted_element = "#comments";
if( typeof params.selector !== "undefined")
targeted_element = params.selector;
if( typeof data.stats === "undefined")
if( typeof data.stats === "undefined" || data.comments.length === 0)
return;
var stats = data.stats;
var root = data.stats.root;
var element = jQuery('<div/>', {
id: 'mastalab_comments',
class: 'mastodon comments-container',
title: 'Mastodon Comments'
class: 'mastodon comments-container'
});
if( typeof params.mastodon_bg)
element.css("background-color", params.mastodon_bg);
......@@ -59,8 +58,7 @@
element.css("color", params.mastodon_text);
var elementCounter = jQuery('<div/>', {
id: 'mastalab_comments_counters',
class: 'mastodon_container_counters',
title: 'Mastodon Comments Counters'
class: 'mastodon_container_counters'
});
$("<style type='text/css'> " +
".mastodon.comments-container{ background-color:"+params.mastodon_bg +";color:" + params.mastodon_text + "}" +
......@@ -131,12 +129,11 @@
'mastalab_comments_nonce': params.mastalab_comments_nonce
},
function(data){
if( typeof data.stats === "undefined")
if( typeof data.stats === "undefined" || data.comments.length === 0)
return;
var stats = data.stats;
var element = jQuery('<div/>', {
class: 'peertube comments-container',
title: 'Mastodon Comments'
class: 'peertube comments-container'
});
$("<style type='text/css'> " +
".peertube.comments-container{ background-color:"+params.peertube_bg +" !important;color:" + params.peertube_text + " !important;}" +
......@@ -163,7 +160,6 @@
comment += "<div class='toot'>" + value.toot + "</div>";
comment += "</div>";
element.append(comment);
$(peertubeComment).prepend(element);
});
$(peertubeComment).prepend(element);
}
......
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