plugin update (wp-media-folder)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -2297,4 +2297,24 @@ class WpmfHelper
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is folder active for post type
|
||||
*
|
||||
* @param string $post_type Post type name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isForThisPostType($post_type)
|
||||
{
|
||||
$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 : [];
|
||||
} else {
|
||||
$post_types = array();
|
||||
}
|
||||
|
||||
return in_array($post_type, $post_types);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1016,6 +1016,12 @@ class WpMediaFolder
|
||||
*/
|
||||
public function loadAssets()
|
||||
{
|
||||
global $typenow, $current_screen;
|
||||
|
||||
if (WpmfHelper::isForThisPostType($typenow) && 'edit' == $current_screen->base) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_script('jquery');
|
||||
wp_enqueue_script('jquery-ui-sortable');
|
||||
wp_enqueue_script('jquery-ui-draggable');
|
||||
@@ -2042,7 +2048,8 @@ class WpMediaFolder
|
||||
continue;
|
||||
}
|
||||
|
||||
if (defined('WPMFAD_PLUGIN_DIR')) {
|
||||
// Todo: Upon disconnection, remove cloud folder data from the database. This will bypass the unnecessary 'exclude' check, enhancing overall performance
|
||||
if (false && defined('WPMFAD_PLUGIN_DIR')) {
|
||||
$type = $this->getTermMeta($term->term_id, 'wpmf_drive_type');
|
||||
if ((in_array('Dropbox', $exclude) && $type === 'dropbox')
|
||||
|| (in_array('Google Drive', $exclude) && $type === 'google_drive')
|
||||
|
||||
@@ -201,22 +201,29 @@ class WpmfPdfEmbed
|
||||
$width = (!empty($attrs['width']) && strpos($attrs['width'], '%') === false) ? $attrs['width'] : '100%';
|
||||
$height = (!empty($attrs['height']) && strpos($attrs['height'], '%') === false) ? $attrs['height'] : '800';
|
||||
$download = (!empty($attrs['download'])) ? $attrs['download'] : 'off';
|
||||
$plugin_dir_url = plugin_dir_url(__DIR__);
|
||||
$viewer_base_url = $plugin_dir_url . 'class/templates/pdf-embed.php';
|
||||
|
||||
$response = wp_remote_head($url);
|
||||
if (is_wp_error($response)) {
|
||||
$url = $plugin_dir_url . 'assets/pdf-loading-error.pdf';
|
||||
}
|
||||
|
||||
$status_code = wp_remote_retrieve_response_code($response);
|
||||
if ($status_code === 404) {
|
||||
$url = $plugin_dir_url . 'assets/pdf-loading-error.pdf';
|
||||
}
|
||||
$wpmf_pdf_embed_old = apply_filters('wpmf_pdf_embed_old', false);
|
||||
if ($wpmf_pdf_embed_old) {
|
||||
$width = (!empty($attrs['width']) && strpos($attrs['width'], '%') === false) ? $attrs['width'] : '';
|
||||
$return = '<a class="wpmf-pdfemb-viewer" data-download="'. $download .'" data-width="'. (int)$width .'" data-height="'. ((int)$height - 31) .'" href="'.esc_url($url).'">'.esc_html($title).'</a>';
|
||||
} else {
|
||||
$plugin_dir_url = plugin_dir_url(__DIR__);
|
||||
$viewer_base_url = $plugin_dir_url . 'class/templates/pdf-embed.php';
|
||||
|
||||
$attachment_info = '?file=' . urlencode($url);
|
||||
$final_url = $viewer_base_url . $attachment_info . '&plugins_url=' . urlencode($plugin_dir_url);
|
||||
$return = '<div><iframe width="' . esc_attr($width) . '" height="' . esc_attr($height) . '" src="' . esc_url($final_url) . '" title="Embedded PDF" class="wpmf-pdfjs-iframe"></iframe></div>';
|
||||
$response = wp_remote_head($url);
|
||||
if (is_wp_error($response)) {
|
||||
$url = $plugin_dir_url . 'assets/pdf-loading-error.pdf';
|
||||
}
|
||||
|
||||
$status_code = wp_remote_retrieve_response_code($response);
|
||||
if ($status_code === 404) {
|
||||
$url = $plugin_dir_url . 'assets/pdf-loading-error.pdf';
|
||||
}
|
||||
|
||||
$attachment_info = '?file=' . urlencode($url);
|
||||
$final_url = $viewer_base_url . $attachment_info . '&plugins_url=' . urlencode($plugin_dir_url);
|
||||
$return = '<div><iframe width="' . esc_attr($width) . '" height="' . esc_attr($height) . '" src="' . esc_url($final_url) . '" title="Embedded PDF" class="wpmf-pdfjs-iframe"></iframe></div>';
|
||||
}
|
||||
} else {
|
||||
$return = '<a href="'.esc_url($url).'" '. (($attrs['target'] !== '') ? 'target="'.esc_attr($attrs['target']).'"' : '') .'>'.esc_html($title).'</a>';
|
||||
}
|
||||
@@ -257,7 +264,13 @@ class WpmfPdfEmbed
|
||||
*/
|
||||
public function enqueue()
|
||||
{
|
||||
wp_enqueue_script('wpmf_compat_js');
|
||||
$wpmf_pdf_embed_old = apply_filters('wpmf_pdf_embed_old', false);
|
||||
if ($wpmf_pdf_embed_old) {
|
||||
wp_enqueue_script('wpmf_embed_pdf_js');
|
||||
wp_enqueue_script('wpmf_compat_js');
|
||||
wp_enqueue_script('wpmf_pdf_js');
|
||||
wp_enqueue_style('pdfemb_embed_pdf_css');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,7 +282,6 @@ class WpmfPdfEmbed
|
||||
public function getTranslation()
|
||||
{
|
||||
$array = array(
|
||||
// 'worker_src' => plugins_url('assets/js/pdf-embed/pdf.worker.min.js', dirname(__FILE__)),
|
||||
'worker_src' => plugins_url('assets/js/pdf-embed/pdf.worker.js', dirname(__FILE__)),
|
||||
'cmap_url' => plugins_url('assets/js/pdf-embed/cmaps/', dirname(__FILE__)),
|
||||
'pdf_sandbox'=> plugins_url('assets/js/pdf-embed/pdf.sandbox.js', dirname(__FILE__)),
|
||||
@@ -292,6 +304,11 @@ class WpmfPdfEmbed
|
||||
'poweredby' => 1
|
||||
)
|
||||
);
|
||||
$wpmf_pdf_embed_old = apply_filters('wpmf_pdf_embed_old', false);
|
||||
if ($wpmf_pdf_embed_old) {
|
||||
$array['worker_src'] = plugins_url('assets/js/pdf-embed/pdf.worker.min.js', dirname(__FILE__));
|
||||
unset($array['pdf_sandbox']);
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -404,22 +421,33 @@ class WpmfPdfEmbed
|
||||
*/
|
||||
public function registerScript()
|
||||
{
|
||||
wp_register_script(
|
||||
'wpmf_compat_js',
|
||||
plugins_url('assets/js/pdf-embed/compatibility.js', dirname(__FILE__)),
|
||||
array('jquery')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add script
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addCustomPdfL10nLink()
|
||||
{
|
||||
$locale_url = plugins_url('assets/js/pdf-embed/locale/locale.properties', dirname(__FILE__));
|
||||
echo '<link rel="resource" type="application/l10n" href="' . esc_url($locale_url) . '">';
|
||||
$wpmf_pdf_embed_old = apply_filters('wpmf_pdf_embed_old', false);
|
||||
if ($wpmf_pdf_embed_old) {
|
||||
wp_register_script(
|
||||
'wpmf_embed_pdf_js',
|
||||
plugins_url('assets/js/pdf-embed/all-pdfemb-basic.min.js', dirname(__FILE__)),
|
||||
array('jquery')
|
||||
);
|
||||
wp_localize_script(
|
||||
'wpmf_embed_pdf_js',
|
||||
'wpmf_pdfemb_trans',
|
||||
$this->getTranslation()
|
||||
);
|
||||
wp_register_script(
|
||||
'wpmf_compat_js',
|
||||
plugins_url('assets/js/pdf-embed/compatibility.js', dirname(__FILE__)),
|
||||
array('jquery')
|
||||
);
|
||||
wp_register_script(
|
||||
'wpmf_pdf_js',
|
||||
plugins_url('assets/js/pdf-embed/pdf-old.js', dirname(__FILE__)),
|
||||
array()
|
||||
);
|
||||
wp_register_style(
|
||||
'pdfemb_embed_pdf_css',
|
||||
plugins_url('assets/css/pdfemb-embed-pdf.css', dirname(__FILE__))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1693,6 +1693,22 @@ class WpmfMediaFolderOption
|
||||
if (!get_option('wpmf_gallery_settings', false)) {
|
||||
add_option('wpmf_gallery_settings', $gallery_settings, '', 'yes');
|
||||
}
|
||||
|
||||
if (!get_option('wpmf_minimize_folder_tree_post_type', false)) {
|
||||
add_option('wpmf_minimize_folder_tree_post_type', 1, '', 'yes');
|
||||
}
|
||||
|
||||
$post_types = $this->getAllPostTypes();
|
||||
foreach ($post_types as $post_type) {
|
||||
$option_name = 'wpmf_option_folder_'.$post_type->name;
|
||||
if (!get_option($option_name, false)) {
|
||||
if ($option_name === 'wpmf_option_folder_post') {
|
||||
add_option($option_name, 1, '', 'yes');
|
||||
} else {
|
||||
add_option($option_name, 0, '', 'yes');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2474,7 +2490,8 @@ class WpmfMediaFolderOption
|
||||
'root_media_count',
|
||||
'watermark_exclude_public_gallery',
|
||||
'watermark_exclude_photograph_gallery',
|
||||
'connect_nextcloud'
|
||||
'connect_nextcloud',
|
||||
'wpmf_minimize_folder_tree_post_type'
|
||||
);
|
||||
if (isset($_POST['btn_wpmf_save'])) {
|
||||
if (empty($_POST['wpmf_nonce'])
|
||||
@@ -2743,6 +2760,19 @@ class WpmfMediaFolderOption
|
||||
}
|
||||
}
|
||||
|
||||
$post_types = $this->getAllPostTypes();
|
||||
$wpmf_active_folders_post_types = array();
|
||||
foreach ($post_types as $post_type) {
|
||||
$option = 'wpmf_option_folder_'.$post_type->name;
|
||||
if (isset($_POST[$option])) {
|
||||
wpmfSetOption($option, $_POST[$option]);
|
||||
if ((int) $_POST[$option] === 1) {
|
||||
$wpmf_active_folders_post_types[] = $post_type->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
wpmfSetOption('wpmf_active_folders_post_types', $wpmf_active_folders_post_types);
|
||||
|
||||
if (isset($_POST['wpmf_active_media']) && (int) $_POST['wpmf_active_media'] === 1) {
|
||||
$wpmf_checkbox_tree = get_option('wpmf_checkbox_tree');
|
||||
if (!empty($wpmf_checkbox_tree)) {
|
||||
@@ -4404,4 +4434,29 @@ class WpmfMediaFolderOption
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all post types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllPostTypes()
|
||||
{
|
||||
$post_types = get_post_types(array( 'show_in_menu' => true ), 'objects');
|
||||
// List of post types to exclude
|
||||
$page_builder_post_types = array(
|
||||
'elementor_library',
|
||||
'e-landing-page',
|
||||
'wpb',
|
||||
'attachment'
|
||||
);
|
||||
|
||||
foreach ($page_builder_post_types as $page_builder_post_type) {
|
||||
if (isset($post_types[$page_builder_post_type])) {
|
||||
unset($post_types[$page_builder_post_type]);
|
||||
}
|
||||
}
|
||||
|
||||
return $post_types;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,3 +601,81 @@ $featured_image_folder = wpmfGetOption('featured_image_folder');
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--------------------------------------- Folder settings ----------------------------------->
|
||||
<?php
|
||||
$post_types = get_post_types(array( 'show_in_menu' => true ), 'objects');
|
||||
// List of post types to exclude
|
||||
$exclude_post_types = array(
|
||||
'elementor_library',
|
||||
'e-landing-page',
|
||||
'wpb',
|
||||
'attachment',
|
||||
'shop_order',
|
||||
'shop_coupon'
|
||||
);
|
||||
|
||||
foreach ($exclude_post_types as $exclude_post_type) {
|
||||
if (isset($post_types[$exclude_post_type])) {
|
||||
unset($post_types[$exclude_post_type]);
|
||||
}
|
||||
}
|
||||
|
||||
$countPostTypes = 0;
|
||||
?>
|
||||
<div id="folder_settings" class="tab-content">
|
||||
<div class="content-box">
|
||||
<div class="ju-settings-option">
|
||||
<div class="wpmf_row_full">
|
||||
<input type="hidden" name="wpmf_minimize_folder_tree_post_type" value="0">
|
||||
<label data-wpmftippy="<?php esc_html_e('Open folders sidebar minimized by default on posts and pages', 'wpmf'); ?>" class="ju-setting-label text" for="wpmf_minimize_folder_tree_post_type"><?php echo esc_html__('Open sidebar minimized', 'wpmf') ?></label>
|
||||
<div class="ju-switch-button">
|
||||
<label class="switch">
|
||||
<input type="checkbox" name="wpmf_minimize_folder_tree_post_type" id="wpmf_minimize_folder_tree_post_type" value="1"
|
||||
<?php
|
||||
$minimize_folder_tree_option = wpmfGetOption('wpmf_minimize_folder_tree_post_type');
|
||||
if (isset($minimize_folder_tree_option) && (int) $minimize_folder_tree_option === 1) {
|
||||
echo 'checked';
|
||||
}
|
||||
?>
|
||||
>
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php foreach ($post_types as $value) : ?>
|
||||
<?php
|
||||
$countPostTypes++;
|
||||
$classSetting = 'ju-settings-option';
|
||||
if ($countPostTypes % 2 === 1) {
|
||||
$classSetting = 'ju-settings-option wpmf_right m-r-0';
|
||||
}
|
||||
$tooltip_string = esc_html__('Activate a folder management for WordPress', 'wpmf').' '.strtolower($value->label).' '.esc_html__('(ie. classify', 'wpmf').' '.strtolower($value->label).' '.esc_html__('in folders, like virtual categories)', 'wpmf');
|
||||
?>
|
||||
|
||||
<div class="<?php echo esc_attr($classSetting); ?>">
|
||||
<div class="wpmf_row_full">
|
||||
<input type="hidden" name="wpmf_option_folder_<?php echo esc_attr($value->name); ?>" value="0">
|
||||
<label data-wpmftippy="<?php echo esc_attr($tooltip_string); ?>" class="ju-setting-label text" for="wpmf_option_folder_<?php echo esc_attr($value->name); ?>"><?php echo esc_html__('Activate folders for', 'wpmf') . ' ' . esc_attr($value->label) ?></label>
|
||||
<div class="ju-switch-button">
|
||||
<label class="switch">
|
||||
<input type="checkbox" name="wpmf_option_folder_<?php echo esc_attr($value->name); ?>" id="wpmf_option_folder_<?php echo esc_attr($value->name); ?>" value="1"
|
||||
<?php
|
||||
$option_name = 'wpmf_option_folder_'.$value->name;
|
||||
$option_folder = wpmfGetOption($option_name);
|
||||
if (isset($option_folder) && (int) $option_folder === 1) {
|
||||
echo 'checked';
|
||||
}
|
||||
?>
|
||||
>
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -9,7 +9,7 @@ $tabs_data = array(
|
||||
'sub_tabs' => array(
|
||||
'additional_features' => __('Main settings', 'wpmf'),
|
||||
'media_filtering' => __('Media filtering', 'wpmf'),
|
||||
// 'advanced' => __('Advanced', 'wpmf')
|
||||
'folder_settings' => __('Folder settings', 'wpmf')
|
||||
)
|
||||
),
|
||||
array(
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
global $typenow;
|
||||
if ($typenow === 'page') {
|
||||
$label = esc_html__('pages', 'wpmf');
|
||||
} elseif ($typenow === 'post') {
|
||||
$label = esc_html__('posts', 'wpmf');
|
||||
} else {
|
||||
$post_type_name = $typenow;
|
||||
$post_types = get_post_types([ 'name' => $post_type_name], 'objects');
|
||||
if (!empty($post_types) && is_array($post_types) && isset($post_types[$post_type_name]) && isset($post_types[$post_type_name]->label)) {
|
||||
$label = $post_types[$post_type_name]->label;
|
||||
}
|
||||
}
|
||||
|
||||
$folder_tree_status_option = wpmfGetOption('wpmf_folder_tree_status');
|
||||
$class_name = '';
|
||||
if (!empty($folder_tree_status_option) && (isset($folder_tree_status_option[$typenow]) && $folder_tree_status_option[$typenow] === 'hide') || !isset($folder_tree_status_option[$typenow])) {
|
||||
$class_name = 'wpmf-hide-folder-tree';
|
||||
}
|
||||
?>
|
||||
<div class="wpmf-folder-post-type <?php echo esc_attr($class_name); ?>">
|
||||
<div class="wpmf-main-tree"></div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user