Merge branch 'master' into signature_verification

This commit is contained in:
Matthias Pfefferle 2023-05-22 14:50:49 +02:00 committed by GitHub
commit 750d071c8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 12 deletions

View file

@ -94,7 +94,7 @@ In order for webfinger to work, it must be mapped to the root directory of the U
Add the following to the .htaccess file in the root directory: Add the following to the .htaccess file in the root directory:
RedirectMatch "^\/\.well-known(.*)$" "\/blog\/\.well-known$1" RedirectMatch "^\/\.well-known/(webfinger|nodeinfo|x-nodeinfo2)(.*)$" "\/blog\/\.well-known$1$2"
Where 'blog' is the path to the subdirectory at which your blog resides. Where 'blog' is the path to the subdirectory at which your blog resides.
@ -115,6 +115,8 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
### Next ### ### Next ###
* Compatibility: add a new conditional, `\Activitypub\is_activitypub_request()`, to allow third-party plugins to detect ActivityPub requests.
* Compatibility: add hooks to allow modifying images returned in ActivityPub requests.
* Compatibility: indicate that the plugin is compatible and has been tested with the latest version of WordPress, 6.2. * Compatibility: indicate that the plugin is compatible and has been tested with the latest version of WordPress, 6.2.
### 0.17.0 ### ### 0.17.0 ###

View file

@ -53,7 +53,7 @@ function init() {
Health_Check::init(); Health_Check::init();
Scheduler::init(); Scheduler::init();
} }
\add_action( 'plugins_loaded', '\Activitypub\init' ); \add_action( 'plugins_loaded', __NAMESPACE__ . '\init' );
/** /**
* Class Autoloader * Class Autoloader
@ -142,11 +142,25 @@ function plugin_settings_link( $actions ) {
/** /**
* Only load code that needs BuddyPress to run once BP is loaded and initialized. * Only load code that needs BuddyPress to run once BP is loaded and initialized.
*/ */
function enable_buddypress_features() { add_action(
'bp_include',
function() {
require_once \dirname( __FILE__ ) . '/integration/class-buddypress.php'; require_once \dirname( __FILE__ ) . '/integration/class-buddypress.php';
Integration\Buddypress::init(); Integration\Buddypress::init();
} },
add_action( 'bp_include', '\Activitypub\enable_buddypress_features' ); 0
);
add_action(
'plugins_loaded',
function() {
if ( defined( 'WP_SWEEP_VERSION' ) ) {
require_once \dirname( __FILE__ ) . '/integration/class-wp-sweep.php';
Integration\Wp_Sweep::init();
}
},
0
);
/** /**
* `get_plugin_data` wrapper * `get_plugin_data` wrapper

View file

@ -19,6 +19,7 @@ use function Activitypub\get_remote_metadata_by_actor;
*/ */
class Followers { class Followers {
const TAXONOMY = 'activitypub-followers'; const TAXONOMY = 'activitypub-followers';
const CACHE_KEY_INBOXES = 'follower_inboxes_%s';
/** /**
* Register WordPress hooks/actions and register Taxonomy * Register WordPress hooks/actions and register Taxonomy
@ -225,6 +226,7 @@ class Followers {
if ( is_wp_error( $result ) ) { if ( is_wp_error( $result ) ) {
return $result; return $result;
} else { } else {
wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' );
return $follower; return $follower;
} }
} }
@ -238,6 +240,7 @@ class Followers {
* @return bool|WP_Error True on success, false or WP_Error on failure. * @return bool|WP_Error True on success, false or WP_Error on failure.
*/ */
public static function remove_follower( $user_id, $actor ) { public static function remove_follower( $user_id, $actor ) {
wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' );
return wp_remove_object_terms( $user_id, $actor, self::TAXONOMY ); return wp_remove_object_terms( $user_id, $actor, self::TAXONOMY );
} }
@ -338,6 +341,25 @@ class Followers {
return $items; return $items;
} }
/**
* Get all Followers
*
* @param array $args The WP_Term_Query arguments.
*
* @return array The Term list of Followers.
*/
public static function get_all_followers( $args = array() ) {
$defaults = array(
'taxonomy' => self::TAXONOMY,
'hide_empty' => false,
);
$args = wp_parse_args( $args, $defaults );
$terms = new WP_Term_Query( $args );
return $terms->get_terms();
}
/** /**
* Count the total number of followers * Count the total number of followers
* *
@ -357,6 +379,13 @@ class Followers {
* @return array The list of Inboxes * @return array The list of Inboxes
*/ */
public static function get_inboxes( $user_id ) { public static function get_inboxes( $user_id ) {
$cache_key = sprintf( self::CACHE_KEY_INBOXES, $user_id );
$inboxes = wp_cache_get( $cache_key, 'activitypub' );
if ( $inboxes ) {
return $inboxes;
}
// get all Followers of a ID of the WordPress User // get all Followers of a ID of the WordPress User
$terms = new WP_Term_Query( $terms = new WP_Term_Query(
array( array(
@ -390,7 +419,10 @@ class Followers {
) )
); );
return array_filter( $results ); $inboxes = array_filter( $results );
wp_cache_set( $cache_key, $inboxes, 'activitypub' );
return $inboxes;
} }
/** /**

View file

@ -3,7 +3,7 @@ namespace Activitypub\Integration;
class Buddypress { class Buddypress {
public static function init() { public static function init() {
\add_filter( 'activitypub_json_author_array', array( 'Activitypub\Integration\Buddypress', 'add_user_metadata' ), 11, 2 ); \add_filter( 'activitypub_json_author_array', array( self::class, 'add_user_metadata' ), 11, 2 );
} }
public static function add_user_metadata( $object, $author_id ) { public static function add_user_metadata( $object, $author_id ) {

View file

@ -0,0 +1,50 @@
<?php
namespace Activitypub\Integration;
use Activitypub\Collection\Followers;
/**
* Manages the compatibility with WP Sweep.
*
* @link https://wordpress.org/plugins/wp-sweep/
* @link https://github.com/polylang/polylang/tree/master/integrations/wp-sweep
*/
class Wp_Sweep {
/**
* Setups actions.
*
* @return void
*/
public static function init() {
add_filter( 'wp_sweep_excluded_taxonomies', array( self::class, 'excluded_taxonomies' ) );
add_filter( 'wp_sweep_excluded_termids', array( self::class, 'excluded_termids' ), 0 );
}
/**
* Add 'activitypub-followers' to excluded taxonomies otherwise terms loose their language
* and translation group.
*
* @param array $excluded_taxonomies List of taxonomies excluded from sweeping.
*
* @return array The list of taxonomies excluded from sweeping.
*/
public static function excluded_taxonomies( $excluded_taxonomies ) {
return array_merge( $excluded_taxonomies, array( Followers::TAXONOMY ) );
}
/**
* Add the translation of the default taxonomy terms and our language terms to the excluded terms.
*
* @param array $excluded_term_ids List of term ids excluded from sweeping.
*
* @return array The list of term ids excluded from sweeping.
*/
public static function excluded_termids( $excluded_term_ids ) {
// We got a list of excluded terms (defaults and parents). Let exclude their translations too.
$followers = Followers::get_all_followers( array( 'fields' => 'ids' ) );
$excluded_term_ids = array_merge( $excluded_term_ids, $followers );
return array_unique( $excluded_term_ids );
}
}

View file

@ -94,7 +94,7 @@ In order for webfinger to work, it must be mapped to the root directory of the U
Add the following to the .htaccess file in the root directory: Add the following to the .htaccess file in the root directory:
RedirectMatch "^\/\.well-known(.*)$" "\/blog\/\.well-known$1" RedirectMatch "^\/\.well-known/(webfinger|nodeinfo|x-nodeinfo2)(.*)$" "\/blog\/\.well-known$1$2"
Where 'blog' is the path to the subdirectory at which your blog resides. Where 'blog' is the path to the subdirectory at which your blog resides.

View file

@ -120,8 +120,8 @@
<?php // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited ?> <?php // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited ?>
<?php foreach ( $post_types as $post_type ) { ?> <?php foreach ( $post_types as $post_type ) { ?>
<li> <li>
<input type="checkbox" id="activitypub_support_post_types" name="activitypub_support_post_types[]" value="<?php echo \esc_attr( $post_type->name ); ?>" <?php echo \checked( true, \in_array( $post_type->name, $support_post_types, true ) ); ?> /> <input type="checkbox" id="activitypub_support_post_type_<?php echo \esc_attr( $post_type->name ); ?>" name="activitypub_support_post_types[]" value="<?php echo \esc_attr( $post_type->name ); ?>" <?php echo \checked( \in_array( $post_type->name, $support_post_types, true ) ); ?> />
<label for="<?php echo \esc_attr( $post_type->name ); ?>"><?php echo \esc_html( $post_type->label ); ?></label> <label for="activitypub_support_post_type_<?php echo \esc_attr( $post_type->name ); ?>"><?php echo \esc_html( $post_type->label ); ?></label>
</li> </li>
<?php } ?> <?php } ?>
</ul> </ul>