Commit a6723929 authored by agata's avatar agata

[auto] plugin: autopost-to-mastodon 3.6

parent 3571c7cc
......@@ -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://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>
<a href="https://paypal.me/51edpo" target="_blank"><img src="<?php echo plugins_url( 'img/paypal.png', __FILE__ );?>" style="height:30px;"></a>
<br>
<br>
<?php if(ACCOUNT_CONNECTED): ?>
......@@ -117,6 +117,15 @@ define("ADVANCED_VIEW",false);
</td>
</tr>
<tr style="display:<?php echo ACCOUNT_CONNECTED ? "block" : "none"?>">
<th scope="row">
<label for="cats_as_tags"><?php esc_html_e( 'Use categories as tags', 'autopost-to-mastodon' ); ?></label>
</th>
<td>
<input type="checkbox" id="cats_as_tags" name="cats_as_tags" value="on" <?php echo ( $cats_as_tags == 'on')?'checked':''; ?>>
</td>
</tr>
<tr style="display:<?php echo ACCOUNT_CONNECTED ? "block" : "none"?>">
<th scope="row">
<label for="autopost_standard"><?php esc_html_e( 'Autopost new posts', 'autopost-to-mastodon' ); ?></label>
......@@ -124,7 +133,30 @@ define("ADVANCED_VIEW",false);
<td>
<input type="checkbox" id="autopost_standard" name="autopost_standard" value="on" <?php echo ( $autopost == 'on')?'checked':''; ?>>
</td>
</tr>
</tr>
<tr style="display:<?php echo ACCOUNT_CONNECTED ? "block" : "none"?>">
<th scope="row">
<label for="post_types"><?php esc_html_e( 'Choose active post types', 'autopost-to-mastodon' ); ?></label>
</th>
<td>
<fieldset id="post_types">
<?php
// get all post types
$args = array(
'public' => true,
// '_builtin' => false,
);
$output = 'objects';
$operator = 'and';
$wp_post_types = get_post_types( $args, $output, $operator );
foreach ( $wp_post_types as $post_type ) {
$checked = ($post_types[$post_type->name] == 'on')?'checked':'';
echo "<label for=\"" . $post_type->name . "\"><input type=\"checkbox\" id=\"" . $post_type->name . "\" name=\"" . $post_type->name . "\"" . $checked . " />" . $post_type->label . "</label></br>";
}
?>
</fieldset>
</td>
</tr>
</tbody>
</table>
......
......@@ -107,4 +107,8 @@ msgid "characters"
msgstr "Zeichen"
msgid "View Toot"
msgstr "Zum Toot"
\ No newline at end of file
msgstr "Zum Toot"
msgid "Choose active post types"
msgstr "Aktiviere für folgende Post-Types"
......@@ -3,9 +3,9 @@
* 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.4
* Version: 3.6
* Author: L1am0
* Author URI: http://www.simon-frey.eu
* Author URI: https://www.simon-frey.eu
* License: GPL2
* Text Domain: autopost-to-mastodon
* Domain Path: /languages
......@@ -208,6 +208,30 @@ class autopostToMastodon
update_option('autopostToMastodon-postOnStandard', 'off');
}
if (isset($_POST['cats_as_tags'])) {
update_option('autopostToMastodon-catsAsTags', 'on');
} else {
update_option('autopostToMastodon-catsAsTags', 'off');
}
// get all post types
$args = array(
'public' => true,
);
$output = 'names';
$operator = 'and';
$post_types = get_post_types( $args, $output, $operator );
// check post for content type configs
foreach ( $post_types as $post_type ) {
if (isset($_POST[$post_type]) ? $_POST[$post_type] : "off" == "on") {
update_option("autopostToMastodon-post_types-$post_type", 'on');
}
else {
update_option("autopostToMastodon-post_types-$post_type", 'off');
}
}
update_option('autopostToMastodon-content-warning', sanitize_textarea_field($content_warning));
$account = $client->verify_credentials($token);
......@@ -248,6 +272,21 @@ class autopostToMastodon
$toot_size = get_option('autopostToMastodon-toot-size', 500);
$content_warning = get_option('autopostToMastodon-content-warning', '');
$autopost = get_option('autopostToMastodon-postOnStandard', 'on');
$cats_as_tags = get_option('autopostToMastodon-catsAsTags', 'on');
$post_types = [];
// get all post types
$args = array(
'public' => true,
);
$output = 'names';
$operator = 'and';
$wp_post_types = get_post_types( $args, $output, $operator );
// add form context data for post type options
foreach ( $wp_post_types as $post_type ) {
$post_types[$post_type] = get_option("autopostToMastodon-post_types-$post_type", 'on');
}
include 'form.tpl.php';
}
......@@ -413,14 +452,33 @@ class autopostToMastodon
*/
public function add_metabox()
{
add_meta_box(
'autopostToMastodon_metabox',
'Mastodon Autopost',
array($this, 'metabox'),
['post', 'page'],
'side',
'high'
$active_post_types = [];
// get all post types
$args = array(
'public' => true,
);
$output = 'names';
$operator = 'and';
$post_types = get_post_types( $args, $output, $operator );
// add form context data for post type options
foreach ( $post_types as $post_type ) {
if (get_option("autopostToMastodon-post_types-$post_type", 'on') == 'on') {
array_push($active_post_types, $post_type);
}
}
// empty array activates everywhere -> check
if (!empty($active_post_types)) {
add_meta_box(
'autopostToMastodon_metabox',
'Mastodon Autopost',
array($this, 'metabox'),
$active_post_types,
'side',
'high'
);
}
}
/**
......@@ -472,18 +530,27 @@ class autopostToMastodon
$message_template = str_replace("[permalink]", $post_permalink, $message_template);
//Replace tags
$post_tags = get_the_tags($id);
$post_tags_content = '';
$cats_as_tags = get_option('autopostToMastodon-catsAsTags', 'off');
if ($cats_as_tags == 'on') {
$post_cats = get_the_category($id);
if (sizeof($post_cats) > 0 && $post_cats) {
foreach ($post_cats as $cat) {
$post_tags_content = $post_tags_content . '#' . preg_replace('/\s+/', '', html_entity_decode($cat->name, 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+/', '', 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);
}
$message_template = str_replace("[tags]", $post_tags_content, $message_template);
//Replace excerpt
//Replace with the excerpt of the post
......
......@@ -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: 5.2.1
Stable tag: 3.4
Tested up to: 5.3.2
Stable tag: 3.6
License: GPLv2
Donate link: https://patreon.com/simonfrey
Donate link: https://paypal.me/51edpo
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 [Patreon](https://patreon.com/simonfrey), [PayPal](https://paypal.me/51edpo) or [Liberapay](https://liberapay.com/Mastodon-Auto-Share-Team/donate) <3
Please consider donating via [PayPal](https://paypal.me/51edpo) <3
== Frequently Asked Questions ==
......@@ -46,6 +46,12 @@ The plugin never transmits any data to me, or anyone else than the mastodon node
== Changelog ==
= 3.6 =
* Allow the plugin to work on custom post types (Thanks to [unicode-it](https://github.com/unicode-it))
= 3.5 =
* Use categorys as hashtags on posts (Thanks to [rseabra](https://github.com/rseabra))
= 3.4 =
* Fix for the manual added excerpt to also get encoded and remove html tags
......
......@@ -10,4 +10,15 @@ delete_option( 'autopostToMastodon-instance' );
delete_option( 'autopostToMastodon-message' );
delete_option( 'autopostToMastodon-mode' );
delete_option( 'autopostToMastodon-toot-size' );
delete_option( 'autopostToMastodon-notice' );
\ No newline at end of file
delete_option( 'autopostToMastodon-notice' );
// get all post types
$args = array(
'public' => true,
);
$output = 'names';
$operator = 'and';
$post_types = get_post_types( $args, $output, $operator );
// delete configs for all post_types
foreach ( $post_types as $post_type ) {
delete_option("autopostToMastodon-post_types-$post_type" );
}
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