diff --git a/php/autoload.php b/php/autoload.php new file mode 100644 index 000000000..b8f1d76f5 --- /dev/null +++ b/php/autoload.php @@ -0,0 +1,48 @@ + ELFINDER_PHP_ROOT_PATH . '/elFinder.class.php', + 'elFinderConnector' => ELFINDER_PHP_ROOT_PATH . '/elFinderConnector.class.php', + 'elFinderLibGdBmp' => ELFINDER_PHP_ROOT_PATH . '/libs/GdBmp.php', + 'elFinderPluginAutoResize' => ELFINDER_PHP_ROOT_PATH . '/plugins/AutoResize/plugin.php', + 'elFinderPluginAutoRotate' => ELFINDER_PHP_ROOT_PATH . '/plugins/AutoRotate/plugin.php', + 'elFinderPluginNormalizer' => ELFINDER_PHP_ROOT_PATH . '/plugins/Normalizer/plugin.php', + 'elFinderPluginSanitizer' => ELFINDER_PHP_ROOT_PATH . '/plugins/Sanitizer/plugin.php', + 'elFinderPluginWatermark' => ELFINDER_PHP_ROOT_PATH . '/plugins/Watermark/plugin.php', + 'elFinderSession' => ELFINDER_PHP_ROOT_PATH . '/elFinderSession.php', + 'elFinderSessionInterface' => ELFINDER_PHP_ROOT_PATH . '/elFinderSessionInterface.php', + 'elFinderVolumeDriver' => ELFINDER_PHP_ROOT_PATH . '/elFinderVolumeDriver.class.php', + 'elFinderVolumeDropbox' => ELFINDER_PHP_ROOT_PATH . '/elFinderVolumeDropbox.class.php', + 'elFinderVolumeFTP' => ELFINDER_PHP_ROOT_PATH . '/elFinderVolumeFTP.class.php', + 'elFinderVolumeFlysystemGoogleDriveCache' => ELFINDER_PHP_ROOT_PATH . '/elFinderFlysystemGoogleDriveNetmount.php', + 'elFinderVolumeFlysystemGoogleDriveNetmount' => ELFINDER_PHP_ROOT_PATH . '/elFinderFlysystemGoogleDriveNetmount.php', + 'elFinderVolumeLocalFileSystem' => ELFINDER_PHP_ROOT_PATH . '/elFinderVolumeLocalFileSystem.class.php', + 'elFinderVolumeMsSQL' => ELFINDER_PHP_ROOT_PATH . '/elFinderVolumeMsSQL.class.php', + 'elFinderVolumeMySQL' => ELFINDER_PHP_ROOT_PATH . '/elFinderVolumeMySQL.class.php', + 'elFinderVolumeS3' => ELFINDER_PHP_ROOT_PATH . '/elFinderVolumeS3.class.php', + ); + if (isset($map[$name])) { + return include_once($map[$name]); + } + $prefix = substr($name, 0, 14); + if (substr($prefix, 0, 8) === 'elFinder') { + if ($prefix === 'elFinderVolume') { + $file = ELFINDER_PHP_ROOT_PATH . '/' . $name . '.class.php'; + return (is_file($file) && include_once($file)); + } else if ($prefix === 'elFinderPlugin') { + $file = ELFINDER_PHP_ROOT_PATH . '/plugins/' . substr($name, 14) . '/plugin.php'; + return (is_file($file) && include_once($file)); + } + } + return false; +} + +if (version_compare(PHP_VERSION, '5.3', '<')) { + spl_autoload_register('elFinderAutoloader'); +} else { + spl_autoload_register('elFinderAutoloader', true, true); +} + diff --git a/php/connector.minimal.php-dist b/php/connector.minimal.php-dist index e14ff58dc..6374603b1 100644 --- a/php/connector.minimal.php-dist +++ b/php/connector.minimal.php-dist @@ -2,14 +2,15 @@ error_reporting(0); // Set E_ALL for debuging -include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderConnector.class.php'; -include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinder.class.php'; -include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDriver.class.php'; -include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSystem.class.php'; -// Required for MySQL storage connector -// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeMySQL.class.php'; -// Required for FTP connector support -// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeFTP.class.php'; +// load composer autoload before load elFinder autoload If you need composer +//require './vendor/autoload.php'; + +// elFinder autoload +require './autoload.php'; +// =============================================== + +// Enable FTP connector netmount +elFinder::$netDrivers['ftp'] = 'FTP'; // =============================================== /** @@ -22,7 +23,6 @@ include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSyste */ // // Required for Dropbox.com connector support // // On composer -// require 'vendor/autoload.php'; // elFinder::$netDrivers['dropbox'] = 'Dropbox'; // // OR on pear // include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDropbox.class.php'; @@ -36,8 +36,6 @@ include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSyste // // Required for Google Drive network mount // // Installation by composer // // `composer require nao-pon/flysystem-google-drive:~1.1 google/apiclient:~2.0@rc nao-pon/elfinder-flysystem-driver-ext` -// // composer autoload -// require 'vendor/autoload.php'; // // Enable network mount // elFinder::$netDrivers['googledrive'] = 'FlysystemGoogleDriveNetmount'; // // GoogleDrive Netmount driver need next two settings. You can get at https://console.developers.google.com diff --git a/php/connector.php-dist b/php/connector.php-dist index 243ecaa58..365e46a29 100644 --- a/php/connector.php-dist +++ b/php/connector.php-dist @@ -13,12 +13,15 @@ if (function_exists('date_default_timezone_set')) { date_default_timezone_set('Europe/Moscow'); } -include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderConnector.class.php'; -include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinder.class.php'; -include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDriver.class.php'; -include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSystem.class.php'; -include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeMySQL.class.php'; -include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeFTP.class.php'; +// load composer autoload before load elFinder autoload If you need composer +//require './vendor/autoload.php'; + +// elFinder autoload +require './autoload.php'; +// =============================================== + +// Enable FTP connector netmount +elFinder::$netDrivers['ftp'] = 'FTP'; // =============================================== /** @@ -31,7 +34,6 @@ include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeFTP.class.php' */ // // Required for Dropbox.com connector support // // On composer -// require 'vendor/autoload.php'; // elFinder::$netDrivers['dropbox'] = 'Dropbox'; // // OR on pear // include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDropbox.class.php'; @@ -45,8 +47,6 @@ include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeFTP.class.php' // // Required for Google Drive network mount // // Installation by composer // // `composer require nao-pon/flysystem-google-drive:~1.1 google/apiclient:~2.0@rc nao-pon/elfinder-flysystem-driver-ext` -// // composer autoload -// require 'vendor/autoload.php'; // // Enable network mount // elFinder::$netDrivers['googledrive'] = 'FlysystemGoogleDriveNetmount'; // // GoogleDrive Netmount driver need next two settings. You can get at https://console.developers.google.com diff --git a/php/elFinder.class.php b/php/elFinder.class.php index fd9f04d87..93174e844 100644 --- a/php/elFinder.class.php +++ b/php/elFinder.class.php @@ -815,10 +815,15 @@ class elFinder { protected function getPluginInstance($name, $opts = array()) { $key = strtolower($name); if (! isset($this->plugins[$key])) { - $p_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . 'plugin.php'; - if (is_file($p_file)) { - require_once $p_file; - $class = 'elFinderPlugin' . $name; + $class = 'elFinderPlugin' . $name; + // to try auto load + if (! class_exists($class)) { + $p_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . 'plugin.php'; + if (is_file($p_file)) { + include_once $p_file; + } + } + if (class_exists($class, false)) { $this->plugins[$key] = new $class($opts); } else { $this->plugins[$key] = false;