Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Media Count Not Updating. #2074

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/assets/js/rtMedia.backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } );
Expand Down
3 changes: 3 additions & 0 deletions app/helper/RTMediaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) {
Expand All @@ -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(
Expand All @@ -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;
Expand Down
50 changes: 29 additions & 21 deletions app/main/controllers/template/RTMediaTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion app/main/controllers/template/rtmedia-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function rtmedia_add_album_selection_field( $media_type ) {
}
?>
<div class="rtmedia-edit-change-album rtm-field-wrap">
<label for=""><?php esc_html_e( 'Album', 'buddypress-media' ); ?> : </label>
<label ><?php esc_html_e( 'Album', 'buddypress-media' ); ?> : </label>
<?php
if ( isset( $rtmedia_query->query['context'] ) && 'group' === $rtmedia_query->query['context'] ) {
// show group album list.
Expand Down
2 changes: 2 additions & 0 deletions app/main/controllers/template/rtmedia-ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
)
);

Expand Down
12 changes: 8 additions & 4 deletions app/main/controllers/template/rtmedia-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand All @@ -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();
}
Expand Down