Suggestion: Adopt WordPress PHP Coding Standards (#905)

* Update phpcs rules

* Automated style updates

* Silence all other Warnings and Errors

We'll fix them in follow ups.
This commit is contained in:
Konstantin Obenland 2024-09-28 12:53:21 -05:00 committed by GitHub
parent f5989f0380
commit 2b5f635ba3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 441 additions and 446 deletions

View file

@ -112,7 +112,7 @@ function plugin_init() {
if ( strncmp( $full_class, $base, strlen( $base ) ) === 0 ) { if ( strncmp( $full_class, $base, strlen( $base ) ) === 0 ) {
$maybe_uppercase = str_replace( $base, '', $full_class ); $maybe_uppercase = str_replace( $base, '', $full_class );
$class = strtolower( $maybe_uppercase ); $class = strtolower( $maybe_uppercase );
// All classes should be capitalized. If this is instead looking for a lowercase method, we ignore that. // All classes should be capitalized. If this is instead looking for a lowercase method, we ignore that.
if ( $maybe_uppercase === $class ) { if ( $maybe_uppercase === $class ) {
return; return;
@ -144,7 +144,7 @@ function plugin_init() {
* Add plugin settings link * Add plugin settings link
*/ */
function plugin_settings_link( $actions ) { function plugin_settings_link( $actions ) {
$settings_link = array(); $settings_link = array();
$settings_link[] = \sprintf( $settings_link[] = \sprintf(
'<a href="%1s">%2s</a>', '<a href="%1s">%2s</a>',
\menu_page_url( 'activitypub', false ), \menu_page_url( 'activitypub', false ),

View file

@ -41,7 +41,7 @@
"vendor/bin/phpunit" "vendor/bin/phpunit"
], ],
"lint": [ "lint": [
"vendor/bin/phpcs -n -q" "vendor/bin/phpcs"
], ],
"lint:fix": [ "lint:fix": [
"vendor/bin/phpcbf" "vendor/bin/phpcbf"

View file

@ -22,28 +22,28 @@ class Actor extends Base_Object {
'https://w3id.org/security/v1', 'https://w3id.org/security/v1',
'https://purl.archive.org/socialweb/webfinger', 'https://purl.archive.org/socialweb/webfinger',
array( array(
'schema' => 'http://schema.org#', 'schema' => 'http://schema.org#',
'toot' => 'http://joinmastodon.org/ns#', 'toot' => 'http://joinmastodon.org/ns#',
'lemmy' => 'https://join-lemmy.org/ns#', 'lemmy' => 'https://join-lemmy.org/ns#',
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
'PropertyValue' => 'schema:PropertyValue', 'PropertyValue' => 'schema:PropertyValue',
'value' => 'schema:value', 'value' => 'schema:value',
'Hashtag' => 'as:Hashtag', 'Hashtag' => 'as:Hashtag',
'featured' => array( 'featured' => array(
'@id' => 'toot:featured', '@id' => 'toot:featured',
'@type' => '@id', '@type' => '@id',
), ),
'featuredTags' => array( 'featuredTags' => array(
'@id' => 'toot:featuredTags', '@id' => 'toot:featuredTags',
'@type' => '@id', '@type' => '@id',
), ),
'moderators' => array( 'moderators' => array(
'@id' => 'lemmy:moderators', '@id' => 'lemmy:moderators',
'@type' => '@id', '@type' => '@id',
), ),
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods', 'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods',
'discoverable' => 'toot:discoverable', 'discoverable' => 'toot:discoverable',
'indexable' => 'toot:indexable', 'indexable' => 'toot:indexable',
), ),
); );

View file

@ -51,6 +51,7 @@ class Event extends Base_Object {
/** /**
* Mobilizon compatible values for repliesModertaionOption. * Mobilizon compatible values for repliesModertaionOption.
*
* @var array * @var array
*/ */
const REPLIES_MODERATION_OPTION_TYPES = array( 'allow_all', 'closed' ); const REPLIES_MODERATION_OPTION_TYPES = array( 'allow_all', 'closed' );
@ -62,6 +63,7 @@ class Event extends Base_Object {
/** /**
* Allowed values for ical VEVENT STATUS. * Allowed values for ical VEVENT STATUS.
*
* @var array * @var array
*/ */
const ICAL_EVENT_STATUS_TYPES = array( 'TENTATIVE', 'CONFIRMED', 'CANCELLED' ); const ICAL_EVENT_STATUS_TYPES = array( 'TENTATIVE', 'CONFIRMED', 'CANCELLED' );
@ -70,6 +72,7 @@ class Event extends Base_Object {
* Default event categories. * Default event categories.
* *
* These values currently reflect the default set as proposed by Mobilizon to maximize interoperability. * These values currently reflect the default set as proposed by Mobilizon to maximize interoperability.
*
* @var array * @var array
*/ */
const DEFAULT_EVENT_CATEGORIES = array( const DEFAULT_EVENT_CATEGORIES = array(
@ -253,7 +256,7 @@ class Event extends Base_Object {
public function set_replies_moderation_option( $type ) { public function set_replies_moderation_option( $type ) {
if ( in_array( $type, self::REPLIES_MODERATION_OPTION_TYPES, true ) ) { if ( in_array( $type, self::REPLIES_MODERATION_OPTION_TYPES, true ) ) {
$this->replies_moderation_option = $type; $this->replies_moderation_option = $type;
$this->comments_enabled = ( 'allow_all' === $type ) ? true : false; $this->comments_enabled = ( 'allow_all' === $type ) ? true : false;
} else { } else {
_doing_it_wrong( _doing_it_wrong(
__METHOD__, __METHOD__,
@ -272,7 +275,7 @@ class Event extends Base_Object {
*/ */
public function set_comments_enabled( $comments_enabled ) { public function set_comments_enabled( $comments_enabled ) {
if ( is_bool( $comments_enabled ) ) { if ( is_bool( $comments_enabled ) ) {
$this->comments_enabled = $comments_enabled; $this->comments_enabled = $comments_enabled;
$this->replies_moderation_option = $comments_enabled ? 'allow_all' : 'closed'; $this->replies_moderation_option = $comments_enabled ? 'allow_all' : 'closed';
} else { } else {
_doing_it_wrong( _doing_it_wrong(
@ -332,7 +335,7 @@ class Event extends Base_Object {
public function set_external_participation_url( $url ) { public function set_external_participation_url( $url ) {
if ( preg_match( '/^https?:\/\/.*/i', $url ) ) { if ( preg_match( '/^https?:\/\/.*/i', $url ) ) {
$this->external_participation_url = $url; $this->external_participation_url = $url;
$this->join_mode = 'external'; $this->join_mode = 'external';
} }
return $this; return $this;

View file

@ -508,7 +508,7 @@ class Activitypub {
// Both User and Blog Extra Fields types have the same args. // Both User and Blog Extra Fields types have the same args.
$args = array( $args = array(
'labels' => array( 'labels' => array(
'name' => _x( 'Extra fields', 'post_type plural name', 'activitypub' ), 'name' => _x( 'Extra fields', 'post_type plural name', 'activitypub' ),
'singular_name' => _x( 'Extra field', 'post_type single name', 'activitypub' ), 'singular_name' => _x( 'Extra field', 'post_type single name', 'activitypub' ),
'add_new' => __( 'Add new', 'activitypub' ), 'add_new' => __( 'Add new', 'activitypub' ),

View file

@ -193,8 +193,8 @@ class Admin {
'activitypub', 'activitypub',
'activitypub_post_content_type', 'activitypub_post_content_type',
array( array(
'type' => 'string', 'type' => 'string',
'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ), 'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ),
'show_in_rest' => array( 'show_in_rest' => array(
'schema' => array( 'schema' => array(
'enum' => array( 'enum' => array(
@ -204,34 +204,34 @@ class Admin {
), ),
), ),
), ),
'default' => 'content', 'default' => 'content',
) )
); );
\register_setting( \register_setting(
'activitypub', 'activitypub',
'activitypub_custom_post_content', 'activitypub_custom_post_content',
array( array(
'type' => 'string', 'type' => 'string',
'description' => \__( 'Define your own custom post template', 'activitypub' ), 'description' => \__( 'Define your own custom post template', 'activitypub' ),
'show_in_rest' => true, 'show_in_rest' => true,
'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT, 'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT,
) )
); );
\register_setting( \register_setting(
'activitypub', 'activitypub',
'activitypub_max_image_attachments', 'activitypub_max_image_attachments',
array( array(
'type' => 'integer', 'type' => 'integer',
'description' => \__( 'Number of images to attach to posts.', 'activitypub' ), 'description' => \__( 'Number of images to attach to posts.', 'activitypub' ),
'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS, 'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS,
) )
); );
\register_setting( \register_setting(
'activitypub', 'activitypub',
'activitypub_object_type', 'activitypub_object_type',
array( array(
'type' => 'string', 'type' => 'string',
'description' => \__( 'The Activity-Object-Type', 'activitypub' ), 'description' => \__( 'The Activity-Object-Type', 'activitypub' ),
'show_in_rest' => array( 'show_in_rest' => array(
'schema' => array( 'schema' => array(
'enum' => array( 'enum' => array(
@ -240,25 +240,25 @@ class Admin {
), ),
), ),
), ),
'default' => 'note', 'default' => 'note',
) )
); );
\register_setting( \register_setting(
'activitypub', 'activitypub',
'activitypub_use_hashtags', 'activitypub_use_hashtags',
array( array(
'type' => 'boolean', 'type' => 'boolean',
'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ), 'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
'default' => '0', 'default' => '0',
) )
); );
\register_setting( \register_setting(
'activitypub', 'activitypub',
'activitypub_use_opengraph', 'activitypub_use_opengraph',
array( array(
'type' => 'boolean', 'type' => 'boolean',
'description' => \__( 'Automatically add "fediverse:creator" OpenGraph tags for Authors and the Blog-User.', 'activitypub' ), 'description' => \__( 'Automatically add "fediverse:creator" OpenGraph tags for Authors and the Blog-User.', 'activitypub' ),
'default' => '1', 'default' => '1',
) )
); );
\register_setting( \register_setting(
@ -275,18 +275,18 @@ class Admin {
'activitypub', 'activitypub',
'activitypub_enable_users', 'activitypub_enable_users',
array( array(
'type' => 'boolean', 'type' => 'boolean',
'description' => \__( 'Every Author on this Blog (with the publish_posts capability) gets his own ActivityPub enabled Profile.', 'activitypub' ), 'description' => \__( 'Every Author on this Blog (with the publish_posts capability) gets his own ActivityPub enabled Profile.', 'activitypub' ),
'default' => '1', 'default' => '1',
) )
); );
\register_setting( \register_setting(
'activitypub', 'activitypub',
'activitypub_enable_blog_user', 'activitypub_enable_blog_user',
array( array(
'type' => 'boolean', 'type' => 'boolean',
'description' => \__( 'Your Blog becomes an ActivityPub compatible Profile.', 'activitypub' ), 'description' => \__( 'Your Blog becomes an ActivityPub compatible Profile.', 'activitypub' ),
'default' => '0', 'default' => '0',
) )
); );
@ -295,10 +295,10 @@ class Admin {
'activitypub_blog', 'activitypub_blog',
'activitypub_blog_description', 'activitypub_blog_description',
array( array(
'type' => 'string', 'type' => 'string',
'description' => \esc_html__( 'The Description of the Blog-User', 'activitypub' ), 'description' => \esc_html__( 'The Description of the Blog-User', 'activitypub' ),
'show_in_rest' => true, 'show_in_rest' => true,
'default' => '', 'default' => '',
) )
); );
\register_setting( \register_setting(
@ -350,9 +350,9 @@ class Admin {
'activitypub_blog', 'activitypub_blog',
'activitypub_header_image', 'activitypub_header_image',
array( array(
'type' => 'integer', 'type' => 'integer',
'description' => \__( 'The Attachment-ID of the Sites Header-Image', 'activitypub' ), 'description' => \__( 'The Attachment-ID of the Sites Header-Image', 'activitypub' ),
'default' => null, 'default' => null,
) )
); );
} }
@ -665,7 +665,7 @@ class Admin {
* @return array The extended bulk options. * @return array The extended bulk options.
*/ */
public static function user_bulk_options( $actions ) { public static function user_bulk_options( $actions ) {
$actions['add_activitypub_cap'] = __( 'Enable for ActivityPub', 'activitypub' ); $actions['add_activitypub_cap'] = __( 'Enable for ActivityPub', 'activitypub' );
$actions['remove_activitypub_cap'] = __( 'Disable for ActivityPub', 'activitypub' ); $actions['remove_activitypub_cap'] = __( 'Disable for ActivityPub', 'activitypub' );
return $actions; return $actions;

View file

@ -62,17 +62,17 @@ class Blocks {
} }
public static function add_data() { public static function add_data() {
$context = is_admin() ? 'editor' : 'view'; $context = is_admin() ? 'editor' : 'view';
$followers_handle = 'activitypub-followers-' . $context . '-script'; $followers_handle = 'activitypub-followers-' . $context . '-script';
$follow_me_handle = 'activitypub-follow-me-' . $context . '-script'; $follow_me_handle = 'activitypub-follow-me-' . $context . '-script';
$data = array( $data = array(
'namespace' => ACTIVITYPUB_REST_NAMESPACE, 'namespace' => ACTIVITYPUB_REST_NAMESPACE,
'enabled' => array( 'enabled' => array(
'site' => ! is_user_type_disabled( 'blog' ), 'site' => ! is_user_type_disabled( 'blog' ),
'users' => ! is_user_type_disabled( 'user' ), 'users' => ! is_user_type_disabled( 'user' ),
), ),
); );
$js = sprintf( 'var _activityPubOptions = %s;', wp_json_encode( $data ) ); $js = sprintf( 'var _activityPubOptions = %s;', wp_json_encode( $data ) );
\wp_add_inline_script( $followers_handle, $js, 'before' ); \wp_add_inline_script( $followers_handle, $js, 'before' );
\wp_add_inline_script( $follow_me_handle, $js, 'before' ); \wp_add_inline_script( $follow_me_handle, $js, 'before' );
} }
@ -152,6 +152,7 @@ class Blocks {
/** /**
* Filter an array by a list of keys. * Filter an array by a list of keys.
*
* @param array $array The array to filter. * @param array $array The array to filter.
* @param array $keys The keys to keep. * @param array $keys The keys to keep.
* @return array The filtered array. * @return array The filtered array.
@ -162,12 +163,13 @@ class Blocks {
/** /**
* Render the follow me block. * Render the follow me block.
*
* @param array $attrs The block attributes. * @param array $attrs The block attributes.
* @return string The HTML to render. * @return string The HTML to render.
*/ */
public static function render_follow_me_block( $attrs ) { public static function render_follow_me_block( $attrs ) {
$user_id = self::get_user_id( $attrs['selectedUser'] ); $user_id = self::get_user_id( $attrs['selectedUser'] );
$user = User_Collection::get_by_id( $user_id ); $user = User_Collection::get_by_id( $user_id );
if ( is_wp_error( $user ) ) { if ( is_wp_error( $user ) ) {
if ( 'inherit' === $attrs['selectedUser'] ) { if ( 'inherit' === $attrs['selectedUser'] ) {
// If the user is 'inherit' and we couldn't determine the user, don't render anything. // If the user is 'inherit' and we couldn't determine the user, don't render anything.
@ -204,10 +206,10 @@ class Blocks {
return '<!-- Followers block: `' . $followee_user_id . '` not an active ActivityPub user -->'; return '<!-- Followers block: `' . $followee_user_id . '` not an active ActivityPub user -->';
} }
$per_page = absint( $attrs['per_page'] ); $per_page = absint( $attrs['per_page'] );
$follower_data = Followers::get_followers_with_count( $followee_user_id, $per_page ); $follower_data = Followers::get_followers_with_count( $followee_user_id, $per_page );
$attrs['followerData']['total'] = $follower_data['total']; $attrs['followerData']['total'] = $follower_data['total'];
$attrs['followerData']['followers'] = array_map( $attrs['followerData']['followers'] = array_map(
function ( $follower ) { function ( $follower ) {
return self::filter_array_by_keys( return self::filter_array_by_keys(
@ -217,7 +219,7 @@ class Blocks {
}, },
$follower_data['followers'] $follower_data['followers']
); );
$wrapper_attributes = get_block_wrapper_attributes( $wrapper_attributes = get_block_wrapper_attributes(
array( array(
'aria-label' => __( 'Fediverse Followers', 'activitypub' ), 'aria-label' => __( 'Fediverse Followers', 'activitypub' ),
'class' => 'activitypub-follower-block', 'class' => 'activitypub-follower-block',
@ -261,7 +263,7 @@ class Blocks {
public static function render_follower( $follower ) { public static function render_follower( $follower ) {
$external_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" class="components-external-link__icon css-rvs7bx esh4a730" aria-hidden="true" focusable="false"><path d="M18.2 17c0 .7-.6 1.2-1.2 1.2H7c-.7 0-1.2-.6-1.2-1.2V7c0-.7.6-1.2 1.2-1.2h3.2V4.2H7C5.5 4.2 4.2 5.5 4.2 7v10c0 1.5 1.2 2.8 2.8 2.8h10c1.5 0 2.8-1.2 2.8-2.8v-3.6h-1.5V17zM14.9 3v1.5h3.7l-6.4 6.4 1.1 1.1 6.4-6.4v3.7h1.5V3h-6.3z"></path></svg>'; $external_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" class="components-external-link__icon css-rvs7bx esh4a730" aria-hidden="true" focusable="false"><path d="M18.2 17c0 .7-.6 1.2-1.2 1.2H7c-.7 0-1.2-.6-1.2-1.2V7c0-.7.6-1.2 1.2-1.2h3.2V4.2H7C5.5 4.2 4.2 5.5 4.2 7v10c0 1.5 1.2 2.8 2.8 2.8h10c1.5 0 2.8-1.2 2.8-2.8v-3.6h-1.5V17zM14.9 3v1.5h3.7l-6.4 6.4 1.1 1.1 6.4-6.4v3.7h1.5V3h-6.3z"></path></svg>';
$template = $template =
'<a href="%s" title="%s" class="components-external-link activitypub-link" target="_blank" rel="external noreferrer noopener"> '<a href="%s" title="%s" class="components-external-link activitypub-link" target="_blank" rel="external noreferrer noopener">
<img width="40" height="40" src="%s" class="avatar activitypub-avatar" /> <img width="40" height="40" src="%s" class="avatar activitypub-avatar" />
<span class="activitypub-actor"> <span class="activitypub-actor">

View file

@ -54,7 +54,7 @@ class Comment {
$attrs = array( $attrs = array(
'selectedComment' => self::generate_id( $comment ), 'selectedComment' => self::generate_id( $comment ),
'commentId' => $comment->comment_ID, 'commentId' => $comment->comment_ID,
); );
$div = sprintf( $div = sprintf(
@ -78,7 +78,7 @@ class Comment {
*/ */
private static function create_fediverse_reply_link( $link, $args ) { private static function create_fediverse_reply_link( $link, $args ) {
$str_to_replace = sprintf( '>%s<', $args['reply_text'] ); $str_to_replace = sprintf( '>%s<', $args['reply_text'] );
$replace_with = sprintf( $replace_with = sprintf(
' title="%s">%s<', ' title="%s">%s<',
esc_attr__( 'This comment was received from the fediverse and your reply will be sent to the original author', 'activitypub' ), esc_attr__( 'This comment was received from the fediverse and your reply will be sent to the original author', 'activitypub' ),
esc_html__( 'Reply with federation', 'activitypub' ) esc_html__( 'Reply with federation', 'activitypub' )
@ -343,8 +343,8 @@ class Comment {
/** /**
* Gets the public comment id via the WordPress comments meta. * Gets the public comment id via the WordPress comments meta.
* *
* @param int $wp_comment_id The internal WordPress comment ID. * @param int $wp_comment_id The internal WordPress comment ID.
* @param bool $fallback Whether the code should fall back to `source_url` if `source_id` is not set. * @param bool $fallback Whether the code should fall back to `source_url` if `source_id` is not set.
* *
* @return string|null The ActivityPub id/url of the comment. * @return string|null The ActivityPub id/url of the comment.
*/ */
@ -363,8 +363,8 @@ class Comment {
/** /**
* Gets the public comment url via the WordPress comments meta. * Gets the public comment url via the WordPress comments meta.
* *
* @param int $wp_comment_id The internal WordPress comment ID. * @param int $wp_comment_id The internal WordPress comment ID.
* @param bool $fallback Whether the code should fall back to `source_id` if `source_url` is not set. * @param bool $fallback Whether the code should fall back to `source_id` if `source_url` is not set.
* *
* @return string|null The ActivityPub id/url of the comment. * @return string|null The ActivityPub id/url of the comment.
*/ */
@ -383,7 +383,7 @@ class Comment {
/** /**
* Link remote comments to source url. * Link remote comments to source url.
* *
* @param string $comment_link * @param string $comment_link
* @param object|WP_Comment $comment * @param object|WP_Comment $comment
* *
* @return string $url * @return string $url
@ -430,7 +430,7 @@ class Comment {
private static function post_has_remote_comments( $post_id ) { private static function post_has_remote_comments( $post_id ) {
$comments = \get_comments( $comments = \get_comments(
array( array(
'post_id' => $post_id, 'post_id' => $post_id,
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'meta_query' => array( 'meta_query' => array(
'relation' => 'AND', 'relation' => 'AND',
@ -496,7 +496,7 @@ class Comment {
\wp_enqueue_style( \wp_enqueue_style(
$handle, $handle,
\plugins_url( 'build/remote-reply/style-index.css', __DIR__ ), \plugins_url( 'build/remote-reply/style-index.css', __DIR__ ),
[ 'wp-components' ], array( 'wp-components' ),
$assets['version'] $assets['version']
); );
} }

View file

@ -28,7 +28,8 @@ class Hashtag {
* @return array the activity object array * @return array the activity object array
*/ */
public static function filter_activity_object( $object_array ) { public static function filter_activity_object( $object_array ) {
/* Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629 /*
Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
if ( ! empty( $object_array['summary'] ) ) { if ( ! empty( $object_array['summary'] ) ) {
$object_array['summary'] = self::the_content( $object_array['summary'] ); $object_array['summary'] = self::the_content( $object_array['summary'] );
} }
@ -85,7 +86,7 @@ class Hashtag {
* @return string the final string * @return string the final string
*/ */
public static function replace_with_links( $result ) { public static function replace_with_links( $result ) {
$tag = $result[1]; $tag = $result[1];
$tag_object = \get_term_by( 'name', $tag, 'post_tag' ); $tag_object = \get_term_by( 'name', $tag, 'post_tag' );
if ( ! $tag_object ) { if ( ! $tag_object ) {
$tag_object = \get_term_by( 'name', $tag, 'category' ); $tag_object = \get_term_by( 'name', $tag, 'category' );

View file

@ -112,7 +112,7 @@ class Health_Check {
'<p>%s</p>', '<p>%s</p>',
\__( 'Enhance your WordPress sites performance and mitigate potential heavy loads caused by plugins like ActivityPub by setting up a system cron job to run WP Cron. This ensures scheduled tasks are executed consistently and reduces the reliance on website traffic for trigger events.', 'activitypub' ) \__( 'Enhance your WordPress sites performance and mitigate potential heavy loads caused by plugins like ActivityPub by setting up a system cron job to run WP Cron. This ensures scheduled tasks are executed consistently and reduces the reliance on website traffic for trigger events.', 'activitypub' )
); );
$result['actions'] .= sprintf( $result['actions'] .= sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>', '<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
__( 'https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/', 'activitypub' ), __( 'https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/', 'activitypub' ),
__( 'Learn how to hook the WP-Cron into the System Task Scheduler.', 'activitypub' ), __( 'Learn how to hook the WP-Cron into the System Task Scheduler.', 'activitypub' ),
@ -167,8 +167,8 @@ class Health_Check {
* @return boolean|WP_Error * @return boolean|WP_Error
*/ */
public static function is_author_url_accessible() { public static function is_author_url_accessible() {
$user = \wp_get_current_user(); $user = \wp_get_current_user();
$author_url = \get_author_posts_url( $user->ID ); $author_url = \get_author_posts_url( $user->ID );
$reference_author_url = self::get_author_posts_url( $user->ID, $user->user_nicename ); $reference_author_url = self::get_author_posts_url( $user->ID, $user->user_nicename );
// check for "author" in URL // check for "author" in URL
@ -190,7 +190,7 @@ class Health_Check {
$response = \wp_remote_get( $response = \wp_remote_get(
$author_url, $author_url,
array( array(
'headers' => array( 'Accept' => 'application/activity+json' ), 'headers' => array( 'Accept' => 'application/activity+json' ),
'redirection' => 0, 'redirection' => 0,
) )
); );
@ -252,7 +252,7 @@ class Health_Check {
* @return boolean|WP_Error * @return boolean|WP_Error
*/ */
public static function is_webfinger_endpoint_accessible() { public static function is_webfinger_endpoint_accessible() {
$user = Users::get_by_id( Users::APPLICATION_USER_ID ); $user = Users::get_by_id( Users::APPLICATION_USER_ID );
$resource = $user->get_webfinger(); $resource = $user->get_webfinger();
$url = Webfinger::resolve( $resource ); $url = Webfinger::resolve( $resource );
@ -277,7 +277,7 @@ class Health_Check {
); );
$health_messages = array( $health_messages = array(
'webfinger_url_not_accessible' => \sprintf( 'webfinger_url_not_accessible' => \sprintf(
$not_accessible, $not_accessible,
$url->get_error_data()['data'] $url->get_error_data()['data']
), ),
@ -287,7 +287,7 @@ class Health_Check {
$url->get_error_data()['data'] $url->get_error_data()['data']
), ),
); );
$message = null; $message = null;
if ( isset( $health_messages[ $url->get_error_code() ] ) ) { if ( isset( $health_messages[ $url->get_error_code() ] ) ) {
$message = $health_messages[ $url->get_error_code() ]; $message = $health_messages[ $url->get_error_code() ];
} }
@ -314,7 +314,7 @@ class Health_Check {
public static function get_author_posts_url( $author_id, $author_nicename = '' ) { public static function get_author_posts_url( $author_id, $author_nicename = '' ) {
global $wp_rewrite; global $wp_rewrite;
$auth_id = (int) $author_id; $auth_id = (int) $author_id;
$link = $wp_rewrite->get_author_permastruct(); $link = $wp_rewrite->get_author_permastruct();
if ( empty( $link ) ) { if ( empty( $link ) ) {
$file = home_url( '/' ); $file = home_url( '/' );
@ -343,12 +343,12 @@ class Health_Check {
$info['activitypub'] = array( $info['activitypub'] = array(
'label' => __( 'ActivityPub', 'activitypub' ), 'label' => __( 'ActivityPub', 'activitypub' ),
'fields' => array( 'fields' => array(
'webfinger' => array( 'webfinger' => array(
'label' => __( 'WebFinger Resource', 'activitypub' ), 'label' => __( 'WebFinger Resource', 'activitypub' ),
'value' => Webfinger::get_user_resource( wp_get_current_user()->ID ), 'value' => Webfinger::get_user_resource( wp_get_current_user()->ID ),
'private' => true, 'private' => true,
), ),
'author_url' => array( 'author_url' => array(
'label' => __( 'Author URL', 'activitypub' ), 'label' => __( 'Author URL', 'activitypub' ),
'value' => get_author_posts_url( wp_get_current_user()->ID ), 'value' => get_author_posts_url( wp_get_current_user()->ID ),
'private' => true, 'private' => true,

View file

@ -24,8 +24,8 @@ class Http {
public static function post( $url, $body, $user_id ) { public static function post( $url, $body, $user_id ) {
\do_action( 'activitypub_pre_http_post', $url, $body, $user_id ); \do_action( 'activitypub_pre_http_post', $url, $body, $user_id );
$date = \gmdate( 'D, d M Y H:i:s T' ); $date = \gmdate( 'D, d M Y H:i:s T' );
$digest = Signature::generate_digest( $body ); $digest = Signature::generate_digest( $body );
$signature = Signature::generate_signature( $user_id, 'post', $url, $date, $digest ); $signature = Signature::generate_signature( $user_id, 'post', $url, $date, $digest );
$wp_version = get_masked_wp_version(); $wp_version = get_masked_wp_version();
@ -36,19 +36,19 @@ class Http {
* @param string $user_agent The user agent string. * @param string $user_agent The user agent string.
*/ */
$user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) ); $user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) );
$args = array( $args = array(
'timeout' => 100, 'timeout' => 100,
'limit_response_size' => 1048576, 'limit_response_size' => 1048576,
'redirection' => 3, 'redirection' => 3,
'user-agent' => "$user_agent; ActivityPub", 'user-agent' => "$user_agent; ActivityPub",
'headers' => array( 'headers' => array(
'Accept' => 'application/activity+json', 'Accept' => 'application/activity+json',
'Content-Type' => 'application/activity+json', 'Content-Type' => 'application/activity+json',
'Digest' => $digest, 'Digest' => $digest,
'Signature' => $signature, 'Signature' => $signature,
'Date' => $date, 'Date' => $date,
), ),
'body' => $body, 'body' => $body,
); );
$response = \wp_safe_remote_post( $url, $args ); $response = \wp_safe_remote_post( $url, $args );
@ -86,7 +86,7 @@ class Http {
} }
} }
$date = \gmdate( 'D, d M Y H:i:s T' ); $date = \gmdate( 'D, d M Y H:i:s T' );
$signature = Signature::generate_signature( Users::APPLICATION_USER_ID, 'get', $url, $date ); $signature = Signature::generate_signature( Users::APPLICATION_USER_ID, 'get', $url, $date );
$wp_version = get_masked_wp_version(); $wp_version = get_masked_wp_version();
@ -99,15 +99,15 @@ class Http {
$user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) ); $user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) );
$args = array( $args = array(
'timeout' => apply_filters( 'activitypub_remote_get_timeout', 100 ), 'timeout' => apply_filters( 'activitypub_remote_get_timeout', 100 ),
'limit_response_size' => 1048576, 'limit_response_size' => 1048576,
'redirection' => 3, 'redirection' => 3,
'user-agent' => "$user_agent; ActivityPub", 'user-agent' => "$user_agent; ActivityPub",
'headers' => array( 'headers' => array(
'Accept' => 'application/activity+json', 'Accept' => 'application/activity+json',
'Content-Type' => 'application/activity+json', 'Content-Type' => 'application/activity+json',
'Signature' => $signature, 'Signature' => $signature,
'Date' => $date, 'Date' => $date,
), ),
); );

View file

@ -24,7 +24,8 @@ class Link {
* @return array the activity object array * @return array the activity object array
*/ */
public static function filter_activity_object( $object_array ) { public static function filter_activity_object( $object_array ) {
/* Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629 /*
Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
if ( ! empty( $object_array['summary'] ) ) { if ( ! empty( $object_array['summary'] ) ) {
$object_array['summary'] = self::the_content( $object_array['summary'] ); $object_array['summary'] = self::the_content( $object_array['summary'] );
} }
@ -82,7 +83,7 @@ class Link {
$text_url = $parsed_url['host']; $text_url = $parsed_url['host'];
if ( 'www.' === substr( $text_url, 0, 4 ) ) { if ( 'www.' === substr( $text_url, 0, 4 ) ) {
$text_url = substr( $text_url, 4 ); $text_url = substr( $text_url, 4 );
$invisible_prefix .= 'www.'; $invisible_prefix .= 'www.';
} }
if ( ! empty( $parsed_url['port'] ) ) { if ( ! empty( $parsed_url['port'] ) ) {
@ -98,7 +99,7 @@ class Link {
$text_url .= '#' . $parsed_url['fragment']; $text_url .= '#' . $parsed_url['fragment'];
} }
$display = \substr( $text_url, 0, 30 ); $display = \substr( $text_url, 0, 30 );
$invisible_suffix = \substr( $text_url, 30 ); $invisible_suffix = \substr( $text_url, 30 );
$display_class = ''; $display_class = '';

View file

@ -43,8 +43,8 @@ class Notification {
* @param int $target The WordPress User-Id. * @param int $target The WordPress User-Id.
*/ */
public function __construct( $type, $actor, $object, $target ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound public function __construct( $type, $actor, $object, $target ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound
$this->type = $type; $this->type = $type;
$this->actor = $actor; $this->actor = $actor;
$this->object = $object; $this->object = $object;
$this->target = $target; $this->target = $target;
} }

View file

@ -332,7 +332,7 @@ class Shortcodes {
} }
$author_id = \get_post_field( 'post_author', $item->ID ); $author_id = \get_post_field( 'post_author', $item->ID );
$name = \get_the_author_meta( 'display_name', $author_id ); $name = \get_the_author_meta( 'display_name', $author_id );
if ( ! $name ) { if ( ! $name ) {
return ''; return '';
@ -358,7 +358,7 @@ class Shortcodes {
} }
$author_id = \get_post_field( 'post_author', $item->ID ); $author_id = \get_post_field( 'post_author', $item->ID );
$url = \get_the_author_meta( 'user_url', $author_id ); $url = \get_the_author_meta( 'user_url', $author_id );
if ( ! $url ) { if ( ! $url ) {
return ''; return '';
@ -422,7 +422,7 @@ class Shortcodes {
return ''; return '';
} }
$datetime = \get_post_datetime( $item ); $datetime = \get_post_datetime( $item );
$dateformat = \get_option( 'date_format' ); $dateformat = \get_option( 'date_format' );
$timeformat = \get_option( 'time_format' ); $timeformat = \get_option( 'time_format' );
@ -451,7 +451,7 @@ class Shortcodes {
return ''; return '';
} }
$datetime = \get_post_datetime( $item ); $datetime = \get_post_datetime( $item );
$dateformat = \get_option( 'date_format' ); $dateformat = \get_option( 'date_format' );
$timeformat = \get_option( 'time_format' ); $timeformat = \get_option( 'time_format' );
@ -480,7 +480,7 @@ class Shortcodes {
return ''; return '';
} }
$datetime = \get_post_datetime( $item ); $datetime = \get_post_datetime( $item );
$dateformat = \get_option( 'date_format' ); $dateformat = \get_option( 'date_format' );
$timeformat = \get_option( 'time_format' ); $timeformat = \get_option( 'time_format' );

View file

@ -60,7 +60,7 @@ class Signature {
*/ */
public static function get_keypair_for( $user_id ) { public static function get_keypair_for( $user_id ) {
$option_key = self::get_signature_options_key_for( $user_id ); $option_key = self::get_signature_options_key_for( $user_id );
$key_pair = \get_option( $option_key ); $key_pair = \get_option( $option_key );
if ( ! $key_pair ) { if ( ! $key_pair ) {
$key_pair = self::generate_key_pair_for( $user_id ); $key_pair = self::generate_key_pair_for( $user_id );
@ -78,7 +78,7 @@ class Signature {
*/ */
protected static function generate_key_pair_for( $user_id ) { protected static function generate_key_pair_for( $user_id ) {
$option_key = self::get_signature_options_key_for( $user_id ); $option_key = self::get_signature_options_key_for( $user_id );
$key_pair = self::check_legacy_key_pair_for( $user_id ); $key_pair = self::check_legacy_key_pair_for( $user_id );
if ( $key_pair ) { if ( $key_pair ) {
\add_option( $option_key, $key_pair ); \add_option( $option_key, $key_pair );
@ -87,14 +87,14 @@ class Signature {
} }
$config = array( $config = array(
'digest_alg' => 'sha512', 'digest_alg' => 'sha512',
'private_key_bits' => 2048, 'private_key_bits' => 2048,
'private_key_type' => \OPENSSL_KEYTYPE_RSA, 'private_key_type' => \OPENSSL_KEYTYPE_RSA,
); );
$key = \openssl_pkey_new( $config ); $key = \openssl_pkey_new( $config );
$priv_key = null; $priv_key = null;
$detail = array(); $detail = array();
if ( $key ) { if ( $key ) {
\openssl_pkey_export( $key, $priv_key ); \openssl_pkey_export( $key, $priv_key );
@ -152,15 +152,15 @@ class Signature {
protected static function check_legacy_key_pair_for( $user_id ) { protected static function check_legacy_key_pair_for( $user_id ) {
switch ( $user_id ) { switch ( $user_id ) {
case 0: case 0:
$public_key = \get_option( 'activitypub_blog_user_public_key' ); $public_key = \get_option( 'activitypub_blog_user_public_key' );
$private_key = \get_option( 'activitypub_blog_user_private_key' ); $private_key = \get_option( 'activitypub_blog_user_private_key' );
break; break;
case -1: case -1:
$public_key = \get_option( 'activitypub_application_user_public_key' ); $public_key = \get_option( 'activitypub_application_user_public_key' );
$private_key = \get_option( 'activitypub_application_user_private_key' ); $private_key = \get_option( 'activitypub_application_user_private_key' );
break; break;
default: default:
$public_key = \get_user_meta( $user_id, 'magic_sig_public_key', true ); $public_key = \get_user_meta( $user_id, 'magic_sig_public_key', true );
$private_key = \get_user_meta( $user_id, 'magic_sig_private_key', true ); $private_key = \get_user_meta( $user_id, 'magic_sig_private_key', true );
break; break;
} }
@ -253,11 +253,11 @@ class Signature {
$route = '/' . $path . $route; $route = '/' . $path . $route;
} }
$headers = $request->get_headers(); $headers = $request->get_headers();
$headers['(request-target)'][0] = strtolower( $request->get_method() ) . ' ' . $route; $headers['(request-target)'][0] = strtolower( $request->get_method() ) . ' ' . $route;
} else { } else {
$request = self::format_server_request( $request ); $request = self::format_server_request( $request );
$headers = $request['headers']; // $_SERVER array $headers = $request['headers']; // $_SERVER array
$headers['(request-target)'][0] = strtolower( $headers['request_method'][0] ) . ' ' . $headers['request_uri'][0]; $headers['(request-target)'][0] = strtolower( $headers['request_method'][0] ) . ' ' . $headers['request_uri'][0];
} }
@ -359,7 +359,7 @@ class Signature {
if ( $signature_block['algorithm'] ) { if ( $signature_block['algorithm'] ) {
switch ( $signature_block['algorithm'] ) { switch ( $signature_block['algorithm'] ) {
case 'rsa-sha-512': case 'rsa-sha-512':
return 'sha512'; //hs2019 https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12 return 'sha512'; // hs2019 https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12
default: default:
return 'sha256'; return 'sha256';
} }
@ -375,8 +375,8 @@ class Signature {
* @return array signature parts * @return array signature parts
*/ */
public static function parse_signature_header( $signature ) { public static function parse_signature_header( $signature ) {
$parsed_header = array(); $parsed_header = array();
$matches = array(); $matches = array();
if ( \preg_match( '/keyId="(.*?)"/ism', $signature, $matches ) ) { if ( \preg_match( '/keyId="(.*?)"/ism', $signature, $matches ) ) {
$parsed_header['keyId'] = trim( $matches[1] ); $parsed_header['keyId'] = trim( $matches[1] );
@ -459,7 +459,7 @@ class Signature {
$d->setTimeZone( new DateTimeZone( 'UTC' ) ); $d->setTimeZone( new DateTimeZone( 'UTC' ) );
$c = $d->format( 'U' ); $c = $d->format( 'U' );
$dplus = time() + ( 3 * HOUR_IN_SECONDS ); $dplus = time() + ( 3 * HOUR_IN_SECONDS );
$dminus = time() - ( 3 * HOUR_IN_SECONDS ); $dminus = time() - ( 3 * HOUR_IN_SECONDS );
if ( $c > $dplus || $c < $dminus ) { if ( $c > $dplus || $c < $dminus ) {
@ -499,7 +499,7 @@ class Signature {
if ( 'REQUEST_URI' === $req_param ) { if ( 'REQUEST_URI' === $req_param ) {
$request['headers']['route'][] = $param_val; $request['headers']['route'][] = $param_val;
} else { } else {
$header_key = str_replace( $header_key = str_replace(
'http_', 'http_',
'', '',
$req_param $req_param

View file

@ -142,10 +142,10 @@ class Webfinger {
if ( ! preg_match( '/^([a-zA-Z+]+):/', $url, $match ) ) { if ( ! preg_match( '/^([a-zA-Z+]+):/', $url, $match ) ) {
$identifier = 'acct:' . $url; $identifier = 'acct:' . $url;
$scheme = 'acct'; $scheme = 'acct';
} else { } else {
$identifier = $url; $identifier = $url;
$scheme = $match[1]; $scheme = $match[1];
} }
$host = null; $host = null;

View file

@ -21,9 +21,9 @@ class Extra_Fields {
* @return \WP_Post[] The extra fields. * @return \WP_Post[] The extra fields.
*/ */
public static function get_actor_fields( $user_id ) { public static function get_actor_fields( $user_id ) {
$is_blog = self::is_blog( $user_id ); $is_blog = self::is_blog( $user_id );
$post_type = $is_blog ? self::BLOG_POST_TYPE : self::USER_POST_TYPE; $post_type = $is_blog ? self::BLOG_POST_TYPE : self::USER_POST_TYPE;
$args = array( $args = array(
'post_type' => $post_type, 'post_type' => $post_type,
'nopaging' => true, 'nopaging' => true,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
@ -33,7 +33,7 @@ class Extra_Fields {
$args['author'] = $user_id; $args['author'] = $user_id;
} }
$query = new \WP_Query( $args ); $query = new \WP_Query( $args );
$fields = $query->posts ?? array(); $fields = $query->posts ?? array();
return apply_filters( 'activitypub_get_actor_extra_fields', $fields, $user_id ); return apply_filters( 'activitypub_get_actor_extra_fields', $fields, $user_id );
@ -75,10 +75,10 @@ class Extra_Fields {
); );
foreach ( $fields as $post ) { foreach ( $fields as $post ) {
$content = self::get_formatted_content( $post ); $content = self::get_formatted_content( $post );
$attachments[] = array( $attachments[] = array(
'type' => 'PropertyValue', 'type' => 'PropertyValue',
'name' => \get_the_title( $post ), 'name' => \get_the_title( $post ),
'value' => \html_entity_decode( 'value' => \html_entity_decode(
$content, $content,
\ENT_QUOTES, \ENT_QUOTES,
@ -104,7 +104,7 @@ class Extra_Fields {
'type' => 'Link', 'type' => 'Link',
'name' => \get_the_title( $post ), 'name' => \get_the_title( $post ),
'href' => \esc_url( $tags->get_attribute( 'href' ) ), 'href' => \esc_url( $tags->get_attribute( 'href' ) ),
'rel' => explode( ' ', $tags->get_attribute( 'rel' ) ), 'rel' => explode( ' ', $tags->get_attribute( 'rel' ) ),
); );
$link_added = true; $link_added = true;
@ -176,7 +176,7 @@ class Extra_Fields {
return $extra_fields; return $extra_fields;
} }
$is_blog = self::is_blog( $user_id ); $is_blog = self::is_blog( $user_id );
$already_migrated = $is_blog $already_migrated = $is_blog
? \get_option( 'activitypub_default_extra_fields' ) ? \get_option( 'activitypub_default_extra_fields' )
: \get_user_meta( $user_id, 'activitypub_default_extra_fields', true ); : \get_user_meta( $user_id, 'activitypub_default_extra_fields', true );
@ -199,7 +199,7 @@ class Extra_Fields {
); );
if ( ! $is_blog ) { if ( ! $is_blog ) {
$author_url = \get_the_author_meta( 'user_url', $user_id ); $author_url = \get_the_author_meta( 'user_url', $user_id );
$author_posts_url = \get_author_posts_url( $user_id ); $author_posts_url = \get_author_posts_url( $user_id );
$defaults[ \__( 'Profile', 'activitypub' ) ] = $author_posts_url; $defaults[ \__( 'Profile', 'activitypub' ) ] = $author_posts_url;
@ -226,7 +226,7 @@ class Extra_Fields {
'menu_order' => $menu_order, 'menu_order' => $menu_order,
); );
$menu_order += 10; $menu_order += 10;
$extra_field_id = wp_insert_post( $extra_field ); $extra_field_id = wp_insert_post( $extra_field );
$extra_fields[] = get_post( $extra_field_id ); $extra_fields[] = get_post( $extra_field_id );
} }
@ -247,6 +247,7 @@ class Extra_Fields {
/** /**
* Checks if the user is the blog user. * Checks if the user is the blog user.
*
* @param int $user_id The user ID. * @param int $user_id The user ID.
* @return bool True if the user is the blog user, otherwise false. * @return bool True if the user is the blog user, otherwise false.
*/ */

View file

@ -17,7 +17,7 @@ use function Activitypub\get_remote_metadata_by_actor;
* @author Matthias Pfefferle * @author Matthias Pfefferle
*/ */
class Followers { class Followers {
const POST_TYPE = 'ap_follower'; const POST_TYPE = 'ap_follower';
const CACHE_KEY_INBOXES = 'follower_inboxes_%s'; const CACHE_KEY_INBOXES = 'follower_inboxes_%s';
/** /**
@ -139,10 +139,10 @@ class Followers {
/** /**
* Get the Followers of a given user * Get the Followers of a given user
* *
* @param int $user_id The ID of the WordPress User. * @param int $user_id The ID of the WordPress User.
* @param int $number Maximum number of results to return. * @param int $number Maximum number of results to return.
* @param int $page Page number. * @param int $page Page number.
* @param array $args The WP_Query arguments. * @param array $args The WP_Query arguments.
* @return array List of `Follower` objects. * @return array List of `Follower` objects.
*/ */
public static function get_followers( $user_id, $number = -1, $page = null, $args = array() ) { public static function get_followers( $user_id, $number = -1, $page = null, $args = array() ) {
@ -153,10 +153,10 @@ class Followers {
/** /**
* Get the Followers of a given user, along with a total count for pagination purposes. * Get the Followers of a given user, along with a total count for pagination purposes.
* *
* @param int $user_id The ID of the WordPress User. * @param int $user_id The ID of the WordPress User.
* @param int $number Maximum number of results to return. * @param int $number Maximum number of results to return.
* @param int $page Page number. * @param int $page Page number.
* @param array $args The WP_Query arguments. * @param array $args The WP_Query arguments.
* *
* @return array * @return array
* followers List of `Follower` objects. * followers List of `Follower` objects.
@ -178,9 +178,9 @@ class Followers {
), ),
); );
$args = wp_parse_args( $args, $defaults ); $args = wp_parse_args( $args, $defaults );
$query = new WP_Query( $args ); $query = new WP_Query( $args );
$total = $query->found_posts; $total = $query->found_posts;
$followers = array_map( $followers = array_map(
function ( $post ) { function ( $post ) {
return Follower::init_from_cpt( $post ); return Follower::init_from_cpt( $post );
@ -259,7 +259,7 @@ class Followers {
*/ */
public static function get_inboxes( $user_id ) { public static function get_inboxes( $user_id ) {
$cache_key = sprintf( self::CACHE_KEY_INBOXES, $user_id ); $cache_key = sprintf( self::CACHE_KEY_INBOXES, $user_id );
$inboxes = wp_cache_get( $cache_key, 'activitypub' ); $inboxes = wp_cache_get( $cache_key, 'activitypub' );
if ( $inboxes ) { if ( $inboxes ) {
return $inboxes; return $inboxes;

View file

@ -62,7 +62,7 @@ class Interactions {
public static function update_comment( $activity ) { public static function update_comment( $activity ) {
$meta = get_remote_metadata_by_actor( $activity['actor'] ); $meta = get_remote_metadata_by_actor( $activity['actor'] );
//Determine comment_ID // Determine comment_ID
$comment = object_id_to_comment( \esc_url_raw( $activity['object']['id'] ) ); $comment = object_id_to_comment( \esc_url_raw( $activity['object']['id'] ) );
$commentdata = \get_comment( $comment, ARRAY_A ); $commentdata = \get_comment( $comment, ARRAY_A );
@ -70,8 +70,8 @@ class Interactions {
return false; return false;
} }
//found a local comment id // found a local comment id
$commentdata['comment_author'] = \esc_attr( $meta['name'] ? $meta['name'] : $meta['preferredUsername'] ); $commentdata['comment_author'] = \esc_attr( $meta['name'] ? $meta['name'] : $meta['preferredUsername'] );
$commentdata['comment_content'] = \addslashes( $activity['object']['content'] ); $commentdata['comment_content'] = \addslashes( $activity['object']['content'] );
return self::persist( $commentdata, self::UPDATE ); return self::persist( $commentdata, self::UPDATE );
@ -80,7 +80,7 @@ class Interactions {
/** /**
* Adds an incoming Like, Announce, ... as a comment to a post. * Adds an incoming Like, Announce, ... as a comment to a post.
* *
* @param array $activity Activity array. * @param array $activity Activity array.
* *
* @return array|false Comment data or `false` on failure. * @return array|false Comment data or `false` on failure.
*/ */
@ -173,14 +173,14 @@ class Interactions {
$actor = object_to_uri( $meta['url'] ); $actor = object_to_uri( $meta['url'] );
} }
$args = array( $args = array(
'nopaging' => true, 'nopaging' => true,
'author_url' => $actor, 'author_url' => $actor,
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'meta_query' => array( 'meta_query' => array(
array( array(
'key' => 'protocol', 'key' => 'protocol',
'value' => 'activitypub', 'value' => 'activitypub',
'compare' => '=', 'compare' => '=',
), ),
), ),
@ -252,14 +252,14 @@ class Interactions {
} }
$commentdata = array( $commentdata = array(
'comment_author' => \esc_attr( $comment_author ), 'comment_author' => \esc_attr( $comment_author ),
'comment_author_url' => \esc_url_raw( $url ), 'comment_author_url' => \esc_url_raw( $url ),
'comment_content' => $comment_content, 'comment_content' => $comment_content,
'comment_type' => 'comment', 'comment_type' => 'comment',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_meta' => array( 'comment_meta' => array(
'source_id' => \esc_url_raw( object_to_uri( $activity['object'] ) ), 'source_id' => \esc_url_raw( object_to_uri( $activity['object'] ) ),
'protocol' => 'activitypub', 'protocol' => 'activitypub',
), ),
); );

View file

@ -21,13 +21,13 @@ class Replies {
*/ */
private static function build_args( $wp_object ) { private static function build_args( $wp_object ) {
$args = array( $args = array(
'status' => 'approve', 'status' => 'approve',
'orderby' => 'comment_date_gmt', 'orderby' => 'comment_date_gmt',
'order' => 'ASC', 'order' => 'ASC',
); );
if ( $wp_object instanceof WP_Post ) { if ( $wp_object instanceof WP_Post ) {
$args['parent'] = 0; // TODO: maybe this is unnecessary. $args['parent'] = 0; // TODO: maybe this is unnecessary.
$args['post_id'] = $wp_object->ID; $args['post_id'] = $wp_object->ID;
} elseif ( $wp_object instanceof WP_Comment ) { } elseif ( $wp_object instanceof WP_Comment ) {
$args['parent'] = $wp_object->comment_ID; $args['parent'] = $wp_object->comment_ID;
@ -48,7 +48,7 @@ class Replies {
private static function add_pagination_args( $args, $page, $comments_per_page ) { private static function add_pagination_args( $args, $page, $comments_per_page ) {
$args['number'] = $comments_per_page; $args['number'] = $comments_per_page;
$offset = intval( $page ) * $comments_per_page; $offset = intval( $page ) * $comments_per_page;
$args['offset'] = $offset; $args['offset'] = $offset;
return $args; return $args;
@ -76,7 +76,7 @@ class Replies {
* Get the replies collection. * Get the replies collection.
* *
* @param WP_Post|WP_Comment $wp_object * @param WP_Post|WP_Comment $wp_object
* @param int $page * @param int $page
* *
* @return array An associative array containing the replies collection without JSON-LD context. * @return array An associative array containing the replies collection without JSON-LD context.
*/ */
@ -88,8 +88,8 @@ class Replies {
} }
$replies = array( $replies = array(
'id' => $id, 'id' => $id,
'type' => 'Collection', 'type' => 'Collection',
); );
$replies['first'] = self::get_collection_page( $wp_object, 0, $replies['id'] ); $replies['first'] = self::get_collection_page( $wp_object, 0, $replies['id'] );

View file

@ -88,12 +88,12 @@ class Users {
// check for 'activitypub_username' meta // check for 'activitypub_username' meta
$user = new WP_User_Query( $user = new WP_User_Query(
array( array(
'count_total' => false, 'count_total' => false,
'number' => 1, 'number' => 1,
'hide_empty' => true, 'hide_empty' => true,
'fields' => 'ID', 'fields' => 'ID',
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'meta_query' => array( 'meta_query' => array(
'relation' => 'OR', 'relation' => 'OR',
array( array(
'key' => 'activitypub_user_identifier', 'key' => 'activitypub_user_identifier',
@ -144,7 +144,7 @@ class Users {
$resource = object_to_uri( $resource ); $resource = object_to_uri( $resource );
$scheme = 'acct'; $scheme = 'acct';
$match = array(); $match = array();
// try to extract the scheme and the host // try to extract the scheme and the host
if ( preg_match( '/^([a-zA-Z^:]+):(.*)$/i', $resource, $match ) ) { if ( preg_match( '/^([a-zA-Z^:]+):(.*)$/i', $resource, $match ) ) {
// extract the scheme // extract the scheme

View file

@ -64,7 +64,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
return new WP_Error( return new WP_Error(
'activitypub_no_valid_actor_identifier', 'activitypub_no_valid_actor_identifier',
\__( 'The "actor" identifier is not valid', 'activitypub' ), \__( 'The "actor" identifier is not valid', 'activitypub' ),
array( 'status' => 404, 'actor' => $actor ) array(
'status' => 404,
'actor' => $actor,
)
); );
} }
} }
@ -77,7 +80,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
return new WP_Error( return new WP_Error(
'activitypub_no_valid_actor_identifier', 'activitypub_no_valid_actor_identifier',
\__( 'The "actor" identifier is not valid', 'activitypub' ), \__( 'The "actor" identifier is not valid', 'activitypub' ),
array( 'status' => 404, 'actor' => $actor ) array(
'status' => 404,
'actor' => $actor,
)
); );
} }
@ -100,7 +106,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
$metadata = new WP_Error( $metadata = new WP_Error(
'activitypub_no_valid_actor_url', 'activitypub_no_valid_actor_url',
\__( 'The "actor" is no valid URL', 'activitypub' ), \__( 'The "actor" is no valid URL', 'activitypub' ),
array( 'status' => 400, 'actor' => $actor ) array(
'status' => 400,
'actor' => $actor,
)
); );
return $metadata; return $metadata;
} }
@ -118,7 +127,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
$metadata = new WP_Error( $metadata = new WP_Error(
'activitypub_invalid_json', 'activitypub_invalid_json',
\__( 'No valid JSON data', 'activitypub' ), \__( 'No valid JSON data', 'activitypub' ),
array( 'status' => 400, 'actor' => $actor ) array(
'status' => 400,
'actor' => $actor,
)
); );
return $metadata; return $metadata;
} }
@ -185,7 +197,7 @@ function url_to_authorid( $url ) {
// generate rewrite rule for the author url // generate rewrite rule for the author url
$author_rewrite = $wp_rewrite->get_author_permastruct(); $author_rewrite = $wp_rewrite->get_author_permastruct();
$author_regexp = \str_replace( '%author%', '', $author_rewrite ); $author_regexp = \str_replace( '%author%', '', $author_rewrite );
// match the rewrite rule with the passed url // match the rewrite rule with the passed url
if ( \preg_match( '/https?:\/\/(.+)' . \preg_quote( $author_regexp, '/' ) . '([^\/]+)/i', $url, $match ) ) { if ( \preg_match( '/https?:\/\/(.+)' . \preg_quote( $author_regexp, '/' ) . '([^\/]+)/i', $url, $match ) ) {
@ -248,7 +260,7 @@ function is_tombstone( $wp_error ) {
*/ */
function get_rest_url_by_path( $path = '' ) { function get_rest_url_by_path( $path = '' ) {
// we'll handle the leading slash. // we'll handle the leading slash.
$path = ltrim( $path, '/' ); $path = ltrim( $path, '/' );
$namespaced_path = sprintf( '/%s/%s', ACTIVITYPUB_REST_NAMESPACE, $path ); $namespaced_path = sprintf( '/%s/%s', ACTIVITYPUB_REST_NAMESPACE, $path );
return \get_rest_url( null, $namespaced_path ); return \get_rest_url( null, $namespaced_path );
} }
@ -631,9 +643,9 @@ function is_activity_public( $data ) {
*/ */
function get_active_users( $duration = 1 ) { function get_active_users( $duration = 1 ) {
$duration = intval( $duration ); $duration = intval( $duration );
$transient_key = sprintf( 'monthly_active_users_%d', $duration ); $transient_key = sprintf( 'monthly_active_users_%d', $duration );
$count = get_transient( $transient_key ); $count = get_transient( $transient_key );
if ( false === $count ) { if ( false === $count ) {
global $wpdb; global $wpdb;
@ -924,8 +936,8 @@ function get_enclosures( $post_id ) {
} }
return array( return array(
'url' => $attributes[0], 'url' => $attributes[0],
'length' => isset( $attributes[1] ) ? trim( $attributes[1] ) : null, 'length' => isset( $attributes[1] ) ? trim( $attributes[1] ) : null,
'mediaType' => isset( $attributes[2] ) ? trim( $attributes[2] ) : null, 'mediaType' => isset( $attributes[2] ) ? trim( $attributes[2] ) : null,
); );
}, },
@ -961,7 +973,7 @@ function get_comment_ancestors( $comment ) {
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( $id > 0 ) { while ( $id > 0 ) {
$ancestor = \get_comment( $id ); $ancestor = \get_comment( $id );
$parent_id = (int) $ancestor->comment_parent; $parent_id = (int) $ancestor->comment_parent;
// Loop detection: If the ancestor has been seen before, break. // Loop detection: If the ancestor has been seen before, break.
@ -1019,7 +1031,6 @@ function custom_large_numbers( $formatted, $number, $decimals ) {
/** /**
* Registers a ActivityPub comment type. * Registers a ActivityPub comment type.
* *
*
* @param string $comment_type Key for comment type. * @param string $comment_type Key for comment type.
* @param array $args Arguments. * @param array $args Arguments.
* *
@ -1040,7 +1051,6 @@ function register_comment_type( $comment_type, $args = array() ) {
/** /**
* Fires after a ActivityPub comment type is registered. * Fires after a ActivityPub comment type is registered.
* *
*
* @param string $comment_type Comment type. * @param string $comment_type Comment type.
* @param array $args Arguments used to register the comment type. * @param array $args Arguments used to register the comment type.
*/ */
@ -1102,8 +1112,8 @@ function enrich_content_data( $content, $regex, $regex_callback ) {
if ( mb_strlen( $content ) > MB_IN_BYTES ) { if ( mb_strlen( $content ) > MB_IN_BYTES ) {
return $content; return $content;
} }
$tag_stack = array(); $tag_stack = array();
$protected_tags = array( $protected_tags = array(
'pre', 'pre',
'code', 'code',
'textarea', 'textarea',
@ -1111,7 +1121,7 @@ function enrich_content_data( $content, $regex, $regex_callback ) {
'a', 'a',
); );
$content_with_links = ''; $content_with_links = '';
$in_protected_tag = false; $in_protected_tag = false;
foreach ( wp_html_split( $content ) as $chunk ) { foreach ( wp_html_split( $content ) as $chunk ) {
if ( preg_match( '#^<!--[\s\S]*-->$#i', $chunk, $m ) ) { if ( preg_match( '#^<!--[\s\S]*-->$#i', $chunk, $m ) ) {
$content_with_links .= $chunk; $content_with_links .= $chunk;
@ -1210,7 +1220,8 @@ function generate_post_summary( $post, $length = 500 ) {
$content = $content[0] . ' ' . $excerpt_more; $content = $content[0] . ' ' . $excerpt_more;
} }
/* Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629 /*
Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
return \apply_filters( 'the_excerpt', $content ); return \apply_filters( 'the_excerpt', $content );
*/ */
return $content; return $content;

View file

@ -70,7 +70,7 @@ class Create {
* @param bool $valid The validation state * @param bool $valid The validation state
* @param string $param The object parameter * @param string $param The object parameter
* @param \WP_REST_Request $request The request object * @param \WP_REST_Request $request The request object
* @param array $array The activity-object * @param array $array The activity-object
* *
* @return bool The validation state: true if valid, false if not * @return bool The validation state: true if valid, false if not
*/ */

View file

@ -40,7 +40,7 @@ class Undo {
// Handle "Unfollow" requests // Handle "Unfollow" requests
if ( 'Follow' === $type ) { if ( 'Follow' === $type ) {
$user_id = object_to_uri( $activity['object']['object'] ); $user_id = object_to_uri( $activity['object']['object'] );
$user = Users::get_by_resource( $user_id ); $user = Users::get_by_resource( $user_id );
if ( ! $user || is_wp_error( $user ) ) { if ( ! $user || is_wp_error( $user ) ) {
// If we can not find a user, // If we can not find a user,

View file

@ -23,8 +23,8 @@ class Update {
/** /**
* Handle "Update" requests * Handle "Update" requests
* *
* @param array $array The activity-object * @param array $array The activity-object
* @param int $user_id The id of the local blog-user * @param int $user_id The id of the local blog-user
*/ */
public static function handle_update( $array ) { public static function handle_update( $array ) {
$object_type = isset( $array['object']['type'] ) ? $array['object']['type'] : ''; $object_type = isset( $array['object']['type'] ) ? $array['object']['type'] : '';

View file

@ -81,7 +81,7 @@ class Application extends Actor {
return $this->get_name(); return $this->get_name();
} }
/** /**
* Get the User-Icon. * Get the User-Icon.
* *
* @return array The User-Icon. * @return array The User-Icon.
@ -178,8 +178,8 @@ class Application extends Actor {
public function get_public_key() { public function get_public_key() {
return array( return array(
'id' => $this->get_id() . '#main-key', 'id' => $this->get_id() . '#main-key',
'owner' => $this->get_id(), 'owner' => $this->get_id(),
'publicKeyPem' => Signature::get_public_key_for( Users::APPLICATION_USER_ID ), 'publicKeyPem' => Signature::get_public_key_for( Users::APPLICATION_USER_ID ),
); );
} }

View file

@ -301,8 +301,8 @@ class Blog extends Actor {
public function get_public_key() { public function get_public_key() {
return array( return array(
'id' => $this->get_id() . '#main-key', 'id' => $this->get_id() . '#main-key',
'owner' => $this->get_id(), 'owner' => $this->get_id(),
'publicKeyPem' => Signature::get_public_key_for( $this->get__id() ), 'publicKeyPem' => Signature::get_public_key_for( $this->get__id() ),
); );
} }
@ -400,21 +400,21 @@ class Blog extends Actor {
} }
/** /**
* Update the User-Description. * Update the User-Description.
* *
* @param mixed $value The new value. * @param mixed $value The new value.
* @return bool True if the attribute was updated, false otherwise. * @return bool True if the attribute was updated, false otherwise.
*/ */
public function update_summary( $value ) { public function update_summary( $value ) {
return \update_option( 'blogdescription', $value ); return \update_option( 'blogdescription', $value );
} }
/** /**
* Update the User-Icon. * Update the User-Icon.
* *
* @param mixed $value The new value. * @param mixed $value The new value.
* @return bool True if the attribute was updated, false otherwise. * @return bool True if the attribute was updated, false otherwise.
*/ */
public function update_icon( $value ) { public function update_icon( $value ) {
if ( ! wp_attachment_is_image( $value ) ) { if ( ! wp_attachment_is_image( $value ) ) {
return false; return false;
@ -423,11 +423,11 @@ class Blog extends Actor {
} }
/** /**
* Update the User-Header-Image. * Update the User-Header-Image.
* *
* @param mixed $value The new value. * @param mixed $value The new value.
* @return bool True if the attribute was updated, false otherwise. * @return bool True if the attribute was updated, false otherwise.
*/ */
public function update_header( $value ) { public function update_header( $value ) {
if ( ! wp_attachment_is_image( $value ) ) { if ( ! wp_attachment_is_image( $value ) ) {
return false; return false;

View file

@ -184,7 +184,7 @@ class Follower extends Actor {
$args['post_date_gmt'] = $post->post_date_gmt; $args['post_date_gmt'] = $post->post_date_gmt;
} }
$post_id = wp_insert_post( $args ); $post_id = wp_insert_post( $args );
$this->_id = $post_id; $this->_id = $post_id;
return $post_id; return $post_id;
@ -205,6 +205,7 @@ class Follower extends Actor {
* Beware that this os deleting a Follower for ALL users!!! * Beware that this os deleting a Follower for ALL users!!!
* *
* To delete only the User connection (unfollow) * To delete only the User connection (unfollow)
*
* @see \Activitypub\Rest\Followers::remove_follower() * @see \Activitypub\Rest\Followers::remove_follower()
* *
* @return void * @return void
@ -219,8 +220,8 @@ class Follower extends Actor {
* @return void * @return void
*/ */
protected function get_post_meta_input() { protected function get_post_meta_input() {
$meta_input = array(); $meta_input = array();
$meta_input['activitypub_inbox'] = $this->get_shared_inbox(); $meta_input['activitypub_inbox'] = $this->get_shared_inbox();
$meta_input['activitypub_actor_json'] = $this->to_json(); $meta_input['activitypub_actor_json'] = $this->to_json();
return $meta_input; return $meta_input;
@ -239,9 +240,9 @@ class Follower extends Actor {
} }
return array( return array(
'type' => 'Image', 'type' => 'Image',
'mediaType' => 'image/jpeg', 'mediaType' => 'image/jpeg',
'url' => ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg', 'url' => ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg',
); );
} }
@ -339,7 +340,7 @@ class Follower extends Actor {
*/ */
public static function init_from_cpt( $post ) { public static function init_from_cpt( $post ) {
$actor_json = get_post_meta( $post->ID, 'activitypub_actor_json', true ); $actor_json = get_post_meta( $post->ID, 'activitypub_actor_json', true );
$object = self::init_from_json( $actor_json ); $object = self::init_from_json( $actor_json );
$object->set__id( $post->ID ); $object->set__id( $post->ID );
$object->set_id( $post->guid ); $object->set_id( $post->guid );
$object->set_name( $post->post_title ); $object->set_name( $post->post_title );

View file

@ -76,7 +76,7 @@ class User extends Actor {
); );
} }
$object = new static(); $object = new static();
$object->_id = $user_id; $object->_id = $user_id;
return $object; return $object;
@ -185,8 +185,8 @@ class User extends Actor {
public function get_public_key() { public function get_public_key() {
return array( return array(
'id' => $this->get_id() . '#main-key', 'id' => $this->get_id() . '#main-key',
'owner' => $this->get_id(), 'owner' => $this->get_id(),
'publicKeyPem' => Signature::get_public_key_for( $this->get__id() ), 'publicKeyPem' => Signature::get_public_key_for( $this->get__id() ),
); );
} }
@ -295,7 +295,10 @@ class User extends Actor {
* @return bool True if the attribute was updated, false otherwise. * @return bool True if the attribute was updated, false otherwise.
*/ */
public function update_name( $value ) { public function update_name( $value ) {
$userdata = [ 'ID' => $this->_id, 'display_name' => $value ]; $userdata = array(
'ID' => $this->_id,
'display_name' => $value,
);
return \wp_update_user( $userdata ); return \wp_update_user( $userdata );
} }

View file

@ -65,7 +65,7 @@ class Actors {
/** /**
* Handle GET request * Handle GET request
* *
* @param WP_REST_Request $request * @param WP_REST_Request $request
* *
* @return WP_REST_Response * @return WP_REST_Response
*/ */
@ -127,7 +127,10 @@ class Actors {
$url = str_replace( '{uri}', $resource, $template ); $url = str_replace( '{uri}', $resource, $template );
return new WP_REST_Response( return new WP_REST_Response(
array( 'url' => $url, 'template' => $template ), array(
'url' => $url,
'template' => $template,
),
200 200
); );
} }

View file

@ -84,7 +84,10 @@ class Comment {
$url = str_replace( '{uri}', $resource, $template ); $url = str_replace( '{uri}', $resource, $template );
return new WP_REST_Response( return new WP_REST_Response(
array( 'url' => $url, 'template' => $template ), array(
'url' => $url,
'template' => $template,
),
200 200
); );
} }

View file

@ -47,7 +47,7 @@ class Followers {
/** /**
* Handle GET request * Handle GET request
* *
* @param WP_REST_Request $request * @param WP_REST_Request $request
* *
* @return WP_REST_Response * @return WP_REST_Response
*/ */
@ -74,10 +74,10 @@ class Followers {
$json->{'@context'} = \Activitypub\get_context(); $json->{'@context'} = \Activitypub\get_context();
$json->id = get_rest_url_by_path( sprintf( 'actors/%d/followers', $user->get__id() ) ); $json->id = get_rest_url_by_path( sprintf( 'actors/%d/followers', $user->get__id() ) );
$json->generator = 'http://wordpress.org/?v=' . get_masked_wp_version(); $json->generator = 'http://wordpress.org/?v=' . get_masked_wp_version();
$json->actor = $user->get_id(); $json->actor = $user->get_id();
$json->type = 'OrderedCollectionPage'; $json->type = 'OrderedCollectionPage';
$json->totalItems = $data['total']; // phpcs:ignore $json->totalItems = $data['total']; // phpcs:ignore
$json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/followers', $user->get__id() ) ); // phpcs:ignore $json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/followers', $user->get__id() ) ); // phpcs:ignore
@ -119,12 +119,12 @@ class Followers {
$params = array(); $params = array();
$params['page'] = array( $params['page'] = array(
'type' => 'integer', 'type' => 'integer',
'default' => 1, 'default' => 1,
); );
$params['per_page'] = array( $params['per_page'] = array(
'type' => 'integer', 'type' => 'integer',
'default' => 20, 'default' => 20,
); );
@ -136,13 +136,13 @@ class Followers {
$params['user_id'] = array( $params['user_id'] = array(
'required' => true, 'required' => true,
'type' => 'string', 'type' => 'string',
); );
$params['context'] = array( $params['context'] = array(
'type' => 'string', 'type' => 'string',
'default' => 'simple', 'default' => 'simple',
'enum' => array( 'simple', 'full' ), 'enum' => array( 'simple', 'full' ),
); );
return $params; return $params;

View file

@ -46,7 +46,7 @@ class Following {
/** /**
* Handle GET request * Handle GET request
* *
* @param WP_REST_Request $request * @param WP_REST_Request $request
* *
* @return WP_REST_Response * @return WP_REST_Response
*/ */
@ -67,10 +67,10 @@ class Following {
$json->{'@context'} = \Activitypub\get_context(); $json->{'@context'} = \Activitypub\get_context();
$json->id = get_rest_url_by_path( sprintf( 'actors/%d/following', $user->get__id() ) ); $json->id = get_rest_url_by_path( sprintf( 'actors/%d/following', $user->get__id() ) );
$json->generator = 'http://wordpress.org/?v=' . get_masked_wp_version(); $json->generator = 'http://wordpress.org/?v=' . get_masked_wp_version();
$json->actor = $user->get_id(); $json->actor = $user->get_id();
$json->type = 'OrderedCollectionPage'; $json->type = 'OrderedCollectionPage';
$json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/following', $user->get__id() ) ); // phpcs:ignore $json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/following', $user->get__id() ) ); // phpcs:ignore
@ -101,7 +101,7 @@ class Following {
$params['user_id'] = array( $params['user_id'] = array(
'required' => true, 'required' => true,
'type' => 'string', 'type' => 'string',
); );
return $params; return $params;

View file

@ -69,7 +69,7 @@ class Inbox {
/** /**
* Renders the user-inbox * Renders the user-inbox
* *
* @param WP_REST_Request $request * @param WP_REST_Request $request
* @return WP_REST_Response * @return WP_REST_Response
*/ */
public static function user_inbox_get( $request ) { public static function user_inbox_get( $request ) {
@ -90,9 +90,9 @@ class Inbox {
$json = new \stdClass(); $json = new \stdClass();
$json->{'@context'} = get_context(); $json->{'@context'} = get_context();
$json->id = get_rest_url_by_path( sprintf( 'actors/%d/inbox', $user->get__id() ) ); $json->id = get_rest_url_by_path( sprintf( 'actors/%d/inbox', $user->get__id() ) );
$json->generator = 'http://wordpress.org/?v=' . get_masked_wp_version(); $json->generator = 'http://wordpress.org/?v=' . get_masked_wp_version();
$json->type = 'OrderedCollectionPage'; $json->type = 'OrderedCollectionPage';
$json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/inbox', $user->get__id() ) ); // phpcs:ignore $json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/inbox', $user->get__id() ) ); // phpcs:ignore
$json->totalItems = 0; // phpcs:ignore $json->totalItems = 0; // phpcs:ignore
$json->orderedItems = array(); // phpcs:ignore $json->orderedItems = array(); // phpcs:ignore
@ -115,7 +115,7 @@ class Inbox {
/** /**
* Handles user-inbox requests * Handles user-inbox requests
* *
* @param WP_REST_Request $request * @param WP_REST_Request $request
* *
* @return WP_REST_Response * @return WP_REST_Response
*/ */
@ -144,7 +144,7 @@ class Inbox {
/** /**
* The shared inbox * The shared inbox
* *
* @param WP_REST_Request $request * @param WP_REST_Request $request
* *
* @return WP_REST_Response * @return WP_REST_Response
*/ */
@ -177,7 +177,7 @@ class Inbox {
$params['user_id'] = array( $params['user_id'] = array(
'required' => true, 'required' => true,
'type' => 'string', 'type' => 'string',
); );
return $params; return $params;
@ -193,16 +193,16 @@ class Inbox {
$params['user_id'] = array( $params['user_id'] = array(
'required' => true, 'required' => true,
'type' => 'string', 'type' => 'string',
); );
$params['id'] = array( $params['id'] = array(
'required' => true, 'required' => true,
'sanitize_callback' => 'esc_url_raw', 'sanitize_callback' => 'esc_url_raw',
); );
$params['actor'] = array( $params['actor'] = array(
'required' => true, 'required' => true,
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
'sanitize_callback' => function ( $param, $request, $key ) { 'sanitize_callback' => function ( $param, $request, $key ) {
return object_to_uri( $param ); return object_to_uri( $param );
@ -214,7 +214,7 @@ class Inbox {
); );
$params['object'] = array( $params['object'] = array(
'required' => true, 'required' => true,
'validate_callback' => function ( $param, $request, $key ) { 'validate_callback' => function ( $param, $request, $key ) {
return apply_filters( 'activitypub_validate_object', true, $param, $request, $key ); return apply_filters( 'activitypub_validate_object', true, $param, $request, $key );
}, },
@ -232,7 +232,7 @@ class Inbox {
$params = self::user_inbox_post_parameters(); $params = self::user_inbox_post_parameters();
$params['to'] = array( $params['to'] = array(
'required' => false, 'required' => false,
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
'sanitize_callback' => function ( $param, $request, $key ) { 'sanitize_callback' => function ( $param, $request, $key ) {
if ( \is_string( $param ) ) { if ( \is_string( $param ) ) {
@ -277,7 +277,7 @@ class Inbox {
*/ */
public static function get_recipients( $data ) { public static function get_recipients( $data ) {
$recipients = extract_recipients_from_activity( $data ); $recipients = extract_recipients_from_activity( $data );
$users = array(); $users = array();
foreach ( $recipients as $recipient ) { foreach ( $recipients as $recipient ) {
$user_id = url_to_authorid( $recipient ); $user_id = url_to_authorid( $recipient );

View file

@ -67,7 +67,7 @@ class Nodeinfo {
/** /**
* Render NodeInfo file * Render NodeInfo file
* *
* @param WP_REST_Request $request * @param WP_REST_Request $request
* *
* @return WP_REST_Response * @return WP_REST_Response
*/ */
@ -79,37 +79,37 @@ class Nodeinfo {
$nodeinfo = array(); $nodeinfo = array();
$nodeinfo['version'] = '2.0'; $nodeinfo['version'] = '2.0';
$nodeinfo['software'] = array( $nodeinfo['software'] = array(
'name' => 'wordpress', 'name' => 'wordpress',
'version' => get_masked_wp_version(), 'version' => get_masked_wp_version(),
); );
$posts = \wp_count_posts(); $posts = \wp_count_posts();
$comments = \wp_count_comments(); $comments = \wp_count_comments();
$nodeinfo['usage'] = array( $nodeinfo['usage'] = array(
'users' => array( 'users' => array(
'total' => get_total_users(), 'total' => get_total_users(),
'activeMonth' => get_active_users( '1 month ago' ), 'activeMonth' => get_active_users( '1 month ago' ),
'activeHalfyear' => get_active_users( '6 month ago' ), 'activeHalfyear' => get_active_users( '6 month ago' ),
), ),
'localPosts' => (int) $posts->publish, 'localPosts' => (int) $posts->publish,
'localComments' => (int) $comments->approved, 'localComments' => (int) $comments->approved,
); );
$nodeinfo['openRegistrations'] = false; $nodeinfo['openRegistrations'] = false;
$nodeinfo['protocols'] = array( 'activitypub' ); $nodeinfo['protocols'] = array( 'activitypub' );
$nodeinfo['services'] = array( $nodeinfo['services'] = array(
'inbound' => array(), 'inbound' => array(),
'outbound' => array(), 'outbound' => array(),
); );
$nodeinfo['metadata'] = array( $nodeinfo['metadata'] = array(
'nodeName' => \get_bloginfo( 'name' ), 'nodeName' => \get_bloginfo( 'name' ),
'nodeDescription' => \get_bloginfo( 'description' ), 'nodeDescription' => \get_bloginfo( 'description' ),
'nodeIcon' => \get_site_icon_url(), 'nodeIcon' => \get_site_icon_url(),
); );
return new WP_REST_Response( $nodeinfo, 200 ); return new WP_REST_Response( $nodeinfo, 200 );
@ -118,7 +118,7 @@ class Nodeinfo {
/** /**
* Render NodeInfo file * Render NodeInfo file
* *
* @param WP_REST_Request $request * @param WP_REST_Request $request
* *
* @return WP_REST_Response * @return WP_REST_Response
*/ */
@ -131,31 +131,31 @@ class Nodeinfo {
$nodeinfo = array(); $nodeinfo = array();
$nodeinfo['version'] = '2.0'; $nodeinfo['version'] = '2.0';
$nodeinfo['server'] = array( $nodeinfo['server'] = array(
'baseUrl' => \home_url( '/' ), 'baseUrl' => \home_url( '/' ),
'name' => \get_bloginfo( 'name' ), 'name' => \get_bloginfo( 'name' ),
'software' => 'wordpress', 'software' => 'wordpress',
'version' => get_masked_wp_version(), 'version' => get_masked_wp_version(),
); );
$posts = \wp_count_posts(); $posts = \wp_count_posts();
$comments = \wp_count_comments(); $comments = \wp_count_comments();
$nodeinfo['usage'] = array( $nodeinfo['usage'] = array(
'users' => array( 'users' => array(
'total' => get_total_users(), 'total' => get_total_users(),
'activeMonth' => get_active_users( 1 ), 'activeMonth' => get_active_users( 1 ),
'activeHalfyear' => get_active_users( 6 ), 'activeHalfyear' => get_active_users( 6 ),
), ),
'localPosts' => (int) $posts->publish, 'localPosts' => (int) $posts->publish,
'localComments' => (int) $comments->approved, 'localComments' => (int) $comments->approved,
); );
$nodeinfo['openRegistrations'] = false; $nodeinfo['openRegistrations'] = false;
$nodeinfo['protocols'] = array( 'activitypub' ); $nodeinfo['protocols'] = array( 'activitypub' );
$nodeinfo['services'] = array( $nodeinfo['services'] = array(
'inbound' => array(), 'inbound' => array(),
'outbound' => array(), 'outbound' => array(),
); );
@ -165,19 +165,19 @@ class Nodeinfo {
/** /**
* Render NodeInfo discovery file * Render NodeInfo discovery file
* *
* @param WP_REST_Request $request * @param WP_REST_Request $request
* *
* @return WP_REST_Response * @return WP_REST_Response
*/ */
public static function discovery( $request ) { public static function discovery( $request ) {
$discovery = array(); $discovery = array();
$discovery['links'] = array( $discovery['links'] = array(
array( array(
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0', 'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
'href' => get_rest_url_by_path( 'nodeinfo' ), 'href' => get_rest_url_by_path( 'nodeinfo' ),
), ),
array( array(
'rel' => 'https://www.w3.org/ns/activitystreams#Application', 'rel' => 'https://www.w3.org/ns/activitystreams#Application',
'href' => get_rest_url_by_path( 'application' ), 'href' => get_rest_url_by_path( 'application' ),
), ),
); );

View file

@ -49,7 +49,7 @@ class Outbox {
/** /**
* Renders the user-outbox * Renders the user-outbox
* *
* @param WP_REST_Request $request * @param WP_REST_Request $request
* @return WP_REST_Response * @return WP_REST_Response
*/ */
public static function user_outbox_get( $request ) { public static function user_outbox_get( $request ) {
@ -72,19 +72,19 @@ class Outbox {
$json = new stdClass(); $json = new stdClass();
$json->{'@context'} = get_context(); $json->{'@context'} = get_context();
$json->id = get_rest_url_by_path( sprintf( 'actors/%d/outbox', $user_id ) ); $json->id = get_rest_url_by_path( sprintf( 'actors/%d/outbox', $user_id ) );
$json->generator = 'http://wordpress.org/?v=' . get_masked_wp_version(); $json->generator = 'http://wordpress.org/?v=' . get_masked_wp_version();
$json->actor = $user->get_id(); $json->actor = $user->get_id();
$json->type = 'OrderedCollectionPage'; $json->type = 'OrderedCollectionPage';
$json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/outbox', $user_id ) ); // phpcs:ignore $json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/outbox', $user_id ) ); // phpcs:ignore
$json->totalItems = 0; // phpcs:ignore $json->totalItems = 0; // phpcs:ignore
if ( $user_id > 0 ) { if ( $user_id > 0 ) {
$count_posts = \count_user_posts( $user_id, $post_types, true ); $count_posts = \count_user_posts( $user_id, $post_types, true );
$json->totalItems = \intval( $count_posts ); // phpcs:ignore $json->totalItems = \intval( $count_posts ); // phpcs:ignore
} else { } else {
foreach ( $post_types as $post_type ) { foreach ( $post_types as $post_type ) {
$count_posts = \wp_count_posts( $post_type ); $count_posts = \wp_count_posts( $post_type );
$json->totalItems += \intval( $count_posts->publish ); // phpcs:ignore $json->totalItems += \intval( $count_posts->publish ); // phpcs:ignore
} }
} }
@ -148,13 +148,13 @@ class Outbox {
$params = array(); $params = array();
$params['page'] = array( $params['page'] = array(
'type' => 'integer', 'type' => 'integer',
'default' => 1, 'default' => 1,
); );
$params['user_id'] = array( $params['user_id'] = array(
'required' => true, 'required' => true,
'type' => 'string', 'type' => 'string',
); );
return $params; return $params;

View file

@ -73,7 +73,7 @@ class Webfinger {
$code, $code,
array( array(
'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Origin' => '*',
'Content-Type' => 'application/jrd+json; charset=' . get_option( 'blog_charset' ), 'Content-Type' => 'application/jrd+json; charset=' . get_option( 'blog_charset' ),
) )
); );
} }
@ -88,8 +88,8 @@ class Webfinger {
$params['resource'] = array( $params['resource'] = array(
'required' => true, 'required' => true,
'type' => 'string', 'type' => 'string',
'pattern' => '^(acct:)|^(https?://)(.+)$', 'pattern' => '^(acct:)|^(https?://)(.+)$',
); );
return $params; return $params;

View file

@ -191,7 +191,7 @@ class Comment extends Base {
$mentions = $this->get_mentions(); $mentions = $this->get_mentions();
if ( $mentions ) { if ( $mentions ) {
foreach ( $mentions as $mention => $url ) { foreach ( $mentions as $mention => $url ) {
$tag = array( $tag = array(
'type' => 'Mention', 'type' => 'Mention',
'href' => \esc_url( $url ), 'href' => \esc_url( $url ),
'name' => \esc_html( $mention ), 'name' => \esc_html( $mention ),
@ -255,7 +255,7 @@ class Comment extends Base {
if ( $comment && ! empty( $comment->comment_author_url ) ) { if ( $comment && ! empty( $comment->comment_author_url ) ) {
$acct = Webfinger::uri_to_acct( $comment->comment_author_url ); $acct = Webfinger::uri_to_acct( $comment->comment_author_url );
if ( $acct && ! is_wp_error( $acct ) ) { if ( $acct && ! is_wp_error( $acct ) ) {
$acct = str_replace( 'acct:', '@', $acct ); $acct = str_replace( 'acct:', '@', $acct );
$mentions[ $acct ] = $comment->comment_author_url; $mentions[ $acct ] = $comment->comment_author_url;
} }
} }

View file

@ -62,7 +62,7 @@ class Post extends Base {
* @return \Activitypub\Activity\Base_Object The ActivityPub Object * @return \Activitypub\Activity\Base_Object The ActivityPub Object
*/ */
public function to_object() { public function to_object() {
$post = $this->wp_object; $post = $this->wp_object;
$object = parent::to_object(); $object = parent::to_object();
$published = \strtotime( $post->post_date_gmt ); $published = \strtotime( $post->post_date_gmt );
@ -109,7 +109,7 @@ class Post extends Base {
return $this->actor_object; return $this->actor_object;
} }
$blog_user = new Blog(); $blog_user = new Blog();
$this->actor_object = $blog_user; $this->actor_object = $blog_user;
if ( is_single_user() ) { if ( is_single_user() ) {
@ -299,16 +299,17 @@ class Post extends Base {
} }
$blocks = \parse_blocks( $this->wp_object->post_content ); $blocks = \parse_blocks( $this->wp_object->post_content );
$media = self::get_media_from_blocks( $blocks, $media ); $media = self::get_media_from_blocks( $blocks, $media );
return $media; return $media;
} }
/** /**
* Recursively get media IDs from blocks. * Recursively get media IDs from blocks.
*
* @param array $blocks The blocks to search for media IDs * @param array $blocks The blocks to search for media IDs
* @param array $media The media IDs to append new IDs to * @param array $media The media IDs to append new IDs to
* @param int $max_media The maximum number of media to return. * @param int $max_media The maximum number of media to return.
* *
* @return array The image IDs. * @return array The image IDs.
*/ */
@ -443,14 +444,14 @@ class Post extends Base {
if ( 0 === $img_id ) { if ( 0 === $img_id ) {
$count = 0; $count = 0;
$src = preg_replace( '/-(?:\d+x\d+)(\.[a-zA-Z]+)$/', '$1', $src, 1, $count ); $src = preg_replace( '/-(?:\d+x\d+)(\.[a-zA-Z]+)$/', '$1', $src, 1, $count );
if ( $count > 0 ) { if ( $count > 0 ) {
$img_id = \attachment_url_to_postid( $src ); $img_id = \attachment_url_to_postid( $src );
} }
} }
if ( 0 === $img_id ) { if ( 0 === $img_id ) {
$src = preg_replace( '/(\.[a-zA-Z]+)$/', '-scaled$1', $src ); $src = preg_replace( '/(\.[a-zA-Z]+)$/', '-scaled$1', $src );
$img_id = \attachment_url_to_postid( $src ); $img_id = \attachment_url_to_postid( $src );
} }
@ -484,12 +485,12 @@ class Post extends Base {
$images = array(); $images = array();
$query = new \WP_Query( $query = new \WP_Query(
array( array(
'post_parent' => $this->wp_object->ID, 'post_parent' => $this->wp_object->ID,
'post_status' => 'inherit', 'post_status' => 'inherit',
'post_type' => 'attachment', 'post_type' => 'attachment',
'post_mime_type' => 'image', 'post_mime_type' => 'image',
'order' => 'ASC', 'order' => 'ASC',
'orderby' => 'menu_order ID', 'orderby' => 'menu_order ID',
'posts_per_page' => $max_images, 'posts_per_page' => $max_images,
) )
); );
@ -584,10 +585,10 @@ class Post extends Base {
'url' => \esc_url( \wp_get_attachment_url( $id ) ), 'url' => \esc_url( \wp_get_attachment_url( $id ) ),
'name' => \esc_attr( \get_the_title( $id ) ), 'name' => \esc_attr( \get_the_title( $id ) ),
); );
$meta = wp_get_attachment_metadata( $id ); $meta = wp_get_attachment_metadata( $id );
// height and width for videos // height and width for videos
if ( isset( $meta['width'] ) && isset( $meta['height'] ) ) { if ( isset( $meta['width'] ) && isset( $meta['height'] ) ) {
$attachment['width'] = \esc_attr( $meta['width'] ); $attachment['width'] = \esc_attr( $meta['width'] );
$attachment['height'] = \esc_attr( $meta['height'] ); $attachment['height'] = \esc_attr( $meta['height'] );
} }
// @todo: add `icon` support for audio/video attachments. Maybe use post thumbnail? // @todo: add `icon` support for audio/video attachments. Maybe use post thumbnail?
@ -723,7 +724,7 @@ class Post extends Base {
$post_tags = \get_the_tags( $this->wp_object->ID ); $post_tags = \get_the_tags( $this->wp_object->ID );
if ( $post_tags ) { if ( $post_tags ) {
foreach ( $post_tags as $post_tag ) { foreach ( $post_tags as $post_tag ) {
$tag = array( $tag = array(
'type' => 'Hashtag', 'type' => 'Hashtag',
'href' => \esc_url( \get_tag_link( $post_tag->term_id ) ), 'href' => \esc_url( \get_tag_link( $post_tag->term_id ) ),
'name' => esc_hashtag( $post_tag->name ), 'name' => esc_hashtag( $post_tag->name ),
@ -735,7 +736,7 @@ class Post extends Base {
$mentions = $this->get_mentions(); $mentions = $this->get_mentions();
if ( $mentions ) { if ( $mentions ) {
foreach ( $mentions as $mention => $url ) { foreach ( $mentions as $mention => $url ) {
$tag = array( $tag = array(
'type' => 'Mention', 'type' => 'Mention',
'href' => \esc_url( $url ), 'href' => \esc_url( $url ),
'name' => \esc_html( $mention ), 'name' => \esc_html( $mention ),

View file

@ -15,7 +15,7 @@ class Buddypress {
} }
public static function add_user_metadata( $object, $author_id ) { public static function add_user_metadata( $object, $author_id ) {
$object->url = bp_core_get_user_domain( $author_id ); //add BP member profile URL as user URL $object->url = bp_core_get_user_domain( $author_id ); // add BP member profile URL as user URL
// add BuddyPress' cover_image instead of WordPress' header_image // add BuddyPress' cover_image instead of WordPress' header_image
$cover_image_url = bp_attachments_get_attachment( 'url', array( 'item_id' => $author_id ) ); $cover_image_url = bp_attachments_get_attachment( 'url', array( 'item_id' => $author_id ) );
@ -29,8 +29,8 @@ class Buddypress {
// change profile URL to BuddyPress' profile URL // change profile URL to BuddyPress' profile URL
$object->attachment['profile_url'] = array( $object->attachment['profile_url'] = array(
'type' => 'PropertyValue', 'type' => 'PropertyValue',
'name' => \__( 'Profile', 'activitypub' ), 'name' => \__( 'Profile', 'activitypub' ),
'value' => \html_entity_decode( 'value' => \html_entity_decode(
sprintf( sprintf(
'<a rel="me" title="%s" target="_blank" href="%s">%s</a>', '<a rel="me" title="%s" target="_blank" href="%s">%s</a>',
@ -45,7 +45,7 @@ class Buddypress {
// replace blog URL on multisite // replace blog URL on multisite
if ( is_multisite() ) { if ( is_multisite() ) {
$user_blogs = get_blogs_of_user( $author_id ); //get sites of user to send as AP metadata $user_blogs = get_blogs_of_user( $author_id ); // get sites of user to send as AP metadata
if ( ! empty( $user_blogs ) ) { if ( ! empty( $user_blogs ) ) {
unset( $object->attachment['blog_url'] ); unset( $object->attachment['blog_url'] );
@ -53,8 +53,8 @@ class Buddypress {
foreach ( $user_blogs as $blog ) { foreach ( $user_blogs as $blog ) {
if ( 1 !== $blog->userblog_id ) { if ( 1 !== $blog->userblog_id ) {
$object->attachment[] = array( $object->attachment[] = array(
'type' => 'PropertyValue', 'type' => 'PropertyValue',
'name' => $blog->blogname, 'name' => $blog->blogname,
'value' => \html_entity_decode( 'value' => \html_entity_decode(
sprintf( sprintf(
'<a rel="me" title="%s" target="_blank" href="%s">%s</a>', '<a rel="me" title="%s" target="_blank" href="%s">%s</a>',

View file

@ -117,8 +117,8 @@ class Enable_Mastodon_Apps {
foreach ( $fields as $field ) { foreach ( $fields as $field ) {
$ret[] = array( $ret[] = array(
'name' => $field->post_title, 'name' => $field->post_title,
'value' => Extra_Fields::get_formatted_content( $field ), 'value' => Extra_Fields::get_formatted_content( $field ),
); );
} }
@ -190,29 +190,29 @@ class Enable_Mastodon_Apps {
$acct = $item->get_url(); $acct = $item->get_url();
} }
$account = new Account(); $account = new Account();
$account->id = \strval( $item->get__id() ); $account->id = \strval( $item->get__id() );
$account->username = $item->get_preferred_username(); $account->username = $item->get_preferred_username();
$account->acct = $acct; $account->acct = $acct;
$account->display_name = $item->get_name(); $account->display_name = $item->get_name();
$account->url = $item->get_url(); $account->url = $item->get_url();
$account->avatar = $item->get_icon_url(); $account->avatar = $item->get_icon_url();
$account->avatar_static = $item->get_icon_url(); $account->avatar_static = $item->get_icon_url();
$account->created_at = new DateTime( $item->get_published() ); $account->created_at = new DateTime( $item->get_published() );
$account->last_status_at = new DateTime( $item->get_published() ); $account->last_status_at = new DateTime( $item->get_published() );
$account->note = $item->get_summary(); $account->note = $item->get_summary();
$account->header = $item->get_image_url(); $account->header = $item->get_image_url();
$account->header_static = $item->get_image_url(); $account->header_static = $item->get_image_url();
$account->followers_count = 0; $account->followers_count = 0;
$account->following_count = 0; $account->following_count = 0;
$account->statuses_count = 0; $account->statuses_count = 0;
$account->bot = false; $account->bot = false;
$account->locked = false; $account->locked = false;
$account->group = false; $account->group = false;
$account->discoverable = false; $account->discoverable = false;
$account->noindex = false; $account->noindex = false;
$account->fields = array(); $account->fields = array();
$account->emojis = array(); $account->emojis = array();
return $account; return $account;
}, },
@ -260,7 +260,7 @@ class Enable_Mastodon_Apps {
public static function api_account_internal( $user_data, $user_id ) { public static function api_account_internal( $user_data, $user_id ) {
$user_id_to_use = self::maybe_map_user_to_blog( $user_id ); $user_id_to_use = self::maybe_map_user_to_blog( $user_id );
$user = Users::get_by_id( $user_id_to_use ); $user = Users::get_by_id( $user_id_to_use );
if ( ! $user || is_wp_error( $user ) ) { if ( ! $user || is_wp_error( $user ) ) {
return $user_data; return $user_data;
@ -269,21 +269,21 @@ class Enable_Mastodon_Apps {
// convert user to account. // convert user to account.
$account = new Account(); $account = new Account();
// even if we have a blog user, maintain the provided user_id so as not to confuse clients // even if we have a blog user, maintain the provided user_id so as not to confuse clients
$account->id = (int) $user_id; $account->id = (int) $user_id;
$account->username = $user->get_preferred_username(); $account->username = $user->get_preferred_username();
$account->acct = $account->username; $account->acct = $account->username;
$account->display_name = $user->get_name(); $account->display_name = $user->get_name();
$account->note = $user->get_summary(); $account->note = $user->get_summary();
$account->source['note'] = wp_strip_all_tags( $account->note, true ); $account->source['note'] = wp_strip_all_tags( $account->note, true );
$account->url = $user->get_url(); $account->url = $user->get_url();
$icon = $user->get_icon(); $icon = $user->get_icon();
$account->avatar = $icon['url']; $account->avatar = $icon['url'];
$account->avatar_static = $account->avatar; $account->avatar_static = $account->avatar;
$header = $user->get_image(); $header = $user->get_image();
if ( $header ) { if ( $header ) {
$account->header = $header['url']; $account->header = $header['url'];
$account->header_static = $account->header; $account->header_static = $account->header;
} }
@ -291,13 +291,13 @@ class Enable_Mastodon_Apps {
$post_types = \get_option( 'activitypub_support_post_types', array( 'post' ) ); $post_types = \get_option( 'activitypub_support_post_types', array( 'post' ) );
$query_args = array( $query_args = array(
'post_type' => $post_types, 'post_type' => $post_types,
'posts_per_page' => 1, 'posts_per_page' => 1,
); );
if ( $user_id > 0 ) { if ( $user_id > 0 ) {
$query_args['author'] = $user_id; $query_args['author'] = $user_id;
} }
$posts = \get_posts( $query_args ); $posts = \get_posts( $query_args );
$account->last_status_at = ! empty( $posts ) ? new DateTime( $posts[0]->post_date_gmt ) : $account->created_at; $account->last_status_at = ! empty( $posts ) ? new DateTime( $posts[0]->post_date_gmt ) : $account->created_at;
$account->fields = self::get_extra_fields( $user_id_to_use ); $account->fields = self::get_extra_fields( $user_id_to_use );
@ -331,11 +331,11 @@ class Enable_Mastodon_Apps {
$acct = substr( $acct, 5 ); $acct = substr( $acct, 5 );
} }
$account->id = $acct; $account->id = $acct;
$account->username = $acct; $account->username = $acct;
$account->acct = $acct; $account->acct = $acct;
$account->display_name = $data['name']; $account->display_name = $data['name'];
$account->url = $uri; $account->url = $uri;
if ( ! empty( $data['summary'] ) ) { if ( ! empty( $data['summary'] ) ) {
$account->note = $data['summary']; $account->note = $data['summary'];
@ -412,20 +412,20 @@ class Enable_Mastodon_Apps {
$acct = $follower->get_url(); $acct = $follower->get_url();
} }
$account = new Account(); $account = new Account();
$account->id = \strval( $follower->get__id() ); $account->id = \strval( $follower->get__id() );
$account->username = $follower->get_preferred_username(); $account->username = $follower->get_preferred_username();
$account->acct = $acct; $account->acct = $acct;
$account->display_name = $follower->get_name(); $account->display_name = $follower->get_name();
$account->url = $follower->get_url(); $account->url = $follower->get_url();
$account->uri = $follower->get_id(); $account->uri = $follower->get_id();
$account->avatar = $follower->get_icon_url(); $account->avatar = $follower->get_icon_url();
$account->avatar_static = $follower->get_icon_url(); $account->avatar_static = $follower->get_icon_url();
$account->created_at = new DateTime( $follower->get_published() ); $account->created_at = new DateTime( $follower->get_published() );
$account->last_status_at = new DateTime( $follower->get_published() ); $account->last_status_at = new DateTime( $follower->get_published() );
$account->note = $follower->get_summary(); $account->note = $follower->get_summary();
$account->header = $follower->get_image_url(); $account->header = $follower->get_image_url();
$account->header_static = $follower->get_image_url(); $account->header_static = $follower->get_image_url();
$search_data['accounts'][] = $account; $search_data['accounts'][] = $account;
} }
@ -456,7 +456,7 @@ class Enable_Mastodon_Apps {
return null; return null;
} }
$status = new Status(); $status = new Status();
$status->id = $object['id']; $status->id = $object['id'];
$status->created_at = new DateTime( $object['published'] ); $status->created_at = new DateTime( $object['published'] );
$status->content = $object['content']; $status->content = $object['content'];
@ -480,20 +480,20 @@ class Enable_Mastodon_Apps {
$status->media_attachments = array_map( $status->media_attachments = array_map(
function ( $attachment ) { function ( $attachment ) {
$default_attachment = array( $default_attachment = array(
'url' => null, 'url' => null,
'mediaType' => null, 'mediaType' => null,
'name' => null, 'name' => null,
'width' => 0, 'width' => 0,
'height' => 0, 'height' => 0,
'blurhash' => null, 'blurhash' => null,
); );
$attachment = array_merge( $default_attachment, $attachment ); $attachment = array_merge( $default_attachment, $attachment );
$media_attachment = new Media_Attachment(); $media_attachment = new Media_Attachment();
$media_attachment->id = $attachment['url']; $media_attachment->id = $attachment['url'];
$media_attachment->type = strtok( $attachment['mediaType'], '/' ); $media_attachment->type = strtok( $attachment['mediaType'], '/' );
$media_attachment->url = $attachment['url']; $media_attachment->url = $attachment['url'];
$media_attachment->preview_url = $attachment['url']; $media_attachment->preview_url = $attachment['url'];
$media_attachment->description = $attachment['name']; $media_attachment->description = $attachment['name'];
if ( $attachment['blurhash'] ) { if ( $attachment['blurhash'] ) {
@ -545,8 +545,8 @@ class Enable_Mastodon_Apps {
$limit = 40; $limit = 40;
} }
$activitypub_statuses = array(); $activitypub_statuses = array();
$url = $outbox['first']; $url = $outbox['first'];
$tries = 0; $tries = 0;
while ( $url ) { while ( $url ) {
if ( ++$tries > 3 ) { if ( ++$tries > 3 ) {
break; break;
@ -557,7 +557,7 @@ class Enable_Mastodon_Apps {
return $statuses; return $statuses;
} }
$new_statuses = array_map( $new_statuses = array_map(
function ( $item ) use ( $account, $args ) { function ( $item ) use ( $account, $args ) {
if ( $args['exclude_replies'] ) { if ( $args['exclude_replies'] ) {
if ( isset( $item['object']['inReplyTo'] ) && $item['object']['inReplyTo'] ) { if ( isset( $item['object']['inReplyTo'] ) && $item['object']['inReplyTo'] ) {
@ -569,7 +569,7 @@ class Enable_Mastodon_Apps {
$posts['orderedItems'] $posts['orderedItems']
); );
$activitypub_statuses = array_merge( $activitypub_statuses, array_filter( $new_statuses ) ); $activitypub_statuses = array_merge( $activitypub_statuses, array_filter( $new_statuses ) );
$url = $posts['next']; $url = $posts['next'];
if ( count( $activitypub_statuses ) >= $limit ) { if ( count( $activitypub_statuses ) >= $limit ) {
break; break;
@ -586,7 +586,7 @@ class Enable_Mastodon_Apps {
} }
$replies_url = $meta['replies']['first']['next']; $replies_url = $meta['replies']['first']['next'];
$replies = Http::get_remote_object( $replies_url, true ); $replies = Http::get_remote_object( $replies_url, true );
if ( is_wp_error( $replies ) || ! isset( $replies['items'] ) ) { if ( is_wp_error( $replies ) || ! isset( $replies['items'] ) ) {
return $context; return $context;
} }
@ -602,7 +602,7 @@ class Enable_Mastodon_Apps {
} }
$account = self::get_account_for_actor( $status['attributedTo'] ); $account = self::get_account_for_actor( $status['attributedTo'] );
$status = self::activity_to_status( $status, $account ); $status = self::activity_to_status( $status, $account );
if ( $status ) { if ( $status ) {
$context['descendants'][ $status->id ] = $status; $context['descendants'][ $status->id ] = $status;
} }

View file

@ -11,11 +11,11 @@ class Jetpack {
if ( ! is_array( $whitelist ) ) { if ( ! is_array( $whitelist ) ) {
return $whitelist; return $whitelist;
} }
$activitypub_meta_keys = [ $activitypub_meta_keys = array(
'activitypub_user_id', 'activitypub_user_id',
'activitypub_inbox', 'activitypub_inbox',
'activitypub_actor_json', 'activitypub_actor_json',
]; );
return \array_merge( $whitelist, $activitypub_meta_keys ); return \array_merge( $whitelist, $activitypub_meta_keys );
} }
} }

View file

@ -25,7 +25,7 @@ class Nodeinfo {
* Extend NodeInfo data * Extend NodeInfo data
* *
* @param array $nodeinfo NodeInfo data * @param array $nodeinfo NodeInfo data
* @param string The NodeInfo Version * @param string $version The NodeInfo Version
* *
* @return array The extended array * @return array The extended array
*/ */
@ -74,7 +74,7 @@ class Nodeinfo {
*/ */
public static function add_wellknown_nodeinfo_data( $data ) { public static function add_wellknown_nodeinfo_data( $data ) {
$data['links'][] = array( $data['links'][] = array(
'rel' => 'https://www.w3.org/ns/activitystreams#Application', 'rel' => 'https://www.w3.org/ns/activitystreams#Application',
'href' => get_rest_url_by_path( 'application' ), 'href' => get_rest_url_by_path( 'application' ),
); );

View file

@ -5,74 +5,39 @@
<file>./includes/</file> <file>./includes/</file>
<file>./integration/</file> <file>./integration/</file>
<file>./build/</file> <file>./build/</file>
<exclude-pattern>*\.(inc|css|js|svg)</exclude-pattern> <exclude-pattern>*\.(inc|css|js|svg)</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern> <exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern> <exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*.asset.php</exclude-pattern> <exclude-pattern>*.asset.php</exclude-pattern>
<arg value="ps"/>
<arg name="basepath" value="."/><!-- Strip the file paths down to the relevant bit -->
<arg name="colors"/>
<arg name="parallel" value="50"/>
<rule ref="PHPCompatibility"/> <rule ref="PHPCompatibility"/>
<config name="testVersion" value="7.0-"/> <config name="testVersion" value="7.0-"/>
<rule ref="PHPCompatibilityWP"/> <rule ref="PHPCompatibilityWP"/>
<config name="minimum_supported_wp_version" value="4.7"/> <config name="minimum_supported_wp_version" value="4.7"/>
<rule ref="WordPress-Core">
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning" />
<exclude name="WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction" />
</rule>
<rule ref="WordPress.Files.FileName">
<properties>
<property name="strict_class_file_names" value="false" />
</properties>
</rule>
<rule ref="WordPress.WP.DeprecatedFunctions" />
<rule ref="WordPress-Extra" />
<rule ref="WordPress.WP.I18n"/>
<config name="text_domain" value="activitypub,default"/> <config name="text_domain" value="activitypub,default"/>
<arg value="ps"/>
<arg name="parallel" value="20"/> <rule ref="WordPress">
<rule ref="VariableAnalysis"/> <exclude name="Generic.Commenting.DocComment.MissingShort"/>
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable"> <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<type>error</type> <exclude name="Generic.Commenting.DocComment.LongNotCapital"/>
<exclude name="Squiz.Commenting"/>
<exclude name="Squiz.PHP.CommentedOutCode.Found"/>
<exclude name="Universal.NamingConventions.NoReservedKeywordParameterNames"/>
<exclude name="WordPress.Security.NonceVerification.Recommended"/>
<exclude name="WordPress.WP.GetMetaSingle.Missing"/>
<exclude name="WordPress.DB.PreparedSQL.NotPrepared"/>
</rule> </rule>
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis"> <rule ref="VariableAnalysis">
<properties> <exclude name="VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable"/>
<property name="allowUnusedCaughtExceptions" value="true"/>
</properties>
</rule>
<rule ref="WordPress"/>
<rule ref="WordPress.WP.I18n.NoHtmlWrappedStrings">
<type>error</type>
</rule>
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<rule ref="Generic.Arrays.DisallowShortArraySyntax">
<severity>0</severity>
</rule>
<rule ref="Universal.Arrays.DisallowShortArraySyntax">
<severity>0</severity>
</rule>
<rule ref="Squiz.Commenting">
<severity>0</severity>
</rule>
<rule ref="Generic.Commenting">
<severity>0</severity>
</rule>
<rule ref="WordPress.Files.FileName">
<severity>0</severity>
</rule>
<rule ref="WordPress.DB.PreparedSQL.NotPrepared">
<severity>0</severity>
</rule>
<rule ref="WordPress.WP.CapitalPDangit">
<severity>0</severity>
</rule>
<rule ref="WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound">
<severity>0</severity>
</rule>
<rule ref="WordPress.PHP.YodaConditions.NotYoda">
<type>warning</type>
</rule>
<rule ref="WordPress.Arrays.ArrayDeclarationSpacing">
<exclude-pattern>**/*.asset.php</exclude-pattern>
</rule> </rule>
<rule ref="WordPress.WP.Capabilities"> <rule ref="WordPress.WP.Capabilities">
<properties> <properties>
<property name="custom_capabilities" type="array"> <property name="custom_capabilities" type="array">