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

@@ -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);