Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/languages/buddyboss.pot
  • Loading branch information
eisenwasser committed Aug 10, 2020
2 parents 86a4db6 + b6cbeb1 commit 002116d
Show file tree
Hide file tree
Showing 22 changed files with 439 additions and 295 deletions.
2 changes: 1 addition & 1 deletion bp-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: The BuddyBoss Platform adds community features to WordPress. Member Profiles, Activity Feeds, Direct Messaging, Notifications, and more!
* Author: BuddyBoss
* Author URI: https://buddyboss.com/
* Version: 1.4.7
* Version: 1.4.8
* Text Domain: buddyboss
* Domain Path: /bp-languages/
* License: GPLv2 or later (license.txt)
Expand Down
14 changes: 7 additions & 7 deletions src/bp-activity/bp-activity-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -1625,12 +1625,12 @@ function bp_activity_has_media_activity_filter( $has_activities, $activities ) {
* @param $media
*/
function bp_activity_media_add( $media ) {
global $bp_media_upload_count, $bp_new_activity_comment;
global $bp_media_upload_count, $bp_new_activity_comment, $bp_activity_post_update_id, $bp_activity_post_update;

if ( ! empty( $media ) ) {
$parent_activity_id = false;
if ( isset( $_POST['bp_activity_update'] ) && isset( $_POST['bp_activity_id'] ) ) {
$parent_activity_id = (int) $_POST['bp_activity_id'];
if ( ! empty( $bp_activity_post_update ) && ! empty( $bp_activity_post_update_id ) ) {
$parent_activity_id = (int) $bp_activity_post_update_id;
}

if ( $bp_media_upload_count > 1 || ! empty( $bp_new_activity_comment ) ) {
Expand Down Expand Up @@ -1708,14 +1708,14 @@ function bp_activity_media_add( $media ) {
* @return mixed
*/
function bp_activity_create_parent_media_activity( $media_ids ) {
global $bp_media_upload_count;
global $bp_media_upload_count, $bp_activity_post_update, $bp_media_upload_activity_content;

if ( ! empty( $media_ids ) && ! isset( $_POST['bp_activity_update'] ) ) {
if ( ! empty( $media_ids ) && empty( $bp_activity_post_update ) ) {

$added_media_ids = $media_ids;
$content = false;

if ( ! empty( $_POST['content'] ) ) {
if ( ! empty( $bp_media_upload_activity_content ) ) {

/**
* Filters the content provided in the activity input field.
Expand All @@ -1725,7 +1725,7 @@ function bp_activity_create_parent_media_activity( $media_ids ) {
* @since BuddyPress 1.2.0
*
*/
$content = apply_filters( 'bp_activity_post_update_content', $_POST['content'] );
$content = apply_filters( 'bp_activity_post_update_content', $bp_media_upload_activity_content );
}

$group_id = FILTER_INPUT( INPUT_POST, 'group_id', FILTER_SANITIZE_NUMBER_INT );
Expand Down
2 changes: 1 addition & 1 deletion src/bp-core/bp-core-cssjs.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function bp_core_register_common_scripts() {
'dictDefaultMessage' => __( "Drop files here to upload", 'buddyboss' ),
'dictFallbackMessage' => __( "Your browser does not support drag'n'drop file uploads.", 'buddyboss' ),
'dictFallbackText' => __( "Please use the fallback form below to upload your files like in the olden days.", 'buddyboss' ),
'dictFileTooBig' => __( "File is too large ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.", 'buddyboss' ),
'dictFileTooBig' => __( "File is too large ({{filesize}} MB). Max filesize: {{maxFilesize}} MB.", 'buddyboss' ),
'dictInvalidFileType' => __( "You can't upload files of this type.", 'buddyboss' ),
'dictResponseError' => __( "Server responded with {{statusCode}} code.", 'buddyboss' ),
'dictCancelUpload' => __( "Cancel upload", 'buddyboss' ),
Expand Down
54 changes: 53 additions & 1 deletion src/bp-core/bp-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4847,4 +4847,56 @@ function bp_core_hide_display_name_field( $field_id = 0 ) {
* @param int $field_id ID for the profile field.
*/
return ( bool ) apply_filters( 'bp_core_hide_display_name_field', $retval, $field_id );
}
}

/**
* Return the file upload max size in bytes.
*
* @return mixed|void
*
* @since BuddyBoss 1.4.8
*/
function bp_core_upload_max_size() {

static $max_size = - 1;

if ( $max_size < 0 ) {
// Start with post_max_size.
$size = @ini_get( 'post_max_size' );
$unit = preg_replace( '/[^bkmgtpezy]/i', '', $size ); // Remove the non-unit characters from the size.
$size = preg_replace( '/[^0-9\.]/', '', $size ); // Remove the non-numeric characters from the size.
if ( $unit ) {
$post_max_size = round( $size * pow( 1024, stripos( 'bkmgtpezy', $unit[0] ) ) );
} else {
$post_max_size = round( $size );
}

if ( $post_max_size > 0 ) {
$max_size = $post_max_size;
}

// If upload_max_size is less, then reduce. Except if upload_max_size is
// zero, which indicates no limit.
$size = @ini_get( 'upload_max_filesize' );
$unit = preg_replace( '/[^bkmgtpezy]/i', '', $size ); // Remove the non-unit characters from the size.
$size = preg_replace( '/[^0-9\.]/', '', $size ); // Remove the non-numeric characters from the size.
if ( $unit ) {
$upload_max = round( $size * pow( 1024, stripos( 'bkmgtpezy', $unit[0] ) ) );
} else {
$upload_max = round( $size );
}
if ( $upload_max > 0 && $upload_max < $max_size ) {
$max_size = $upload_max;
}
}

/**
* Filters file upload max limit.
*
* @param mixed $max_size file upload max limit.
*
* @since BuddyBoss 1.4.8
*/
return apply_filters( 'bp_core_upload_max_size', $max_size );

}
45 changes: 10 additions & 35 deletions src/bp-document/bp-document-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,40 +259,16 @@ function bp_document_folder_add_meta( $folder_id, $meta_key, $meta_value, $uniqu
* @return string
* @since BuddyBoss 1.4.0
*/
function bp_document_file_upload_max_size( $post_string = false, $type = 'bytes' ) {
static $max_size = - 1;

if ( $max_size < 0 ) {
// Start with post_max_size.
$size = @ini_get( 'post_max_size' );
$unit = preg_replace( '/[^bkmgtpezy]/i', '', $size ); // Remove the non-unit characters from the size.
$size = preg_replace( '/[^0-9\.]/', '', $size ); // Remove the non-numeric characters from the size.
if ( $unit ) {
$post_max_size = round( $size * pow( 1024, stripos( 'bkmgtpezy', $unit[0] ) ) );
} else {
$post_max_size = round( $size );
}

if ( $post_max_size > 0 ) {
$max_size = $post_max_size;
}

// If upload_max_size is less, then reduce. Except if upload_max_size is
// zero, which indicates no limit.
$size = @ini_get( 'upload_max_filesize' );
$unit = preg_replace( '/[^bkmgtpezy]/i', '', $size ); // Remove the non-unit characters from the size.
$size = preg_replace( '/[^0-9\.]/', '', $size ); // Remove the non-numeric characters from the size.
if ( $unit ) {
$upload_max = round( $size * pow( 1024, stripos( 'bkmgtpezy', $unit[0] ) ) );
} else {
$upload_max = round( $size );
}
if ( $upload_max > 0 && $upload_max < $max_size ) {
$max_size = $upload_max;
}
}
function bp_document_file_upload_max_size() {

return apply_filters( 'bp_document_file_upload_max_size', bp_document_format_size_units( $max_size, $post_string, $type ) );
/**
* Filters doucment file upload max limit.
*
* @param mixed $max_size document upload max limit.
*
* @since BuddyBoss 1.4.0
*/
return apply_filters( 'bp_document_file_upload_max_size', bp_media_allowed_upload_document_size() );
}

/**
Expand Down Expand Up @@ -1399,8 +1375,7 @@ function bp_document_upload_handler( $file_id = 'file' ) {
'test_form' => false,
'upload_error_strings' => array(
false,
__( 'The uploaded file exceeds ', 'buddyboss' ) . bp_document_file_upload_max_size( true ),
__( 'The uploaded file exceeds ', 'buddyboss' ) . bp_document_file_upload_max_size( true ),
__( 'The uploaded file exceeds ', 'buddyboss' ) . bp_document_file_upload_max_size(),
__( 'The uploaded file was only partially uploaded.', 'buddyboss' ),
__( 'No file was uploaded.', 'buddyboss' ),
'',
Expand Down
4 changes: 2 additions & 2 deletions src/bp-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: The BuddyBoss Platform adds community features to WordPress. Member Profiles, Activity Feeds, Direct Messaging, Notifications, and more!
* Author: BuddyBoss
* Author URI: https://buddyboss.com/
* Version: 1.4.7
* Version: 1.4.8
* Text Domain: buddyboss
* Domain Path: /languages/
* License: GPLv2 or later (license.txt)
Expand All @@ -21,7 +21,7 @@


if ( ! defined( 'BP_PLATFORM_VERSION' ) ) {
define( 'BP_PLATFORM_VERSION', '1.4.7' );
define( 'BP_PLATFORM_VERSION', '1.4.8' );
}

if ( ! defined( 'BP_PLATFORM_API' ) ) {
Expand Down
15 changes: 7 additions & 8 deletions src/bp-media/bp-media-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,13 @@ function bp_media_activity_comment_entry( $comment_id ) {
* @return bool
*/
function bp_media_update_activity_media_meta( $content, $user_id, $activity_id ) {

global $bp_activity_post_update, $bp_activity_post_update_id;
if ( ! isset( $_POST['media'] ) || empty( $_POST['media'] ) ) {
return false;
}

$_POST['medias'] = $_POST['media'];
$_POST['bp_activity_update'] = true;
$_POST['bp_activity_id'] = $activity_id;
$bp_activity_post_update = true;
$bp_activity_post_update_id = $activity_id;

// Update activity comment attached document privacy with parent one.
if ( ! empty( $activity_id ) && isset( $_POST['action'] ) && $_POST['action'] === 'new_activity_comment' ) {
Expand All @@ -319,7 +318,7 @@ function bp_media_update_activity_media_meta( $content, $user_id, $activity_id )
remove_action( 'bp_activity_comment_posted', 'bp_media_activity_comments_update_media_meta', 10, 3 );
remove_action( 'bp_activity_comment_posted_notification_skipped', 'bp_media_activity_comments_update_media_meta', 10, 3 );

$media_ids = bp_media_add_handler();
$media_ids = bp_media_add_handler( $_POST['media'], $_POST['privacy'] );

add_action( 'bp_activity_posted_update', 'bp_media_update_activity_media_meta', 10, 3 );
add_action( 'bp_groups_posted_update', 'bp_media_groups_activity_update_media_meta', 10, 4 );
Expand Down Expand Up @@ -681,7 +680,7 @@ function bp_media_attach_media_to_message( &$message ) {
remove_action( 'bp_media_add', 'bp_activity_media_add', 9 );
remove_filter( 'bp_media_add_handler', 'bp_activity_create_parent_media_activity', 9 );

$media_ids = bp_media_add_handler( $_POST['media'] );
$media_ids = bp_media_add_handler( $_POST['media'], 'message' );

add_action( 'bp_media_add', 'bp_activity_media_add', 9 );
add_filter( 'bp_media_add_handler', 'bp_activity_create_parent_media_activity', 9 );
Expand Down Expand Up @@ -901,7 +900,7 @@ function bp_media_activity_save_gif_data( $activity ) {
}

function bp_media_get_tools_media_settings_admin_tabs( $tabs ) {

$tabs[] = array(
'href' => bp_get_admin_url( add_query_arg( array(
'page' => 'bp-media-import',
Expand Down Expand Up @@ -1912,4 +1911,4 @@ function bp_media_activity_after_email_content( $activity ) {
);
echo wpautop( $content );
}
}
}
67 changes: 23 additions & 44 deletions src/bp-media/bp-media-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ function bp_media_upload_handler( $file_id = 'file' ) {
'test_form' => false,
'upload_error_strings' => array(
false,
__( 'The uploaded file exceeds ', 'buddyboss' ) . bp_media_file_upload_max_size( true ),
__( 'The uploaded file exceeds ', 'buddyboss' ) . bp_media_file_upload_max_size( true ),
__( 'The uploaded file exceeds ', 'buddyboss' ) . bp_media_file_upload_max_size(),
__( 'The uploaded file was only partially uploaded.', 'buddyboss' ),
__( 'No file was uploaded.', 'buddyboss' ),
'',
Expand Down Expand Up @@ -184,40 +183,16 @@ function bp_media_compress_image( $source, $destination, $quality = 90 ) {
*
* @return string
*/
function bp_media_file_upload_max_size( $post_string = false, $type = 'bytes' ) {
static $max_size = - 1;

if ( $max_size < 0 ) {
// Start with post_max_size.
$size = @ini_get( 'post_max_size' );
$unit = preg_replace( '/[^bkmgtpezy]/i', '', $size ); // Remove the non-unit characters from the size.
$size = preg_replace( '/[^0-9\.]/', '', $size ); // Remove the non-numeric characters from the size.
if ( $unit ) {
$post_max_size = round( $size * pow( 1024, stripos( 'bkmgtpezy', $unit[0] ) ) );
} else {
$post_max_size = round( $size );
}

if ( $post_max_size > 0 ) {
$max_size = $post_max_size;
}
function bp_media_file_upload_max_size() {

// If upload_max_size is less, then reduce. Except if upload_max_size is
// zero, which indicates no limit.
$size = @ini_get( 'upload_max_filesize' );
$unit = preg_replace( '/[^bkmgtpezy]/i', '', $size ); // Remove the non-unit characters from the size.
$size = preg_replace( '/[^0-9\.]/', '', $size ); // Remove the non-numeric characters from the size.
if ( $unit ) {
$upload_max = round( $size * pow( 1024, stripos( 'bkmgtpezy', $unit[0] ) ) );
} else {
$upload_max = round( $size );
}
if ( $upload_max > 0 && $upload_max < $max_size ) {
$max_size = $upload_max;
}
}

return apply_filters( 'bp_media_file_upload_max_size', bp_media_format_size_units( $max_size, $post_string, $type ) );
/**
* Filters file media upload max limit.
*
* @param mixed $max_size media upload max limit.
*
* @since BuddyBoss 1.4.1
*/
return apply_filters( 'bp_media_file_upload_max_size', bp_media_allowed_upload_media_size() );
}

/**
Expand Down Expand Up @@ -504,33 +479,37 @@ function bp_media_add( $args = '' ) {
* Media add handler function
*
* @since BuddyBoss 1.2.0
*
* @param array $medias
* @param string $privacy
* @param string $content
* @param int $group_id
* @param int $album_id
*
* @return mixed|void
*/
function bp_media_add_handler( $medias = array() ) {
global $bp_media_upload_count;
function bp_media_add_handler( $medias = array(), $privacy = 'public', $content = '', $group_id = false, $album_id = false ) {
global $bp_media_upload_count, $bp_media_upload_activity_content;
$media_ids = array();

if ( empty( $medias ) && ! empty( $_POST['medias'] ) ) {
$medias = $_POST['medias'];
}

$privacy = ! empty( $_POST['privacy'] ) && in_array( $_POST['privacy'], array_keys( bp_media_get_visibility_levels() ) ) ? $_POST['privacy'] : 'public';
$privacy = in_array( $privacy, array_keys( bp_media_get_visibility_levels() ) ) ? $privacy : 'public';

if ( ! empty( $medias ) && is_array( $medias ) ) {

// update count of media for later use.
$bp_media_upload_count = count( $medias );

// update the content of medias for later use.
$bp_media_upload_activity_content = $content;

// save media.
foreach ( $medias as $media ) {

$media_id = bp_media_add( array(
'attachment_id' => $media['id'],
'title' => $media['name'],
'album_id' => ! empty( $media['album_id'] ) ? $media['album_id'] : false,
'group_id' => ! empty( $media['group_id'] ) ? $media['group_id'] : false,
'album_id' => ! empty( $media['album_id'] ) ? $media['album_id'] : $album_id,
'group_id' => ! empty( $media['group_id'] ) ? $media['group_id'] : $group_id,
'privacy' => ! empty( $media['privacy'] ) && in_array( $media['privacy'], array_merge( array_keys( bp_media_get_visibility_levels() ), array( 'message' ) ) ) ? $media['privacy'] : $privacy,
) );

Expand Down
Loading

0 comments on commit 002116d

Please sign in to comment.