updated plugin ActivityPub
version 5.8.0
This commit is contained in:
wp-content/plugins/activitypub
activitypub.php
assets
build
editor-plugin
follow-me
followers
reactions
remote-reply
reply-intent
reply
includes
activity
class-activity-dispatcher.phpclass-activitypub.phpclass-admin.phpclass-autoloader.phpclass-blocks.phpclass-cli.phpclass-comment.phpclass-debug.phpclass-dispatcher.phpclass-embed.phpclass-handler.phpclass-hashtag.phpclass-health-check.phpclass-http.phpclass-link.phpclass-mailer.phpclass-mention.phpclass-migration.phpclass-move.phpclass-notification.phpclass-options.phpclass-query.phpclass-sanitize.phpclass-scheduler.phpclass-shortcodes.phpclass-signature.phpclass-webfinger.phpcollection
class-actors.phpclass-extra-fields.phpclass-followers.phpclass-interactions.phpclass-outbox.phpclass-replies.phpclass-users.php
compat.phpconstants.phpdebug.phpfunctions.phphandler
class-announce.phpclass-create.phpclass-delete.phpclass-follow.phpclass-like.phpclass-move.phpclass-undo.phpclass-update.php
help.phpmodel
rest
class-actors-controller.phpclass-actors-inbox-controller.phpclass-actors.phpclass-application-controller.phpclass-collection.phpclass-collections-controller.phpclass-comment.phpclass-comments-controller.phpclass-followers-controller.phpclass-followers.phpclass-following-controller.phpclass-following.phpclass-inbox-controller.phpclass-inbox.phpclass-interaction-controller.phpclass-interaction.phpclass-moderators-controller.phpclass-nodeinfo-controller.phpclass-nodeinfo.phpclass-outbox-controller.phpclass-outbox.phpclass-post.phpclass-replies-controller.phpclass-server.phpclass-url-validator-controller.phpclass-webfinger-controller.phpclass-webfinger.phptrait-collection.php
scheduler
table
transformer
integration
class-akismet.phpclass-enable-mastodon-apps.phpclass-jetpack.phpclass-multisite-language-switcher.phpclass-nodeinfo.phpclass-opengraph.phpclass-seriously-simple-podcasting.phpclass-stream-connector.phpclass-webfinger.phpclass-wpml.phpload.php
readme.txttemplates
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* ActivityPub URL Validator Controller.
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Rest;
|
||||
|
||||
use Activitypub\Http;
|
||||
use Activitypub\Embed;
|
||||
|
||||
/**
|
||||
* URL Validator Controller Class.
|
||||
*/
|
||||
class URL_Validator_Controller extends \WP_REST_Controller {
|
||||
/**
|
||||
* The namespace of this controller's route.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = ACTIVITYPUB_REST_NAMESPACE;
|
||||
|
||||
/**
|
||||
* The base of this controller's route.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'url/validate';
|
||||
|
||||
/**
|
||||
* Register routes.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => array(
|
||||
'url' => array(
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'required' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given request has access to validate URLs.
|
||||
*
|
||||
* @param \WP_REST_Request $request The request.
|
||||
*
|
||||
* @return bool True if the request has access to validate URLs, false otherwise.
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
return current_user_can( 'edit_posts' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if URL is a valid ActivityPub endpoint.
|
||||
*
|
||||
* @param \WP_REST_Request $request The request.
|
||||
*
|
||||
* @return \WP_REST_Response|\WP_Error
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$url = $request->get_param( 'url' );
|
||||
$object = Http::get_remote_object( $url );
|
||||
|
||||
if ( is_wp_error( $object ) ) {
|
||||
return new \WP_Error(
|
||||
'activitypub_invalid_url',
|
||||
__( 'Invalid URL.', 'activitypub' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
|
||||
$response = array(
|
||||
'is_activitypub' => ! empty( $object['type'] ),
|
||||
'is_real_oembed' => Embed::has_real_oembed( $url ),
|
||||
'html' => false,
|
||||
);
|
||||
|
||||
if ( $response['is_activitypub'] ) {
|
||||
$response['html'] = wp_oembed_get( $url );
|
||||
}
|
||||
|
||||
return rest_ensure_response( $response );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL validation schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
if ( $this->schema ) {
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'validated-url',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'is_activitypub' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
),
|
||||
'is_real_oembed' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
),
|
||||
'html' => array(
|
||||
'type' => 'string',
|
||||
'default' => false,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->schema = $schema;
|
||||
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user