phpcs fixes
This commit is contained in:
parent
56458da618
commit
44c652eba8
13 changed files with 122 additions and 63 deletions
|
@ -72,9 +72,12 @@ function init() {
|
||||||
\Activitypub\Health_Check::init();
|
\Activitypub\Health_Check::init();
|
||||||
|
|
||||||
require_once \dirname( __FILE__ ) . '/includes/rest/class-server.php';
|
require_once \dirname( __FILE__ ) . '/includes/rest/class-server.php';
|
||||||
\add_filter( 'wp_rest_server_class', function() {
|
\add_filter(
|
||||||
return '\Activitypub\Rest\Server';
|
'wp_rest_server_class',
|
||||||
} );
|
function() {
|
||||||
|
return '\Activitypub\Rest\Server';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if ( \WP_DEBUG ) {
|
if ( \WP_DEBUG ) {
|
||||||
require_once \dirname( __FILE__ ) . '/includes/debug.php';
|
require_once \dirname( __FILE__ ) . '/includes/debug.php';
|
||||||
|
|
|
@ -54,7 +54,9 @@ class Admin {
|
||||||
*/
|
*/
|
||||||
public static function register_settings() {
|
public static function register_settings() {
|
||||||
\register_setting(
|
\register_setting(
|
||||||
'activitypub', 'activitypub_post_content_type', array(
|
'activitypub',
|
||||||
|
'activitypub_post_content_type',
|
||||||
|
array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ),
|
'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ),
|
||||||
'show_in_rest' => array(
|
'show_in_rest' => array(
|
||||||
|
@ -66,7 +68,9 @@ class Admin {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
\register_setting(
|
\register_setting(
|
||||||
'activitypub', 'activitypub_custom_post_content', array(
|
'activitypub',
|
||||||
|
'activitypub_custom_post_content',
|
||||||
|
array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'description' => \__( 'Define your own custom post template', 'activitypub' ),
|
'description' => \__( 'Define your own custom post template', 'activitypub' ),
|
||||||
'show_in_rest' => true,
|
'show_in_rest' => true,
|
||||||
|
@ -74,7 +78,9 @@ class Admin {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
\register_setting(
|
\register_setting(
|
||||||
'activitypub', 'activitypub_object_type', array(
|
'activitypub',
|
||||||
|
'activitypub_object_type',
|
||||||
|
array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'description' => \__( 'The Activity-Object-Type', 'activitypub' ),
|
'description' => \__( 'The Activity-Object-Type', 'activitypub' ),
|
||||||
'show_in_rest' => array(
|
'show_in_rest' => array(
|
||||||
|
@ -86,21 +92,27 @@ class Admin {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
\register_setting(
|
\register_setting(
|
||||||
'activitypub', 'activitypub_use_hashtags', array(
|
'activitypub',
|
||||||
|
'activitypub_use_hashtags',
|
||||||
|
array(
|
||||||
'type' => 'boolean',
|
'type' => 'boolean',
|
||||||
'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
|
'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
|
||||||
'default' => 0,
|
'default' => 0,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
\register_setting(
|
\register_setting(
|
||||||
'activitypub', 'activitypub_allowed_html', array(
|
'activitypub',
|
||||||
|
'activitypub_allowed_html',
|
||||||
|
array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'description' => \__( 'List of HTML elements that are allowed in activities.', 'activitypub' ),
|
'description' => \__( 'List of HTML elements that are allowed in activities.', 'activitypub' ),
|
||||||
'default' => ACTIVITYPUB_ALLOWED_HTML,
|
'default' => ACTIVITYPUB_ALLOWED_HTML,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
\register_setting(
|
\register_setting(
|
||||||
'activitypub', 'activitypub_support_post_types', array(
|
'activitypub',
|
||||||
|
'activitypub_support_post_types',
|
||||||
|
array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ),
|
'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ),
|
||||||
'show_in_rest' => true,
|
'show_in_rest' => true,
|
||||||
|
|
|
@ -123,11 +123,13 @@ function get_remote_metadata_by_actor( $actor ) {
|
||||||
return new \WP_Error( 'activitypub_no_valid_actor_url', \__( 'The "actor" is no valid URL', 'activitypub' ), $actor );
|
return new \WP_Error( 'activitypub_no_valid_actor_url', \__( 'The "actor" is no valid URL', 'activitypub' ), $actor );
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = \get_users( array (
|
$user = \get_users(
|
||||||
'number' => 1,
|
array(
|
||||||
'who' => 'authors',
|
'number' => 1,
|
||||||
'fields' => 'ID',
|
'who' => 'authors',
|
||||||
) );
|
'fields' => 'ID',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// we just need any user to generate a request signature
|
// we just need any user to generate a request signature
|
||||||
$user_id = \reset( $user );
|
$user_id = \reset( $user );
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->type = \ucfirst( $type );
|
$this->type = \ucfirst( $type );
|
||||||
$this->published = \date( 'Y-m-d\TH:i:s\Z', \strtotime( 'now' ) );
|
$this->published = \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( 'now' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __call( $method, $params ) {
|
public function __call( $method, $params ) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ class Post {
|
||||||
$array = array(
|
$array = array(
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'type' => $this->object_type,
|
'type' => $this->object_type,
|
||||||
'published' => \date( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_date_gmt ) ),
|
'published' => \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_date_gmt ) ),
|
||||||
'attributedTo' => \get_author_posts_url( $post->post_author ),
|
'attributedTo' => \get_author_posts_url( $post->post_author ),
|
||||||
'summary' => $this->summary,
|
'summary' => $this->summary,
|
||||||
'inReplyTo' => null,
|
'inReplyTo' => null,
|
||||||
|
|
|
@ -50,9 +50,13 @@ class Followers {
|
||||||
$actor = $actor['id'];
|
$actor = $actor['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return new \WP_Error( 'invalid_actor_object', \__( 'Unknown Actor schema', 'activitypub' ), array(
|
return new \WP_Error(
|
||||||
'status' => 404,
|
'invalid_actor_object',
|
||||||
) );
|
\__( 'Unknown Actor schema', 'activitypub' ),
|
||||||
|
array(
|
||||||
|
'status' => 404,
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! \is_array( $followers ) ) {
|
if ( ! \is_array( $followers ) ) {
|
||||||
|
|
|
@ -21,7 +21,9 @@ class Followers {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0', '/users/(?P<user_id>\d+)/followers', array(
|
'activitypub/1.0',
|
||||||
|
'/users/(?P<user_id>\d+)/followers',
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( '\Activitypub\Rest\Followers', 'get' ),
|
'callback' => array( '\Activitypub\Rest\Followers', 'get' ),
|
||||||
|
@ -44,12 +46,16 @@ class Followers {
|
||||||
$user = \get_user_by( 'ID', $user_id );
|
$user = \get_user_by( 'ID', $user_id );
|
||||||
|
|
||||||
if ( ! $user ) {
|
if ( ! $user ) {
|
||||||
return new \WP_Error( 'rest_invalid_param', \__( 'User not found', 'activitypub' ), array(
|
return new \WP_Error(
|
||||||
'status' => 404,
|
'rest_invalid_param',
|
||||||
'params' => array(
|
\__( 'User not found', 'activitypub' ),
|
||||||
'user_id' => \__( 'User not found', 'activitypub' ),
|
array(
|
||||||
),
|
'status' => 404,
|
||||||
) );
|
'params' => array(
|
||||||
|
'user_id' => \__( 'User not found', 'activitypub' ),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -21,7 +21,9 @@ class Following {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0', '/users/(?P<user_id>\d+)/following', array(
|
'activitypub/1.0',
|
||||||
|
'/users/(?P<user_id>\d+)/following',
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( '\Activitypub\Rest\Following', 'get' ),
|
'callback' => array( '\Activitypub\Rest\Following', 'get' ),
|
||||||
|
@ -44,12 +46,16 @@ class Following {
|
||||||
$user = \get_user_by( 'ID', $user_id );
|
$user = \get_user_by( 'ID', $user_id );
|
||||||
|
|
||||||
if ( ! $user ) {
|
if ( ! $user ) {
|
||||||
return new \WP_Error( 'rest_invalid_param', \__( 'User not found', 'activitypub' ), array(
|
return new \WP_Error(
|
||||||
'status' => 404,
|
'rest_invalid_param',
|
||||||
'params' => array(
|
\__( 'User not found', 'activitypub' ),
|
||||||
'user_id' => \__( 'User not found', 'activitypub' ),
|
array(
|
||||||
),
|
'status' => 404,
|
||||||
) );
|
'params' => array(
|
||||||
|
'user_id' => \__( 'User not found', 'activitypub' ),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -27,7 +27,9 @@ class Inbox {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0', '/inbox', array(
|
'activitypub/1.0',
|
||||||
|
'/inbox',
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::EDITABLE,
|
'methods' => \WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( '\Activitypub\Rest\Inbox', 'shared_inbox_post' ),
|
'callback' => array( '\Activitypub\Rest\Inbox', 'shared_inbox_post' ),
|
||||||
|
@ -38,7 +40,9 @@ class Inbox {
|
||||||
);
|
);
|
||||||
|
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0', '/users/(?P<user_id>\d+)/inbox', array(
|
'activitypub/1.0',
|
||||||
|
'/users/(?P<user_id>\d+)/inbox',
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::EDITABLE,
|
'methods' => \WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( '\Activitypub\Rest\Inbox', 'user_inbox_post' ),
|
'callback' => array( '\Activitypub\Rest\Inbox', 'user_inbox_post' ),
|
||||||
|
@ -161,16 +165,20 @@ class Inbox {
|
||||||
$users = self::extract_recipients( $data );
|
$users = self::extract_recipients( $data );
|
||||||
|
|
||||||
if ( ! $users ) {
|
if ( ! $users ) {
|
||||||
return new \WP_Error( 'rest_invalid_param', \__( 'No recipients found', 'activitypub' ), array(
|
return new \WP_Error(
|
||||||
'status' => 404,
|
'rest_invalid_param',
|
||||||
'params' => array(
|
\__( 'No recipients found', 'activitypub' ),
|
||||||
'to' => \__( 'Please check/validate "to" field', 'activitypub' ),
|
array(
|
||||||
'bto' => \__( 'Please check/validate "bto" field', 'activitypub' ),
|
'status' => 404,
|
||||||
'cc' => \__( 'Please check/validate "cc" field', 'activitypub' ),
|
'params' => array(
|
||||||
'bcc' => \__( 'Please check/validate "bcc" field', 'activitypub' ),
|
'to' => \__( 'Please check/validate "to" field', 'activitypub' ),
|
||||||
'audience' => \__( 'Please check/validate "audience" field', 'activitypub' ),
|
'bto' => \__( 'Please check/validate "bto" field', 'activitypub' ),
|
||||||
),
|
'cc' => \__( 'Please check/validate "cc" field', 'activitypub' ),
|
||||||
) );
|
'bcc' => \__( 'Please check/validate "bcc" field', 'activitypub' ),
|
||||||
|
'audience' => \__( 'Please check/validate "audience" field', 'activitypub' ),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $users as $user ) {
|
foreach ( $users as $user ) {
|
||||||
|
|
|
@ -23,7 +23,9 @@ class Nodeinfo {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0', '/nodeinfo/discovery', array(
|
'activitypub/1.0',
|
||||||
|
'/nodeinfo/discovery',
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'discovery' ),
|
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'discovery' ),
|
||||||
|
@ -33,7 +35,9 @@ class Nodeinfo {
|
||||||
);
|
);
|
||||||
|
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0', '/nodeinfo', array(
|
'activitypub/1.0',
|
||||||
|
'/nodeinfo',
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo' ),
|
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo' ),
|
||||||
|
@ -43,7 +47,9 @@ class Nodeinfo {
|
||||||
);
|
);
|
||||||
|
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0', '/nodeinfo2', array(
|
'activitypub/1.0',
|
||||||
|
'/nodeinfo2',
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo2' ),
|
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo2' ),
|
||||||
|
|
|
@ -14,7 +14,9 @@ class Ostatus {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0', '/ostatus/remote-follow', array(
|
'activitypub/1.0',
|
||||||
|
'/ostatus/remote-follow',
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( '\Activitypub\Rest\Ostatus', 'get' ),
|
'callback' => array( '\Activitypub\Rest\Ostatus', 'get' ),
|
||||||
|
|
|
@ -21,7 +21,9 @@ class Outbox {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0', '/users/(?P<user_id>\d+)/outbox', array(
|
'activitypub/1.0',
|
||||||
|
'/users/(?P<user_id>\d+)/outbox',
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( '\Activitypub\Rest\Outbox', 'user_outbox_get' ),
|
'callback' => array( '\Activitypub\Rest\Outbox', 'user_outbox_get' ),
|
||||||
|
@ -43,12 +45,16 @@ class Outbox {
|
||||||
$author = \get_user_by( 'ID', $user_id );
|
$author = \get_user_by( 'ID', $user_id );
|
||||||
|
|
||||||
if ( ! $author ) {
|
if ( ! $author ) {
|
||||||
return new \WP_Error( 'rest_invalid_param', \__( 'User not found', 'activitypub' ), array(
|
return new \WP_Error(
|
||||||
'status' => 404,
|
'rest_invalid_param',
|
||||||
'params' => array(
|
\__( 'User not found', 'activitypub' ),
|
||||||
'user_id' => \__( 'User not found', 'activitypub' ),
|
array(
|
||||||
),
|
'status' => 404,
|
||||||
) );
|
'params' => array(
|
||||||
|
'user_id' => \__( 'User not found', 'activitypub' ),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = $request->get_param( 'page', 0 );
|
$page = $request->get_param( 'page', 0 );
|
||||||
|
@ -78,12 +84,14 @@ class Outbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $page ) {
|
if ( $page ) {
|
||||||
$posts = \get_posts( array(
|
$posts = \get_posts(
|
||||||
'posts_per_page' => 10,
|
array(
|
||||||
'author' => $user_id,
|
'posts_per_page' => 10,
|
||||||
'offset' => ( $page - 1 ) * 10,
|
'author' => $user_id,
|
||||||
'post_type' => 'post',
|
'offset' => ( $page - 1 ) * 10,
|
||||||
) );
|
'post_type' => 'post',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
foreach ( $posts as $post ) {
|
foreach ( $posts as $post ) {
|
||||||
$activitypub_post = new \Activitypub\Model\Post( $post );
|
$activitypub_post = new \Activitypub\Model\Post( $post );
|
||||||
|
|
|
@ -22,7 +22,9 @@ class Webfinger {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0', '/webfinger', array(
|
'activitypub/1.0',
|
||||||
|
'/webfinger',
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( '\Activitypub\Rest\Webfinger', 'webfinger' ),
|
'callback' => array( '\Activitypub\Rest\Webfinger', 'webfinger' ),
|
||||||
|
|
Loading…
Reference in a new issue