From a672392934107ebd17b7db6eb3f0c94832ac9960 Mon Sep 17 00:00:00 2001
From: agata <automa@insicuri.net>
Date: Wed, 22 Jan 2020 16:35:50 +0100
Subject: [PATCH] [auto] plugin: autopost-to-mastodon 3.6

---
 .../plugins/autopost-to-mastodon/form.tpl.php |  36 ++++++-
 .../languages/autopost-to-mastodon-de_DE.mo   | Bin 2539 -> 2615 bytes
 .../languages/autopost-to-mastodon-de_DE.po   |   6 +-
 .../mastodon_autopost.php                     |  91 +++++++++++++++---
 .../plugins/autopost-to-mastodon/readme.txt   |  14 ++-
 .../autopost-to-mastodon/uninstall.php        |  13 ++-
 6 files changed, 140 insertions(+), 20 deletions(-)

diff --git a/wp-content/plugins/autopost-to-mastodon/form.tpl.php b/wp-content/plugins/autopost-to-mastodon/form.tpl.php
index e86d566ac..ef5ade019 100644
--- a/wp-content/plugins/autopost-to-mastodon/form.tpl.php
+++ b/wp-content/plugins/autopost-to-mastodon/form.tpl.php
@@ -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>
 
diff --git a/wp-content/plugins/autopost-to-mastodon/languages/autopost-to-mastodon-de_DE.mo b/wp-content/plugins/autopost-to-mastodon/languages/autopost-to-mastodon-de_DE.mo
index a9a5928389fa2e043c2202f4d519b7e81d40bafd..2cd906195a344ec14d07a6a7f54ca454834a5e79 100644
GIT binary patch
delta 929
zcmaDYyj`UJo)F7a1_lNOH3kL-83qOhA4UcSQw9cx8YTt?F$M;P0A>aTSq27%bY=zy
zAqED9R%QkUK?Vkf8O#g}5)2FstC$%Wlo%Ko4l^?_2s1D+JY!~H;9+23_{Ge?AkM(R
zz|O+Jz{bG9AkV_Uzy-301tM?A!oZ-wz);U%$HKtC!N9-}&%(eUz`($e!NR~G&%nS?
z$-=<E&cMJhlLg|qg;4$psDT%t23==?IP3`v0|Ore1H*R~1_luZ1_m}(hy$fr85k@W
z7#K`g85rys7#MO{85pb>7#P;DGB9v5)H5(VXN6e&k(Gf#l7WGNi47#dz#zj0F+hzC
z;y`<-xCa}=K|yQ`49p;hvO#=S3sv921__~sY><%K45cr!K|<<18v}z50|SE)I|GAQ
zJp%)SJv##fF9QQZ7(2wm6n03E)v`lEpoJacfF5>;#;H*8L+lWXPO(Em><&A`;eXf}
z81z6PzyUGGl!JkRn}LDBh6CbJ4-QDwL~<}N)PsV&kOLCeO&kmihM*wlU|=v{U|=}S
z!N6e7z`*c_gMq;o6oi}*pB8a4Fo-fRFw}A~Feo!HFihrzSg@Uwfk7IS7C0eMai0_7
z@OPXH491|S;e>>kHW$QW`dke4;J5-MKoADG5)|hk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i*
Aw*UYD

diff --git a/wp-content/plugins/autopost-to-mastodon/languages/autopost-to-mastodon-de_DE.po b/wp-content/plugins/autopost-to-mastodon/languages/autopost-to-mastodon-de_DE.po
index cae4d815a..05da24324 100644
--- a/wp-content/plugins/autopost-to-mastodon/languages/autopost-to-mastodon-de_DE.po
+++ b/wp-content/plugins/autopost-to-mastodon/languages/autopost-to-mastodon-de_DE.po
@@ -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"
+
diff --git a/wp-content/plugins/autopost-to-mastodon/mastodon_autopost.php b/wp-content/plugins/autopost-to-mastodon/mastodon_autopost.php
index ab19ae961..2e52bdc59 100644
--- a/wp-content/plugins/autopost-to-mastodon/mastodon_autopost.php
+++ b/wp-content/plugins/autopost-to-mastodon/mastodon_autopost.php
@@ -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
diff --git a/wp-content/plugins/autopost-to-mastodon/readme.txt b/wp-content/plugins/autopost-to-mastodon/readme.txt
index 87c13046c..c81eeb195 100644
--- a/wp-content/plugins/autopost-to-mastodon/readme.txt
+++ b/wp-content/plugins/autopost-to-mastodon/readme.txt
@@ -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
 
diff --git a/wp-content/plugins/autopost-to-mastodon/uninstall.php b/wp-content/plugins/autopost-to-mastodon/uninstall.php
index 3dcd0c2af..2816e500b 100644
--- a/wp-content/plugins/autopost-to-mastodon/uninstall.php
+++ b/wp-content/plugins/autopost-to-mastodon/uninstall.php
@@ -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" );
+}
-- 
GitLab