Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions admin/rt-transcoder-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function rta() {
function rt_media_shortcode( $attrs, $content = '' ) {

if ( empty( $attrs['attachment_id'] ) ) {
return false;
return false;
}

$attachment_id = $attrs['attachment_id'];
Expand All @@ -64,7 +64,7 @@ function rt_media_shortcode( $attrs, $content = '' ) {
$attrs['poster'] = $poster;

foreach ( $attrs as $key => $value ) {
$video_shortcode_attributes .= ' ' . $key . '="' . $value . '"';
$video_shortcode_attributes .= ' ' . $key . '="' . $value . '"';
}

$content = do_shortcode( "[video {$video_shortcode_attributes}]" );
Expand All @@ -76,7 +76,7 @@ function rt_media_shortcode( $attrs, $content = '' ) {
$audio_shortcode_attributes = 'src="' . $media_url . '"';

foreach ( $attrs as $key => $value ) {
$audio_shortcode_attributes .= ' ' . $key . '="' . $value . '"';
$audio_shortcode_attributes .= ' ' . $key . '="' . $value . '"';
}

$content = do_shortcode( "[audio {$audio_shortcode_attributes}]" );
Expand Down Expand Up @@ -133,7 +133,7 @@ function is_file_being_transcoded( $attachment_id ) {
function rt_media_get_video_thumbnail( $attachment_id ) {

if ( empty( $attachment_id ) ) {
return;
return;
}

$thumbnails = get_post_meta( $attachment_id, '_rt_media_video_thumbnail', true );
Expand All @@ -150,11 +150,11 @@ function rt_media_get_video_thumbnail( $attachment_id ) {

if ( 0 === strpos( $file_url, $uploads['baseurl'] ) ) {
$final_file_url = $file_url;
} else {
$final_file_url = $uploads['baseurl'] . '/' . $file_url;
}
} else {
$final_file_url = $uploads['baseurl'] . '/' . $file_url;
}

$final_file_url = apply_filters( 'transcoded_file_url', $final_file_url, $attachment_id );
$final_file_url = apply_filters( 'transcoded_file_url', $final_file_url, $attachment_id );

return $final_file_url;
}
Expand All @@ -175,7 +175,7 @@ function rt_media_get_video_thumbnail( $attachment_id ) {
function rtt_get_media_url( $attachment_id, $media_type = 'mp4' ) {

if ( empty( $attachment_id ) ) {
return;
return;
}

$medias = get_post_meta( $attachment_id, '_rt_media_transcoded_files', true );
Expand All @@ -190,10 +190,10 @@ function rtt_get_media_url( $attachment_id, $media_type = 'mp4' ) {
}
if ( 0 === strpos( $file_url, $uploads['baseurl'] ) ) {
$final_file_url = $file_url;
} else {
$final_file_url = $uploads['baseurl'] . '/' . $file_url;
}
$final_file_url = apply_filters( 'transcoded_file_url', $final_file_url, $attachment_id );
} else {
$final_file_url = $uploads['baseurl'] . '/' . $file_url;
}
$final_file_url = apply_filters( 'transcoded_file_url', $final_file_url, $attachment_id );
} else {
$final_file_url = wp_get_attachment_url( $attachment_id );
}
Expand Down Expand Up @@ -291,22 +291,22 @@ function rtt_get_edit_post_link( $id = 0, $context = 'display' ) {
}

if ( 'revision' === $post->post_type ) {
$action = '';
$action = '';
} elseif ( 'display' === $context ) {
$action = '&action=edit';
$action = '&action=edit';
} else {
$action = '&action=edit';
$action = '&action=edit';
}

$post_type_object = get_post_type_object( $post->post_type );
if ( ! $post_type_object ) {
return;
return;
}

if ( $post_type_object->_edit_link ) {
$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
} else {
$link = '';
$link = '';
}

return $link;
Expand Down Expand Up @@ -634,3 +634,15 @@ function rtt_is_override_thumbnail( $attachment_id = '' ) {
return $rtt_override_thumbnail;
}

/**
* Get remote IP address
* @return string Remote IP address
*/
function rtt_get_remote_ip_address() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
return $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $_SERVER['REMOTE_ADDR'];
}
6 changes: 4 additions & 2 deletions admin/rt-transcoder-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public function __construct( $no_init = false ) {

/* Do not let the user to upload non supported media types on localhost */
$blacklist = array( '127.0.0.1', '::1' );
if ( ! in_array( wp_unslash( $_SERVER['REMOTE_ADDR'] ), $blacklist, true ) ) { // @codingStandardsIgnoreLine
$remote_addr = rtt_get_remote_ip_address();
if ( ! in_array( wp_unslash( $remote_addr ), $blacklist, true ) ) { // @codingStandardsIgnoreLine
add_filter( 'rtmedia_plupload_files_filter', array( $this, 'allowed_types' ), 10, 1 );
add_filter( 'rtmedia_allowed_types', array( $this, 'allowed_types_admin_settings' ), 10, 1 );
add_filter( 'rtmedia_valid_type_check', array( $this, 'bypass_video_audio' ), 10, 2 );
Expand Down Expand Up @@ -439,7 +440,8 @@ public function save_api_key() {
if ( ! empty( $apikey ) && is_admin() && ! empty( $page ) && ( 'rt-transcoder' === $page ) ) {
/* Do not activate transcoding service on localhost */
$blacklist = array( '127.0.0.1', '::1' );
if ( in_array( wp_unslash( $_SERVER['REMOTE_ADDR'] ), $blacklist, true ) ) {
$remote_addr = rtt_get_remote_ip_address();
if ( in_array( wp_unslash( $remote_addr ), $blacklist, true ) ) {
$return_page = add_query_arg( array(
'page' => 'rt-transcoder',
'need-public-host' => '1',
Expand Down