|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace UniSharp\LaravelFilemanager\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use UniSharp\LaravelFilemanager\Lfm; |
|
6
|
|
|
use UniSharp\LaravelFilemanager\LfmPath; |
|
7
|
|
|
|
|
8
|
|
|
class LfmController extends Controller |
|
9
|
|
|
{ |
|
10
|
|
|
protected static $success_response = 'OK'; |
|
11
|
|
|
|
|
12
|
|
|
public function __construct() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->applyIniOverrides(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Set up needed functions. |
|
19
|
|
|
* |
|
20
|
|
|
* @return object|null |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __get($var_name) |
|
23
|
|
|
{ |
|
24
|
|
|
if ($var_name === 'lfm') { |
|
25
|
|
|
return app(LfmPath::class); |
|
|
|
|
|
|
26
|
|
|
} elseif ($var_name === 'helper') { |
|
27
|
|
|
return app(Lfm::class); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Show the filemanager. |
|
33
|
|
|
* |
|
34
|
|
|
* @return mixed |
|
35
|
|
|
*/ |
|
36
|
|
|
public function show() |
|
37
|
|
|
{ |
|
38
|
|
|
$key_auth_token = \config('lfm')['key_auth_token']; |
|
|
|
|
|
|
39
|
|
|
$no_authenticate_redirect_to = \config('lfm')['no_authenticate_token_redirect_to']; |
|
40
|
|
|
|
|
41
|
|
|
return view('laravel-filemanager::index', compact('key_auth_token', 'no_authenticate_redirect_to')) |
|
|
|
|
|
|
42
|
|
|
->withHelper($this->helper); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Check if any extension or config is missing. |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getErrors() |
|
51
|
|
|
{ |
|
52
|
|
|
$arr_errors = []; |
|
53
|
|
|
|
|
54
|
|
|
if (!extension_loaded('gd') && !extension_loaded('imagick')) { |
|
55
|
|
|
array_push($arr_errors, trans('laravel-filemanager::lfm.message-extension_not_found')); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if (!extension_loaded('exif')) { |
|
59
|
|
|
array_push($arr_errors, 'EXIF extension not found.'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (!extension_loaded('fileinfo')) { |
|
63
|
|
|
array_push($arr_errors, 'Fileinfo extension not found.'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$mine_config_key = 'lfm.folder_categories.' |
|
67
|
|
|
. $this->helper->currentLfmType() |
|
|
|
|
|
|
68
|
|
|
. '.valid_mime'; |
|
69
|
|
|
|
|
70
|
|
|
if (!is_array(config($mine_config_key))) { |
|
|
|
|
|
|
71
|
|
|
array_push($arr_errors, 'Config : ' . $mine_config_key . ' is not a valid array.'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $arr_errors; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function error($error_type, $variables = []) |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->helper->error($error_type, $variables); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Overrides settings in php.ini. |
|
84
|
|
|
* |
|
85
|
|
|
* @return null |
|
86
|
|
|
*/ |
|
87
|
|
|
public function applyIniOverrides() |
|
88
|
|
|
{ |
|
89
|
|
|
$overrides = config('lfm.php_ini_overrides', []); |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
if ($overrides && is_array($overrides) && count($overrides) === 0) { |
|
92
|
|
|
return; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
foreach ($overrides as $key => $value) { |
|
96
|
|
|
if ($value && $value != 'false') { |
|
97
|
|
|
ini_set($key, $value); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* If your use token authenticate, before show media manager call this api for checking authenticate |
|
105
|
|
|
* |
|
106
|
|
|
* @return object|null |
|
107
|
|
|
* |
|
108
|
|
|
*/ |
|
109
|
|
|
public function checkAuthenticate() |
|
110
|
|
|
{ |
|
111
|
|
|
try { |
|
112
|
|
|
$guard_name = \config('lfm.guard_name'); |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
$auth = \Auth::guard($guard_name); |
|
115
|
|
|
if ($auth->check()) { |
|
116
|
|
|
$response = [ |
|
117
|
|
|
'message' => 'Authorization', |
|
118
|
|
|
'errors' => [], |
|
119
|
|
|
'data' => [ |
|
120
|
|
|
'authorization' => true, |
|
121
|
|
|
'redirect_to' => null, |
|
122
|
|
|
] |
|
123
|
|
|
]; |
|
124
|
|
|
$status_code = 200; |
|
125
|
|
|
} else { |
|
126
|
|
|
$response = [ |
|
127
|
|
|
'message' => 'No authorization', |
|
128
|
|
|
'errors' => [], |
|
129
|
|
|
'data' => [ |
|
130
|
|
|
'authorization' => false, |
|
131
|
|
|
'redirect_to' => \config('lfm.no_authenticate_token_redirect_to'), |
|
132
|
|
|
] |
|
133
|
|
|
]; |
|
134
|
|
|
$status_code = 401; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
return response($response, $status_code); |
|
|
|
|
|
|
138
|
|
|
} catch (\Exception $e) { |
|
139
|
|
|
return \response([ |
|
140
|
|
|
'message' => 'Error machine', |
|
141
|
|
|
'errors' => [ |
|
142
|
|
|
'machine' => [$e->getMessage()], |
|
143
|
|
|
], |
|
144
|
|
|
'data' => [], |
|
145
|
|
|
], 500); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|