plugin updates

This commit is contained in:
Tony Volpe
2024-10-11 13:25:50 -04:00
parent 5e5b879a68
commit a6fc17dcaa
391 changed files with 6812 additions and 4326 deletions

View File

@@ -684,6 +684,10 @@ ul.jaofiletree a:hover {
float: right;
}
.wpmf-setting-only-file-import{
margin: 30px 0 15px 0;
}
.wpmf-process-bar-full {
display: none;
width: 100%;

View File

@@ -414,7 +414,7 @@
/* ===== Material Design ===== */
.wpmf-attachment.mdc-list-item {
width: 190px !important;
padding: 0 16px !important;
padding: 0 10px !important;
margin: 8px !important;
overflow: hidden;
height: 48px !important;
@@ -517,7 +517,7 @@
-ms-flex-direction: column;
flex-direction: column;
display: inline-block;
width: 90px;
width: 135px;
white-space: nowrap;
overflow: hidden !important;
text-overflow: ellipsis;

View File

@@ -853,11 +853,17 @@ var wpmfTreeOptionsModule;
*/
$('.import_ftp_button').on('click', function () {
var $this = $(this);
var check_only_file = document.getElementById("only_file");
var wpmf_only_file = 0;
if (check_only_file.checked == true){
wpmf_only_file = 1;
}
$.ajax({
type: 'POST',
url: ajaxurl,
data: {
action: "wpmf_import_folder",
wpmf_only_file: wpmf_only_file,
wpmf_list_import: wpmf_list_import,
wpmf_nonce: wpmfoption.vars.wpmf_nonce
},

View File

@@ -237,4 +237,117 @@ class WpmfFolderAccess
return $parent;
}
/**
* Delete folders created by the user
*
* @param integer $user_id User ID
*
* @return void
*/
public static function deleteUserFolders($user_id)
{
global $wpdb;
// Get folders created by the user
$folders = $wpdb->get_results($wpdb->prepare(
'SELECT term_id FROM ' . $wpdb->terms . ' WHERE term_group = %d',
$user_id
));
if (!empty($folders)) {
foreach ($folders as $folder) {
wp_delete_term($folder->term_id, WPMF_TAXO);
}
}
}
/**
* Delete folders created by deleted users
*
* @return void
*/
public static function deleteFoldersOfDeletedUsers()
{
global $wpdb;
$wpmf_checkbox_tree = get_option('wpmf_checkbox_tree');
$parent = 0;
if (!empty($wpmf_checkbox_tree)) {
$current_parrent = get_term($wpmf_checkbox_tree, WPMF_TAXO);
if (!empty($current_parrent)) {
$parent = $wpmf_checkbox_tree;
}
}
$descendant_term_ids = get_term_children($parent, WPMF_TAXO);
if (empty($descendant_term_ids)) {
return;
}
$descendant_term_ids_str = implode(',', $descendant_term_ids);
$query = '
SELECT t.term_id, t.term_group
FROM ' . $wpdb->terms . ' t
INNER JOIN ' . $wpdb->term_taxonomy . ' tt ON t.term_id = tt.term_id
WHERE tt.taxonomy = %s
AND t.term_group != 0
AND tt.term_id IN (' . $descendant_term_ids_str . ')
';
$folders = $wpdb->get_results($wpdb->prepare($query, WPMF_TAXO)); // phpcs:ignore
if (!empty($folders)) {
foreach ($folders as $folder) {
// Check if the user still exists
if (!get_user_by('ID', $folder->term_group)) {
// If the user does not exist, delete the folder
wp_delete_term($folder->term_id, WPMF_TAXO);
}
}
}
}
/**
* Add admin menu for deleting user folders
*
* @return void
*/
public static function addDeleteUserFoldersMenu()
{
add_menu_page(
esc_html__('WPMF Delete Folders of Deleted Users', 'wpmf'),
esc_html__('WPMF Delete Folders', 'wpmf'),
'manage_options',
'wpmf-delete-user-folders',
array('WpmfFolderAccess', 'deleteUserFoldersPage')
);
}
/**
* Callback to render the admin page for deleting folders
*
* @return void
*/
public static function deleteUserFoldersPage()
{
// Handle the form submission
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
if (isset($_POST['delete_folders'])) {
self::deleteFoldersOfDeletedUsers();
echo '<div class="updated"><p>' . esc_html__('All folders of deleted users have been removed.', 'wpmf') . '</p></div>';
}
?>
<div class="wrap">
<h1><?php echo esc_html__('Delete Folders of Deleted Users', 'wpmf'); ?></h1>
<form method="post" action="">
<input type="hidden" name="delete_folders" value="1" />
<p>
<input type="submit" class="button-primary" value="<?php echo esc_attr__('Delete Folders', 'wpmf'); ?>" />
</p>
</form>
</div>
<?php
}
}

View File

@@ -15,7 +15,30 @@ class WpMediaFolder
* @var integer
*/
public $folderRootId = 0;
/**
* Init option configuration variable
*
* @var string
*/
private static $option_google_drive_config = '_wpmfAddon_cloud_config';
/**
* Init option configuration variable
*
* @var string
*/
private static $option_dropbox_config = '_wpmfAddon_dropbox_config';
/**
* Init option configuration variable
*
* @var string
*/
private static $option_one_drive_config = '_wpmfAddon_onedrive_config';
/**
* Init option configuration variable
*
* @var string
*/
private static $option_one_drive_business_config = '_wpmfAddon_onedrive_business_config';
/**
* Check user full access
*
@@ -93,6 +116,7 @@ class WpMediaFolder
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);
add_action('wp_enqueue_media', array($this, 'removeDatabaseWhenCloudDisconnected'));
}
/**
@@ -5725,7 +5749,7 @@ class WpMediaFolder
*/
public function moveFileUploadToSelectFolder($attachment_id)
{
if (isset($_POST['id_category'])) {
if (isset($_POST['id_category']) && isset($_POST['wpmf_nonce'])) {
if (empty($_POST['wpmf_nonce']) || !wp_verify_nonce($_POST['wpmf_nonce'], 'wpmf_nonce')) {
die();
}
@@ -5788,4 +5812,43 @@ class WpMediaFolder
}
}
}
/**
* Delete files and folders information in database if cloud was disconnected
*
* @return void
*/
public function removeDatabaseWhenCloudDisconnected()
{
//on Google Drive
$option_cloud_google_drive = get_option(self::$option_google_drive_config);
$folder_google_drive = get_terms(array('name' => 'Google Drive', 'parent' => 0, 'hide_empty' => false, 'taxonomy' => WPMF_TAXO));
if (!is_wp_error($folder_google_drive) && $folder_google_drive && (!isset($option_cloud_google_drive['connected']) || $option_cloud_google_drive['connected'] !== 1)) {
$this->doRemoveFolders($folder_google_drive[0]->term_id);
}
//on Dropbox
$option_cloud_dropbox = get_option(self::$option_dropbox_config);
$folder_dropbox = get_terms(array('name' => 'Dropbox', 'parent' => 0, 'hide_empty' => false, 'taxonomy' => WPMF_TAXO));
if (!is_wp_error($folder_dropbox) && $folder_dropbox && empty($option_cloud_dropbox['dropboxToken'])) {
$this->doRemoveFolders((int)$folder_dropbox[0]->term_id);
}
//on One Drive
$option_cloud_one_drive = get_option(self::$option_one_drive_config);
$folder_one_drive = get_terms(array('name' => 'Onedrive', 'parent' => 0, 'hide_empty' => false, 'taxonomy' => WPMF_TAXO));
if (!is_wp_error($folder_one_drive) && $folder_one_drive && !isset($option_cloud_one_drive['connected'])) {
$this->doRemoveFolders((int)$folder_one_drive[0]->term_id);
}
//on One Drive business
$option_cloud_one_drive_business = get_option(self::$option_one_drive_business_config);
$folder_one_drive_business = get_terms(array('name' => 'Onedrive Business', 'parent' => 0, 'hide_empty' => false, 'taxonomy' => WPMF_TAXO));
if (!is_wp_error($folder_one_drive_business) && $folder_one_drive_business && !isset($option_cloud_one_drive_business['connected'])) {
$this->doRemoveFolders((int)$folder_one_drive_business[0]->term_id);
}
//on Next Cloud
$connect_nextcloud = wpmfGetOption('connect_nextcloud');
$folder_next_cloud = get_terms(array('name' => 'Nextcloud', 'parent' => 0, 'hide_empty' => false, 'taxonomy' => WPMF_TAXO));
if (!is_wp_error($folder_next_cloud) && $folder_next_cloud && empty($connect_nextcloud)) {
$this->doRemoveFolders((int)$folder_next_cloud[0]->term_id);
}
}
}

View File

@@ -511,7 +511,7 @@ class WpmfMediaFolderOption
$wpmfQueue = JuMainQueue::getInstance('wpmf');
$wpmfQueue->updateQueueTermMeta((int)$responses['folder_id'], (int)$element_id);
$wpmfQueue->updateResponses((int)$element_id, $responses);
$this->doAddImportFtpQueue($datas['path'] . DIRECTORY_SEPARATOR, (int)$responses['folder_id']);
$this->doAddImportFtpQueue($datas['path'] . DIRECTORY_SEPARATOR, (int)$responses['folder_id'], $datas['only_file']);
} else {
$upload_dir = wp_upload_dir();
$info_file = wp_check_filetype($datas['path']);
@@ -908,10 +908,11 @@ class WpmfMediaFolderOption
*
* @param string $directory Directory
* @param integer $folder_parent ID of folder parent on media library
* @param integer $only_file Import file without subdirectories
*
* @return void
*/
public function doAddImportFtpQueue($directory, $folder_parent = 0)
public function doAddImportFtpQueue($directory, $folder_parent = 0, $only_file = null)
{
if (file_exists($directory)) {
$dir_files = glob($directory . '*');
@@ -929,7 +930,7 @@ class WpmfMediaFolderOption
'folder_parent' => $folder_parent,
'action' => 'wpmf_import_ftp_to_library'
);
if (is_dir($dir_file)) {
if (is_dir($dir_file) && empty($only_file)) {
$datas['name'] = $name;
$datas['type'] = 'folder';
} else {
@@ -1315,6 +1316,7 @@ class WpmfMediaFolderOption
}
$list_import = $_POST['wpmf_list_import'];
$only_file = $_POST['wpmf_only_file'];
if ($list_import !== '') {
$lists = explode(',', $list_import);
if (in_array('', $lists)) {
@@ -1337,7 +1339,8 @@ class WpmfMediaFolderOption
'folder_parent' => 0,
'action' => 'wpmf_import_ftp_to_library',
'name' => basename($validate_path),
'type' => 'folder'
'type' => 'folder',
'only_file' => $only_file
);
$wpmfQueue = JuMainQueue::getInstance('wpmf');
@@ -1347,7 +1350,7 @@ class WpmfMediaFolderOption
} else {
$responses = json_decode($row->responses, true);
if (isset($responses['folder_id'])) {
$this->doAddImportFtpQueue($datas['path'] . DIRECTORY_SEPARATOR, (int)$responses['folder_id']);
$this->doAddImportFtpQueue($datas['path'] . DIRECTORY_SEPARATOR, (int)$responses['folder_id'], $only_file);
}
}
}

View File

@@ -124,6 +124,10 @@ $size = size_format($bytes);
<div class="wpmf-process-bar-full process_import_ftp_full" style="">
<div class="wpmf-process-bar process_import_ftp" data-w="0"></div>
</div>
<div class="wpmf-setting-only-file-import">
<input type="checkbox" id="only_file">
<span>Import folders without their subdirectories</span>
</div>
<button type="button"
class="ju-button no-background orange-button waves-effect waves-light import_ftp_button"
style="padding: 8.5px 15px">

View File

@@ -1126,6 +1126,7 @@ if (!class_exists('JuPluginInfo', false)) :
/**
* A container class for holding and transforming various plugin metadata.
*/
#[AllowDynamicProperties]
class JuPluginInfo // phpcs:ignore Generic.Files.OneClassPerFile.MultipleFound -- some classes have no function
{

View File

@@ -1133,9 +1133,18 @@ class JuMainQueue
{
global $wpdb;
$pluginPrefix = self::getOption('plugin_prefix');
$charset_collate = $this->getWpCharsetCollate();
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Params has prepared
$createTable = "CREATE TABLE `" . $wpdb->prefix . $pluginPrefix . "_queue` (
$result = false;
$table_name = $wpdb->prefix . $pluginPrefix . '_queue' ;
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->prefix . $pluginPrefix . '_queue' ) );
if ( $wpdb->get_var( $query ) === $table_name) {
$result = true;
}
if(!$result) {
$charset_collate = $this->getWpCharsetCollate();
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Params has prepared
$createTable = "CREATE TABLE `" . $wpdb->prefix . $pluginPrefix . "_queue` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`datas` LONGTEXT NOT NULL,
`data_hash` VARCHAR(32) NOT NULL DEFAULT '',
@@ -1149,10 +1158,15 @@ class JuMainQueue
KEY idx_data_hash (data_hash(32)),
KEY idx_status (status)
) " . $charset_collate . " ENGINE=InnoDB";
// phpcs:enable
// Create table if not exists. Return true on table exists or success.
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$result = \maybe_create_table($wpdb->prefix . $pluginPrefix . '_queue', $createTable);
// phpcs:enable
// Didn't find it, so try to create it.
$wpdb->query( $createTable );
// We cannot directly tell that whether this succeeded!
if ( $wpdb->get_var( $query ) === $table_name ) {
$result = true;
}
}
// Update
$queueVersion = get_option($pluginPrefix . '_queue', false);

View File

@@ -3,7 +3,7 @@ Tags: media, folder
Requires at least: 4.7.0
Tested up to: 6.6
Requires PHP: 5.6
Stable tag: 5.9.5
Stable tag: 5.9.7
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -20,6 +20,12 @@ Stop searching for an image through thousand of media, just navigate like you do
= Changelog =
= 5.9.7 =
* Fix : Error while using Elementor theme builder
= 5.9.6 =
* Add : Option to import files without subdirectories
= 5.9.5 =
* Fix : Upload image error at the 'Add new media' page

View File

@@ -4,7 +4,7 @@
Plugin URI: http://www.joomunited.com
Description: WP media Folder is a WordPress plugin that enhance the WordPress media manager by adding a folder manager inside.
Author: Joomunited
Version: 5.9.5
Version: 5.9.7
Update URI: https://www.joomunited.com/juupdater_files/wp-media-folder.json
Author URI: http://www.joomunited.com
Text Domain: wpmf
@@ -79,7 +79,7 @@ if (!defined('WPMF_TAXO')) {
define('_WPMF_GALLERY_PREFIX', '_wpmf_gallery_');
define('WPMF_PLUGIN_URL', plugin_dir_url(__FILE__));
define('WPMF_DOMAIN', 'wpmf');
define('WPMF_VERSION', '5.9.5');
define('WPMF_VERSION', '5.9.7');
define('WPMF_HIDE_USER_MEDIA_FOLDER_ROOT', true);
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
@@ -1726,7 +1726,7 @@ if ($remote_video) {
*/
function wpmfFindImages($content)
{
if (preg_match_all('/<img [^<>]+ \/>/i', $content, $matches)) {
if (preg_match_all('/(<img[^>]+>)/i', $content, $matches)) {
if (isset($matches[0]) && is_array($matches[0])) {
foreach ($matches[0] as $img) {
$dom = new DOMDocument();
@@ -1955,7 +1955,7 @@ function wpmfDownloadFile()
break;
case 'onedrive':
require_once WPMFAD_PLUGIN_DIR . '/class/wpmfAddonOneDriveAdmin.php';
$library = new WpmfAddonOneDriveBusinessAdmin;
$library = new WpmfAddonOneDrive;
$library->getContentFile($drive_id, 1);
break;
case 'onedrive_business':