Plugin Directory

Changeset 3421965


Ignore:
Timestamp:
12/17/2025 01:38:18 PM (3 months ago)
Author:
ninjateam
Message:

New version 2.0.2

Location:
filester
Files:
383 added
5 edited

Legend:

Unmodified
Added
Removed
  • filester/trunk/includes/File_manager/FileManager.php

    r3386229 r3421965  
    275275        $uploadMaxSize = isset($this->options['njt_fs_file_manager_settings']['upload_max_size']) && !empty($this->options['njt_fs_file_manager_settings']['upload_max_size']) ? $this->options['njt_fs_file_manager_settings']['upload_max_size'] : 0;
    276276
     277        // Get and validate root folder path
     278        $root_folder_path = isset($this->options['njt_fs_file_manager_settings']['root_folder_path']) && !empty($this->options['njt_fs_file_manager_settings']['root_folder_path'])
     279            ? $this->options['njt_fs_file_manager_settings']['root_folder_path']
     280            : ABSPATH;
     281       
     282        // Get and validate root folder URL
     283        $root_folder_url = isset($this->options['njt_fs_file_manager_settings']['root_folder_url']) && !empty($this->options['njt_fs_file_manager_settings']['root_folder_url'])
     284            ? $this->options['njt_fs_file_manager_settings']['root_folder_url']
     285            : site_url();
     286       
     287        // Validate path exists and is readable - auto-fix if invalid
     288        $path_needs_update = false;
     289        if (!empty($root_folder_path) && (!is_dir($root_folder_path) || !is_readable($root_folder_path))) {
     290            // Path is invalid, fallback to ABSPATH
     291            $root_folder_path = ABSPATH;
     292            $path_needs_update = true;
     293        }
     294       
     295        // Validate URL - auto-update to current site_url() if path was invalid
     296        // This ensures URL matches the new server/domain
     297        if ($path_needs_update) {
     298            $root_folder_url = site_url();
     299        }
     300       
     301        // Auto-update saved settings if path/URL was invalid
     302        if ($path_needs_update) {
     303            $this->options['njt_fs_file_manager_settings']['root_folder_path'] = $root_folder_path;
     304            $this->options['njt_fs_file_manager_settings']['root_folder_url'] = $root_folder_url;
     305            update_option('njt_fs_settings', $this->options);
     306        }
     307
    277308        $opts = array(
    278309            'bind' => array(
     
    283314                array(
    284315                    'driver' => 'LocalFileSystem',
    285                     'path' => isset($this->options['njt_fs_file_manager_settings']['root_folder_path']) && !empty($this->options['njt_fs_file_manager_settings']['root_folder_path']) ? $this->options['njt_fs_file_manager_settings']['root_folder_path'] : ABSPATH,
    286                     'URL' => isset($this->options['njt_fs_file_manager_settings']['root_folder_url']) && !empty($this->options['njt_fs_file_manager_settings']['root_folder_url']) ? $this->options['njt_fs_file_manager_settings']['root_folder_url'] : site_url(),
     316                    'path' => $root_folder_path,
     317                    'URL' => $root_folder_url,
    287318                    'tmpPath' => NJT_FS_BN_PLUGIN_PATH . 'includes/File_manager/lib/files/.tmp/',
    288319                    'trashHash'     => '', // default is empty, when not enable trash
     
    341372        }
    342373        //Creat root path for user
     374        $private_path_valid = false;
    343375        if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'])){
    344             $opts['roots'][0]['path'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'] .'/';
     376            $private_path = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'] .'/';
     377            // Validate private folder path exists and is readable
     378            if (is_dir($private_path) && is_readable($private_path)) {
     379                $opts['roots'][0]['path'] = $private_path;
     380                $private_path_valid = true;
     381            }
     382            // If invalid, keep using default root path (already validated above)
    345383        }
    346384
    347385         //Creat url root path for user
    348          if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'])){
    349             $opts['roots'][0]['URL'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'] .'/';
     386         if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access']) && $private_path_valid){
     387            $private_url = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'] .'/';
     388            $opts['roots'][0]['URL'] = $private_url;
    350389        }
    351390
  • filester/trunk/includes/File_manager/lib/php/elFinderVolumeDriver.class.php

    r3360238 r3421965  
    33373337            }
    33383338            $path = str_replace('%2F', '/', rawurlencode($path));
    3339             return $this->URL . $path;
     3339            return $this->_buildFileUrl($path);
    33403340        } else {
    33413341            $ret = false;
     
    47324732            }
    47334733            if (!isset($stat['url']) && $this->URL && $this->encoding) {
    4734                 $_path = str_replace($this->separator, '/', substr($path, strlen($this->root) + 1));
    4735                 $stat['url'] = rtrim($this->URL, '/') . '/' . str_replace('%2F', '/', rawurlencode((substr(PHP_OS, 0, 3) === 'WIN') ? $_path : $this->convEncIn($_path, true)));
     4734                $_path = $this->_getRelativePath($path);
     4735                $_path = str_replace($this->separator, '/', $_path);
     4736                $_path = (substr(PHP_OS, 0, 3) === 'WIN') ? $_path : $this->convEncIn($_path, true);
     4737                $_path = str_replace('%2F', '/', rawurlencode($_path));
     4738                $stat['url'] = $this->_buildFileUrl($_path);
    47364739            }
    47374740        } else {
     
    52065209                $stat['path'] = $this->path($stat['hash']);
    52075210                if ($this->URL && !isset($stat['url'])) {
    5208                     $path = str_replace($this->separator, '/', substr($p, strlen($this->root) + 1));
     5211                    $_path = $this->_getRelativePath($p);
     5212                    $path = str_replace($this->separator, '/', $_path);
    52095213                    if ($this->encoding) {
    52105214                        $path = str_replace('%2F', '/', rawurlencode($this->convEncIn($path, true)));
     
    52125216                        $path = str_replace('%2F', '/', rawurlencode($path));
    52135217                    }
    5214                     $stat['url'] = $this->URL . $path;
     5218                    $stat['url'] = $this->_buildFileUrl($path);
    52155219                }
    52165220
     
    76447648
    76457649    /**
     7650     * Get relative path from root path
     7651     * Helper method to correctly calculate relative path regardless of trailing separator
     7652     *
     7653     * @param  string $path Full file path
     7654     * @return string Relative path from root
     7655     * @author Filester Fix
     7656     **/
     7657    protected function _getRelativePath($path)
     7658    {
     7659        // Normalize root path - remove trailing separators
     7660        $root = rtrim($this->root, $this->separator . '/');
     7661        $rootLen = strlen($root);
     7662       
     7663        // Normalize file path
     7664        $normalizedPath = str_replace($this->separator, '/', $path);
     7665        $normalizedRoot = str_replace($this->separator, '/', $root);
     7666       
     7667        // Check if path starts with root (case-sensitive)
     7668        if (strpos($normalizedPath, $normalizedRoot) === 0) {
     7669            $relative = substr($normalizedPath, $rootLen);
     7670            // Remove leading separator
     7671            $relative = ltrim($relative, '/');
     7672            return $relative;
     7673        }
     7674       
     7675        // Fallback: try to calculate using original method
     7676        // Handle case where root ends with separator
     7677        $rootWithSep = rtrim($this->root, $this->separator . '/') . $this->separator;
     7678        if (strpos($path, $rootWithSep) === 0) {
     7679            $relative = substr($path, strlen($rootWithSep));
     7680            return str_replace($this->separator, '/', $relative);
     7681        }
     7682       
     7683        // Last fallback: old method
     7684        if (strlen($path) > strlen($this->root)) {
     7685            $relative = substr($path, strlen($this->root));
     7686            $relative = ltrim($relative, $this->separator . '/');
     7687            return str_replace($this->separator, '/', $relative);
     7688        }
     7689       
     7690        return '';
     7691    }
     7692
     7693    /**
     7694     * Build file URL from base URL and relative path
     7695     * Helper method to ensure correct URL construction with proper separator
     7696     *
     7697     * @param  string $path Relative file path (already encoded if needed)
     7698     * @return string Complete file URL
     7699     * @author Filester Fix
     7700     **/
     7701    protected function _buildFileUrl($path)
     7702    {
     7703        if (empty($this->URL)) {
     7704            return '';
     7705        }
     7706       
     7707        // Remove trailing slash from base URL
     7708        $baseUrl = rtrim($this->URL, '/');
     7709       
     7710        // Ensure path starts with /
     7711        $path = '/' . ltrim($path, '/');
     7712       
     7713        return $baseUrl . $path;
     7714    }
     7715
     7716    /**
    76467717     * Detect available archivers
    76477718     *
  • filester/trunk/includes/File_manager/lib/php/elFinderVolumeLocalFileSystem.class.php

    r3011147 r3421965  
    14181418                    $stat['path'] = $this->path($stat['hash']);
    14191419                    if ($this->URL && !isset($stat['url'])) {
    1420                         $_path = str_replace(DIRECTORY_SEPARATOR, '/', substr($p, strlen($this->root) + 1));
    1421                         $stat['url'] = $this->URL . str_replace('%2F', '/', rawurlencode($_path));
     1420                        $_path = $this->_getRelativePath($p);
     1421                        $_path = str_replace('%2F', '/', rawurlencode($_path));
     1422                        $stat['url'] = $this->_buildFileUrl($_path);
    14221423                    }
    14231424
  • filester/trunk/ninja-file-manager.php

    r3386229 r3421965  
    44 * Plugin URI: https://ninjateam.org/filester
    55 * Description: Made to help you focus on WordPress file management and avoid being distracted.
    6  * Version: 2.0.1
     6 * Version: 2.0.2
    77 * Author: Ninja Team
    88 * Author URI: https://ninjateam.org
     
    3636
    3737define('NJT_FS_BN_PREFIX', 'njt-fs');
    38 define('NJT_FS_BN_VERSION', '2.0.1');
     38define('NJT_FS_BN_VERSION', '2.0.2');
    3939define('NJT_FS_BN_DOMAIN', 'filester');
    4040
  • filester/trunk/readme.txt

    r3386229 r3421965  
    55Requires at least: 3.0
    66Tested up to: 6.8
    7 Stable tag: 2.0.1
     7Stable tag: 2.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    112112== Changelog ==
    113113
     114= Dec 17, 2025 - Version 2.0.2 =
     115- Added: Implement validation and auto-correction for the root folder path and URL
     116- Fixed: Occasionally, "/s/" is included in the link path on the file info
     117
    114118= Oct 29, 2025 - Version 2.0.1 =
    115119- Fixed: Display notice
Note: See TracChangeset for help on using the changeset viewer.