plugin updates

This commit is contained in:
Tony Volpe
2024-07-16 13:57:46 +00:00
parent 41f50eacc4
commit 8f93917880
1529 changed files with 259452 additions and 25451 deletions

View File

@@ -0,0 +1,42 @@
(function ($) {
if (typeof ajaxurl === "undefined") {
ajaxurl = wpmfimport.vars.ajaxurl;
}
$(document).ready(function () {
/**
* Import category
* @param doit true or false
* @param button
*/
var importWpmfTaxonomy = function (doit, button) {
jQuery(button).find(".spinner").show().css({"visibility": "visible"});
jQuery.post(
ajaxurl,
{
action: "wpmf",
task: "import",
doit: doit,
wpmf_nonce: wpmfimport.vars.wpmf_nonce
},
function (response) {
jQuery(button).closest("div#wpmf_error").hide();
if (doit === true) {
jQuery("#wpmf_error").after("<div class='updated'> <p><strong>Categories imported into WP Media Folder. Enjoy!!!</strong></p></div>");
}
});
};
/* Click import button */
$('.wmpf_import_category').on('click', function () {
var $this = $(this);
importWpmfTaxonomy(true, $this);
});
/* Click no import button */
$('.wmpfNoImportBtn').on('click', function () {
var $this = $(this);
importWpmfTaxonomy(false, $this);
});
});
}(jQuery));

View File

@@ -0,0 +1,451 @@
(function ($) {
wpmfImportCloudModule = {
categories: [], // categories
folders_states: [], // Contains open or closed status of folders
/**
* Retrieve the Jquery tree view element
* of the current frame
* @return jQuery
*/
getTreeElement: function () {
return $('.librarytree_cloudimport');
},
initModule: function () {
if ($('.librarytree_cloudimport').length === 0) {
return;
}
// Import categories from wpmf main module
wpmfImportCloudModule.importCategories();
wpmfImportCloudModule.loadTreeView();
},
/**
* Render tree view inside content
*/
loadTreeView: function () {
wpmfImportCloudModule.getTreeElement().append(wpmfImportCloudModule.getRendering());
},
/**
* Import categories from wpmf main module
*/
importCategories: function () {
let folders_ordered = [];
// Add each category
$(wpmfFoldersModule.categories_order).each(function () {
folders_ordered.push(wpmfFoldersModule.categories[this]);
});
// Order the array depending on main ordering
switch (wpmfFoldersModule.folder_ordering) {
default:
case 'name-ASC':
folders_ordered = Object.values(folders_ordered).sort(function (a, b) {
if (a.id === 0) return -1; // Root folder is always first
if (b.id === 0) return 1; // Root folder is always first
return a.label.localeCompare(b.label);
});
break;
case 'name-DESC':
folders_ordered = Object.values(folders_ordered).sort(function (a, b) {
if (a.id === 0) return -1; // Root folder is always first
if (b.id === 0) return 1; // Root folder is always first
return b.label.localeCompare(a.label);
});
break;
case 'id-ASC':
folders_ordered = Object.values(folders_ordered).sort(function (a, b) {
if (a.id === 0) return -1; // Root folder is always first
if (b.id === 0) return 1; // Root folder is always first
return a.id - b.id;
});
break;
case 'id-DESC':
folders_ordered = Object.values(folders_ordered).sort(function (a, b) {
if (a.id === 0) return -1; // Root folder is always first
if (b.id === 0) return 1; // Root folder is always first
return b.id - a.id;
});
break;
case 'custom':
folders_ordered = Object.values(folders_ordered).sort(function (a, b) {
if (a.id === 0) return -1; // Root folder is always first
if (b.id === 0) return 1; // Root folder is always first
return a.order - b.order;
});
break;
}
// Reorder array based on children
let folders_ordered_deep = [];
let processed_ids = [];
const loadChildren = function (id) {
if (processed_ids.indexOf(id) < 0) {
processed_ids.push(id);
for (let ij = 0; ij < folders_ordered.length; ij++) {
if (folders_ordered[ij].parent_id === id) {
folders_ordered_deep.push(folders_ordered[ij]);
loadChildren(folders_ordered[ij].id);
}
}
}
};
loadChildren(parseInt(wpmf.vars.term_root_id));
// Finally save it to the global var
wpmfImportCloudModule.categories = folders_ordered_deep;
},
/**
* open folder tree by dir name
*/
getRendering: function () {
var ij = 0;
var content = '';
var generateList = function (tree_class = '') {
content += '<ul class="' + tree_class + '">';
while (ij < wpmfImportCloudModule.categories.length) {
var className = '';
if (typeof wpmfImportCloudModule.categories[ij].drive_type !== "undefined" && wpmfImportCloudModule.categories[ij].drive_type !== "") {
className += ' hide';
}
// get color folder
var bgcolor = '';
if (typeof wpmf.vars.colors !== 'undefined' && typeof wpmf.vars.colors[wpmfImportCloudModule.categories[ij].id] !== 'undefined') {
bgcolor = 'color: ' + wpmf.vars.colors[wpmfImportCloudModule.categories[ij].id];
} else {
bgcolor = 'color: #8f8f8f';
}
className += ' closed';
// Open li tag
content += '<li class="' + className + '" data-id="' + wpmfImportCloudModule.categories[ij].id + '" >';
const a_tag = '<a data-id="' + wpmfImportCloudModule.categories[ij].id + '">';
if (wpmfImportCloudModule.categories[ij + 1] && wpmfImportCloudModule.categories[ij + 1].depth > wpmfImportCloudModule.categories[ij].depth) { // The next element is a sub folder
// Add folder icon
content += '<a onclick="wpmfImportCloudModule.toggle(' + wpmfImportCloudModule.categories[ij].id + ')"><i class="material-icons wpmf-arrow">keyboard_arrow_down</i></a>';
content += a_tag;
content += '<input type="radio" name="selection_folder_import" class="wpmf_checkbox_tree selection_folder_import" value="'+ wpmfImportCloudModule.categories[ij].id +'" data-id="' + wpmfImportCloudModule.categories[ij].id + '">';
content += '<i class="material-icons-outlined folder-tree-icon" style="' + bgcolor + '">folder</i>';
} else {
content += a_tag;
// Add folder icon
content += '<span class="wpmf-no-arrow"><input type="radio" name="selection_folder_import" class="wpmf_checkbox_tree selection_folder_import" value="'+ wpmfImportCloudModule.categories[ij].id +'" data-id="' + wpmfImportCloudModule.categories[ij].id + '"><i class="material-icons-outlined folder-tree-icon" style="' + bgcolor + '">folder</i></span>';
}
// Add current category name
if (wpmfImportCloudModule.categories[ij].id === 0) {
// If this is the root folder then rename it
content += wpmf.l18n.media_folder;
} else {
content += '<span>' + wpmfImportCloudModule.categories[ij].label + '</span>';
}
content += '</a>';
// This is the end of the array
if (wpmfImportCloudModule.categories[ij + 1] === undefined) {
// Let's close all opened tags
for (let ik = wpmfImportCloudModule.categories[ij].depth; ik >= 0; ik--) {
content += '</li>';
content += '</ul>';
}
// We are at the end don't continue to process array
return false;
}
if (wpmfImportCloudModule.categories[ij + 1].depth > wpmfImportCloudModule.categories[ij].depth) { // The next element is a sub folder
// Recursively list it
ij++;
if (generateList() === false) {
// We have reached the end, let's recursively end
return false;
}
} else if (wpmfImportCloudModule.categories[ij + 1].depth < wpmfImportCloudModule.categories[ij].depth) { // The next element don't have the same parent
// Let's close opened tags
for (let ik = wpmfImportCloudModule.categories[ij].depth; ik > wpmfImportCloudModule.categories[ij + 1].depth; ik--) {
content += '</li>';
content += '</ul>';
}
// We're not at the end of the array let's continue processing it
return true;
}
// Close the current element
content += '</li>';
ij++;
}
};
generateList('wpmf_media_library');
return content;
},
/**
* Toggle the open / closed state of a folder
* @param folder_id
*/
toggle: function (folder_id) {
// get last status folder tree
let lastStatusTree = [];
// Check is folder has closed class
if (wpmfImportCloudModule.getTreeElement().find('li[data-id="' + folder_id + '"]').hasClass('closed')) {
// Open the folder
wpmfImportCloudModule.openFolder(folder_id);
$('#librarytree li[data-id="'+ folder_id +'"] > a >.folder-tree-icon').html('folder_open');
} else {
// Close the folder
wpmfImportCloudModule.closeFolder(folder_id);
// close all sub folder
$('li[data-id="' + folder_id + '"]').find('li').addClass('closed');
$('#librarytree li[data-id="'+ folder_id +'"] > a >.folder-tree-icon').html('folder')
}
},
/**
* Open a folder to show children
*/
openFolder: function (folder_id) {
wpmfImportCloudModule.getTreeElement().find('li[data-id="' + folder_id + '"]').removeClass('closed');
wpmfImportCloudModule.folders_states[folder_id] = 'open';
},
/**
* Close a folder and hide children
*/
closeFolder: function (folder_id) {
wpmfImportCloudModule.getTreeElement().find('li[data-id="' + folder_id + '"]').addClass('closed');
wpmfImportCloudModule.folders_states[folder_id] = 'close';
},
showdialog: function (is_multiple, library_type = 'cloud-library-files', files = [], mimeTypes = [], filenames = [], source = 'photos') {
var text = '';
text += '<div id="librarytree" class="librarytree librarytree_cloudimport"></div>';
if (library_type === 'google-photo' && source === 'album') {
var albumTitle = $('.photo-album-item.selected .album-title span').text();
text += '<div class="import_album_as_new_folder">';
text += '<label>'+ wpmf.l18n.import_album_as_new_folder +'</label>';
text += '<input type="checkbox" checked class="enable_import_album_as_new_folder">';
text += '<input type="text" class="album-title-input" value="'+ albumTitle +'">';
text += '</div>';
}
showDialog({
title: (library_type === 'cloud-library-files') ? wpmf.l18n.import_cloud_title : wpmf.l18n.import_google_photo_title,
id: (library_type === 'google-photo') ? 'wpmf-google-photo-dialog' : 'wpmf-cloud-dialog',
text: text,
negative: {
title: wpmf.l18n.cancel
},
positive: {
title: wpmf.l18n.import,
onClick: function () {
if (!$('.selection_folder_import:checked').length) {
return;
}
var folder = $('.selection_folder_import:checked').val();
if (library_type === 'cloud-library-files') {
var filesselected;
if (is_multiple) {
filesselected = [];
$('.attachment.selected').each(function (i, v) {
var id = $(v).data('id');
if (filesselected.indexOf(id) == -1) {
filesselected.push(id);
}
});
} else {
filesselected = [];
filesselected.push(wpmfFoldersModule.editFileId);
}
var ids = filesselected.join();
wpmfImportCloudModule.importCloud(ids, folder);
} else if (library_type === 'google-photo') {
if (source === 'album') {
var albumId = $('.photo-album-item.selected').data('id');
var album_title = $('.album-title-input').val();
if (album_title === '') {
album_title = $('.photo-album-item.selected .album-title span').text();
}
wpmfImportCloudModule.importGooglePhotoAlbum(albumId, album_title, folder);
} else {
wpmfImportCloudModule.importGooglePhoto(files, mimeTypes, filenames, folder);
}
}
}
}
});
},
importGooglePhotoAlbum: function(albumId, album_title, folder, pageToken = '', created_album = false) {
var datas = {
action: 'wpmf_google_photo_album_import',
albumId: albumId,
pageToken: pageToken,
folder: folder,
wpmf_nonce: wpmf.vars.wpmf_nonce
};
if ($('.enable_import_album_as_new_folder').is(':checked')) {
datas.album_title = album_title;
datas.created_album = (created_album) ? 1 : 0;
} else {
datas.created_album = 1;
}
$.ajax({
url: ajaxurl,
method: 'POST',
dataType: 'json',
data: datas,
beforeSend: function () {
if (!$('.wpmf-snackbar[data-id="importing_cloud_file"]').length) {
wpmfSnackbarModule.show({
id: 'importing_cloud_file',
content: wpmf.l18n.importing_goolge_photo_album,
auto_close: false,
is_progress: true
});
}
},
success: function (res) {
if (res.status) {
if (res.continue) {
wpmfImportCloudModule.importGooglePhotoAlbum(albumId, album_title, res.albumCreatedId, res.pageToken, true);
} else {
wpmfSnackbarModule.close('importing_cloud_file');
}
} else {
wpmfSnackbarModule.close('importing_cloud_file');
}
},
});
},
importGooglePhoto: function (files, mimeTypes, filenames, folder, page = 0) {
$.ajax({
url: ajaxurl,
method: 'POST',
dataType: 'json',
data: {
action: 'wpmf_google_photo_import',
files: files.join(),
mimeTypes: mimeTypes.join(),
filenames: filenames.join(),
page: page,
folder: folder,
wpmf_nonce: wpmf.vars.wpmf_nonce
},
beforeSend: function () {
if (!$('.wpmf-snackbar[data-id="importing_cloud_file"]').length) {
wpmfSnackbarModule.show({
id: 'importing_cloud_file',
content: wpmf.l18n.importing_goolge_photo,
auto_close: false,
is_progress: true
});
}
},
success: function (res) {
if (res.status) {
if (res.continue) {
page++;
wpmfImportCloudModule.importGooglePhoto(files, mimeTypes, filenames, folder, page);
} else {
wpmfSnackbarModule.close('importing_cloud_file');
}
} else {
wpmfSnackbarModule.close('importing_cloud_file');
}
},
});
},
importCloud: function (ids, folder) {
$.ajax({
url: ajaxurl,
method: 'POST',
dataType: 'json',
data: {
action: 'wpmf_cloud_import',
ids: ids,
folder: folder,
wpmf_nonce: wpmf.vars.wpmf_nonce
}, beforeSend: function () {
if (!$('.wpmf-snackbar[data-id="importing_cloud_file"]').length) {
wpmfSnackbarModule.show({
id: 'importing_cloud_file',
content: wpmf.l18n.importing_cloud_file,
icon: '<span class="material-icons-outlined wpmf-snack-icon wpmf-snack-loader">sync</span>',
auto_close: false,
is_progress: true
});
}
},
success: function (res) {
if (res.status) {
if (res.continue) {
wpmfImportCloudModule.importCloud(res.ids, folder);
} else {
wpmfSnackbarModule.close('importing_cloud_file');
if ($('.media-frame').hasClass('mode-select')) {
$('.select-mode-toggle-button').click();
}
wpmfFoldersModule.reloadAttachments();
}
}
},
});
}
};
// Let's initialize WPMF folder tree features
$(document).ready(function () {
if (typeof wp === "undefined") {
return;
}
if ((wpmf.vars.wpmf_pagenow === 'upload.php' && !wpmfFoldersModule.page_type) || typeof wp.media === "undefined") {
return;
}
if (wpmfFoldersModule.page_type !== 'upload-list') {
// Wait for the main wpmf module to be ready
wpmfFoldersModule.on('ready', function ($current_frame) {
if (!$('.upload-php .open-cloud-import').length) {
$('.upload-php .media-frame-content .media-toolbar-secondary').append('<button class="button open-cloud-import media-button button-large">' + wpmf.l18n.import_cloud_btn + '</button>');
$('.open-cloud-import').on('click', function () {
wpmfImportCloudModule.showdialog(true);
wpmfImportCloudModule.initModule();
wpmfFoldersModule.houtside();
});
if (typeof wpmfFoldersModule.categories[wpmfFoldersModule.last_selected_folder].drive_type !== "undefined" && wpmfFoldersModule.categories[wpmfFoldersModule.last_selected_folder].drive_type !== "") {
$('.open-cloud-import ').removeClass('hide');
} else {
$('.open-cloud-import ').addClass('hide');
}
wpmfFoldersModule.on('changeFolder', function (folder_id) {
if (typeof wpmfFoldersModule.categories[folder_id].drive_type !== "undefined" && wpmfFoldersModule.categories[folder_id].drive_type !== "") {
$('.open-cloud-import').removeClass('hide');
} else {
$('.open-cloud-import ').addClass('hide');
}
});
}
});
}
});
}(jQuery));

View File

@@ -0,0 +1,34 @@
(function ($) {
if (typeof ajaxurl === "undefined") {
ajaxurl = wpmf.vars.ajaxurl;
}
var current_import_page = 0;
$(document).ready(function () {
/**
* Import order
* @param current_import_page
*/
var wpmfImportOrder = function (current_import_page) {
/* Ajax import */
jQuery.ajax({
type: 'POST',
url: ajaxurl,
data: {
action: "wpmf",
task: 'import_order',
current_import_page: current_import_page,
wpmf_nonce: wpmf.vars.wpmf_nonce
},
success: function (res) {
if (!res.status) {
current_import_page++;
wpmfImportOrder(current_import_page);
}
}
});
};
wpmfImportOrder(current_import_page);
});
}(jQuery));

View File

@@ -0,0 +1,396 @@
var wpmfExternalCatsImportModule;
(function ($) {
wpmfExternalCatsImportModule = {
category_name: '',
categories: [],
categories_order: [],
init: function () {
$('.open_import_external_cats').on('click', function () {
wpmfExternalCatsImportModule.category_name = $(this).data('cat-name');
var title = '';
switch (wpmfExternalCatsImportModule.category_name) {
case "rml_category":
title = import_external_cats_objects.l18n.rml_label_dialog;
break;
case "media_category":
title = import_external_cats_objects.l18n.eml_label_dialog;
break;
case "happyfiles_category":
title = import_external_cats_objects.l18n.happyfiles_label_dialog;
break;
case "media_folder":
title = import_external_cats_objects.l18n.mf_label_dialog;
break;
case "filebird":
title = import_external_cats_objects.l18n.fbv_label_dialog;
break
}
var button = '<div class="wpmfexternal_cats_action">';
button += '<button class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect wpmfexternal_cats_button wpmfexternal_cats_import_all_btn">'+ import_external_cats_objects.l18n.import_all_label +'</button>';
button += '<button class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect wpmfexternal_cats_button wpmfexternal_cats_import_selected_btn">'+ import_external_cats_objects.l18n.import_selected_label +'</button>';
button += '<button class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect wpmfexternal_cats_button wpmfexternal_cats_cancel_btn">'+ import_external_cats_objects.l18n.cancel_label +'</button>';
button += '<span class="spinner" style="margin: 8px"></span>';
button += '</div>';
showDialog({
title: title,
id: 'import-external_cats-dialog',
text: '<div class="wpmfexternal_cats_categories_tree"></div>' + button
});
switch (wpmfExternalCatsImportModule.category_name) {
case "rml_category":
wpmfExternalCatsImportModule.categories_order = import_external_cats_objects.vars.rml_categories_order;
wpmfExternalCatsImportModule.categories = import_external_cats_objects.vars.rml_categories;
break;
case "media_category":
wpmfExternalCatsImportModule.categories_order = import_external_cats_objects.vars.media_category_categories_order;
wpmfExternalCatsImportModule.categories = import_external_cats_objects.vars.media_category_categories;
break;
case "happyfiles_category":
wpmfExternalCatsImportModule.categories_order = import_external_cats_objects.vars.happy_categories_order;
wpmfExternalCatsImportModule.categories = import_external_cats_objects.vars.happy_categories;
break;
case "media_folder":
wpmfExternalCatsImportModule.categories_order = import_external_cats_objects.vars.mf_categories_order;
wpmfExternalCatsImportModule.categories = import_external_cats_objects.vars.mf_categories;
break;
case "filebird":
wpmfExternalCatsImportModule.categories_order = import_external_cats_objects.vars.filebird_categories_order;
wpmfExternalCatsImportModule.categories = import_external_cats_objects.vars.filebird_categories;
break
}
wpmfExternalCatsImportModule.importCategories();
// Render the tree view
wpmfExternalCatsImportModule.loadTreeView();
wpmfExternalCatsImportModule.handleClick();
});
$('.wpmfexternal_cats_notice .wpmf-notice-dismiss').unbind('click').bind('click', function () {
$.ajax({
type: 'POST',
url: import_external_cats_objects.vars.ajaxurl,
data: {
action: "wpmf_update_external_cats_notice_flag",
wpmf_nonce: import_external_cats_objects.vars.wpmf_nonce
},
beforeSend: function () {
$('.wpmfexternal_cats_notice').remove();
},
success: function (res) {}
});
});
},
handleClick: function () {
$('.wpmfexternal_cats-check').unbind('click').bind('click', function () {
if ($(this).closest('.wpmfexternal_cats-item-check').hasClass('wpmfexternal_cats_checked')) {
$(this).closest('.wpmfexternal_cats-item-check').removeClass('wpmfexternal_cats_checked').addClass('wpmfexternal_cats_notchecked');
$(this).closest('li').find('ul .wpmfexternal_cats-item-check').removeClass('wpmfexternal_cats_checked').addClass('wpmfexternal_cats_notchecked');
} else {
$(this).closest('.wpmfexternal_cats-item-check').addClass('wpmfexternal_cats_checked').removeClass('wpmfexternal_cats_notchecked');
$(this).closest('li').find('ul .wpmfexternal_cats-item-check').addClass('wpmfexternal_cats_checked').removeClass('wpmfexternal_cats_notchecked');
}
var parents = $(this).parents('li');
$.each(parents, function (i, parent) {
var checked_length = $(parent).find(' > .wpmfexternal_cats_trees > li > .wpmfexternal_cats-item .wpmfexternal_cats_checked').length;
var not_checked_length = $(parent).find(' > .wpmfexternal_cats_trees > li > .wpmfexternal_cats-item .wpmfexternal_cats_notchecked').length;
if (checked_length && not_checked_length) {
$(parent).find('> .wpmfexternal_cats-item .wpmfexternal_cats-item-check').removeClass('wpmfexternal_cats_checked wpmfexternal_cats_notchecked').addClass('wpmfexternal_cats_part_checked');
}
if (checked_length && !not_checked_length) {
$(parent).find('> .wpmfexternal_cats-item .wpmfexternal_cats-item-check').removeClass('wpmfexternal_cats_part_checked wpmfexternal_cats_notchecked').addClass('wpmfexternal_cats_checked');
}
if (!checked_length && not_checked_length) {
$(parent).find('> .wpmfexternal_cats-item .wpmfexternal_cats-item-check').removeClass('wpmfexternal_cats_part_checked wpmfexternal_cats_checked').addClass('wpmfexternal_cats_notchecked');
}
});
if ($('.wpmfexternal_cats_checked').length) {
$('.wpmfexternal_cats_import_selected_btn').show();
$('.wpmfexternal_cats_import_all_btn').hide();
} else {
$('.wpmfexternal_cats_import_selected_btn').hide();
$('.wpmfexternal_cats_import_all_btn').show();
}
});
$('.wpmfexternal_cats_cancel_btn').unbind('click').bind('click', function () {
var dialod = $('#import-external_cats-dialog');
hideDialog(dialod);
});
$('.wpmfexternal_cats_import_all_btn').unbind('click').bind('click', function () {
wpmfExternalCatsImportModule.getAndInsertAllExternalCatsCategories(1);
});
$('.wpmfexternal_cats_import_selected_btn').unbind('click').bind('click', function () {
var ids = [];
$('.wpmfexternal_cats_checked').each(function (i, checkbox) {
var id = $(checkbox).closest('.wpmfexternal_cats-item').data('id');
if (parseInt(id) !== 0) {
ids.push(id);
}
});
if (ids.length) {
wpmfExternalCatsImportModule.getAndInsertAllExternalCatsCategories(1, 'selected', ids);
}
});
},
getAndInsertAllExternalCatsCategories: function (paged, type = 'all', ids = []) {
var data = {
paged: paged,
wpmf_nonce: import_external_cats_objects.vars.wpmf_nonce
};
switch (wpmfExternalCatsImportModule.category_name) {
case "rml_category":
data.action = 'wpmf_get_insert_rml_categories';
break;
case "media_category":
data.action = 'wpmf_get_insert_eml_categories';
break;
case "happyfiles_category":
data.action = 'wpmf_get_insert_happyfiles_categories';
break;
case "media_folder":
data.action = 'wpmf_get_insert_mf_categories';
break;
case "filebird":
data.action = 'wpmf_get_insert_fbv_categories';
break
}
if (type === 'selected') {
data.type = 'selected';
data.ids = ids.join();
}
$.ajax({
type: 'POST',
url: import_external_cats_objects.vars.ajaxurl,
data: data,
beforeSend: function () {
$('.wpmfexternal_cats_action .spinner').css('visibility', 'visible').show();
},
success: function (res) {
if (res.status) {
if (res.continue) {
wpmfExternalCatsImportModule.getAndInsertAllExternalCatsCategories(parseInt(paged) + 1, type, ids);
} else {
// update parent and add object
wpmfExternalCatsImportModule.updateParentForImportedExternalCatsFolder(1)
}
}
}
});
},
updateParentForImportedExternalCatsFolder: function (paged) {
var data = {
paged: paged,
wpmf_nonce: import_external_cats_objects.vars.wpmf_nonce
};
switch (wpmfExternalCatsImportModule.category_name) {
case "rml_category":
data.action = 'wpmf_update_rml_categories';
break;
case "media_category":
data.action = 'wpmf_update_eml_categories';
break;
case "happyfiles_category":
data.action = 'wpmf_update_happyfiles_categories';
break;
case "media_folder":
data.action = 'wpmf_update_mf_categories';
break;
case "filebird":
data.action = 'wpmf_update_fbv_categories';
break
}
$.ajax({
type: 'POST',
url: import_external_cats_objects.vars.ajaxurl,
data: data,
success: function (res) {
if (res.status) {
if (res.continue) {
wpmfExternalCatsImportModule.updateParentForImportedExternalCatsFolder(parseInt(paged) + 1)
} else {
$('.wpmfexternal_cats_action .spinner').hide();
$('.wpmfexternal_cats_notice').remove();
var dialod = $('#import-external_cats-dialog');
hideDialog(dialod);
if (import_external_cats_objects.vars.pagenow === 'upload.php') {
location.reload();
}
}
}
}
});
},
importCategories: function () {
var folders_ordered = [];
// Add each category
$(wpmfExternalCatsImportModule.categories_order).each(function () {
folders_ordered.push(wpmfExternalCatsImportModule.categories[this]);
});
// Reorder array based on children
var folders_ordered_deep = [];
var processed_ids = [];
var loadChildren = function loadChildren(id) {
if (processed_ids.indexOf(id) < 0) {
processed_ids.push(id);
for (var ij = 0; ij < folders_ordered.length; ij++) {
if (parseInt(folders_ordered[ij].parent_id) === parseInt(id)) {
folders_ordered_deep.push(folders_ordered[ij]);
loadChildren(folders_ordered[ij].id);
}
}
}
};
loadChildren(0);
// Finally save it to the global var
wpmfExternalCatsImportModule.categories = folders_ordered_deep;
},
/**
* Render tree view inside content
*/
loadTreeView: function () {
$('.wpmfexternal_cats_categories_tree').html(wpmfExternalCatsImportModule.getRendering());
},
/**
* Get the html resulting tree view
* @return {string}
*/
getRendering: function () {
var ij = 0;
var content = '';
/**
* Recursively print list of folders
* @return {boolean}
*/
var generateList = function () {
content += '<ul class="wpmfexternal_cats_trees">';
while (ij < wpmfExternalCatsImportModule.categories.length) {
var className = 'closed ';
// Open li tag
content += '<li class="' + className + '" data-id="' + wpmfExternalCatsImportModule.categories[ij].id + '">';
content += '<div class="wpmfexternal_cats-item" data-id="' + wpmfExternalCatsImportModule.categories[ij].id + '">';
content += '<div class="wpmfexternal_cats-item-inside" data-id="' + wpmfExternalCatsImportModule.categories[ij].id + '">';
var a_tag = '<a class="wpmfexternal_cats-text-item" data-id="' + wpmfExternalCatsImportModule.categories[ij].id + '">';
if (wpmfExternalCatsImportModule.categories[ij + 1] && wpmfExternalCatsImportModule.categories[ij + 1].depth > wpmfExternalCatsImportModule.categories[ij].depth) {
// The next element is a sub folder
content += '<a class="wpmfexternal_cats-toggle-icon" onclick="wpmfExternalCatsImportModule.toggle(' + wpmfExternalCatsImportModule.categories[ij].id + ')"><i class="material-icons wpmfexternal_cats-arrow">arrow_right</i></a>';
} else {
content += '<a class="wpmfexternal_cats-toggle-icon wpmfexternal_cats-notoggle-icon"><i class="material-icons wpmfexternal_cats-arrow">arrow_right</i></a>';
}
if (parseInt(wpmfExternalCatsImportModule.categories[ij].id) !== 0) {
content += '<a class="wpmfexternal_cats-item-check wpmfexternal_cats_notchecked"><span class="material-icons wpmfexternal_cats-check wpmfexternal_cats-item-checkbox-checked"> check_box </span><span class="material-icons wpmfexternal_cats-check wpmfexternal_cats-item-checkbox"> check_box_outline_blank </span><span class="material-icons wpmfexternal_cats-check wpmfexternal_cats-item-part-checkbox"> indeterminate_check_box </span></a>';
}
content += a_tag;
if (parseInt(wpmfExternalCatsImportModule.categories[ij].id) === 0) {
content += '<i class="wpmfexternal_cats-icon-root"></i>';
} else {
content += '<i class="material-icons wpmfexternal_cats-item-icon">folder</i>';
}
content += '<span class="wpmfexternal_cats-item-title" data-id="'+ wpmfExternalCatsImportModule.categories[ij].id +'">' + wpmfExternalCatsImportModule.categories[ij].label + '</span>';
content += '</a>';
content += '</div>';
content += '</div>';
// This is the end of the array
if (wpmfExternalCatsImportModule.categories[ij + 1] === undefined) {
// Let's close all opened tags
for (var ik = wpmfExternalCatsImportModule.categories[ij].depth; ik >= 0; ik--) {
content += '</li>';
content += '</ul>';
}
// We are at the end don't continue to process array
return false;
}
if (wpmfExternalCatsImportModule.categories[ij + 1].depth > wpmfExternalCatsImportModule.categories[ij].depth) {
// The next element is a sub folder
// Recursively list it
ij++;
if (generateList() === false) {
// We have reached the end, let's recursively end
return false;
}
} else if (wpmfExternalCatsImportModule.categories[ij + 1].depth < wpmfExternalCatsImportModule.categories[ij].depth) {
// The next element don't have the same parent
// Let's close opened tags
for (var _ik = wpmfExternalCatsImportModule.categories[ij].depth; _ik > wpmfExternalCatsImportModule.categories[ij + 1].depth; _ik--) {
content += '</li>';
content += '</ul>';
}
// We're not at the end of the array let's continue processing it
return true;
}
// Close the current element
content += '</li>';
ij++;
}
};
// Start generation
generateList();
return content;
},
/**
* Toggle the open / closed state of a folder
* @param folder_id
*/
toggle: function (folder_id) {
// Check is folder has closed class
if ($('.wpmfexternal_cats_categories_tree').find('li[data-id="' + folder_id + '"]').hasClass('closed')) {
// Open the folder
wpmfExternalCatsImportModule.openFolder(folder_id);
} else {
// Close the folder
wpmfExternalCatsImportModule.closeFolder(folder_id);
// close all sub folder
$('li[data-id="' + folder_id + '"]').find('li').addClass('closed');
}
},
/**
* Open a folder to show children
*/
openFolder: function (folder_id) {
$('.wpmfexternal_cats_categories_tree').find('li[data-id="' + folder_id + '"]').removeClass('closed');
},
/**
* Close a folder and hide children
*/
closeFolder: function (folder_id) {
$('.wpmfexternal_cats_categories_tree').find('li[data-id="' + folder_id + '"]').addClass('closed');
}
};
$(document).ready(function () {
wpmfExternalCatsImportModule.init();
});
})(jQuery);

View File

@@ -0,0 +1,50 @@
(function ($) {
if (typeof wpmfImportGallery === "undefined") {
return;
}
if (typeof ajaxurl === "undefined") {
ajaxurl = wpmfImportGallery.vars.ajaxurl;
}
$(document).ready(function () {
/**
* Import nextgen gallery
* @param doit true or false
* @param button
*/
var importWpmfgallery = function (doit, button) {
jQuery(button).closest("p").find(".spinner").show().css({"visibility": "visible"});
jQuery.post(ajaxurl, {
action: "import_gallery",
doit: doit,
wpmf_nonce: wpmfImportGallery.vars.wpmf_nonce
}, function (response) {
if (response === "error time") {
jQuery("#wmpfImportgallery").click();
} else {
jQuery(button).closest("div#wpmf_error").hide();
if (doit === true) {
jQuery("#wpmf_error").after("<div class='updated'> <p><strong>NextGEN galleries successfully imported in WP Media Folder</strong></p></div>");
}
}
});
};
/**
* import nextgen gallery
*/
$('#wmpfImportgallery').on('click', function () {
var $this = $(this);
importWpmfgallery(true, $this);
});
/**
* cancel import gallery button
*/
$('.wmpfNoImportgallery').on('click', function () {
var $this = $(this);
importWpmfgallery(false, $this);
});
});
}(jQuery));

View File

@@ -0,0 +1,39 @@
(function ($) {
if (typeof ajaxurl === "undefined") {
ajaxurl = wpmfimport.vars.ajaxurl;
}
$(document).ready(function () {
/**
* Import size and filetype
* @param page
*/
var wpmfimport_meta_size = function (page) {
var $this = jQuery('#wmpfImportsize');
$this.find(".spinner").show().css({"visibility": "visible"});
/* Ajax import */
jQuery.ajax({
type: 'POST',
url: ajaxurl,
data: {
action: "wpmf_import_size_filetype",
wpmf_current_page: page,
wpmf_nonce: wpmfimport.vars.wpmf_nonce
},
success: function (res) {
if (res.status) {
if (res.continue) {
wpmfimport_meta_size(parseInt(page) + 1)
} else {
$this.closest("div#wpmf_error").hide();
}
}
}
});
};
$('#wmpfImportsize').on('click', function () {
wpmfimport_meta_size(0);
});
});
}(jQuery));