Skip to content

Commit

Permalink
Merge pull request #1675 from rtCamp/develop
Browse files Browse the repository at this point in the history
Version update v4.6.4
  • Loading branch information
nitun authored Jul 16, 2020
2 parents 893f351 + 1a4a318 commit b0c1d80
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 170 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ https://www.youtube.com/watch?v=dJrykKQGDcs

## Changelog ##

### 4.6.4 [July 16, 2020] ###

* Enhancement
* Support for Amazon S3 presigned URLs
* Add attachment_ids in `rtmedia_after_add_media` action hook

* FIXED

* Console errors on media editing
* Extension getting changed when renaming media before upload
* Activities not in sync with other subsites in a multisite network, when each subsite has a separate BuddyPress activity feed
* PHP Notices and Warnings
* Comment nesting issue with media activities
* Wrong timestamp while adding comments

### 4.6.3 [April 30, 2020] ###

* FIXED
Expand Down
37 changes: 29 additions & 8 deletions app/assets/js/rtMedia.backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ jQuery( function( $ ) {
media_children.remove();
}
});

/**
* Remove imageEdit.save function call and add it only when image is being modified in WP editor.
*/
$( '#rtmedia_media_single_edit .rtm-button-save' ).on( 'click', function() {
var $media_id = $( '#rtmedia-editor-media-id' ).val();
var $nonce = $( '#rtmedia-editor-nonce' ).val();
if ( 'undefined' === typeof $nonce || '' === $nonce.trim() || 'undefined' === typeof $media_id || '' === $media_id.trim() ) {
return;
}
$media_id = parseInt( $media_id );
$media_head = $( '#media-head-' + $media_id );
if ( ! $media_head.length || 'undefined' === typeof $media_head.css( 'display' ) || 'none' !== $media_head.css( 'display' ).trim() ) {
return;
}

imageEdit.save( $media_id, $nonce );
} );
});
/**
* End of issue 1059 fix
Expand Down Expand Up @@ -717,10 +735,11 @@ jQuery( function( $ ) {
var file_desc_val = jQuery( rtm_file_desc_input ).val();
var file_name_wrapper_el = jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' );

if ( file_title_val != '' ) {
file_name_wrapper_el.text( file_title_val + '.' + rtm_file_name_array[ 1 ] );
file.title = file_title_val;
}
if ( '' !== file_title_val.trim() ) {
var extension = file.name.split( '.' )[1];
file_name_wrapper_el.text( file_title_val + '.' + extension );
file.title = file_title_val;
}

if ( file_desc_val != '' ) {
file.description = file_desc_val;
Expand Down Expand Up @@ -1285,8 +1304,9 @@ jQuery( document ).ready( function( $ ) {

var file_name_wrapper_el = jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' );

if ( file_title_val != '' ) {
file_name_wrapper_el.text( file_title_val + '.' + rtm_file_name_array[ 1 ] );
if ( '' !== file_title_val.trim() ) {
var extension = file.name.split( '.' )[1];
file_name_wrapper_el.text( file_title_val + '.' + extension );
file.title = file_title_val;
}

Expand Down Expand Up @@ -2631,8 +2651,9 @@ function renderUploadercomment_media( widget_id, parent_id_type ) {

var file_name_wrapper_el = jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' );

if ( file_title_val != '' ) {
file_name_wrapper_el.text( file_title_val + '.' + rtm_file_name_array[ 1 ] );
if ( '' !== file_title_val.trim() ) {
var extension = file.name.split( '.' )[1];
file_name_wrapper_el.text( file_title_val + '.' + extension );
file.title = file_title_val;
}

Expand Down
18 changes: 18 additions & 0 deletions app/helper/RTMediaActivityModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ public function get( $columns, $offset = false, $per_page = false, $order_by = '
return parent::get( $columns, $offset, $per_page, $order_by );
}

/**
* Get activity without setting blog_id.
* This function is needed because there's no way to get activity of a different blog.
* Existing get method sets blog_id to current blog.
*
* @since v4.6.4
*
* @param array $columns Columns.
* @param bool|int $offset Offset.
* @param bool|int $per_page Per page.
* @param string $order_by Order by.
*
* @return array Returned data.
*/
public function get_without_blog_id( $columns, $offset = false, $per_page = false, $order_by = 'activity_id DESC' ) {
return parent::get( $columns, $offset, $per_page, $order_by );
}

/**
* Insert row.
*
Expand Down
17 changes: 0 additions & 17 deletions app/main/controllers/activity/RTMediaBuddyPressActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function __construct() {
add_filter( 'bp_activity_truncate_entry', array( $this, 'bp_activity_truncate_entry' ), 10, 3 );
}
}
add_action( 'bp_init', array( $this, 'non_threaded_comments' ) );
add_action( 'bp_activity_comment_posted', array( $this, 'comment_sync' ), 10, 2 );
add_action( 'bp_activity_delete_comment', array( $this, 'delete_comment_sync' ), 10, 2 );
add_filter( 'bp_activity_allowed_tags', array( &$this, 'override_allowed_tags' ) );
Expand Down Expand Up @@ -557,22 +556,6 @@ public function comment_sync( $comment_id, $param ) {
}
}

/**
* Save Non-threaded comments.
*/
public function non_threaded_comments() {
$action = sanitize_text_field( filter_input( INPUT_POST, 'action', FILTER_SANITIZE_STRING ) );
if ( 'new_activity_comment' === $action ) {
$activity_id = filter_input( INPUT_POST, 'form_id', FILTER_SANITIZE_NUMBER_INT );
$disable_media = filter_input( INPUT_POST, 'rtmedia_disable_media_in_commented_media', FILTER_SANITIZE_STRING );
$act = new BP_Activity_Activity( $activity_id );

if ( 'rtmedia_update' === $act->type && ! empty( $disable_media ) ) {
$_POST['comment_id'] = $activity_id;
}
}
}

/**
* Groups posted update.
*
Expand Down
13 changes: 12 additions & 1 deletion app/main/controllers/media/RTMediaMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,20 @@ public function add( $uploaded, $file_object ) {
$rtmedia_points_media_id = $media_ids[0];
}

/**
* Action after a specific type of media is added from rtMedia.
*/
do_action( 'rtmedia_after_add_' . $rtmedia_type );

do_action( 'rtmedia_after_add_media', $media_ids, $file_object, $uploaded );
/**
* Action after media is added from rtMedia.
*
* @param array $media_ids rtMedia IDs.
* @param array $file_object File details.
* @param array $uploaded Uploaded media details.
* @param array $attachment_ids Attachment IDs of uploaded media.
*/
do_action( 'rtmedia_after_add_media', $media_ids, $file_object, $uploaded, $attachment_ids );

return $media_ids;
}
Expand Down
19 changes: 16 additions & 3 deletions app/main/controllers/template/rtmedia-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ function replace_src_with_transcoded_file_url( $html, $rtmedia_media ) {
$final_file_url = wp_get_attachment_url( $attachment_id );
}

// Add timestamp to resolve conflict with cache media.
return preg_replace( '/src=["]([^"]+)["]/', 'src="' . $final_file_url . '?' . time() . '"', $html );
$final_file_url = rtmedia_append_timestamp_in_url( $final_file_url );

return preg_replace( '/src=["]([^"]+)["]/', 'src="' . $final_file_url . '"', $html );

}
add_filter( 'rtmedia_single_content_filter', 'replace_src_with_transcoded_file_url', 100, 2 );
Expand Down Expand Up @@ -418,15 +419,27 @@ function replace_aws_img_urls_from_activities( $content, $activity = '' ) {

if ( ! class_exists( 'RTAWSS3_Class' ) && ! class_exists( 'AS3CF_Utils' ) ) {

// for WordPress backward compatibility.
// Get blog_id of activity from rtMedia table.
$rt_activity_model = new RTMediaActivityModel();
$rtmedia_activity = $rt_activity_model->get_without_blog_id( array( 'activity_id' => $activity->id ) );
// Switch to activity blog to get correct uploads URL.
if ( ! empty( $rtmedia_activity[0]->blog_id ) ) {
switch_to_blog( $rtmedia_activity[0]->blog_id );
}
// For WordPress backward compatibility.
if ( function_exists( 'wp_get_upload_dir' ) ) {
$uploads = wp_get_upload_dir();
} else {
$uploads = wp_upload_dir();
}
// Restore current blog if it was switched to other blog.
if ( ! empty( $rtmedia_activity[0]->blog_id ) ) {
restore_current_blog();
}

$baseurl = $uploads['baseurl'];

$thumbnail_url = '';
if ( 0 === strpos( $url, $uploads['baseurl'] ) ) {
$thumbnail_url = $url;
} else {
Expand Down
83 changes: 50 additions & 33 deletions app/main/controllers/template/rtmedia-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,18 +578,18 @@ function rtmedia_media( $size_flag = true, $echo = true, $media_size = 'rt_media
if ( isset( $rtmedia_media->media_type ) ) {

if ( 'photo' === $rtmedia_media->media_type ) {

$src = wp_get_attachment_image_src( $rtmedia_media->media_id, $media_size );

/**
* Used `set_url_scheme` because `esc_url` breaks the image if there is special characters are there into image name.
* Added by checking the code from "wp-admin/includes/media.php:2740".
* Because in media library, it was not breaking.
*
* Add timestamp to resolve conflict with cache image.
*/
$html = "<img src='" . set_url_scheme( $src[0] . '?' . time() ) . "' alt='" . esc_attr( $rtmedia_media->post_name ) . "' />";
if ( ! empty( $src[0] ) ) {
$src = rtmedia_append_timestamp_in_url( $src[0] );

/**
* Used `set_url_scheme` because `esc_url` breaks the image if there is special characters are there into image name.
* Added by checking the code from "wp-admin/includes/media.php:2740".
* Because in media library, it was not breaking.
*/
$html = "<img src='" . set_url_scheme( $src ) . "' alt='" . esc_attr( $rtmedia_media->post_name ) . "' />";
}
} elseif ( 'video' === $rtmedia_media->media_type ) {

$youtube_url = get_rtmedia_meta( $rtmedia_media->id, 'video_url_uploaded_from' );
Expand Down Expand Up @@ -746,9 +746,7 @@ function rtmedia_image( $size = 'rt_media_thumbnail', $id = false, $echo = true,
}

$src = apply_filters( 'rtmedia_media_thumb', $src, $media_object->id, $media_object->media_type );

// Added timestamp because conflict with cache image.
$src = $src . '?' . time();
$src = rtmedia_append_timestamp_in_url( $src );

if ( true === $echo ) {
echo wp_kses( set_url_scheme( $src ), RTMedia::expanded_allowed_tags() );
Expand All @@ -758,6 +756,24 @@ function rtmedia_image( $size = 'rt_media_thumbnail', $id = false, $echo = true,

}

/**
* Appends timestamp at the end of the URL to bypass cache and load fresh image.
*
* @param string $src Image URL.
*
* @return string Modified URL.
*/
function rtmedia_append_timestamp_in_url( $src ) {
$src_query = wp_parse_url( $src, PHP_URL_QUERY );
if ( empty( $src_query ) ) {
$src .= '?' . time();
} elseif ( false === strpos( $src, 'amazonaws.com' ) ) {
$src .= '&' . time();
}

return $src;
}

/**
* Get media alt
*
Expand Down Expand Up @@ -3121,22 +3137,22 @@ function rtmedia_who_like_html( $like_count = false, $user_like_it = false ) {
}

/**
* Get music cover art
* Get music cover art.
*
* @param object $media_object Media details object.
*
* @return bool|string
* @return string|bool Uploaded thumbnail URL | False.
*/
function rtm_get_music_cover_art( $media_object ) {

// return URL if cover_art already set.
// Return URL if cover_art already set.
$url = $media_object->cover_art;

if ( ! empty( $url ) && ! is_numeric( $url ) ) {
return $url;
}

// return false if covert_art is already analyzed earlier.
// Return false if covert_art is already analyzed earlier.
if ( -1 === intval( $url ) ) {
return false;
}
Expand All @@ -3147,25 +3163,25 @@ function rtm_get_music_cover_art( $media_object ) {
$media_tags = new RTMediaTags( $file );
$title_info = $media_tags->title;
$image_info = $media_tags->image;
$image_mime = $image_info['mime'];
$mime = explode( '/', $image_mime );
$id = $media_object->id;

if ( ! empty( $image_info['data'] ) ) {
if ( ! empty( $image_info['data'] ) && ! empty( $image_info['mime'] ) ) {
$mime = explode( '/', $image_info['mime'] );

$thumb_upload_info = wp_upload_bits( $title_info . '.' . $mime[ count( $mime ) - 1 ], null, $image_info['data'] );

if ( is_array( $thumb_upload_info ) && ! empty( $thumb_upload_info['url'] ) ) {
$media_obj->model->update(
array(
'cover_art' => $thumb_upload_info['url'],
),
array(
'id' => $id,
)
);
if ( ! empty( $mime ) && is_array( $mime ) ) {
$thumb_upload_info = wp_upload_bits( $title_info . '.' . $mime[ count( $mime ) - 1 ], null, $image_info['data'] );
if ( ! empty( $thumb_upload_info['url'] ) ) {
$media_obj->model->update(
array(
'cover_art' => $thumb_upload_info['url'],
),
array(
'id' => $id,
)
);

return $thumb_upload_info['url'];
return $thumb_upload_info['url'];
}
}
}

Expand All @@ -3179,7 +3195,6 @@ function rtm_get_music_cover_art( $media_object ) {
);

return false;

}

if ( ! function_exists( 'get_music_cover_art' ) ) {
Expand Down Expand Up @@ -3308,7 +3323,9 @@ function rtmedia_convert_date( $_date ) {
$no = $diff / $length[ $i ];
while ( $i >= 0 && $no <= 1 ) {
$i--;
$no = $diff / $length[ $i ];
if ( $i >= 0 ) {
$no = $diff / $length[ $i ];
}
}

if ( $i < 0 ) {
Expand Down
36 changes: 19 additions & 17 deletions app/main/controllers/upload/RTMediaUploadEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,23 +270,25 @@ public function template_redirect( $create_activity = true ) {
}
$obj_activity = new RTMediaActivity( $update_activity_media, $privacy, false );

global $wpdb, $bp;
$user = get_userdata( $same_medias[0]->media_author );
$username = '<a href="' . esc_url( get_rtmedia_user_link( $same_medias[0]->media_author ) ) . '">' . esc_html( $user->display_name ) . '</a>';

// translators: 1: Username, 2: Number of medias, 3: Media slug.
$action = sprintf( esc_html__( '%1$s added %2$d %3$s', 'buddypress-media' ), $username, count( $same_medias ), RTMEDIA_MEDIA_SLUG );
$action = apply_filters( 'rtmedia_buddypress_action_text_fitler_multiple_media', $action, $username, count( $same_medias ), $user->display_name );

$wpdb->update(
$bp->activity->table_name,
array(
'type' => 'rtmedia_update',
'content' => $obj_activity->create_activity_html(),
'action' => $action,
),
array( 'id' => $activity_id )
);
if ( ! empty( $same_medias[0] ) && ! empty( $activity_id ) ) {
global $wpdb, $bp;
$user = get_userdata( $same_medias[0]->media_author );
$username = '<a href="' . esc_url( get_rtmedia_user_link( $same_medias[0]->media_author ) ) . '">' . esc_html( $user->display_name ) . '</a>';

// translators: 1: Username, 2: Number of medias, 3: Media slug.
$action = sprintf( esc_html__( '%1$s added %2$d %3$s', 'buddypress-media' ), $username, count( $same_medias ), RTMEDIA_MEDIA_SLUG );
$action = apply_filters( 'rtmedia_buddypress_action_text_fitler_multiple_media', $action, $username, count( $same_medias ), $user->display_name );

$wpdb->update(
$bp->activity->table_name,
array(
'type' => 'rtmedia_update',
'content' => $obj_activity->create_activity_html(),
'action' => $action,
),
array( 'id' => $activity_id )
);
}
}

// update group last active.
Expand Down
Loading

0 comments on commit b0c1d80

Please sign in to comment.