mirror of
https://github.com/Automattic/wordpress-activitypub
synced 2024-10-18 12:23:32 +00:00
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:
parent
f5989f0380
commit
2b5f635ba3
44 changed files with 441 additions and 446 deletions
|
@ -112,7 +112,7 @@ function plugin_init() {
|
|||
|
||||
if ( strncmp( $full_class, $base, strlen( $base ) ) === 0 ) {
|
||||
$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.
|
||||
if ( $maybe_uppercase === $class ) {
|
||||
return;
|
||||
|
@ -144,7 +144,7 @@ function plugin_init() {
|
|||
* Add plugin settings link
|
||||
*/
|
||||
function plugin_settings_link( $actions ) {
|
||||
$settings_link = array();
|
||||
$settings_link = array();
|
||||
$settings_link[] = \sprintf(
|
||||
'<a href="%1s">%2s</a>',
|
||||
\menu_page_url( 'activitypub', false ),
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
"vendor/bin/phpunit"
|
||||
],
|
||||
"lint": [
|
||||
"vendor/bin/phpcs -n -q"
|
||||
"vendor/bin/phpcs"
|
||||
],
|
||||
"lint:fix": [
|
||||
"vendor/bin/phpcbf"
|
||||
|
|
|
@ -22,28 +22,28 @@ class Actor extends Base_Object {
|
|||
'https://w3id.org/security/v1',
|
||||
'https://purl.archive.org/socialweb/webfinger',
|
||||
array(
|
||||
'schema' => 'http://schema.org#',
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'lemmy' => 'https://join-lemmy.org/ns#',
|
||||
'schema' => 'http://schema.org#',
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'lemmy' => 'https://join-lemmy.org/ns#',
|
||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||
'PropertyValue' => 'schema:PropertyValue',
|
||||
'value' => 'schema:value',
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'featured' => array(
|
||||
'@id' => 'toot:featured',
|
||||
'PropertyValue' => 'schema:PropertyValue',
|
||||
'value' => 'schema:value',
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'featured' => array(
|
||||
'@id' => 'toot:featured',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'featuredTags' => array(
|
||||
'@id' => 'toot:featuredTags',
|
||||
'featuredTags' => array(
|
||||
'@id' => 'toot:featuredTags',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'moderators' => array(
|
||||
'@id' => 'lemmy:moderators',
|
||||
'moderators' => array(
|
||||
'@id' => 'lemmy:moderators',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods',
|
||||
'discoverable' => 'toot:discoverable',
|
||||
'indexable' => 'toot:indexable',
|
||||
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods',
|
||||
'discoverable' => 'toot:discoverable',
|
||||
'indexable' => 'toot:indexable',
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ class Event extends Base_Object {
|
|||
|
||||
/**
|
||||
* Mobilizon compatible values for repliesModertaionOption.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const REPLIES_MODERATION_OPTION_TYPES = array( 'allow_all', 'closed' );
|
||||
|
@ -62,6 +63,7 @@ class Event extends Base_Object {
|
|||
|
||||
/**
|
||||
* Allowed values for ical VEVENT STATUS.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const ICAL_EVENT_STATUS_TYPES = array( 'TENTATIVE', 'CONFIRMED', 'CANCELLED' );
|
||||
|
@ -70,6 +72,7 @@ class Event extends Base_Object {
|
|||
* Default event categories.
|
||||
*
|
||||
* These values currently reflect the default set as proposed by Mobilizon to maximize interoperability.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const DEFAULT_EVENT_CATEGORIES = array(
|
||||
|
@ -253,7 +256,7 @@ class Event extends Base_Object {
|
|||
public function set_replies_moderation_option( $type ) {
|
||||
if ( in_array( $type, self::REPLIES_MODERATION_OPTION_TYPES, true ) ) {
|
||||
$this->replies_moderation_option = $type;
|
||||
$this->comments_enabled = ( 'allow_all' === $type ) ? true : false;
|
||||
$this->comments_enabled = ( 'allow_all' === $type ) ? true : false;
|
||||
} else {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
|
@ -272,7 +275,7 @@ class Event extends Base_Object {
|
|||
*/
|
||||
public function set_comments_enabled( $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';
|
||||
} else {
|
||||
_doing_it_wrong(
|
||||
|
@ -332,7 +335,7 @@ class Event extends Base_Object {
|
|||
public function set_external_participation_url( $url ) {
|
||||
if ( preg_match( '/^https?:\/\/.*/i', $url ) ) {
|
||||
$this->external_participation_url = $url;
|
||||
$this->join_mode = 'external';
|
||||
$this->join_mode = 'external';
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
|
@ -508,7 +508,7 @@ class Activitypub {
|
|||
|
||||
// Both User and Blog Extra Fields types have the same args.
|
||||
$args = array(
|
||||
'labels' => array(
|
||||
'labels' => array(
|
||||
'name' => _x( 'Extra fields', 'post_type plural name', 'activitypub' ),
|
||||
'singular_name' => _x( 'Extra field', 'post_type single name', 'activitypub' ),
|
||||
'add_new' => __( 'Add new', 'activitypub' ),
|
||||
|
|
|
@ -193,8 +193,8 @@ class Admin {
|
|||
'activitypub',
|
||||
'activitypub_post_content_type',
|
||||
array(
|
||||
'type' => 'string',
|
||||
'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ),
|
||||
'type' => 'string',
|
||||
'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ),
|
||||
'show_in_rest' => array(
|
||||
'schema' => array(
|
||||
'enum' => array(
|
||||
|
@ -204,34 +204,34 @@ class Admin {
|
|||
),
|
||||
),
|
||||
),
|
||||
'default' => 'content',
|
||||
'default' => 'content',
|
||||
)
|
||||
);
|
||||
\register_setting(
|
||||
'activitypub',
|
||||
'activitypub_custom_post_content',
|
||||
array(
|
||||
'type' => 'string',
|
||||
'description' => \__( 'Define your own custom post template', 'activitypub' ),
|
||||
'type' => 'string',
|
||||
'description' => \__( 'Define your own custom post template', 'activitypub' ),
|
||||
'show_in_rest' => true,
|
||||
'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT,
|
||||
'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT,
|
||||
)
|
||||
);
|
||||
\register_setting(
|
||||
'activitypub',
|
||||
'activitypub_max_image_attachments',
|
||||
array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
'description' => \__( 'Number of images to attach to posts.', 'activitypub' ),
|
||||
'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS,
|
||||
'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS,
|
||||
)
|
||||
);
|
||||
\register_setting(
|
||||
'activitypub',
|
||||
'activitypub_object_type',
|
||||
array(
|
||||
'type' => 'string',
|
||||
'description' => \__( 'The Activity-Object-Type', 'activitypub' ),
|
||||
'type' => 'string',
|
||||
'description' => \__( 'The Activity-Object-Type', 'activitypub' ),
|
||||
'show_in_rest' => array(
|
||||
'schema' => array(
|
||||
'enum' => array(
|
||||
|
@ -240,25 +240,25 @@ class Admin {
|
|||
),
|
||||
),
|
||||
),
|
||||
'default' => 'note',
|
||||
'default' => 'note',
|
||||
)
|
||||
);
|
||||
\register_setting(
|
||||
'activitypub',
|
||||
'activitypub_use_hashtags',
|
||||
array(
|
||||
'type' => 'boolean',
|
||||
'type' => 'boolean',
|
||||
'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
|
||||
'default' => '0',
|
||||
'default' => '0',
|
||||
)
|
||||
);
|
||||
\register_setting(
|
||||
'activitypub',
|
||||
'activitypub_use_opengraph',
|
||||
array(
|
||||
'type' => 'boolean',
|
||||
'type' => 'boolean',
|
||||
'description' => \__( 'Automatically add "fediverse:creator" OpenGraph tags for Authors and the Blog-User.', 'activitypub' ),
|
||||
'default' => '1',
|
||||
'default' => '1',
|
||||
)
|
||||
);
|
||||
\register_setting(
|
||||
|
@ -275,18 +275,18 @@ class Admin {
|
|||
'activitypub',
|
||||
'activitypub_enable_users',
|
||||
array(
|
||||
'type' => 'boolean',
|
||||
'type' => 'boolean',
|
||||
'description' => \__( 'Every Author on this Blog (with the publish_posts capability) gets his own ActivityPub enabled Profile.', 'activitypub' ),
|
||||
'default' => '1',
|
||||
'default' => '1',
|
||||
)
|
||||
);
|
||||
\register_setting(
|
||||
'activitypub',
|
||||
'activitypub_enable_blog_user',
|
||||
array(
|
||||
'type' => 'boolean',
|
||||
'type' => 'boolean',
|
||||
'description' => \__( 'Your Blog becomes an ActivityPub compatible Profile.', 'activitypub' ),
|
||||
'default' => '0',
|
||||
'default' => '0',
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -295,10 +295,10 @@ class Admin {
|
|||
'activitypub_blog',
|
||||
'activitypub_blog_description',
|
||||
array(
|
||||
'type' => 'string',
|
||||
'description' => \esc_html__( 'The Description of the Blog-User', 'activitypub' ),
|
||||
'type' => 'string',
|
||||
'description' => \esc_html__( 'The Description of the Blog-User', 'activitypub' ),
|
||||
'show_in_rest' => true,
|
||||
'default' => '',
|
||||
'default' => '',
|
||||
)
|
||||
);
|
||||
\register_setting(
|
||||
|
@ -350,9 +350,9 @@ class Admin {
|
|||
'activitypub_blog',
|
||||
'activitypub_header_image',
|
||||
array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
'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.
|
||||
*/
|
||||
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' );
|
||||
|
||||
return $actions;
|
||||
|
|
|
@ -62,17 +62,17 @@ class Blocks {
|
|||
}
|
||||
|
||||
public static function add_data() {
|
||||
$context = is_admin() ? 'editor' : 'view';
|
||||
$context = is_admin() ? 'editor' : 'view';
|
||||
$followers_handle = 'activitypub-followers-' . $context . '-script';
|
||||
$follow_me_handle = 'activitypub-follow-me-' . $context . '-script';
|
||||
$data = array(
|
||||
$data = array(
|
||||
'namespace' => ACTIVITYPUB_REST_NAMESPACE,
|
||||
'enabled' => array(
|
||||
'site' => ! is_user_type_disabled( 'blog' ),
|
||||
'enabled' => array(
|
||||
'site' => ! is_user_type_disabled( 'blog' ),
|
||||
'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( $follow_me_handle, $js, 'before' );
|
||||
}
|
||||
|
@ -152,6 +152,7 @@ class Blocks {
|
|||
|
||||
/**
|
||||
* Filter an array by a list of keys.
|
||||
*
|
||||
* @param array $array The array to filter.
|
||||
* @param array $keys The keys to keep.
|
||||
* @return array The filtered array.
|
||||
|
@ -162,12 +163,13 @@ class Blocks {
|
|||
|
||||
/**
|
||||
* Render the follow me block.
|
||||
*
|
||||
* @param array $attrs The block attributes.
|
||||
* @return string The HTML to render.
|
||||
*/
|
||||
public static function render_follow_me_block( $attrs ) {
|
||||
$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 ( 'inherit' === $attrs['selectedUser'] ) {
|
||||
// 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 -->';
|
||||
}
|
||||
|
||||
$per_page = absint( $attrs['per_page'] );
|
||||
$per_page = absint( $attrs['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(
|
||||
function ( $follower ) {
|
||||
return self::filter_array_by_keys(
|
||||
|
@ -217,7 +219,7 @@ class Blocks {
|
|||
},
|
||||
$follower_data['followers']
|
||||
);
|
||||
$wrapper_attributes = get_block_wrapper_attributes(
|
||||
$wrapper_attributes = get_block_wrapper_attributes(
|
||||
array(
|
||||
'aria-label' => __( 'Fediverse Followers', 'activitypub' ),
|
||||
'class' => 'activitypub-follower-block',
|
||||
|
@ -261,7 +263,7 @@ class Blocks {
|
|||
|
||||
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>';
|
||||
$template =
|
||||
$template =
|
||||
'<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" />
|
||||
<span class="activitypub-actor">
|
||||
|
|
|
@ -54,7 +54,7 @@ class Comment {
|
|||
|
||||
$attrs = array(
|
||||
'selectedComment' => self::generate_id( $comment ),
|
||||
'commentId' => $comment->comment_ID,
|
||||
'commentId' => $comment->comment_ID,
|
||||
);
|
||||
|
||||
$div = sprintf(
|
||||
|
@ -78,7 +78,7 @@ class Comment {
|
|||
*/
|
||||
private static function create_fediverse_reply_link( $link, $args ) {
|
||||
$str_to_replace = sprintf( '>%s<', $args['reply_text'] );
|
||||
$replace_with = sprintf(
|
||||
$replace_with = sprintf(
|
||||
' title="%s">%s<',
|
||||
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' )
|
||||
|
@ -343,8 +343,8 @@ class Comment {
|
|||
/**
|
||||
* Gets the public comment id via the WordPress comments meta.
|
||||
*
|
||||
* @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 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.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @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 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.
|
||||
*
|
||||
* @return string|null The ActivityPub id/url of the comment.
|
||||
*/
|
||||
|
@ -383,7 +383,7 @@ class Comment {
|
|||
/**
|
||||
* Link remote comments to source url.
|
||||
*
|
||||
* @param string $comment_link
|
||||
* @param string $comment_link
|
||||
* @param object|WP_Comment $comment
|
||||
*
|
||||
* @return string $url
|
||||
|
@ -430,7 +430,7 @@ class Comment {
|
|||
private static function post_has_remote_comments( $post_id ) {
|
||||
$comments = \get_comments(
|
||||
array(
|
||||
'post_id' => $post_id,
|
||||
'post_id' => $post_id,
|
||||
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
|
@ -496,7 +496,7 @@ class Comment {
|
|||
\wp_enqueue_style(
|
||||
$handle,
|
||||
\plugins_url( 'build/remote-reply/style-index.css', __DIR__ ),
|
||||
[ 'wp-components' ],
|
||||
array( 'wp-components' ),
|
||||
$assets['version']
|
||||
);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ class Hashtag {
|
|||
* @return array the activity 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'] ) ) {
|
||||
$object_array['summary'] = self::the_content( $object_array['summary'] );
|
||||
}
|
||||
|
@ -85,7 +86,7 @@ class Hashtag {
|
|||
* @return string the final string
|
||||
*/
|
||||
public static function replace_with_links( $result ) {
|
||||
$tag = $result[1];
|
||||
$tag = $result[1];
|
||||
$tag_object = \get_term_by( 'name', $tag, 'post_tag' );
|
||||
if ( ! $tag_object ) {
|
||||
$tag_object = \get_term_by( 'name', $tag, 'category' );
|
||||
|
|
|
@ -112,7 +112,7 @@ class Health_Check {
|
|||
'<p>%s</p>',
|
||||
\__( 'Enhance your WordPress site’s 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>',
|
||||
__( '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' ),
|
||||
|
@ -167,8 +167,8 @@ class Health_Check {
|
|||
* @return boolean|WP_Error
|
||||
*/
|
||||
public static function is_author_url_accessible() {
|
||||
$user = \wp_get_current_user();
|
||||
$author_url = \get_author_posts_url( $user->ID );
|
||||
$user = \wp_get_current_user();
|
||||
$author_url = \get_author_posts_url( $user->ID );
|
||||
$reference_author_url = self::get_author_posts_url( $user->ID, $user->user_nicename );
|
||||
|
||||
// check for "author" in URL
|
||||
|
@ -190,7 +190,7 @@ class Health_Check {
|
|||
$response = \wp_remote_get(
|
||||
$author_url,
|
||||
array(
|
||||
'headers' => array( 'Accept' => 'application/activity+json' ),
|
||||
'headers' => array( 'Accept' => 'application/activity+json' ),
|
||||
'redirection' => 0,
|
||||
)
|
||||
);
|
||||
|
@ -252,7 +252,7 @@ class Health_Check {
|
|||
* @return boolean|WP_Error
|
||||
*/
|
||||
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();
|
||||
|
||||
$url = Webfinger::resolve( $resource );
|
||||
|
@ -277,7 +277,7 @@ class Health_Check {
|
|||
);
|
||||
|
||||
$health_messages = array(
|
||||
'webfinger_url_not_accessible' => \sprintf(
|
||||
'webfinger_url_not_accessible' => \sprintf(
|
||||
$not_accessible,
|
||||
$url->get_error_data()['data']
|
||||
),
|
||||
|
@ -287,7 +287,7 @@ class Health_Check {
|
|||
$url->get_error_data()['data']
|
||||
),
|
||||
);
|
||||
$message = null;
|
||||
$message = null;
|
||||
if ( isset( $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 = '' ) {
|
||||
global $wp_rewrite;
|
||||
$auth_id = (int) $author_id;
|
||||
$link = $wp_rewrite->get_author_permastruct();
|
||||
$link = $wp_rewrite->get_author_permastruct();
|
||||
|
||||
if ( empty( $link ) ) {
|
||||
$file = home_url( '/' );
|
||||
|
@ -343,12 +343,12 @@ class Health_Check {
|
|||
$info['activitypub'] = array(
|
||||
'label' => __( 'ActivityPub', 'activitypub' ),
|
||||
'fields' => array(
|
||||
'webfinger' => array(
|
||||
'webfinger' => array(
|
||||
'label' => __( 'WebFinger Resource', 'activitypub' ),
|
||||
'value' => Webfinger::get_user_resource( wp_get_current_user()->ID ),
|
||||
'private' => true,
|
||||
),
|
||||
'author_url' => array(
|
||||
'author_url' => array(
|
||||
'label' => __( 'Author URL', 'activitypub' ),
|
||||
'value' => get_author_posts_url( wp_get_current_user()->ID ),
|
||||
'private' => true,
|
||||
|
|
|
@ -24,8 +24,8 @@ class Http {
|
|||
public static function 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' );
|
||||
$digest = Signature::generate_digest( $body );
|
||||
$date = \gmdate( 'D, d M Y H:i:s T' );
|
||||
$digest = Signature::generate_digest( $body );
|
||||
$signature = Signature::generate_signature( $user_id, 'post', $url, $date, $digest );
|
||||
|
||||
$wp_version = get_masked_wp_version();
|
||||
|
@ -36,19 +36,19 @@ class Http {
|
|||
* @param string $user_agent The user agent string.
|
||||
*/
|
||||
$user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) );
|
||||
$args = array(
|
||||
'timeout' => 100,
|
||||
$args = array(
|
||||
'timeout' => 100,
|
||||
'limit_response_size' => 1048576,
|
||||
'redirection' => 3,
|
||||
'user-agent' => "$user_agent; ActivityPub",
|
||||
'headers' => array(
|
||||
'Accept' => 'application/activity+json',
|
||||
'redirection' => 3,
|
||||
'user-agent' => "$user_agent; ActivityPub",
|
||||
'headers' => array(
|
||||
'Accept' => 'application/activity+json',
|
||||
'Content-Type' => 'application/activity+json',
|
||||
'Digest' => $digest,
|
||||
'Signature' => $signature,
|
||||
'Date' => $date,
|
||||
'Digest' => $digest,
|
||||
'Signature' => $signature,
|
||||
'Date' => $date,
|
||||
),
|
||||
'body' => $body,
|
||||
'body' => $body,
|
||||
);
|
||||
|
||||
$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 );
|
||||
|
||||
$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' ) );
|
||||
|
||||
$args = array(
|
||||
'timeout' => apply_filters( 'activitypub_remote_get_timeout', 100 ),
|
||||
'timeout' => apply_filters( 'activitypub_remote_get_timeout', 100 ),
|
||||
'limit_response_size' => 1048576,
|
||||
'redirection' => 3,
|
||||
'user-agent' => "$user_agent; ActivityPub",
|
||||
'headers' => array(
|
||||
'Accept' => 'application/activity+json',
|
||||
'redirection' => 3,
|
||||
'user-agent' => "$user_agent; ActivityPub",
|
||||
'headers' => array(
|
||||
'Accept' => 'application/activity+json',
|
||||
'Content-Type' => 'application/activity+json',
|
||||
'Signature' => $signature,
|
||||
'Date' => $date,
|
||||
'Signature' => $signature,
|
||||
'Date' => $date,
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ class Link {
|
|||
* @return array the activity 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'] ) ) {
|
||||
$object_array['summary'] = self::the_content( $object_array['summary'] );
|
||||
}
|
||||
|
@ -82,7 +83,7 @@ class Link {
|
|||
|
||||
$text_url = $parsed_url['host'];
|
||||
if ( 'www.' === substr( $text_url, 0, 4 ) ) {
|
||||
$text_url = substr( $text_url, 4 );
|
||||
$text_url = substr( $text_url, 4 );
|
||||
$invisible_prefix .= 'www.';
|
||||
}
|
||||
if ( ! empty( $parsed_url['port'] ) ) {
|
||||
|
@ -98,7 +99,7 @@ class Link {
|
|||
$text_url .= '#' . $parsed_url['fragment'];
|
||||
}
|
||||
|
||||
$display = \substr( $text_url, 0, 30 );
|
||||
$display = \substr( $text_url, 0, 30 );
|
||||
$invisible_suffix = \substr( $text_url, 30 );
|
||||
|
||||
$display_class = '';
|
||||
|
|
|
@ -43,8 +43,8 @@ class Notification {
|
|||
* @param int $target The WordPress User-Id.
|
||||
*/
|
||||
public function __construct( $type, $actor, $object, $target ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound
|
||||
$this->type = $type;
|
||||
$this->actor = $actor;
|
||||
$this->type = $type;
|
||||
$this->actor = $actor;
|
||||
$this->object = $object;
|
||||
$this->target = $target;
|
||||
}
|
||||
|
|
|
@ -332,7 +332,7 @@ class Shortcodes {
|
|||
}
|
||||
|
||||
$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 ) {
|
||||
return '';
|
||||
|
@ -358,7 +358,7 @@ class Shortcodes {
|
|||
}
|
||||
|
||||
$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 ) {
|
||||
return '';
|
||||
|
@ -422,7 +422,7 @@ class Shortcodes {
|
|||
return '';
|
||||
}
|
||||
|
||||
$datetime = \get_post_datetime( $item );
|
||||
$datetime = \get_post_datetime( $item );
|
||||
$dateformat = \get_option( 'date_format' );
|
||||
$timeformat = \get_option( 'time_format' );
|
||||
|
||||
|
@ -451,7 +451,7 @@ class Shortcodes {
|
|||
return '';
|
||||
}
|
||||
|
||||
$datetime = \get_post_datetime( $item );
|
||||
$datetime = \get_post_datetime( $item );
|
||||
$dateformat = \get_option( 'date_format' );
|
||||
$timeformat = \get_option( 'time_format' );
|
||||
|
||||
|
@ -480,7 +480,7 @@ class Shortcodes {
|
|||
return '';
|
||||
}
|
||||
|
||||
$datetime = \get_post_datetime( $item );
|
||||
$datetime = \get_post_datetime( $item );
|
||||
$dateformat = \get_option( 'date_format' );
|
||||
$timeformat = \get_option( 'time_format' );
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class Signature {
|
|||
*/
|
||||
public static function get_keypair_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 ) {
|
||||
$key_pair = self::generate_key_pair_for( $user_id );
|
||||
|
@ -78,7 +78,7 @@ class Signature {
|
|||
*/
|
||||
protected static function generate_key_pair_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 ) {
|
||||
\add_option( $option_key, $key_pair );
|
||||
|
@ -87,14 +87,14 @@ class Signature {
|
|||
}
|
||||
|
||||
$config = array(
|
||||
'digest_alg' => 'sha512',
|
||||
'digest_alg' => 'sha512',
|
||||
'private_key_bits' => 2048,
|
||||
'private_key_type' => \OPENSSL_KEYTYPE_RSA,
|
||||
);
|
||||
|
||||
$key = \openssl_pkey_new( $config );
|
||||
$key = \openssl_pkey_new( $config );
|
||||
$priv_key = null;
|
||||
$detail = array();
|
||||
$detail = array();
|
||||
if ( $key ) {
|
||||
\openssl_pkey_export( $key, $priv_key );
|
||||
|
||||
|
@ -152,15 +152,15 @@ class Signature {
|
|||
protected static function check_legacy_key_pair_for( $user_id ) {
|
||||
switch ( $user_id ) {
|
||||
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' );
|
||||
break;
|
||||
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' );
|
||||
break;
|
||||
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 );
|
||||
break;
|
||||
}
|
||||
|
@ -253,11 +253,11 @@ class Signature {
|
|||
$route = '/' . $path . $route;
|
||||
}
|
||||
|
||||
$headers = $request->get_headers();
|
||||
$headers = $request->get_headers();
|
||||
$headers['(request-target)'][0] = strtolower( $request->get_method() ) . ' ' . $route;
|
||||
} else {
|
||||
$request = self::format_server_request( $request );
|
||||
$headers = $request['headers']; // $_SERVER array
|
||||
$request = self::format_server_request( $request );
|
||||
$headers = $request['headers']; // $_SERVER array
|
||||
$headers['(request-target)'][0] = strtolower( $headers['request_method'][0] ) . ' ' . $headers['request_uri'][0];
|
||||
}
|
||||
|
||||
|
@ -359,7 +359,7 @@ class Signature {
|
|||
if ( $signature_block['algorithm'] ) {
|
||||
switch ( $signature_block['algorithm'] ) {
|
||||
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:
|
||||
return 'sha256';
|
||||
}
|
||||
|
@ -375,8 +375,8 @@ class Signature {
|
|||
* @return array signature parts
|
||||
*/
|
||||
public static function parse_signature_header( $signature ) {
|
||||
$parsed_header = array();
|
||||
$matches = array();
|
||||
$parsed_header = array();
|
||||
$matches = array();
|
||||
|
||||
if ( \preg_match( '/keyId="(.*?)"/ism', $signature, $matches ) ) {
|
||||
$parsed_header['keyId'] = trim( $matches[1] );
|
||||
|
@ -459,7 +459,7 @@ class Signature {
|
|||
$d->setTimeZone( new DateTimeZone( 'UTC' ) );
|
||||
$c = $d->format( 'U' );
|
||||
|
||||
$dplus = time() + ( 3 * HOUR_IN_SECONDS );
|
||||
$dplus = time() + ( 3 * HOUR_IN_SECONDS );
|
||||
$dminus = time() - ( 3 * HOUR_IN_SECONDS );
|
||||
|
||||
if ( $c > $dplus || $c < $dminus ) {
|
||||
|
@ -499,7 +499,7 @@ class Signature {
|
|||
if ( 'REQUEST_URI' === $req_param ) {
|
||||
$request['headers']['route'][] = $param_val;
|
||||
} else {
|
||||
$header_key = str_replace(
|
||||
$header_key = str_replace(
|
||||
'http_',
|
||||
'',
|
||||
$req_param
|
||||
|
|
|
@ -142,10 +142,10 @@ class Webfinger {
|
|||
|
||||
if ( ! preg_match( '/^([a-zA-Z+]+):/', $url, $match ) ) {
|
||||
$identifier = 'acct:' . $url;
|
||||
$scheme = 'acct';
|
||||
$scheme = 'acct';
|
||||
} else {
|
||||
$identifier = $url;
|
||||
$scheme = $match[1];
|
||||
$scheme = $match[1];
|
||||
}
|
||||
|
||||
$host = null;
|
||||
|
|
|
@ -21,9 +21,9 @@ class Extra_Fields {
|
|||
* @return \WP_Post[] The extra fields.
|
||||
*/
|
||||
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;
|
||||
$args = array(
|
||||
$args = array(
|
||||
'post_type' => $post_type,
|
||||
'nopaging' => true,
|
||||
'orderby' => 'menu_order',
|
||||
|
@ -33,7 +33,7 @@ class Extra_Fields {
|
|||
$args['author'] = $user_id;
|
||||
}
|
||||
|
||||
$query = new \WP_Query( $args );
|
||||
$query = new \WP_Query( $args );
|
||||
$fields = $query->posts ?? array();
|
||||
|
||||
return apply_filters( 'activitypub_get_actor_extra_fields', $fields, $user_id );
|
||||
|
@ -75,10 +75,10 @@ class Extra_Fields {
|
|||
);
|
||||
|
||||
foreach ( $fields as $post ) {
|
||||
$content = self::get_formatted_content( $post );
|
||||
$content = self::get_formatted_content( $post );
|
||||
$attachments[] = array(
|
||||
'type' => 'PropertyValue',
|
||||
'name' => \get_the_title( $post ),
|
||||
'type' => 'PropertyValue',
|
||||
'name' => \get_the_title( $post ),
|
||||
'value' => \html_entity_decode(
|
||||
$content,
|
||||
\ENT_QUOTES,
|
||||
|
@ -104,7 +104,7 @@ class Extra_Fields {
|
|||
'type' => 'Link',
|
||||
'name' => \get_the_title( $post ),
|
||||
'href' => \esc_url( $tags->get_attribute( 'href' ) ),
|
||||
'rel' => explode( ' ', $tags->get_attribute( 'rel' ) ),
|
||||
'rel' => explode( ' ', $tags->get_attribute( 'rel' ) ),
|
||||
);
|
||||
|
||||
$link_added = true;
|
||||
|
@ -176,7 +176,7 @@ class Extra_Fields {
|
|||
return $extra_fields;
|
||||
}
|
||||
|
||||
$is_blog = self::is_blog( $user_id );
|
||||
$is_blog = self::is_blog( $user_id );
|
||||
$already_migrated = $is_blog
|
||||
? \get_option( 'activitypub_default_extra_fields' )
|
||||
: \get_user_meta( $user_id, 'activitypub_default_extra_fields', true );
|
||||
|
@ -199,7 +199,7 @@ class Extra_Fields {
|
|||
);
|
||||
|
||||
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 );
|
||||
|
||||
$defaults[ \__( 'Profile', 'activitypub' ) ] = $author_posts_url;
|
||||
|
@ -226,7 +226,7 @@ class Extra_Fields {
|
|||
'menu_order' => $menu_order,
|
||||
);
|
||||
|
||||
$menu_order += 10;
|
||||
$menu_order += 10;
|
||||
$extra_field_id = wp_insert_post( $extra_field );
|
||||
$extra_fields[] = get_post( $extra_field_id );
|
||||
}
|
||||
|
@ -247,6 +247,7 @@ class Extra_Fields {
|
|||
|
||||
/**
|
||||
* Checks if the user is the blog user.
|
||||
*
|
||||
* @param int $user_id The user ID.
|
||||
* @return bool True if the user is the blog user, otherwise false.
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,7 @@ use function Activitypub\get_remote_metadata_by_actor;
|
|||
* @author Matthias Pfefferle
|
||||
*/
|
||||
class Followers {
|
||||
const POST_TYPE = 'ap_follower';
|
||||
const POST_TYPE = 'ap_follower';
|
||||
const CACHE_KEY_INBOXES = 'follower_inboxes_%s';
|
||||
|
||||
/**
|
||||
|
@ -139,10 +139,10 @@ class Followers {
|
|||
/**
|
||||
* Get the Followers of a given user
|
||||
*
|
||||
* @param int $user_id The ID of the WordPress User.
|
||||
* @param int $number Maximum number of results to return.
|
||||
* @param int $page Page number.
|
||||
* @param array $args The WP_Query arguments.
|
||||
* @param int $user_id The ID of the WordPress User.
|
||||
* @param int $number Maximum number of results to return.
|
||||
* @param int $page Page number.
|
||||
* @param array $args The WP_Query arguments.
|
||||
* @return array List of `Follower` objects.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param int $user_id The ID of the WordPress User.
|
||||
* @param int $number Maximum number of results to return.
|
||||
* @param int $page Page number.
|
||||
* @param array $args The WP_Query arguments.
|
||||
* @param int $user_id The ID of the WordPress User.
|
||||
* @param int $number Maximum number of results to return.
|
||||
* @param int $page Page number.
|
||||
* @param array $args The WP_Query arguments.
|
||||
*
|
||||
* @return array
|
||||
* followers List of `Follower` objects.
|
||||
|
@ -178,9 +178,9 @@ class Followers {
|
|||
),
|
||||
);
|
||||
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
$query = new WP_Query( $args );
|
||||
$total = $query->found_posts;
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
$query = new WP_Query( $args );
|
||||
$total = $query->found_posts;
|
||||
$followers = array_map(
|
||||
function ( $post ) {
|
||||
return Follower::init_from_cpt( $post );
|
||||
|
@ -259,7 +259,7 @@ class Followers {
|
|||
*/
|
||||
public static function get_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 ) {
|
||||
return $inboxes;
|
||||
|
|
|
@ -62,7 +62,7 @@ class Interactions {
|
|||
public static function update_comment( $activity ) {
|
||||
$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'] ) );
|
||||
$commentdata = \get_comment( $comment, ARRAY_A );
|
||||
|
||||
|
@ -70,8 +70,8 @@ class Interactions {
|
|||
return false;
|
||||
}
|
||||
|
||||
//found a local comment id
|
||||
$commentdata['comment_author'] = \esc_attr( $meta['name'] ? $meta['name'] : $meta['preferredUsername'] );
|
||||
// found a local comment id
|
||||
$commentdata['comment_author'] = \esc_attr( $meta['name'] ? $meta['name'] : $meta['preferredUsername'] );
|
||||
$commentdata['comment_content'] = \addslashes( $activity['object']['content'] );
|
||||
|
||||
return self::persist( $commentdata, self::UPDATE );
|
||||
|
@ -80,7 +80,7 @@ class Interactions {
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
@ -173,14 +173,14 @@ class Interactions {
|
|||
$actor = object_to_uri( $meta['url'] );
|
||||
}
|
||||
|
||||
$args = array(
|
||||
$args = array(
|
||||
'nopaging' => true,
|
||||
'author_url' => $actor,
|
||||
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'protocol',
|
||||
'value' => 'activitypub',
|
||||
'key' => 'protocol',
|
||||
'value' => 'activitypub',
|
||||
'compare' => '=',
|
||||
),
|
||||
),
|
||||
|
@ -252,14 +252,14 @@ class Interactions {
|
|||
}
|
||||
|
||||
$commentdata = array(
|
||||
'comment_author' => \esc_attr( $comment_author ),
|
||||
'comment_author_url' => \esc_url_raw( $url ),
|
||||
'comment_content' => $comment_content,
|
||||
'comment_type' => 'comment',
|
||||
'comment_author' => \esc_attr( $comment_author ),
|
||||
'comment_author_url' => \esc_url_raw( $url ),
|
||||
'comment_content' => $comment_content,
|
||||
'comment_type' => 'comment',
|
||||
'comment_author_email' => '',
|
||||
'comment_meta' => array(
|
||||
'source_id' => \esc_url_raw( object_to_uri( $activity['object'] ) ),
|
||||
'protocol' => 'activitypub',
|
||||
'comment_meta' => array(
|
||||
'source_id' => \esc_url_raw( object_to_uri( $activity['object'] ) ),
|
||||
'protocol' => 'activitypub',
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -21,13 +21,13 @@ class Replies {
|
|||
*/
|
||||
private static function build_args( $wp_object ) {
|
||||
$args = array(
|
||||
'status' => 'approve',
|
||||
'status' => 'approve',
|
||||
'orderby' => 'comment_date_gmt',
|
||||
'order' => 'ASC',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
|
||||
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;
|
||||
} elseif ( $wp_object instanceof WP_Comment ) {
|
||||
$args['parent'] = $wp_object->comment_ID;
|
||||
|
@ -48,7 +48,7 @@ class Replies {
|
|||
private static function add_pagination_args( $args, $page, $comments_per_page ) {
|
||||
$args['number'] = $comments_per_page;
|
||||
|
||||
$offset = intval( $page ) * $comments_per_page;
|
||||
$offset = intval( $page ) * $comments_per_page;
|
||||
$args['offset'] = $offset;
|
||||
|
||||
return $args;
|
||||
|
@ -76,7 +76,7 @@ class Replies {
|
|||
* Get the replies collection.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
|
@ -88,8 +88,8 @@ class Replies {
|
|||
}
|
||||
|
||||
$replies = array(
|
||||
'id' => $id,
|
||||
'type' => 'Collection',
|
||||
'id' => $id,
|
||||
'type' => 'Collection',
|
||||
);
|
||||
|
||||
$replies['first'] = self::get_collection_page( $wp_object, 0, $replies['id'] );
|
||||
|
|
|
@ -88,12 +88,12 @@ class Users {
|
|||
// check for 'activitypub_username' meta
|
||||
$user = new WP_User_Query(
|
||||
array(
|
||||
'count_total' => false,
|
||||
'number' => 1,
|
||||
'hide_empty' => true,
|
||||
'fields' => 'ID',
|
||||
'count_total' => false,
|
||||
'number' => 1,
|
||||
'hide_empty' => true,
|
||||
'fields' => 'ID',
|
||||
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
'meta_query' => array(
|
||||
'meta_query' => array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => 'activitypub_user_identifier',
|
||||
|
@ -144,7 +144,7 @@ class Users {
|
|||
$resource = object_to_uri( $resource );
|
||||
|
||||
$scheme = 'acct';
|
||||
$match = array();
|
||||
$match = array();
|
||||
// try to extract the scheme and the host
|
||||
if ( preg_match( '/^([a-zA-Z^:]+):(.*)$/i', $resource, $match ) ) {
|
||||
// extract the scheme
|
||||
|
|
|
@ -64,7 +64,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
|
|||
return new WP_Error(
|
||||
'activitypub_no_valid_actor_identifier',
|
||||
\__( '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(
|
||||
'activitypub_no_valid_actor_identifier',
|
||||
\__( '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(
|
||||
'activitypub_no_valid_actor_url',
|
||||
\__( 'The "actor" is no valid URL', 'activitypub' ),
|
||||
array( 'status' => 400, 'actor' => $actor )
|
||||
array(
|
||||
'status' => 400,
|
||||
'actor' => $actor,
|
||||
)
|
||||
);
|
||||
return $metadata;
|
||||
}
|
||||
|
@ -118,7 +127,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
|
|||
$metadata = new WP_Error(
|
||||
'activitypub_invalid_json',
|
||||
\__( 'No valid JSON data', 'activitypub' ),
|
||||
array( 'status' => 400, 'actor' => $actor )
|
||||
array(
|
||||
'status' => 400,
|
||||
'actor' => $actor,
|
||||
)
|
||||
);
|
||||
return $metadata;
|
||||
}
|
||||
|
@ -185,7 +197,7 @@ function url_to_authorid( $url ) {
|
|||
|
||||
// generate rewrite rule for the author url
|
||||
$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
|
||||
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 = '' ) {
|
||||
// we'll handle the leading slash.
|
||||
$path = ltrim( $path, '/' );
|
||||
$path = ltrim( $path, '/' );
|
||||
$namespaced_path = sprintf( '/%s/%s', ACTIVITYPUB_REST_NAMESPACE, $path );
|
||||
return \get_rest_url( null, $namespaced_path );
|
||||
}
|
||||
|
@ -631,9 +643,9 @@ function is_activity_public( $data ) {
|
|||
*/
|
||||
function get_active_users( $duration = 1 ) {
|
||||
|
||||
$duration = intval( $duration );
|
||||
$duration = intval( $duration );
|
||||
$transient_key = sprintf( 'monthly_active_users_%d', $duration );
|
||||
$count = get_transient( $transient_key );
|
||||
$count = get_transient( $transient_key );
|
||||
|
||||
if ( false === $count ) {
|
||||
global $wpdb;
|
||||
|
@ -924,8 +936,8 @@ function get_enclosures( $post_id ) {
|
|||
}
|
||||
|
||||
return array(
|
||||
'url' => $attributes[0],
|
||||
'length' => isset( $attributes[1] ) ? trim( $attributes[1] ) : null,
|
||||
'url' => $attributes[0],
|
||||
'length' => isset( $attributes[1] ) ? trim( $attributes[1] ) : null,
|
||||
'mediaType' => isset( $attributes[2] ) ? trim( $attributes[2] ) : null,
|
||||
);
|
||||
},
|
||||
|
@ -961,7 +973,7 @@ function get_comment_ancestors( $comment ) {
|
|||
|
||||
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
|
||||
while ( $id > 0 ) {
|
||||
$ancestor = \get_comment( $id );
|
||||
$ancestor = \get_comment( $id );
|
||||
$parent_id = (int) $ancestor->comment_parent;
|
||||
|
||||
// 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.
|
||||
*
|
||||
*
|
||||
* @param string $comment_type Key for comment type.
|
||||
* @param array $args Arguments.
|
||||
*
|
||||
|
@ -1040,7 +1051,6 @@ function register_comment_type( $comment_type, $args = array() ) {
|
|||
/**
|
||||
* Fires after a ActivityPub comment type is registered.
|
||||
*
|
||||
*
|
||||
* @param string $comment_type 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 ) {
|
||||
return $content;
|
||||
}
|
||||
$tag_stack = array();
|
||||
$protected_tags = array(
|
||||
$tag_stack = array();
|
||||
$protected_tags = array(
|
||||
'pre',
|
||||
'code',
|
||||
'textarea',
|
||||
|
@ -1111,7 +1121,7 @@ function enrich_content_data( $content, $regex, $regex_callback ) {
|
|||
'a',
|
||||
);
|
||||
$content_with_links = '';
|
||||
$in_protected_tag = false;
|
||||
$in_protected_tag = false;
|
||||
foreach ( wp_html_split( $content ) as $chunk ) {
|
||||
if ( preg_match( '#^<!--[\s\S]*-->$#i', $chunk, $m ) ) {
|
||||
$content_with_links .= $chunk;
|
||||
|
@ -1210,7 +1220,8 @@ function generate_post_summary( $post, $length = 500 ) {
|
|||
$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 $content;
|
||||
|
|
|
@ -70,7 +70,7 @@ class Create {
|
|||
* @param bool $valid The validation state
|
||||
* @param string $param The object parameter
|
||||
* @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
|
||||
*/
|
||||
|
|
|
@ -40,7 +40,7 @@ class Undo {
|
|||
// Handle "Unfollow" requests
|
||||
if ( 'Follow' === $type ) {
|
||||
$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 we can not find a user,
|
||||
|
|
|
@ -23,8 +23,8 @@ class Update {
|
|||
/**
|
||||
* Handle "Update" requests
|
||||
*
|
||||
* @param array $array The activity-object
|
||||
* @param int $user_id The id of the local blog-user
|
||||
* @param array $array The activity-object
|
||||
* @param int $user_id The id of the local blog-user
|
||||
*/
|
||||
public static function handle_update( $array ) {
|
||||
$object_type = isset( $array['object']['type'] ) ? $array['object']['type'] : '';
|
||||
|
|
|
@ -81,7 +81,7 @@ class Application extends Actor {
|
|||
return $this->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the User-Icon.
|
||||
*
|
||||
* @return array The User-Icon.
|
||||
|
@ -178,8 +178,8 @@ class Application extends Actor {
|
|||
|
||||
public function get_public_key() {
|
||||
return array(
|
||||
'id' => $this->get_id() . '#main-key',
|
||||
'owner' => $this->get_id(),
|
||||
'id' => $this->get_id() . '#main-key',
|
||||
'owner' => $this->get_id(),
|
||||
'publicKeyPem' => Signature::get_public_key_for( Users::APPLICATION_USER_ID ),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -301,8 +301,8 @@ class Blog extends Actor {
|
|||
|
||||
public function get_public_key() {
|
||||
return array(
|
||||
'id' => $this->get_id() . '#main-key',
|
||||
'owner' => $this->get_id(),
|
||||
'id' => $this->get_id() . '#main-key',
|
||||
'owner' => $this->get_id(),
|
||||
'publicKeyPem' => Signature::get_public_key_for( $this->get__id() ),
|
||||
);
|
||||
}
|
||||
|
@ -400,21 +400,21 @@ class Blog extends Actor {
|
|||
}
|
||||
|
||||
/**
|
||||
* Update the User-Description.
|
||||
*
|
||||
* @param mixed $value The new value.
|
||||
* @return bool True if the attribute was updated, false otherwise.
|
||||
*/
|
||||
* Update the User-Description.
|
||||
*
|
||||
* @param mixed $value The new value.
|
||||
* @return bool True if the attribute was updated, false otherwise.
|
||||
*/
|
||||
public function update_summary( $value ) {
|
||||
return \update_option( 'blogdescription', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the User-Icon.
|
||||
*
|
||||
* @param mixed $value The new value.
|
||||
* @return bool True if the attribute was updated, false otherwise.
|
||||
*/
|
||||
* Update the User-Icon.
|
||||
*
|
||||
* @param mixed $value The new value.
|
||||
* @return bool True if the attribute was updated, false otherwise.
|
||||
*/
|
||||
public function update_icon( $value ) {
|
||||
if ( ! wp_attachment_is_image( $value ) ) {
|
||||
return false;
|
||||
|
@ -423,11 +423,11 @@ class Blog extends Actor {
|
|||
}
|
||||
|
||||
/**
|
||||
* Update the User-Header-Image.
|
||||
*
|
||||
* @param mixed $value The new value.
|
||||
* @return bool True if the attribute was updated, false otherwise.
|
||||
*/
|
||||
* Update the User-Header-Image.
|
||||
*
|
||||
* @param mixed $value The new value.
|
||||
* @return bool True if the attribute was updated, false otherwise.
|
||||
*/
|
||||
public function update_header( $value ) {
|
||||
if ( ! wp_attachment_is_image( $value ) ) {
|
||||
return false;
|
||||
|
|
|
@ -184,7 +184,7 @@ class Follower extends Actor {
|
|||
$args['post_date_gmt'] = $post->post_date_gmt;
|
||||
}
|
||||
|
||||
$post_id = wp_insert_post( $args );
|
||||
$post_id = wp_insert_post( $args );
|
||||
$this->_id = $post_id;
|
||||
|
||||
return $post_id;
|
||||
|
@ -205,6 +205,7 @@ class Follower extends Actor {
|
|||
* Beware that this os deleting a Follower for ALL users!!!
|
||||
*
|
||||
* To delete only the User connection (unfollow)
|
||||
*
|
||||
* @see \Activitypub\Rest\Followers::remove_follower()
|
||||
*
|
||||
* @return void
|
||||
|
@ -219,8 +220,8 @@ class Follower extends Actor {
|
|||
* @return void
|
||||
*/
|
||||
protected function get_post_meta_input() {
|
||||
$meta_input = array();
|
||||
$meta_input['activitypub_inbox'] = $this->get_shared_inbox();
|
||||
$meta_input = array();
|
||||
$meta_input['activitypub_inbox'] = $this->get_shared_inbox();
|
||||
$meta_input['activitypub_actor_json'] = $this->to_json();
|
||||
|
||||
return $meta_input;
|
||||
|
@ -239,9 +240,9 @@ class Follower extends Actor {
|
|||
}
|
||||
|
||||
return array(
|
||||
'type' => 'Image',
|
||||
'type' => 'Image',
|
||||
'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 ) {
|
||||
$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->guid );
|
||||
$object->set_name( $post->post_title );
|
||||
|
|
|
@ -76,7 +76,7 @@ class User extends Actor {
|
|||
);
|
||||
}
|
||||
|
||||
$object = new static();
|
||||
$object = new static();
|
||||
$object->_id = $user_id;
|
||||
|
||||
return $object;
|
||||
|
@ -185,8 +185,8 @@ class User extends Actor {
|
|||
|
||||
public function get_public_key() {
|
||||
return array(
|
||||
'id' => $this->get_id() . '#main-key',
|
||||
'owner' => $this->get_id(),
|
||||
'id' => $this->get_id() . '#main-key',
|
||||
'owner' => $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.
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ class Actors {
|
|||
/**
|
||||
* Handle GET request
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
|
@ -127,7 +127,10 @@ class Actors {
|
|||
$url = str_replace( '{uri}', $resource, $template );
|
||||
|
||||
return new WP_REST_Response(
|
||||
array( 'url' => $url, 'template' => $template ),
|
||||
array(
|
||||
'url' => $url,
|
||||
'template' => $template,
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
|
|
@ -84,7 +84,10 @@ class Comment {
|
|||
$url = str_replace( '{uri}', $resource, $template );
|
||||
|
||||
return new WP_REST_Response(
|
||||
array( 'url' => $url, 'template' => $template ),
|
||||
array(
|
||||
'url' => $url,
|
||||
'template' => $template,
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class Followers {
|
|||
/**
|
||||
* Handle GET request
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
|
@ -74,10 +74,10 @@ class Followers {
|
|||
|
||||
$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->actor = $user->get_id();
|
||||
$json->type = 'OrderedCollectionPage';
|
||||
$json->actor = $user->get_id();
|
||||
$json->type = 'OrderedCollectionPage';
|
||||
|
||||
$json->totalItems = $data['total']; // 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['page'] = array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
'default' => 1,
|
||||
);
|
||||
|
||||
$params['per_page'] = array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
'default' => 20,
|
||||
);
|
||||
|
||||
|
@ -136,13 +136,13 @@ class Followers {
|
|||
|
||||
$params['user_id'] = array(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
);
|
||||
|
||||
$params['context'] = array(
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
'default' => 'simple',
|
||||
'enum' => array( 'simple', 'full' ),
|
||||
'enum' => array( 'simple', 'full' ),
|
||||
);
|
||||
|
||||
return $params;
|
||||
|
|
|
@ -46,7 +46,7 @@ class Following {
|
|||
/**
|
||||
* Handle GET request
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
|
@ -67,10 +67,10 @@ class Following {
|
|||
|
||||
$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->actor = $user->get_id();
|
||||
$json->type = 'OrderedCollectionPage';
|
||||
$json->actor = $user->get_id();
|
||||
$json->type = 'OrderedCollectionPage';
|
||||
|
||||
$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(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
);
|
||||
|
||||
return $params;
|
||||
|
|
|
@ -69,7 +69,7 @@ class Inbox {
|
|||
/**
|
||||
* Renders the user-inbox
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function user_inbox_get( $request ) {
|
||||
|
@ -90,9 +90,9 @@ class Inbox {
|
|||
$json = new \stdClass();
|
||||
|
||||
$json->{'@context'} = get_context();
|
||||
$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->type = 'OrderedCollectionPage';
|
||||
$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->type = 'OrderedCollectionPage';
|
||||
$json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/inbox', $user->get__id() ) ); // phpcs:ignore
|
||||
$json->totalItems = 0; // phpcs:ignore
|
||||
$json->orderedItems = array(); // phpcs:ignore
|
||||
|
@ -115,7 +115,7 @@ class Inbox {
|
|||
/**
|
||||
* Handles user-inbox requests
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
|
@ -144,7 +144,7 @@ class Inbox {
|
|||
/**
|
||||
* The shared inbox
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
|
@ -177,7 +177,7 @@ class Inbox {
|
|||
|
||||
$params['user_id'] = array(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
);
|
||||
|
||||
return $params;
|
||||
|
@ -193,16 +193,16 @@ class Inbox {
|
|||
|
||||
$params['user_id'] = array(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
);
|
||||
|
||||
$params['id'] = array(
|
||||
'required' => true,
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'esc_url_raw',
|
||||
);
|
||||
|
||||
$params['actor'] = array(
|
||||
'required' => true,
|
||||
'required' => true,
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
'sanitize_callback' => function ( $param, $request, $key ) {
|
||||
return object_to_uri( $param );
|
||||
|
@ -214,7 +214,7 @@ class Inbox {
|
|||
);
|
||||
|
||||
$params['object'] = array(
|
||||
'required' => true,
|
||||
'required' => true,
|
||||
'validate_callback' => function ( $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['to'] = array(
|
||||
'required' => false,
|
||||
'required' => false,
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
'sanitize_callback' => function ( $param, $request, $key ) {
|
||||
if ( \is_string( $param ) ) {
|
||||
|
@ -277,7 +277,7 @@ class Inbox {
|
|||
*/
|
||||
public static function get_recipients( $data ) {
|
||||
$recipients = extract_recipients_from_activity( $data );
|
||||
$users = array();
|
||||
$users = array();
|
||||
|
||||
foreach ( $recipients as $recipient ) {
|
||||
$user_id = url_to_authorid( $recipient );
|
||||
|
|
|
@ -67,7 +67,7 @@ class Nodeinfo {
|
|||
/**
|
||||
* Render NodeInfo file
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
|
@ -79,37 +79,37 @@ class Nodeinfo {
|
|||
|
||||
$nodeinfo = array();
|
||||
|
||||
$nodeinfo['version'] = '2.0';
|
||||
$nodeinfo['version'] = '2.0';
|
||||
$nodeinfo['software'] = array(
|
||||
'name' => 'wordpress',
|
||||
'name' => 'wordpress',
|
||||
'version' => get_masked_wp_version(),
|
||||
);
|
||||
|
||||
$posts = \wp_count_posts();
|
||||
$posts = \wp_count_posts();
|
||||
$comments = \wp_count_comments();
|
||||
|
||||
$nodeinfo['usage'] = array(
|
||||
'users' => array(
|
||||
'users' => array(
|
||||
'total' => get_total_users(),
|
||||
'activeMonth' => get_active_users( '1 month ago' ),
|
||||
'activeHalfyear' => get_active_users( '6 month ago' ),
|
||||
),
|
||||
'localPosts' => (int) $posts->publish,
|
||||
'localPosts' => (int) $posts->publish,
|
||||
'localComments' => (int) $comments->approved,
|
||||
);
|
||||
|
||||
$nodeinfo['openRegistrations'] = false;
|
||||
$nodeinfo['protocols'] = array( 'activitypub' );
|
||||
$nodeinfo['protocols'] = array( 'activitypub' );
|
||||
|
||||
$nodeinfo['services'] = array(
|
||||
'inbound' => array(),
|
||||
'inbound' => array(),
|
||||
'outbound' => array(),
|
||||
);
|
||||
|
||||
$nodeinfo['metadata'] = array(
|
||||
'nodeName' => \get_bloginfo( 'name' ),
|
||||
'nodeName' => \get_bloginfo( 'name' ),
|
||||
'nodeDescription' => \get_bloginfo( 'description' ),
|
||||
'nodeIcon' => \get_site_icon_url(),
|
||||
'nodeIcon' => \get_site_icon_url(),
|
||||
);
|
||||
|
||||
return new WP_REST_Response( $nodeinfo, 200 );
|
||||
|
@ -118,7 +118,7 @@ class Nodeinfo {
|
|||
/**
|
||||
* Render NodeInfo file
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
|
@ -131,31 +131,31 @@ class Nodeinfo {
|
|||
$nodeinfo = array();
|
||||
|
||||
$nodeinfo['version'] = '2.0';
|
||||
$nodeinfo['server'] = array(
|
||||
'baseUrl' => \home_url( '/' ),
|
||||
'name' => \get_bloginfo( 'name' ),
|
||||
$nodeinfo['server'] = array(
|
||||
'baseUrl' => \home_url( '/' ),
|
||||
'name' => \get_bloginfo( 'name' ),
|
||||
'software' => 'wordpress',
|
||||
'version' => get_masked_wp_version(),
|
||||
'version' => get_masked_wp_version(),
|
||||
);
|
||||
|
||||
$posts = \wp_count_posts();
|
||||
$posts = \wp_count_posts();
|
||||
$comments = \wp_count_comments();
|
||||
|
||||
$nodeinfo['usage'] = array(
|
||||
'users' => array(
|
||||
'users' => array(
|
||||
'total' => get_total_users(),
|
||||
'activeMonth' => get_active_users( 1 ),
|
||||
'activeHalfyear' => get_active_users( 6 ),
|
||||
),
|
||||
'localPosts' => (int) $posts->publish,
|
||||
'localPosts' => (int) $posts->publish,
|
||||
'localComments' => (int) $comments->approved,
|
||||
);
|
||||
|
||||
$nodeinfo['openRegistrations'] = false;
|
||||
$nodeinfo['protocols'] = array( 'activitypub' );
|
||||
$nodeinfo['protocols'] = array( 'activitypub' );
|
||||
|
||||
$nodeinfo['services'] = array(
|
||||
'inbound' => array(),
|
||||
'inbound' => array(),
|
||||
'outbound' => array(),
|
||||
);
|
||||
|
||||
|
@ -165,19 +165,19 @@ class Nodeinfo {
|
|||
/**
|
||||
* Render NodeInfo discovery file
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function discovery( $request ) {
|
||||
$discovery = array();
|
||||
$discovery = array();
|
||||
$discovery['links'] = 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' ),
|
||||
),
|
||||
array(
|
||||
'rel' => 'https://www.w3.org/ns/activitystreams#Application',
|
||||
'rel' => 'https://www.w3.org/ns/activitystreams#Application',
|
||||
'href' => get_rest_url_by_path( 'application' ),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -49,7 +49,7 @@ class Outbox {
|
|||
/**
|
||||
* Renders the user-outbox
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function user_outbox_get( $request ) {
|
||||
|
@ -72,19 +72,19 @@ class Outbox {
|
|||
$json = new stdClass();
|
||||
|
||||
$json->{'@context'} = get_context();
|
||||
$json->id = get_rest_url_by_path( sprintf( 'actors/%d/outbox', $user_id ) );
|
||||
$json->generator = 'http://wordpress.org/?v=' . get_masked_wp_version();
|
||||
$json->actor = $user->get_id();
|
||||
$json->type = 'OrderedCollectionPage';
|
||||
$json->id = get_rest_url_by_path( sprintf( 'actors/%d/outbox', $user_id ) );
|
||||
$json->generator = 'http://wordpress.org/?v=' . get_masked_wp_version();
|
||||
$json->actor = $user->get_id();
|
||||
$json->type = 'OrderedCollectionPage';
|
||||
$json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/outbox', $user_id ) ); // phpcs:ignore
|
||||
$json->totalItems = 0; // phpcs:ignore
|
||||
|
||||
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
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -148,13 +148,13 @@ class Outbox {
|
|||
$params = array();
|
||||
|
||||
$params['page'] = array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
'default' => 1,
|
||||
);
|
||||
|
||||
$params['user_id'] = array(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
);
|
||||
|
||||
return $params;
|
||||
|
|
|
@ -73,7 +73,7 @@ class Webfinger {
|
|||
$code,
|
||||
array(
|
||||
'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(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'pattern' => '^(acct:)|^(https?://)(.+)$',
|
||||
'type' => 'string',
|
||||
'pattern' => '^(acct:)|^(https?://)(.+)$',
|
||||
);
|
||||
|
||||
return $params;
|
||||
|
|
|
@ -191,7 +191,7 @@ class Comment extends Base {
|
|||
$mentions = $this->get_mentions();
|
||||
if ( $mentions ) {
|
||||
foreach ( $mentions as $mention => $url ) {
|
||||
$tag = array(
|
||||
$tag = array(
|
||||
'type' => 'Mention',
|
||||
'href' => \esc_url( $url ),
|
||||
'name' => \esc_html( $mention ),
|
||||
|
@ -255,7 +255,7 @@ class Comment extends Base {
|
|||
if ( $comment && ! empty( $comment->comment_author_url ) ) {
|
||||
$acct = Webfinger::uri_to_acct( $comment->comment_author_url );
|
||||
if ( $acct && ! is_wp_error( $acct ) ) {
|
||||
$acct = str_replace( 'acct:', '@', $acct );
|
||||
$acct = str_replace( 'acct:', '@', $acct );
|
||||
$mentions[ $acct ] = $comment->comment_author_url;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ class Post extends Base {
|
|||
* @return \Activitypub\Activity\Base_Object The ActivityPub Object
|
||||
*/
|
||||
public function to_object() {
|
||||
$post = $this->wp_object;
|
||||
$post = $this->wp_object;
|
||||
$object = parent::to_object();
|
||||
|
||||
$published = \strtotime( $post->post_date_gmt );
|
||||
|
@ -109,7 +109,7 @@ class Post extends Base {
|
|||
return $this->actor_object;
|
||||
}
|
||||
|
||||
$blog_user = new Blog();
|
||||
$blog_user = new Blog();
|
||||
$this->actor_object = $blog_user;
|
||||
|
||||
if ( is_single_user() ) {
|
||||
|
@ -299,16 +299,17 @@ class Post extends Base {
|
|||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively get media IDs from blocks.
|
||||
*
|
||||
* @param array $blocks The blocks to search for media IDs
|
||||
* @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.
|
||||
*/
|
||||
|
@ -443,14 +444,14 @@ class Post extends Base {
|
|||
|
||||
if ( 0 === $img_id ) {
|
||||
$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 ) {
|
||||
$img_id = \attachment_url_to_postid( $src );
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
|
@ -484,12 +485,12 @@ class Post extends Base {
|
|||
$images = array();
|
||||
$query = new \WP_Query(
|
||||
array(
|
||||
'post_parent' => $this->wp_object->ID,
|
||||
'post_status' => 'inherit',
|
||||
'post_type' => 'attachment',
|
||||
'post_parent' => $this->wp_object->ID,
|
||||
'post_status' => 'inherit',
|
||||
'post_type' => 'attachment',
|
||||
'post_mime_type' => 'image',
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'menu_order ID',
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'menu_order ID',
|
||||
'posts_per_page' => $max_images,
|
||||
)
|
||||
);
|
||||
|
@ -584,10 +585,10 @@ class Post extends Base {
|
|||
'url' => \esc_url( \wp_get_attachment_url( $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
|
||||
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'] );
|
||||
}
|
||||
// @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 );
|
||||
if ( $post_tags ) {
|
||||
foreach ( $post_tags as $post_tag ) {
|
||||
$tag = array(
|
||||
$tag = array(
|
||||
'type' => 'Hashtag',
|
||||
'href' => \esc_url( \get_tag_link( $post_tag->term_id ) ),
|
||||
'name' => esc_hashtag( $post_tag->name ),
|
||||
|
@ -735,7 +736,7 @@ class Post extends Base {
|
|||
$mentions = $this->get_mentions();
|
||||
if ( $mentions ) {
|
||||
foreach ( $mentions as $mention => $url ) {
|
||||
$tag = array(
|
||||
$tag = array(
|
||||
'type' => 'Mention',
|
||||
'href' => \esc_url( $url ),
|
||||
'name' => \esc_html( $mention ),
|
||||
|
|
|
@ -15,7 +15,7 @@ class Buddypress {
|
|||
}
|
||||
|
||||
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
|
||||
$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
|
||||
$object->attachment['profile_url'] = array(
|
||||
'type' => 'PropertyValue',
|
||||
'name' => \__( 'Profile', 'activitypub' ),
|
||||
'type' => 'PropertyValue',
|
||||
'name' => \__( 'Profile', 'activitypub' ),
|
||||
'value' => \html_entity_decode(
|
||||
sprintf(
|
||||
'<a rel="me" title="%s" target="_blank" href="%s">%s</a>',
|
||||
|
@ -45,7 +45,7 @@ class Buddypress {
|
|||
|
||||
// replace blog URL on 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 ) ) {
|
||||
unset( $object->attachment['blog_url'] );
|
||||
|
@ -53,8 +53,8 @@ class Buddypress {
|
|||
foreach ( $user_blogs as $blog ) {
|
||||
if ( 1 !== $blog->userblog_id ) {
|
||||
$object->attachment[] = array(
|
||||
'type' => 'PropertyValue',
|
||||
'name' => $blog->blogname,
|
||||
'type' => 'PropertyValue',
|
||||
'name' => $blog->blogname,
|
||||
'value' => \html_entity_decode(
|
||||
sprintf(
|
||||
'<a rel="me" title="%s" target="_blank" href="%s">%s</a>',
|
||||
|
|
|
@ -117,8 +117,8 @@ class Enable_Mastodon_Apps {
|
|||
|
||||
foreach ( $fields as $field ) {
|
||||
$ret[] = array(
|
||||
'name' => $field->post_title,
|
||||
'value' => Extra_Fields::get_formatted_content( $field ),
|
||||
'name' => $field->post_title,
|
||||
'value' => Extra_Fields::get_formatted_content( $field ),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -190,29 +190,29 @@ class Enable_Mastodon_Apps {
|
|||
$acct = $item->get_url();
|
||||
}
|
||||
|
||||
$account = new Account();
|
||||
$account->id = \strval( $item->get__id() );
|
||||
$account->username = $item->get_preferred_username();
|
||||
$account->acct = $acct;
|
||||
$account->display_name = $item->get_name();
|
||||
$account->url = $item->get_url();
|
||||
$account->avatar = $item->get_icon_url();
|
||||
$account->avatar_static = $item->get_icon_url();
|
||||
$account->created_at = new DateTime( $item->get_published() );
|
||||
$account->last_status_at = new DateTime( $item->get_published() );
|
||||
$account->note = $item->get_summary();
|
||||
$account->header = $item->get_image_url();
|
||||
$account->header_static = $item->get_image_url();
|
||||
$account = new Account();
|
||||
$account->id = \strval( $item->get__id() );
|
||||
$account->username = $item->get_preferred_username();
|
||||
$account->acct = $acct;
|
||||
$account->display_name = $item->get_name();
|
||||
$account->url = $item->get_url();
|
||||
$account->avatar = $item->get_icon_url();
|
||||
$account->avatar_static = $item->get_icon_url();
|
||||
$account->created_at = new DateTime( $item->get_published() );
|
||||
$account->last_status_at = new DateTime( $item->get_published() );
|
||||
$account->note = $item->get_summary();
|
||||
$account->header = $item->get_image_url();
|
||||
$account->header_static = $item->get_image_url();
|
||||
$account->followers_count = 0;
|
||||
$account->following_count = 0;
|
||||
$account->statuses_count = 0;
|
||||
$account->bot = false;
|
||||
$account->locked = false;
|
||||
$account->group = false;
|
||||
$account->discoverable = false;
|
||||
$account->noindex = false;
|
||||
$account->fields = array();
|
||||
$account->emojis = array();
|
||||
$account->statuses_count = 0;
|
||||
$account->bot = false;
|
||||
$account->locked = false;
|
||||
$account->group = false;
|
||||
$account->discoverable = false;
|
||||
$account->noindex = false;
|
||||
$account->fields = array();
|
||||
$account->emojis = array();
|
||||
|
||||
return $account;
|
||||
},
|
||||
|
@ -260,7 +260,7 @@ class Enable_Mastodon_Apps {
|
|||
|
||||
public static function api_account_internal( $user_data, $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 ) ) {
|
||||
return $user_data;
|
||||
|
@ -269,21 +269,21 @@ class Enable_Mastodon_Apps {
|
|||
// convert user to account.
|
||||
$account = new Account();
|
||||
// even if we have a blog user, maintain the provided user_id so as not to confuse clients
|
||||
$account->id = (int) $user_id;
|
||||
$account->username = $user->get_preferred_username();
|
||||
$account->acct = $account->username;
|
||||
$account->display_name = $user->get_name();
|
||||
$account->note = $user->get_summary();
|
||||
$account->id = (int) $user_id;
|
||||
$account->username = $user->get_preferred_username();
|
||||
$account->acct = $account->username;
|
||||
$account->display_name = $user->get_name();
|
||||
$account->note = $user->get_summary();
|
||||
$account->source['note'] = wp_strip_all_tags( $account->note, true );
|
||||
$account->url = $user->get_url();
|
||||
$account->url = $user->get_url();
|
||||
|
||||
$icon = $user->get_icon();
|
||||
$account->avatar = $icon['url'];
|
||||
$icon = $user->get_icon();
|
||||
$account->avatar = $icon['url'];
|
||||
$account->avatar_static = $account->avatar;
|
||||
|
||||
$header = $user->get_image();
|
||||
if ( $header ) {
|
||||
$account->header = $header['url'];
|
||||
$account->header = $header['url'];
|
||||
$account->header_static = $account->header;
|
||||
}
|
||||
|
||||
|
@ -291,13 +291,13 @@ class Enable_Mastodon_Apps {
|
|||
|
||||
$post_types = \get_option( 'activitypub_support_post_types', array( 'post' ) );
|
||||
$query_args = array(
|
||||
'post_type' => $post_types,
|
||||
'post_type' => $post_types,
|
||||
'posts_per_page' => 1,
|
||||
);
|
||||
if ( $user_id > 0 ) {
|
||||
$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->fields = self::get_extra_fields( $user_id_to_use );
|
||||
|
@ -331,11 +331,11 @@ class Enable_Mastodon_Apps {
|
|||
$acct = substr( $acct, 5 );
|
||||
}
|
||||
|
||||
$account->id = $acct;
|
||||
$account->username = $acct;
|
||||
$account->acct = $acct;
|
||||
$account->display_name = $data['name'];
|
||||
$account->url = $uri;
|
||||
$account->id = $acct;
|
||||
$account->username = $acct;
|
||||
$account->acct = $acct;
|
||||
$account->display_name = $data['name'];
|
||||
$account->url = $uri;
|
||||
|
||||
if ( ! empty( $data['summary'] ) ) {
|
||||
$account->note = $data['summary'];
|
||||
|
@ -412,20 +412,20 @@ class Enable_Mastodon_Apps {
|
|||
$acct = $follower->get_url();
|
||||
}
|
||||
|
||||
$account = new Account();
|
||||
$account->id = \strval( $follower->get__id() );
|
||||
$account->username = $follower->get_preferred_username();
|
||||
$account->acct = $acct;
|
||||
$account->display_name = $follower->get_name();
|
||||
$account->url = $follower->get_url();
|
||||
$account->uri = $follower->get_id();
|
||||
$account->avatar = $follower->get_icon_url();
|
||||
$account->avatar_static = $follower->get_icon_url();
|
||||
$account->created_at = new DateTime( $follower->get_published() );
|
||||
$account = new Account();
|
||||
$account->id = \strval( $follower->get__id() );
|
||||
$account->username = $follower->get_preferred_username();
|
||||
$account->acct = $acct;
|
||||
$account->display_name = $follower->get_name();
|
||||
$account->url = $follower->get_url();
|
||||
$account->uri = $follower->get_id();
|
||||
$account->avatar = $follower->get_icon_url();
|
||||
$account->avatar_static = $follower->get_icon_url();
|
||||
$account->created_at = new DateTime( $follower->get_published() );
|
||||
$account->last_status_at = new DateTime( $follower->get_published() );
|
||||
$account->note = $follower->get_summary();
|
||||
$account->header = $follower->get_image_url();
|
||||
$account->header_static = $follower->get_image_url();
|
||||
$account->note = $follower->get_summary();
|
||||
$account->header = $follower->get_image_url();
|
||||
$account->header_static = $follower->get_image_url();
|
||||
|
||||
$search_data['accounts'][] = $account;
|
||||
}
|
||||
|
@ -456,7 +456,7 @@ class Enable_Mastodon_Apps {
|
|||
return null;
|
||||
}
|
||||
|
||||
$status = new Status();
|
||||
$status = new Status();
|
||||
$status->id = $object['id'];
|
||||
$status->created_at = new DateTime( $object['published'] );
|
||||
$status->content = $object['content'];
|
||||
|
@ -480,20 +480,20 @@ class Enable_Mastodon_Apps {
|
|||
$status->media_attachments = array_map(
|
||||
function ( $attachment ) {
|
||||
$default_attachment = array(
|
||||
'url' => null,
|
||||
'url' => null,
|
||||
'mediaType' => null,
|
||||
'name' => null,
|
||||
'width' => 0,
|
||||
'height' => 0,
|
||||
'blurhash' => null,
|
||||
'name' => null,
|
||||
'width' => 0,
|
||||
'height' => 0,
|
||||
'blurhash' => null,
|
||||
);
|
||||
|
||||
$attachment = array_merge( $default_attachment, $attachment );
|
||||
|
||||
$media_attachment = new Media_Attachment();
|
||||
$media_attachment->id = $attachment['url'];
|
||||
$media_attachment->type = strtok( $attachment['mediaType'], '/' );
|
||||
$media_attachment->url = $attachment['url'];
|
||||
$media_attachment = new Media_Attachment();
|
||||
$media_attachment->id = $attachment['url'];
|
||||
$media_attachment->type = strtok( $attachment['mediaType'], '/' );
|
||||
$media_attachment->url = $attachment['url'];
|
||||
$media_attachment->preview_url = $attachment['url'];
|
||||
$media_attachment->description = $attachment['name'];
|
||||
if ( $attachment['blurhash'] ) {
|
||||
|
@ -545,8 +545,8 @@ class Enable_Mastodon_Apps {
|
|||
$limit = 40;
|
||||
}
|
||||
$activitypub_statuses = array();
|
||||
$url = $outbox['first'];
|
||||
$tries = 0;
|
||||
$url = $outbox['first'];
|
||||
$tries = 0;
|
||||
while ( $url ) {
|
||||
if ( ++$tries > 3 ) {
|
||||
break;
|
||||
|
@ -557,7 +557,7 @@ class Enable_Mastodon_Apps {
|
|||
return $statuses;
|
||||
}
|
||||
|
||||
$new_statuses = array_map(
|
||||
$new_statuses = array_map(
|
||||
function ( $item ) use ( $account, $args ) {
|
||||
if ( $args['exclude_replies'] ) {
|
||||
if ( isset( $item['object']['inReplyTo'] ) && $item['object']['inReplyTo'] ) {
|
||||
|
@ -569,7 +569,7 @@ class Enable_Mastodon_Apps {
|
|||
$posts['orderedItems']
|
||||
);
|
||||
$activitypub_statuses = array_merge( $activitypub_statuses, array_filter( $new_statuses ) );
|
||||
$url = $posts['next'];
|
||||
$url = $posts['next'];
|
||||
|
||||
if ( count( $activitypub_statuses ) >= $limit ) {
|
||||
break;
|
||||
|
@ -586,7 +586,7 @@ class Enable_Mastodon_Apps {
|
|||
}
|
||||
|
||||
$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'] ) ) {
|
||||
return $context;
|
||||
}
|
||||
|
@ -602,7 +602,7 @@ class Enable_Mastodon_Apps {
|
|||
}
|
||||
|
||||
$account = self::get_account_for_actor( $status['attributedTo'] );
|
||||
$status = self::activity_to_status( $status, $account );
|
||||
$status = self::activity_to_status( $status, $account );
|
||||
if ( $status ) {
|
||||
$context['descendants'][ $status->id ] = $status;
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ class Jetpack {
|
|||
if ( ! is_array( $whitelist ) ) {
|
||||
return $whitelist;
|
||||
}
|
||||
$activitypub_meta_keys = [
|
||||
$activitypub_meta_keys = array(
|
||||
'activitypub_user_id',
|
||||
'activitypub_inbox',
|
||||
'activitypub_actor_json',
|
||||
];
|
||||
);
|
||||
return \array_merge( $whitelist, $activitypub_meta_keys );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class Nodeinfo {
|
|||
* Extend NodeInfo data
|
||||
*
|
||||
* @param array $nodeinfo NodeInfo data
|
||||
* @param string The NodeInfo Version
|
||||
* @param string $version The NodeInfo Version
|
||||
*
|
||||
* @return array The extended array
|
||||
*/
|
||||
|
@ -74,7 +74,7 @@ class Nodeinfo {
|
|||
*/
|
||||
public static function add_wellknown_nodeinfo_data( $data ) {
|
||||
$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' ),
|
||||
);
|
||||
|
||||
|
|
79
phpcs.xml
79
phpcs.xml
|
@ -5,74 +5,39 @@
|
|||
<file>./includes/</file>
|
||||
<file>./integration/</file>
|
||||
<file>./build/</file>
|
||||
|
||||
<exclude-pattern>*\.(inc|css|js|svg)</exclude-pattern>
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
<exclude-pattern>*/node_modules/*</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"/>
|
||||
<config name="testVersion" value="7.0-"/>
|
||||
<rule ref="PHPCompatibilityWP"/>
|
||||
<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"/>
|
||||
<arg value="ps"/>
|
||||
<arg name="parallel" value="20"/>
|
||||
<rule ref="VariableAnalysis"/>
|
||||
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable">
|
||||
<type>error</type>
|
||||
|
||||
<rule ref="WordPress">
|
||||
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
|
||||
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter"/>
|
||||
<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 ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
|
||||
<properties>
|
||||
<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 ref="VariableAnalysis">
|
||||
<exclude name="VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="WordPress.WP.Capabilities">
|
||||
<properties>
|
||||
<property name="custom_capabilities" type="array">
|
||||
|
|
Loading…
Reference in a new issue