@@ -45,44 +45,6 @@ public function change_wp_user_id( $user_id ) {
4545 $ this ->wp_object ->user_id = $ user_id ;
4646 }
4747
48- /**
49- * Transforms the WP_Comment object to an ActivityPub Object.
50- *
51- * @see \Activitypub\Activity\Base_Object
52- *
53- * @return \Activitypub\Activity\Base_Object The ActivityPub Object.
54- */
55- public function to_object () {
56- $ object = parent ::to_object ();
57-
58- $ content = $ this ->get_content ();
59- $ at_replies = '' ;
60- $ reply_context = $ this ->extract_reply_context ( array () );
61-
62- foreach ( $ reply_context as $ acct => $ url ) {
63- $ at_replies .= sprintf (
64- '<a class="u-mention mention" href="%s">%s</a> ' ,
65- esc_url ( $ url ),
66- esc_html ( $ acct )
67- );
68- }
69-
70- $ at_replies = trim ( $ at_replies );
71-
72- if ( $ at_replies ) {
73- $ content = sprintf ( '<p>%s</p>%s ' , $ at_replies , $ content );
74- }
75-
76- $ object ->set_content ( $ content );
77- $ object ->set_content_map (
78- array (
79- $ this ->get_locale () => $ content ,
80- )
81- );
82-
83- return $ object ;
84- }
85-
8648 /**
8749 * Returns the User-URL of the Author of the Post.
8850 *
@@ -107,8 +69,18 @@ protected function get_attributed_to() {
10769 * @return string The content.
10870 */
10971 protected function get_content () {
110- $ comment = $ this ->wp_object ;
111- $ content = $ comment ->comment_content ;
72+ $ comment = $ this ->wp_object ;
73+ $ content = $ comment ->comment_content ;
74+ $ mentions = '' ;
75+
76+ foreach ( $ this ->extract_reply_context () as $ acct => $ url ) {
77+ $ mentions .= sprintf (
78+ '<a rel="mention" class="u-url mention" href="%s">%s</a> ' ,
79+ esc_url ( $ url ),
80+ esc_html ( $ acct )
81+ );
82+ }
83+ $ content = $ mentions . $ content ;
11284
11385 /**
11486 * Filter the content of the comment.
@@ -258,11 +230,11 @@ function ( $comment_id ) {
258230 * Collect all other Users that participated in this comment-thread
259231 * to send them a notification about the new reply.
260232 *
261- * @param array $mentions The already mentioned ActivityPub users.
233+ * @param array $mentions Optional. The already mentioned ActivityPub users. Default empty array .
262234 *
263235 * @return array The list of all Repliers.
264236 */
265- public function extract_reply_context ( $ mentions ) {
237+ public function extract_reply_context ( $ mentions = array () ) {
266238 // Check if `$this->wp_object` is a WP_Comment.
267239 if ( 'WP_Comment ' !== get_class ( $ this ->wp_object ) ) {
268240 return $ mentions ;
@@ -364,4 +336,15 @@ public function get_to() {
364336 get_rest_url_by_path ( $ path ),
365337 );
366338 }
339+
340+ /**
341+ * Returns the content map for the comment.
342+ *
343+ * @return array The content map for the comment.
344+ */
345+ public function get_content_map () {
346+ return array (
347+ $ this ->get_locale () => $ this ->get_content (),
348+ );
349+ }
367350}
0 commit comments