diff --git a/includes/class-mention.php b/includes/class-mention.php index 5bf88c1..c5752bb 100644 --- a/includes/class-mention.php +++ b/includes/class-mention.php @@ -48,8 +48,15 @@ class Mention { return $result[0]; } - public static function extract_mentions( $mentions, \ActivityPub\Model\Post $post ) { - \preg_match_all( '/@' . ACTIVITYPUB_USERNAME_REGEXP . '/i', $post->get_content(), $matches ); + /** + * Extract the mentions from the post_content. + * + * @param array $mentions The already found mentions. + * @param string $post_content The post content. + * @return mixed The discovered mentions. + */ + public static function extract_mentions( $mentions, $post_content ) { + \preg_match_all( '/@' . ACTIVITYPUB_USERNAME_REGEXP . '/i', $post_content, $matches ); foreach ( $matches[0] as $match ) { $link = \Activitypub\Rest\Webfinger::resolve( $match ); if ( ! is_wp_error( $link ) ) { diff --git a/includes/model/class-post.php b/includes/model/class-post.php index 5496500..543a890 100644 --- a/includes/model/class-post.php +++ b/includes/model/class-post.php @@ -278,7 +278,7 @@ class Post { } } - $mentions = apply_filters( 'activitypub_extract_mentions', array(), $this ); + $mentions = apply_filters( 'activitypub_extract_mentions', array(), $this->post->post_content, $this ); if ( $mentions ) { foreach ( $mentions as $mention => $url ) { $tag = array( @@ -456,4 +456,28 @@ class Post { return $content; } + /** + * Adds all tags as hashtags to the post/summary content + * + * @param string $content + * @param WP_Post $post + * + * @return string + */ + public function get_the_mentions() { + $post = $this->post; + $tags = \get_the_tags( $post->ID ); + + if ( ! $tags ) { + return ''; + } + + $hash_tags = array(); + + foreach ( $tags as $tag ) { + $hash_tags[] = \sprintf( '', \get_tag_link( $tag ), $tag->slug ); + } + + return \implode( ' ', $hash_tags ); + } } diff --git a/integration/class-friends-feed-parser-activitypub.php b/integration/class-friends-feed-parser-activitypub.php index 00e17b6..c4f59f2 100644 --- a/integration/class-friends-feed-parser-activitypub.php +++ b/integration/class-friends-feed-parser-activitypub.php @@ -413,7 +413,7 @@ class Friends_Feed_Parser_ActivityPub extends \Friends\Feed_Parser { public function get_possible_mentions() { static $users = null; - if ( is_null( $users ) ) { + if ( is_null( $users ) || true ) { $feeds = \Friends\User_Feed::get_by_parser( 'activitypub' ); $users = array(); foreach ( $feeds as $feed ) { @@ -425,9 +425,16 @@ class Friends_Feed_Parser_ActivityPub extends \Friends\Feed_Parser { return $users; } - public function activitypub_extract_mentions( $mentions, \ActivityPub\Model\Post $post ) { + /** + * Extract the mentions from the post_content. + * + * @param array $mentions The already found mentions. + * @param string $post_content The post content. + * @return mixed The discovered mentions. + */ + public function activitypub_extract_mentions( $mentions, $post_content ) { $users = $this->get_possible_mentions(); - preg_match_all( '/@(?:[a-zA-Z0-9_-]+)/', $post->get_content(), $matches ); + preg_match_all( '/@(?:[a-zA-Z0-9_-]+)/', $post_content, $matches ); foreach ( $matches[0] as $match ) { if ( isset( $users[ $match ] ) ) { $mentions[ $match ] = $users[ $match ];