plugin updates

This commit is contained in:
Tony Volpe
2024-11-15 13:53:04 -05:00
parent 1293d604ca
commit 0238f0c4ca
2009 changed files with 163492 additions and 89543 deletions

View File

@@ -26,4 +26,12 @@
height: 100%;
width: 100%;
max-width: 100%;
}
.wpmf-block-embed .wrapper-kaltura {
width: 50%;
}
.wrapper-kaltura-center {
text-align: -webkit-center;
}

View File

@@ -9,6 +9,11 @@ var wpmfGalleryModule;
var this_url = new URL(location.href);
var get_wpmf_folder = this_url.searchParams.get("wpmf-folder");
var last_selected_folder = wpmfFoldersModule.getCookie('lastAccessFolder_' + wpmf.vars.host);
//check folder upload same to last selected folder
if (last_selected_folder && get_wpmf_folder && last_selected_folder !== get_wpmf_folder) {
window.location.href = wpmf.vars.media_new_url + '?wpmf-folder=' + last_selected_folder;
};
wpmfGalleryModule = {
comment_parent: 0,
@@ -180,29 +185,71 @@ var wpmfGalleryModule;
wpmfGalleryModule.initPackery();
});
function check_local_to_cloud(id_category, wmpf_nonce, callback){
$.ajax({
method: "POST",
dataType: "json",
url: ajaxurl,
data: {
action: "wpmf",
task: 'check_local_to_cloud',
id_category: id_category,
wpmf_nonce: wmpf_nonce,
},
success: function success(response) {
callback(response.status);
},
});
}
// initialize WPMF gallery features
$(document).ready(function () {
wpmfGalleryModule.init();
var wmpf_nonce = $('.wpmf-gallery-folder').attr('data-wmpf-nonce');
uploader.bind('BeforeUpload', function(up, file) {
var multipart_params = up.settings.multipart_params;
multipart_params['wpmf_folder'] = 0;
if (get_wpmf_folder !== 'undefined') {
multipart_params['id_category'] = get_wpmf_folder;
multipart_params['wpmf_folder'] = get_wpmf_folder;
multipart_params['wpmf_nonce'] = wmpf_nonce;
}
up.settings.multipart_params = multipart_params;
});
$('.wpmf-gallery-folder').on('change', function(){
var id_category = $(this).val();
if (get_wpmf_folder) {
check_local_to_cloud(get_wpmf_folder, wmpf_nonce, function(is_local_to_cloud){
uploader.bind('BeforeUpload', function(up, file) {
var multipart_params = up.settings.multipart_params;
multipart_params['wpmf_nonce'] = wmpf_nonce;
multipart_params['no_move'] = 1;
multipart_params['wpmf_folder'] = get_wpmf_folder;
if (is_local_to_cloud) {
multipart_params['id_category'] = get_wpmf_folder;
multipart_params['no_move'] = null;
multipart_params['current_category'] = 0;
}
up.settings.multipart_params = multipart_params;
});
})
} else {
uploader.bind('BeforeUpload', function(up, file) {
var multipart_params = up.settings.multipart_params;
multipart_params['id_category'] = id_category;
multipart_params['wpmf_folder'] = id_category;
multipart_params['wpmf_folder'] = 0;
multipart_params['no_move'] = 1;
multipart_params['wpmf_nonce'] = wmpf_nonce;
if (get_wpmf_folder) {
multipart_params['wpmf_folder'] = get_wpmf_folder;
}
up.settings.multipart_params = multipart_params;
});
}
$('.wpmf-gallery-folder').on('change', function(){
var id_category = $(this).val();
//check local to cloud
check_local_to_cloud(id_category, wmpf_nonce, function(is_local_to_cloud){
uploader.bind('BeforeUpload', function(up, file) {
var multipart_params = up.settings.multipart_params;
multipart_params['wpmf_nonce'] = wmpf_nonce;
if (is_local_to_cloud) {
multipart_params['id_category'] = id_category;
multipart_params['no_move'] = null;
multipart_params['current_category'] = 0;
} else {
multipart_params['wpmf_folder'] = id_category;
}
up.settings.multipart_params = multipart_params;
});
})
});
});

View File

@@ -97,10 +97,15 @@ var wpmfReplaceModule;
$('#thumbnail-head-' + attachmentID + ' img').attr('src', old_url + '?ver=' + n);
} else {
var src_thumbnail = $thumb.attr('src');
$thumb.attr('src', src_thumbnail + '?ver=' + n);
var $img = $('.attachment-details').find('.thumbnail img');
var src_detail = $img.attr('src');
$img.attr('src', src_detail + '?ver=' + n);
if (ob.cloud_file_type === 'google_drive' || ob.cloud_file_type === 'onedrive_business' || ob.cloud_file_type === 'nextcloud') {
$thumb.attr('src', src_thumbnail + '&ver=' + n);
$img.attr('src', src_detail + '&ver=' + n);
} else {
$thumb.attr('src', src_thumbnail + '?ver=' + n);
$img.attr('src', src_detail + '?ver=' + n);
}
/* clear cache img */
wpmfReplaceModule.forceImgReload(src_thumbnail, false, null, false);
wpmfReplaceModule.forceImgReload(src_detail, false, null, false);

View File

@@ -181,6 +181,39 @@ var wpmfFoldersModule = void 0,
$('.page-title-action').after('<a href="#" class="wpmf_btn_upload_folder">' + wpmf.l18n.upload_folder_label + '</a><input name="id_category" class="wpmf_id_category" type="hidden" value="0">');
}
// Download file table list media
$('.wp-list-table .download').off('click').on('click', function (e){
e.preventDefault();
var post_id = $(this).parent().parent().parent().attr('id');
if (post_id) {
var post_id_array = post_id.split("-");
if (Array.isArray(post_id_array)) {
let id = post_id_array.pop();
if (id) {
$.ajax({
type: "POST",
url: wpmf.vars.ajaxurl,
data: {
action: "wpmf",
task: "wpmf_download_file",
id: id,
wpmf_nonce: wpmf.vars.wpmf_nonce
},
success: function success(response) {
if (response.status) {
window.location.href = wpmf.vars.site_url + '?act=wpmf_download_file&id=' + id + '&wpmf_nonce=' + wpmf.vars.wpmf_nonce;
} else {
showDialog({
text: wpmf.l18n.cannot_download,
closeicon: true
});
}
}
});
}
}
}
})
//Select tag for media
$('#doaction').on('click', function (e) {
var action = $('#bulk-action-selector-top').val();
@@ -512,17 +545,24 @@ var wpmfFoldersModule = void 0,
var upload_type = 'file';
$.extend(wp.Uploader.prototype, {
init: function init() {
// Add the current wpmf folder to the request
this.uploader.bind('BeforeUpload', function (t, e) {
e.wpmf_folder = typeof e.wpmf_folder !== "undefined" ? e.wpmf_folder : wpmfFoldersModule.last_selected_folder;
t.settings.multipart_params.wpmf_folder = e.wpmf_folder;
var file = e.getSource();
delete this.settings.multipart_params['relativePath'];
if (file.relativePath !== '') {
this.settings.multipart_params['relativePath'] = file.relativePath;
upload_type = 'folder';
}
});
var this_url = document.URL;
if (this_url.indexOf('media-new.php') < 0) {
// Add the current wpmf folder to the request
this.uploader.bind('BeforeUpload', function(up, e) {
e.wpmf_folder = typeof e.wpmf_folder !== "undefined" ? e.wpmf_folder : wpmfFoldersModule.last_selected_folder;
var file = e.getSource();
delete this.settings.multipart_params['relativePath'];
if (file.relativePath !== '') {
this.settings.multipart_params['relativePath'] = file.relativePath;
upload_type = 'folder';
}
var multipart_params = up.settings.multipart_params;
multipart_params['wpmf_nonce'] = wpmf.vars.wpmf_nonce;
multipart_params['no_move'] = 1;
multipart_params['wpmf_folder'] = e.wpmf_folder;
up.settings.multipart_params = multipart_params;
});
}
this.uploader.bind('FilesAdded', function (up, files) {
wpmfFoldersModule.added_files_length = parseInt(wpmfFoldersModule.added_files_length) + files.length;
@@ -1976,7 +2016,26 @@ var wpmfFoldersModule = void 0,
$('.material_downloadfile').off('click').on('click', function (e) {
e.preventDefault();
var id = $(this).data('id');
window.location.href = wpmf.vars.site_url + '?act=wpmf_download_file&id=' + id + '&wpmf_nonce=' + wpmf.vars.wpmf_nonce;
$.ajax({
type: "POST",
url: wpmf.vars.ajaxurl,
data: {
action: "wpmf",
task: "wpmf_download_file",
id: id,
wpmf_nonce: wpmf.vars.wpmf_nonce
},
success: function success(response) {
if (response.status) {
window.location.href = wpmf.vars.site_url + '?act=wpmf_download_file&id=' + id + '&wpmf_nonce=' + wpmf.vars.wpmf_nonce;
} else {
showDialog({
text: wpmf.l18n.cannot_download,
closeicon: true
});
}
}
});
});
$('.material_overridefile').off('click').on('click', function (e) {

View File

@@ -9,4 +9,14 @@ jQuery(document).ready(function ($) {
window.location.href = wpmf_single.vars.site_url + '?act=wpmf_download_file&id=' + id + '&wpmf_nonce=' + wpmf_single.vars.wpmf_nonce;
}
});
//remove black background iframe
$('.wpmf-block-embed__wrapper').find('iframe').each(function(){
var src = $(this).attr('src');
var check_video_kaltura = src.indexOf("kaltura")
if (check_video_kaltura > 0) {
$(this).parent().addClass('wrapper-kaltura');
$(this).parent().parent().addClass('wrapper-kaltura-center');
}
});
});

View File

@@ -576,13 +576,15 @@ input.ju-radiobox:focus {
}
.ju-main-wrapper .ju-right-panel .tabs.ju-top-tabs {
width: fit-content !important
/* width: fit-content !important */
flex-wrap: wrap;
}
.ju-main-wrapper .ju-right-panel .tabs.ju-top-tabs li.tab {
text-transform: capitalize;
min-width: 200px;
background-color: #fff
background-color: #fff;
width: 20%;
flex-grow: inherit;
}
.ju-main-wrapper .ju-right-panel .tabs.ju-top-tabs li.tab a.link-tab {
@@ -599,6 +601,10 @@ input.ju-radiobox:focus {
vertical-align: middle
}
.ju-main-wrapper .ju-right-panel .tabs.ju-top-tabs li:has(> a.active) {
border-bottom: 3px solid #ff8726;
}
.ju-main-wrapper .ju-right-panel .tabs.ju-top-tabs li.tab a.link-tab:focus {
-webkit-box-shadow: none;
-moz-box-shadow: none;

View File

@@ -36,23 +36,23 @@
$($content).show();
// append indicator then set indicator width to tab width
$this.append('<div class="indicator"></div>');
var $indicator = $this.find('.indicator');
if ($this.is(":visible")) {
$indicator.css({"right": $tabs_width - (($index + 1) * $tab_width)});
$indicator.css({"left": $index * $tab_width});
}
$(window).resize(function () {
$tabs_width = $this.width();
$tab_width = $this.find('li').first().outerWidth();
if ($index < 0) {
$index = 0;
}
if ($tab_width !== 0 && $tabs_width !== 0) {
$indicator.css({"right": $tabs_width - (($index + 1) * $tab_width)});
$indicator.css({"left": $index * $tab_width});
}
});
// $this.append('<div class="indicator"></div>');
// var $indicator = $this.find('.indicator');
// if ($this.is(":visible")) {
// $indicator.css({"right": $tabs_width - (($index + 1) * $tab_width)});
// $indicator.css({"left": $index * $tab_width});
// }
// $(window).resize(function () {
// $tabs_width = $this.width();
// $tab_width = $this.find('li').first().outerWidth();
// if ($index < 0) {
// $index = 0;
// }
// if ($tab_width !== 0 && $tabs_width !== 0) {
// $indicator.css({"right": $tabs_width - (($index + 1) * $tab_width)});
// $indicator.css({"left": $index * $tab_width});
// }
// });
// Hide the remaining content
$links.not($active).each(function () {

View File

@@ -403,8 +403,12 @@ class WpmfDisplayGallery
$query = new WP_Query($args);
$_attachments = $query->get_posts();
$gallery_items = array();
$last_folder_parent = $this->getFolderParent($wpmf_folder_id[0]);
foreach ($_attachments as $key => $val) {
$gallery_items[$val->ID] = $_attachments[$key];
if (($last_folder_parent->slug !== 'nextcloud' || !strpos($val->post_mime_type, 'avif')) && !strpos($val->post_mime_type, 'pdf')) { // hide file pdf and avif in nextcloud folder
$gallery_items[$val->ID] = $_attachments[$key];
}
}
} else {
$args = array(
@@ -1141,9 +1145,10 @@ class WpmfDisplayGallery
$query = new WP_Query($args);
$attachments = $query->get_posts();
$last_folder_parent = $this->getFolderParent($folders[0]);
$list_images = array();
foreach ($attachments as $attachment) {
if (strpos($attachment->post_mime_type, 'image') !== false) {
if (strpos($attachment->post_mime_type, 'image') !== false && ($last_folder_parent->slug !== 'nextcloud' || !strpos($attachment->post_mime_type, 'avif'))) {
$custom_link = get_post_meta($attachment->ID, _WPMF_GALLERY_PREFIX . 'custom_image_link', true);
$target = get_post_meta($attachment->ID, '_gallery_link_target', true);
$details = array(
@@ -1174,6 +1179,26 @@ class WpmfDisplayGallery
wp_send_json(array('status' => true, 'images' => $list_images));
}
/**
* Get last folder parent
*
* @param integer $folder_id Folder ID
*
* @return object
*/
public function getFolderParent($folder_id)
{
if ($folder_id) {
$term = get_term($folder_id, 'wpmf-category');
if ($term && $term->parent) {
$parent = $this->getFolderParent($term->parent);
} else {
return $term;
}
}
return $parent;
}
/**
* Get lightbox URL and type
*

View File

@@ -370,19 +370,25 @@ class WpmfHelper
/**
* Create thumbnail after replace
*
* @param string $filepath Physical path of file
* @param string $extimage Extension of file
* @param array $metadata Meta data of file
* @param integer $post_id ID of file
* @param string $filepath Physical path of file
* @param string $extimage Extension of file
* @param array $metadata Meta data of file
* @param integer $post_id ID of file
* @param boolean $isOffload Check file is AWS
*
* @return void
*/
public static function createThumbs($filepath, $extimage, $metadata, $post_id)
public static function createThumbs($filepath, $extimage, $metadata, $post_id, $isOffload = false)
{
if (isset($metadata['sizes']) && is_array($metadata['sizes'])) {
$uploadpath = wp_upload_dir();
foreach ($metadata['sizes'] as $size => $sizeinfo) {
$intermediate_file = str_replace(basename($filepath), $sizeinfo['file'], $filepath);
if ($isOffload) {
$filepath = apply_filters('wp_get_attachment_url', $filepath, $post_id);
$physicalPath = get_attached_file($post_id);
$intermediate_file = str_replace(basename($physicalPath), $sizeinfo['file'], $physicalPath);
}
// load image and get image size
list($width, $height) = getimagesize($filepath);
@@ -450,6 +456,18 @@ class WpmfHelper
$metadata[$size]['width'] = $new_width;
$metadata[$size]['width'] = $new_height;
wp_update_attachment_metadata($post_id, $metadata);
if ($isOffload) {
$physicalPath = path_join($uploadpath['basedir'], $intermediate_file);
if (file_exists($physicalPath)) {
$awsS3infos = get_post_meta($post_id, 'wpmf_awsS3_info', true);
if (isset($awsS3infos['Key'])) {
$intermediate_file = str_replace(basename($awsS3infos['Key']), $sizeinfo['file'], $awsS3infos['Key']);
apply_filters('wpmfAddonReplaceFileOffload', file_get_contents($physicalPath), $intermediate_file);
}
unlink($physicalPath);
}
}
}
} else {
wp_update_attachment_metadata($post_id, $metadata);

View File

@@ -45,9 +45,9 @@ class WpmfWatermark
}
if (!empty($attachment_id)) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
$galleryid = (int)$_POST['up_gallery_id'];
if (is_plugin_active('wp-media-folder-gallery-addon/wp-media-folder-gallery-addon.php')) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
$galleryid = isset($_POST['up_gallery_id']) ? (int)$_POST['up_gallery_id'] : 0;
$watermark_exclude_public_gallery = wpmfGetOption('watermark_exclude_public_gallery');
$watermark_exclude_photograph_gallery = wpmfGetOption('watermark_exclude_photograph_gallery');
$check = false;

View File

@@ -627,6 +627,12 @@ class WpMediaFolder
case 'auto_load_video_thumbnail':
$this->autoLoadVideoThumbnail();
break;
case 'check_local_to_cloud':
$this->checkLocalToCloud();
break;
case 'wpmf_download_file':
$this->wpmfDownloadFile();
break;
case 'get_tag_item':
$this->getTagItem();
break;
@@ -2004,7 +2010,8 @@ class WpMediaFolder
'remove_file_permission_msg' => esc_html__('You do not have permission to delete this file. Refresh folder to see image again', 'wpmf'),
'remove_file_permission_msg1' => esc_html__('You do not have permission to delete this file', 'wpmf'),
'update_file_permission_msg' => esc_html__('You do not have permission to update this file', 'wpmf'),
'select_file_required' => esc_html__('Please select file to do this action', 'wpmf')
'select_file_required' => esc_html__('Please select file to do this action', 'wpmf'),
'cannot_download' => esc_html__('This file cannot be downloaded.', 'wpmf')
);
return $l18n;
@@ -3079,94 +3086,96 @@ class WpMediaFolder
*/
public function afterUpload($attachment_id)
{
// Get the parent folder from the post request
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
if (isset($_POST['wpmf_folder'])) {
// phpcs:disable WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
$parent = (int)$_POST['wpmf_folder'];
$folder = (int)$_POST['wpmf_folder'];
// phpcs:enable
} else {
if ($this->user_full_access) {
$parent = 0;
if (!isset($_POST['id_category']) && isset($_POST['wpmf_nonce']) && wp_verify_nonce($_POST['wpmf_nonce'], 'wpmf_nonce')) {
// Get the parent folder from the post request
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
if (isset($_POST['wpmf_folder'])) {
// phpcs:disable WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
$parent = (int)$_POST['wpmf_folder'];
$folder = (int)$_POST['wpmf_folder'];
// phpcs:enable
} else {
if ($this->user_full_access) {
$parent = 0;
}
$folder = 0;
}
$folder = 0;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
$relativePath = isset($_POST['relativePath']) ? $_POST['relativePath'] : '';
if ($relativePath !== '') {
$relativePath = html_entity_decode($relativePath, ENT_COMPAT, 'UTF-8');
if ($relativePath) {
$fileUploadName = basename($relativePath);
$fileRelativePath = str_replace($fileUploadName, '', $relativePath);
if ($fileRelativePath) {
$newCatID = $this->getCategoryByPath($fileRelativePath, $parent);
if ($newCatID) {
$parent = $newCatID;
} else {
$folder_name = basename($fileRelativePath);
$parent_path = dirname($fileRelativePath) . '/';
// create folder & sub folder
$parent_paths = explode('/', $parent_path);
$pr = $parent;
foreach ($parent_paths as $pp) {
if ($pp !== '' && $pp !== '.' && $pp !== '\\') {
$inserted = wp_insert_term($pp, WPMF_TAXO, array('parent' => $pr));
if (is_wp_error($inserted)) {
$pr = $inserted->error_data['term_exists'];
} else {
$pr = $inserted['term_id'];
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
$relativePath = isset($_POST['relativePath']) ? $_POST['relativePath'] : '';
if ($relativePath !== '') {
$relativePath = html_entity_decode($relativePath, ENT_COMPAT, 'UTF-8');
if ($relativePath) {
$fileUploadName = basename($relativePath);
$fileRelativePath = str_replace($fileUploadName, '', $relativePath);
if ($fileRelativePath) {
$newCatID = $this->getCategoryByPath($fileRelativePath, $parent);
if ($newCatID) {
$parent = $newCatID;
} else {
$folder_name = basename($fileRelativePath);
$parent_path = dirname($fileRelativePath) . '/';
// create folder & sub folder
$parent_paths = explode('/', $parent_path);
$pr = $parent;
foreach ($parent_paths as $pp) {
if ($pp !== '' && $pp !== '.' && $pp !== '\\') {
$inserted = wp_insert_term($pp, WPMF_TAXO, array('parent' => $pr));
if (is_wp_error($inserted)) {
$pr = $inserted->error_data['term_exists'];
} else {
$pr = $inserted['term_id'];
}
}
}
}
if ($parent_path === './' || dirname($fileRelativePath) === '/') {
$inserted = wp_insert_term($folder_name, WPMF_TAXO, array('parent' => $parent));
} else {
$parent_id = $this->getCategoryByPath($parent_path, $parent);
$inserted = wp_insert_term($folder_name, WPMF_TAXO, array('parent' => $parent_id));
}
if ($parent_path === './' || dirname($fileRelativePath) === '/') {
$inserted = wp_insert_term($folder_name, WPMF_TAXO, array('parent' => $parent));
} else {
$parent_id = $this->getCategoryByPath($parent_path, $parent);
$inserted = wp_insert_term($folder_name, WPMF_TAXO, array('parent' => $parent_id));
}
if (!is_wp_error($inserted)) {
$parent = $inserted['term_id'];
if (!is_wp_error($inserted)) {
$parent = $inserted['term_id'];
}
}
if ($parent === 0) {
$parent = $this->getFolderParent($parent, $folder);
}
}
if ($parent === 0) {
$parent = $this->getFolderParent($parent, $folder);
}
}
} else {
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
$parent = $this->getFolderParent($parent, $folder);
}
} else {
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
$parent = $this->getFolderParent($parent, $folder);
}
$post_upload = get_post($attachment_id);
// only set object to term when upload files from media library screen
if (!empty($post_upload) && !strpos($post_upload->post_content, 'wpmf-nextgen-image')
&& !strpos($post_upload->post_content, '[wpmf-ftp-import]')) {
if ($parent) {
wp_set_object_terms($attachment_id, $parent, WPMF_TAXO, true);
$post_upload = get_post($attachment_id);
// only set object to term when upload files from media library screen
if (!empty($post_upload) && !strpos($post_upload->post_content, 'wpmf-nextgen-image')
&& !strpos($post_upload->post_content, '[wpmf-ftp-import]')) {
if ($parent) {
wp_set_object_terms($attachment_id, $parent, WPMF_TAXO, true);
/**
* Set attachmnent folder after upload
*
* @param integer Attachment ID
* @param integer Target folder
* @param array Extra informations
*
* @ignore Hook already documented
*/
do_action('wpmf_attachment_set_folder', $attachment_id, $parent, array('trigger' => 'upload'));
/**
* Set attachmnent folder after upload
*
* @param integer Attachment ID
* @param integer Target folder
* @param array Extra informations
*
* @ignore Hook already documented
*/
do_action('wpmf_attachment_set_folder', $attachment_id, $parent, array('trigger' => 'upload'));
}
}
}
if (!empty($attachment_id)) {
$this->addSizeFiletype($attachment_id);
// add custom order position
if (!metadata_exists('post', $attachment_id, 'wpmf_order')) {
add_post_meta($attachment_id, 'wpmf_order', 0);
if (!empty($attachment_id)) {
$this->addSizeFiletype($attachment_id);
// add custom order position
if (!metadata_exists('post', $attachment_id, 'wpmf_order')) {
add_post_meta($attachment_id, 'wpmf_order', 0);
}
}
}
}
@@ -3393,10 +3402,10 @@ class WpMediaFolder
*
* @ignore Hook already documented
*/
do_action('wpmf_create_folder', $inserted['term_id'], $pp, $pr, array('trigger' => 'media_library_action'));
if (is_wp_error($inserted)) {
$pr = $inserted->error_data['term_exists'];
} else {
do_action('wpmf_create_folder', $inserted['term_id'], $pp, $pr, array('trigger' => 'media_library_action'));
$pr = $inserted['term_id'];
}
}
@@ -4357,8 +4366,9 @@ class WpMediaFolder
}
}
}
wp_send_json(array('status' => $return, 'is_local_to_cloud' => $is_local_to_cloud));
if (!isset($_POST['no_return'])) {
wp_send_json(array('status' => $return, 'is_local_to_cloud' => $is_local_to_cloud));
}
}
/**
@@ -5788,64 +5798,21 @@ class WpMediaFolder
public function moveFileUploadToSelectFolder($attachment_id)
{
if (isset($_POST['id_category']) && isset($_POST['wpmf_nonce'])) {
$_POST['ids'][] = $attachment_id;
$_POST['no_return'] = 1;
if (empty($_POST['wpmf_nonce']) || !wp_verify_nonce($_POST['wpmf_nonce'], 'wpmf_nonce')) {
die();
}
if ($attachment_id) {
//move file
$_POST['ids'][] = $attachment_id;
$parent = $this->getFolderParent($_POST['id_category'], $_POST['id_category']);
$user_id = get_current_user_id();
$is_access = WpmfHelper::getAccess($parent, $user_id, 'move_media');
if (empty($_POST['current_category'])) {
$is_access1 = true;
} else {
$is_access1 = WpmfHelper::getAccess($_POST['current_category'], $user_id, 'move_media');
}
if (!$is_access || !$is_access1) {
wp_send_json(array('status' => false, 'msg' => esc_html__('You not have a permission to move the file to this folder!', 'wpmf')));
}
// check current folder
$current_category = $this->folderRootId;
if (!empty($_POST['ids']) && is_array($_POST['ids'])) {
foreach (array_unique($_POST['ids']) as $id) {
$cloud_file_type = wpmfGetCloudFileType($id);
$cloud_folder_type = wpmfGetCloudFolderType($parent);
$file_s3_infos = get_post_meta((int) $id, 'wpmf_awsS3_info', true);
if (($cloud_file_type === $cloud_folder_type) || ($cloud_file_type === 'local' && $cloud_folder_type !== 'local' && empty($file_s3_infos))) {
// compability with WPML plugin
WpmfHelper::moveFileWpml($id, $current_category, $parent);
wp_remove_object_terms((int) $id, $current_category, WPMF_TAXO);
if ((int)$parent === 0 || wp_set_object_terms((int) $id, (int)$parent, WPMF_TAXO, true)) {
$params = array('trigger' => 'move_attachment');
if (($cloud_file_type === 'local' && $cloud_folder_type !== 'local' && empty($file_s3_infos))) {
$params['local_to_cloud'] = 1;
}
/**
* Set attachment folder after moving an attachment to a folder in the media manager
* This hook is also used when importing attachment to categories, after an attachment upload and
* when assigning multiple folder to an attachment
*
* @param integer Attachment ID
* @param integer|array Target folder or array of target folders
* @param array Extra informations
*/
do_action('wpmf_attachment_set_folder', $id, (int)$parent, $params);
// reset order
update_post_meta(
(int) $id,
'wpmf_order',
0
);
}
}
}
// check is local or cloud
$cloud_file_type = wpmfGetCloudFileType($attachment_id);
$cloud_folder_type = wpmfGetCloudFolderType($parent);
$file_s3_infos = get_post_meta((int) $attachment_id, 'wpmf_awsS3_info', true);
if ($cloud_file_type === 'local' && $cloud_folder_type !== 'local' && empty($file_s3_infos)) {
$this->moveFile();
}
}
}
@@ -5956,6 +5923,60 @@ class WpMediaFolder
}
}
/**
* Check file local to cloud
*
* @return void
*/
public function checkLocalToCloud()
{
if (empty($_POST['wpmf_nonce'])
|| !wp_verify_nonce($_POST['wpmf_nonce'], 'wpmf_nonce')) {
die();
}
$cloud_folder_type = wpmfGetCloudFolderType($_POST['id_category']);
if ($cloud_folder_type !== 'local') {
wp_send_json(array('status' => true));
}
wp_send_json(array('status' => false));
}
/**
* Download file
*
* @return void
*/
public function wpmfDownloadFile()
{
if (empty($_POST['wpmf_nonce'])
|| !wp_verify_nonce($_POST['wpmf_nonce'], 'wpmf_nonce')) {
die();
}
$file_id = (isset($_POST['id'])) ? intval($_POST['id']) : 0;
if (!empty($file_id)) {
$path = get_attached_file($file_id);
if (file_exists($path)) {
wp_send_json(array('status' => true));
} else {
$drive_type = get_post_meta($file_id, 'wpmf_drive_type', true);
if (!empty($drive_type)) {
if (!is_plugin_active('wp-media-folder-addon/wp-media-folder-addon.php')) {
die();
}
$drive_id = get_post_meta($file_id, 'wpmf_drive_id', true);
if (!empty($drive_id)) {
wp_send_json(array('status' => true));
}
wp_send_json(array('status' => false));
}
wp_send_json(array('status' => false));
}
}
wp_send_json(array('status' => false));
}
/**
* Add tag helps
*
@@ -5978,11 +5999,13 @@ class WpMediaFolder
*/
public function addTagFilter($query)
{
$query->unset('wpmf_tag');
if (isset($_COOKIE['wpmf_tag']) && !empty($_COOKIE['wpmf_tag'])) {
$query->set('wpmf_tag', $_COOKIE['wpmf_tag']);
} else {
$query->unset('wpmf_tag');
if (isset($query->query['post_type']) && $query->query['post_type'] === 'attachment') {
if (isset($query->query['wpmf_tag'])) {
$query->unset('wpmf_tag');
}
if (isset($_COOKIE['wpmf_tag']) && !empty($_COOKIE['wpmf_tag']) && $_COOKIE['wpmf_tag'] !== 'uncategorized') {
$query->set('wpmf_tag', $_COOKIE['wpmf_tag']);
}
}
}

View File

@@ -54,15 +54,41 @@ class WpmfReplaceFile
$id = $_POST['post_selected'];
$metadata = wp_get_attachment_metadata($id);
$filepath = get_attached_file($id);
$infopath = pathinfo($filepath);
$allowedImageTypes = array('gif', 'jpg', 'png', 'bmp', 'webp', 'pdf');
$new_filetype = wp_check_filetype($_FILES['wpmf_replace_file']['name']);
if ($new_filetype['ext'] === 'jpeg') {
$new_filetype['ext'] = 'jpg';
}
$cloud_file_type = wpmfGetCloudFileType($id);
$awsS3infos = get_post_meta($id, 'wpmf_awsS3_info', true);
$isLocal = false;
if ($cloud_file_type === 'local' && empty($awsS3infos)) {
$isLocal = true;
}
if ($isLocal || empty($awsS3infos)) {
$filepath = get_attached_file($id);
if ($cloud_file_type === 'nextcloud') {
$filepath = get_post_meta($id, 'wpmf_drive_path', true);
}
} else {
if (isset($awsS3infos['Key'])) {
$cloud_file_type = 'offload';
$filepath = $awsS3infos['Key'];
$localPath = get_attached_file($id);
} else {
wp_send_json(
array(
'status' => false,
'msg' => __('File doesn\'t exist', 'wpmf')
)
);
}
}
$infopath = pathinfo($filepath);
if ($infopath['extension'] === 'jpeg') {
$infopath['extension'] = 'jpg';
}
@@ -70,8 +96,7 @@ class WpmfReplaceFile
wp_send_json(
array(
'status' => false,
'msg' => __('To replace a media and keep the link to this media working,
it must be in the same format, ie. jpg > jpg… Thanks!', 'wpmf')
'msg' => __('To replace a media and keep the link to this media working, it must be in the same format, ie. jpg > jpg… Thanks!', 'wpmf')
)
);
}
@@ -86,51 +111,129 @@ it must be in the same format, ie. jpg > jpg… Thanks!', 'wpmf')
} else {
$uploadpath = wp_upload_dir();
if (!file_exists($filepath)) {
wp_send_json(
array(
'status' => false,
'msg' => __('File doesn\'t exist', 'wpmf')
)
);
if ($isLocal) {
wp_send_json(
array(
'status' => false,
'msg' => __('File doesn\'t exist', 'wpmf')
)
);
}
} else {
wp_delete_file($filepath);
}
wp_delete_file($filepath);
if (in_array($infopath['extension'], $allowedImageTypes)) {
if (isset($metadata['sizes']) && is_array($metadata['sizes'])) {
foreach ($metadata['sizes'] as $size => $sizeinfo) {
$intermediate_file = str_replace(basename($filepath), $sizeinfo['file'], $filepath);
// This filter is documented in wp-includes/functions.php
$intermediate_file = apply_filters('wp_delete_file', $intermediate_file);
$link = path_join(
$uploadpath['basedir'],
$intermediate_file
);
if (file_exists($link) && is_writable($link)) {
unlink($link);
if ($isLocal) {
if (in_array($infopath['extension'], $allowedImageTypes)) {
if (isset($metadata['sizes']) && is_array($metadata['sizes'])) {
foreach ($metadata['sizes'] as $size => $sizeinfo) {
$intermediate_file = str_replace(basename($filepath), $sizeinfo['file'], $filepath);
// This filter is documented in wp-includes/functions.php
$intermediate_file = apply_filters('wp_delete_file', $intermediate_file);
$link = path_join(
$uploadpath['basedir'],
$intermediate_file
);
if (file_exists($link) && is_writable($link)) {
unlink($link);
}
}
}
}
}
move_uploaded_file(
$_FILES['wpmf_replace_file']['tmp_name'],
$infopath['dirname'] . '/' . $infopath['basename']
);
update_post_meta($id, 'wpmf_size', filesize($infopath['dirname'] . '/' . $infopath['basename']));
move_uploaded_file(
$_FILES['wpmf_replace_file']['tmp_name'],
$infopath['dirname'] . '/' . $infopath['basename']
);
update_post_meta($id, 'wpmf_size', filesize($infopath['dirname'] . '/' . $infopath['basename']));
if ($infopath['extension'] === 'pdf') {
WpmfHelper::createPdfThumbnail($filepath);
}
if ($infopath['extension'] === 'pdf') {
WpmfHelper::createPdfThumbnail($filepath);
}
if (in_array($infopath['extension'], $allowedImageTypes)) {
if ($infopath['extension'] !== 'pdf') {
$actual_sizes_array = getimagesize($filepath);
$metadata['width'] = $actual_sizes_array[0];
$metadata['height'] = $actual_sizes_array[1];
WpmfHelper::createThumbs($filepath, $infopath['extension'], $metadata, $id);
}
}
do_action('wpmf_after_file_replace', $infopath, $id);
} else {
$newContent = file_get_contents($_FILES['wpmf_replace_file']['tmp_name']);
switch ($cloud_file_type) {
case 'offload':
if (isset($localPath) && file_exists($localPath)) {
wp_delete_file($localPath);
if (in_array($infopath['extension'], $allowedImageTypes)) {
if (isset($metadata['sizes']) && is_array($metadata['sizes'])) {
foreach ($metadata['sizes'] as $size => $sizeinfo) {
$intermediate_file = str_replace(basename($localPath), $sizeinfo['file'], $localPath);
// This filter is documented in wp-includes/functions.php
$intermediate_file = apply_filters('wp_delete_file', $intermediate_file);
$link = path_join(
$uploadpath['basedir'],
$intermediate_file
);
if (file_exists($link) && is_writable($link)) {
unlink($link);
}
}
}
}
if (in_array($infopath['extension'], $allowedImageTypes)) {
if ($infopath['extension'] !== 'pdf') {
$actual_sizes_array = getimagesize($filepath);
$metadata['width'] = $actual_sizes_array[0];
$metadata['height'] = $actual_sizes_array[1];
WpmfHelper::createThumbs($filepath, $infopath['extension'], $metadata, $id);
move_uploaded_file(
$_FILES['wpmf_replace_file']['tmp_name'],
$infopath['dirname'] . '/' . $infopath['basename']
);
update_post_meta($id, 'wpmf_size', filesize($infopath['dirname'] . '/' . $infopath['basename']));
if ($infopath['extension'] === 'pdf') {
WpmfHelper::createPdfThumbnail($localPath);
}
if (in_array($infopath['extension'], $allowedImageTypes)) {
if ($infopath['extension'] !== 'pdf') {
$actual_sizes_array = getimagesize($localPath);
$metadata['width'] = $actual_sizes_array[0];
$metadata['height'] = $actual_sizes_array[1];
WpmfHelper::createThumbs($localPath, $infopath['extension'], $metadata, $id);
}
}
}
apply_filters('wpmfAddonReplaceFileOffload', $newContent, $filepath);
$s3FilePath = apply_filters('wp_get_attachment_url', $filepath, $id);
if (in_array($infopath['extension'], $allowedImageTypes)) {
if ($infopath['extension'] !== 'pdf') {
$actual_sizes_array = getimagesize($s3FilePath);
$metadata['width'] = $actual_sizes_array[0];
$metadata['height'] = $actual_sizes_array[1];
WpmfHelper::createThumbs($filepath, $infopath['extension'], $metadata, $id, true);
}
}
break;
case 'google_drive':
apply_filters('wpmfAddonReplaceFileGGD', $newContent, $id);
break;
case 'dropbox':
apply_filters('wpmfAddonReplaceFileDropbox', $newContent, $id);
break;
case 'onedrive':
apply_filters('wpmfAddonReplaceFileOnedrive', $newContent, $id);
break;
case 'onedrive_business':
apply_filters('wpmfAddonReplaceFileOnedriveBusiness', $newContent, $id);
break;
case 'nextcloud':
apply_filters('wpmfAddonReplaceFileNextcloud', $newContent, $filepath);
break;
default:
break;
}
}
do_action('wpmf_after_file_replace', $infopath, $id);
if (isset($_FILES['wpmf_replace_file']['size'])) {
$size = $_FILES['wpmf_replace_file']['size'];
$metadata = wp_get_attachment_metadata($id);
@@ -190,7 +293,7 @@ it must be in the same format, ie. jpg > jpg… Thanks!', 'wpmf')
if (in_array($infopath['extension'], $allowedImageTypes) && $infopath['extension'] !== 'pdf') {
$metadata = wp_get_attachment_metadata($id);
$dimensions = $metadata['width'] . ' x ' . $metadata['height'];
wp_send_json(array('status' => true, 'size' => $size, 'dimensions' => $dimensions));
wp_send_json(array('status' => true, 'size' => $size, 'dimensions' => $dimensions, 'cloud_file_type' => $cloud_file_type));
} else {
wp_send_json(array('status' => true, 'size' => $size));
}

View File

@@ -176,10 +176,12 @@ class JUQueueActions
'update_database' => false,
'action' => 'wpmf_physical_folders'
);
JUQueueHelper::moveFile($datas);
if (!isset($_POST['no_move']) && wp_verify_nonce($_POST['wpmf_nonce'], 'wpmf_nonce')) {
JUQueueHelper::moveFile($datas);
}
}
if (isset($data['file'])) {
if (isset($data['file']) && isset($destination) && $destination) {
$dirname = _wp_get_attachment_relative_path($data['file']);
if ($dirname) {
$dirname = trailingslashit($dirname);

View File

@@ -3,7 +3,7 @@ Tags: media, folder
Requires at least: 4.7.0
Tested up to: 6.6
Requires PHP: 5.6
Stable tag: 5.9.8
Stable tag: 5.9.10
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -20,6 +20,13 @@ Stop searching for an image through thousand of media, just navigate like you do
= Changelog =
= 5.9.10 =
* Fix : Upload file to wrong folder in specific case
* Fix : A PHP warning
= 5.9.9 =
* Fix : Conflict with Woocomerce product listing in dashboard
= 5.9.8 =
* Add : Create tags: Possibility to create tags for media files
* Add : Bulk add tags: You can add tags to multiple media files at once.

View File

@@ -4,7 +4,7 @@
Plugin URI: http://www.joomunited.com
Description: WP media Folder is a WordPress plugin that enhance the WordPress media manager by adding a folder manager inside.
Author: Joomunited
Version: 5.9.8
Version: 5.9.10
Update URI: https://www.joomunited.com/juupdater_files/wp-media-folder.json
Author URI: http://www.joomunited.com
Text Domain: wpmf
@@ -79,7 +79,7 @@ if (!defined('WPMF_TAXO')) {
define('_WPMF_GALLERY_PREFIX', '_wpmf_gallery_');
define('WPMF_PLUGIN_URL', plugin_dir_url(__FILE__));
define('WPMF_DOMAIN', 'wpmf');
define('WPMF_VERSION', '5.9.8');
define('WPMF_VERSION', '5.9.10');
define('WPMF_HIDE_USER_MEDIA_FOLDER_ROOT', true);
include_once(ABSPATH . 'wp-admin/includes/plugin.php');