/** * Ajax action to update the video transcoding status from the WPCOM API. * * @return void */ public function wp_ajax_update_transcoding_status() { if (!isset($_POST['post_id'])) { wp_send_json_error(array('message' => __('A valid post_id is required.', 'jetpack'))); return; } $post_id = (int) $_POST['post_id']; if (!videopress_update_meta_data($post_id)) { wp_send_json_error(array('message' => __('That post does not have a VideoPress video associated to it..', 'jetpack'))); return; } wp_send_json_success(array('message' => __('Status updated', 'jetpack'), 'status' => videopress_get_transcoding_status($post_id))); }
/** * @param stdClass $post */ public function videopress_information_box($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 (!isset($meta['videopress'])) { return; } $info = (object) $meta['videopress']; $status = videopress_get_transcoding_status($post_id); $formats = array('std_mp4' => 'Standard MP4', 'std_ogg' => 'OGG Vorbis', 'dvd_mp4' => 'DVD', 'hd_mp4' => 'High Definition'); $embed = "[videopress {$info->guid}]"; $shortcode = '<input type="text" id="plugin-embed" readonly="readonly" style="width:180px;" value="' . esc_attr($embed) . '" onclick="this.focus();this.select();" />'; $trans_status = ''; $all_trans_done = true; foreach ($formats as $status_key => $name) { if ('DONE' !== $status[$status_key]) { $all_trans_done = false; } $trans_status .= '- <strong>' . $name . ":</strong> <span id=\"status_{$status_key}\">" . ('DONE' === $status[$status_key] ? 'Done' : 'Processing') . '</span><br>'; } $nonce = wp_create_nonce('videopress-update-transcoding-status'); $url = 'empty'; if (!empty($info->guid)) { $url = videopress_build_url($info->guid); $url = "<a href=\"{$url}\">{$url}</a>"; } $poster = '<em>Still Processing</em>'; if (!empty($info->poster)) { $poster = "<br><img src=\"{$info->poster}\" width=\"175px\">"; } $status_update = ''; if (!$all_trans_done) { $status_update = ' (<a href="javascript:;" id="videopress-update-transcoding-status">update</a>)'; } $html = <<<HTML <div class="misc-pub-section misc-pub-shortcode"> \t<strong>Shortcode</strong><br> \t{$shortcode} </div> <div class="misc-pub-section misc-pub-url"> \t<strong>Url</strong> \t{$url} </div> <div class="misc-pub-section misc-pub-poster"> \t<strong>Poster</strong> \t{$poster} </div> <div class="misc-pub-section misc-pub-status"> \t<strong>Transcoding Status{$status_update}:</strong> \t<div id="videopress-transcoding-status">{$trans_status}</div> </div> <script> \tjQuery( function(\$) { \t\t\$( '#videopress-update-transcoding-status' ).on( "click", function() { \t\t\tjQuery.ajax( { \t\t\t\ttype: 'post', \t\t\t\turl: 'admin-ajax.php', \t\t\t\tdata: { \t\t\t\t\taction: 'videopress-update-transcoding-status', \t\t\t\t\tpost_id: '{$post_id}', \t\t\t\t\t_ajax_nonce: '{$nonce}' \t\t\t\t}, \t\t\t\tcomplete: function( response ) { \t\t\t\t\tif ( 200 === response.status ) { \t\t\t\t\t\tvar statuses = response.responseJSON.data.status; \t\t\t\t\t\tfor (var key in statuses) { \t\t\t\t\t\t\t\$('#status_' + key).text( 'DONE' === statuses[key] ? 'Done' : 'Processing' ); \t\t\t\t\t\t} \t\t\t\t\t} \t\t\t\t} \t\t\t}); \t\t} ); \t} ); </script> HTML; echo $html; }