From 06250909896e7bd3a6ab35aca90b5cfe63602ec4 Mon Sep 17 00:00:00 2001
From: Matt Wiebe )|(?<=
)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' );
\defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9\._-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
-\defined( 'ACTIVITYPUB_URL_REGEXP' ) || \define( 'ACTIVITYPUB_URL_REGEXP', '(www.|http:|https:)+[^\s]+[\w\/]' );
+\defined( 'ACTIVITYPUB_URL_REGEXP' ) || \define( 'ACTIVITYPUB_URL_REGEXP', '(https?:|www\.)\S+[\w\/]' );
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "[ap_title]
\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" );
\defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) || \define( 'ACTIVITYPUB_AUTHORIZED_FETCH', false );
\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
diff --git a/includes/class-link.php b/includes/class-link.php
index 2e48d1be..52a81400 100644
--- a/includes/class-link.php
+++ b/includes/class-link.php
@@ -62,7 +62,7 @@ class Link {
$result[0] = 'https://' . $result[0];
}
$parsed_url = \wp_parse_url( html_entity_decode( $result[0] ) );
- if ( ! $parsed_url ) {
+ if ( ! $parsed_url || empty( $parsed_url['host'] ) ) {
return $result[0];
}
diff --git a/tests/test-class-activitypub-link.php b/tests/test-class-activitypub-link.php
index e966ce89..bfe124db 100644
--- a/tests/test-class-activitypub-link.php
+++ b/tests/test-class-activitypub-link.php
@@ -37,6 +37,8 @@ ENDPRE;
array( 'hello https://www.test.de test', 'hello https://www.test.de test' ),
array( 'hello www.test.de test', 'hello https://www.test.de test' ),
array( 'hello https://test:test@test.de test', 'hello https://test:test@test.de test' ),
+ array( 'wwwfoocom', 'wwwfoocom' ),
+ array( 'www.foo.com', 'https://www.foo.com' ),
array( $code, $code ),
array( $style, $style ),
array( $textarea, $textarea ),
From 00a57c39a4e844949bc4f64a45714d1f21d9645d Mon Sep 17 00:00:00 2001
From: Konstantin Obenland
%s
was replaced, this is often done by plugins.',
'activitypub'
@@ -186,7 +192,7 @@ class Health_Check {
);
}
- // try to access author URL
+ // Try to access author URL.
$response = \wp_remote_get(
$author_url,
array(
@@ -199,7 +205,7 @@ class Health_Check {
return new WP_Error(
'author_url_not_accessible',
\sprintf(
- // translators: %s: Author URL
+ // translators: %s: Author URL.
\__(
'Your author URL %s
is not accessible. Please check your WordPress setup or permalink structure. If the setup seems fine, maybe check if a plugin might restrict the access.',
'activitypub'
@@ -211,12 +217,12 @@ class Health_Check {
$response_code = \wp_remote_retrieve_response_code( $response );
- // check for redirects
+ // Check for redirects.
if ( \in_array( $response_code, array( 301, 302, 307, 308 ), true ) ) {
return new WP_Error(
'author_url_not_accessible',
\sprintf(
- // translators: %s: Author URL
+ // translators: %s: Author URL.
\__(
'Your author URL %s
is redirecting to another page, this is often done by SEO plugins like "Yoast SEO".',
'activitypub'
@@ -226,14 +232,14 @@ class Health_Check {
);
}
- // check if response is JSON
+ // Check if response is JSON.
$body = \wp_remote_retrieve_body( $response );
if ( ! \is_string( $body ) || ! \is_array( \json_decode( $body, true ) ) ) {
return new WP_Error(
'author_url_not_accessible',
\sprintf(
- // translators: %s: Author URL
+ // translators: %s: Author URL.
\__(
'Your author URL %s
does not return valid JSON for application/activity+json
. Please check if your hosting supports alternate Accept
headers.',
'activitypub'
@@ -260,7 +266,7 @@ class Health_Check {
$allowed = array( 'code' => array() );
$not_accessible = wp_kses(
- // translators: %s: Author URL
+ // translators: %s: Author URL.
\__(
'Your WebFinger endpoint %s
is not accessible. Please check your WordPress setup or permalink structure.',
'activitypub'
@@ -268,7 +274,7 @@ class Health_Check {
$allowed
);
$invalid_response = wp_kses(
- // translators: %s: Author URL
+ // translators: %s: Author URL.
\__(
'Your WebFinger endpoint %s
does not return valid JSON for application/jrd+json
.',
'activitypub'
@@ -282,7 +288,7 @@ class Health_Check {
$url->get_error_data()['data']
),
'webfinger_url_invalid_response' => \sprintf(
- // translators: %s: Author URL
+ // translators: %s: Author URL.
$invalid_response,
$url->get_error_data()['data']
),
@@ -291,6 +297,7 @@ class Health_Check {
if ( isset( $health_messages[ $url->get_error_code() ] ) ) {
$message = $health_messages[ $url->get_error_code() ];
}
+
return new WP_Error(
$url->get_error_code(),
$message,
@@ -304,7 +311,7 @@ class Health_Check {
/**
* Retrieve the URL to the author page for the user with the ID provided.
*
- * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
+ * @global \WP_Rewrite $wp_rewrite WordPress rewrite component.
*
* @param int $author_id Author ID.
* @param string $author_nicename Optional. The author's nicename (slug). Default empty.
@@ -313,6 +320,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();
diff --git a/includes/class-http.php b/includes/class-http.php
index 7cc5f9ae..133a3469 100644
--- a/includes/class-http.php
+++ b/includes/class-http.php
@@ -1,11 +1,15 @@
$code ) );
}
+ /**
+ * Action to save the response of the remote POST request.
+ *
+ * @param array|WP_Error $response The response of the remote POST request.
+ * @param string $url The URL endpoint.
+ * @param string $body The Post Body.
+ * @param int $user_id The WordPress User-ID.
+ */
\do_action( 'activitypub_safe_remote_post_response', $response, $url, $body, $user_id );
return $response;
}
/**
- * Send a GET Request with the needed HTTP Headers
+ * Send a GET Request with the needed HTTP Headers.
*
- * @param string $url The URL endpoint
- * @param bool|int $cached If the result should be cached, or its duration. Default: 1hr.
+ * @param string $url The URL endpoint.
+ * @param bool|int $cached Optional. Whether the result should be cached, or its duration. Default false.
*
- * @return array|WP_Error The GET Response or an WP_ERROR
+ * @return array|WP_Error The GET Response or a WP_Error.
*/
public static function get( $url, $cached = false ) {
\do_action( 'activitypub_pre_http_get', $url );
@@ -80,6 +92,12 @@ class Http {
$response = \get_transient( $transient_key );
if ( $response ) {
+ /**
+ * Action to save the response of the remote GET request.
+ *
+ * @param array|WP_Error $response The response of the remote GET request.
+ * @param string $url The URL endpoint.
+ */
\do_action( 'activitypub_safe_remote_get_response', $response, $url );
return $response;
@@ -118,6 +136,12 @@ class Http {
$response = new WP_Error( $code, __( 'Failed HTTP Request', 'activitypub' ), array( 'status' => $code ) );
}
+ /**
+ * Action to save the response of the remote GET request.
+ *
+ * @param array|WP_Error $response The response of the remote GET request.
+ * @param string $url The URL endpoint.
+ */
\do_action( 'activitypub_safe_remote_get_response', $response, $url );
if ( $cached ) {
@@ -139,6 +163,11 @@ class Http {
* @return bool True if the URL is a tombstone.
*/
public static function is_tombstone( $url ) {
+ /**
+ * Action before checking if the URL is a tombstone.
+ *
+ * @param string $url The URL to check.
+ */
\do_action( 'activitypub_pre_http_is_tombstone', $url );
$response = \wp_safe_remote_get( $url );
@@ -151,15 +180,22 @@ class Http {
return false;
}
+ /**
+ * Generate a cache key for the URL.
+ *
+ * @param string $url The URL to generate the cache key for.
+ *
+ * @return string The cache key.
+ */
public static function generate_cache_key( $url ) {
return 'activitypub_http_' . \md5( $url );
}
/**
- * Requests the Data from the Object-URL or Object-Array
+ * Requests the Data from the Object-URL or Object-Array.
*
* @param array|string $url_or_object The Object or the Object URL.
- * @param bool $cached If the result should be cached.
+ * @param bool $cached Optional. Whether the result should be cached. Default true.
*
* @return array|WP_Error The Object data as array or WP_Error on failure.
*/
@@ -204,7 +240,7 @@ class Http {
$transient_key = self::generate_cache_key( $url );
- // only check the cache if needed.
+ // Only check the cache if needed.
if ( $cached ) {
$data = \get_transient( $transient_key );
diff --git a/includes/class-link.php b/includes/class-link.php
index 52a81400..3c53f3bb 100644
--- a/includes/class-link.php
+++ b/includes/class-link.php
@@ -1,61 +1,66 @@
'ID' ) ) as $user_id ) {
$followers = get_user_meta( $user_id, 'activitypub_followers', true );
@@ -210,9 +208,7 @@ class Migration {
}
/**
- * Clear the cache after updating to 1.3.0
- *
- * @return void
+ * Clear the cache after updating to 1.3.0.
*/
private static function migrate_from_1_2_0() {
$user_ids = \get_users(
@@ -228,9 +224,7 @@ class Migration {
}
/**
- * Unschedule Hooks after updating to 2.0.0
- *
- * @return void
+ * Unschedule Hooks after updating to 2.0.0.
*/
private static function migrate_from_2_0_0() {
wp_clear_scheduled_hook( 'activitypub_send_post_activity' );
@@ -249,19 +243,15 @@ class Migration {
/**
* Add the ActivityPub capability to all users that can publish posts
- * Delete old meta to store followers
- *
- * @return void
+ * Delete old meta to store followers.
*/
private static function migrate_from_2_2_0() {
- // add the ActivityPub capability to all users that can publish posts
+ // Add the ActivityPub capability to all users that can publish posts.
self::add_activitypub_capability();
}
/**
- * Rename DB fields
- *
- * @return void
+ * Rename DB fields.
*/
private static function migrate_from_2_6_0() {
wp_cache_flush();
@@ -273,30 +263,26 @@ class Migration {
}
/**
- * Set the defaults needed for the plugin to work
+ * Set the defaults needed for the plugin to work.
*
- * * Add the ActivityPub capability to all users that can publish posts
- *
- * @return void
+ * Add the ActivityPub capability to all users that can publish posts.
*/
public static function add_default_settings() {
self::add_activitypub_capability();
}
/**
- * Add the ActivityPub capability to all users that can publish posts
- *
- * @return void
+ * Add the ActivityPub capability to all users that can publish posts.
*/
private static function add_activitypub_capability() {
- // get all WP_User objects that can publish posts
+ // Get all WP_User objects that can publish posts.
$users = \get_users(
array(
'capability__in' => array( 'publish_posts' ),
)
);
- // add ActivityPub capability to all users that can publish posts
+ // Add ActivityPub capability to all users that can publish posts.
foreach ( $users as $user ) {
$user->add_cap( 'activitypub' );
}
@@ -305,16 +291,16 @@ class Migration {
/**
* Rename meta keys.
*
- * @param string $old The old commentmeta key
- * @param string $new The new commentmeta key
+ * @param string $old_key The old comment meta key.
+ * @param string $new_key The new comment meta key.
*/
- private static function update_usermeta_key( $old, $new ) { // phpcs:ignore
+ private static function update_usermeta_key( $old_key, $new_key ) {
global $wpdb;
- $wpdb->update( // phpcs:ignore
+ $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
$wpdb->usermeta,
- array( 'meta_key' => $new ), // phpcs:ignore
- array( 'meta_key' => $old ), // phpcs:ignore
+ array( 'meta_key' => $new_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
+ array( 'meta_key' => $old_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
array( '%s' ),
array( '%s' )
);
@@ -323,16 +309,16 @@ class Migration {
/**
* Rename option keys.
*
- * @param string $old The old option key
- * @param string $new The new option key
+ * @param string $old_key The old option key.
+ * @param string $new_key The new option key.
*/
- private static function update_options_key( $old, $new ) { // phpcs:ignore
+ private static function update_options_key( $old_key, $new_key ) {
global $wpdb;
- $wpdb->update( // phpcs:ignore
+ $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
$wpdb->options,
- array( 'option_name' => $new ), // phpcs:ignore
- array( 'option_name' => $old ), // phpcs:ignore
+ array( 'option_name' => $new_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
+ array( 'option_name' => $old_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
array( '%s' ),
array( '%s' )
);
diff --git a/includes/class-notification.php b/includes/class-notification.php
index 3aed0207..bab72774 100644
--- a/includes/class-notification.php
+++ b/includes/class-notification.php
@@ -1,4 +1,9 @@
user_id ) {
return;
}
@@ -211,7 +207,7 @@ class Scheduler {
return;
}
- // check if comment should be federated or not
+ // Check if comment should be federated or not.
if ( ! should_comment_be_federated( $comment ) ) {
return;
}
@@ -226,9 +222,7 @@ class Scheduler {
}
/**
- * Update followers
- *
- * @return void
+ * Update followers.
*/
public static function update_followers() {
$number = 5;
@@ -237,6 +231,11 @@ class Scheduler {
$number = 50;
}
+ /**
+ * Filter the number of followers to update.
+ *
+ * @param int $number The number of followers to update.
+ */
$number = apply_filters( 'activitypub_update_followers_number', $number );
$followers = Followers::get_outdated_followers( $number );
@@ -253,9 +252,7 @@ class Scheduler {
}
/**
- * Cleanup followers
- *
- * @return void
+ * Cleanup followers.
*/
public static function cleanup_followers() {
$number = 5;
@@ -264,6 +261,11 @@ class Scheduler {
$number = 50;
}
+ /**
+ * Filter the number of followers to clean up.
+ *
+ * @param int $number The number of followers to clean up.
+ */
$number = apply_filters( 'activitypub_update_followers_number', $number );
$followers = Followers::get_faulty_followers( $number );
@@ -292,18 +294,17 @@ class Scheduler {
/**
* Send a profile update when relevant user meta is updated.
*
- * @param int $meta_id Meta ID being updated.
- * @param int $user_id User ID being updated.
+ * @param int $meta_id Meta ID being updated.
+ * @param int $user_id User ID being updated.
* @param string $meta_key Meta key being updated.
- *
- * @return void
*/
public static function user_meta_update( $meta_id, $user_id, $meta_key ) {
- // don't bother if the user can't publish
+ // Don't bother if the user can't publish.
if ( ! \user_can( $user_id, 'activitypub' ) ) {
return;
}
- // the user meta fields that affect a profile.
+
+ // The user meta fields that affect a profile.
$fields = array(
'activitypub_description',
'activitypub_header_image',
@@ -319,12 +320,10 @@ class Scheduler {
/**
* Send a profile update when a user is updated.
*
- * @param int $user_id User ID being updated.
- *
- * @return void
+ * @param int $user_id User ID being updated.
*/
public static function user_update( $user_id ) {
- // don't bother if the user can't publish
+ // Don't bother if the user can't publish.
if ( ! \user_can( $user_id, 'activitypub' ) ) {
return;
}
@@ -335,7 +334,7 @@ class Scheduler {
/**
* Theme mods only have a dynamic filter so we fudge it like this.
*
- * @param mixed $value
+ * @param mixed $value Optional. The value to be updated. Default null.
*
* @return mixed
*/
diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php
index 06bb796e..eb9c5135 100644
--- a/includes/class-shortcodes.php
+++ b/includes/class-shortcodes.php
@@ -1,12 +1,18 @@
post_type ) {
- // get title of attachment with fallback to alt text.
+ // Get title of attachment with fallback to alt text.
$content = wp_get_attachment_caption( $item->ID );
if ( empty( $content ) ) {
$content = get_post_meta( $item->ID, '_wp_attachment_image_alt', true );
@@ -154,7 +156,7 @@ class Shortcodes {
$content = wp_filter_content_tags( $content );
}
- // replace script and style elements
+ // Replace script and style elements.
$content = \preg_replace( '@<(script|style)[^>]*?>.*?\\1>@si', '', $content );
$content = strip_shortcodes( $content );
$content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
@@ -166,7 +168,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_permalink' Shortcode
+ * Generates output for the 'ap_permalink' Shortcode.
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
@@ -200,7 +202,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_shortlink' Shortcode
+ * Generates output for the 'ap_shortlink' Shortcode.
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
@@ -234,7 +236,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_image' Shortcode
+ * Generates output for the 'ap_image' Shortcode.
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
@@ -277,7 +279,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_hashcats' Shortcode
+ * Generates output for the 'ap_hashcats' Shortcode.
*
* @return string The post categories as hashtags.
*/
@@ -308,7 +310,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_author' Shortcode
+ * Generates output for the 'ap_author' Shortcode.
*
* @return string The author name.
*/
@@ -330,7 +332,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_authorurl' Shortcode
+ * Generates output for the 'ap_authorurl' Shortcode.
*
* @return string The author URL.
*/
@@ -352,7 +354,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_blogurl' Shortcode
+ * Generates output for the 'ap_blogurl' Shortcode.
*
* @return string The site URL.
*/
@@ -361,7 +363,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_blogname' Shortcode
+ * Generates output for the 'ap_blogname' Shortcode.
*
* @return string
*/
@@ -370,7 +372,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_blogdesc' Shortcode
+ * Generates output for the 'ap_blogdesc' Shortcode.
*
* @return string The site description.
*/
@@ -379,7 +381,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_date' Shortcode
+ * Generates output for the 'ap_date' Shortcode.
*
* @return string The post date.
*/
@@ -403,7 +405,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_time' Shortcode
+ * Generates output for the 'ap_time' Shortcode.
*
* @return string The post time.
*/
@@ -427,7 +429,7 @@ class Shortcodes {
}
/**
- * Generates output for the 'ap_datetime' Shortcode
+ * Generates output for the 'ap_datetime' Shortcode.
*
* @return string The post date/time.
*/
@@ -457,7 +459,7 @@ class Shortcodes {
* Checks if item (WP_Post) is "public", a supported post type
* and not password protected.
*
- * @return null|WP_Post The WordPress item.
+ * @return null|\WP_Post The WordPress item.
*/
protected static function get_item() {
$post = \get_post();
diff --git a/includes/class-signature.php b/includes/class-signature.php
index 07831583..aa2a109b 100644
--- a/includes/class-signature.php
+++ b/includes/class-signature.php
@@ -1,4 +1,10 @@
$detail['key'],
);
- // persist keys
+ // Persist keys.
\add_option( $option_key, $key_pair );
return $key_pair;
@@ -135,7 +141,7 @@ class Signature {
if ( $user_id > 0 ) {
$user = \get_userdata( $user_id );
- // sanatize username because it could include spaces and special chars
+ // Sanitize username because it could include spaces and special chars.
$id = sanitize_title( $user->user_login );
}
@@ -176,13 +182,13 @@ class Signature {
}
/**
- * Generates the Signature for a HTTP Request
+ * Generates the Signature for an HTTP Request.
*
* @param int $user_id The WordPress User ID.
* @param string $http_method The HTTP method.
* @param string $url The URL to send the request to.
* @param string $date The date the request is sent.
- * @param string $digest The digest of the request body.
+ * @param string $digest Optional. The digest of the request body. Default null.
*
* @return string The signature.
*/
@@ -195,12 +201,12 @@ class Signature {
$host = $url_parts['host'];
$path = '/';
- // add path
+ // Add path.
if ( ! empty( $url_parts['path'] ) ) {
$path = $url_parts['path'];
}
- // add query
+ // Add query.
if ( ! empty( $url_parts['query'] ) ) {
$path .= '?' . $url_parts['query'];
}
@@ -231,18 +237,18 @@ class Signature {
*
* @param WP_REST_Request|array $request The request object or $_SERVER array.
*
- * @return mixed A boolean or WP_Error.
+ * @return bool|WP_Error A boolean or WP_Error.
*/
public static function verify_http_signature( $request ) {
- if ( is_object( $request ) ) { // REST Request object
- // check if route starts with "index.php"
+ if ( is_object( $request ) ) { // REST Request object.
+ // Check if route starts with "index.php".
if ( str_starts_with( $request->get_route(), '/index.php' ) || ! rest_get_url_prefix() ) {
$route = $request->get_route();
} else {
$route = '/' . rest_get_url_prefix() . '/' . ltrim( $request->get_route(), '/' );
}
- // fix route for subdirectory installs
+ // Fix route for subdirectory installs.
$path = \wp_parse_url( \get_home_url(), PHP_URL_PATH );
if ( \is_string( $path ) ) {
@@ -323,14 +329,14 @@ class Signature {
}
/**
- * Get public key from key_id
+ * Get public key from key_id.
*
* @param string $key_id The URL to the public key.
*
* @return WP_Error|string The public key or WP_Error.
*/
- public static function get_remote_key( $key_id ) { // phpcs:ignore
- $actor = get_remote_metadata_by_actor( strip_fragment_from_url( $key_id ) ); // phpcs:ignore
+ public static function get_remote_key( $key_id ) {
+ $actor = get_remote_metadata_by_actor( strip_fragment_from_url( $key_id ) );
if ( \is_wp_error( $actor ) ) {
return new WP_Error(
'activitypub_no_remote_profile_found',
@@ -349,9 +355,9 @@ class Signature {
}
/**
- * Gets the signature algorithm from the signature header
+ * Gets the signature algorithm from the signature header.
*
- * @param array $signature_block
+ * @param array $signature_block The signature block.
*
* @return string The signature algorithm.
*/
@@ -359,7 +365,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';
}
@@ -368,11 +374,11 @@ class Signature {
}
/**
- * Parses the Signature header
+ * Parses the Signature header.
*
* @param string $signature The signature header.
*
- * @return array signature parts
+ * @return array Signature parts.
*/
public static function parse_signature_header( $signature ) {
$parsed_header = array();
@@ -405,16 +411,17 @@ class Signature {
}
/**
- * Gets the header data from the included pseudo headers
+ * Gets the header data from the included pseudo headers.
*
* @param array $signed_headers The signed headers.
- * @param array $signature_block (pseudo-headers)
- * @param array $headers (http headers)
+ * @param array $signature_block The signature block.
+ * @param array $headers The HTTP headers.
*
* @return string signed headers for comparison
*/
public static function get_signed_data( $signed_headers, $signature_block, $headers ) {
$signed_data = '';
+
// This also verifies time-based values by returning false if any of these are out of range.
foreach ( $signed_headers as $header ) {
if ( 'host' === $header ) {
@@ -433,7 +440,7 @@ class Signature {
}
if ( '(created)' === $header ) {
if ( ! empty( $signature_block['(created)'] ) && \intval( $signature_block['(created)'] ) > \time() ) {
- // created in future
+ // Created in the future.
return false;
}
@@ -444,7 +451,7 @@ class Signature {
}
if ( '(expires)' === $header ) {
if ( ! empty( $signature_block['(expires)'] ) && \intval( $signature_block['(expires)'] ) < \time() ) {
- // expired in past
+ // Expired in the past.
return false;
}
@@ -454,7 +461,7 @@ class Signature {
}
}
if ( 'date' === $header ) {
- // allow a bit of leeway for misconfigured clocks.
+ // Allow a bit of leeway for misconfigured clocks.
$d = new DateTime( $headers[ $header ][0] );
$d->setTimeZone( new DateTimeZone( 'UTC' ) );
$c = $d->format( 'U' );
@@ -463,7 +470,7 @@ class Signature {
$dminus = time() - ( 3 * HOUR_IN_SECONDS );
if ( $c > $dplus || $c < $dminus ) {
- // time out of range
+ // Time out of range.
return false;
}
}
@@ -473,22 +480,22 @@ class Signature {
}
/**
- * Generates the digest for a HTTP Request
+ * Generates the digest for an HTTP Request.
*
* @param string $body The body of the request.
*
* @return string The digest.
*/
public static function generate_digest( $body ) {
- $digest = \base64_encode( \hash( 'sha256', $body, true ) ); // phpcs:ignore
+ $digest = \base64_encode( \hash( 'sha256', $body, true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
return "SHA-256=$digest";
}
/**
* Formats the $_SERVER to resemble the WP_REST_REQUEST array,
- * for use with verify_http_signature()
+ * for use with verify_http_signature().
*
- * @param array $_SERVER The $_SERVER array.
+ * @param array $server The $_SERVER array.
*
* @return array $request The formatted request array.
*/
diff --git a/includes/class-webfinger.php b/includes/class-webfinger.php
index f26de250..f6a189af 100644
--- a/includes/class-webfinger.php
+++ b/includes/class-webfinger.php
@@ -1,11 +1,17 @@
@' . \__( 'The Fediverse is a new word made of two words: "federation" + "universe"', 'activitypub' ) . '
' . '' . \__( 'It is a federated social network running on free open software on a myriad of computers across the globe. Many independent servers are interconnected and allow people to interact with one another. There\'s no one central site: you choose a server to register. This ensures some decentralization and sovereignty of data. Fediverse (also called Fedi) has no built-in advertisements, no tricky algorithms, no one big corporation dictating the rules. Instead we have small cozy communities of like-minded people. Welcome!', 'activitypub' ) . '
' . - '' . \__( 'For more informations please visit fediverse.party', 'activitypub' ) . '
' . + '' . \__( 'For more information please visit fediverse.party', 'activitypub' ) . '
' . '' . \__( 'ActivityPub is a decentralized social networking protocol based on the ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended standard published by the W3C Social Web Working Group. It provides a client to server API for creating, updating and deleting content, as well as a federated server to server API for delivering notifications and subscribing to content.', 'activitypub' ) . '
' . '' . \__( 'WebFinger is used to discover information about people or other entities on the Internet that are identified by a URI using standard Hypertext Transfer Protocol (HTTP) methods over a secure transport. A WebFinger resource returns a JavaScript Object Notation (JSON) object describing the entity that is queried. The JSON object is referred to as the JSON Resource Descriptor (JRD).', 'activitypub' ) . '
' . '' . \__( 'For a person, the type of information that might be discoverable via WebFinger includes a personal profile address, identity service, telephone number, or preferred avatar. For other entities on the Internet, a WebFinger resource might return JRDs containing link relations that enable a client to discover, for example, that a printer can print in color on A4 paper, the physical location of a server, or other static information.', 'activitypub' ) . '
' . '' . \__( 'On Mastodon [and other Plattforms], user profiles can be hosted either locally on the same website as yours, or remotely on a completely different website. The same username may be used on a different domain. Therefore, a Mastodon user\'s full mention consists of both the username and the domain, in the form @username@domain
. In practical terms, @user@example.com
is not the same as @user@example.org
. If the domain is not included, Mastodon will try to find a local user named @username
. However, in order to deliver to someone over ActivityPub, the @username@domain
mention is not enough – mentions must be translated to an HTTPS URI first, so that the remote actor\'s inbox and outbox can be found. (This paragraph is copied from the Mastodon Documentation)', 'activitypub' ) . '
' . \__( 'For more informations please visit webfinger.net', 'activitypub' ) . '
' . + '' . \__( 'For more information please visit webfinger.net', 'activitypub' ) . '
' . '' . \__( 'NodeInfo is an effort to create a standardized way of exposing metadata about a server running one of the distributed social networks. The two key goals are being able to get better insights into the user base of distributed social networking and the ability to build tools that allow users to choose the best fitting software and server for their needs.', 'activitypub' ) . '
' . - '' . \__( 'For more informations please visit nodeinfo.diaspora.software', 'activitypub' ) . '
', + '' . \__( 'For more information please visit nodeinfo.diaspora.software', 'activitypub' ) . '
', ) ); diff --git a/includes/model/class-application.php b/includes/model/class-application.php index a0bda431..b7d38af2 100644 --- a/includes/model/class-application.php +++ b/includes/model/class-application.php @@ -1,4 +1,10 @@ + * @var string */ protected $webfinger; + /** + * Returns the type of the object. + * + * @return string The type of the object. + */ public function get_type() { return 'Application'; } + /** + * Returns whether the Application manually approves followers. + * + * @return true Whether the Application manually approves followers. + */ public function get_manually_approves_followers() { return true; } + /** + * Returns the ID of the Application. + * + * @return string The ID of the Application. + */ public function get_id() { return get_rest_url_by_path( 'application' ); } @@ -73,10 +97,20 @@ class Application extends Actor { return $this->get_url(); } + /** + * Get the Username. + * + * @return string The Username. + */ public function get_name() { return 'application'; } + /** + * Get the preferred username. + * + * @return string The preferred username. + */ public function get_preferred_username() { return $this->get_name(); } @@ -87,10 +121,10 @@ class Application extends Actor { * @return array The User-Icon. */ public function get_icon() { - // try site icon first + // Try site icon first. $icon_id = get_option( 'site_icon' ); - // try custom logo second + // Try custom logo second. if ( ! $icon_id ) { $icon_id = get_theme_mod( 'custom_logo' ); } @@ -105,7 +139,7 @@ class Application extends Actor { } if ( ! $icon_url ) { - // fallback to default icon + // Fallback to default icon. $icon_url = plugins_url( '/assets/img/wp-logo.png', ACTIVITYPUB_PLUGIN_FILE ); } @@ -131,6 +165,11 @@ class Application extends Actor { return null; } + /** + * Get the first published date. + * + * @return string The published date. + */ public function get_published() { $first_post = new WP_Query( array( @@ -176,6 +215,11 @@ class Application extends Actor { return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST ); } + /** + * Returns the public key. + * + * @return array The public key. + */ public function get_public_key() { return array( 'id' => $this->get_id() . '#main-key', @@ -185,9 +229,9 @@ class Application extends Actor { } /** - * Get the User-Description. + * Get the User description. * - * @return string The User-Description. + * @return string The User description. */ public function get_summary() { return \wpautop( @@ -198,6 +242,11 @@ class Application extends Actor { ); } + /** + * Returns the canonical URL of the object. + * + * @return string|null The canonical URL of the object. + */ public function get_canonical_url() { return \home_url(); } diff --git a/includes/model/class-blog.php b/includes/model/class-blog.php index aff08831..3cbd6f91 100644 --- a/includes/model/class-blog.php +++ b/includes/model/class-blog.php @@ -1,8 +1,13 @@ + * @var string */ protected $webfinger; /** - * If the User is discoverable. + * Whether the User is discoverable. * * @see https://docs.joinmastodon.org/spec/activitypub/#discoverable * @@ -74,7 +81,7 @@ class Blog extends Actor { protected $discoverable; /** - * Restrict posting to mods + * Restrict posting to mods. * * @see https://join-lemmy.org/docs/contributors/05-federation.html * @@ -82,18 +89,28 @@ class Blog extends Actor { */ protected $posting_restricted_to_mods; + /** + * Whether the User manually approves followers. + * + * @return false + */ public function get_manually_approves_followers() { return false; } + /** + * Whether the User is discoverable. + * + * @return boolean + */ public function get_discoverable() { return true; } /** - * Get the User-ID. + * Get the User ID. * - * @return string The User-ID. + * @return string The User ID. */ public function get_id() { return $this->get_url(); @@ -115,9 +132,9 @@ class Blog extends Actor { } /** - * Get the User-Name. + * Get the Username. * - * @return string The User-Name. + * @return string The Username. */ public function get_name() { return \wp_strip_all_tags( @@ -130,9 +147,9 @@ class Blog extends Actor { } /** - * Get the User-Description. + * Get the User description. * - * @return string The User-Description. + * @return string The User description. */ public function get_summary() { $summary = \get_option( 'activitypub_blog_description', null ); @@ -150,9 +167,9 @@ class Blog extends Actor { } /** - * Get the User-Url. + * Get the User url. * - * @return string The User-Url. + * @return string The User url. */ public function get_url() { return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() ); @@ -173,12 +190,12 @@ class Blog extends Actor { * @return string The auto-generated Username. */ public static function get_default_username() { - // check if domain host has a subdomain + // Check if domain host has a subdomain. $host = \wp_parse_url( \get_home_url(), \PHP_URL_HOST ); $host = \preg_replace( '/^www\./i', '', $host ); /** - * Filter the default blog username. + * Filters the default blog username. * * @param string $host The default username. */ @@ -186,9 +203,9 @@ class Blog extends Actor { } /** - * Get the preferred User-Name. + * Get the preferred Username. * - * @return string The User-Name. + * @return string The Username. */ public function get_preferred_username() { $username = \get_option( 'activitypub_blog_identifier' ); @@ -201,15 +218,15 @@ class Blog extends Actor { } /** - * Get the User-Icon. + * Get the User icon. * - * @return array The User-Icon. + * @return array The User icon. */ public function get_icon() { - // try site_logo, falling back to site_icon, first + // Try site_logo, falling back to site_icon, first. $icon_id = get_option( 'site_icon' ); - // try custom logo second + // Try custom logo second. if ( ! $icon_id ) { $icon_id = get_theme_mod( 'custom_logo' ); } @@ -224,7 +241,7 @@ class Blog extends Actor { } if ( ! $icon_url ) { - // fallback to default icon + // Fallback to default icon. $icon_url = plugins_url( '/assets/img/wp-logo.png', ACTIVITYPUB_PLUGIN_FILE ); } @@ -261,6 +278,11 @@ class Blog extends Actor { return null; } + /** + * Get the published date. + * + * @return string The published date. + */ public function get_published() { $first_post = new WP_Query( array( @@ -279,10 +301,20 @@ class Blog extends Actor { return \gmdate( 'Y-m-d\TH:i:s\Z', $time ); } + /** + * Get the canonical URL. + * + * @return string|null The canonical URL. + */ public function get_canonical_url() { return \home_url(); } + /** + * Get the Moderators endpoint. + * + * @return string|null The Moderators endpoint. + */ public function get_moderators() { if ( is_single_user() || 'Group' !== $this->get_type() ) { return null; @@ -291,6 +323,11 @@ class Blog extends Actor { return get_rest_url_by_path( 'collections/moderators' ); } + /** + * Get attributedTo value. + * + * @return string|null The attributedTo value. + */ public function get_attributed_to() { if ( is_single_user() || 'Group' !== $this->get_type() ) { return null; @@ -299,6 +336,11 @@ class Blog extends Actor { return get_rest_url_by_path( 'collections/moderators' ); } + /** + * Get the public key information. + * + * @return array The public key. + */ public function get_public_key() { return array( 'id' => $this->get_id() . '#main-key', @@ -307,6 +349,11 @@ class Blog extends Actor { ); } + /** + * Returns whether posting is restricted to mods. + * + * @return bool|null True if posting is restricted to mods, null if not applicable. + */ public function get_posting_restricted_to_mods() { if ( 'Group' === $this->get_type() ) { return true; @@ -351,6 +398,11 @@ class Blog extends Actor { return get_rest_url_by_path( sprintf( 'actors/%d/following', $this->get__id() ) ); } + /** + * Returns endpoints. + * + * @return array|null The endpoints. + */ public function get_endpoints() { $endpoints = null; @@ -381,6 +433,11 @@ class Blog extends Actor { return get_rest_url_by_path( sprintf( 'actors/%d/collections/featured', $this->get__id() ) ); } + /** + * Returns whether the site is indexable. + * + * @return bool Whether the site is indexable. + */ public function get_indexable() { if ( is_blog_public() ) { return true; @@ -390,7 +447,7 @@ class Blog extends Actor { } /** - * Update the User-Name. + * Update the Username. * * @param mixed $value The new value. * @return bool True if the attribute was updated, false otherwise. @@ -400,7 +457,7 @@ class Blog extends Actor { } /** - * Update the User-Description. + * Update the User description. * * @param mixed $value The new value. * @return bool True if the attribute was updated, false otherwise. @@ -410,7 +467,7 @@ class Blog extends Actor { } /** - * Update the User-Icon. + * Update the User icon. * * @param mixed $value The new value. * @return bool True if the attribute was updated, false otherwise. @@ -436,11 +493,11 @@ class Blog extends Actor { } /** - * Get the User - Hashtags . + * Get the User - Hashtags. * * @see https://docs.joinmastodon.org/spec/activitypub/#Hashtag * - * @return array The User - Hashtags . + * @return array The User - Hashtags. */ public function get_tag() { $hashtags = array(); diff --git a/includes/model/class-follower.php b/includes/model/class-follower.php index 21565911..af30303d 100644 --- a/includes/model/class-follower.php +++ b/includes/model/class-follower.php @@ -1,13 +1,18 @@ summary ) ) { @@ -51,7 +56,7 @@ class Follower extends Actor { * Getter for URL attribute. * * Falls back to ID, if no URL is set. This is relevant for - * Plattforms like Lemmy, where the ID is the URL. + * Platforms like Lemmy, where the ID is the URL. * * @return string The URL. */ @@ -65,8 +70,6 @@ class Follower extends Actor { /** * Reset (delete) all errors. - * - * @return void */ public function reset_errors() { delete_post_meta( $this->_id, 'activitypub_errors' ); @@ -103,21 +106,19 @@ class Follower extends Actor { } /** - * Update the current Follower-Object. - * - * @return void + * Update the current Follower object. */ public function update() { $this->save(); } /** - * Validate the current Follower-Object. + * Validate the current Follower object. * * @return boolean True if the verification was successful. */ public function is_valid() { - // the minimum required attributes + // The minimum required attributes. $required_attributes = array( 'id', 'preferredUsername', @@ -136,9 +137,9 @@ class Follower extends Actor { } /** - * Save the current Follower-Object. + * Save the current Follower object. * - * @return int|WP_Error The Post-ID or an WP_Error. + * @return int|WP_Error The post ID or an WP_Error. */ public function save() { if ( ! $this->is_valid() ) { @@ -177,8 +178,7 @@ class Follower extends Actor { ); if ( ! empty( $post_id ) ) { - // If this is an update, prevent the "followed" date from being - // overwritten by the current date. + // If this is an update, prevent the "followed" date from being overwritten by the current date. $post = get_post( $post_id ); $args['post_date'] = $post->post_date; $args['post_date_gmt'] = $post->post_date_gmt; @@ -191,24 +191,22 @@ class Follower extends Actor { } /** - * Upsert the current Follower-Object. + * Upsert the current Follower object. * - * @return int|WP_Error The Post-ID or an WP_Error. + * @return int|WP_Error The post ID or an WP_Error. */ public function upsert() { return $this->save(); } /** - * Delete the current Follower-Object. + * Delete the current Follower object. * * 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 */ public function delete() { wp_delete_post( $this->_id ); @@ -216,8 +214,6 @@ class Follower extends Actor { /** * Update the post meta. - * - * @return void */ protected function get_post_meta_input() { $meta_input = array(); @@ -279,7 +275,7 @@ class Follower extends Actor { } /** - * Get the Icon URL (Avatar) + * Get the Icon URL (Avatar). * * @return string The URL to the Avatar. */ @@ -298,7 +294,7 @@ class Follower extends Actor { } /** - * Get the Icon URL (Avatar) + * Get the Icon URL (Avatar). * * @return string The URL to the Avatar. */ @@ -334,9 +330,8 @@ class Follower extends Actor { /** * Convert a Custom-Post-Type input to an Activitypub\Model\Follower. * - * @return string The JSON string. - * - * @return array Activitypub\Model\Follower + * @param \WP_Post $post The post object. + * @return \Activitypub\Activity\Base_Object|WP_Error */ public static function init_from_cpt( $post ) { $actor_json = get_post_meta( $post->ID, 'activitypub_actor_json', true ); @@ -371,10 +366,10 @@ class Follower extends Actor { if ( $path ) { if ( \strpos( $name, '@' ) !== false ) { - // expected: https://example.com/@user (default URL pattern) + // Expected: https://example.com/@user (default URL pattern). $name = \preg_replace( '|^/@?|', '', $path ); } else { - // expected: https://example.com/users/user (default ID pattern) + // Expected: https://example.com/users/user (default ID pattern). $parts = \explode( '/', $path ); $name = \array_pop( $parts ); } @@ -384,7 +379,7 @@ class Follower extends Actor { \strpos( $name, 'acct' ) === 0 || \strpos( $name, '@' ) === 0 ) { - // expected: user@example.com or acct:user@example (WebFinger) + // Expected: user@example.com or acct:user@example (WebFinger). $name = \ltrim( $name, '@' ); $name = \ltrim( $name, 'acct:' ); $parts = \explode( '@', $name ); diff --git a/includes/model/class-user.php b/includes/model/class-user.php index 7849b9ab..997c5210 100644 --- a/includes/model/class-user.php +++ b/includes/model/class-user.php @@ -1,19 +1,24 @@ + * @var string */ protected $webfinger; + /** + * The type of the object. + * + * @return string The type of the object. + */ public function get_type() { return 'Person'; } + /** + * Generate a User object from a WP_User. + * + * @param int $user_id The user ID. + * + * @return WP_Error|User The User object or WP_Error if user not found. + */ public static function from_wp_user( $user_id ) { if ( is_user_disabled( $user_id ) ) { return new WP_Error( @@ -83,27 +100,27 @@ class User extends Actor { } /** - * Get the User-ID. + * Get the user ID. * - * @return string The User-ID. + * @return string The user ID. */ public function get_id() { return $this->get_url(); } /** - * Get the User-Name. + * Get the Username. * - * @return string The User-Name. + * @return string The Username. */ public function get_name() { return \esc_attr( \get_the_author_meta( 'display_name', $this->_id ) ); } /** - * Get the User-Description. + * Get the User description. * - * @return string The User-Description. + * @return string The User description. */ public function get_summary() { $description = get_user_option( 'activitypub_description', $this->_id ); @@ -114,27 +131,37 @@ class User extends Actor { } /** - * Get the User-Url. + * Get the User url. * - * @return string The User-Url. + * @return string The User url. */ public function get_url() { return \esc_url( \get_author_posts_url( $this->_id ) ); } /** - * Returns the User-URL with @-Prefix for the username. + * Returns the User URL with @-Prefix for the username. * - * @return string The User-URL with @-Prefix for the username. + * @return string The User URL with @-Prefix for the username. */ public function get_alternate_url() { return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() ); } + /** + * Get the preferred username. + * + * @return string The preferred username. + */ public function get_preferred_username() { return \esc_attr( \get_the_author_meta( 'login', $this->_id ) ); } + /** + * Get the User icon. + * + * @return array The User icon. + */ public function get_icon() { $icon = \get_user_option( 'activitypub_icon', $this->_id ); if ( wp_attachment_is_image( $icon ) ) { @@ -157,6 +184,11 @@ class User extends Actor { ); } + /** + * Returns the header image. + * + * @return array|null The header image. + */ public function get_image() { $header_image = get_user_option( 'activitypub_header_image', $this->_id ); $image_url = null; @@ -179,10 +211,20 @@ class User extends Actor { return null; } + /** + * Returns the date the user was created. + * + * @return false|string The date the user was created. + */ public function get_published() { return \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( \get_the_author_meta( 'registered', $this->_id ) ) ); } + /** + * Returns the public key. + * + * @return array The public key. + */ public function get_public_key() { return array( 'id' => $this->get_id() . '#main-key', @@ -236,6 +278,11 @@ class User extends Actor { return get_rest_url_by_path( sprintf( 'actors/%d/collections/featured', $this->get__id() ) ); } + /** + * Returns the endpoints. + * + * @return array|null The endpoints. + */ public function get_endpoints() { $endpoints = null; @@ -267,18 +314,38 @@ class User extends Actor { return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST ); } + /** + * Returns the canonical URL. + * + * @return string The canonical URL. + */ public function get_canonical_url() { return $this->get_url(); } + /** + * Returns the streams. + * + * @return null The streams. + */ public function get_streams() { return null; } + /** + * Returns the tag. + * + * @return array The tag. + */ public function get_tag() { return array(); } + /** + * Returns the indexable state. + * + * @return bool Whether the user is indexable. + */ public function get_indexable() { if ( is_blog_public() ) { return true; @@ -287,12 +354,11 @@ class User extends Actor { } } - /** - * Update the User-Name. + * Update the username. * - * @param mixed $value The new value. - * @return bool True if the attribute was updated, false otherwise. + * @param string $value The new value. + * @return int|WP_Error The updated user ID or WP_Error on failure. */ public function update_name( $value ) { $userdata = array( @@ -303,9 +369,9 @@ class User extends Actor { } /** - * Update the User-Description. + * Update the User description. * - * @param mixed $value The new value. + * @param string $value The new value. * @return bool True if the attribute was updated, false otherwise. */ public function update_summary( $value ) { @@ -313,9 +379,9 @@ class User extends Actor { } /** - * Update the User-Icon. + * Update the User icon. * - * @param mixed $value The new value. Should be an attachment ID. + * @param int $value The new value. Should be an attachment ID. * @return bool True if the attribute was updated, false otherwise. */ public function update_icon( $value ) { @@ -328,7 +394,7 @@ class User extends Actor { /** * Update the User-Header-Image. * - * @param mixed $value The new value. Should be an attachment ID. + * @param int $value The new value. Should be an attachment ID. * @return bool True if the attribute was updated, false otherwise. */ public function update_header( $value ) { diff --git a/includes/rest/class-actors.php b/includes/rest/class-actors.php index f7bfc45a..60f03d29 100644 --- a/includes/rest/class-actors.php +++ b/includes/rest/class-actors.php @@ -1,18 +1,22 @@ get_param( 'user_id' ); @@ -79,15 +83,15 @@ class Actors { $link_header = sprintf( '<%1$s>; rel="alternate"; type="application/activity+json"', $user->get_id() ); - // redirect to canonical URL if it is not an ActivityPub request + // Redirect to canonical URL if it is not an ActivityPub request. if ( ! is_activitypub_request() ) { header( 'Link: ' . $link_header ); header( 'Location: ' . $user->get_canonical_url(), true, 301 ); exit; } - /* - * Action triggerd prior to the ActivityPub profile being created and sent to the client + /** + * Action triggered prior to the ActivityPub profile being created and sent to the client. */ \do_action( 'activitypub_rest_users_pre' ); @@ -102,11 +106,11 @@ class Actors { /** - * Endpoint for remote follow UI/Block + * Endpoint for remote follow UI/Block. * * @param WP_REST_Request $request The request object. * - * @return void|string The URL to the remote follow page + * @return WP_REST_Response|\WP_Error The response object or WP_Error. */ public static function remote_follow_get( WP_REST_Request $request ) { $resource = $request->get_param( 'resource' ); @@ -136,9 +140,9 @@ class Actors { } /** - * The supported parameters + * The supported parameters. * - * @return array list of parameters + * @return array List of parameters, */ public static function request_parameters() { $params = array(); diff --git a/includes/rest/class-collection.php b/includes/rest/class-collection.php index c15ddd7d..02cc99bf 100644 --- a/includes/rest/class-collection.php +++ b/includes/rest/class-collection.php @@ -1,4 +1,10 @@ get_param( 'type' ); @@ -144,9 +150,9 @@ class Collection { /** * The Featured Tags endpoint * - * @param WP_REST_Request $request The request object. + * @param \WP_REST_Request $request The request object. * - * @return WP_REST_Response The response object. + * @return WP_REST_Response|\WP_Error The response object or WP_Error. */ public static function tags_get( $request ) { $user_id = $request->get_param( 'user_id' ); @@ -196,9 +202,9 @@ class Collection { /** * Featured posts endpoint * - * @param WP_REST_Request $request The request object. + * @param \WP_REST_Request $request The request object. * - * @return WP_REST_Response The response object. + * @return WP_REST_Response|\WP_Error The response object or WP_Error. */ public static function featured_get( $request ) { $user_id = $request->get_param( 'user_id' ); @@ -254,7 +260,7 @@ class Collection { } /** - * Moderators endpoint + * Moderators endpoint. * * @return WP_REST_Response The response object. */ @@ -279,9 +285,9 @@ class Collection { } /** - * The supported parameters + * The supported parameters. * - * @return array list of parameters + * @return array List of parameters. */ public static function request_parameters() { $params = array(); @@ -295,9 +301,9 @@ class Collection { } /** - * The supported parameters + * The supported parameters. * - * @return array list of parameters + * @return array list of parameters. */ public static function request_parameters_for_replies() { $params = array(); diff --git a/includes/rest/class-comment.php b/includes/rest/class-comment.php index cb9e1126..095c8589 100644 --- a/includes/rest/class-comment.php +++ b/includes/rest/class-comment.php @@ -1,4 +1,10 @@ get_param( 'resource' ); diff --git a/includes/rest/class-followers.php b/includes/rest/class-followers.php index 0543a199..fe97548e 100644 --- a/includes/rest/class-followers.php +++ b/includes/rest/class-followers.php @@ -1,7 +1,12 @@ get_param( 'user_id' ); @@ -64,36 +69,34 @@ class Followers { $page = (int) $request->get_param( 'page' ); $context = $request->get_param( 'context' ); - /* - * Action triggerd prior to the ActivityPub profile being created and sent to the client + /** + * Action triggered prior to the ActivityPub profile being created and sent to the client */ \do_action( 'activitypub_rest_followers_pre' ); $data = Follower_Collection::get_followers_with_count( $user_id, $per_page, $page, array( 'order' => ucwords( $order ) ) ); $json = new stdClass(); + // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $json->{'@context'} = \Activitypub\get_context(); + $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->totalItems = $data['total']; + $json->partOf = 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->first = \add_query_arg( 'page', 1, $json->partOf ); + $json->last = \add_query_arg( 'page', \ceil( $json->totalItems / $per_page ), $json->partOf ); - $json->totalItems = $data['total']; // phpcs:ignore - $json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/followers', $user->get__id() ) ); // phpcs:ignore - - $json->first = \add_query_arg( 'page', 1, $json->partOf ); // phpcs:ignore - $json->last = \add_query_arg( 'page', \ceil ( $json->totalItems / $per_page ), $json->partOf ); // phpcs:ignore - - if ( $page && ( ( \ceil ( $json->totalItems / $per_page ) ) > $page ) ) { // phpcs:ignore - $json->next = \add_query_arg( 'page', $page + 1, $json->partOf ); // phpcs:ignore + if ( $page && ( ( \ceil( $json->totalItems / $per_page ) ) > $page ) ) { + $json->next = \add_query_arg( 'page', $page + 1, $json->partOf ); } - if ( $page && ( $page > 1 ) ) { // phpcs:ignore - $json->prev = \add_query_arg( 'page', $page - 1, $json->partOf ); // phpcs:ignore + if ( $page && ( $page > 1 ) ) { + $json->prev = \add_query_arg( 'page', $page - 1, $json->partOf ); } - // phpcs:ignore $json->orderedItems = array_map( function ( $item ) use ( $context ) { if ( 'full' === $context ) { @@ -103,6 +106,7 @@ class Followers { }, $data['followers'] ); + // phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $rest_response = new WP_REST_Response( $json, 200 ); $rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) ); @@ -111,9 +115,9 @@ class Followers { } /** - * The supported parameters + * The supported parameters. * - * @return array list of parameters + * @return array List of parameters. */ public static function request_parameters() { $params = array(); diff --git a/includes/rest/class-following.php b/includes/rest/class-following.php index e3e22cc5..bf546e96 100644 --- a/includes/rest/class-following.php +++ b/includes/rest/class-following.php @@ -1,4 +1,10 @@ get_param( 'user_id' ); @@ -58,8 +64,8 @@ class Following { return $user; } - /* - * Action triggerd prior to the ActivityPub profile being created and sent to the client + /** + * Action triggered prior to the ActivityPub profile being created and sent to the client. */ \do_action( 'activitypub_rest_following_pre' ); @@ -67,19 +73,25 @@ class Following { $json->{'@context'} = \Activitypub\get_context(); + // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $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->partOf = get_rest_url_by_path( sprintf( 'actors/%d/following', $user->get__id() ) ); - $json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/following', $user->get__id() ) ); // phpcs:ignore + /** + * Filter the list of following urls. + * + * @param array $items The array of following urls. + * @param \Activitypub\Model\User $user The user object. + */ + $items = apply_filters( 'activitypub_rest_following', array(), $user ); - $items = apply_filters( 'activitypub_rest_following', array(), $user ); // phpcs:ignore - - $json->totalItems = is_countable( $items ) ? count( $items ) : 0; // phpcs:ignore - $json->orderedItems = $items; // phpcs:ignore - - $json->first = $json->partOf; // phpcs:ignore + $json->totalItems = is_countable( $items ) ? count( $items ) : 0; + $json->orderedItems = $items; + $json->first = $json->partOf; + // phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $rest_response = new WP_REST_Response( $json, 200 ); $rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) ); @@ -88,9 +100,9 @@ class Following { } /** - * The supported parameters + * The supported parameters. * - * @return array list of parameters + * @return array List of parameters. */ public static function request_parameters() { $params = array(); diff --git a/includes/rest/class-inbox.php b/includes/rest/class-inbox.php index 9ade01ea..d4a104f6 100644 --- a/includes/rest/class-inbox.php +++ b/includes/rest/class-inbox.php @@ -1,7 +1,12 @@ get_param( 'user_id' ); @@ -80,27 +85,33 @@ class Inbox { return $user; } - /* - * Action triggerd prior to the ActivityPub profile being created and sent to the client + /** + * Action triggered prior to the ActivityPub profile being created and sent to the client. */ \do_action( 'activitypub_rest_inbox_pre' ); $json = new \stdClass(); + // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $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->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 - $json->first = $json->partOf; // phpcs:ignore + $json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/inbox', $user->get__id() ) ); + $json->totalItems = 0; + $json->orderedItems = array(); + $json->first = $json->partOf; + // phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase - // filter output + /** + * Filter the ActivityPub inbox array. + * + * @param array $json The ActivityPub inbox array. + */ $json = \apply_filters( 'activitypub_rest_inbox_array', $json ); - /* - * Action triggerd after the ActivityPub profile has been created and sent to the client + /** + * Action triggered after the ActivityPub profile has been created and sent to the client. */ \do_action( 'activitypub_inbox_post' ); @@ -111,11 +122,11 @@ class Inbox { } /** - * Handles user-inbox requests + * Handles user-inbox requests. * - * @param WP_REST_Request $request + * @param \WP_REST_Request $request The request object. * - * @return WP_REST_Response + * @return WP_REST_Response|\WP_Error The response object or WP_Error. */ public static function user_inbox_post( $request ) { $user_id = $request->get_param( 'user_id' ); @@ -130,7 +141,23 @@ class Inbox { $type = $request->get_param( 'type' ); $type = \strtolower( $type ); + /** + * ActivityPub inbox action. + * + * @param array $data The data array. + * @param int|null $user_id The user ID. + * @param string $type The type of the activity. + * @param Activity $activity The Activity object. + */ \do_action( 'activitypub_inbox', $data, $user->get__id(), $type, $activity ); + + /** + * ActivityPub inbox action for specific activity types. + * + * @param array $data The data array. + * @param int|null $user_id The user ID. + * @param Activity $activity The Activity object. + */ \do_action( "activitypub_inbox_{$type}", $data, $user->get__id(), $activity ); $rest_response = new WP_REST_Response( array(), 202 ); @@ -140,9 +167,9 @@ class Inbox { } /** - * The shared inbox + * The shared inbox. * - * @param WP_REST_Request $request + * @param \WP_REST_Request $request The request object. * * @return WP_REST_Response */ @@ -152,7 +179,23 @@ class Inbox { $type = $request->get_param( 'type' ); $type = \strtolower( $type ); + /** + * ActivityPub inbox action. + * + * @param array $data The data array. + * @param int|null $user_id The user ID. + * @param string $type The type of the activity. + * @param Activity $activity The Activity object. + */ \do_action( 'activitypub_inbox', $data, null, $type, $activity ); + + /** + * ActivityPub inbox action for specific activity types. + * + * @param array $data The data array. + * @param int|null $user_id The user ID. + * @param Activity $activity The Activity object. + */ \do_action( "activitypub_inbox_{$type}", $data, null, $activity ); $rest_response = new WP_REST_Response( array(), 202 ); @@ -162,9 +205,9 @@ class Inbox { } /** - * The supported parameters + * The supported parameters. * - * @return array list of parameters + * @return array List of parameters. */ public static function user_inbox_get_parameters() { $params = array(); @@ -182,9 +225,9 @@ class Inbox { } /** - * The supported parameters + * The supported parameters. * - * @return array list of parameters + * @return array List of parameters. */ public static function user_inbox_post_parameters() { $params = array(); @@ -201,10 +244,7 @@ class Inbox { $params['actor'] = array( 'required' => true, - // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - 'sanitize_callback' => function ( $param, $request, $key ) { - return object_to_uri( $param ); - }, + 'sanitize_callback' => 'object_to_uri', ); $params['type'] = array( @@ -214,6 +254,14 @@ class Inbox { $params['object'] = array( 'required' => true, 'validate_callback' => function ( $param, $request, $key ) { + /** + * Filter the ActivityPub object validation. + * + * @param bool $validate The validation result. + * @param array $param The object data. + * @param object $request The request object. + * @param string $key The key. + */ return apply_filters( 'activitypub_validate_object', true, $param, $request, $key ); }, ); @@ -222,17 +270,16 @@ class Inbox { } /** - * The supported parameters + * The supported parameters. * - * @return array list of parameters + * @return array List of parameters. */ public static function shared_inbox_post_parameters() { $params = self::user_inbox_post_parameters(); $params['to'] = array( 'required' => false, - // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - 'sanitize_callback' => function ( $param, $request, $key ) { + 'sanitize_callback' => function ( $param ) { if ( \is_string( $param ) ) { $param = array( $param ); } @@ -242,8 +289,7 @@ class Inbox { ); $params['cc'] = array( - // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - 'sanitize_callback' => function ( $param, $request, $key ) { + 'sanitize_callback' => function ( $param ) { if ( \is_string( $param ) ) { $param = array( $param ); } @@ -253,8 +299,7 @@ class Inbox { ); $params['bcc'] = array( - // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - 'sanitize_callback' => function ( $param, $request, $key ) { + 'sanitize_callback' => function ( $param ) { if ( \is_string( $param ) ) { $param = array( $param ); } @@ -267,11 +312,11 @@ class Inbox { } /** - * Get local user recipients + * Get local user recipients. * - * @param array $data + * @param array $data The data array. * - * @return array The list of local users + * @return array The list of local users. */ public static function get_recipients( $data ) { $recipients = extract_recipients_from_activity( $data ); diff --git a/includes/rest/class-interaction.php b/includes/rest/class-interaction.php index 011f1303..8bf78267 100644 --- a/includes/rest/class-interaction.php +++ b/includes/rest/class-interaction.php @@ -1,12 +1,21 @@ get_param( 'uri' ); @@ -78,10 +87,16 @@ class Interaction { $redirect_url = \apply_filters( 'activitypub_interactions_reply_url', $redirect_url, $uri, $object ); } - // generic Interaction hook + /** + * Filter the redirect URL. + * + * @param string $redirect_url The URL to redirect to. + * @param string $uri The URI of the object. + * @param array $object The object. + */ $redirect_url = \apply_filters( 'activitypub_interactions_url', $redirect_url, $uri, $object ); - // check if hook is implemented + // Check if hook is implemented. if ( ! $redirect_url ) { \wp_die( esc_html__( diff --git a/includes/rest/class-nodeinfo.php b/includes/rest/class-nodeinfo.php index 1ec5d502..3eb5fc00 100644 --- a/includes/rest/class-nodeinfo.php +++ b/includes/rest/class-nodeinfo.php @@ -1,4 +1,10 @@ get_param( 'user_id' ); @@ -64,41 +69,43 @@ class Outbox { $page = $request->get_param( 'page', 1 ); - /* - * Action triggerd prior to the ActivityPub profile being created and sent to the client + /** + * Action triggered prior to the ActivityPub profile being created and sent to the client. */ \do_action( 'activitypub_rest_outbox_pre' ); $json = new stdClass(); + // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $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->partOf = get_rest_url_by_path( sprintf( 'actors/%d/outbox', $user_id ) ); // phpcs:ignore - $json->totalItems = 0; // phpcs:ignore + $json->partOf = get_rest_url_by_path( sprintf( 'actors/%d/outbox', $user_id ) ); + $json->totalItems = 0; if ( $user_id > 0 ) { $count_posts = \count_user_posts( $user_id, $post_types, true ); - $json->totalItems = \intval( $count_posts ); // phpcs:ignore + $json->totalItems = \intval( $count_posts ); } else { foreach ( $post_types as $post_type ) { $count_posts = \wp_count_posts( $post_type ); - $json->totalItems += \intval( $count_posts->publish ); // phpcs:ignore + $json->totalItems += \intval( $count_posts->publish ); } } - $json->first = \add_query_arg( 'page', 1, $json->partOf ); // phpcs:ignore - $json->last = \add_query_arg( 'page', \ceil ( $json->totalItems / 10 ), $json->partOf ); // phpcs:ignore + $json->first = \add_query_arg( 'page', 1, $json->partOf ); + $json->last = \add_query_arg( 'page', \ceil( $json->totalItems / 10 ), $json->partOf ); - if ( $page && ( ( \ceil ( $json->totalItems / 10 ) ) > $page ) ) { // phpcs:ignore - $json->next = \add_query_arg( 'page', $page + 1, $json->partOf ); // phpcs:ignore + if ( $page && ( ( \ceil( $json->totalItems / 10 ) ) > $page ) ) { + $json->next = \add_query_arg( 'page', $page + 1, $json->partOf ); } if ( $page && ( $page > 1 ) ) { // phpcs:ignore - $json->prev = \add_query_arg( 'page', $page - 1, $json->partOf ); // phpcs:ignore + $json->prev = \add_query_arg( 'page', $page - 1, $json->partOf ); } + // phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase if ( $page ) { $posts = \get_posts( @@ -121,15 +128,19 @@ class Outbox { $activity = new Activity(); $activity->set_type( 'Create' ); $activity->set_object( $post ); - $json->orderedItems[] = $activity->to_array( false ); // phpcs:ignore + $json->orderedItems[] = $activity->to_array( false ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase } } - // filter output + /** + * Filter the ActivityPub outbox array. + * + * @param array $json The ActivityPub outbox array. + */ $json = \apply_filters( 'activitypub_rest_outbox_array', $json ); - /* - * Action triggerd after the ActivityPub profile has been created and sent to the client + /** + * Action triggered after the ActivityPub profile has been created and sent to the client */ \do_action( 'activitypub_outbox_post' ); @@ -140,9 +151,9 @@ class Outbox { } /** - * The supported parameters + * The supported parameters. * - * @return array list of parameters + * @return array List of parameters. */ public static function request_parameters() { $params = array(); diff --git a/includes/rest/class-server.php b/includes/rest/class-server.php index a910e367..aac34982 100644 --- a/includes/rest/class-server.php +++ b/includes/rest/class-server.php @@ -1,14 +1,19 @@ get_route(); - // check if it is an activitypub request and exclude webfinger and nodeinfo endpoints + // Check if it is an activitypub request and exclude webfinger and nodeinfo endpoints. if ( ! \str_starts_with( $route, '/' . ACTIVITYPUB_REST_NAMESPACE ) || \str_starts_with( $route, '/' . \trailingslashit( ACTIVITYPUB_REST_NAMESPACE ) . 'webfinger' ) || @@ -95,13 +100,13 @@ class Server { } /** - * Filter to defer signature verification + * Filter to defer signature verification. * * Skip signature verification for debugging purposes or to reduce load for * certain Activity-Types, like "Delete". * - * @param bool $defer Whether to defer signature verification. - * @param WP_REST_Request $request The request used to generate the response. + * @param bool $defer Whether to defer signature verification. + * @param \WP_REST_Request $request The request used to generate the response. * * @return bool Whether to defer signature verification. */ @@ -112,9 +117,9 @@ class Server { } if ( - // POST-Requests are always signed + // POST-Requests are always signed. 'GET' !== $request->get_method() || - // GET-Requests only require a signature in secure mode + // GET-Requests only require a signature in secure mode. ( 'GET' === $request->get_method() && ACTIVITYPUB_AUTHORIZED_FETCH ) ) { $verified_request = Signature::verify_http_signature( $request ); @@ -133,10 +138,10 @@ class Server { /** * Callback function to validate incoming ActivityPub requests * - * @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. - * Usually a WP_REST_Response or WP_Error. - * @param array $handler Route handler used for the request. - * @param WP_REST_Request $request Request used to generate the response. + * @param WP_REST_Response|\WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. + * Usually a WP_REST_Response or WP_Error. + * @param array $handler Route handler used for the request. + * @param \WP_REST_Request $request Request used to generate the response. * * @return mixed|WP_Error The response, error, or modified response. */ @@ -156,7 +161,7 @@ class Server { $params = $request->get_json_params(); - // Type is required for ActivityPub requests, so it fail later in the process + // Type is required for ActivityPub requests, so it fail later in the process. if ( ! isset( $params['type'] ) ) { return $response; } diff --git a/includes/rest/class-webfinger.php b/includes/rest/class-webfinger.php index b6bba3d5..868ed50d 100644 --- a/includes/rest/class-webfinger.php +++ b/includes/rest/class-webfinger.php @@ -1,11 +1,16 @@ id === 'settings_page_activitypub' ) { $this->user_id = Users::BLOG_USER_ID; @@ -30,6 +47,11 @@ class Followers extends WP_List_Table { ); } + /** + * Get columns. + * + * @return array + */ public function get_columns() { return array( 'cb' => '', @@ -42,16 +64,22 @@ class Followers extends WP_List_Table { ); } + /** + * Returns sortable columns. + * + * @return array + */ public function get_sortable_columns() { - $sortable_columns = array( + return array( 'post_title' => array( 'post_title', true ), 'modified' => array( 'modified', false ), 'published' => array( 'published', false ), ); - - return $sortable_columns; } + /** + * Prepare items. + */ public function prepare_items() { $columns = $this->get_columns(); $hidden = array(); @@ -113,12 +141,24 @@ class Followers extends WP_List_Table { } } + /** + * Returns bulk actions. + * + * @return array + */ public function get_bulk_actions() { return array( 'delete' => __( 'Delete', 'activitypub' ), ); } + /** + * Column default. + * + * @param array $item Item. + * @param string $column_name Column name. + * @return string + */ public function column_default( $item, $column_name ) { if ( ! array_key_exists( $column_name, $item ) ) { return __( 'None', 'activitypub' ); @@ -126,6 +166,12 @@ class Followers extends WP_List_Table { return $item[ $column_name ]; } + /** + * Column avatar. + * + * @param array $item Item. + * @return string + */ public function column_avatar( $item ) { return sprintf( '', @@ -133,45 +179,63 @@ class Followers extends WP_List_Table { ); } + /** + * Column url. + * + * @param array $item Item. + * @return string + */ public function column_url( $item ) { return sprintf( '%s', - $item['url'], + esc_url( $item['url'] ), $item['url'] ); } + /** + * Column cb. + * + * @param array $item Item. + * @return string + */ public function column_cb( $item ) { return sprintf( '', esc_attr( $item['identifier'] ) ); } + /** + * Process action. + */ public function process_action() { if ( ! isset( $_REQUEST['followers'] ) || ! isset( $_REQUEST['_wpnonce'] ) ) { - return false; + return; } $nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ); if ( ! wp_verify_nonce( $nonce, 'bulk-' . $this->_args['plural'] ) ) { - return false; + return; } if ( ! current_user_can( 'edit_user', $this->user_id ) ) { - return false; + return; } $followers = $_REQUEST['followers']; // phpcs:ignore - switch ( $this->current_action() ) { - case 'delete': - if ( ! is_array( $followers ) ) { - $followers = array( $followers ); - } - foreach ( $followers as $follower ) { - FollowerCollection::remove_follower( $this->user_id, $follower ); - } - break; + if ( $this->current_action() === 'delete' ) { + if ( ! is_array( $followers ) ) { + $followers = array( $followers ); + } + foreach ( $followers as $follower ) { + FollowerCollection::remove_follower( $this->user_id, $follower ); + } } } + /** + * Returns user count. + * + * @return int + */ public function get_user_count() { return FollowerCollection::count_followers( $this->user_id ); } diff --git a/includes/transformer/class-attachment.php b/includes/transformer/class-attachment.php index 2fc46350..98aaf8bf 100644 --- a/includes/transformer/class-attachment.php +++ b/includes/transformer/class-attachment.php @@ -1,10 +1,14 @@ wp_object->ID ); $media_type = preg_replace( '/(\/[a-zA-Z]+)/i', '', $mime_type ); + $type = ''; switch ( $media_type ) { case 'audio': diff --git a/includes/transformer/class-base.php b/includes/transformer/class-base.php index f33e5642..6d4c202a 100644 --- a/includes/transformer/class-base.php +++ b/includes/transformer/class-base.php @@ -1,4 +1,10 @@ wp_object = $wp_object; @@ -50,9 +55,9 @@ abstract class Base { /** * Transform all properties with available get(ter) functions. * - * @param Base_Object|object $object + * @param Base_Object|object $activitypub_object The ActivityPub Object. * - * @return Base_Object|object $object + * @return Base_Object|object */ protected function transform_object_properties( $activitypub_object ) { $vars = $activitypub_object->get_object_var_keys(); @@ -76,13 +81,12 @@ abstract class Base { /** * Transform the WordPress Object into an ActivityPub Object. * - * @return Activitypub\Activity\Base_Object + * @return Base_Object|object The ActivityPub Object. */ public function to_object() { $activitypub_object = new Base_Object(); - $activitypub_object = $this->transform_object_properties( $activitypub_object ); - return $activitypub_object; + return $this->transform_object_properties( $activitypub_object ); } /** @@ -90,7 +94,7 @@ abstract class Base { * * @param string $type The Activity-Type. * - * @return \Activitypub\Activity\Activity The Activity. + * @return Activity The Activity. */ public function to_activity( $type ) { $object = $this->to_object(); @@ -101,7 +105,7 @@ abstract class Base { // Pre-fill the Activity with data (for example cc and to). $activity->set_object( $object ); - // Use simple Object (only ID-URI) for Like and Announce + // Use simple Object (only ID-URI) for Like and Announce. if ( in_array( $type, array( 'Like', 'Announce' ), true ) ) { $activity->set_object( $object->get_id() ); } @@ -109,27 +113,27 @@ abstract class Base { return $activity; } + /** + * Get the ID of the WordPress Object. + */ abstract protected function get_id(); /** * Get the replies Collection. */ public function get_replies() { - $replies = Replies::get_collection( $this->wp_object, $this->get_id() ); - return $replies; + return Replies::get_collection( $this->wp_object ); } /** * Returns the ID of the WordPress Object. - * - * @return int The ID of the WordPress Object */ abstract public function get_wp_user_id(); /** * Change the User-ID of the WordPress Post. * - * @return int The User-ID of the WordPress Post + * @param int $user_id The new user ID. */ abstract public function change_wp_user_id( $user_id ); } diff --git a/includes/transformer/class-comment.php b/includes/transformer/class-comment.php index 930f8fe5..7f0d3f68 100644 --- a/includes/transformer/class-comment.php +++ b/includes/transformer/class-comment.php @@ -1,21 +1,23 @@ wp_object->user_id = $user_id; } /** - * Transforms the WP_Comment object to an ActivityPub Object + * Transforms the WP_Comment object to an ActivityPub Object. * * @see \Activitypub\Activity\Base_Object * - * @return \Activitypub\Activity\Base_Object The ActivityPub Object + * @return \Activitypub\Activity\Base_Object The ActivityPub Object. */ public function to_object() { $comment = $this->wp_object; @@ -106,28 +108,41 @@ class Comment extends Base { * @return string The content. */ protected function get_content() { - // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited $comment = $this->wp_object; $content = $comment->comment_content; + /** + * Filter the content of the comment. + * + * @param string $content The content of the comment. + * @param \WP_Comment $comment The comment object. + * @param array $args The arguments. + * + * @return string The filtered content of the comment. + */ $content = \apply_filters( 'comment_text', $content, $comment, array() ); $content = \preg_replace( '/[\n\r\t]/', '', $content ); $content = \trim( $content ); - $content = \apply_filters( 'activitypub_the_content', $content, $comment ); - return $content; + /** + * Filter the content of the comment. + * + * @param string $content The content of the comment. + * @param \WP_Comment $comment The comment object. + * + * @return string The filtered content of the comment. + */ + return \apply_filters( 'activitypub_the_content', $content, $comment ); } /** * Returns the in-reply-to for the ActivityPub Item. * - * @return int The URL of the in-reply-to. + * @return false|string|null The URL of the in-reply-to. */ protected function get_in_reply_to() { - $comment = $this->wp_object; - + $comment = $this->wp_object; $parent_comment = null; - $in_reply_to = null; if ( $comment->comment_parent ) { $parent_comment = \get_comment( $comment->comment_parent ); @@ -211,6 +226,15 @@ class Comment extends Base { protected function get_mentions() { \add_filter( 'activitypub_extract_mentions', array( $this, 'extract_reply_context' ) ); + /** + * Filter the mentions in the comment. + * + * @param array $mentions The list of mentions. + * @param string $content The content of the comment. + * @param \WP_Comment $comment The comment object. + * + * @return array The filtered list of mentions. + */ return apply_filters( 'activitypub_extract_mentions', array(), $this->wp_object->comment_content, $this->wp_object ); } @@ -222,7 +246,7 @@ class Comment extends Base { protected function get_comment_ancestors() { $ancestors = get_comment_ancestors( $this->wp_object ); - // Now that we have the full tree of ancestors, only return the ones received from the fediverse + // Now that we have the full tree of ancestors, only return the ones received from the fediverse. return array_filter( $ancestors, function ( $comment_id ) { @@ -235,12 +259,12 @@ class Comment extends Base { * Collect all other Users that participated in this comment-thread * to send them a notification about the new reply. * - * @param array $mentions The already mentioned ActivityPub users + * @param array $mentions The already mentioned ActivityPub users. * * @return array The list of all Repliers. */ public function extract_reply_context( $mentions ) { - // Check if `$this->wp_object` is a WP_Comment + // Check if `$this->wp_object` is a WP_Comment. if ( 'WP_Comment' !== get_class( $this->wp_object ) ) { return $mentions; } @@ -276,9 +300,9 @@ class Comment extends Base { /** * Filter the locale of the comment. * - * @param string $lang The locale of the comment. - * @param int $comment_id The comment ID. - * @param WP_Post $post The comment object. + * @param string $lang The locale of the comment. + * @param int $comment_id The comment ID. + * @param \WP_Post $post The comment object. * * @return string The filtered locale of the comment. */ diff --git a/includes/transformer/class-factory.php b/includes/transformer/class-factory.php index 2824072c..e8e59796 100644 --- a/includes/transformer/class-factory.php +++ b/includes/transformer/class-factory.php @@ -1,11 +1,13 @@ post_type ) { diff --git a/includes/transformer/class-post.php b/includes/transformer/class-post.php index ca996cf8..85a8b809 100644 --- a/includes/transformer/class-post.php +++ b/includes/transformer/class-post.php @@ -1,23 +1,26 @@ wp_object->post_author = $user_id; @@ -80,7 +85,7 @@ class Post extends Base { * * If `single_user` mode is enabled, the Blog-User is returned. * - * @return Activitypub\Activity\Actor The User-Object. + * @return \Activitypub\Activity\Actor The User-Object. */ protected function get_actor_object() { if ( $this->actor_object ) { @@ -126,7 +131,7 @@ class Post extends Base { $permalink = \get_post_meta( $post->ID, 'activitypub_canonical_url', true ); break; case 'draft': - // get_sample_permalink is in wp-admin, not always loaded + // Get_sample_permalink is in wp-admin, not always loaded. if ( ! \function_exists( '\get_sample_permalink' ) ) { require_once ABSPATH . 'wp-admin/includes/post.php'; } @@ -179,7 +184,7 @@ class Post extends Base { ); $id = $this->wp_object->ID; - // list post thumbnail first if this post has one + // List post thumbnail first if this post has one. if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) { $media['image'][] = array( 'id' => \get_post_thumbnail_id( $id ) ); } @@ -207,17 +212,17 @@ class Post extends Base { */ $media = \apply_filters( 'activitypub_attachment_ids', $media, $this->wp_object ); - $attchments = \array_filter( \array_map( array( self::class, 'wp_attachment_to_activity_attachment' ), $media ) ); + $attachments = \array_filter( \array_map( array( self::class, 'wp_attachment_to_activity_attachment' ), $media ) ); /** * Filter the attachments for a post. * - * @param array $attchments The attachments. + * @param array $attachments The attachments. * @param WP_Post $this->wp_object The post object. * * @return array The filtered attachments. */ - return \apply_filters( 'activitypub_attachments', $attchments, $this->wp_object ); + return \apply_filters( 'activitypub_attachments', $attachments, $this->wp_object ); } /** @@ -235,7 +240,7 @@ class Post extends Base { } foreach ( $enclosures as $enclosure ) { - // check if URL is an attachment + // Check if URL is an attachment. $attachment_id = \attachment_url_to_postid( $enclosure['url'] ); if ( $attachment_id ) { $enclosure['id'] = $attachment_id; @@ -271,29 +276,27 @@ class Post extends Base { * @return array The attachments. */ protected function get_block_attachments( $media, $max_media ) { - // max media can't be negative or zero + // Max media can't be negative or zero. if ( $max_media <= 0 ) { return array(); } $blocks = \parse_blocks( $this->wp_object->post_content ); - $media = self::get_media_from_blocks( $blocks, $media ); - return $media; + return self::get_media_from_blocks( $blocks, $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 array $blocks The blocks to search for media IDs. + * @param array $media The media IDs to append new IDs to. * * @return array The image IDs. */ protected static function get_media_from_blocks( $blocks, $media ) { foreach ( $blocks as $block ) { - // recurse into inner blocks + // Recurse into inner blocks. if ( ! empty( $block['innerBlocks'] ) ) { $media = self::get_media_from_blocks( $block['innerBlocks'], $media ); } @@ -364,7 +367,7 @@ class Post extends Base { * @return array The attachments. */ protected function get_classic_editor_images( $media, $max_images ) { - // max images can't be negative or zero + // Max images can't be negative or zero. if ( $max_images <= 0 ) { return array(); } @@ -388,12 +391,12 @@ class Post extends Base { * @return array The attachments. */ protected function get_classic_editor_image_embeds( $max_images ) { - // if someone calls that function directly, bail + // If someone calls that function directly, bail. if ( ! \class_exists( '\WP_HTML_Tag_Processor' ) ) { return array(); } - // max images can't be negative or zero + // Max images can't be negative or zero. if ( $max_images <= 0 ) { return array(); } @@ -403,20 +406,21 @@ class Post extends Base { $content = \get_post_field( 'post_content', $this->wp_object ); $tags = new \WP_HTML_Tag_Processor( $content ); - // This linter warning is a false positive - we have to - // re-count each time here as we modify $images. + // This linter warning is a false positive - we have to re-count each time here as we modify $images. // phpcs:ignore Squiz.PHP.DisallowSizeFunctionsInLoops.Found while ( $tags->next_tag( 'img' ) && ( \count( $images ) <= $max_images ) ) { $src = $tags->get_attribute( 'src' ); - // If the img source is in our uploads dir, get the - // associated ID. Note: if there's a -500x500 - // type suffix, we remove it, but we try the original - // first in case the original image is actually called - // that. Likewise, we try adding the -scaled suffix for - // the case that this is a small version of an image - // that was big enough to get scaled down on upload: - // https://make.wordpress.org/core/2019/10/09/introducing-handling-of-big-images-in-wordpress-5-3/ + /* + * If the img source is in our uploads dir, get the + * associated ID. Note: if there's a -500x500 + * type suffix, we remove it, but we try the original + * first in case the original image is actually called + * that. Likewise, we try adding the -scaled suffix for + * the case that this is a small version of an image + * that was big enough to get scaled down on upload: + * https://make.wordpress.org/core/2019/10/09/introducing-handling-of-big-images-in-wordpress-5-3/ + */ if ( null !== $src && \str_starts_with( $src, $base ) ) { $img_id = \attachment_url_to_postid( $src ); @@ -455,7 +459,7 @@ class Post extends Base { * @return array The attachment IDs. */ protected function get_classic_editor_image_attachments( $max_images ) { - // max images can't be negative or zero + // Max images can't be negative or zero. if ( $max_images <= 0 ) { return array(); } @@ -485,12 +489,21 @@ class Post extends Base { /** * Filter media IDs by object type. * - * @param array $media The media array grouped by type. - * @param string $type The object type. + * @param array $media The media array grouped by type. + * @param string $type The object type. + * @param WP_Post $wp_object The post object. * * @return array The filtered media IDs. */ protected static function filter_media_by_object_type( $media, $type, $wp_object ) { + /** + * Filter the object type for media attachments. + * + * @param string $type The object type. + * @param WP_Post $wp_object The post object. + * + * @return string The filtered object type. + */ $type = \apply_filters( 'filter_media_by_object_type', \strtolower( $type ), $wp_object ); if ( ! empty( $media[ $type ] ) ) { @@ -516,7 +529,7 @@ class Post extends Base { $attachment = array(); $mime_type = \get_post_mime_type( $id ); $mime_type_parts = \explode( '/', $mime_type ); - // switching on image/audio/video + // Switching on image/audio/video. switch ( $mime_type_parts[0] ) { case 'image': $image_size = 'large'; @@ -564,7 +577,7 @@ class Post extends Base { 'name' => \esc_attr( \get_the_title( $id ) ), ); $meta = wp_get_attachment_metadata( $id ); - // height and width for videos + // Height and width for videos. if ( isset( $meta['width'] ) && isset( $meta['height'] ) ) { $attachment['width'] = \esc_attr( $meta['width'] ); $attachment['height'] = \esc_attr( $meta['height'] ); @@ -573,6 +586,14 @@ class Post extends Base { break; } + /** + * Filter the attachment for a post. + * + * @param array $attachment The attachment. + * @param int $id The attachment ID. + * + * @return array The filtered attachment. + */ return \apply_filters( 'activitypub_attachment', $attachment, $id ); } @@ -679,7 +700,11 @@ class Post extends Base { return $cc; } - + /** + * Returns the Audience for the Post. + * + * @return string|null The audience. + */ public function get_audience() { if ( is_single_user() ) { return null; @@ -818,7 +843,7 @@ class Post extends Base { $content = \apply_filters( 'activitypub_the_content', $content, $post ); - // Don't need these any more, should never appear in a post. + // Don't need these anymore, should never appear in a post. Shortcodes::unregister(); return $content; @@ -863,6 +888,15 @@ class Post extends Base { * @return array The list of @-Mentions. */ protected function get_mentions() { + /** + * Filter the mentions in the post content. + * + * @param array $mentions The mentions. + * @param string $content The post content. + * @param WP_Post $post The post object. + * + * @return array The filtered mentions. + */ return apply_filters( 'activitypub_extract_mentions', array(), @@ -1002,8 +1036,8 @@ class Post extends Base { * @see https://www.w3.org/TR/activitypub/#security-sanitizing-content * @see https://www.w3.org/wiki/ActivityPub/Primer/HTML * - * @param string $block_content The block content (html) - * @param object $block The block object + * @param string $block_content The block content (html). + * @param object $block The block object. * * @return string A block level link */ diff --git a/integration/class-buddypress.php b/integration/class-buddypress.php index 14afbe4d..1e86ee5f 100644 --- a/integration/class-buddypress.php +++ b/integration/class-buddypress.php @@ -1,23 +1,37 @@ url = bp_core_get_user_domain( $author_id ); // add BP member profile URL as user URL + $author->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 ) ); if ( $cover_image_url ) { @@ -27,7 +41,7 @@ class Buddypress { ); } - // change profile URL to BuddyPress' profile URL + // Change profile URL to BuddyPress' profile URL. $author->attachment['profile_url'] = array( 'type' => 'PropertyValue', 'name' => \__( 'Profile', 'activitypub' ), @@ -43,9 +57,9 @@ class Buddypress { ), ); - // replace blog URL on multisite + // 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( $author->attachment['blog_url'] ); diff --git a/integration/class-enable-mastodon-apps.php b/integration/class-enable-mastodon-apps.php index c04b68fa..04c24ff7 100644 --- a/integration/class-enable-mastodon-apps.php +++ b/integration/class-enable-mastodon-apps.php @@ -1,4 +1,10 @@ update_icon( $data['avatar'] ) ) { - // unset the avatar so it doesn't get saved again by other plugins. + // Unset the avatar so it doesn't get saved again by other plugins. // Ditto for all other fields below. unset( $data['avatar'] ); } @@ -106,7 +110,7 @@ class Enable_Mastodon_Apps { } /** - * Get extra fields for Mastodon API + * Get extra fields for Mastodon API. * * @param int $user_id The user id to act on. * @return array The extra fields. @@ -126,11 +130,10 @@ class Enable_Mastodon_Apps { } /** - * Set extra fields for Mastodon API + * Set extra fields for Mastodon API. * * @param int $user_id The user id to act on. * @param array $fields The fields to set. It is assumed to be the entire set of desired fields. - * @return void */ private static function set_extra_fields( $user_id, $fields ) { // The Mastodon API submits a simple hash for every field. @@ -168,12 +171,12 @@ class Enable_Mastodon_Apps { } } } + /** - * Add followers to Mastodon API + * Add followers to Mastodon API. * - * @param array $followers An array of followers - * @param string $user_id The user id - * @param WP_REST_Request $request The request object + * @param array $followers An array of followers. + * @param string $user_id The user id. * * @return array The filtered followers */ @@ -219,18 +222,16 @@ class Enable_Mastodon_Apps { $activitypub_followers ); - $followers = array_merge( $mastodon_followers, $followers ); - - return $followers; + return array_merge( $mastodon_followers, $followers ); } /** * Resolve external accounts for Mastodon API * - * @param Enable_Mastodon_Apps\Entity\Account $user_data The user data - * @param string $user_id The user id + * @param Account $user_data The user data. + * @param string $user_id The user id. * - * @return Enable_Mastodon_Apps\Entity\Account The filtered Account + * @return Account The filtered Account. */ public static function api_account_external( $user_data, $user_id ) { if ( $user_data || ( is_numeric( $user_id ) && $user_id ) ) { @@ -258,6 +259,14 @@ class Enable_Mastodon_Apps { return $user_data; } + /** + * Resolve internal accounts for Mastodon API + * + * @param Account $user_data The user data. + * @param string $user_id The user id. + * + * @return Account The filtered Account. + */ 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 ); @@ -266,9 +275,9 @@ class Enable_Mastodon_Apps { return $user_data; } - // convert user to account. + // 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 + // 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; @@ -301,7 +310,7 @@ class Enable_Mastodon_Apps { $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 ); - // Now do it in source['fields'] with stripped tags + // Now do it in source['fields'] with stripped tags. $account->source['fields'] = \array_map( function ( $field ) { $field['value'] = \wp_strip_all_tags( $field['value'], true ); @@ -315,6 +324,13 @@ class Enable_Mastodon_Apps { return $account; } + /** + * Get account for actor. + * + * @param string $uri The URI. + * + * @return Account|null The account. + */ private static function get_account_for_actor( $uri ) { if ( ! is_string( $uri ) ) { return null; @@ -362,6 +378,14 @@ class Enable_Mastodon_Apps { return $account; } + /** + * Search by URL for Mastodon API. + * + * @param array $search_data The search data. + * @param object $request The request object. + * + * @return array The filtered search data. + */ public static function api_search_by_url( $search_data, $request ) { $p = \wp_parse_url( $request->get_param( 'q' ) ); if ( ! $p || ! isset( $p['host'] ) ) { @@ -386,6 +410,14 @@ class Enable_Mastodon_Apps { return $search_data; } + /** + * Search for Mastodon API. + * + * @param array $search_data The search data. + * @param object $request The request object. + * + * @return array The filtered search data. + */ public static function api_search( $search_data, $request ) { $user_id = \get_current_user_id(); if ( ! $user_id ) { @@ -433,6 +465,13 @@ class Enable_Mastodon_Apps { return $search_data; } + /** + * Get posts query args for Mastodon API. + * + * @param array $args The query arguments. + * + * @return array The filtered args. + */ public static function api_get_posts_query_args( $args ) { if ( isset( $args['author'] ) && is_string( $args['author'] ) ) { $uri = Webfinger_Util::resolve( $args['author'] ); @@ -445,6 +484,14 @@ class Enable_Mastodon_Apps { return $args; } + /** + * Convert an activity to a status. + * + * @param array $item The activity. + * @param Account $account The account. + * + * @return Status|null The status. + */ private static function activity_to_status( $item, $account ) { if ( isset( $item['object'] ) ) { $object = $item['object']; @@ -517,6 +564,14 @@ class Enable_Mastodon_Apps { return $status; } + /** + * Get posts for Mastodon API. + * + * @param array $statuses The statuses. + * @param array $args The arguments. + * + * @return array The filtered statuses. + */ public static function api_statuses_external( $statuses, $args ) { if ( ! isset( $args['activitypub'] ) ) { return $statuses; @@ -579,6 +634,15 @@ class Enable_Mastodon_Apps { return array_slice( $activitypub_statuses, 0, $limit ); } + /** + * Get replies for Mastodon API. + * + * @param array $context The context. + * @param int $post_id The post id. + * @param string $url The URL. + * + * @return array The filtered context. + */ public static function api_get_replies( $context, $post_id, $url ) { $meta = Http::get_remote_object( $url, true ); if ( is_wp_error( $meta ) || ! isset( $meta['replies']['first']['next'] ) ) { diff --git a/integration/class-jetpack.php b/integration/class-jetpack.php index d3662364..002de2cb 100644 --- a/integration/class-jetpack.php +++ b/integration/class-jetpack.php @@ -1,21 +1,40 @@ = '2.0' ) { @@ -47,11 +53,11 @@ class Nodeinfo { } /** - * Extend NodeInfo2 data + * Extend NodeInfo2 data. * - * @param array $nodeinfo NodeInfo2 data + * @param array $nodeinfo NodeInfo2 data. * - * @return array The extended array + * @return array The extended array. */ public static function add_nodeinfo2_data( $nodeinfo ) { $nodeinfo['protocols'][] = 'activitypub'; @@ -66,11 +72,11 @@ class Nodeinfo { } /** - * Extend the well-known nodeinfo data + * Extend the well-known nodeinfo data. * - * @param array $data The well-known nodeinfo data + * @param array $data The well-known nodeinfo data. * - * @return array The extended array + * @return array The extended array. */ public static function add_wellknown_nodeinfo_data( $data ) { $data['links'][] = array( diff --git a/integration/class-opengraph.php b/integration/class-opengraph.php index 2d0f8c96..4eb1b1e0 100644 --- a/integration/class-opengraph.php +++ b/integration/class-opengraph.php @@ -1,4 +1,10 @@ get_webfinger(); return $metadata; } if ( \is_author() ) { - // Use the Author of the Archive-Page + // Use the Author of the Archive-Page. $user_id = \get_queried_object_id(); } elseif ( \is_singular() ) { - // Use the Author of the Post + // Use the Author of the Post. $user_id = \get_post_field( 'post_author', \get_queried_object_id() ); } elseif ( ! is_user_type_disabled( 'blog' ) ) { - // Use the Blog-User for any other page, if the Blog-User is not disabled + // Use the Blog-User for any other page, if the Blog-User is not disabled. $user_id = Users::BLOG_USER_ID; } else { - // Do not add any metadata otherwise + // Do not add any metadata otherwise. return $metadata; } @@ -78,7 +84,7 @@ class Opengraph { return $metadata; } - // add WebFinger resource + // Add WebFinger resource. $metadata['fediverse:creator'] = $user->get_webfinger(); return $metadata; diff --git a/integration/class-seriously-simple-podcasting.php b/integration/class-seriously-simple-podcasting.php index 1a5ccbe8..c678f6d3 100644 --- a/integration/class-seriously-simple-podcasting.php +++ b/integration/class-seriously-simple-podcasting.php @@ -1,4 +1,10 @@ log( sprintf( - // translators: %s is a URL + // translators: %s is a URL. __( 'New Follower: %s', 'activitypub' ), $notification->actor ), diff --git a/integration/class-webfinger.php b/integration/class-webfinger.php index f566e523..7ae9607d 100644 --- a/integration/class-webfinger.php +++ b/integration/class-webfinger.php @@ -1,7 +1,12 @@ ID ); @@ -56,12 +61,12 @@ class Webfinger { } /** - * Add WebFinger discovery links + * Add WebFinger discovery links. * - * @param array $jrd the jrd array - * @param string $uri the WebFinger resource + * @param array $jrd The jrd array. + * @param string $uri The WebFinger resource. * - * @return array the jrd array + * @return array|\WP_Error The jrd array or WP_Error. */ public static function add_pseudo_user_discovery( $jrd, $uri ) { $user = User_Collection::get_by_resource( $uri ); diff --git a/integration/load.php b/integration/load.php index ed254bc3..0bdef288 100644 --- a/integration/load.php +++ b/integration/load.php @@ -1,10 +1,15 @@ -