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 +48 -0 2.0.03.2.2 View file →
@@ -12,10 +12,25 @@
12 12 // this is already being called on the init hook, so just add it.
13 13 self::register_blocks();
14 14 \add_action( 'wp_enqueue_scripts', array( self::class, 'add_data' ) );
15 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' ) );
16 17 }
17 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 +
18 33 public static function add_data() {
19 34 $context = is_admin() ? 'editor' : 'view';
20 35 $followers_handle = 'activitypub-followers-' . $context . '-script';
21 36 $follow_me_handle = 'activitypub-follow-me-' . $context . '-script';
@@ -43,8 +58,14 @@
43 58 array(
44 59 'render_callback' => array( self::class, 'render_follow_me_block' ),
45 60 )
46 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 + );
47 68 }
48 69
49 70 private static function get_user_id( $user_string ) {
50 71 if ( is_numeric( $user_string ) ) {
@@ -77,8 +98,14 @@
77 98 $user->to_array(),
78 99 array( 'icon', 'name', 'webfinger' )
79 100 );
80 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 +
81 108 $wrapper_attributes = get_block_wrapper_attributes(
82 109 array(
83 110 'aria-label' => __( 'Follow me on the Fediverse', 'activitypub' ),
84 111 'class' => 'activitypub-follow-me-block-wrapper',
@@ -122,8 +149,29 @@
122 149 }
123 150 // We are only pagination on the JS side. Could be revisited but we gotta ship!
124 151 $html .= '</ul></div>';
125 152 return $html;
153 + }
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 + );
126 174 }
127 175
128 176 public static function render_follower( $follower ) {
129 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>';