PluginProbe
ActivityPub / 4.0.2
ActivityPub v4.0.2
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / rest / class-interaction.php

class-interaction.php in ActivityPub 4.0.2, at includes/rest/class-interaction.php

119 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ActivityPub Interaction REST-Class file.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\Rest;
9
10 use WP_REST_Response;
11 use Activitypub\Http;
12
13 /**
14 * Interaction class.
15 */
16 class Interaction {
17 /**
18 * Initialize the class, registering WordPress hooks.
19 */
20 public static function init() {
21 self::register_routes();
22 }
23
24 /**
25 * Register routes
26 */
27 public static function register_routes() {
28 \register_rest_route(
29 ACTIVITYPUB_REST_NAMESPACE,
30 '/interactions',
31 array(
32 array(
33 'methods' => \WP_REST_Server::READABLE,
34 'callback' => array( self::class, 'get' ),
35 'permission_callback' => '__return_true',
36 'args' => array(
37 'uri' => array(
38 'type' => 'string',
39 'required' => true,
40 'sanitize_callback' => 'esc_url',
41 ),
42 ),
43 ),
44 )
45 );
46 }
47
48 /**
49 * Handle GET request.
50 *
51 * @param \WP_REST_Request $request The request object.
52 *
53 * @return WP_REST_Response Redirect to the editor or die.
54 */
55 public static function get( $request ) {
56 $uri = $request->get_param( 'uri' );
57 $redirect_url = null;
58 $object = Http::get_remote_object( $uri );
59
60 if (
61 \is_wp_error( $object ) ||
62 ! isset( $object['type'] )
63 ) {
64 \wp_die(
65 \esc_html__(
66 'The URL is not supported!',
67 'activitypub'
68 ),
69 400
70 );
71 }
72
73 if ( ! empty( $object['url'] ) ) {
74 $uri = \esc_url( $object['url'] );
75 }
76
77 switch ( $object['type'] ) {
78 case 'Group':
79 case 'Person':
80 case 'Service':
81 case 'Application':
82 case 'Organization':
83 $redirect_url = \apply_filters( 'activitypub_interactions_follow_url', $redirect_url, $uri, $object );
84 break;
85 default:
86 $redirect_url = \admin_url( 'post-new.php?in_reply_to=' . $uri );
87 $redirect_url = \apply_filters( 'activitypub_interactions_reply_url', $redirect_url, $uri, $object );
88 }
89
90 /**
91 * Filter the redirect URL.
92 *
93 * @param string $redirect_url The URL to redirect to.
94 * @param string $uri The URI of the object.
95 * @param array $object The object.
96 */
97 $redirect_url = \apply_filters( 'activitypub_interactions_url', $redirect_url, $uri, $object );
98
99 // Check if hook is implemented.
100 if ( ! $redirect_url ) {
101 \wp_die(
102 esc_html__(
103 'This Interaction type is not supported yet!',
104 'activitypub'
105 ),
106 400
107 );
108 }
109
110 return new WP_REST_Response(
111 null,
112 302,
113 array(
114 'Location' => \esc_url( $redirect_url ),
115 )
116 );
117 }
118 }
119