@@ -45,44 +45,6 @@ public function change_wp_user_id( $user_id ) {
45
45
$ this ->wp_object ->user_id = $ user_id ;
46
46
}
47
47
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
-
86
48
/**
87
49
* Returns the User-URL of the Author of the Post.
88
50
*
@@ -107,8 +69,18 @@ protected function get_attributed_to() {
107
69
* @return string The content.
108
70
*/
109
71
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 ;
112
84
113
85
/**
114
86
* Filter the content of the comment.
@@ -258,11 +230,11 @@ function ( $comment_id ) {
258
230
* Collect all other Users that participated in this comment-thread
259
231
* to send them a notification about the new reply.
260
232
*
261
- * @param array $mentions The already mentioned ActivityPub users.
233
+ * @param array $mentions Optional. The already mentioned ActivityPub users. Default empty array .
262
234
*
263
235
* @return array The list of all Repliers.
264
236
*/
265
- public function extract_reply_context ( $ mentions ) {
237
+ public function extract_reply_context ( $ mentions = array () ) {
266
238
// Check if `$this->wp_object` is a WP_Comment.
267
239
if ( 'WP_Comment ' !== get_class ( $ this ->wp_object ) ) {
268
240
return $ mentions ;
@@ -364,4 +336,15 @@ public function get_to() {
364
336
get_rest_url_by_path ( $ path ),
365
337
);
366
338
}
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
+ }
367
350
}
0 commit comments