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

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