-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathElfinderController.php
151 lines (133 loc) · 4.85 KB
/
ElfinderController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php namespace Barryvdh\Elfinder;
use Barryvdh\Elfinder\Session\LaravelSession;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Foundation\Application;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Request;
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Memory;
use League\Flysystem\Filesystem;
class ElfinderController extends Controller
{
protected $package = 'elfinder';
/**
* The application instance.
*
* @var \Illuminate\Foundation\Application
*/
protected $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function showIndex()
{
return $this->app['view']
->make($this->package . '::elfinder')
->with($this->getViewVars());
}
public function showTinyMCE()
{
return $this->app['view']
->make($this->package . '::tinymce')
->with($this->getViewVars());
}
public function showTinyMCE4()
{
return $this->app['view']
->make($this->package . '::tinymce4')
->with($this->getViewVars());
}
public function showTinyMCE5()
{
return $this->app['view']
->make($this->package . '::tinymce5')
->with($this->getViewVars());
}
public function showCKeditor4()
{
return $this->app['view']
->make($this->package . '::ckeditor4')
->with($this->getViewVars());
}
public function showPopup($input_id)
{
return $this->app['view']
->make($this->package . '::standalonepopup')
->with($this->getViewVars())
->with(compact('input_id'));
}
public function showFilePicker($input_id)
{
$type = Request::input('type');
$mimeTypes = implode(',',array_map(function($t){return "'".$t."'";}, explode(',',$type)));
return $this->app['view']
->make($this->package . '::filepicker')
->with($this->getViewVars())
->with(compact('input_id','type','mimeTypes'));
}
public function showConnector()
{
$roots = $this->app->config->get('elfinder.roots', []);
if (empty($roots)) {
$dirs = (array) $this->app['config']->get('elfinder.dir', []);
foreach ($dirs as $dir) {
$roots[] = [
'driver' => 'LocalFileSystem', // driver for accessing file system (REQUIRED)
'path' => public_path($dir), // path to files (REQUIRED)
'URL' => url($dir), // URL to files (REQUIRED)
'accessControl' => $this->app->config->get('elfinder.access') // filter callback (OPTIONAL)
];
}
$disks = (array) $this->app['config']->get('elfinder.disks', []);
foreach ($disks as $key => $root) {
if (is_string($root)) {
$key = $root;
$root = [];
}
$disk = app('filesystem')->disk($key);
if ($disk instanceof FilesystemAdapter) {
$defaults = [
'driver' => 'Flysystem',
'filesystem' => $disk->getDriver(),
'alias' => $key,
'accessControl' => $this->app->config->get('elfinder.access') // filter callback (OPTIONAL)
];
$root = array_merge($defaults, $root);
if (!isset($root['URL'])) {
$root['URLCallback'] = function($path) use ($disk) {
return $disk->url($path);
};
}
$roots[] = $root;
}
}
}
if (app()->bound('session.store')) {
$sessionStore = app('session.store');
$session = new LaravelSession($sessionStore);
} else {
$session = null;
}
$rootOptions = $this->app->config->get('elfinder.root_options', array());
foreach ($roots as $key => $root) {
$roots[$key] = array_merge($rootOptions, $root);
}
$opts = $this->app->config->get('elfinder.options', array());
$opts = array_merge($opts, ['roots' => $roots, 'session' => $session]);
// run elFinder
$connector = new Connector(new \elFinder($opts));
$connector->run();
return $connector->getResponse();
}
protected function getViewVars()
{
$dir = 'packages/barryvdh/' . $this->package;
$locale = str_replace("-", "_", $this->app->config->get('app.locale'));
if (!file_exists($this->app['path.public'] . "/$dir/js/i18n/elfinder.$locale.js")) {
$locale = false;
}
$csrf = true;
return compact('dir', 'locale', 'csrf');
}
}