2021-12-20 13:41:52 +00:00
|
|
|
<?php
|
2024-10-09 12:44:17 +00:00
|
|
|
/**
|
|
|
|
* BuddyPress integration class file.
|
|
|
|
*
|
|
|
|
* @package Activitypub
|
|
|
|
*/
|
|
|
|
|
2021-12-20 13:41:52 +00:00
|
|
|
namespace Activitypub\Integration;
|
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
/**
|
2024-10-09 12:44:17 +00:00
|
|
|
* Compatibility with the BuddyPress plugin.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
|
|
|
* @see https://buddypress.org/
|
|
|
|
*/
|
2021-12-20 13:41:52 +00:00
|
|
|
class Buddypress {
|
2023-10-22 22:20:53 +00:00
|
|
|
/**
|
2024-10-09 12:44:17 +00:00
|
|
|
* Initialize the class, registering WordPress hooks.
|
2023-10-22 22:20:53 +00:00
|
|
|
*/
|
2021-12-20 13:41:52 +00:00
|
|
|
public static function init() {
|
2023-10-22 22:20:53 +00:00
|
|
|
\add_filter( 'activitypub_json_author_array', array( self::class, 'add_user_metadata' ), 11, 2 );
|
2021-12-20 13:41:52 +00:00
|
|
|
}
|
|
|
|
|
2024-10-09 12:44:17 +00:00
|
|
|
/**
|
|
|
|
* Add BuddyPress user metadata to the author array.
|
|
|
|
*
|
|
|
|
* @param object $author The author object.
|
|
|
|
* @param int $author_id The author ID.
|
|
|
|
*
|
|
|
|
* @return object The author object.
|
|
|
|
*/
|
|
|
|
public static function add_user_metadata( $author, $author_id ) {
|
|
|
|
$author->url = bp_core_get_user_domain( $author_id ); // Add BP member profile URL as user URL.
|
2021-12-20 13:41:52 +00:00
|
|
|
|
2024-10-09 12:44:17 +00:00
|
|
|
// Add BuddyPress' cover_image instead of WordPress' header_image.
|
2021-12-20 13:41:52 +00:00
|
|
|
$cover_image_url = bp_attachments_get_attachment( 'url', array( 'item_id' => $author_id ) );
|
|
|
|
|
|
|
|
if ( $cover_image_url ) {
|
2024-10-09 12:44:17 +00:00
|
|
|
$author->image = array(
|
2021-12-20 13:41:52 +00:00
|
|
|
'type' => 'Image',
|
|
|
|
'url' => $cover_image_url,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-10-09 12:44:17 +00:00
|
|
|
// Change profile URL to BuddyPress' profile URL.
|
|
|
|
$author->attachment['profile_url'] = array(
|
|
|
|
'type' => 'PropertyValue',
|
|
|
|
'name' => \__( 'Profile', 'activitypub' ),
|
2021-12-20 13:41:52 +00:00
|
|
|
'value' => \html_entity_decode(
|
2024-07-19 19:46:05 +00:00
|
|
|
sprintf(
|
|
|
|
'<a rel="me" title="%s" target="_blank" href="%s">%s</a>',
|
|
|
|
\esc_attr( bp_core_get_user_domain( $author_id ) ),
|
|
|
|
\bp_core_get_user_domain( $author_id ),
|
|
|
|
\wp_parse_url( \bp_core_get_user_domain( $author_id ), \PHP_URL_HOST )
|
|
|
|
),
|
2021-12-20 13:41:52 +00:00
|
|
|
\ENT_QUOTES,
|
|
|
|
'UTF-8'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2024-10-09 12:44:17 +00:00
|
|
|
// Replace blog URL on multisite.
|
2021-12-20 13:41:52 +00:00
|
|
|
if ( is_multisite() ) {
|
2024-10-09 12:44:17 +00:00
|
|
|
$user_blogs = get_blogs_of_user( $author_id ); // Get sites of user to send as AP metadata.
|
2021-12-20 13:41:52 +00:00
|
|
|
|
|
|
|
if ( ! empty( $user_blogs ) ) {
|
2024-10-09 12:44:17 +00:00
|
|
|
unset( $author->attachment['blog_url'] );
|
2021-12-20 13:41:52 +00:00
|
|
|
|
|
|
|
foreach ( $user_blogs as $blog ) {
|
|
|
|
if ( 1 !== $blog->userblog_id ) {
|
2024-10-09 12:44:17 +00:00
|
|
|
$author->attachment[] = array(
|
|
|
|
'type' => 'PropertyValue',
|
|
|
|
'name' => $blog->blogname,
|
2021-12-20 13:41:52 +00:00
|
|
|
'value' => \html_entity_decode(
|
2024-07-19 19:46:05 +00:00
|
|
|
sprintf(
|
|
|
|
'<a rel="me" title="%s" target="_blank" href="%s">%s</a>',
|
|
|
|
\esc_attr( $blog->siteurl ),
|
|
|
|
$blog->siteurl,
|
|
|
|
\wp_parse_url( $blog->siteurl, \PHP_URL_HOST )
|
|
|
|
),
|
2021-12-20 13:41:52 +00:00
|
|
|
\ENT_QUOTES,
|
|
|
|
'UTF-8'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-09 12:44:17 +00:00
|
|
|
return $author;
|
2021-12-20 13:41:52 +00:00
|
|
|
}
|
|
|
|
}
|