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

216 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( 'Paste the comment URL into the search field of your favorite open social app or platform.', '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 class="wp-block-search__input"
89 id="<?php echo esc_attr( $block_id . '-profile-handle' ); ?>"
90 readonly
91 tabindex="-1"
92 type="text"
93 value="<?php echo esc_attr( $selected_comment ); ?>"
94 />
95 <button
96 aria-label="<?php esc_attr_e( 'Copy URL to clipboard', 'activitypub' ); ?>"
97 class="wp-element-button"
98 data-wp-on--click="actions.copyToClipboard"
99 type="button"
100 >
101 <span data-wp-text="context.copyButtonText"></span>
102 </button>
103 </div>
104 </div>
105 <div class="activitypub-dialog__section">
106 <h4><?php esc_html_e( 'Your Profile', 'activitypub' ); ?></h4>
107 <div class="activitypub-dialog__description">
108 <?php esc_html_e( 'Or, if you know your own profile, we can start things that way!', 'activitypub' ); ?>
109 <?php Blocks::render_modal_help(); ?>
110 </div>
111 <div class="activitypub-dialog__button-group">
112 <label for="<?php echo esc_attr( $block_id . '-remote-profile' ); ?>" class="screen-reader-text">
113 <?php esc_html_e( 'Your Fediverse profile', 'activitypub' ); ?>
114 </label>
115 <input
116 class="wp-block-search__input"
117 data-wp-bind--aria-invalid="context.isError"
118 data-wp-bind--value="context.remoteProfile"
119 data-wp-on--input="actions.updateRemoteProfile"
120 data-wp-on--keydown="actions.onInputKeydown"
121 id="<?php echo esc_attr( $block_id . '-remote-profile' ); ?>"
122 placeholder="<?php esc_attr_e( '@username@example.com', 'activitypub' ); ?>"
123 type="text"
124 />
125 <button
126 aria-label="<?php esc_attr_e( 'Reply', 'activitypub' ); ?>"
127 class="wp-element-button"
128 data-wp-bind--disabled="context.isLoading"
129 data-wp-on--click="actions.submitRemoteProfile"
130 type="button"
131 >
132 <span data-wp-bind--hidden="context.isLoading"><?php esc_html_e( 'Reply', 'activitypub' ); ?></span>
133 <span data-wp-bind--hidden="!context.isLoading"><?php esc_html_e( 'Loading&hellip;', 'activitypub' ); ?></span>
134 </button>
135 </div>
136 <div
137 class="activitypub-dialog__error"
138 data-wp-bind--hidden="!context.isError"
139 data-wp-text="context.errorMessage"
140 ></div>
141 <div class="activitypub-dialog__remember">
142 <label>
143 <input
144 checked
145 data-wp-bind--checked="context.shouldSaveProfile"
146 data-wp-on--change="actions.toggleRememberProfile"
147 type="checkbox"
148 />
149 <?php esc_html_e( 'Save my profile for future comments.', 'activitypub' ); ?>
150 </label>
151 </div>
152 </div>
153 <?php
154 $modal_content = ob_get_clean();
155
156 ?>
157 <div
158 <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput ?>
159 <?php echo $wrapper_context; // phpcs:ignore WordPress.Security.EscapeOutput ?>
160 >
161 <div class="activitypub-remote-profile" hidden data-wp-bind--hidden="!state.hasRemoteUser">
162 <a
163 href=""
164 class="comment-reply-link activitypub-remote-profile__link"
165 data-wp-bind--href="state.remoteProfileUrl"
166 target="_blank"
167 >
168 <?php
169 printf(
170 /* translators: %s: profile name */
171 esc_html__( 'Reply as %s', 'activitypub' ),
172 '<span data-wp-text="state.profileURL"></span>'
173 );
174 ?>
175 </a>
176
177 <button
178 type="button"
179 class="activitypub-remote-profile__close wp-element-button"
180 data-wp-on--click="actions.deleteRemoteUser"
181 title="<?php esc_attr_e( 'Delete Remote Profile', 'activitypub' ); ?>"
182 >
183 <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">
184 <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>
185 </svg>
186 </button>
187 </div>
188
189 <a
190 class="comment-reply-link activitypub-remote-reply__link"
191 data-wp-on--click="actions.toggleModal"
192 data-wp-on--keydown="actions.onReplyLinkKeydown"
193 data-wp-bind--hidden="state.hasRemoteUser"
194 data-wp-bind--aria-expanded="context.modal.isOpen"
195 aria-label="<?php esc_attr_e( 'Reply on the Fediverse', 'activitypub' ); ?>"
196 aria-haspopup="dialog"
197 aria-controls="<?php echo esc_attr( $block_id . '-modal-title' ); ?>"
198 role="button"
199 tabindex="0"
200 hidden
201 >
202 <?php esc_html_e( 'Reply on the Fediverse', 'activitypub' ); ?>
203 </a>
204
205 <?php
206 Blocks::render_modal(
207 array(
208 'id' => $block_id . '-modal',
209 'title' => __( 'Remote Reply', 'activitypub' ),
210 'content' => $modal_content,
211 )
212 );
213 ?>
214 </div>
215 <?php
216