Merge branch 'master' into signature_verification

This commit is contained in:
Matthias Pfefferle 2023-05-19 12:01:53 +02:00 committed by GitHub
commit 92712e1d4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 18 deletions

View file

@ -15,6 +15,8 @@
namespace Activitypub;
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
/**
* Initialize plugin
*/
@ -26,7 +28,6 @@ function init() {
\defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<strong>[ap_title]</strong>\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" );
\defined( 'ACTIVITYPUB_SECURE_MODE' ) || \define( 'ACTIVITYPUB_SECURE_MODE', apply_filters( 'activitypub_secure_mode', $value = false ) );
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
@ -42,7 +43,6 @@ function init() {
Rest\Inbox::init();
Rest\Followers::init();
Rest\Following::init();
Rest\Nodeinfo::init();
Rest\Webfinger::init();
Rest\Server::init();
@ -131,7 +131,7 @@ function plugin_settings_link( $actions ) {
)
);
register_uninstall_hook(
\register_uninstall_hook(
__FILE__,
array(
__NAMESPACE__ . '\Activitypub',

View file

@ -1,11 +1,16 @@
<?php
namespace Activitypub\Rest;
use WP_Error;
use WP_REST_Server;
use WP_REST_Response;
use Activitypub\Signature;
use Activitypub\Model\Activity;
use function Activitypub\get_context;
use function Activitypub\url_to_authorid;
use function Activitypub\get_rest_url_by_path;
use function Activitypub\get_remote_metadata_by_actor;
/**
* ActivityPub Inbox REST-Class
@ -33,7 +38,7 @@ class Inbox {
'/inbox',
array(
array(
'methods' => \WP_REST_Server::EDITABLE,
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( self::class, 'shared_inbox_post' ),
'args' => self::shared_inbox_post_parameters(),
'permission_callback' => '__return_true',
@ -46,13 +51,13 @@ class Inbox {
'/users/(?P<user_id>\d+)/inbox',
array(
array(
'methods' => \WP_REST_Server::EDITABLE,
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( self::class, 'user_inbox_post' ),
'args' => self::user_inbox_post_parameters(),
'permission_callback' => '__return_true',
),
array(
'methods' => \WP_REST_Server::READABLE,
'methods' => WP_REST_Server::READABLE,
'callback' => array( self::class, 'user_inbox_get' ),
'args' => self::user_inbox_get_parameters(),
'permission_callback' => '__return_true',
@ -78,7 +83,7 @@ class Inbox {
$json = new \stdClass();
$json->{'@context'} = \Activitypub\get_context();
$json->{'@context'} = get_context();
$json->id = \home_url( \add_query_arg( null, null ) );
$json->generator = 'http://wordpress.org/?v=' . \get_bloginfo_rss( 'version' );
$json->type = 'OrderedCollectionPage';
@ -140,7 +145,7 @@ class Inbox {
$users = self::extract_recipients( $data );
if ( ! $users ) {
return new \WP_Error(
return new WP_Error(
'rest_invalid_param',
\__( 'No recipients found', 'activitypub' ),
array(
@ -324,7 +329,7 @@ class Inbox {
* @param int $user_id The id of the local blog-user
*/
public static function handle_reaction( $object, $user_id ) {
$meta = \Activitypub\get_remote_metadata_by_actor( $object['actor'] );
$meta = get_remote_metadata_by_actor( $object['actor'] );
$comment_post_id = \url_to_postid( $object['object'] );
@ -369,7 +374,7 @@ class Inbox {
* @param int $user_id The id of the local blog-user
*/
public static function handle_create( $object, $user_id ) {
$meta = \Activitypub\get_remote_metadata_by_actor( $object['actor'] );
$meta = get_remote_metadata_by_actor( $object['actor'] );
if ( ! isset( $object['object']['inReplyTo'] ) ) {
return;
@ -476,7 +481,7 @@ class Inbox {
$users = array();
foreach ( $recipients as $recipient ) {
$user_id = \Activitypub\url_to_authorid( $recipient );
$user_id = url_to_authorid( $recipient );
$user = get_user_by( 'id', $user_id );

View file

@ -1,6 +1,13 @@
<?php
namespace Activitypub\Rest;
use stdClass;
use WP_Error;
use WP_REST_Server;
use WP_REST_Response;
use Activitypub\Model\Post;
use Activitypub\Model\Activity;
use function Activitypub\get_rest_url_by_path;
/**
@ -27,7 +34,7 @@ class Outbox {
'/users/(?P<user_id>\d+)/outbox',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'methods' => WP_REST_Server::READABLE,
'callback' => array( self::class, 'user_outbox_get' ),
'args' => self::request_parameters(),
'permission_callback' => '__return_true',
@ -48,7 +55,7 @@ class Outbox {
$post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) );
if ( ! $author ) {
return new \WP_Error(
return new WP_Error(
'rest_invalid_param',
\__( 'User not found', 'activitypub' ),
array(
@ -67,9 +74,9 @@ class Outbox {
*/
\do_action( 'activitypub_outbox_pre' );
$json = new \stdClass();
$json = new stdClass();
$json->{'@context'} = \Activitypub\get_context();
$json->{'@context'} = get_context();
$json->id = \home_url( \add_query_arg( null, null ) );
$json->generator = 'http://wordpress.org/?v=' . \get_bloginfo_rss( 'version' );
$json->actor = \get_author_posts_url( $user_id );
@ -103,8 +110,8 @@ class Outbox {
);
foreach ( $posts as $post ) {
$activitypub_post = new \Activitypub\Model\Post( $post );
$activitypub_activity = new \Activitypub\Model\Activity( 'Create', false );
$activitypub_post = new Post( $post );
$activitypub_activity = new Activity( 'Create', false );
$activitypub_activity->from_post( $activitypub_post );
$json->orderedItems[] = $activitypub_activity->to_array(); // phpcs:ignore
@ -119,7 +126,7 @@ class Outbox {
*/
\do_action( 'activitypub_outbox_post' );
$response = new \WP_REST_Response( $json, 200 );
$response = new WP_REST_Response( $json, 200 );
$response->header( 'Content-Type', 'application/activity+json' );