diff --git a/README.md b/README.md index dce067a..a189385 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **Donate link:** https://notiz.blog/donate/ **Tags:** OStatus, fediverse, activitypub, activitystream **Requires at least:** 4.7 -**Tested up to:** 5.0.2 +**Tested up to:** 5.0.3 **Stable tag:** 0.2.1 **Requires PHP:** 5.6 **License:** MIT @@ -55,6 +55,10 @@ To implement: Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). +### 0.3.0 ### + +* basic hashtag support + ### 0.2.1 ### * customizable backlink (permalink or shorturl) diff --git a/activitypub.php b/activitypub.php index 2845a26..4841a13 100644 --- a/activitypub.php +++ b/activitypub.php @@ -16,6 +16,8 @@ * Initialize plugin */ function activitypub_init() { + defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(^|\s|>)#([^\s<>]+)\b' ); + require_once dirname( __FILE__ ) . '/includes/class-activitypub-signature.php'; require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php'; require_once dirname( __FILE__ ) . '/includes/class-activitypub-activity.php'; @@ -65,6 +67,10 @@ function activitypub_init() { add_action( 'admin_menu', array( 'Activitypub_Admin', 'admin_menu' ) ); add_action( 'admin_init', array( 'Activitypub_Admin', 'register_settings' ) ); add_action( 'show_user_profile', array( 'Activitypub_Admin', 'add_fediverse_profile' ) ); + + require_once dirname( __FILE__ ) . '/includes/class-activitypub-hashtag.php'; + add_filter( 'wp_insert_post', array( 'Activitypub_Hashtag', 'insert_post' ), 99, 2 ); + add_filter( 'the_content', array( 'Activitypub_Hashtag', 'the_content' ), 99, 2 ); } add_action( 'plugins_loaded', 'activitypub_init' ); diff --git a/includes/class-activitypub-hashtag.php b/includes/class-activitypub-hashtag.php new file mode 100644 index 0000000..efa3c2b --- /dev/null +++ b/includes/class-activitypub-hashtag.php @@ -0,0 +1,51 @@ +post_content, $match ) ) { + $tags = implode( ', ', $match[2] ); + + wp_add_post_tags( $data->post_parent, $tags ); + } + + return $id; + } + + /** + * Filter to replace the #tags in the content with links + * + * @param string $the_content the post-content + */ + public static function the_content( $the_content ) { + $the_content = preg_replace_callback( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', array( 'Activitypub_Hashtag', 'replace_with_links' ), $the_content ); + + return $the_content; + } + + /** + * A callback for preg_replace to build the term links + * + * @param array $result the preg_match results + * @return string the final string + */ + public static function replace_with_links( $result ) { + $tag = $result[2]; + $space = $result[1]; + $tag_object = get_term_by( 'name', $result[2], 'post_tag' ); + + if ( $tag_object ) { + $link = get_term_link( $tag_object, 'post_tag' ); + return "$space"; + } + + return $space . '#' . $tag; + } +} diff --git a/languages/activitypub.pot b/languages/activitypub.pot index 6712783..2602354 100644 --- a/languages/activitypub.pot +++ b/languages/activitypub.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: ActivityPub 0.2.1\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n" -"POT-Creation-Date: 2019-01-16 20:52:51+00:00\n" +"POT-Creation-Date: 2019-01-22 19:51:00+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/readme.txt b/readme.txt index bc842f2..4c8dc87 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: pfefferle Donate link: https://notiz.blog/donate/ Tags: OStatus, fediverse, activitypub, activitystream Requires at least: 4.7 -Tested up to: 5.0.2 +Tested up to: 5.0.3 Stable tag: 0.2.1 Requires PHP: 5.6 License: MIT @@ -55,6 +55,10 @@ To implement: Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). += 0.3.0 = + +* basic hashtag support + = 0.2.1 = * customizable backlink (permalink or shorturl)