PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
← All changes | modules/videopress/class.videopress-edit-attachment.php +82 -41 12.0.3 → 16.3-beta View file →
@@ -1,8 +1,13 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 2
3 3 use Automattic\Jetpack\Connection\Client;
4 +use Automattic\Jetpack\Status;
4 5
6 +if ( ! defined( 'ABSPATH' ) ) {
7 + exit( 0 );
8 +}
9 +
5 10 /**
6 11 * VideoPress edit attachment screen
7 12 *
8 13 * @since 4.1
@@ -86,12 +91,12 @@
86 91 }
87 92
88 93 $post_title = isset( $_POST['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['post_title'] ) ) : null;
89 94 $post_excerpt = isset( $_POST['post_excerpt'] ) ? sanitize_textarea_field( wp_unslash( $_POST['post_excerpt'] ) ) : null;
90 - $rating = isset( $attachment['rating'] ) ? $attachment['rating'] : null;
91 - $display_embed = isset( $attachment['display_embed'] ) ? $attachment['display_embed'] : 0;
92 - $allow_download = isset( $attachment['allow_download'] ) ? $attachment['allow_download'] : 0;
93 - $privacy_setting = isset( $attachment['privacy_setting'] ) ? $attachment['privacy_setting'] : VIDEOPRESS_PRIVACY::SITE_DEFAULT;
95 + $rating = $attachment['rating'] ?? null;
96 + $display_embed = $attachment['display_embed'] ?? 0;
97 + $allow_download = $attachment['allow_download'] ?? 0;
98 + $privacy_setting = $attachment['privacy_setting'] ?? VIDEOPRESS_PRIVACY::SITE_DEFAULT;
94 99
95 100 $result = Videopress_Attachment_Metadata::persist_metadata(
96 101 $post['ID'],
97 102 get_post_meta( $post['ID'], 'videopress_guid', true ),
@@ -156,9 +161,9 @@
156 161 return $fields;
157 162 }
158 163
159 164 $info = (object) $meta['videopress'];
160 - $file_statuses = isset( $meta['file_statuses'] ) ? $meta['file_statuses'] : array();
165 + $file_statuses = $meta['file_statuses'] ?? array();
161 166
162 167 $guid = get_post_meta( $post_id, 'videopress_guid', true );
163 168
164 169 unset( $fields['url'] );
@@ -234,51 +239,87 @@
234 239 * @param stdClass $post Post object.
235 240 */
236 241 public function videopress_information_box( $post ) {
237 242 $post_id = absint( $post->ID );
243 + $guid = get_post_meta( $post_id, 'videopress_guid', true );
238 244
239 - $meta = wp_get_attachment_metadata( $post_id );
240 - $guid = get_post_meta( $post_id, 'videopress_guid', true );
241 -
242 245 // If this has not been processed by videopress, we can skip the rest.
243 - if ( ! is_videopress_attachment( $post_id ) ) {
246 + if ( ! is_videopress_attachment( $post_id ) || empty( $guid ) ) {
244 247 return;
245 248 }
246 249
250 + $meta = wp_get_attachment_metadata( $post_id );
247 251 $info = (object) $meta['videopress'];
248 252
249 - $embed = "[videopress {$guid}]";
253 + $is_public = VIDEOPRESS_PRIVACY::IS_PUBLIC === $info->privacy_setting || ( VIDEOPRESS_PRIVACY::SITE_DEFAULT === $info->privacy_setting && ! ( new Status() )->is_private_site() );
254 + /* Translators: %s is the video title */
255 + $alt_text = sprintf( __( 'Poster image for video: %s', 'jetpack' ), get_the_title( $post_id ) );
256 + ?>
250 257
251 - $shortcode = '<input type="text" id="plugin-embed" readonly="readonly" style="width:180px;" value="' . esc_attr( $embed ) . '" onclick="this.focus();this.select();" />';
258 + <p class="post-attributes-label-wrapper">
259 + <label class="post-attributes-label" for="videopress-shortcode"><?php esc_html_e( 'Shortcode', 'jetpack' ); ?></label>
260 + </p>
261 + <input type="text" class="widefat" id="videopress-shortcode" readonly="readonly" value="<?php echo esc_attr( "[videopress $guid]" ); ?>" onclick="this.focus();this.select();" />
252 262
253 - $url = 'empty';
254 - if ( ! empty( $guid ) ) {
255 - $url = videopress_build_url( $guid );
256 - $url = "<a href=\"{$url}\">{$url}</a>";
257 - }
263 + <p class="post-attributes-label-wrapper">
264 + <label class="post-attributes-label"><?php esc_html_e( 'URL', 'jetpack' ); ?></label>
265 + </p>
266 + <?php printf( '<a href="%1$s">%1$s</a>', esc_url( videopress_build_url( $guid ) ) ); ?>
258 267
259 - $poster = '<em>Still Processing</em>';
260 - if ( ! empty( $info->poster ) ) {
261 - $poster = "<br><img src=\"{$info->poster}\" width=\"175px\">";
262 - }
268 + <p class="post-attributes-label-wrapper">
269 + <label class="post-attributes-label"><?php esc_html_e( 'Poster', 'jetpack' ); ?></label>
270 + </p>
271 + <?php if ( ! empty( $info->poster ) ) : ?>
272 + <?php if ( $is_public ) : ?>
273 + <img src="<?php echo esc_url( $info->poster ); ?>" width="100%" alt="<?php echo esc_attr( $alt_text ); ?>" />
274 + <?php else : ?>
275 + <img
276 + id="videopress-poster-<?php echo esc_attr( $guid ); ?>"
277 + data-poster="<?php echo esc_url( $info->poster ); ?>"
278 + data-guid="<?php echo esc_attr( $guid ); ?>"
279 + width="100%"
280 + alt="<?php echo esc_attr( $alt_text ); ?>"
281 + style="display:none;"
282 + src=""
283 + />
284 + <em class="videopress-poster-loading" data-error="<?php esc_attr_e( 'Poster unavailable.', 'jetpack' ); ?>"><?php esc_html_e( 'Loading…', 'jetpack' ); ?></em>
285 + <script>
286 + ( function() {
287 + var img = document.getElementById( 'videopress-poster-<?php echo esc_attr( $guid ); ?>' );
288 + var loading = img ? img.nextElementSibling : null;
289 + if ( ! img || ! loading || ! window.videopressAjax ) {
290 + return;
291 + }
263 292
264 - $html = <<< HTML
265 -
266 -<div class="misc-pub-section misc-pub-shortcode">
267 - <strong>Shortcode</strong><br>
268 - {$shortcode}
269 -</div>
270 -<div class="misc-pub-section misc-pub-url">
271 - <strong>Url</strong>
272 - {$url}
273 -</div>
274 -<div class="misc-pub-section misc-pub-poster">
275 - <strong>Poster</strong>
276 - {$poster}
277 -</div>
278 -HTML;
279 -
280 - echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Variables built above.
293 + fetch( window.videopressAjax.ajaxUrl, {
294 + method: 'POST',
295 + credentials: 'same-origin',
296 + body: new URLSearchParams( {
297 + action: 'videopress-get-playback-jwt',
298 + guid: img.dataset.guid,
299 + post_id: window.videopressAjax.post_id || 0
300 + } )
301 + } )
302 + .then( function( response ) { return response.json(); } )
303 + .then( function( data ) {
304 + if ( data.success && data.data.jwt ) {
305 + img.src = img.dataset.poster + '?metadata_token=' + data.data.jwt;
306 + img.style.display = '';
307 + loading.style.display = 'none';
308 + } else {
309 + loading.textContent = loading.dataset.error;
310 + }
311 + } )
312 + .catch( function() {
313 + loading.textContent = loading.dataset.error;
314 + } );
315 + } )();
316 + </script>
317 + <?php endif; ?>
318 + <?php else : ?>
319 + <em><?php esc_html_e( 'Processing…', 'jetpack' ); ?></em>
320 + <?php
321 + endif;
281 322 }
282 323
283 324 /**
284 325 * Creates a checkbox and a label for a video option.
@@ -309,9 +350,9 @@
309 350 return $this->create_checkbox_for_option(
310 351 "attachments-{$info->post_id}-displayembed",
311 352 "attachments[{$info->post_id}][display_embed]",
312 353 __( 'Display share menu and allow viewers to copy a link or embed this video', 'jetpack' ),
313 - isset( $info->display_embed ) ? $info->display_embed : 0
354 + $info->display_embed ?? 0
314 355 );
315 356 }
316 357
317 358 /**
@@ -342,14 +383,14 @@
342 383 VIDEOPRESS_PRIVACY::IS_PUBLIC => __( 'Public', 'jetpack' ),
343 384 VIDEOPRESS_PRIVACY::IS_PRIVATE => __( 'Private', 'jetpack' ),
344 385 );
345 386
346 - $displayed_privacy_setting = intval( isset( $info->privacy_setting ) ? $info->privacy_setting : VIDEOPRESS_PRIVACY::SITE_DEFAULT );
387 + $displayed_privacy_setting = intval( $info->privacy_setting ?? VIDEOPRESS_PRIVACY::SITE_DEFAULT );
347 388
348 389 $out = "<select name='attachments[{$info->post_id}][privacy_setting]'>";
349 390 foreach ( $privacy_settings as $r => $label ) {
350 391 $out .= "<option value=\"$r\"";
351 - if ( intval( $r ) === $displayed_privacy_setting ) {
392 + if ( $r === $displayed_privacy_setting ) {
352 393 $out .= ' selected';
353 394 }
354 395
355 396 $out .= ">$label</option>";
@@ -374,9 +415,9 @@
374 415 'PG-13' => 'PG-13',
375 416 'R-17' => 'R',
376 417 );
377 418
378 - $displayed_rating = isset( $info->rating ) ? $info->rating : null;
419 + $displayed_rating = $info->rating ?? null;
379 420
380 421 // X-18 was previously supported but is now removed to better comply with our TOS.
381 422 if ( 'X-18' === $displayed_rating ) {
382 423 $displayed_rating = 'R-17';