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

Prepares release 1.0.7

parent 2aaca58c
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
* *
*/ */
defined('ABSPATH') or die("No script kiddies please!"); 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 { class CollectMastodonData {
...@@ -56,19 +57,28 @@ class CollectMastodonData { ...@@ -56,19 +57,28 @@ class CollectMastodonData {
private function filterComments($descendants, $root, &$result) { private function filterComments($descendants, $root, &$result) {
foreach ($descendants as $d) { foreach ($descendants as $d) {
if( $d['visibility'] === "public") if( $d['visibility'] === "public") {
$result['comments'][$d['id']] = [ $content = $d['content'];
'author' => [ if( !empty($d['emojis'])){
'display_name' => $d['account']['display_name'], foreach ($d['emojis'] as $emoji){
'avatar' => $d['account']['avatar_static'], $shortcode = $emoji['shortcode'];
'url' => $d['account']['url'] $url = $emoji['url'];
], $content = str_replace(":" . $shortcode . ":", "<img alt=':". $shortcode .":' width=15 src='" .$url."'/>" , $content);
'toot' => $d['content'], }
'date' => $d['created_at'], }
'url' => $d['uri'], $result['comments'][ $d['id'] ] = [
'reply_to' => $d['in_reply_to_id'], 'author' => [
'root' => $root, '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; return $result;
......
=== Mastalab comments === === Mastalab comments ===
Contributors: (this should be a list of wordpress.org userid's) Contributors: stom79
Donate link: https://liberapay.com/tom79/ Donate link: https://liberapay.com/tom79/
Tags: comments, Mastodon, Mastalab Tags: comments, Mastodon, Mastalab
Contributors: stom79
Requires at least: 4.6 Requires at least: 4.6
Tested up to: 4.7 Tested up to: 4.7
Requires PHP: 5.2.4 Requires PHP: 5.2.4
...@@ -15,11 +14,18 @@ Mastalab comments allows to display comments from Mastodon and Peertube related ...@@ -15,11 +14,18 @@ Mastalab comments allows to display comments from Mastodon and Peertube related
== Description == == 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. 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. 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. 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 == == Installation ==
This section describes how to install the plugin and get it working. This section describes how to install the plugin and get it working.
...@@ -33,6 +39,17 @@ e.g. ...@@ -33,6 +39,17 @@ e.g.
== Changelog == == 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 = = 1.0.4 =
* Add a cache feature * Add a cache feature
* Use Wordpress HTTP API instead of cURL * Use Wordpress HTTP API instead of cURL
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
defined('ABSPATH') or die("No script kiddies please!"); defined('ABSPATH') or die("No script kiddies please!");
@session_start(); @session_start();
@define('ROOTPATH', __DIR__); @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 $active_tab;
global $wpdb; global $wpdb;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* Plugin Name: Mastalab comments * Plugin Name: Mastalab comments
* Plugin URI: https://mastalab.app * Plugin URI: https://mastalab.app
* Description: Display comments coming from Mastodon and Peertube related to a URL * Description: Display comments coming from Mastodon and Peertube related to a URL
* Version: 1.0.6 * Version: 1.0.7
* Author: Thomas Schneider * Author: Thomas Schneider
* Author URI: https://gitlab.com/tom79/mastodon-comments-for-wordpress * Author URI: https://gitlab.com/tom79/mastodon-comments-for-wordpress
* License: GPL-2.0+ * License: GPL-2.0+
...@@ -35,7 +35,7 @@ if ( ! defined( 'WPINC' ) ) { ...@@ -35,7 +35,7 @@ if ( ! defined( 'WPINC' ) ) {
* Start at version 1.0.0 and use SemVer - https://semver.org * 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. * 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. * The code that runs during plugin activation.
......
...@@ -116,13 +116,19 @@ class Mastalab_comments_Public { ...@@ -116,13 +116,19 @@ class Mastalab_comments_Public {
wp_localize_script( $this->plugin_name, 'params', $params ); 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(){ public function prefix_ajax_mastalab_comments_getcomment_peertube(){
global $wpdb; global $wpdb;
$result = ['comments' => [], 'stats' => ['reblogs' => 0, 'favs' => 0, 'replies' => 0, 'url' => '', 'root' => 0]]; $result = ['comments' => [], 'stats' => ['reblogs' => 0, 'favs' => 0, 'replies' => 0, 'url' => '', 'root' => 0]];
$search = isset($_GET['search']) ? $_GET['search'] : ''; $search = isset($_GET['search']) ? $_GET['search'] : '';
@define('ROOTPATH', __DIR__); @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(); $MastodonAPI = new Mastodon_api();
$source = isset($_GET['source']) ? $_GET['source'] : '#'; $source = isset($_GET['source']) ? $_GET['source'] : '#';
$source = str_replace("embed","watch",$source); $source = str_replace("embed","watch",$source);
...@@ -154,7 +160,6 @@ class Mastalab_comments_Public { ...@@ -154,7 +160,6 @@ class Mastalab_comments_Public {
'date' => $dateInsert->format( 'Y-m-d H:i:s' ), 'date' => $dateInsert->format( 'Y-m-d H:i:s' ),
'URL' => urlencode( $search ), 'URL' => urlencode( $search ),
'cache' => json_encode( $searchResult ) 'cache' => json_encode( $searchResult )
) )
); );
} else{ //Update cache } else{ //Update cache
...@@ -162,7 +167,7 @@ class Mastalab_comments_Public { ...@@ -162,7 +167,7 @@ class Mastalab_comments_Public {
$wpdb->prefix . "mastalab_comments_cache", $wpdb->prefix . "mastalab_comments_cache",
array( array(
'date' => $dateInsert->format( 'Y-m-d H:i:s' ), 'date' => $dateInsert->format( 'Y-m-d H:i:s' ),
'cache' => json_encode( $result ) 'cache' => json_encode( $searchResult )
), ),
array( 'URL' => urlencode( $search )) array( 'URL' => urlencode( $search ))
); );
...@@ -201,6 +206,13 @@ class Mastalab_comments_Public { ...@@ -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(){ public function prefix_ajax_mastalab_comments_getcomment(){
......
...@@ -43,15 +43,14 @@ ...@@ -43,15 +43,14 @@
var targeted_element = "#comments"; var targeted_element = "#comments";
if( typeof params.selector !== "undefined") if( typeof params.selector !== "undefined")
targeted_element = params.selector; targeted_element = params.selector;
if( typeof data.stats === "undefined") if( typeof data.stats === "undefined" || data.comments.length === 0)
return; return;
var stats = data.stats; var stats = data.stats;
var root = data.stats.root; var root = data.stats.root;
var element = jQuery('<div/>', { var element = jQuery('<div/>', {
id: 'mastalab_comments', id: 'mastalab_comments',
class: 'mastodon comments-container', class: 'mastodon comments-container'
title: 'Mastodon Comments'
}); });
if( typeof params.mastodon_bg) if( typeof params.mastodon_bg)
element.css("background-color", params.mastodon_bg); element.css("background-color", params.mastodon_bg);
...@@ -59,8 +58,7 @@ ...@@ -59,8 +58,7 @@
element.css("color", params.mastodon_text); element.css("color", params.mastodon_text);
var elementCounter = jQuery('<div/>', { var elementCounter = jQuery('<div/>', {
id: 'mastalab_comments_counters', id: 'mastalab_comments_counters',
class: 'mastodon_container_counters', class: 'mastodon_container_counters'
title: 'Mastodon Comments Counters'
}); });
$("<style type='text/css'> " + $("<style type='text/css'> " +
".mastodon.comments-container{ background-color:"+params.mastodon_bg +";color:" + params.mastodon_text + "}" + ".mastodon.comments-container{ background-color:"+params.mastodon_bg +";color:" + params.mastodon_text + "}" +
...@@ -131,12 +129,11 @@ ...@@ -131,12 +129,11 @@
'mastalab_comments_nonce': params.mastalab_comments_nonce 'mastalab_comments_nonce': params.mastalab_comments_nonce
}, },
function(data){ function(data){
if( typeof data.stats === "undefined") if( typeof data.stats === "undefined" || data.comments.length === 0)
return; return;
var stats = data.stats; var stats = data.stats;
var element = jQuery('<div/>', { var element = jQuery('<div/>', {
class: 'peertube comments-container', class: 'peertube comments-container'
title: 'Mastodon Comments'
}); });
$("<style type='text/css'> " + $("<style type='text/css'> " +
".peertube.comments-container{ background-color:"+params.peertube_bg +" !important;color:" + params.peertube_text + " !important;}" + ".peertube.comments-container{ background-color:"+params.peertube_bg +" !important;color:" + params.peertube_text + " !important;}" +
...@@ -163,7 +160,6 @@ ...@@ -163,7 +160,6 @@
comment += "<div class='toot'>" + value.toot + "</div>"; comment += "<div class='toot'>" + value.toot + "</div>";
comment += "</div>"; comment += "</div>";
element.append(comment); element.append(comment);
$(peertubeComment).prepend(element);
}); });
$(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