From 6ccc40741e8c5345ed0980a267739d15d3347c1e Mon Sep 17 00:00:00 2001 From: bhargaviananthbandaru Date: Mon, 21 Jul 2025 22:18:45 +0530 Subject: [PATCH 01/17] Fix: Ensure rtMedia compatibility with WordPress 6.7 (#2155) --- app/assets/js/rtMedia.backbone.js | 6260 ++++++++++++++++------------- app/assets/js/rtMedia.js | 2804 +++++++------ app/main/RTMedia.php | 108 +- 3 files changed, 5119 insertions(+), 4053 deletions(-) diff --git a/app/assets/js/rtMedia.backbone.js b/app/assets/js/rtMedia.backbone.js index 5ea033882..d0ef680ee 100755 --- a/app/assets/js/rtMedia.backbone.js +++ b/app/assets/js/rtMedia.backbone.js @@ -7,1184 +7,1448 @@ var objUploadView; var rtmedia_load_template_flag = true; var rtmedia_add_media_button_post_update = false; +jQuery(document).ready(function () { + // Need to pass the object[key] as global variable. + if ("object" === typeof rtmedia_backbone) { + for (var key in rtmedia_backbone) { + window[key] = rtmedia_backbone[key]; + } + } + if ("object" === typeof rtMedia_plupload) { + for (var key in rtMedia_plupload) { + window[key] = rtMedia_plupload[key]; + } + } + if ("object" === typeof rtmedia_template) { + for (var key in rtmedia_template) { + window[key] = rtmedia_template[key]; + } + } + if ("object" === typeof rtMedia_activity) { + for (var key in rtMedia_activity) { + window[key] = rtMedia_activity[key]; + } + } + if ("object" === typeof rtmedia_bp) { + for (var key in rtmedia_bp) { + window[key] = rtmedia_bp[key]; + } + } + if ("object" === typeof rtmedia_main) { + for (var key in rtmedia_main) { + window[key] = rtmedia_main[key]; + } + } +}); -jQuery( document ).ready( function () { - - // Need to pass the object[key] as global variable. - if ( 'object' === typeof rtmedia_backbone ) { - for ( var key in rtmedia_backbone ) { - window[key] = rtmedia_backbone[key]; - } - } - if ( 'object' === typeof rtMedia_plupload ) { - for( var key in rtMedia_plupload ) { - window[key] = rtMedia_plupload[key]; - } - } - if ( 'object' === typeof rtmedia_template ) { - for( var key in rtmedia_template ) { - window[key] = rtmedia_template[key]; - } - } - if ( 'object' === typeof rtMedia_activity ) { - for( var key in rtMedia_activity ) { - window[key] = rtMedia_activity[key]; - } - } - if ( 'object' === typeof rtmedia_bp ) { - for( var key in rtmedia_bp ) { - window[key] = rtmedia_bp[key]; - } - } - if ( 'object' === typeof rtmedia_main ) { - for( var key in rtmedia_main ) { - window[key] = rtmedia_main[key]; - } - } -} ); - -jQuery( function( $ ) { - /** - * Issue 1059 fixed: negative comment count - */ - $( document ).ready( function () { - /** - * Bind dynamic event on delete button to remove media ul - */ - $( '#activity-stream' ).on( 'click', '.acomment-delete', function () { - /** - * get media ul - */ - let media_children = $( this ).closest('li').find( 'div.acomment-content ul.rtmedia-list' ); - if ( media_children.length > 0 ) { - /** - * remove ul if exists, so buddypress comment js doesn't get confused between media ul and child comment ul - */ - media_children.remove(); - } - }); - - /** - * Remove imageEdit.save function call and add it only when image is being modified in WP editor. - */ - $( '#rtmedia_media_single_edit .rtm-button-save' ).on( 'click', function() { - var $media_id = $( '#rtmedia-editor-media-id' ).val(); - var $nonce = $( '#rtmedia-editor-nonce' ).val(); - if ( 'undefined' === typeof $nonce || '' === $nonce.trim() || 'undefined' === typeof $media_id || '' === $media_id.trim() ) { - return; - } - $media_id = parseInt( $media_id ); - $media_head = $( '#media-head-' + $media_id ); - if ( ! $media_head.length || 'undefined' === typeof $media_head.css( 'display' ) || 'none' !== $media_head.css( 'display' ).trim() ) { - return; - } - - imageEdit.save( $media_id, $nonce ); - } ); - - /** - * Reload page when rtmedia_update type of activity is edited. - */ - function filterBeaSaveSuccess() { - location.reload(); - } - /** - * Prefilters ajax call which saves edited activity content. - * Needed with BuddyPress Edit Activity plugin. - * https://wordpress.org/plugins/buddypress-edit-activity/ - */ - $.ajaxPrefilter( function( options, originalOptions, jqXHR ) { - // Modify options, control originalOptions, store jqXHR, etc - try { - if ( null === originalOptions.data || typeof ( originalOptions.data ) === 'undefined' || typeof ( originalOptions.data.action ) === 'undefined' || 'buddypress-edit-activity-save' !== originalOptions.data.action ) { - return true; - } - } catch ( e ) { - return true; - } - - if ( ! $( '#activity-' + originalOptions.data.activity_id ).hasClass( 'rtmedia_update' ) ) { - return; - } - - // Change the callback function to our own function, which reloads the page. - originalOptions.success = filterBeaSaveSuccess; - options.success = filterBeaSaveSuccess; - } ); - }); - /** - * End of issue 1059 fix - */ - - - var o_is_album, o_is_edit_allowed; - if ( typeof ( is_album ) == 'undefined' ) { - o_is_album = new Array( '' ); - } else { - o_is_album = is_album; - } - if ( typeof ( is_edit_allowed ) == 'undefined' ) { - o_is_edit_allowed = new Array( '' ); - } else { - o_is_edit_allowed = is_edit_allowed; - } - - rtMedia = window.rtMedia || { }; - - rtMedia = window.rtMedia || { }; - - rtMedia.Context = Backbone.Model.extend( { - url: function() { - var url = rtmedia_media_slug + '/'; - - if ( ! upload_sync && nextpage > 0 ) { - url += 'pg/' + nextpage + '/'; - } - - return url; - }, - defaults: { - 'context': 'post', - 'context_id': false - } - } ); +jQuery(function ($) { + /** + * Issue 1059 fixed: negative comment count + */ + $(document).ready(function () { + /** + * Bind dynamic event on delete button to remove media ul + */ + $("#activity-stream").on("click", ".acomment-delete", function () { + /** + * get media ul + */ + let media_children = $(this) + .closest("li") + .find("div.acomment-content ul.rtmedia-list"); + if (media_children.length > 0) { + /** + * remove ul if exists, so buddypress comment js doesn't get confused between media ul and child comment ul + */ + media_children.remove(); + } + }); + + /** + * Remove imageEdit.save function call and add it only when image is being modified in WP editor. + */ + $("#rtmedia_media_single_edit .rtm-button-save").on("click", function () { + var $media_id = $("#rtmedia-editor-media-id").val(); + var $nonce = $("#rtmedia-editor-nonce").val(); + if ( + "undefined" === typeof $nonce || + "" === $nonce.trim() || + "undefined" === typeof $media_id || + "" === $media_id.trim() + ) { + return; + } + $media_id = parseInt($media_id); + $media_head = $("#media-head-" + $media_id); + if ( + !$media_head.length || + "undefined" === typeof $media_head.css("display") || + "none" !== $media_head.css("display").trim() + ) { + return; + } + + imageEdit.save($media_id, $nonce); + }); + + /** + * Reload page when rtmedia_update type of activity is edited. + */ + function filterBeaSaveSuccess() { + location.reload(); + } + /** + * Prefilters ajax call which saves edited activity content. + * Needed with BuddyPress Edit Activity plugin. + * https://wordpress.org/plugins/buddypress-edit-activity/ + */ + $.ajaxPrefilter(function (options, originalOptions, jqXHR) { + // Modify options, control originalOptions, store jqXHR, etc + try { + if ( + null === originalOptions.data || + typeof originalOptions.data === "undefined" || + typeof originalOptions.data.action === "undefined" || + "buddypress-edit-activity-save" !== originalOptions.data.action + ) { + return true; + } + } catch (e) { + return true; + } + + if ( + !$("#activity-" + originalOptions.data.activity_id).hasClass( + "rtmedia_update" + ) + ) { + return; + } + + // Change the callback function to our own function, which reloads the page. + originalOptions.success = filterBeaSaveSuccess; + options.success = filterBeaSaveSuccess; + }); + }); + /** + * End of issue 1059 fix + */ + + var o_is_album, o_is_edit_allowed; + if (typeof is_album == "undefined") { + o_is_album = new Array(""); + } else { + o_is_album = is_album; + } + if (typeof is_edit_allowed == "undefined") { + o_is_edit_allowed = new Array(""); + } else { + o_is_edit_allowed = is_edit_allowed; + } + + rtMedia = window.rtMedia || {}; + + rtMedia = window.rtMedia || {}; + + rtMedia.Context = Backbone.Model.extend({ + url: function () { + var url = rtmedia_media_slug + "/"; + + if (!upload_sync && nextpage > 0) { + url += "pg/" + nextpage + "/"; + } + + return url; + }, + defaults: { + context: "post", + context_id: false, + }, + }); + + rtMedia.Media = Backbone.Model.extend({ + defaults: { + id: 0, + blog_id: false, + media_id: false, + media_author: false, + media_title: false, + album_id: false, + media_type: "photo", + activity_id: false, + privacy: 0, + views: 0, + downloads: 0, + ratings_average: 0, + ratings_total: 0, + ratings_count: 0, + likes: 0, + dislikes: 0, + guid: false, + width: 0, + height: 0, + rt_permalink: false, + duration: "0:00", + //"next": -1, + //"prev": -1 + }, + }); + + rtMedia.Gallery = Backbone.Collection.extend({ + model: rtMedia.Media, + url: function () { + var temp = window.location.pathname; + var url = ""; + if (temp.indexOf("/" + rtmedia_media_slug + "/") == -1) { + url = rtmedia_media_slug + "/"; + } else { + if (temp.indexOf("pg/") == -1) { + url = temp; + } else { + url = window.location.pathname.substr( + 0, + window.location.pathname.lastIndexOf("pg/") + ); + } + } + if (!upload_sync && nextpage >= 1) { + if (url.substr(url.length - 1) != "/") { + url += "/"; + } - rtMedia.Media = Backbone.Model.extend( { - defaults: { - 'id': 0, - 'blog_id': false, - 'media_id': false, - 'media_author': false, - 'media_title': false, - 'album_id': false, - 'media_type': 'photo', - 'activity_id': false, - 'privacy': 0, - 'views': 0, - 'downloads': 0, - 'ratings_average': 0, - 'ratings_total': 0, - 'ratings_count': 0, - 'likes': 0, - 'dislikes': 0, - 'guid': false, - 'width': 0, - 'height': 0, - 'rt_permalink': false, - 'duration': '0:00' - //"next": -1, - //"prev": -1 - } + url += "pg/" + nextpage + "/"; + } - } ); + return url; + }, + getNext: function (page, el, element) { + if (jQuery(".rtmedia-no-media-found").length > 0) { + var rtmediaListUl = jQuery("