Skip to content

Commit eff1922

Browse files
authored
Merge branch 'trunk' into add/same-server-domain-move
2 parents 4fe7efb + b022733 commit eff1922

28 files changed

+922
-117
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Added a Mastodon importer to move your Mastodon posts to your WordPress site.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Standardized mentions to use usernames only in comments and posts.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Use the `$from` account for the object in Move activity for internal Moves
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Prevent self-replies on local comments.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Support multiple layers of nested Outbox activities when searching for the Object ID.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Permanently delete reactions that were `Undo` instead of trashing them.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Importing attachments no longer creates Outbox items for them.

.github/workflows/gardening.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ jobs:
5858
{"path": "integration", "label": "[Focus] Compatibility"},
5959
{"path": "includes/collection", "label": "[Feature] Collections"},
6060
{"path": "includes/class-mailer.php", "label": "[Feature] Notifications"},
61+
{"path": "includes/wp-admin/import", "label": "[Feature] Import"},
6162
{"path": "includes/wp-admin", "label": "[Feature] WP Admin"}
6263
]'

activitypub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ function plugin_admin_init() {
102102
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Welcome_Fields', 'init' ) );
103103
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Blog_Settings_Fields', 'init' ) );
104104
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\User_Settings_Fields', 'init' ) );
105+
106+
if ( defined( 'WP_LOAD_IMPORTERS' ) && WP_LOAD_IMPORTERS ) {
107+
require_once __DIR__ . '/includes/wp-admin/import/load.php';
108+
\add_action( 'init', __NAMESPACE__ . '\WP_Admin\Import\load' );
109+
}
105110
}
106111
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_admin_init' );
107112

includes/activity/class-activity.php

Lines changed: 91 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
namespace Activitypub\Activity;
1111

12-
use Activitypub\Link;
12+
use Activitypub\Activity\Extended_Object\Event;
13+
use Activitypub\Activity\Extended_Object\Place;
1314

1415
/**
1516
* \Activitypub\Activity\Activity implements the common
@@ -23,6 +24,43 @@ class Activity extends Base_Object {
2324
'https://www.w3.org/ns/activitystreams',
2425
);
2526

27+
/**
28+
* The default types for Activities.
29+
*
30+
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
31+
*
32+
* @var array
33+
*/
34+
const TYPES = array(
35+
'Accept',
36+
'Add',
37+
'Announce',
38+
'Arrive',
39+
'Block',
40+
'Create',
41+
'Delete',
42+
'Dislike',
43+
'Follow',
44+
'Flag',
45+
'Ignore',
46+
'Invite',
47+
'Join',
48+
'Leave',
49+
'Like',
50+
'Listen',
51+
'Move',
52+
'Offer',
53+
'Read',
54+
'Reject',
55+
'Remove',
56+
'TentativeAccept',
57+
'TentativeReject',
58+
'Travel',
59+
'Undo',
60+
'Update',
61+
'View',
62+
);
63+
2664
/**
2765
* The type of the object.
2866
*
@@ -124,58 +162,87 @@ class Activity extends Base_Object {
124162
*
125163
* @see https://www.w3.org/TR/activitypub/#object-without-create
126164
*
127-
* @param array|string|Base_Object|Link|null $data Activity object.
165+
* @param array|string|Base_Object|Activity|Actor|null $data Activity object.
128166
*/
129167
public function set_object( $data ) {
130-
// Convert array to object.
168+
$object = $data;
169+
170+
// Convert array to appropriate object type.
131171
if ( is_array( $data ) ) {
132-
$data = Generic_Object::init_from_array( $data );
172+
$type = $data['type'] ?? null;
173+
174+
if ( in_array( $type, self::TYPES, true ) ) {
175+
$object = self::init_from_array( $data );
176+
} elseif ( in_array( $type, Actor::TYPES, true ) ) {
177+
$object = Actor::init_from_array( $data );
178+
} elseif ( in_array( $type, Base_Object::TYPES, true ) ) {
179+
switch ( $type ) {
180+
case 'Event':
181+
$object = Event::init_from_array( $data );
182+
break;
183+
case 'Place':
184+
$object = Place::init_from_array( $data );
185+
break;
186+
default:
187+
$object = Base_Object::init_from_array( $data );
188+
break;
189+
}
190+
} else {
191+
$object = Generic_Object::init_from_array( $data );
192+
}
133193
}
134194

135-
// Set object.
136-
$this->set( 'object', $data );
195+
$this->set( 'object', $object );
196+
$this->pre_fill_activity_from_object();
197+
}
198+
199+
/**
200+
* Fills the Activity with the specified activity object.
201+
*/
202+
public function pre_fill_activity_from_object() {
203+
$object = $this->get_object();
137204

138205
// Check if `$data` is a URL and use it to generate an ID then.
139-
if ( is_string( $data ) && filter_var( $data, FILTER_VALIDATE_URL ) && ! $this->get_id() ) {
140-
$this->set( 'id', $data . '#activity-' . strtolower( $this->get_type() ) . '-' . time() );
206+
if ( is_string( $object ) && filter_var( $object, FILTER_VALIDATE_URL ) && ! $this->get_id() ) {
207+
$this->set( 'id', $object . '#activity-' . strtolower( $this->get_type() ) . '-' . time() );
141208

142209
return;
143210
}
144211

145212
// Check if `$data` is an object and copy some properties otherwise do nothing.
146-
if ( ! is_object( $data ) ) {
213+
if ( ! is_object( $object ) ) {
147214
return;
148215
}
149216

150217
foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) {
151-
$value = $data->get( $i );
218+
$value = $object->get( $i );
152219
if ( $value && ! $this->get( $i ) ) {
153220
$this->set( $i, $value );
154221
}
155222
}
156223

157-
if ( $data->get_published() && ! $this->get_published() ) {
158-
$this->set( 'published', $data->get_published() );
224+
if ( $object->get_published() && ! $this->get_published() ) {
225+
$this->set( 'published', $object->get_published() );
159226
}
160227

161-
if ( $data->get_updated() && ! $this->get_updated() ) {
162-
$this->set( 'updated', $data->get_updated() );
228+
if ( $object->get_updated() && ! $this->get_updated() ) {
229+
$this->set( 'updated', $object->get_updated() );
163230
}
164231

165-
if ( $data->get_attributed_to() && ! $this->get_actor() ) {
166-
$this->set( 'actor', $data->get_attributed_to() );
232+
if ( $object->get_attributed_to() && ! $this->get_actor() ) {
233+
$this->set( 'actor', $object->get_attributed_to() );
167234
}
168235

169-
if ( $data->get_in_reply_to() && ! $this->get_in_reply_to() ) {
170-
$this->set( 'in_reply_to', $data->get_in_reply_to() );
236+
if ( $object->get_in_reply_to() && ! $this->get_in_reply_to() ) {
237+
$this->set( 'in_reply_to', $object->get_in_reply_to() );
171238
}
172239

173-
if ( $data->get_id() && ! $this->get_id() ) {
174-
$id = strtok( $data->get_id(), '#' );
175-
if ( $data->get_updated() ) {
176-
$updated = $data->get_updated();
177-
} elseif ( $data->get_published() ) {
178-
$updated = $data->get_published();
240+
if ( $object->get_id() && ! $this->get_id() ) {
241+
$id = strtok( $object->get_id(), '#' );
242+
if ( $object->get_updated() ) {
243+
$updated = $object->get_updated();
244+
} elseif ( $object->get_published() ) {
245+
$updated = $object->get_published();
179246
} else {
180247
$updated = time();
181248
}

0 commit comments

Comments
 (0)