diff --git a/README.md b/README.md index cbf10ee..4bb7bd5 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,10 @@ To implement: Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). +### 0.5.2 ### + +* add tags as hashtags to the end of each activity + ### 0.5.1 ### * fixed name-collision that cases an invenate loop diff --git a/activitypub.php b/activitypub.php index 951049f..0ed1197 100644 --- a/activitypub.php +++ b/activitypub.php @@ -19,7 +19,7 @@ namespace Activitypub; * Initialize plugin */ function init() { - defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(^|\s|>)#([^\s<>]+)\b' ); + defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(^|\s|\/>)#([^\s<>]+)\b' ); require_once dirname( __FILE__ ) . '/includes/class-signature.php'; require_once dirname( __FILE__ ) . '/includes/class-activity.php'; @@ -51,10 +51,8 @@ function init() { require_once dirname( __FILE__ ) . '/includes/class-admin.php'; \Activitypub\Admin::init(); - if ( '1' === get_option( 'activitypub_use_hashtags', '1' ) ) { - require_once dirname( __FILE__ ) . '/includes/class-hashtag.php'; - \Activitypub\Hashtag::init(); - } + require_once dirname( __FILE__ ) . '/includes/class-hashtag.php'; + \Activitypub\Hashtag::init(); } add_action( 'plugins_loaded', '\Activitypub\init' ); diff --git a/includes/class-admin.php b/includes/class-admin.php index 525c7d8..e54d943 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -76,7 +76,14 @@ class Admin { register_setting( 'activitypub', 'activitypub_use_hashtags', array( 'type' => 'boolean', - 'description' => __( 'Use the Shortlink instead of the permalink', 'activitypub' ), + 'description' => __( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ), + 'default' => 0, + ) + ); + register_setting( + 'activitypub', 'activitypub_add_tags_as_hashtags', array( + 'type' => 'boolean', + 'description' => __( 'Add all tags as hashtags at the end of each activity', 'activitypub' ), 'default' => 0, ) ); diff --git a/includes/class-hashtag.php b/includes/class-hashtag.php index dc7db0d..1546ffe 100644 --- a/includes/class-hashtag.php +++ b/includes/class-hashtag.php @@ -11,8 +11,14 @@ class Hashtag { * Initialize the class, registering WordPress hooks */ public static function init() { - add_filter( 'wp_insert_post', array( '\Activitypub\Hashtag', 'insert_post' ), 99, 2 ); - add_filter( 'the_content', array( '\Activitypub\Hashtag', 'the_content' ), 99, 2 ); + if ( '1' === get_option( 'activitypub_use_hashtags', '1' ) ) { + add_filter( 'wp_insert_post', array( '\Activitypub\Hashtag', 'insert_post' ), 99, 2 ); + add_filter( 'the_content', array( '\Activitypub\Hashtag', 'the_content' ), 99, 2 ); + } + if ( '1' === get_option( 'activitypub_add_tags_as_hashtags', '1' ) ) { + add_filter( 'activitypub_the_summary', array( '\Activitypub\Hashtag', 'add_hashtags_to_content' ), 10, 2 ); + add_filter( 'activitypub_the_content', array( '\Activitypub\Hashtag', 'add_hashtags_to_content' ), 10, 2 ); + } } /** @@ -60,4 +66,28 @@ class Hashtag { return $space . '#' . $tag; } + + /** + * Adds all tags as hashtags to the post/summary content + * + * @param string $content + * @param WP_Post $post + * + * @return string + */ + public static function add_hashtags_to_content( $content, $post ) { + $tags = get_the_tags( $post->ID ); + + if ( ! $tags ) { + return $content; + } + + $hash_tags = array(); + + foreach ( $tags as $tag ) { + $hash_tags[] = sprintf( '', get_tag_link( $tag ), $tag->slug ); + } + + return $content . '

' . implode( ' ', $hash_tags ) . '

'; + } } diff --git a/includes/class-post.php b/includes/class-post.php index 51f3958..78f8c34 100644 --- a/includes/class-post.php +++ b/includes/class-post.php @@ -13,8 +13,8 @@ class Post { * Initialize the class, registering WordPress hooks */ public static function init() { - add_filter( 'activitypub_the_summary', array( '\Activitypub\Post', 'add_backlink' ), 10, 2 ); - add_filter( 'activitypub_the_content', array( '\Activitypub\Post', 'add_backlink' ), 10, 2 ); + add_filter( 'activitypub_the_summary', array( '\Activitypub\Post', 'add_backlink_to_content' ), 15, 2 ); + add_filter( 'activitypub_the_content', array( '\Activitypub\Post', 'add_backlink_to_content' ), 15, 2 ); } public function __construct( $post = null ) { @@ -126,7 +126,7 @@ class Post { $post_tags = get_the_tags( $this->post->ID ); if ( $post_tags ) { - foreach( $post_tags as $post_tag ) { + foreach ( $post_tags as $post_tag ) { $tag = array( 'type' => 'Hashtag', 'href' => get_tag_link( $post_tag->term_id ), @@ -299,7 +299,15 @@ class Post { return trim( preg_replace( '/[\r\n]{2,}/', '', strip_tags( $decoded_summary, $allowed_html ) ) ); } - public static function add_backlink( $content, $post ) { + /** + * Adds a backlink to the post/summary content + * + * @param string $content + * @param WP_Post $post + * + * @return string + */ + public static function add_backlink_to_content( $content, $post ) { $link = ''; if ( get_option( 'activitypub_use_shortlink', 0 ) ) { diff --git a/languages/activitypub.pot b/languages/activitypub.pot index 13ac072..f26d300 100644 --- a/languages/activitypub.pot +++ b/languages/activitypub.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: ActivityPub 0.5.1\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n" -"POT-Creation-Date: 2019-03-02 19:31:03+00:00\n" +"POT-Creation-Date: 2019-03-02 20:10:15+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -21,16 +21,25 @@ msgstr "" msgid "The Activity-Object-Type" msgstr "" -#: includes/class-admin.php:72 includes/class-admin.php:79 -#: templates/settings-page.php:33 +#: includes/class-admin.php:72 templates/settings-page.php:33 msgid "Use the Shortlink instead of the permalink" msgstr "" -#: includes/class-admin.php:89 +#: includes/class-admin.php:79 +msgid "" +"Add hashtags in the content as native tags and replace the #tag with the " +"tag-link" +msgstr "" + +#: includes/class-admin.php:86 +msgid "Add all tags as hashtags at the end of each activity" +msgstr "" + +#: includes/class-admin.php:96 msgid "Overview" msgstr "" -#: includes/class-admin.php:91 +#: includes/class-admin.php:98 msgid "" "ActivityPub is a decentralized social networking protocol based on the " "ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended " @@ -40,29 +49,29 @@ msgid "" "subscribing to content." msgstr "" -#: includes/class-admin.php:96 +#: includes/class-admin.php:103 msgid "For more information:" msgstr "" -#: includes/class-admin.php:97 +#: includes/class-admin.php:104 msgid "Test Suite" msgstr "" -#: includes/class-admin.php:98 +#: includes/class-admin.php:105 msgid "W3C Spec" msgstr "" -#: includes/class-admin.php:99 +#: includes/class-admin.php:106 msgid "" "Give " "us feedback" msgstr "" -#: includes/class-admin.php:101 +#: includes/class-admin.php:108 msgid "Donate" msgstr "" -#: includes/class-admin.php:107 +#: includes/class-admin.php:114 msgid "Fediverse" msgstr "" @@ -125,7 +134,7 @@ msgstr "" msgid "Blog" msgstr "" -#: templates/json-author.php:59 templates/settings-page.php:79 +#: templates/json-author.php:59 templates/settings-page.php:71 msgid "Profile" msgstr "" @@ -206,45 +215,41 @@ msgstr "" msgid "Maps the WordPress Post-Format to the ActivityPub Object Type." msgstr "" -#: templates/settings-page.php:58 -msgid "Hashtag" +#: templates/settings-page.php:55 +msgid "Hashtags" msgstr "" -#: templates/settings-page.php:60 -msgid "All #tag related settings" -msgstr "" - -#: templates/settings-page.php:66 -msgid "Support Hashtags" -msgstr "" - -#: templates/settings-page.php:70 +#: templates/settings-page.php:59 msgid "" "Add hashtags in the content as native tags and replace the " "#tag with the tag-link." msgstr "" -#: templates/settings-page.php:81 +#: templates/settings-page.php:62 +msgid "Add all tags as hashtags to the end of each activity." +msgstr "" + +#: templates/settings-page.php:73 msgid "All profile related settings." msgstr "" -#: templates/settings-page.php:87 +#: templates/settings-page.php:79 msgid "Followers" msgstr "" -#: templates/settings-page.php:89 +#: templates/settings-page.php:81 msgid "All follower related settings." msgstr "" -#: templates/settings-page.php:95 +#: templates/settings-page.php:87 msgid "List of followers" msgstr "" -#: templates/settings-page.php:105 +#: templates/settings-page.php:97 msgid "No followers yet" msgstr "" -#: templates/settings-page.php:120 +#: templates/settings-page.php:112 msgid "" "If you like this plugin, what about a small donation?" diff --git a/readme.txt b/readme.txt index 2a4da56..7e888c4 100644 --- a/readme.txt +++ b/readme.txt @@ -55,6 +55,10 @@ To implement: Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). += 0.5.2 = + +* add tags as hashtags to the end of each activity + = 0.5.1 = * fixed name-collision that cases an invenate loop diff --git a/templates/settings-page.php b/templates/settings-page.php index 577571e..368e389 100644 --- a/templates/settings-page.php +++ b/templates/settings-page.php @@ -50,31 +50,23 @@

- - - - - -

- -

- - -
- +

+

+ +

- +

@@ -97,7 +89,7 @@