PluginProbe
ActivityPub / 9.3.0
ActivityPub v9.3.0
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 9.3.0, at build/remote-reply/render.php

219 lines 6.8 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 $error_id = $block_id . '-remote-profile-error';
26
27 // Set up the Interactivity API config.
28 wp_interactivity_config(
29 'activitypub/remote-reply',
30 array(
31 'namespace' => ACTIVITYPUB_REST_NAMESPACE,
32 'i18n' => array(
33 'copied' => __( 'Copied!', 'activitypub' ),
34 'copy' => __( 'Copy', 'activitypub' ),
35 'emptyProfileError' => __( 'Please enter a profile URL or handle.', 'activitypub' ),
36 'genericError' => __( 'An error occurred. Please try again.', 'activitypub' ),
37 'invalidProfileError' => __( 'Please enter a valid profile URL or handle.', 'activitypub' ),
38 ),
39 )
40 );
41
42 // Add the block wrapper attributes.
43 $wrapper_attributes = get_block_wrapper_attributes(
44 array(
45 'id' => $block_id,
46 'class' => 'activitypub-remote-reply reply',
47 'data-wp-interactive' => 'activitypub/remote-reply',
48 'data-wp-init' => 'callbacks.init',
49 )
50 );
51
52 $wrapper_context = wp_interactivity_data_wp_context(
53 array(
54 'blockId' => $block_id,
55 'commentId' => $comment_id,
56 'commentURL' => $selected_comment,
57 'copyButtonText' => __( 'Copy', 'activitypub' ),
58 'errorMessage' => '',
59 'isError' => false,
60 'isLoading' => false,
61 'modal' => array( 'isOpen' => false ),
62 'remoteProfile' => '',
63 'shouldSaveProfile' => true,
64 )
65 );
66
67 wp_interactivity_state(
68 'activitypub/remote-reply',
69 array(
70 'hasRemoteUser' => false,
71 'profileURL' => '',
72 'template' => '',
73 )
74 );
75
76 ob_start();
77 ?>
78 <div class="activitypub-dialog__section">
79 <h4><?php esc_html_e( 'Original Comment URL', 'activitypub' ); ?></h4>
80 <div class="activitypub-dialog__description">
81 <?php esc_html_e( 'Paste the comment URL into the search field of your favorite open social app or platform.', 'activitypub' ); ?>
82 </div>
83 <div class="activitypub-dialog__button-group">
84 <label for="<?php echo esc_attr( $block_id . '-profile-handle' ); ?>" class="screen-reader-text">
85 <?php esc_html_e( 'Comment URL', 'activitypub' ); ?>
86 </label>
87 <input
88 aria-readonly="true"
89 class="wp-block-search__input"
90 id="<?php echo esc_attr( $block_id . '-profile-handle' ); ?>"
91 readonly
92 tabindex="-1"
93 type="text"
94 value="<?php echo esc_attr( $selected_comment ); ?>"
95 />
96 <button
97 aria-label="<?php esc_attr_e( 'Copy URL to clipboard', 'activitypub' ); ?>"
98 class="wp-element-button"
99 data-wp-on--click="actions.copyToClipboard"
100 type="button"
101 >
102 <span data-wp-text="context.copyButtonText"></span>
103 </button>
104 </div>
105 </div>
106 <div class="activitypub-dialog__section">
107 <h4><?php esc_html_e( 'Your Profile', 'activitypub' ); ?></h4>
108 <div class="activitypub-dialog__description">
109 <?php esc_html_e( 'Or, if you know your own profile, we can start things that way!', 'activitypub' ); ?>
110 <?php Blocks::render_modal_help(); ?>
111 </div>
112 <div class="activitypub-dialog__button-group">
113 <label for="<?php echo esc_attr( $block_id . '-remote-profile' ); ?>" class="screen-reader-text">
114 <?php esc_html_e( 'Your Fediverse profile', 'activitypub' ); ?>
115 </label>
116 <input
117 aria-describedby="<?php echo esc_attr( $error_id ); ?>"
118 class="wp-block-search__input"
119 data-wp-bind--aria-invalid="context.isError"
120 data-wp-bind--value="context.remoteProfile"
121 data-wp-on--input="actions.updateRemoteProfile"
122 data-wp-on--keydown="actions.onInputKeydown"
123 id="<?php echo esc_attr( $block_id . '-remote-profile' ); ?>"
124 placeholder="<?php esc_attr_e( '@username@example.com', 'activitypub' ); ?>"
125 type="text"
126 />
127 <button
128 aria-label="<?php esc_attr_e( 'Reply', 'activitypub' ); ?>"
129 class="wp-element-button"
130 data-wp-bind--disabled="context.isLoading"
131 data-wp-on--click="actions.submitRemoteProfile"
132 type="button"
133 >
134 <span data-wp-bind--hidden="context.isLoading"><?php esc_html_e( 'Reply', 'activitypub' ); ?></span>
135 <span data-wp-bind--hidden="!context.isLoading"><?php esc_html_e( 'Loading&hellip;', 'activitypub' ); ?></span>
136 </button>
137 </div>
138 <div
139 class="activitypub-dialog__error"
140 data-wp-text="context.errorMessage"
141 id="<?php echo esc_attr( $error_id ); ?>"
142 role="alert"
143 ></div>
144 <div class="activitypub-dialog__remember">
145 <label>
146 <input
147 checked
148 data-wp-bind--checked="context.shouldSaveProfile"
149 data-wp-on--change="actions.toggleRememberProfile"
150 type="checkbox"
151 />
152 <?php esc_html_e( 'Save my profile for future comments.', 'activitypub' ); ?>
153 </label>
154 </div>
155 </div>
156 <?php
157 $modal_content = ob_get_clean();
158
159 ?>
160 <div
161 <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput ?>
162 <?php echo $wrapper_context; // phpcs:ignore WordPress.Security.EscapeOutput ?>
163 >
164 <div class="activitypub-remote-profile" hidden data-wp-bind--hidden="!state.hasRemoteUser">
165 <a
166 href=""
167 class="comment-reply-link activitypub-remote-profile__link"
168 data-wp-bind--href="state.remoteProfileUrl"
169 target="_blank"
170 >
171 <?php
172 printf(
173 /* translators: %s: profile name */
174 esc_html__( 'Reply as %s', 'activitypub' ),
175 '<span data-wp-text="state.profileURL"></span>'
176 );
177 ?>
178 </a>
179
180 <button
181 type="button"
182 class="activitypub-remote-profile__close wp-element-button"
183 data-wp-on--click="actions.deleteRemoteUser"
184 title="<?php esc_attr_e( 'Delete Remote Profile', 'activitypub' ); ?>"
185 >
186 <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">
187 <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>
188 </svg>
189 </button>
190 </div>
191
192 <a
193 class="comment-reply-link activitypub-remote-reply__link"
194 data-wp-on--click="actions.toggleModal"
195 data-wp-on--keydown="actions.onReplyLinkKeydown"
196 data-wp-bind--hidden="state.hasRemoteUser"
197 data-wp-bind--aria-expanded="context.modal.isOpen"
198 aria-label="<?php esc_attr_e( 'Reply on the Fediverse', 'activitypub' ); ?>"
199 aria-haspopup="dialog"
200 aria-controls="<?php echo esc_attr( $block_id . '-modal-title' ); ?>"
201 role="button"
202 tabindex="0"
203 hidden
204 >
205 <?php esc_html_e( 'Reply on the Fediverse', 'activitypub' ); ?>
206 </a>
207
208 <?php
209 Blocks::render_modal(
210 array(
211 'id' => $block_id . '-modal',
212 'title' => __( 'Remote Reply', 'activitypub' ),
213 'content' => $modal_content,
214 )
215 );
216 ?>
217 </div>
218 <?php
219