Skip to content

Commit

Permalink
Merge pull request #1561 from rtMediaWP/develop
Browse files Browse the repository at this point in the history
Version update v4.6.0
  • Loading branch information
thrijith authored Feb 17, 2020
2 parents 74b9721 + 5244101 commit 7ab210f
Show file tree
Hide file tree
Showing 95 changed files with 1,560 additions and 876 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ https://www.youtube.com/watch?v=dJrykKQGDcs

## Changelog ##

### 4.6.0 [February 17, 2020] ###

* Enhancement
* Show long text truncated with read more option and image displayed below the truncated text on activity

* FIXED
* Error uploading media in comments with Kleo theme
* JavaScript errors
* Album styling when masonry style is disabled
* The template loaded on media page when nouveau template is set
* Compatibility issues with PHP 7.4.1
* UI related bugs
* Notices and Warnings

### 4.5.11 [December 26, 2019] ###

* Enhancement
Expand Down Expand Up @@ -1648,8 +1662,8 @@ https://www.youtube.com/watch?v=dJrykKQGDcs
* HTML5 Audio Tag Support (with fallback)
* HTML5 Video Tag Support (with fallback)

#### 4.5.11 ####
rtMedia 4.5.11, with improved styling for albums and improved UX on BuddyPress Activity Wall.
#### 4.6.0 ####
rtMedia 4.6.0, with improved activity content preview and JavaScript and Nouveau template related fixes.

## Sponsors ##

Expand Down
11 changes: 10 additions & 1 deletion app/assets/css/rtmedia.css
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ button#rtmedia-add-media-button-post-update .dashicons {
.rtm-form .rtm-field-wrap {
margin-bottom: 20px;
}
.rtm-form .rtm-field-wrap .rtmedia-title-editor {
width: 100%;
}

#buddypress a.rtm-button-back {
padding: 3px 10px;
Expand Down Expand Up @@ -651,7 +654,12 @@ input.imgedit-submit-btn {
}
.rtm-tabs a {
border: 0;
display: block;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 5px 15px;
text-decoration: none;
}
Expand Down Expand Up @@ -1919,6 +1927,7 @@ a.rtmedia-comment-link.rtmedia-comments-link {
border: 1px solid #ddd;
padding: 5px;
border-radius: 5px;
width: auto;
}

/*------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/assets/css/rtmedia.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/assets/css/sass/_album.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
border: 1px solid #ddd;
padding: 5px;
border-radius: 5px;
width: auto;
}
}
}
4 changes: 4 additions & 0 deletions app/assets/css/sass/_rtm.scss
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ button#rtmedia-add-media-button-post-update {
.rtm-form {
.rtm-field-wrap {
margin-bottom: 20px;

.rtmedia-title-editor {
width: 100%;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/assets/css/sass/_tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

a {
border: 0;
display: block;
display: flex;
align-items: center;
padding: 5px 15px;
text-decoration: none; //2012

Expand Down
8 changes: 4 additions & 4 deletions app/assets/js/rtMedia.backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2443,7 +2443,7 @@ function renderUploadercomment_media( widget_id, parent_id_type ) {
jQuery( input_file_el ).click();
file_dialog_open = false;
}
$(this).blur();
jQuery(this).blur();
} );

var form_html = jQuery( "."+comment_media_wrapper+widget_id );
Expand Down Expand Up @@ -2621,15 +2621,15 @@ function renderUploadercomment_media( widget_id, parent_id_type ) {

if ( 'undefined' != typeof rtmedia_direct_upload_enabled && '1' == rtmedia_direct_upload_enabled ) {

$( '.rtmedia-comment-media-submit-' + widget_id ).focus();
jQuery( '.rtmedia-comment-media-submit-' + widget_id ).focus();
/* when direct upload is enable */
jQuery( '.'+rtmedia_comment_media_submit+widget_id ).trigger( 'click' );
}

/**
* Uploader improper enter behavior issue(124) fixed
*/
$('.rtmedia-comment-media-submit-'+widget_id).focus();
jQuery('.rtmedia-comment-media-submit-'+widget_id).focus();
/**
* End of issue 124
*/
Expand Down Expand Up @@ -2739,7 +2739,7 @@ function renderUploadercomment_media( widget_id, parent_id_type ) {
'class': 'plupload_file_progress ui-widget-header',
});
progressBar.css( 'width', file.percent + '%' );
$( '#' + file.id + ' .plupload_file_status' ).html( progressBar );
jQuery( '#' + file.id + ' .plupload_file_status' ).html( progressBar );
// filter to customize existing progress bar can be used to display
// '%' of upload completed.
rtMediaHook.call( 'rtm_custom_progress_bar_content', [ file ] );
Expand Down
2 changes: 1 addition & 1 deletion app/assets/js/rtm-upload-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if ( 'object' === typeof rtMediaHook ) {
});

rtMediaHook.register( 'rtmedia_js_after_activity_added', function() {
var rtmedia_terms_conditions = $( '#rtmedia_upload_terms_conditions' );
var rtmedia_terms_conditions = jQuery( '#rtmedia_upload_terms_conditions' );
if ( rtmedia_terms_conditions && rtmedia_terms_conditions.is(':checked') ) {
rtmedia_terms_conditions.prop( 'checked', false );
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/js/rtm-upload-terms.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 1 addition & 16 deletions app/main/RTMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public function init_site_options() {
break;
case 'video':
case 'music':
$old = ( 'video' === $type ) ? 'video' : ( 'music' === $type ) ? 'audio' : '';
$old = ( 'video' === $type ) ? 'video' : ( ( 'music' === $type ) ? 'audio' : '' );
switch ( $size ) {
case 'activityPlayer':
if ( isset( $bp_media_options['sizes'][ $old ]['medium'][ $dimension ] ) && ! empty( $bp_media_options['sizes'][ $old ]['medium'][ $dimension ] ) ) {
Expand Down Expand Up @@ -1337,21 +1337,6 @@ function enqueue_scripts_styles() {
if ( empty( $is_buddypress_activate ) ) {
wp_localize_script( 'rtmedia-main', 'ajaxurl', admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' ) );
}

// Only Applay if BP Template Nouveau is activate.
if ( ! empty( $bp_template ) && 'nouveau' === $bp_template && ( 'group' === $rtmedia_interaction->context->type || 'profile' === $rtmedia_interaction->context->type ) ) {
$rtmedia_router = new RTMediaRouter();
if ( ! empty( $rtmedia_router->query_vars ) ) {
$wp_current_stylesheet = get_stylesheet();

// If file is already exists in buddypress then enqueue it.
if ( file_exists( sprintf( '%sbp-templates/bp-legacy/css/%s.min.css', BP_PLUGIN_DIR, $wp_current_stylesheet ) ) ) {
wp_enqueue_style( 'bp-nouveau-stylesheet-theme', BP_PLUGIN_URL . 'bp-templates/bp-legacy/css/' . $wp_current_stylesheet . '.min.css' );
}

wp_enqueue_style( 'bp-nouveau-stylesheet-buddypress', BP_PLUGIN_URL . 'bp-templates/bp-legacy/css/buddypress.min.css', '' );
}
}
}

function set_bp_bar() {
Expand Down
170 changes: 170 additions & 0 deletions app/main/controllers/activity/RTMediaBuddyPressActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ function __construct() {
// manage user's last activity update.
add_action( 'bp_activity_posted_update', array( &$this, 'manage_user_last_activity_update' ), 999, 3 );
add_action( 'bp_groups_posted_update', array( &$this, 'bp_groups_posted_update' ), 99, 4 );

/**
* Filter to disable bp_activity_truncate_entry override function.
*
* @param boolean By default its enabled.
*/
if ( apply_filters( 'rtmedia_disable_truncate_entry_override', true ) ) {
// Code to show media with read more option.
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 );
Expand Down Expand Up @@ -64,6 +74,166 @@ function __construct() {
}
}

/**
* Show media even if the text is long with read more option.
*
* @param string $excerpt Excerpt of the activity text.
* @param string $text Actual text of activity.
* @param string $readmore Read more text.
*
* @return string Custom excerpt if conditions are match.
*/
public function bp_activity_truncate_entry( $excerpt, $text, $readmore ) {
// Return if class doesn't exist.
if ( ! class_exists( 'DOMDocument' ) ) {
return $excerpt;
}

global $activities_template;

$excerpt_length = bp_activity_get_excerpt_length();
// Run the text through the excerpt function. If it's too short, the original text will be returned.
$temp_excerpt = bp_create_excerpt( $text, $excerpt_length, array() );
if ( strlen( $temp_excerpt ) >= strlen( strip_shortcodes( $text ) ) ) {
return $excerpt;
}

// Get current activity id.
$activity_id = bp_get_activity_id();

// We need to separate text and rtMedia images, for this we need DOM manipulation.
$dom = new DOMDocument();
// DOMDocument gives error on html5 tags, so we need to disable errors.
libxml_use_internal_errors( true );
$dom->loadHTML( $text );
// DOMDocument gives error on html5 tags, so we need to disable errors.
libxml_clear_errors();
// We need to find div having rtmedia-activity-text class, but no direct method for it.
// So we need to iterate.
$div_list = $dom->getElementsByTagName( 'div' );

// Return if no divs found.
if ( empty( $div_list ) ) {
return $excerpt;
}

// We're storing first div to create final markup.
// If we create markup from dom object, it'll create whole HTML which we don't want.
$first_div = '';

foreach ( $div_list as $div ) {
// Set first div.
if ( empty( $first_div ) ) {
$first_div = $div;
}

// We need div with class attribute.
if ( empty( $div->attributes ) ) {
continue;
}

$atts = $div->attributes;
// Check attributes by iterating them.
foreach ( $atts as $att ) {
if ( empty( $att->name ) || empty( $att->value ) ) {
continue;
}

// Condition to find text div.
if ( 'class' === $att->name && strpos( $att->value, 'rtmedia-activity-text' ) !== false ) {
// Create excerpt only on text and then set it to div text.
// We're using actual length / 2 to make space for image.
$custom_excerpt = bp_create_excerpt( $div->textContent, (int) $excerpt_length / 2, array( 'ending' => '...' ) ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Can't change property name.
$div->textContent = trim( $custom_excerpt ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Can't change property name.

// Show 4 images if text is less, else show 2 images.
$images_to_show = 4;
if ( strlen( $div->textContent ) > 20 ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Can't change property name.
$images_to_show = 2;
}

// Set number of images to show in excerpt.
$dom = $this->get_bp_activity_media_html( $dom, $images_to_show );

// Code copied from buddypress.
$id = ( ! empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . $activity_id );

// Get final HTML.
$content = $first_div->ownerDocument->saveHTML( $first_div ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Can't change property name.

// Append read more link and text.
$return = sprintf( '%1$s<span class="activity-read-more" id="%2$s"><a href="%3$s" rel="nofollow">%4$s</a></span>', $content, $id, bp_get_activity_thread_permalink(), $readmore );

return $return;
}
}
}

return $excerpt;
}

/**
* Set number of images to show in activity excerpt.
*
* @param object $dom DOMDocument object for DOM manipulation.
* @param int $images_to_show Number of images to show.
*
* @return object Modified DOMDocument object.
*/
private function get_bp_activity_media_html( $dom, $images_to_show ) {
// Get media list which is inside <ul>.
$ul_list = $dom->getElementsByTagName( 'ul' );

// Return if no ul element.
if ( empty( $ul_list ) ) {
return $dom;
}

// Iterate to find out media-list ul.
foreach ( $ul_list as $ul ) {
// We need ul having class 'rtm-activity-media-list'.
if ( empty( $ul->attributes ) ) {
continue;
}

// Iterate attributes.
foreach ( $ul->attributes as $att ) {
if ( empty( $att->name ) || empty( $att->value ) ) {
continue;
}

// Conditions to match required class.
if ( 'class' === $att->name && strpos( $att->value, 'rtm-activity-media-list' ) !== false && count( $ul->childNodes ) > 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Can't change property name.

// Number of li (images) allowed to show.
$count = 1;
// Array where items to remove will be stored.
$items_to_remove = array();
// Iterate all children of ul which are images (li).
foreach ( $ul->childNodes as $li ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Can't change property name.

// If max number of images reached, add li to items_to_remove array.
if ( $count > $images_to_show ) {
$items_to_remove[] = $li;
}

$count++;
}

// Remove images.
foreach ( $items_to_remove as $item ) {
$ul->removeChild( $item );
}

return $dom;
}
}
}

return $dom;
}


/**
* For adding secondary avatar in the activity header.
*
Expand Down
Loading

0 comments on commit 7ab210f

Please sign in to comment.