diff --git a/composer.json b/composer.json index 13368e2..6a150e5 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "require": { "php": ">=5.3.0", "illuminate/support": "4.x", - "barryvdh/elfinder-builds": "2.1.x" + "barryvdh/elfinder-builds": "2.1.x", + "barryvdh/elfinder-flysystem-driver": "0.1.x@dev" }, "autoload": { "psr-4": { diff --git a/readme.md b/readme.md index 15d1d27..5c069a3 100644 --- a/readme.md +++ b/readme.md @@ -44,6 +44,23 @@ The default configuration requires a directory called 'files' in the public fold In your app/config/packages/barryvdh/laravel-elfinder, you can change the default folder, the access callback or define your own roots. +### Using Filesystem disks + +Laravel 4 has the ability to use Flysystem adapters using the package "graham-campbell/flysystem": "~1.0" [found here](https://github.com/GrahamCampbell/Laravel-Flysystem/tree/v1.0.0) as local/cloud disks. You can add those disks to elFinder, using the `disks` config. + +This examples adds the `local` disk and `my-disk`: + + 'disks' => [ + 'local', + 'my-disk' => [ + 'URL' => url('to/disk'), + 'alias' => 'Local storage', + ] + ], + +You can add an array to provide extra options, like the URL, alias etc. [Look here](https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options-2.1#root-options) for all options. +Also see [elfinder-flysystem-driver](https://github.com/barryvdh/elfinder-flysystem-driver) for [Glide](http://glide.thephpleague.com/) usage. + ### TinyMCE 4.x You can add tinyMCE integration by adding the following route: diff --git a/src/ElfinderController.php b/src/ElfinderController.php index c08391c..09d44f1 100644 --- a/src/ElfinderController.php +++ b/src/ElfinderController.php @@ -22,7 +22,6 @@ public function showTinyMCE() public function showTinyMCE4() { - return $this->app['view'] ->make($this->package . '::tinymce4') ->with($this->getViewVars()); @@ -45,25 +44,42 @@ public function showPopup($input_id) public function showConnector() { - $dir = $this->app->config->get($this->package . '::dir'); - $roots = $this->app->config->get($this->package . '::roots'); + $roots = $this->app->config->get($this->package . '::roots', []); + + if (empty($roots)) { - if (!$roots) - { - $roots = array( - array( + $dirs = (array) $this->app->config->get($this->package . '::dir', []); + foreach ($dirs as $dir) { + $roots[] = [ 'driver' => 'LocalFileSystem', // driver for accessing file system (REQUIRED) - 'path' => $this->app['path.public'] . DIRECTORY_SEPARATOR . $dir, // path to files (REQUIRED) - 'URL' => $this->app['url']->asset($dir), // URL to files (REQUIRED) + 'path' => public_path($dir), // path to files (REQUIRED) + 'URL' => url($dir), // URL to files (REQUIRED) 'accessControl' => $this->app->config->get($this->package . '::access') // filter callback (OPTIONAL) - ) - ); + ]; + } + + $disks = (array) $this->app['config']->get($this->package . '::disks', []); + if ($this->app->bound('flysystem')) { + foreach ($disks as $key => $root) { + if (is_string($root)) { + $key = $root; + $root = []; + } + $driver = app('flysystem')->connection($key); + if ($driver instanceof \League\Flysystem\Filesystem) { + $defaults = [ + 'driver' => 'Flysystem', + 'filesystem' => $driver, + 'alias' => $key, + ]; + $roots[] = array_merge($defaults, $root); + } + } + } } $opts = $this->app->config->get($this->package . '::options', array()); - $opts = array_merge(array( - 'roots' => $roots - ), $opts); + $opts = array_merge(array('roots' => $roots), $opts); // run elFinder $connector = new Connector(new \elFinder($opts)); diff --git a/src/config/config.php b/src/config/config.php index b231c6b..c0f153e 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -10,8 +10,24 @@ | The dir where to store the images (relative from public) | */ + 'dir' => ['files'], - 'dir' => 'files', + /* + |-------------------------------------------------------------------------- + | Filesystem disks (Flysytem) + |-------------------------------------------------------------------------- + | + | Define an array of Filesystem disks, which use Flysystem. + | You can set extra options, example: + | + | 'my-disk' => [ + | 'URL' => url('to/disk'), + | 'alias' => 'Local storage', + | ] + */ + 'disks' => [ + + ], /* |--------------------------------------------------------------------------