plugin updates
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user