|
7 | 7 |
|
8 | 8 | namespace Activitypub;
|
9 | 9 |
|
| 10 | +use Activitypub\Activity\Extended_Object\Quote_Authorization; |
10 | 11 | use Activitypub\Collection\Actors;
|
11 | 12 | use Activitypub\Collection\Outbox;
|
12 | 13 | use Activitypub\Transformer\Factory;
|
@@ -138,6 +139,10 @@ public function get_activitypub_object_id() {
|
138 | 139 | private function prepare_activitypub_data() {
|
139 | 140 | $queried_object = $this->get_queried_object();
|
140 | 141 |
|
| 142 | + if ( $queried_object instanceof \WP_Post && \get_query_var( 'stamp' ) ) { |
| 143 | + return $this->maybe_get_stamp(); |
| 144 | + } |
| 145 | + |
141 | 146 | // Check for Outbox Activity.
|
142 | 147 | if (
|
143 | 148 | $queried_object instanceof \WP_Post &&
|
@@ -311,7 +316,7 @@ public function is_activitypub_request() {
|
311 | 316 | */
|
312 | 317 | public function should_negotiate_content() {
|
313 | 318 | $return = false;
|
314 |
| - $always_negotiate = array( 'p', 'c', 'author', 'actor', 'preview', 'activitypub' ); |
| 319 | + $always_negotiate = array( 'p', 'c', 'author', 'actor', 'stamp', 'preview', 'activitypub' ); |
315 | 320 | $url = \wp_parse_url( $this->get_request_url(), PHP_URL_QUERY );
|
316 | 321 | $query = array();
|
317 | 322 | \wp_parse_str( $url, $query );
|
@@ -368,4 +373,46 @@ public function is_old_host_request() {
|
368 | 373 | public function set_old_host_request( $state = true ) {
|
369 | 374 | $this->is_old_host_request = $state;
|
370 | 375 | }
|
| 376 | + |
| 377 | + /** |
| 378 | + * Maybe get a QuoteAuthorization object from a stamp. |
| 379 | + * |
| 380 | + * @return bool True if the object was prepared, false otherwise. |
| 381 | + */ |
| 382 | + private function maybe_get_stamp() { |
| 383 | + require_once ABSPATH . 'wp-admin/includes/post.php'; |
| 384 | + |
| 385 | + $stamp = \get_query_var( 'stamp' ); |
| 386 | + $meta = \get_post_meta_by_id( (int) $stamp ); |
| 387 | + |
| 388 | + if ( ! $meta ) { |
| 389 | + return false; |
| 390 | + } |
| 391 | + |
| 392 | + $post = $this->get_queried_object(); |
| 393 | + $user_uri = get_user_id( $post->post_author ); |
| 394 | + |
| 395 | + if ( ! $user_uri ) { |
| 396 | + return false; |
| 397 | + } |
| 398 | + |
| 399 | + $stamp_uri = \add_query_arg( |
| 400 | + array( |
| 401 | + 'p' => $post->ID, |
| 402 | + 'stamp' => $meta->meta_id, |
| 403 | + ), |
| 404 | + \home_url( '/' ) |
| 405 | + ); |
| 406 | + |
| 407 | + $activitypub_object = new Quote_Authorization(); |
| 408 | + $activitypub_object->set_id( $stamp_uri ); |
| 409 | + $activitypub_object->set_attributed_to( $user_uri ); |
| 410 | + $activitypub_object->set_interacting_object( $meta->meta_value ); |
| 411 | + $activitypub_object->set_interaction_target( get_post_id( $post->ID ) ); |
| 412 | + |
| 413 | + $this->activitypub_object = $activitypub_object; |
| 414 | + $this->activitypub_object_id = $activitypub_object->get_id(); |
| 415 | + |
| 416 | + return true; |
| 417 | + } |
371 | 418 | }
|
0 commit comments