Skip to content
Snippets Groups Projects
Commit 7595b51e authored by lucha's avatar lucha
Browse files

[auto] plugin: autopost-to-mastodon 3.2.6

parent 87d5e10d
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ define("ADVANCED_VIEW",false);
<svg aria-hidden="true" class="octicon octicon-mark-github" height="32" version="1.1" viewBox="0 0 16 16" width="32"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg>
</a>
<a href="https://liberapay.com/Mastodon-Auto-Share-Team/donate" target="_blank"><img src="<?php echo plugins_url( 'img/donate.svg', __FILE__ );?>"></a>
<a href="https://paypal.me/51edpo" target="_blank"><img src="<?php echo plugins_url( 'img/paypal.png', __FILE__ );?>" style="height:30px;"></a> <a href="https://patreon.com/simonfrey" target="_blank"><img src="<?php echo plugins_url( 'img/patron.png', __FILE__ );?>" style="height:30px;"></a> <a href="https://liberapay.com/Mastodon-Auto-Share-Team/donate" target="_blank"><img src="<?php echo plugins_url( 'img/donate.svg', __FILE__ );?>"></a>
<br>
<br>
<?php if(ACCOUNT_CONNECTED): ?>
......
......@@ -3,7 +3,7 @@
* Plugin Name: Mastodon Autopost
* Plugin URI: https://github.com/simonfrey/mastodon_wordpress_autopost
* Description: A Wordpress Plugin that automatically posts your new articles to Mastodon
* Version: 3.2.2
* Version: 3.2.6
* Author: L1am0
* Author URI: http://www.simon-frey.eu
* License: GPL2
......@@ -11,13 +11,12 @@
* Domain Path: /languages
*/
require_once 'client.php';
class autopostToMastodon
{
public function __construct(){
public function __construct()
{
add_action('plugins_loaded', array($this, 'init'));
add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
add_action('admin_menu', array($this, 'configuration_page'));
......@@ -36,7 +35,8 @@ class autopostToMastodon
*
* @return void
*/
public function init(){
public function init()
{
$plugin_dir = basename(dirname(__FILE__));
load_plugin_textdomain('autopost-to-mastodon', false, $plugin_dir . '/languages');
......@@ -45,8 +45,7 @@ class autopostToMastodon
$client_id = get_option('autopostToMastodon-client-id');
$client_secret = get_option('autopostToMastodon-client-secret');
if(!empty($code) && !empty($client_id) && !empty($client_secret))
{
if (!empty($code) && !empty($client_id) && !empty($client_secret)) {
echo __('Authentification, please wait', 'autopost-to-mastodon') . '...';
update_option('autopostToMastodon-token', 'nada');
......@@ -76,9 +75,7 @@ class autopostToMastodon
update_option('autopostToMastodon-token', $token->access_token);
}
$redirect_url = get_admin_url() . 'options-general.php?page=autopost-to-mastodon';
}
else
{
} else {
//Probably hack or bad refresh, redirect to homepage
$redirect_url = home_url();
}
......@@ -107,7 +104,8 @@ class autopostToMastodon
*
* @return void
*/
public function enqueue_scripts($hook) {
public function enqueue_scripts($hook)
{
global $pagenow;
......@@ -125,7 +123,7 @@ class autopostToMastodon
$title_nonce = wp_create_nonce('mastodonNonce');
wp_localize_script('toot_editor', 'ajax_obj', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => $title_nonce
'nonce' => $title_nonce,
));
}
}
......@@ -137,11 +135,12 @@ class autopostToMastodon
*
* @return void
*/
public function configuration_page() {
public function configuration_page()
{
add_options_page(
'Mastodon Autopost',
'Mastodon Autopost',
'install_plugins',
'manage_options',
'autopost-to-mastodon',
array($this, 'show_configuration_page')
);
......@@ -155,7 +154,8 @@ class autopostToMastodon
* @throws Exception The exception.
* @return void
*/
public function show_configuration_page() {
public function show_configuration_page()
{
wp_enqueue_style('autopostToMastodon-configuration', plugin_dir_url(__FILE__) . 'style.css');
......@@ -269,7 +269,8 @@ class autopostToMastodon
* @param int $id The post ID.
* @return void
*/
public function toot_post( $id ) {
public function toot_post($id)
{
$post = get_post($id);
......@@ -310,7 +311,7 @@ class autopostToMastodon
serialize(
array(
'message' => '<strong>Mastodon Autopost</strong> : ' . __('Toot saved for schedule !', 'autopost-to-mastodon'),
'class' => 'info'
'class' => 'info',
)
)
);
......@@ -324,12 +325,10 @@ class autopostToMastodon
if ($thumb_url) {
$thumb_path = str_replace(get_site_url(), get_home_path(), $thumb_url);
$attachment = $client->create_attachment($thumb_path);
if(is_object($attachment))
{
if (is_object($attachment)) {
$media = $attachment->id;
}
}
......@@ -373,13 +372,14 @@ class autopostToMastodon
* Toot_scheduled_post
* @param integer $post_id
*/
public function toot_scheduled_post($post_id) {
public function toot_scheduled_post($post_id)
{
$instance = get_option('autopostToMastodon-instance');
$access_token = get_option('autopostToMastodon-token');
$mode = get_option('autopostToMastodon-mode', 'public');
$message = get_post_meta($post_id, 'autopostToMastodon-toot', true);
$message = $this->getTootFromTemplate($post_id);
if (!empty($message)) {
$thumb_url = get_the_post_thumbnail_url($post_id);
$thumb_path = get_post_meta($post_id, 'autopostToMastodon-toot-thumbnail', true);
......@@ -390,14 +390,14 @@ class autopostToMastodon
$attachment = $client->create_attachment($thumb_path);
if(is_object($attachment))
{
if (is_object($attachment)) {
$media = $attachment->id;
}
}
$toot = $client->postStatus($message, $mode, $media);
}
}
/**
* Admin_notices
......@@ -405,7 +405,8 @@ class autopostToMastodon
*
* @return void
*/
public function admin_notices() {
public function admin_notices()
{
$notice = unserialize(get_option('autopostToMastodon-notice'));
......@@ -420,7 +421,8 @@ class autopostToMastodon
*
* @return void
*/
public function add_metabox() {
public function add_metabox()
{
add_meta_box(
'autopostToMastodon_metabox',
'Mastodon Autopost',
......@@ -437,7 +439,8 @@ class autopostToMastodon
* @param WP_Post $post the current post.
* @return void
*/
public function metabox( $post ) {
public function metabox($post)
{
if ($post->post_title == '' && $post->post_content == '') {
$status = ('on' == (string) get_option('autopostToMastodon-postOnStandard', true));
} else {
......@@ -451,25 +454,23 @@ class autopostToMastodon
}
public function get_toot_preview_ajax_handler() {
public function get_toot_preview_ajax_handler()
{
check_ajax_referer('mastodonNonce');
$return = array(
'message' => $this->getTootFromTemplate($_POST['post_ID'])
'message' => $this->getTootFromTemplate($_POST['post_ID']),
);
wp_send_json($return);
}
private function getTootFromTemplate($id){
private function getTootFromTemplate($id)
{
$post = get_post($id);
$toot_size = (int) get_option('autopostToMastodon-toot-size', 500);
$message_template = get_option('autopostToMastodon-message', "[title]\n[excerpt]\n[permalink]\n[tags]");
//Replace title
......@@ -481,33 +482,40 @@ class autopostToMastodon
$message_template = str_replace("[permalink]", $post_permalink, $message_template);
//Replace tags
$post_tags = html_entity_decode(get_the_tags($post->ID ), ENT_COMPAT, 'UTF-8');
$post_tags = get_the_tags($id);
if (sizeof($post_tags) > 0) {
$post_tags_content = '';
if ($post_tags) {
foreach ($post_tags as $tag) {
$post_tags_content = $post_tags_content . '#'. preg_replace('/\s+/', '',$tag->name). ' ' ;
$post_tags_content = $post_tags_content . '#' . preg_replace('/\s+/', '', html_entity_decode($tag->name, ENT_COMPAT, 'UTF-8')) . ' ';
}
$post_tags_content = trim($post_tags_content);
}
$message_template = str_replace("[tags]", $post_tags_content, $message_template);
}
//Replace excerpt
$post_content_long = wp_trim_words($post->post_content);
$post_content_long = $post->post_content;
if ($wp_version[0] == "5"){
$post_content_long = excerpt_remove_blocks($post_content_long);
}
$post_content_long = wp_strip_all_tags($post_content_long);
$post_content_long = strip_shortcodes($post_content_long);
$post_content_long = html_entity_decode($post_content_long, ENT_COMPAT, 'UTF-8');
$post_content_long = str_replace("...", "",$post_content_long);
//$post_content_long = str_replace("...", "",$post_content_long);
$excerpt_len = $toot_size - strlen($message_template) + 9 - 5;
$post_excerpt = substr($post_content_long,0,$excerpt_len) ."[...]";
$post_excerpt = substr($post_content_long, 0, $excerpt_len);
$message_template = str_replace("[excerpt]", $post_excerpt, $message_template);
return substr($message_template, 0, $toot_size);
}
private function sendTestToot(){
private function sendTestToot()
{
$instance = get_option('autopostToMastodon-instance');
$access_token = get_option('autopostToMastodon-token');
$mode = 'public';
......
......@@ -2,10 +2,10 @@
Contributors: l1am0, Hellexis
Tags: mastodon, Mastodon, Mastdon Autopost, federated web, GNU social, statusnet, social web, social media, auto post
Requires at least: 4.6
Tested up to: 4.9.4
Stable tag: 3.2.2
Tested up to: 5.0
Stable tag: 3.2.6
License: GPLv2
Donate link: https://liberapay.com/Mastodon-Auto-Share-Team/donate
Donate link: https://patreon.com/simonfrey
License URI: http://www.gnu.org/licenses/gpl-2.0.html
A Wordpress Plugin that automatically posts your new articles to Mastodon. The best: It is set and forget!
......@@ -26,7 +26,7 @@ For any questions, do not hesitate to contact me:
Do you want to help translating this plugin in your language? [Visit the translation page](https://translate.wordpress.org/projects/wp-plugins/autopost-to-mastodon)
Please consider donating via [Liberapay](https://liberapay.com/Mastodon-Auto-Share-Team/donate) <3
Please consider donating via [Patreon](https://patreon.com/simonfrey), [PayPal](https://paypal.me/51edpo) or [Liberapay](https://liberapay.com/Mastodon-Auto-Share-Team/donate) <3
== Frequently Asked Questions ==
......@@ -46,6 +46,22 @@ The plugin never transmits any data to me, or anyone else than the mastodon node
== Changelog ==
= 3.2.6 =
* Change permission for settings page to manage_options
= 3.2.5 =
* 5.0 Fix: Post only the tags of the post
= 3.2.4 =
* Add version check to prevent call to undefined 5.0 function
= 3.2.3 =
* fixup for tags
* remove hardcoded `[...]` from post excerpt
* different excerpt function
* Works with 5.0 and Gutenberg Editor
* Create future toot the moment it gets tooted (not upfront)
= 3.2.2 =
* revert change
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment