PluginProbe
ActivityPub / 3.2.2
ActivityPub v3.2.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
← All changes | includes/class-blocks.php +54 -4 1.2.03.2.2 View file →
@@ -2,10 +2,12 @@
2 2 namespace Activitypub;
3 3
4 4 use Activitypub\Collection\Followers;
5 5 use Activitypub\Collection\Users as User_Collection;
6 -use Activitypub\is_user_type_disabled;
7 6
7 +use function Activitypub\object_to_uri;
8 +use function Activitypub\is_user_type_disabled;
9 +
8 10 class Blocks {
9 11 public static function init() {
10 12 // this is already being called on the init hook, so just add it.
11 13 self::register_blocks();
@@ -10,10 +12,25 @@
10 12 // this is already being called on the init hook, so just add it.
11 13 self::register_blocks();
12 14 \add_action( 'wp_enqueue_scripts', array( self::class, 'add_data' ) );
13 15 \add_action( 'enqueue_block_editor_assets', array( self::class, 'add_data' ) );
16 + \add_action( 'load-post-new.php', array( self::class, 'handle_in_reply_to_get_param' ) );
14 17 }
15 18
19 + /**
20 + * Enqueue the reply handle script if the in_reply_to GET param is set.
21 + */
22 + public static function handle_in_reply_to_get_param() {
23 + // only load the script if the in_reply_to GET param is set, action happens there, not here.
24 + if ( ! isset( $_GET['in_reply_to'] ) ) {
25 + return;
26 + }
27 +
28 + $asset_data = include ACTIVITYPUB_PLUGIN_DIR . 'build/reply-intent/plugin.asset.php';
29 + $plugin_url = plugins_url( 'build/reply-intent/plugin.js', ACTIVITYPUB_PLUGIN_FILE );
30 + wp_enqueue_script( 'activitypub-reply-intent', $plugin_url, $asset_data['dependencies'], $asset_data['version'], true );
31 + }
32 +
16 33 public static function add_data() {
17 34 $context = is_admin() ? 'editor' : 'view';
18 35 $followers_handle = 'activitypub-followers-' . $context . '-script';
19 36 $follow_me_handle = 'activitypub-follow-me-' . $context . '-script';
@@ -41,8 +58,14 @@
41 58 array(
42 59 'render_callback' => array( self::class, 'render_follow_me_block' ),
43 60 )
44 61 );
62 + \register_block_type_from_metadata(
63 + ACTIVITYPUB_PLUGIN_DIR . '/build/reply',
64 + array(
65 + 'render_callback' => array( self::class, 'render_reply_block' ),
66 + )
67 + );
45 68 }
46 69
47 70 private static function get_user_id( $user_string ) {
48 71 if ( is_numeric( $user_string ) ) {
@@ -72,11 +95,17 @@
72 95 $user = User_Collection::get_by_id( $user_id );
73 96 if ( ! is_wp_error( $user ) ) {
74 97 $attrs['profileData'] = self::filter_array_by_keys(
75 98 $user->to_array(),
76 - array( 'icon', 'name', 'resource' )
99 + array( 'icon', 'name', 'webfinger' )
77 100 );
78 101 }
102 +
103 + // add `@` prefix if it's missing
104 + if ( '@' !== substr( $attrs['profileData']['webfinger'], 0, 1 ) ) {
105 + $attrs['profileData']['webfinger'] = '@' . $attrs['profileData']['webfinger'];
106 + }
107 +
79 108 $wrapper_attributes = get_block_wrapper_attributes(
80 109 array(
81 110 'aria-label' => __( 'Follow me on the Fediverse', 'activitypub' ),
82 111 'class' => 'activitypub-follow-me-block-wrapper',
@@ -93,9 +122,9 @@
93 122 $follower_data = Followers::get_followers_with_count( $followee_user_id, $per_page );
94 123
95 124 $attrs['followerData']['total'] = $follower_data['total'];
96 125 $attrs['followerData']['followers'] = array_map(
97 - function( $follower ) {
126 + function ( $follower ) {
98 127 return self::filter_array_by_keys(
99 128 $follower->to_array(),
100 129 array( 'icon', 'name', 'preferredUsername', 'url' )
101 130 );
@@ -122,8 +151,29 @@
122 151 $html .= '</ul></div>';
123 152 return $html;
124 153 }
125 154
155 + /**
156 + * Render the reply block.
157 + *
158 + * @param array $attrs The block attributes.
159 + *
160 + * @return void
161 + */
162 + public static function render_reply_block( $attrs ) {
163 + return apply_filters(
164 + 'activitypub_reply_block',
165 + sprintf(
166 + '<p><a title="%2$s" href="%1$s" class="u-in-reply-to" target="_blank">%3$s</a></p>',
167 + esc_url( $attrs['url'] ),
168 + esc_attr__( 'This post is a response to the referenced content.', 'activitypub' ),
169 + // translators: %s is the URL of the post being replied to.
170 + sprintf( __( '&#8620;%s', 'activitypub' ), \str_replace( array( 'https://', 'http://' ), '', $attrs['url'] ) )
171 + ),
172 + $attrs
173 + );
174 + }
175 +
126 176 public static function render_follower( $follower ) {
127 177 $external_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" class="components-external-link__icon css-rvs7bx esh4a730" aria-hidden="true" focusable="false"><path d="M18.2 17c0 .7-.6 1.2-1.2 1.2H7c-.7 0-1.2-.6-1.2-1.2V7c0-.7.6-1.2 1.2-1.2h3.2V4.2H7C5.5 4.2 4.2 5.5 4.2 7v10c0 1.5 1.2 2.8 2.8 2.8h10c1.5 0 2.8-1.2 2.8-2.8v-3.6h-1.5V17zM14.9 3v1.5h3.7l-6.4 6.4 1.1 1.1 6.4-6.4v3.7h1.5V3h-6.3z"></path></svg>';
128 178 $template =
129 179 '<a href="%s" title="%s" class="components-external-link activitypub-link" target="_blank" rel="external noreferrer noopener">
@@ -139,9 +189,9 @@
139 189 $data = $follower->to_array();
140 190
141 191 return sprintf(
142 192 $template,
143 - esc_url( $data['url'] ),
193 + esc_url( object_to_uri( $data['url'] ) ),
144 194 esc_attr( $data['name'] ),
145 195 esc_attr( $data['icon']['url'] ),
146 196 esc_html( $data['name'] ),
147 197 esc_html( $data['preferredUsername'] ),