Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-release to develop #2015

Merged
merged 13 commits into from
Nov 16, 2023
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
6 changes: 2 additions & 4 deletions app/admin/RTMediaAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1434,10 +1434,8 @@ public function import_settings( $file_path ) {
wp_send_json( $response );
}

ob_start();
include $file_path;

$settings_data_json = ob_get_clean();
$settings_data_json_string = file_get_contents( $file_path );
$settings_data_json = json_decode( $settings_data_json_string, true );
wp_delete_file( $file_path );

if ( empty( $settings_data_json ) ) {
Expand Down
39 changes: 30 additions & 9 deletions app/main/controllers/api/RTMediaJsonApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,8 @@ public function rtmedia_api_process_rtmedia_upload_media_request() {
$ec_no_file = 140001;
$msg_no_file = esc_html__( 'no file', 'buddypress-media' );

$ec_invalid_file_string = 140005;
$msg_invalid_file_string = esc_html__( 'invalid file string', 'buddypress-media' );
$ec_invalid_file_type = 140007;
$msg_invalid_file_type = esc_html__( 'invalid file type. jpeg and png are allowed.', 'buddypress-media' );

$ec_image_type_missing = 140006;
$msg_image_type_missing = esc_html__( 'image type missing', 'buddypress-media' );
Expand All @@ -1100,11 +1100,23 @@ public function rtmedia_api_process_rtmedia_upload_media_request() {
$ec_look_updated = 140004;
$msg_look_updated = esc_html__( 'media updated', 'buddypress-media' );

$rtmedia_file = sanitize_text_field( filter_input( INPUT_POST, 'rtmedia_file', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );
$image_type = sanitize_text_field( filter_input( INPUT_POST, 'image_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );
$title = sanitize_text_field( filter_input( INPUT_POST, 'title', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );
$mime_type = "";

if ( in_array( $image_type, array( 'jpeg', 'jpg' ), true ) ) {
$mime_type = 'image/jpeg';
}
else if ( 'png' === $image_type ) {
$mime_type = 'image/png';
} else {
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_file_type, $msg_invalid_file_type ) );
}

$title = sanitize_title( filter_input( INPUT_POST, 'title', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );
$description = sanitize_text_field( filter_input( INPUT_POST, 'description', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );

$rtmedia_file = sanitize_text_field( filter_input( INPUT_POST, 'rtmedia_file', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );

$updated = false;
$uploaded_look = false;

Expand All @@ -1118,6 +1130,8 @@ public function rtmedia_api_process_rtmedia_upload_media_request() {
}
if ( empty( $title ) ) {
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_file_title, $msg_no_file_title ) );
} else {
$title .= wp_generate_password( 12, false );
}
}

Expand All @@ -1137,23 +1151,30 @@ public function rtmedia_api_process_rtmedia_upload_media_request() {

// Process rtmedia_file.
$img = $rtmedia_file;
$str_replace = 'data:image/' . $image_type . ';base64,';
$str_replace = 'data:' . $mime_type . ';base64,';
$img = str_replace( $str_replace, '', $img );
$rtmedia_file = base64_decode( $img ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode

if ( ! $rtmedia_file ) {
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_file_string, $msg_invalid_file_string ) );
// check if file is valid image.
$actual_file_info = getimagesizefromstring( $rtmedia_file );

if ( ! $actual_file_info || ! isset( $actual_file_info['mime'] ) || ! in_array( $actual_file_info['mime'], array( 'image/jpeg', 'image/png' ), true ) ) {
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_image, $msg_invalid_image ) );
}

define( 'UPLOAD_DIR_LOOK', sys_get_temp_dir() . '/' );
define( 'UPLOAD_DIR_LOOK', sys_get_temp_dir() );

$tmp_name = UPLOAD_DIR_LOOK . $title;
$file = $tmp_name . '.' . $image_type;
$success = file_put_contents( $file, $rtmedia_file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents

if ( ! $success ) {
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_image, $msg_invalid_image ) );
}

add_filter( 'upload_dir', array( $this, 'api_new_media_upload_dir' ) );
$new_look = wp_upload_bits( $title . '.' . $image_type, null, $rtmedia_file );
$new_look['type'] = 'image/' . $image_type;
$new_look['type'] = $mime_type;
remove_filter( 'upload_dir', array( $this, 'api_new_media_upload_dir' ) );

foreach ( $new_look as $key => $value ) {
Expand Down
8 changes: 7 additions & 1 deletion app/main/controllers/media/RTMediaComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,14 @@ public static function pre_comment_render( $attr ) {
$template = 'comment-media';
}

ob_start();

$view = new RTMediaUploadView( $attr );
echo wp_kses( $view->render( $template ), RTMedia::expanded_allowed_tags() );
$view->render( $template );

$buffer = ob_get_clean();

echo wp_kses( $buffer, RTMedia::expanded_allowed_tags() );

}
} else {
Expand Down
8 changes: 7 additions & 1 deletion app/main/controllers/template/rtmedia-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,13 @@ function rtmedia_search_fillter_where_query( $where, $table_name ) {

if ( function_exists( 'rtmedia_media_search_enabled' ) && rtmedia_media_search_enabled() ) {

$search = sanitize_text_field( urldecode( wp_unslash( filter_input( INPUT_GET, 'search', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ) ) );
$raw_search = wp_unslash( filter_input( INPUT_GET, 'search', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );

if ( 'string' !== gettype( $raw_search ) ) {
$raw_search = "";
}

$search = sanitize_text_field( urldecode( $raw_search ) );
$search_by = sanitize_text_field( wp_unslash( filter_input( INPUT_GET, 'search_by', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ) );
$media_type = sanitize_text_field( wp_unslash( filter_input( INPUT_GET, 'media_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ) );
$rtmedia_current_album = sanitize_text_field( wp_unslash( filter_input( INPUT_GET, 'rtmedia-current-album', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ) );
Expand Down
5 changes: 2 additions & 3 deletions app/main/controllers/template/rtmedia-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,7 @@ function rtmedia_duration( $id = false ) {

if ( ! empty( $rtmedia_backbone['backbone'] ) ) {
echo '<%= duration %>';

return;
return '';
}

if ( $id ) {
Expand All @@ -965,7 +964,7 @@ function rtmedia_duration( $id = false ) {
if ( isset( $media[0] ) ) {
$media_object = $media[0];
} else {
return false;
return '';
}
} else {
global $rtmedia_media;
Expand Down