0 ); } if ( 'attachment' !== $post_type ) { return; } // If this has not been processed by videopress, we can skip the rest. if ( ! is_videopress_attachment( $post->ID ) ) { return; } add_meta_box( 'videopress-media-info', __( 'VideoPress Information', 'jetpack' ), array( $this, 'videopress_information_box' ), 'attachment', 'side', 'core' ); } /** * Filter attachment fields data to save. * * @param array $post Post data. * @param array|null $attachment Attachment metadata. * * @return array */ public function save_fields( $post, $attachment = null ) { // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verification already done by core. if ( null === $attachment && isset( $_POST['attachment'] ) ) { $attachment = filter_var( wp_unslash( $_POST['attachment'] ) ); } if ( ! isset( $attachment['is_videopress_attachment'] ) || 'yes' !== $attachment['is_videopress_attachment'] ) { return $post; } // If this has not been processed by videopress, we can skip the rest. if ( ! is_videopress_attachment( $post['ID'] ) ) { $post['errors']['videopress']['errors'][] = __( 'The media you are trying to update is not processed by VideoPress.', 'jetpack' ); return $post; } $post_title = isset( $_POST['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['post_title'] ) ) : null; $post_excerpt = isset( $_POST['post_excerpt'] ) ? sanitize_textarea_field( wp_unslash( $_POST['post_excerpt'] ) ) : null; $rating = isset( $attachment['rating'] ) ? $attachment['rating'] : null; $display_embed = isset( $attachment['display_embed'] ) ? $attachment['display_embed'] : 0; $allow_download = isset( $attachment['allow_download'] ) ? $attachment['allow_download'] : 0; $privacy_setting = isset( $attachment['privacy_setting'] ) ? $attachment['privacy_setting'] : VIDEOPRESS_PRIVACY::SITE_DEFAULT; $result = Videopress_Attachment_Metadata::persist_metadata( $post['ID'], get_post_meta( $post['ID'], 'videopress_guid', true ), $post_title, null, // @todo: Check why we haven't sent the caption in the first place. $post_excerpt, $rating, $this->normalize_checkbox_value( $display_embed ), $this->normalize_checkbox_value( $allow_download ), $privacy_setting ); if ( is_wp_error( $result ) ) { $post['errors']['videopress']['errors'][] = $result->get_error_message(); return $post; } return $post; // phpcs:enable WordPress.Security.NonceVerification.Missing } /** * Convert the string values of a checkbox option to the format that they will be stored in db. * * @param string $value The denormalized version. * * @return int */ private function normalize_checkbox_value( $value ) { return 'on' === $value ? 1 : 0; } /** * Get the upload api path. * * @param string $guid The guid of the video. * @return string */ public function make_video_api_path( $guid ) { return sprintf( '%s/rest/v%s/videos/%s', JETPACK__WPCOM_JSON_API_BASE, Client::WPCOM_JSON_API_VERSION, $guid ); } /** * Creates an array of video fields to edit based on transcoded videos. * * @param array $fields video fields of interest. * @param stdClass $post Post object. * @return array modified version of video fields for administrative interface display */ public function fields_to_edit( $fields, $post ) { $post_id = absint( $post->ID ); $meta = wp_get_attachment_metadata( $post_id ); // If this has not been processed by videopress, we can skip the rest. if ( ! is_videopress_attachment( $post_id ) || ! isset( $meta['videopress'] ) ) { return $fields; } $info = (object) $meta['videopress']; $file_statuses = isset( $meta['file_statuses'] ) ? $meta['file_statuses'] : array(); $guid = get_post_meta( $post_id, 'videopress_guid', true ); unset( $fields['url'] ); unset( $fields['post_content'] ); // If a video isn't attached to any specific post, manually add a post ID. if ( ! isset( $info->post_id ) ) { $info->post_id = 0; } if ( isset( $file_statuses['ogg'] ) && 'done' === $file_statuses['ogg'] ) { $v_name = preg_replace( '/\.\w+/', '', basename( $info->path ) ); $video_name = $v_name . '_fmt1.ogv'; $ogg_url = videopress_cdn_file_url( $guid, $video_name ); $fields['video-ogg'] = array( 'label' => __( 'Ogg File URL', 'jetpack' ), 'input' => 'html', 'html' => "", 'helps' => __( 'Location of the Ogg video file.', 'jetpack' ), ); } $fields['post_title']['helps'] = __( 'Title will appear on the first frame of your video', 'jetpack' ); $fields['post_excerpt']['label'] = _x( 'Description', 'A header for the short description display', 'jetpack' ); $fields['post_excerpt']['input'] = 'textarea'; $fields['post_excerpt']['value'] = ! empty( $info->description ) ? $info->description : ''; $fields['is_videopress_attachment'] = array( 'input' => 'hidden', 'value' => 'yes', ); $fields['videopress_shortcode'] = array( 'label' => _x( 'Shortcode', 'A header for the shortcode display', 'jetpack' ), 'input' => 'html', 'html' => "", 'show_in_modal' => true, 'show_in_edit' => false, ); $fields['display_embed'] = array( 'label' => _x( 'Share', 'A header for the video sharing options area', 'jetpack' ), 'input' => 'html', 'html' => $this->display_embed_choice( $info ), ); $fields['allow_download'] = array( 'label' => _x( 'Download', 'A header for the video allow download option area', 'jetpack' ), 'input' => 'html', 'html' => $this->display_download_choice( $info ), ); $fields['video-rating'] = array( 'label' => _x( 'Rating', 'A header for the video rating area', 'jetpack' ), 'input' => 'html', 'html' => $this->display_rating( $info ), ); $fields['privacy_setting'] = array( 'label' => _x( 'Privacy Setting', 'A header for the video privacy setting area.', 'jetpack' ), 'input' => 'html', 'html' => $this->display_privacy_setting( $info ), ); return $fields; } /** * Meta box output. * * @param stdClass $post Post object. */ public function videopress_information_box( $post ) { $post_id = absint( $post->ID ); $meta = wp_get_attachment_metadata( $post_id ); $guid = get_post_meta( $post_id, 'videopress_guid', true ); // If this has not been processed by videopress, we can skip the rest. if ( ! is_videopress_attachment( $post_id ) ) { return; } $info = (object) $meta['videopress']; $embed = "[videopress {$guid}]"; $shortcode = ''; $url = 'empty'; if ( ! empty( $guid ) ) { $url = videopress_build_url( $guid ); $url = "{$url}"; } $poster = 'Still Processing'; if ( ! empty( $info->poster ) ) { $poster = "
poster}\" width=\"175px\">"; } $html = <<< HTML
Shortcode
{$shortcode}
Url {$url}
Poster {$poster}
HTML; echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Variables built above. } /** * Creates a checkbox and a label for a video option. * * @param string $id the checkbox id. * @param string $name the checkbox name. * @param string $label the label text. * @param bool $is_checked if the checkbox should be checked. * * @return string the generated HTML */ protected function create_checkbox_for_option( $id, $name, $label, $is_checked ) { $html = ""; unset( $id ); } return $out; } } // Let's start this thing up. VideoPress_Edit_Attachment::init();