Skip to content

Commit

Permalink
Merge branch 'trunk' into add/emoji-support
Browse files Browse the repository at this point in the history
  • Loading branch information
obenland authored Jan 10, 2025
2 parents cefc518 + dfc23ad commit 76f5d33
Show file tree
Hide file tree
Showing 18 changed files with 516 additions and 177 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ jobs:
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10
strategy:
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
include:
- wp-version: latest
- wp-version: '6.5'
php-versions: '7.0'
- wp-version: '6.5'
php-versions: '7.1'
- wp-version: '5.9'
php-versions: '7.2'
steps:
- name: Install svn
run: |
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* Support for custom emoji in interaction contents and actor names
* Comment counts get updated when the plugin is activated/deactivated/deleted
* Added a filter to make custom comment types manageable in WP.com Calypso

### Changed

* Hide ActivityPub post meta keys from the custom Fields UI
* Bumped minimum required PHP version to 7.2

### Fixed

* Undefined array key warnings in various places
* @-mentions in federated comments being displayed with a line break
* Fetching replies from the same instance for Enable Mastodon Apps
* Image captions not being included in the ActivityPub representation when the image is attached to the post

Expand Down
4 changes: 2 additions & 2 deletions activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Author URI: https://automattic.com/
* License: MIT
* License URI: http://opensource.org/licenses/MIT
* Requires PHP: 7.0
* Requires PHP: 7.2
* Text Domain: activitypub
* Domain Path: /languages
*
Expand Down Expand Up @@ -44,12 +44,12 @@ function rest_init() {
Rest\Inbox::init();
Rest\Followers::init();
Rest\Following::init();
Rest\Webfinger::init();
Rest\Comment::init();
Rest\Server::init();
Rest\Collection::init();
Rest\Interaction::init();
Rest\Post::init();
( new Rest\Webfinger_Controller() )->register_routes();

// Load NodeInfo endpoints only if blog is public.
if ( is_blog_public() ) {
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"description": "The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.",
"type": "wordpress-plugin",
"require": {
"php": ">=7.0",
"php": ">=7.2",
"composer/installers": "^1.0 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8",
"phpunit/phpunit": "^8 || ^9",
"phpcompatibility/php-compatibility": "*",
"phpcompatibility/phpcompatibility-wp": "*",
"squizlabs/php_codesniffer": "3.*",
Expand Down
9 changes: 9 additions & 0 deletions includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public static function init() {
public static function activate() {
self::flush_rewrite_rules();
Scheduler::register_schedules();

\add_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ), 10, 3 );
Migration::update_comment_counts();
}

/**
Expand All @@ -70,13 +73,19 @@ public static function activate() {
public static function deactivate() {
self::flush_rewrite_rules();
Scheduler::deregister_schedules();

\remove_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ) );
Migration::update_comment_counts( 2000 );
}

/**
* Uninstall Hook.
*/
public static function uninstall() {
Scheduler::deregister_schedules();

\remove_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ) );
Migration::update_comment_counts( 2000 );
}

/**
Expand Down
173 changes: 173 additions & 0 deletions includes/rest/class-webfinger-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php
/**
* WebFinger REST-Class file.
*
* @package Activitypub
*/

namespace Activitypub\Rest;

/**
* ActivityPub WebFinger REST-Class.
*
* @author Matthias Pfefferle
*
* @see https://webfinger.net/
*/
class Webfinger_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 = 'webfinger';

/**
* 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_item' ),
'permission_callback' => '__return_true',
'args' => array(
'resource' => array(
'description' => 'The WebFinger resource.',
'type' => 'string',
'required' => true,
'pattern' => '^(acct:)|^(https?://)(.+)$',
),
),
),
'schema' => array( $this, 'get_item_schema' ),
)
);
}

/**
* Retrieves the WebFinger profile.
*
* @param \WP_REST_Request $request The request object.
*
* @return \WP_REST_Response Response object.
*/
public function get_item( $request ) {
/**
* Action triggered prior to the ActivityPub profile being created and sent to the client.
*/
\do_action( 'activitypub_rest_webfinger_pre' );

$resource = $request->get_param( 'resource' );
$response = $this->get_profile( $resource );
$code = 200;

if ( \is_wp_error( $response ) ) {
$code = 400;
$error_data = $response->get_error_data();

if ( isset( $error_data['status'] ) ) {
$code = $error_data['status'];
}
}

return new \WP_REST_Response(
$response,
$code,
array(
'Access-Control-Allow-Origin' => '*',
'Content-Type' => 'application/jrd+json; charset=' . \get_option( 'blog_charset' ),
)
);
}

/**
* Get the WebFinger profile.
*
* @param string $webfinger The WebFinger resource.
*
* @return array|\WP_Error The WebFinger profile or WP_Error if not found.
*/
public function get_profile( $webfinger ) {
/**
* Filter the WebFinger data.
*
* @param array $data The WebFinger data.
* @param string $webfinger The WebFinger resource.
*/
return \apply_filters( 'webfinger_data', array(), $webfinger );
}

/**
* Retrieves the schema for the WebFinger endpoint.
*
* @return array Schema data.
*/
public function get_item_schema() {
if ( $this->schema ) {
return $this->add_additional_fields_schema( $this->schema );
}

$this->schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'webfinger',
'type' => 'object',
'required' => array( 'subject', 'links' ),
'properties' => array(
'subject' => array(
'description' => 'The subject of this WebFinger record.',
'type' => 'string',
'format' => 'uri',
),
'aliases' => array(
'description' => 'Alternative identifiers for the subject.',
'type' => 'array',
'items' => array(
'type' => 'string',
'format' => 'uri',
),
),
'links' => array(
'description' => 'Links associated with the subject.',
'type' => 'array',
'items' => array(
'type' => 'object',
'properties' => array(
'rel' => array(
'description' => 'The relation type of the link.',
'type' => 'string',
'required' => true,
),
'type' => array(
'description' => 'The content type of the link.',
'type' => 'string',
),
'href' => array(
'description' => 'The target URL of the link.',
'type' => 'string',
'format' => 'uri',
),
'template' => array(
'description' => 'A URI template for the link.',
'type' => 'string',
'format' => 'uri',
),
),
),
),
),
);

return $this->add_additional_fields_schema( $this->schema );
}
}
116 changes: 0 additions & 116 deletions includes/rest/class-webfinger.php

This file was deleted.

Loading

0 comments on commit 76f5d33

Please sign in to comment.