diff --git a/includes/class-notification.php b/includes/class-notification.php index bab72774..1dd65732 100644 --- a/includes/class-notification.php +++ b/includes/class-notification.php @@ -42,15 +42,15 @@ class Notification { /** * Notification constructor. * - * @param string $type The type of the notification. - * @param string $actor The actor URL. - * @param array $object The Activity object. - * @param int $target The WordPress User-Id. + * @param string $type The type of the notification. + * @param string $actor The actor URL. + * @param array $activity The Activity object. + * @param int $target The WordPress User-Id. */ - public function __construct( $type, $actor, $object, $target ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound + public function __construct( $type, $actor, $activity, $target ) { $this->type = $type; $this->actor = $actor; - $this->object = $object; + $this->object = $activity; $this->target = $target; } diff --git a/includes/class-signature.php b/includes/class-signature.php index aa2a109b..b8f8af88 100644 --- a/includes/class-signature.php +++ b/includes/class-signature.php @@ -221,7 +221,7 @@ class Signature { $signature = null; \openssl_sign( $signed_string, $signature, $key, \OPENSSL_ALGO_SHA256 ); - $signature = \base64_encode( $signature ); // phpcs:ignore + $signature = \base64_encode( $signature ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode $key_id = $user->get_url() . '#main-key'; @@ -345,7 +345,7 @@ class Signature { ); } if ( isset( $actor['publicKey']['publicKeyPem'] ) ) { - return \rtrim( $actor['publicKey']['publicKeyPem'] ); // phpcs:ignore + return \rtrim( $actor['publicKey']['publicKeyPem'] ); } return new WP_Error( 'activitypub_no_remote_key_found', @@ -400,7 +400,7 @@ class Signature { $parsed_header['headers'] = \explode( ' ', trim( $matches[1] ) ); } if ( \preg_match( '/signature="(.*?)"/ism', $signature, $matches ) ) { - $parsed_header['signature'] = \base64_decode( preg_replace( '/\s+/', '', trim( $matches[1] ) ) ); // phpcs:ignore + $parsed_header['signature'] = \base64_decode( preg_replace( '/\s+/', '', trim( $matches[1] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode } if ( ( $parsed_header['signature'] ) && ( $parsed_header['algorithm'] ) && ( ! $parsed_header['headers'] ) ) { diff --git a/includes/collection/class-followers.php b/includes/collection/class-followers.php index dfade8c1..76611ff9 100644 --- a/includes/collection/class-followers.php +++ b/includes/collection/class-followers.php @@ -94,7 +94,7 @@ class Followers { public static function get_follower( $user_id, $actor ) { global $wpdb; - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + // phpcs:ignore WordPress.DB.DirectDatabaseQuery $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->postmeta pm ON p.ID = pm.post_id WHERE p.post_type = %s AND pm.meta_key = 'activitypub_user_id' AND pm.meta_value = %d AND p.guid = %s", @@ -119,12 +119,12 @@ class Followers { * * @param string $actor The Actor URL. * - * @return Follower|null The Follower object or null. + * @return \Activitypub\Activity\Base_Object|WP_Error|null */ public static function get_follower_by_actor( $actor ) { global $wpdb; - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + // phpcs:ignore WordPress.DB.DirectDatabaseQuery $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid=%s", diff --git a/includes/functions.php b/includes/functions.php index 27f50e96..8aad9766 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1012,8 +1012,7 @@ function get_enclosures( $post_id ) { function get_comment_ancestors( $comment ) { $comment = \get_comment( $comment ); - // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual - if ( ! $comment || empty( $comment->comment_parent ) || $comment->comment_parent == $comment->comment_ID ) { + if ( ! $comment || empty( $comment->comment_parent ) || (int) $comment->comment_parent === (int) $comment->comment_ID ) { return array(); } diff --git a/includes/handler/class-announce.php b/includes/handler/class-announce.php index b0aa90fd..377a3c6e 100644 --- a/includes/handler/class-announce.php +++ b/includes/handler/class-announce.php @@ -33,27 +33,25 @@ class Announce { /** * Handles "Announce" requests. * - * @param array $array The activity-object. - * @param int $user_id The id of the local blog-user. - * @param \Activitypub\Activity\Activity $activity The activity object. - * - * @return void + * @param array $announcement The activity-object. + * @param int $user_id The id of the local blog-user. + * @param \Activitypub\Activity\Activity $activity The activity object. */ - public static function handle_announce( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound + public static function handle_announce( $announcement, $user_id, $activity = null ) { // Check if Activity is public or not. - if ( ! is_activity_public( $array ) ) { + if ( ! is_activity_public( $announcement ) ) { // @todo maybe send email return; } if ( ! ACTIVITYPUB_DISABLE_REACTIONS ) { - self::maybe_save_announce( $array, $user_id, $activity ); + self::maybe_save_announce( $announcement, $user_id ); } - if ( is_string( $array['object'] ) ) { - $object = Http::get_remote_object( $array['object'] ); + if ( is_string( $announcement['object'] ) ) { + $object = Http::get_remote_object( $announcement['object'] ); } else { - $object = $array['object']; + $object = $announcement['object']; } if ( ! $object || is_wp_error( $object ) ) { @@ -66,21 +64,33 @@ class Announce { $type = \strtolower( $object['type'] ); + /** + * Fires after an Announce has been received. + * + * @param array $object The object. + * @param int $user_id The id of the local blog-user. + * @param array $activity The activity object. + */ \do_action( 'activitypub_inbox', $object, $user_id, $type, $activity ); + + /** + * Fires after an Announce of a specific type has been received. + * + * @param array $object The object. + * @param int $user_id The id of the local blog-user. + * @param array $activity The activity object. + */ \do_action( "activitypub_inbox_{$type}", $object, $user_id, $activity ); } /** * Try to save the Announce. * - * @param array $array The activity-object. - * @param int $user_id The id of the local blog-user. - * @param \Activitypub\Activity\Activity $activity The activity object. - * - * @return void + * @param array $activity The activity-object. + * @param int $user_id The id of the local blog-user. */ - public static function maybe_save_announce( $array, $user_id, $activity ) { // phpcs:ignore - $url = object_to_uri( $array['object'] ); + public static function maybe_save_announce( $activity, $user_id ) { + $url = object_to_uri( $activity['object'] ); if ( empty( $url ) ) { return; @@ -91,13 +101,21 @@ class Announce { return; } - $state = Interactions::add_reaction( $array ); + $state = Interactions::add_reaction( $activity ); $reaction = null; if ( $state && ! is_wp_error( $state ) ) { $reaction = get_comment( $state ); } - do_action( 'activitypub_handled_announce', $array, $user_id, $state, $reaction ); + /** + * Fires after an Announce has been saved. + * + * @param array $activity The activity-object. + * @param int $user_id The id of the local blog-user. + * @param mixed $state The state of the reaction. + * @param mixed $reaction The reaction. + */ + do_action( 'activitypub_handled_announce', $activity, $user_id, $state, $reaction ); } } diff --git a/includes/handler/class-like.php b/includes/handler/class-like.php index 94facde4..1e951576 100644 --- a/includes/handler/class-like.php +++ b/includes/handler/class-like.php @@ -31,18 +31,15 @@ class Like { /** * Handles "Like" requests. * - * @param array $array The Activity array. - * @param int $user_id The ID of the local blog user. - * @param \Activitypub\Activity\Activity $activity The Activity object. - * - * @return void + * @param array $like The Activity array. + * @param int $user_id The ID of the local blog user. */ - public static function handle_like( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound,VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable,Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed + public static function handle_like( $like, $user_id ) { if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) { return; } - $url = object_to_uri( $array['object'] ); + $url = object_to_uri( $like['object'] ); if ( empty( $url ) ) { return; @@ -53,13 +50,21 @@ class Like { return; } - $state = Interactions::add_reaction( $array ); + $state = Interactions::add_reaction( $like ); $reaction = null; if ( $state && ! is_wp_error( $state ) ) { $reaction = get_comment( $state ); } - do_action( 'activitypub_handled_like', $array, $user_id, $state, $reaction ); + /** + * Fires after a Like has been handled. + * + * @param array $like The Activity array. + * @param int $user_id The ID of the local blog user. + * @param mixed $state The state of the reaction. + * @param mixed $reaction The reaction object. + */ + do_action( 'activitypub_handled_like', $like, $user_id, $state, $reaction ); } } diff --git a/includes/model/class-follower.php b/includes/model/class-follower.php index af30303d..45ef6157 100644 --- a/includes/model/class-follower.php +++ b/includes/model/class-follower.php @@ -149,7 +149,7 @@ class Follower extends Actor { if ( ! $this->get__id() ) { global $wpdb; - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching + // phpcs:ignore WordPress.DB.DirectDatabaseQuery $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid=%s", diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 9218874b..461d4286 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -102,7 +102,7 @@ class Outbox { $json->next = \add_query_arg( 'page', $page + 1, $json->partOf ); } - if ( $page && ( $page > 1 ) ) { // phpcs:ignore + if ( $page && ( $page > 1 ) ) { $json->prev = \add_query_arg( 'page', $page - 1, $json->partOf ); } // phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase diff --git a/includes/table/class-followers.php b/includes/table/class-followers.php index b1b0cec8..991f97c1 100644 --- a/includes/table/class-followers.php +++ b/includes/table/class-followers.php @@ -92,26 +92,22 @@ class Followers extends WP_List_Table { $args = array(); - // phpcs:ignore WordPress.Security.NonceVerification.Recommended + // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['orderby'] ) ) { - // phpcs:ignore WordPress.Security.NonceVerification.Recommended $args['orderby'] = sanitize_text_field( wp_unslash( $_GET['orderby'] ) ); } - // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['order'] ) ) { - // phpcs:ignore WordPress.Security.NonceVerification.Recommended $args['order'] = sanitize_text_field( wp_unslash( $_GET['order'] ) ); } - // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['s'] ) && isset( $_REQUEST['_wpnonce'] ) ) { $nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ); if ( wp_verify_nonce( $nonce, 'bulk-' . $this->_args['plural'] ) ) { - // phpcs:ignore WordPress.Security.NonceVerification.Recommended $args['s'] = sanitize_text_field( wp_unslash( $_GET['s'] ) ); } } + // phpcs:enable WordPress.Security.NonceVerification.Recommended $followers_with_count = FollowerCollection::get_followers_with_count( $this->user_id, $per_page, $page_num, $args ); $followers = $followers_with_count['followers']; @@ -219,7 +215,7 @@ class Followers extends WP_List_Table { return; } - $followers = $_REQUEST['followers']; // phpcs:ignore + $followers = $_REQUEST['followers']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput if ( $this->current_action() === 'delete' ) { if ( ! is_array( $followers ) ) { diff --git a/includes/transformer/class-factory.php b/includes/transformer/class-factory.php index e8e59796..a619423a 100644 --- a/includes/transformer/class-factory.php +++ b/includes/transformer/class-factory.php @@ -10,21 +10,22 @@ namespace Activitypub\Transformer; use WP_Error; /** - * Transformer Factory + * Transformer Factory. */ class Factory { /** * Get the transformer for a given object. * - * @param mixed $object The object to transform. + * @param mixed $data The object to transform. + * * @return Base|WP_Error The transformer to use, or an error. */ - public static function get_transformer( $object ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound - if ( ! \is_object( $object ) ) { + public static function get_transformer( $data ) { + if ( ! \is_object( $data ) ) { return new WP_Error( 'invalid_object', __( 'Invalid object', 'activitypub' ) ); } - $class = \get_class( $object ); + $class = \get_class( $data ); /** * Filter the transformer for a given object. @@ -50,12 +51,12 @@ class Factory { * }, 10, 3 ); * * @param Base $transformer The transformer to use. - * @param mixed $object The object to transform. + * @param mixed $data The object to transform. * @param string $object_class The class of the object to transform. * * @return mixed The transformer to use. */ - $transformer = \apply_filters( 'activitypub_transformer', null, $object, $class ); + $transformer = \apply_filters( 'activitypub_transformer', null, $data, $class ); if ( $transformer ) { if ( @@ -71,12 +72,12 @@ class Factory { // Use default transformer. switch ( $class ) { case 'WP_Post': - if ( 'attachment' === $object->post_type ) { - return new Attachment( $object ); + if ( 'attachment' === $data->post_type ) { + return new Attachment( $data ); } - return new Post( $object ); + return new Post( $data ); case 'WP_Comment': - return new Comment( $object ); + return new Comment( $data ); default: return null; } diff --git a/includes/transformer/class-post.php b/includes/transformer/class-post.php index 85a8b809..f18693fb 100644 --- a/includes/transformer/class-post.php +++ b/includes/transformer/class-post.php @@ -868,8 +868,8 @@ class Post extends Base { $template = "[ap_content]\n\n[ap_permalink type=\"html\"]\n\n[ap_hashtags]"; break; default: - // phpcs:ignore Universal.Operators.DisallowShortTernary.Found - $template = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT ) ?: ACTIVITYPUB_CUSTOM_POST_CONTENT; + $content = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT ); + $template = empty( $content ) ? ACTIVITYPUB_CUSTOM_POST_CONTENT : $content; break; } diff --git a/integration/load.php b/integration/load.php index 0bdef288..860f2dc7 100644 --- a/integration/load.php +++ b/integration/load.php @@ -79,14 +79,13 @@ function plugin_init() { if ( \defined( 'SSP_VERSION' ) ) { add_filter( 'activitypub_transformer', - // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound - function ( $transformer, $object, $object_class ) { + function ( $transformer, $data, $object_class ) { if ( 'WP_Post' === $object_class && - \get_post_meta( $object->ID, 'audio_file', true ) + \get_post_meta( $data->ID, 'audio_file', true ) ) { require_once __DIR__ . '/class-seriously-simple-podcasting.php'; - return new Seriously_Simple_Podcasting( $object ); + return new Seriously_Simple_Podcasting( $data ); } return $transformer; }, diff --git a/phpcs.xml b/phpcs.xml index 8a5449b9..f75f4d73 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,14 +1,12 @@ WordPress ActivityPub Standards - ./activitypub.php - ./includes/ - ./integration/ - ./build/ + . *\.(inc|css|js|svg) */vendor/* */node_modules/* + */tests/* *.asset.php diff --git a/templates/admin-header.php b/templates/admin-header.php index 301f7348..c453328d 100644 --- a/templates/admin-header.php +++ b/templates/admin-header.php @@ -5,6 +5,16 @@ * @package Activitypub */ +/* @var array $args Template arguments. */ +$args = wp_parse_args( + $args, + array( + 'welcome' => '', + 'settings' => '', + 'blog-profile' => '', + 'followers' => '', + ) +); ?>
@@ -12,21 +22,21 @@