plugin updates
This commit is contained in:
@@ -41,68 +41,19 @@ class WpmfFolderAccess
|
||||
$wpmf_capability = apply_filters('wpmf_user_can', current_user_can('upload_files'), 'create_user_folder');
|
||||
if (($role !== 'administrator' && $wpmf_capability) || $role === 'employer') {
|
||||
$wpmf_create_folder = get_option('wpmf_create_folder');
|
||||
$parent = $this->getUserParentFolder();
|
||||
$cloud_type = get_term_meta($parent, 'wpmf_drive_type', true);
|
||||
$check_term = false;
|
||||
if ($wpmf_create_folder === 'user') {
|
||||
$slug = sanitize_title($current_user->data->user_login) . '-wpmf';
|
||||
$check_term = get_term_by('slug', $slug, WPMF_TAXO);
|
||||
if (empty($check_term)) {
|
||||
$parent = $this->getUserParentFolder();
|
||||
$this->doCreateUserFolder($current_user->data->user_login, $slug, $parent, $current_user);
|
||||
}
|
||||
|
||||
$google_connect = WpmfHelper::isConnected('google_drive');
|
||||
$dropbox_connect = WpmfHelper::isConnected('dropbox');
|
||||
$onedrive_connect = WpmfHelper::isConnected('onedrive');
|
||||
$onedrive_business_connect = WpmfHelper::isConnected('onedrive_business');
|
||||
if ($google_connect) {
|
||||
$is_exist = get_term_by('slug', $current_user->data->user_login . '-wpmf-google_drive', WPMF_TAXO);
|
||||
if (empty($is_exist)) {
|
||||
$parent = WpmfHelper::getCloudRootFolderID('google_drive');
|
||||
if ($parent) {
|
||||
$this->doCreateUserFolder($current_user->data->user_login, $current_user->data->user_login . '-wpmf-google_drive', $parent, $current_user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($dropbox_connect) {
|
||||
$is_exist = get_term_by('slug', $current_user->data->user_login . '-wpmf-dropbox', WPMF_TAXO);
|
||||
if (empty($is_exist)) {
|
||||
$parent = WpmfHelper::getCloudRootFolderID('dropbox');
|
||||
if ($parent) {
|
||||
$this->doCreateUserFolder($current_user->data->user_login, $current_user->data->user_login . '-wpmf-dropbox', $parent, $current_user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($onedrive_connect) {
|
||||
$is_exist = get_term_by('slug', $current_user->data->user_login . '-wpmf-onedrive', WPMF_TAXO);
|
||||
if (empty($is_exist)) {
|
||||
$parent = WpmfHelper::getCloudRootFolderID('onedrive');
|
||||
if ($parent) {
|
||||
$this->doCreateUserFolder($current_user->data->user_login, $current_user->data->user_login . '-wpmf-onedrive', $parent, $current_user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($onedrive_business_connect) {
|
||||
$is_exist = get_term_by('slug', $current_user->data->user_login . '-wpmf-onedrive_business', WPMF_TAXO);
|
||||
if (empty($is_exist)) {
|
||||
$parent = WpmfHelper::getCloudRootFolderID('onedrive_business');
|
||||
if ($parent) {
|
||||
$this->doCreateUserFolder($current_user->data->user_login, $current_user->data->user_login . '-wpmf-onedrive_business', $parent, $current_user);
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($wpmf_create_folder === 'role') {
|
||||
$slug = sanitize_title($role) . '-wpmf-role';
|
||||
$check_term = get_term_by('slug', $slug, WPMF_TAXO);
|
||||
if (empty($check_term)) {
|
||||
$inserted = wp_insert_term($role, WPMF_TAXO, array('parent' => 0, 'slug' => $slug));
|
||||
if (!is_wp_error($inserted)) {
|
||||
$role = WpmfHelper::getRoles($current_user->data->ID);
|
||||
add_term_meta((int)$inserted['term_id'], 'wpmf_folder_role_permissions', array($role, 'add_media', 'move_media', 'view_folder', 'add_folder', 'update_folder', 'remove_folder', 'view_media', 'remove_media', 'update_media'));
|
||||
do_action('wpmf_create_folder', $inserted['term_id'], $role, 0, array('trigger' => 'media_library_action'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($check_term) && !$cloud_type) {
|
||||
$this->doCreateUserFolder($current_user->data->user_login, $slug, $parent, $current_user);
|
||||
}
|
||||
|
||||
$google_connect = WpmfHelper::isConnected('google_drive');
|
||||
@@ -115,7 +66,7 @@ class WpmfFolderAccess
|
||||
$is_exist = get_term_by('slug', $current_user->data->user_login . '-wpmf-google_drive', WPMF_TAXO);
|
||||
$name = $current_user->data->user_login;
|
||||
$slug = $current_user->data->user_login . '-wpmf-google_drive';
|
||||
$type = '';
|
||||
$type = 'user';
|
||||
} else {
|
||||
$is_exist = get_term_by('slug', $role . '-wpmf-role-google_drive', WPMF_TAXO);
|
||||
$name = $role;
|
||||
@@ -137,7 +88,7 @@ class WpmfFolderAccess
|
||||
$is_exist = get_term_by('slug', $current_user->data->user_login . '-wpmf-dropbox', WPMF_TAXO);
|
||||
$name = $current_user->data->user_login;
|
||||
$slug = $current_user->data->user_login . '-wpmf-dropbox';
|
||||
$type = '';
|
||||
$type = 'user';
|
||||
} else {
|
||||
$is_exist = get_term_by('slug', $role . '-wpmf-role-dropbox', WPMF_TAXO);
|
||||
$name = $role;
|
||||
@@ -159,7 +110,7 @@ class WpmfFolderAccess
|
||||
$is_exist = get_term_by('slug', $current_user->data->user_login . '-wpmf-onedrive', WPMF_TAXO);
|
||||
$name = $current_user->data->user_login;
|
||||
$slug = $current_user->data->user_login . '-wpmf-onedrive';
|
||||
$type = '';
|
||||
$type = 'user';
|
||||
} else {
|
||||
$is_exist = get_term_by('slug', $role . '-wpmf-role-onedrive', WPMF_TAXO);
|
||||
$name = $role;
|
||||
@@ -181,7 +132,7 @@ class WpmfFolderAccess
|
||||
$is_exist = get_term_by('slug', $current_user->data->user_login . '-wpmf-onedrive_business', WPMF_TAXO);
|
||||
$name = $current_user->data->user_login;
|
||||
$slug = $current_user->data->user_login . '-wpmf-onedrive_business';
|
||||
$type = '';
|
||||
$type = 'user';
|
||||
} else {
|
||||
$is_exist = get_term_by('slug', $role . '-wpmf-role-onedrive_business', WPMF_TAXO);
|
||||
$name = $role;
|
||||
@@ -228,7 +179,10 @@ class WpmfFolderAccess
|
||||
add_term_meta((int)$inserted['term_id'], 'inherit_folder', 0);
|
||||
}
|
||||
|
||||
// do_action('wpmf_create_folder', $inserted['term_id'], $name, $parent, array('trigger' => 'media_library_action'));
|
||||
$cloud_type = get_term_meta($parent, 'wpmf_drive_type', true);
|
||||
if (!empty($cloud_type)) {
|
||||
do_action('wpmf_create_folder', $inserted['term_id'], $name, $parent, array('trigger' => 'media_library_action'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Joomunited\WPMediaFolder;
|
||||
|
||||
use \WP_Query;
|
||||
|
||||
/* Prohibit direct script loading */
|
||||
defined('ABSPATH') || die('No direct script access allowed!');
|
||||
/**
|
||||
@@ -995,6 +997,19 @@ class WpmfHelper
|
||||
|
||||
return $is_access;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get kaltura video ID from URL
|
||||
*
|
||||
* @param string $url URL of video
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public static function getKalturaVideoIdFromUrl($url = '')
|
||||
{
|
||||
$array = explode('/', basename($url));
|
||||
return end($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get dailymotion video ID from URL
|
||||
@@ -1041,7 +1056,7 @@ class WpmfHelper
|
||||
$title = '';
|
||||
$ext = '';
|
||||
$content = '';
|
||||
if ($action === 'video_to_gallery' && (int)$thumbnail !== 0) {
|
||||
if ($action === 'video_to_gallery' && (int)$thumbnail !== 0 && !strpos($video_url, 'kaltura')) {
|
||||
update_post_meta($thumbnail, 'wpmf_remote_video_link', $video_url);
|
||||
return $thumbnail;
|
||||
}
|
||||
@@ -1049,7 +1064,8 @@ class WpmfHelper
|
||||
$video_url = str_replace('manage/videos/', '', $video_url);
|
||||
if (!preg_match(self::$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)) {
|
||||
return false;
|
||||
} elseif (preg_match(self::$vimeo_pattern, $video_url, $output_array)) {
|
||||
// for vimeo
|
||||
@@ -1154,6 +1170,35 @@ class WpmfHelper
|
||||
$content = $thumb_gets['body'];
|
||||
$info_thumbnail = pathinfo($info['thumbnail_url']); // get info thumbnail
|
||||
$ext = (!empty($info_thumbnail['extension'])) ? $info_thumbnail['extension'] : 'jpg';
|
||||
} elseif (preg_match('/(videos.kaltura)\.com\b/i', $video_url, $vresult)) {
|
||||
// for kaltura
|
||||
$id = self::getKalturaVideoIdFromUrl($video_url);
|
||||
$partner_id = '5944002'; //partner id from account on Kaltura
|
||||
$thumb = 'http://cdnsecakmi.kaltura.com/p/' . $partner_id . '/thumbnail/entry_id/' . $id . '/width/2560/height/1920';
|
||||
$gets = wp_remote_get($thumb);
|
||||
|
||||
if (empty($gets)) {
|
||||
return false;
|
||||
}
|
||||
$content = $gets['body'];
|
||||
|
||||
//get title video
|
||||
$array_video_url = explode('/', $video_url);
|
||||
array_pop($array_video_url);
|
||||
$title = str_replace('+', ' ', end($array_video_url));
|
||||
|
||||
$src = 'https://cdnapisec.kaltura.com/p/' . $partner_id . '/sp/' . $partner_id . '00/playManifest/entryId/'.$id.'/format/url/protocol/https/'.$partner_id.'/2000/name/'.$id.'.mp4';
|
||||
$video_url = $src;
|
||||
update_post_meta($thumbnail, 'wpmf_remote_video_link', $video_url);
|
||||
$json_datas = wp_remote_get('https://cdnapisec.kaltura.com/p/' . $partner_id . '/sp/' . $partner_id . '00/playManifest/entryId/'.$id.'/format/url/protocol/https/'.$partner_id.'/2000/name/'.$id.'.mp4');
|
||||
|
||||
if (empty($json_datas)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$infos = array();
|
||||
$infos['html'] = "<iframe width='200' height='150' src='".$src."' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share' referrerpolicy='strict-origin-when-cross-origin' allowfullscreen title='".$title."'></iframe>";
|
||||
$ext = 'jpeg';
|
||||
}
|
||||
|
||||
$upload_dir = wp_upload_dir();
|
||||
@@ -2310,7 +2355,7 @@ class WpmfHelper
|
||||
$settings = get_option('wpmf_settings');
|
||||
if (isset($settings) && isset($settings['wpmf_active_folders_post_types'])) {
|
||||
$post_types = $settings['wpmf_active_folders_post_types'];
|
||||
$post_types = is_array($post_types) ? $post_types : [];
|
||||
$post_types = is_array($post_types) ? $post_types : array();
|
||||
} else {
|
||||
$post_types = array();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,9 @@ class WpmfPdfEmbedDivi extends Component {
|
||||
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
if (this.props.embed === 'on' && !this.state.embed) {
|
||||
if($(this.wrap.current).find(".wpmf-pdfemb-viewer").length) {
|
||||
$(this.wrap.current).find(".wpmf-pdfemb-viewer").pdfEmbedder();
|
||||
}
|
||||
this.setState({
|
||||
embed: true
|
||||
});
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user