diff --git a/bp-loader.php b/bp-loader.php index d24215e820..8564012122 100644 --- a/bp-loader.php +++ b/bp-loader.php @@ -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) diff --git a/src/bp-activity/bp-activity-filters.php b/src/bp-activity/bp-activity-filters.php index b2232431c3..2838b7f546 100644 --- a/src/bp-activity/bp-activity-filters.php +++ b/src/bp-activity/bp-activity-filters.php @@ -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 ) ) { @@ -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. @@ -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 ); diff --git a/src/bp-core/bp-core-cssjs.php b/src/bp-core/bp-core-cssjs.php index 4109526233..34ecbbf66d 100644 --- a/src/bp-core/bp-core-cssjs.php +++ b/src/bp-core/bp-core-cssjs.php @@ -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' ), diff --git a/src/bp-core/bp-core-functions.php b/src/bp-core/bp-core-functions.php index 0aa9abb97c..467df36f96 100644 --- a/src/bp-core/bp-core-functions.php +++ b/src/bp-core/bp-core-functions.php @@ -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 ); -} \ No newline at end of file +} + +/** + * 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 ); + +} diff --git a/src/bp-document/bp-document-functions.php b/src/bp-document/bp-document-functions.php index 73f43583c6..399b171b03 100644 --- a/src/bp-document/bp-document-functions.php +++ b/src/bp-document/bp-document-functions.php @@ -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() ); } /** @@ -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' ), '', diff --git a/src/bp-loader.php b/src/bp-loader.php index eb118f826e..8676db7def 100644 --- a/src/bp-loader.php +++ b/src/bp-loader.php @@ -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) @@ -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' ) ) { diff --git a/src/bp-media/bp-media-filters.php b/src/bp-media/bp-media-filters.php index 4f4c65de28..42078b95c0 100644 --- a/src/bp-media/bp-media-filters.php +++ b/src/bp-media/bp-media-filters.php @@ -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' ) { @@ -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 ); @@ -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 ); @@ -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', @@ -1912,4 +1911,4 @@ function bp_media_activity_after_email_content( $activity ) { ); echo wpautop( $content ); } -} \ No newline at end of file +} diff --git a/src/bp-media/bp-media-functions.php b/src/bp-media/bp-media-functions.php index 76ef908d9e..2a6cef74c4 100644 --- a/src/bp-media/bp-media-functions.php +++ b/src/bp-media/bp-media-functions.php @@ -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' ), '', @@ -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() ); } /** @@ -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, ) ); diff --git a/src/bp-media/bp-media-settings.php b/src/bp-media/bp-media-settings.php index 6e7a5aea8c..a9beb4dde4 100644 --- a/src/bp-media/bp-media-settings.php +++ b/src/bp-media/bp-media-settings.php @@ -233,6 +233,20 @@ function bp_media_get_settings_fields() { ); } + $fields['bp_media_settings_photos']['bp_media_allowed_size'] = array( + 'title' => __( 'Upload Size', 'buddyboss' ), + 'callback' => 'bp_media_settings_callback_media_allowed_size', + 'sanitize_callback' => 'absint', + 'args' => array(), + ); + + $fields['bp_media_settings_documents']['bp_document_allowed_size'] = array( + 'title' => __( 'Upload Size', 'buddyboss' ), + 'callback' => 'bp_media_settings_callback_document_allowed_size', + 'sanitize_callback' => 'absint', + 'args' => array(), + ); + $fields['bp_media_settings_documents']['bp_media_extension_document_support'] = array( 'title' => __( 'File Extensions', 'buddyboss' ), 'callback' => 'bp_media_settings_callback_extension_link', @@ -1344,3 +1358,95 @@ function bp_document_settings_callback_extension_section() {

Media > Photos > Allowed Max File Size + * + * @since BuddyBoss 1.4.8 + */ +function bp_media_settings_callback_media_allowed_size() { + $max_size = bp_core_upload_max_size(); + $max_size_mb = bp_media_format_size_units( $max_size, false, 'MB' ); + ?> + +

+ %2$s %3$s', + __( 'Set a maximum file size for photo uploads, in megabytes. Your server\'s maximum upload size is ', 'buddyboss' ), + $max_size_mb, + 'MB.' + ); + ?> +

+ Media > Documents > Allowed Max File Size + * + * @since BuddyBoss 1.4.8 + */ +function bp_media_settings_callback_document_allowed_size() { + $max_size = bp_core_upload_max_size(); + $max_size_mb = bp_document_format_size_units( $max_size, false, 'MB' ); + ?> + +

+ %2$s %3$s', + __( 'Set a maximum file size for document uploads, in megabytes. Your server\'s maximum upload size is ', 'buddyboss' ), + $max_size_mb, + 'MB.' + ); + ?> +

+ search_results['all']['total_match_count'] < 1 ) { - // return; - } - $search_url = $this->search_page_search_url(); // first print the 'all results' tab. diff --git a/src/bp-templates/bp-nouveau/buddypress/media/theatre.php b/src/bp-templates/bp-nouveau/buddypress/media/theatre.php index 01eedf86ac..457efa72cb 100644 --- a/src/bp-templates/bp-nouveau/buddypress/media/theatre.php +++ b/src/bp-templates/bp-nouveau/buddypress/media/theatre.php @@ -5,7 +5,7 @@ * @since BuddyBoss 1.0.0 */ ?> -