diff --git a/app/assets/js/rtMedia.backbone.js b/app/assets/js/rtMedia.backbone.js index cfbc7e26a..5ea033882 100755 --- a/app/assets/js/rtMedia.backbone.js +++ b/app/assets/js/rtMedia.backbone.js @@ -322,6 +322,8 @@ jQuery( function( $ ) { jQuery( '#rtmedia-nav-item-photo span' ).text( response.media_count.photos_count ); jQuery( '#rtmedia-nav-item-music span' ).text( response.media_count.music_count ); jQuery( '#rtmedia-nav-item-video span' ).text( response.media_count.videos_count ); + jQuery( '#rtmedia-nav-item-document span' ).text( response.media_count.docs_count ); + if ( jQuery( 'li#rtm-url-upload' ).length === 0 ) { jQuery( '#' + current_gallery_id + ' .rtmedia-list' ).css( { 'opacity': 1, 'height': 'auto', 'overflow': 'auto' } ); diff --git a/app/helper/RTMediaModel.php b/app/helper/RTMediaModel.php index 0b5ed5f9a..cb2a6a68f 100755 --- a/app/helper/RTMediaModel.php +++ b/app/helper/RTMediaModel.php @@ -486,6 +486,7 @@ public function get_media_count() { $remaining_music = 0; $remaining_videos = 0; $remaining_all_media = 0; + $remaining_docs = 0; // Fetch the remaining media count. if ( class_exists( 'RTMediaNav' ) ) { @@ -512,6 +513,7 @@ public function get_media_count() { $remaining_photos = ( ! empty( $counts['total']['photo'] ) ) ? $counts['total']['photo'] : 0; $remaining_videos = ( ! empty( $counts['total']['video'] ) ) ? $counts['total']['video'] : 0; $remaining_music = ( ! empty( $counts['total']['music'] ) ) ? $counts['total']['music'] : 0; + $remaining_docs = ( ! empty( $counts['total']['document'] ) ) ? $counts['total']['document'] : 0; } $media_counts = array( @@ -520,6 +522,7 @@ public function get_media_count() { 'music_count' => $remaining_music, 'videos_count' => $remaining_videos, 'albums_count' => $remaining_album, + 'docs_count' => $remaining_docs, ); return $media_counts; diff --git a/app/main/controllers/template/RTMediaTemplate.php b/app/main/controllers/template/RTMediaTemplate.php index 4661967ec..05c01a462 100755 --- a/app/main/controllers/template/RTMediaTemplate.php +++ b/app/main/controllers/template/RTMediaTemplate.php @@ -367,16 +367,22 @@ public function save_single_edit() { $data = rtmedia_sanitize_object( $_POST, $data_array ); $media = new RTMediaMedia(); - $image_path = get_attached_file( $rtmedia_query->media[0]->media_id ); - - if ( $image_path && 'photo' === $rtmedia_query->media[0]->media_type ) { + if ( isset( $rtmedia_query->media[0]->media_id ) ) { + $image_path = get_attached_file( $rtmedia_query->media[0]->media_id ); + } else { + $image_path = ''; // or handle the error as needed + } + if ( isset( $rtmedia_query->media[0] ) && 'photo' === $rtmedia_query->media[0]->media_type ) { $image_meta_data = wp_generate_attachment_metadata( $rtmedia_query->media[0]->media_id, $image_path ); wp_update_attachment_metadata( $rtmedia_query->media[0]->media_id, $image_meta_data ); } - $state = $media->update( $rtmedia_query->action_query->id, $data, $rtmedia_query->media[0]->media_id ); - + if ( isset( $rtmedia_query->action_query->id ) && isset( $rtmedia_query->media[0]->media_id ) ) { + $state = $media->update( $rtmedia_query->action_query->id, $data, $rtmedia_query->media[0]->media_id ); + } else { + $state = false; // or handle the error as needed + } $rtmedia_filepath_old = sanitize_text_field( filter_input( INPUT_POST, 'rtmedia-filepath-old', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ); if ( isset( $rtmedia_filepath_old ) ) { $is_valid_url = preg_match( "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $rtmedia_filepath_old ); @@ -423,22 +429,24 @@ public function save_single_edit() { // refresh. $rtmedia_nav = new RTMediaNav(); - if ( 'group' === $rtmedia_query->media[0]->context ) { - $rtmedia_nav->refresh_counts( - $rtmedia_query->media[0]->context_id, - array( - 'context' => $rtmedia_query->media[0]->context, - 'context_id' => $rtmedia_query->media[0]->context_id, - ) - ); - } else { - $rtmedia_nav->refresh_counts( - $rtmedia_query->media[0]->media_author, - array( - 'context' => 'profile', - 'media_author' => $rtmedia_query->media[0]->media_author, - ) - ); + if ( isset( $rtmedia_query->media[0] ) && isset( $rtmedia_query->media[0]->context ) ) { + if ( 'group' === $rtmedia_query->media[0]->context ) { + $rtmedia_nav->refresh_counts( + $rtmedia_query->media[0]->context_id, + array( + 'context' => $rtmedia_query->media[0]->context, + 'context_id' => $rtmedia_query->media[0]->context_id, + ) + ); + } else { + $rtmedia_nav->refresh_counts( + $rtmedia_query->media[0]->media_author, + array( + 'context' => 'profile', + 'media_author' => $rtmedia_query->media[0]->media_author, + ) + ); + } } $state = apply_filters( 'rtmedia_single_edit_state', $state ); diff --git a/app/main/controllers/template/rtmedia-actions.php b/app/main/controllers/template/rtmedia-actions.php index c19e3b6d0..8bdb8833f 100644 --- a/app/main/controllers/template/rtmedia-actions.php +++ b/app/main/controllers/template/rtmedia-actions.php @@ -124,7 +124,7 @@ function rtmedia_add_album_selection_field( $media_type ) { } ?>
- + query['context'] ) && 'group' === $rtmedia_query->query['context'] ) { // show group album list. diff --git a/app/main/controllers/template/rtmedia-ajax-actions.php b/app/main/controllers/template/rtmedia-ajax-actions.php index 12aa8369c..68a3f172c 100644 --- a/app/main/controllers/template/rtmedia-ajax-actions.php +++ b/app/main/controllers/template/rtmedia-ajax-actions.php @@ -52,6 +52,7 @@ function rtmedia_delete_uploaded_media() { $remaining_photos = ( ! empty( $counts['total']['photo'] ) ) ? $counts['total']['photo'] : 0; $remaining_videos = ( ! empty( $counts['total']['video'] ) ) ? $counts['total']['video'] : 0; $remaining_music = ( ! empty( $counts['total']['music'] ) ) ? $counts['total']['music'] : 0; + $remaining_docs = ( ! empty( $counts['total']['document'] ) ) ? $counts['total']['document'] : 0; } wp_send_json_success( @@ -62,6 +63,7 @@ function rtmedia_delete_uploaded_media() { 'music_count' => $remaining_music, 'videos_count' => $remaining_videos, 'albums_count' => $remaining_album, + 'docs_count' => $remaining_docs, ) ); diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php index 5f61f99e3..8c9984346 100644 --- a/app/main/controllers/template/rtmedia-functions.php +++ b/app/main/controllers/template/rtmedia-functions.php @@ -994,8 +994,10 @@ function rtmedia_delete_allowed() { global $rtmedia_media; - $flag = intval( $rtmedia_media->media_author ) === get_current_user_id(); - + $flag = false; + if ( $rtmedia_media !== null && isset( $rtmedia_media->media_author ) ) { + $flag = intval( $rtmedia_media->media_author ) === get_current_user_id(); + } if ( ! $flag && isset( $rtmedia_media->context ) && 'group' === $rtmedia_media->context && function_exists( 'bp_group_is_admin' ) ) { $flag = ( bp_group_is_admin() || bp_group_is_mod() ); } @@ -1020,8 +1022,10 @@ function rtmedia_edit_allowed() { global $rtmedia_media; - $flag = intval( $rtmedia_media->media_author ) === get_current_user_id(); - + $flag = false; + if ( $rtmedia_media !== null && isset( $rtmedia_media->media_author ) ) { + $flag = intval( $rtmedia_media->media_author ) === get_current_user_id(); + } if ( ! $flag ) { $flag = is_super_admin() || rtm_is_bp_group_admin() || rtm_is_bp_group_mod(); }