Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 5011b64

Browse files
committed
Update code PDF thumbnail
1 parent 5a90581 commit 5011b64

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

admin/rt-retranscode-admin.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,28 @@ public function admin_enqueues( $hook_suffix ) {
116116

117117
// Add a "Retranscode Media" link to the media row actions
118118
public function add_media_row_action( $actions, $post ) {
119-
if ( ( 'audio/' !== substr( $post->post_mime_type, 0, 6 ) && 'video/' !== substr( $post->post_mime_type, 0, 6 ) && 'application/pdf' !== $post->post_mime_type ) || 'audio/mpeg' === $post->post_mime_type || ! current_user_can( $this->capability ) ) {
119+
120+
if ( (
121+
'audio/' !== substr( $post->post_mime_type, 0, 6 ) &&
122+
'video/' !== substr( $post->post_mime_type, 0, 6 ) &&
123+
'application/pdf' !== $post->post_mime_type
124+
) ||
125+
'audio/mpeg' === $post->post_mime_type ||
126+
! current_user_can( $this->capability )
127+
) {
120128
return $actions;
121129
}
122130

131+
$actions = ( ! empty( $actions ) && is_array( $actions ) ) ? $actions : [];
132+
123133
$url = wp_nonce_url( admin_url( 'admin.php?page=rt-retranscoder&goback=1&ids=' . $post->ID ), 'rt-retranscoder' );
124-
$actions['retranscode_media'] = '<a href="' . esc_url( $url ) . '" title="' . esc_attr( __( "Retranscode this single media", 'transcoder' ) ) . '">' . __( 'Retranscode Media', 'transcoder' ) . '</a>';
134+
135+
$actions['retranscode_media'] = sprintf(
136+
'<a href="%s" title="%s">%s</a>',
137+
esc_url( $url ),
138+
esc_attr__( 'Retranscode this single media', 'transcoder' ),
139+
__( 'Retranscode Media', 'transcoder' )
140+
);
125141

126142
return $actions;
127143
}
@@ -481,7 +497,13 @@ public function ajax_process_retranscode_request() {
481497
$id = (int) $_REQUEST['id'];
482498
$media = get_post( $id );
483499

484-
if ( ! $media || 'attachment' !== $media->post_type || ( 'audio/' !== substr( $media->post_mime_type, 0, 6 ) && 'video/' !== substr( $media->post_mime_type, 0, 6 ) || 'application/pdf' !== $media->post_mime_type ) ) {
500+
if ( ! $media || 'attachment' !== $media->post_type ||
501+
(
502+
'audio/' !== substr( $media->post_mime_type, 0, 6 ) &&
503+
'video/' !== substr( $media->post_mime_type, 0, 6 ) ||
504+
'application/pdf' !== $media->post_mime_type
505+
)
506+
) {
485507
die( json_encode( array( 'error' => sprintf( __( 'Sending Failed: %s is an invalid media ID/type.', 'transcoder' ), esc_html( $_REQUEST['id'] ) ) ) ) );
486508
}
487509

admin/rt-transcoder-handler.php

Lines changed: 16 additions & 24 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://test.api.rtmedia.io/api/v1/';
32+
protected $transcoding_api_url = 'http://api.rtmedia.io/api/v1/';
3333

3434
/**
3535
* The URL of the EDD store.
@@ -84,6 +84,7 @@ class RT_Transcoder_Handler {
8484
* @var string $audio_extensions Audio extensions with comma separated.
8585
*/
8686
public $audio_extensions = ',wma,ogg,wav,m4a';
87+
8788
/**
8889
* Other extensions with comma separated.
8990
*
@@ -92,6 +93,7 @@ class RT_Transcoder_Handler {
9293
* @var string $other_extensions Other extensions with comma separated.
9394
*/
9495
public $other_extensions = ',pdf';
96+
9597
/**
9698
* Allowed mimetypes.
9799
*
@@ -103,6 +105,7 @@ class RT_Transcoder_Handler {
103105
'application/ogg',
104106
'application/pdf',
105107
);
108+
106109
/**
107110
* Initialize the class and set its properties.
108111
*
@@ -112,15 +115,18 @@ class RT_Transcoder_Handler {
112115
*/
113116
public function __construct( $no_init = false ) {
114117

115-
$this->api_key = get_site_option( 'rt-transcoding-api-key' );
116-
$this->stored_api_key = get_site_option( 'rt-transcoding-api-key-stored' );
118+
$this->api_key = get_site_option( 'rt-transcoding-api-key' );
119+
$this->stored_api_key = get_site_option( 'rt-transcoding-api-key-stored' );
120+
$this->transcoding_api_url = apply_filters( 'transcoding_api_url', $this->transcoding_api_url );
117121

118122
if ( $no_init ) {
119123
return;
120124
}
125+
121126
if ( is_admin() ) {
122127
add_action( 'rt_transcoder_before_widgets', array( $this, 'usage_widget' ) );
123128
}
129+
124130
add_action( 'admin_init', array( $this, 'save_api_key' ), 10, 1 );
125131

126132
if ( $this->api_key ) {
@@ -1449,6 +1455,7 @@ public function get_transcoding_status( $post_id ) {
14491455

14501456
return wp_json_encode( $response );
14511457
}
1458+
14521459
/**
14531460
* Send transcoding request to the server for PDF files.
14541461
*
@@ -1459,35 +1466,20 @@ public function get_transcoding_status( $post_id ) {
14591466
*/
14601467
public function after_upload_pdf( $post_id ) {
14611468

1462-
/**
1463-
* Allow users to disable PDF thumbnail generation using transcoder.
1464-
*/
1465-
if ( ! apply_filters( 'transcoder_enable_pdf_thumbnail', true ) ) {
1466-
return;
1467-
}
1468-
1469-
// Check if the Ghostscript is enabled.
1470-
$is_gs_enabled = false;
1471-
if ( ! defined( 'VIP_GO_APP_ENVIRONMENT' ) && function_exists( 'exec' ) ) {
1472-
$gs = exec( 'gs --version' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec
1473-
if ( empty( $gs ) ) {
1474-
$is_gs_enabled = false;
1475-
} else {
1476-
$is_gs_enabled = true;
1477-
}
1478-
}
1479-
14801469
// If it have native support, skip the use of transcoder server.
1481-
if ( extension_loaded( 'imagick' ) && class_exists( 'Imagick', false ) &&
1470+
if ( extension_loaded( 'imagick' ) &&
1471+
class_exists( 'Imagick', false ) &&
14821472
class_exists( 'ImagickPixel', false ) &&
1483-
version_compare( phpversion( 'imagick' ), '2.2.0', '>=' ) &&
1484-
$is_gs_enabled
1473+
version_compare( phpversion( 'imagick' ), '2.2.0', '>=' )
14851474
) {
14861475
return;
14871476
}
14881477

14891478
$file_url = wp_get_attachment_url( $post_id );
14901479
$filetype = wp_check_filetype( $file_url );
1480+
1481+
$filetype['ext'] = strtolower( $filetype['ext'] );
1482+
14911483
if ( 'pdf' === $filetype['ext'] ) {
14921484
$this->wp_media_transcoding( array( 'mime_type' => 'application/pdf' ), $post_id );
14931485
}

0 commit comments

Comments
 (0)