plugin updates
This commit is contained in:
@@ -91,6 +91,8 @@ class WpMediaFolder
|
||||
add_filter('pre_delete_attachment', array($this, 'preDeleteAttachment'), 10, 3);
|
||||
add_action('check_ajax_referer', array($this, 'disableSaveAjax'), 10, 2);
|
||||
add_filter('wp_insert_post_empty_content', array($this, 'disableSave'), 999999, 2);
|
||||
add_action('pre-upload-ui', array( $this, 'selectFolderUpload'));
|
||||
add_filter('add_attachment', array($this, 'moveFileUploadToSelectFolder'), 0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -617,7 +619,8 @@ class WpMediaFolder
|
||||
$video_url = (isset($_POST['video_url'])) ? $_POST['video_url'] : '';
|
||||
if (!preg_match(WpmfHelper::$vimeo_pattern, $video_url, $output_array)
|
||||
&& !preg_match('/(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/', $video_url, $match)
|
||||
&& !preg_match('/\b(?:dailymotion)\.com\b/i', $video_url, $vresult)) {
|
||||
&& !preg_match('/\b(?:dailymotion)\.com\b/i', $video_url, $vresult)
|
||||
&& !preg_match('/(videos.kaltura)\.com\b/i', $video_url, $vresult)) {
|
||||
wp_send_json(array('status' => false));
|
||||
} elseif (preg_match(WpmfHelper::$vimeo_pattern, $video_url, $output_array)) {
|
||||
// for vimeo
|
||||
@@ -681,6 +684,11 @@ class WpMediaFolder
|
||||
if (!empty($info['thumbnail_url'])) {
|
||||
$thumb_url = $info['thumbnail_url'];
|
||||
}
|
||||
} elseif (preg_match('/(videos.kaltura)\.com\b/i', $video_url, $vresult)) {
|
||||
// for kaltura
|
||||
$id = WpmfHelper::getKalturaVideoIdFromUrl($video_url);
|
||||
$partner_id = 5944002;
|
||||
$thumb_url = 'http://cdnsecakmi.kaltura.com/p/' . $partner_id . '/thumbnail/entry_id/' . $id . '/width/2560/height/1920';
|
||||
}
|
||||
|
||||
if (!empty($thumb_url)) {
|
||||
@@ -1009,6 +1017,50 @@ class WpMediaFolder
|
||||
wp_send_json(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load styles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadAssetsMediaUpload()
|
||||
{
|
||||
wp_enqueue_style(
|
||||
'wpmf-style',
|
||||
plugins_url('/assets/css/style.css', dirname(__FILE__)),
|
||||
array(),
|
||||
WPMF_VERSION
|
||||
);
|
||||
|
||||
wp_register_script(
|
||||
'wpmf-base',
|
||||
plugins_url('/assets/js/script.js', dirname(__FILE__)),
|
||||
array('jquery', 'plupload'),
|
||||
WPMF_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_script('wpmf-base');
|
||||
|
||||
wp_register_script(
|
||||
'wpmf-folder-upload',
|
||||
plugins_url('/assets/js/folder_upload.js', dirname(__FILE__)),
|
||||
array('jquery'),
|
||||
WPMF_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_script('wpmf-folder-upload');
|
||||
|
||||
wp_register_script(
|
||||
'wpmf-folder-tree',
|
||||
plugins_url('/assets/js/folder_tree.js', dirname(__FILE__)),
|
||||
array('wpmf-base'),
|
||||
WPMF_VERSION
|
||||
);
|
||||
wp_enqueue_script('wpmf-folder-tree');
|
||||
|
||||
$params = $this->localizeScript();
|
||||
wp_localize_script('wpmf-base', 'wpmf', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load styles
|
||||
*
|
||||
@@ -1018,7 +1070,7 @@ class WpMediaFolder
|
||||
{
|
||||
global $typenow, $current_screen;
|
||||
|
||||
if (WpmfHelper::isForThisPostType($typenow) && 'edit' == $current_screen->base) {
|
||||
if (WpmfHelper::isForThisPostType($typenow) && 'edit' === $current_screen->base) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1257,6 +1309,7 @@ class WpMediaFolder
|
||||
$this->loadAssets();
|
||||
}
|
||||
} elseif ($pagenow === 'media-new.php') {
|
||||
$this->loadAssetsMediaUpload();
|
||||
// Add current folder to hidden fields on media-new.php page
|
||||
add_filter('upload_post_params', function ($params) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No action, nonce is not required
|
||||
@@ -2113,11 +2166,11 @@ class WpMediaFolder
|
||||
public function getMultiFolderInfos($terms)
|
||||
{
|
||||
if (!$terms) {
|
||||
return [];
|
||||
return array();
|
||||
}
|
||||
$term_ids = array_keys($terms);
|
||||
$return = [];
|
||||
$drive_types = [];
|
||||
$return = array();
|
||||
$drive_types = array();
|
||||
|
||||
if (defined('WPMFAD_PLUGIN_DIR')) {
|
||||
$drive_types = $this->getDriveType($term_ids);
|
||||
@@ -2134,8 +2187,8 @@ class WpMediaFolder
|
||||
'parent_id' => $term->category_parent,
|
||||
'depth' => $term->depth,
|
||||
'term_group' => $term->term_group,
|
||||
'order' => $orders[$term_id] ?? '',
|
||||
'drive_type' => $drive_types[$term_id] ?? ''
|
||||
'order' => isset($orders[$term_id]) ? $orders[$term_id] : '',
|
||||
'drive_type' => isset($drive_types[$term_id]) ? $drive_types[$term_id] : ''
|
||||
);
|
||||
|
||||
// $view_media = WpmfHelper::getAccess($term->term_id, get_current_user_id(), 'view_media');
|
||||
@@ -5645,4 +5698,94 @@ class WpMediaFolder
|
||||
|
||||
return $exclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select Folder To Upload
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function selectFolderUpload()
|
||||
{
|
||||
if (strpos($_SERVER['REQUEST_URI'], 'media-new')) {
|
||||
?>
|
||||
<div class="wpmf-upload-inline">
|
||||
<label for="wpmfu"><?php esc_html_e('Choose folder: ', 'wpmf'); ?></label>
|
||||
<select class="wpmf-gallery-folder" data-wmpf-nonce="<?php echo esc_attr(wp_create_nonce('wpmf_nonce')) ?>"></select>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set file to current folder after upload files
|
||||
*
|
||||
* @param integer $attachment_id Id of attachment
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function moveFileUploadToSelectFolder($attachment_id)
|
||||
{
|
||||
if (isset($_POST['id_category'])) {
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user