Skip to content

Commit

Permalink
Merge branch 'master' into add/outbox-collection
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle authored Dec 21, 2023
2 parents 1558551 + a3ea995 commit 6edc4b5
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 25 deletions.
1 change: 1 addition & 0 deletions FEDERATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The WordPress plugin largely follows ActivityPub's server-to-server specificatio
- [FEP-f1d5: NodeInfo in Fediverse Software](https://codeberg.org/fediverse/fep/src/branch/main/fep/f1d5/fep-f1d5.md)
- [FEP-67ff: FEDERATION.md](https://codeberg.org/fediverse/fep/src/branch/main/fep/67ff/fep-67ff.md)
- [FEP-5feb: Search indexing consent for actors](https://codeberg.org/fediverse/fep/src/branch/main/fep/5feb/fep-5feb.md)
- [FEP-2677: Identifying the Application Actor](https://codeberg.org/fediverse/fep/src/branch/main/fep/2677/fep-2677.md)

Partially supported FEPs

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
* Fixed: Normalize attributes that can have mixed value types
* Added: URL support for WebFinger
* Added: Make Post-Template filterable
* Addes: CSS class for ActivityPub comments to allow custom designs
* Added: CSS class for ActivityPub comments to allow custom designs
* Added: FEP-2677: Identifying the Application Actor
* Improved: WebFinger endpoints

### 1.3.0 ###

Expand Down
2 changes: 1 addition & 1 deletion includes/activity/class-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class Activity extends Base_Object {
public function set_object( $object ) {
// convert array to object
if ( is_array( $object ) ) {
$object = Base_Object::init_from_array( $object );
$object = self::init_from_array( $object );
}

// set object
Expand Down
5 changes: 0 additions & 5 deletions includes/class-health-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public static function add_tests( $tests ) {
'test' => array( self::class, 'test_webfinger' ),
);

$tests['direct']['activitypub_test_system_cron'] = array(
'label' => __( 'System Cron Test', 'activitypub' ),
'test' => array( self::class, 'test_system_cron' ),
);

return $tests;
}

Expand Down
3 changes: 1 addition & 2 deletions includes/class-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ public static function excerpt( $atts, $content, $tag ) {
// Strip out any remaining tags.
$excerpt = \wp_strip_all_tags( $excerpt );

/** This filter is documented in wp-includes/formatting.php */
$excerpt_more = \apply_filters( 'excerpt_more', ' [...]' );
$excerpt_more = \apply_filters( 'activitypub_excerpt_more', ' […]' );
$excerpt_more_len = strlen( $excerpt_more );

// We now have a excerpt, but we need to check it's length, it may be longer than we want for two reasons:
Expand Down
13 changes: 13 additions & 0 deletions includes/model/class-application-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public function get_url() {
return get_rest_url_by_path( 'application' );
}

/**
* Returns the User-URL with @-Prefix for the username.
*
* @return string The User-URL with @-Prefix for the username.
*/
public function get_alternate_url() {
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
}

public function get_name() {
return 'application';
}
Expand Down Expand Up @@ -69,4 +78,8 @@ public function get_moderators() {
public function get_indexable() {
return false;
}

public function get_type() {
return $this->type;
}
}
8 changes: 4 additions & 4 deletions includes/model/class-blog-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public function get_url() {
}

/**
* Returns the User-URL with @-Prefix for the username.
* Get blog's homepage URL.
*
* @return string The User-URL with @-Prefix for the username.
* @return string The User-Url.
*/
public function get_at_url() {
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
public function get_alternate_url() {
return \esc_url( \trailingslashit( get_home_url() ) );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/model/class-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public function get_url() {
*
* @return string The User-URL with @-Prefix for the username.
*/
public function get_at_url() {
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() );
public function get_alternate_url() {
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
}

public function get_preferred_username() {
Expand Down
10 changes: 10 additions & 0 deletions includes/rest/class-nodeinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public static function nodeinfo( $request ) {
'outbound' => array(),
);

$nodeinfo['metadata'] = array(
'nodeName' => \get_bloginfo( 'name' ),
'nodeDescription' => \get_bloginfo( 'description' ),
'nodeIcon' => \get_site_icon_url(),
);

return new WP_REST_Response( $nodeinfo, 200 );
}

Expand Down Expand Up @@ -169,6 +175,10 @@ public static function discovery( $request ) {
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
'href' => get_rest_url_by_path( 'nodeinfo' ),
),
array(
'rel' => 'https://www.w3.org/ns/activitystreams#Application',
'href' => get_rest_url_by_path( 'application' ),
),
);

return new \WP_REST_Response( $discovery, 200 );
Expand Down
9 changes: 6 additions & 3 deletions includes/rest/class-webfinger.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ public static function get_profile( $resource ) {

$aliases = array(
$user->get_url(),
$user->get_alternate_url(),
);

$aliases = array_unique( $aliases );

$profile = array(
'subject' => $resource,
'subject' => sprintf( 'acct:%s', $user->get_resource() ),
'aliases' => array_values( array_unique( $aliases ) ),
'links' => array(
array(
Expand All @@ -113,9 +116,9 @@ public static function get_profile( $resource ) {
),
);

if ( 'Group' === $user->get_type() ) {
if ( 'Person' !== $user->get_type() ) {
$profile['links'][0]['properties'] = array(
'https://www.w3.org/ns/activitystreams#type' => 'Group',
'https://www.w3.org/ns/activitystreams#type' => $user->get_type(),
);
}

Expand Down
27 changes: 23 additions & 4 deletions integration/class-nodeinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use function Activitypub\get_total_users;
use function Activitypub\get_active_users;
use function Activitypub\get_rest_url_by_path;

/**
* Compatibility with the NodeInfo plugin
Expand All @@ -14,8 +15,10 @@ class Nodeinfo {
* Initialize the class, registering WordPress hooks
*/
public static function init() {
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 );
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 );
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_data' ), 10, 2 );
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_data' ), 10 );

\add_filter( 'wellknown_nodeinfo_data', array( self::class, 'add_wellknown_nodeinfo_data' ), 10, 2 );
}

/**
Expand All @@ -26,7 +29,7 @@ public static function init() {
*
* @return array The extended array
*/
public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
public static function add_nodeinfo_data( $nodeinfo, $version ) {
if ( $version >= '2.0' ) {
$nodeinfo['protocols'][] = 'activitypub';
} else {
Expand All @@ -50,7 +53,7 @@ public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
*
* @return array The extended array
*/
public static function add_nodeinfo2_discovery( $nodeinfo ) {
public static function add_nodeinfo2_data( $nodeinfo ) {
$nodeinfo['protocols'][] = 'activitypub';

$nodeinfo['usage']['users'] = array(
Expand All @@ -61,4 +64,20 @@ public static function add_nodeinfo2_discovery( $nodeinfo ) {

return $nodeinfo;
}

/**
* Extend the well-known nodeinfo data
*
* @param array $data The well-known nodeinfo data
*
* @return array The extended array
*/
public static function add_wellknown_nodeinfo_data( $data ) {
$data['links'][] = array(
'rel' => 'https://www.w3.org/ns/activitystreams#Application',
'href' => get_rest_url_by_path( 'application' ),
);

return $data;
}
}
9 changes: 7 additions & 2 deletions integration/class-webfinger.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Webfinger {
* Initialize the class, registering WordPress hooks
*/
public static function init() {
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 1, 3 );
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 1, 2 );
}

/**
Expand All @@ -34,6 +34,11 @@ public static function add_user_discovery( $array, $resource, $user ) {
return $array;
}

$array['subject'] = sprintf( 'acct:%s', $user->get_resource() );

$array['aliases'][] = $user->get_url();
$array['aliases'][] = $user->get_alternate_url();

$array['links'][] = array(
'rel' => 'self',
'type' => 'application/activity+json',
Expand Down
4 changes: 3 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
* Fixed: Normalize attributes that can have mixed value types
* Added: URL support for WebFinger
* Added: Make Post-Template filterable
* Addes: CSS class for ActivityPub comments to allow custom designs
* Added: CSS class for ActivityPub comments to allow custom designs
* Added: FEP-2677: Identifying the Application Actor
* Improved: WebFinger endpoints

= 1.3.0 =

Expand Down
30 changes: 30 additions & 0 deletions tests/test-class-activitypub-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,34 @@ public function test_password_protected_content() {
$this->assertEquals( '', $content );
Shortcodes::unregister();
}

public function test_excerpt() {
Shortcodes::register();
global $post;

$post_id = -97; // negative ID, to avoid clash with a valid post
$post = new stdClass();
$post->ID = $post_id;
$post->post_author = 1;
$post->post_date = current_time( 'mysql' );
$post->post_date_gmt = current_time( 'mysql', 1 );
$post->post_title = 'Some title or other';
$post->post_content = '<script>test</script>Lorem ipsum dolor sit amet, consectetur.<script type="javascript">{"asdf": "qwerty"}</script><style></style>';
$post->post_status = 'publish';
$post->comment_status = 'closed';
$post->ping_status = 'closed';
$post->post_name = 'fake-page-' . rand( 1, 99999 ); // append random number to avoid clash
$post->post_type = 'page';
$post->filter = 'raw'; // important!

$content = '[ap_excerpt length="25"]';

// Fill in the shortcodes.
setup_postdata( $post );
$content = do_shortcode( $content );
wp_reset_postdata();

$this->assertEquals( "<p>Lorem ipsum [&hellip;]</p>\n", $content );
Shortcodes::unregister();
}
}

0 comments on commit 6edc4b5

Please sign in to comment.