Skip to content

Commit

Permalink
Merge pull request #1008 from WPChill/2.8.17
Browse files Browse the repository at this point in the history
2.8.17
  • Loading branch information
TeoAlex authored Jul 30, 2024
2 parents 388983d + e5edd89 commit 85b7352
Show file tree
Hide file tree
Showing 11 changed files with 680 additions and 302 deletions.
4 changes: 2 additions & 2 deletions Modula.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://wp-modula.com/
* Description: Modula is the most powerful, user-friendly WordPress gallery plugin. Add galleries, masonry grids and more in a few clicks.
* Author: WPChill
* Version: 2.8.16
* Version: 2.8.17
* Author URI: https://www.wpchill.com/
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -47,7 +47,7 @@
* @since 2.0.2
*/

define( 'MODULA_LITE_VERSION', '2.8.16' );
define( 'MODULA_LITE_VERSION', '2.8.17' );
define( 'MODULA_PATH', plugin_dir_path( __FILE__ ) );
define( 'MODULA_URL', plugin_dir_url( __FILE__ ) );
defined( 'MODULA_PRO_STORE_URL' ) || define( 'MODULA_PRO_STORE_URL', 'https://wp-modula.com' );
Expand Down
223 changes: 223 additions & 0 deletions assets/js/admin/modula-media.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@

function ModulaMakeItem( model ) {
const defaults = {
'id': '',
'title': '',
'description': '',
'alt': '',
'link': '',
'halign': 'center',
'valign': 'middle',
'target': '',
'togglelightbox': '',
'src': '',
'type': 'image',
'width': 2,
'height': 2,
'full' : '',
'thumbnail': '',
'resize': false,
'index': '',
'orientation': 'landscape'
};
new_item = defaults;

new_item.id = model.attributes.id;
new_item.title = model.attributes.name;
new_item.description = model.attributes.caption;
new_item.alt = model.attributes.alt;
new_item.width = model.attributes.width;
new_item.width = model.attributes.height;
new_item.type = model.attributes.type;

return new_item;
};

jQuery(document).ready(function($) {
var bulkActionTop = $('#bulk-action-selector-top'),
bulkActionBottom = $('#bulk-action-selector-bottom'),
tpl = wp.template( 'modula-gallery-selector');
if( 'undefined' != typeof modulaGalleries.posts && 0 != modulaGalleries.posts.length ){
if( 'undefined' != typeof bulkActionTop[0] ){
modulaGalleries.pos = 'top';
bulkActionTop.after( tpl( modulaGalleries ) );
}

if( 'undefined' != typeof bulkActionBottom[0] ){
modulaGalleries.pos = 'bottom';
bulkActionBottom.after( tpl( modulaGalleries ) );
}
}

$(document).on('change', '#bulk-action-selector-top, #bulk-action-selector-bottom', function(){
if( $(this).val() == 'modula_add_to_gallery' ){
$('#modula_gallery_select_top, #modula_gallery_select_bottom').show();
}else{
$('#modula_gallery_select_top, #modula_gallery_select_bottom').hide();
}
} );

var Button = wp.media.view.Button,
AddToGalleryBtn;

AddToGalleryBtn = Button.extend({
initialize: function() {
Button.prototype.initialize.apply( this, arguments );
if ( this.options.filters ) {
this.options.filters.model.on( 'change', this.filterChange, this );
}
this.controller.on( 'selection:toggle', this.toggleDisabled, this );
this.controller.on( 'select:activate', this.toggleDisabled, this );
},

toggleDisabled: function() {
this.model.set( 'disabled', ! this.controller.state().get( 'selection' ).length );
},

render: function() {
Button.prototype.render.apply( this, arguments );
if ( this.controller.isModeActive( 'select' ) ) {
this.$el.addClass( 'delete-selected-button' );
} else {
this.$el.addClass( 'delete-selected-button hidden' );
}
this.toggleDisabled();

return this;
}
});

ModulaGallerySelector = wp.media.View.extend({
className: 'view-switch wp-modula-gallery-selector',
template: wp.template( 'modula-gallery-selector'),
initialize: function() {
this.controller.on( 'selection:toggle', this.toggleDisabled, this );
this.controller.on( 'select:activate', this.toggleDisabled, this );
this.controller.on( 'select:deactivate', this.toggleDisabled, this );
},
toggleDisabled: function() {

if ( this.controller.isModeActive( 'select' ) ) {
this.$el.show();
} else {
this.$el.hide();
}

if( 0 == this.controller.state().get( 'selection' ).length ){
this.$el.find('select').prop("disabled", true);
}else{
this.$el.find('select').prop("disabled", false);
}

},
render: function() {
this.$el.html( this.template( modulaGalleries.posts ) );
if ( this.controller.isModeActive( 'select' ) ) {
this.$el.addClass( 'view-switch wp-modula-gallery-selector' );

} else {
this.$el.addClass( 'view-switch wp-modula-gallery-selector hidden' );
}
this.toggleDisabled();

return this;
}
});

wp.media.view.modulaGallerySelector = ModulaGallerySelector;
wp.media.view.addToGalleryBtn = AddToGalleryBtn;

var originalAttachmentsBrowser = wp.media.view.AttachmentsBrowser;

wp.media.view.AttachmentsBrowser = originalAttachmentsBrowser.extend({
createToolbar: function() {

originalAttachmentsBrowser.prototype.createToolbar.apply(this, arguments);
if( 'undefined' == typeof modulaGalleries.posts || 0 == modulaGalleries.posts.length ){
return;
}
var toolbar = this.toolbar,
filters = this.toolbar.get('filters');

toolbar.set( 'modulaGallerySelector', new ModulaGallerySelector({
filters: filters,
style: 'primary',
controller: this.controller,
priority: -181
}).render() );

toolbar.set('addToGalleryBtn', new wp.media.view.addToGalleryBtn({
filters: filters,
style: 'primary',
text: 'Add to Modula Gallery',
controller: this.controller,
priority: -180,
click: function() {
var selected = [],
selection = this.controller.state().get( 'selection' ),
library = this.controller.state().get( 'library' );

if ( ! selection.length ) {
return;
}

selection.each( function( model ) {
if ( 'trash' !== model.get( 'status' ) ) {
selected.push( ModulaMakeItem(model) );
}
} );

if ( selected.length ) {
var galleryId = $('#modula_gallery_select').val();
var nonce = modulaGalleries.nonce;

$.ajax({
url: modulaGalleries.ajax_url,
type: 'POST',
dataType: 'json',
data: {
action: 'add_images_to_gallery',
selected: JSON.stringify( selected ),
gallery_id: galleryId,
nonce: nonce
},
success: function(response) {
if(response.success) {
library._requery( true );
$(document).trigger( 'modula:media:insert:done', response.data );
this.controller.trigger( 'selection:action:done' );
} else {
alert( modulaGalleries.l10n.ajax_failed + response.data );
}
}.bind(this),
error: function(xhr, status, error) {
alert( modulaGalleries.l10n.ajax_failed + error );
}
});
} else {
this.controller.trigger( 'selection:action:done' );
}
}
}).render() );
}
});
});

jQuery(document).on('modula:media:insert:done', function(event, data) {
var messageDiv = jQuery('<div>', {
text: data,
class: 'notice notice-success is-dismissible',
css: {
padding: '10px',
margin: '5px 0 0 0',

}
});
jQuery('.attachments-browser').prepend(messageDiv);

setTimeout(function() {
messageDiv.fadeOut(function() {
jQuery(this).remove();
});
}, 5000);
});
2 changes: 1 addition & 1 deletion assets/js/admin/wp-modula-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ wp.Modula = 'undefined' === typeof wp.Modula ? {} : wp.Modula;
},

checkGalleryType: function (type) {
if ('creative-gallery' == type || 'grid' == type) {
if ('creative-gallery' == type || 'grid' == type || 'airbnb' == type) {
this.$el.hide();
} else if ('custom-grid' == type) {
if (!wp.Modula.Settings.get('helpergrid')) {
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
= 2.8.17 - 30.07.2024 =
Added: WordPress Media library option to add selected(grid) or checked(list) images to a Modula gallery.( [#1002]( https://github.com/WPChill/modula-lite/issues/1002) )
Changed: Removed WPChill tracking option.( [#1007]( https://github.com/WPChill/modula-lite/issues/1007) )

= 2.8.16 - 20.07.2024 =
Fixed: Edit/New gallery was not working properly due to debug class

Expand Down
80 changes: 80 additions & 0 deletions includes/admin/class-modula-admin-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,86 @@ public static function modula_tab_navigation( $tabs, $active_tab ) {
}
}

public static function sanitize_image( $image ) {

$new_image = array();

// This list will not contain id because we save our images based on image id.
$image_attributes = apply_filters(
'modula_gallery_image_attributes',
array(
'id',
'alt',
'title',
'description',
'halign',
'valign',
'link',
'target',
'width',
'height',
'togglelightbox',
)
);

foreach ( $image_attributes as $attribute ) {
if ( isset( $image[ $attribute ] ) ) {

switch ( $attribute ) {
case 'alt':
$new_image[ $attribute ] = sanitize_text_field( $image[ $attribute ] );
break;
case 'width':
case 'height':
$new_image[ $attribute ] = absint( $image[ $attribute ] );
break;
case 'title':
case 'description':
$new_image[ $attribute ] = wp_filter_post_kses( $image[ $attribute ] );
break;
case 'link':
$new_image[ $attribute ] = esc_url_raw( $image[ $attribute ] );
break;
case 'target':
if ( isset( $image[ $attribute ] ) ) {
$new_image[ $attribute ] = absint( $image[ $attribute ] );
} else {
$new_image[ $attribute ] = 0;
}
break;
case 'togglelightbox':
if ( isset( $image[ $attribute ] ) ) {
$new_image[ $attribute ] = absint( $image[ $attribute ] );
} else {
$new_image[ $attribute ] = 0;
}
break;
case 'halign':
if ( in_array( $image[ $attribute ], array( 'left', 'right', 'center' ) ) ) {
$new_image[ $attribute ] = $image[ $attribute ];
} else {
$new_image[ $attribute ] = 'center';
}
break;
case 'valign':
if ( in_array( $image[ $attribute ], array( 'top', 'bottom', 'middle' ) ) ) {
$new_image[ $attribute ] = $image[ $attribute ];
} else {
$new_image[ $attribute ] = 'middle';
}
break;
default:
$new_image[ $attribute ] = apply_filters( 'modula_image_field_sanitization', sanitize_text_field( $image[ $attribute ] ), $image[ $attribute ], $attribute );
break;
}
} else {
$new_image[ $attribute ] = '';
}
}

return $new_image;
}

}

$modula_admin_helpers = Modula_Admin_Helpers::get_instance();
Loading

0 comments on commit 85b7352

Please sign in to comment.