PluginProbe
ActivityPub / 7.8.2
ActivityPub v7.8.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 / build / remote-reply / render.php

render.php in ActivityPub 7.8.2, at build/remote-reply/render.php

213 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side rendering of the `activitypub/remote-reply` block.
4 *
5 * @package ActivityPub
6 */
7
8 use Activitypub\Blocks;
9
10 use function Activitypub\is_activitypub_request;
11
12 if ( is_activitypub_request() || is_feed() ) {
13 return;
14 }
15
16 /* @var array $attributes Block attributes. */
17 $attributes = wp_parse_args( $attributes );
18
19 // Get the comment ID and selected comment URL.
20 $comment_id = $attributes['commentId'] ?? 0;
21 $selected_comment = $attributes['selectedComment'] ?? '';
22
23 // Generate a unique ID for the block.
24 $block_id = 'activitypub-remote-reply-block-' . wp_unique_id();
25
26 // Set up the Interactivity API config.
27 wp_interactivity_config(
28 'activitypub/remote-reply',
29 array(
30 'namespace' => ACTIVITYPUB_REST_NAMESPACE,
31 'i18n' => array(
32 'copied' => __( 'Copied!', 'activitypub' ),
33 'copy' => __( 'Copy', 'activitypub' ),
34 'emptyProfileError' => __( 'Please enter a profile URL or handle.', 'activitypub' ),
35 'genericError' => __( 'An error occurred. Please try again.', 'activitypub' ),
36 'invalidProfileError' => __( 'Please enter a valid profile URL or handle.', 'activitypub' ),
37 ),
38 )
39 );
40
41 // Add the block wrapper attributes.
42 $wrapper_attributes = get_block_wrapper_attributes(
43 array(
44 'id' => $block_id,
45 'class' => 'activitypub-remote-reply reply',
46 'data-wp-interactive' => 'activitypub/remote-reply',
47 'data-wp-init' => 'callbacks.init',
48 )
49 );
50
51 $wrapper_context = wp_interactivity_data_wp_context(
52 array(
53 'blockId' => $block_id,
54 'commentId' => $comment_id,
55 'commentURL' => $selected_comment,
56 'copyButtonText' => __( 'Copy', 'activitypub' ),
57 'errorMessage' => '',
58 'isError' => false,
59 'isLoading' => false,
60 'modal' => array( 'isOpen' => false ),
61 'remoteProfile' => '',
62 'shouldSaveProfile' => true,
63 )
64 );
65
66 wp_interactivity_state(
67 'activitypub/remote-reply',
68 array(
69 'hasRemoteUser' => false,
70 'profileURL' => '',
71 'template' => '',
72 )
73 );
74
75 ob_start();
76 ?>
77 <div class="activitypub-dialog__section">
78 <h4><?php esc_html_e( 'Original Comment URL', 'activitypub' ); ?></h4>
79 <div class="activitypub-dialog__description">
80 <?php esc_html_e( 'Copy and paste the Comment URL into the search field of your favorite fediverse app or server.', 'activitypub' ); ?>
81 </div>
82 <div class="activitypub-dialog__button-group">
83 <label for="<?php echo esc_attr( $block_id . '-profile-handle' ); ?>" class="screen-reader-text">
84 <?php esc_html_e( 'Comment URL', 'activitypub' ); ?>
85 </label>
86 <input
87 aria-readonly="true"
88 id="<?php echo esc_attr( $block_id . '-profile-handle' ); ?>"
89 readonly
90 tabindex="-1"
91 type="text"
92 value="<?php echo esc_attr( $selected_comment ); ?>"
93 />
94 <button
95 aria-label="<?php esc_attr_e( 'Copy URL to clipboard', 'activitypub' ); ?>"
96 class="wp-element-button wp-block-button__link"
97 data-wp-on--click="actions.copyToClipboard"
98 type="button"
99 >
100 <span data-wp-text="context.copyButtonText"></span>
101 </button>
102 </div>
103 </div>
104 <div class="activitypub-dialog__section">
105 <h4><?php esc_html_e( 'Your Profile', 'activitypub' ); ?></h4>
106 <div class="activitypub-dialog__description">
107 <?php esc_html_e( 'Or, if you know your own profile, we can start things that way!', 'activitypub' ); ?>
108 </div>
109 <div class="activitypub-dialog__button-group">
110 <label for="<?php echo esc_attr( $block_id . '-remote-profile' ); ?>" class="screen-reader-text">
111 <?php esc_html_e( 'Your Fediverse profile', 'activitypub' ); ?>
112 </label>
113 <input
114 data-wp-bind--aria-invalid="context.isError"
115 data-wp-bind--value="context.remoteProfile"
116 data-wp-on--input="actions.updateRemoteProfile"
117 data-wp-on--keydown="actions.onInputKeydown"
118 id="<?php echo esc_attr( $block_id . '-remote-profile' ); ?>"
119 placeholder="<?php esc_attr_e( '@username@example.com', 'activitypub' ); ?>"
120 type="text"
121 />
122 <button
123 aria-label="<?php esc_attr_e( 'Reply', 'activitypub' ); ?>"
124 class="wp-element-button wp-block-button__link"
125 data-wp-bind--disabled="context.isLoading"
126 data-wp-on--click="actions.submitRemoteProfile"
127 type="button"
128 >
129 <span data-wp-bind--hidden="context.isLoading"><?php esc_html_e( 'Reply', 'activitypub' ); ?></span>
130 <span data-wp-bind--hidden="!context.isLoading"><?php esc_html_e( 'Loading&hellip;', 'activitypub' ); ?></span>
131 </button>
132 </div>
133 <div
134 class="activitypub-dialog__error"
135 data-wp-bind--hidden="!context.isError"
136 data-wp-text="context.errorMessage"
137 ></div>
138 <div class="activitypub-dialog__remember">
139 <label>
140 <input
141 checked
142 data-wp-bind--checked="context.shouldSaveProfile"
143 data-wp-on--change="actions.toggleRememberProfile"
144 type="checkbox"
145 />
146 <?php esc_html_e( 'Save my profile for future comments.', 'activitypub' ); ?>
147 </label>
148 </div>
149 </div>
150 <?php
151 $modal_content = ob_get_clean();
152
153 ?>
154 <div
155 <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput ?>
156 <?php echo $wrapper_context; // phpcs:ignore WordPress.Security.EscapeOutput ?>
157 >
158 <div class="activitypub-remote-profile" hidden data-wp-bind--hidden="!state.hasRemoteUser">
159 <a
160 href=""
161 class="comment-reply-link activitypub-remote-profile__link"
162 data-wp-bind--href="state.remoteProfileUrl"
163 target="_blank"
164 >
165 <?php
166 printf(
167 /* translators: %s: profile name */
168 esc_html__( 'Reply as %s', 'activitypub' ),
169 '<span data-wp-text="state.profileURL"></span>'
170 );
171 ?>
172 </a>
173
174 <button
175 type="button"
176 class="activitypub-remote-profile__close wp-element-button wp-block-button__link"
177 data-wp-on--click="actions.deleteRemoteUser"
178 title="<?php esc_attr_e( 'Delete Remote Profile', 'activitypub' ); ?>"
179 >
180 <svg fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="18" height="18" role="img" aria-hidden="true" focusable="false">
181 <path d="M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"></path>
182 </svg>
183 </button>
184 </div>
185
186 <a
187 class="comment-reply-link activitypub-remote-reply__link"
188 data-wp-on-async--click="actions.toggleModal"
189 data-wp-on-async--keydown="actions.onReplyLinkKeydown"
190 data-wp-bind--hidden="state.hasRemoteUser"
191 data-wp-bind--aria-expanded="context.modal.isOpen"
192 aria-label="<?php esc_attr_e( 'Reply on the Fediverse', 'activitypub' ); ?>"
193 aria-haspopup="dialog"
194 aria-controls="<?php echo esc_attr( $block_id . '-modal-title' ); ?>"
195 role="button"
196 tabindex="0"
197 hidden
198 >
199 <?php esc_html_e( 'Reply on the Fediverse', 'activitypub' ); ?>
200 </a>
201
202 <?php
203 Blocks::render_modal(
204 array(
205 'id' => $block_id . '-modal',
206 'title' => __( 'Remote Reply', 'activitypub' ),
207 'content' => $modal_content,
208 )
209 );
210 ?>
211 </div>
212 <?php
213