Skip to content

Commit 320fdc4

Browse files
Merge pull request #165 from rtMediaWP/fix/retranscode
Fix retranscode service and duplicate thumbnail issue
2 parents 56efe5d + f3aece8 commit 320fdc4

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

admin/rt-retranscode-admin.php

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,8 @@ public function retranscode_interface() {
301301

302302
// Create the list of image IDs.
303303
$usage_info = get_site_option( 'rt-transcoding-usage' );
304-
$ids = transcoder_filter_input( INPUT_REQUEST, 'ids', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY );
305-
304+
$ids = transcoder_filter_input( INPUT_GET, 'ids', FILTER_SANITIZE_STRING );
306305
if ( ! empty( $ids ) ) {
307-
if ( is_array( $ids ) ) {
308-
$ids = implode( ',', $ids );
309-
}
310306
$media = array_map( 'intval', explode( ',', trim( $ids, ',' ) ) );
311307
$ids = implode( ',', $media );
312308
foreach ( $media as $key => $each ) {
@@ -412,7 +408,7 @@ public function retranscode_interface() {
412408

413409

414410
// translators: Count of media which were successfully transcoded with the time in seconds.
415-
$text_goback = ( ! empty( $_GET['goback'] ) ) ? sprintf( __( 'To go back to the previous page, <a href="%s">click here</a>.', 'transcoder' ), 'javascript:history.go(-1)' ) : '';
411+
$text_goback = ( ! empty( $_GET['goback'] ) ) ? __( 'To go back to the previous page, <a id="retranscode-goback" href="#">click here</a>.', 'transcoder' ) : '';
416412

417413
// translators: Count of media which were successfully and media which were failed transcoded with the time in seconds and previout page link.
418414
$text_failures = sprintf( __( 'All done! %1$s media file(s) were successfully sent for transcoding in %2$s seconds and there were %3$s failure(s). To try transcoding the failed media again, <a href="%4$s">click here</a>. %5$s', 'transcoder' ), "' + rt_successes + '", "' + rt_totaltime + '", "' + rt_errors + '", esc_url( wp_nonce_url( admin_url( 'admin.php?page=rt-retranscoder&goback=1' ), 'rt-retranscoder' ) . '&ids=' ) . "' + rt_failedlist + '", $text_goback );
@@ -508,16 +504,33 @@ function RetranscodeMediaFinishUp() {
508504

509505
$('#retranscodemedia-stop').hide();
510506

507+
<?php
508+
// Allowed tags for notice.
509+
$allowed_tags = array(
510+
'a' => array(
511+
'href' => array(),
512+
'id' => array(),
513+
),
514+
);
515+
?>
516+
511517
if ( rt_errors > 0 ) {
512-
rt_resulttext = '<?php echo wp_kses( $text_failures, array( 'a' => array( 'href' => array() ) ) ); ?>';
518+
rt_resulttext = '<?php echo wp_kses( $text_failures, $allowed_tags ); ?>';
513519
} else {
514-
rt_resulttext = '<?php echo esc_html( $text_nofailures ); ?>';
520+
rt_resulttext = '<?php echo wp_kses( $text_nofailures, $allowed_tags ); ?>';
515521
}
516-
517522
$("#message").html("<p><strong>" + rt_resulttext + "</strong></p>");
518523
$("#message").show();
519-
}
520524

525+
$( '#retranscode-goback' ).on( 'click', function () {
526+
window.history.go( -1 );
527+
} );
528+
529+
}
530+
<?php
531+
// translators: Media ID.
532+
$error_response = sprintf( __( 'The resize request was abnormally terminated (ID %s). This is likely due to the media exceeding available memory or some other type of fatal error.', 'transcoder' ), '" + id + "' );
533+
?>
521534
// Regenerate a specified image via AJAX
522535
function RetranscodeMedia( id ) {
523536
$.ajax({
@@ -528,12 +541,7 @@ function RetranscodeMedia( id ) {
528541
if ( response !== Object( response ) || ( typeof response.success === "undefined" && typeof response.error === "undefined" ) ) {
529542
response = new Object;
530543
response.success = false;
531-
response.error = "
532-
<?php
533-
// translators: Media ID.
534-
printf( esc_js( __( 'The resize request was abnormally terminated (ID %s). This is likely due to the media exceeding available memory or some other type of fatal error.', 'transcoder' ) ), '" + id + "' );
535-
?>
536-
";
544+
response.error = '<?php echo esc_js( $error_response ); ?>';
537545
}
538546

539547
if ( response.success ) {
@@ -607,8 +615,7 @@ function RetranscodeMedia( id ) {
607615
public function ajax_process_retranscode_request() {
608616

609617
header( 'Content-type: application/json' );
610-
611-
$id = transcoder_filter_input( INPUT_REQUEST, 'id', FILTER_SANITIZE_NUMBER_INT );
618+
$id = transcoder_filter_input( INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT );
612619
$id = intval( $id );
613620

614621
if ( empty( $id ) || 0 >= $id ) {
@@ -620,7 +627,7 @@ public function ajax_process_retranscode_request() {
620627
if ( ! $media || 'attachment' !== $media->post_type ||
621628
(
622629
'audio/' !== substr( $media->post_mime_type, 0, 6 ) &&
623-
'video/' !== substr( $media->post_mime_type, 0, 6 ) ||
630+
'video/' !== substr( $media->post_mime_type, 0, 6 ) &&
624631
'application/pdf' !== $media->post_mime_type
625632
)
626633
) {

admin/rt-transcoder-handler.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class RT_Transcoder_Handler {
2929
* @access protected
3030
* @var string $transcoding_api_url The URL of the api.
3131
*/
32-
protected $transcoding_api_url = 'http://api.rtmedia.io/api/v1/';
32+
protected $transcoding_api_url = 'https://api.rtmedia.io/api/v1/';
3333

3434
/**
3535
* The URL of the EDD store.
@@ -1510,6 +1510,9 @@ public function get_transcoding_status( $post_id ) {
15101510
$results = $wpdb->get_results( $wpdb->prepare( 'SELECT id FROM %s WHERE media_id = %d', $wpdb->prefix . 'rt_rtm_media', $post_id ), OBJECT ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
15111511
$response['media_id'] = $results[0]->id;
15121512

1513+
} elseif ( ! empty( $status_info ) && 'processed' === $status_info->status && ( 'pdf' === $status_info->job_type ) ) {
1514+
$message = $messages['success'];
1515+
$status = 'Success';
15131516
} elseif ( ! empty( $status_info ) ) {
15141517
$message = $status_info->status;
15151518
}
@@ -1603,7 +1606,6 @@ private function filter_transcoder_response() {
16031606

16041607
$post_array['thumbnail'] = array();
16051608
if ( ! empty( $post_var['thumbnail'] ) && is_array( $post_var['thumbnail'] ) ) {
1606-
$post_array['thumbnail'] = filter_var( $post_var['thumbnail'], FILTER_SANITIZE_URL, FILTER_FORCE_ARRAY );
16071609
foreach ( $post_var['thumbnail'] as $thumbnail_url ) {
16081610
$post_array['thumbnail'][] = filter_var( $thumbnail_url, FILTER_SANITIZE_URL );
16091611
}

0 commit comments

Comments
 (0)