From 417350ea41fc3c1e386057f1936acfd1c8d5bc0e Mon Sep 17 00:00:00 2001 From: Mangesh Parte Date: Mon, 9 Jan 2017 15:52:58 +0530 Subject: [PATCH 1/3] Add function to get remote IP --- admin/rt-transcoder-functions.php | 50 +++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/admin/rt-transcoder-functions.php b/admin/rt-transcoder-functions.php index 82a9ac03..6bbcd9a1 100644 --- a/admin/rt-transcoder-functions.php +++ b/admin/rt-transcoder-functions.php @@ -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']; @@ -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}]" ); @@ -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}]" ); @@ -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 ); @@ -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; } @@ -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 ); @@ -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 ); } @@ -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; @@ -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 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' ]; +} \ No newline at end of file From 622b7ba5b1308145ee3a7c12c3c3760e97b2a1f2 Mon Sep 17 00:00:00 2001 From: Mangesh Parte Date: Mon, 9 Jan 2017 15:53:56 +0530 Subject: [PATCH 2/3] Get remote IP using get_remote_ip_address function --- admin/rt-transcoder-handler.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/admin/rt-transcoder-handler.php b/admin/rt-transcoder-handler.php index a006495a..c417b16a 100644 --- a/admin/rt-transcoder-handler.php +++ b/admin/rt-transcoder-handler.php @@ -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 = 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 ); @@ -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 = 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', From 5425905210ec70682f2bb4884a70ec6558c99675 Mon Sep 17 00:00:00 2001 From: Mangesh Parte Date: Tue, 10 Jan 2017 16:19:50 +0530 Subject: [PATCH 3/3] Add prefix to the function --- admin/rt-transcoder-functions.php | 14 +++++++------- admin/rt-transcoder-handler.php | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/admin/rt-transcoder-functions.php b/admin/rt-transcoder-functions.php index 6bbcd9a1..9ffe3b1b 100644 --- a/admin/rt-transcoder-functions.php +++ b/admin/rt-transcoder-functions.php @@ -638,11 +638,11 @@ function rtt_is_override_thumbnail( $attachment_id = '' ) { * Get remote IP address * @return string Remote IP address */ -function 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' ]; +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' ]; -} \ No newline at end of file + return $_SERVER['REMOTE_ADDR']; +} diff --git a/admin/rt-transcoder-handler.php b/admin/rt-transcoder-handler.php index c417b16a..777cf0e2 100644 --- a/admin/rt-transcoder-handler.php +++ b/admin/rt-transcoder-handler.php @@ -136,7 +136,7 @@ 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' ); - $remote_addr = get_remote_ip_address(); + $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 ); @@ -440,7 +440,7 @@ 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' ); - $remote_addr = get_remote_ip_address(); + $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',