Skip to content

Commit

Permalink
Merge pull request #2032 from rtCamp/feature/allow_media_upload_witho…
Browse files Browse the repository at this point in the history
…ut_text_in_activity

Enhance activity post media experience.
  • Loading branch information
Utsav-Ladani authored Jan 2, 2024
2 parents 44a673e + da73b7e commit cbf23e7
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 30 deletions.
17 changes: 2 additions & 15 deletions app/assets/js/rtMedia.backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1432,10 +1432,7 @@ jQuery( document ).ready( function( $ ) {
* By: Yahil
*/
if ( '' === jQuery( '#whats-new' ).val().trim() ) {
if ( rtmedia_activity_text_with_attachment == 'disable' ) {
$( '#whats-new' ).css( 'color', 'transparent' );
$( '#whats-new' ).val( ' ' );
} else {
if ( rtmedia_activity_text_with_attachment != 'disable' ) {
jQuery('#whats-new-form').prepend('<div id="message" class="error bp-ajax-message" style="display: block;"><p> ' + rtmedia_empty_activity_msg + ' </p></div>')
jQuery( '#whats-new' ).removeAttr( 'disabled' );
return false;
Expand Down Expand Up @@ -1588,13 +1585,6 @@ jQuery( document ).ready( function( $ ) {
* Blank error display issue resolved
*/
if ( bp_template_pack && 'legacy' !== bp_template_pack ) {

if ( 'disable' === rtmedia_activity_text_with_attachment && '' === jQuery.trim( jQuery( '#whats-new' ).val() ) ) {
let textarea = jQuery( '#whats-new' );
textarea.css( 'color', 'transparent' );
textarea.val( ' ' );
}

jQuery( '#whats-new-form' ).submit();
} else {
jQuery( '#aw-whats-new-submit' ).click();
Expand Down Expand Up @@ -1692,10 +1682,7 @@ jQuery( document ).ready( function( $ ) {
* By: Yahil
*/

if ( rtmedia_activity_text_with_attachment == 'disable') {
$( "#whats-new" ).css( 'color', 'transparent' );
$( "#whats-new" ).val( '&nbsp;' );
} else {
if ( rtmedia_activity_text_with_attachment != 'disable') {
jQuery('#whats-new-form').prepend('<div id="message" class="error bp-ajax-message" style="display: block;"><p> ' + rtmedia_empty_activity_msg + ' </p></div>')
jQuery( '#whats-new' ).removeAttr( 'disabled' );
return false;
Expand Down
3 changes: 2 additions & 1 deletion app/main/RTMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,9 @@ public function init() {

$this->set_allowed_types(); // Define allowed types.

global $rtmedia_buddypress_activity;
global $rtmedia_buddypress_activity, $rtmedia_buddypress_group_activity;
$rtmedia_buddypress_activity = new RTMediaBuddyPressActivity();
$rtmedia_buddypress_group_activity = new RTMediaBuddyPressGroupActivity();
$media = new RTMediaMedia();
$media->delete_hook();

Expand Down
25 changes: 25 additions & 0 deletions app/main/controllers/activity/RTMediaBuddyPressActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public function __construct() {
add_filter( 'bea_get_activity_content', array( $this, 'rtm_edit_activity_filter' ) );
add_filter( 'bea_activity_content', array( $this, 'rtm_save_activity_with_media_filter' ), 10, 2 );
}

// Allow only media uploading without text in activity.
add_filter( 'bp_before_activity_post_update_parse_args', array( $this, 'bp_before_activity_post_update_parse_args' ) );
}

/**
Expand Down Expand Up @@ -1473,4 +1476,26 @@ public function rtm_save_activity_with_media_filter( $content_new, $activity_id
}
return $content;
}


/**
* Filter content before processing in activity.
* It adds the '&nbsp;' if content is empty, when we are only uploading media from activity.
*
* @param array $args Activity arguments.
*
* @return array
*/
public function bp_before_activity_post_update_parse_args( $args ) {
// if content is non-breaking space then set it to empty.
if ( isset( $args['content'] ) && '' === $args['content'] ) {

// Nonce verification is not required here as it is already done in previously.
if ( ! empty( $_POST['rtMedia_attached_files'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
$args['content'] = '&nbsp;';
}
}

return $args;
}
}
43 changes: 43 additions & 0 deletions app/main/controllers/group/RTMediaBuddyPressGroupActivity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Handle/change BuddyPress group activities behaviour.
*
* @package rtMedia
*/

/**
* Class to handle/change BuddyPress group activities behaviour.
*
* @author utsavladani
*/
class RTMediaBuddyPressGroupActivity {

/**
* RTMediaBuddyPressGroupActivity constructor.
*/
public function __construct() {
// Allow only media uploading without text in activity.
add_filter( 'bp_before_groups_post_update_parse_args', array( $this, 'bp_before_groups_post_update_parse_args' ) );
}

/**
* Filter content before processing in group activity.
* It adds the '&nbsp;' if content is empty, when we are only uploading media from activity.
*
* @param array $args Activity arguments.
*
* @return array
*/
public function bp_before_groups_post_update_parse_args( $args ) {
// if content is non-breaking space then set it to empty.
if ( isset( $args['content'] ) && '' === $args['content'] ) {

// Nonce verification is not required here as it is already done in previously.
if ( ! empty( $_POST['rtMedia_attached_files'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
$args['content'] = '&nbsp;';
}
}

return $args;
}
}
28 changes: 14 additions & 14 deletions languages/buddypress-media.po
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright (C) 2023 rtCamp
# Copyright (C) 2024 rtCamp
# This file is distributed under the same license as the rtMedia for WordPress, BuddyPress and bbPress package.
msgid ""
msgstr ""
"Project-Id-Version: rtMedia for WordPress, BuddyPress and bbPress 4.6.17\n"
"Report-Msgid-Bugs-To: https://rtmedia.io/support/\n"
"POT-Creation-Date: 2023-12-28 10:36:32+00:00\n"
"POT-Creation-Date: 2024-01-02 06:22:56+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2023-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: 2024-MO-DA HO:MI+ZONE\n"
"Last-Translator: rtMedia <[email protected]>\n"
"Language-Team: rtMedia <[email protected]>\n"
"Language: en\n"
Expand Down Expand Up @@ -2312,7 +2312,7 @@ msgid "rtMedia: Import Media Size"
msgstr ""

#: app/main/RTMedia.php:163 app/main/RTMedia.php:1530 app/main/RTMedia.php:1623
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:760
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:763
#: app/main/controllers/shortcodes/RTMediaGalleryShortcode.php:113
#: app/main/controllers/upload/processors/RTMediaUploadFile.php:246
msgid "Media Files"
Expand Down Expand Up @@ -2581,61 +2581,61 @@ msgstr ""
msgid "Adding media in Comments is not allowed"
msgstr ""

#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:490
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:493
#: app/main/controllers/upload/RTMediaUploadEndpoint.php:60
#: app/main/controllers/upload/RTMediaUploadEndpoint.php:74
msgid "Terms and Conditions checkbox not found!"
msgstr ""

#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:819
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:822
#: app/main/controllers/media/RTMediaComment.php:219
#: app/main/controllers/shortcodes/RTMediaUploadShortcode.php:135
#: app/main/controllers/template/rtmedia-functions.php:2265
msgid "You are not allowed to upload/attach media."
msgstr ""

#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:975
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:978
#: app/main/controllers/media/RTMediaMedia.php:797
#. translators: 1: user link, 2: media.
#. translators: 1: username, 2: media type, 3: media name, 4: total media.
msgid "%1$s added a %2$s"
msgstr ""

#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:982
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:985
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:988
#: app/main/controllers/upload/RTMediaUploadEndpoint.php:283
#. translators: 1: user link, 2: media count, 3: media.
#. translators: 1: user link, 2: media count, 3: rtMedia slug.
#. translators: 1: Username, 2: Number of medias, 3: Media slug.
msgid "%1$s added %2$d %3$s"
msgstr ""

#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1057
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1060
#. translators: 1: username, 2: media, 3: group name.
msgid "%1$s liked a %2$s in the group %3$s"
msgstr ""

#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1060
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1063
#. translators: 1: username, 2: media.
msgid "%1$s liked their %2$s"
msgstr ""

#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1069
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1072
#. translators: 1: username, 2: author, 3: media.
msgid "%1$s liked %2$s's %3$s"
msgstr ""

#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1178
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1181
#. translators: 1: username, 2: media, 3: group name.
msgid "%1$s commented on a %2$s in the group %3$s"
msgstr ""

#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1181
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1184
#. translators: 1: username, 2: media.
msgid "%1$s commented on their %2$s"
msgstr ""

#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1190
#: app/main/controllers/activity/RTMediaBuddyPressActivity.php:1193
#. translators: 1: username, 2: author, 3: media.
msgid "%1$s commented on %2$s's %3$s"
msgstr ""
Expand Down

0 comments on commit cbf23e7

Please sign in to comment.