-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProcessFileManager.module
More file actions
306 lines (267 loc) · 10.7 KB
/
ProcessFileManager.module
File metadata and controls
306 lines (267 loc) · 10.7 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?php
include_once(/*NoCompile*/__DIR__ . '/filemanager/class/FileManager.php');
/**
* File Manager
*
* A module for managing files and folders. It supports creating, opening (e.g. viewing, playing,
* editing), renaming, moving or copying, deleting and searching for files, as well as modifying
* file attributes, properties and file permissions. Folders and files may be displayed in a
* hierarchical tree based on their directory structure.
*
* @version 0.0.5
* @author Matjaz Potocnik
* @author Gerd Tentler
* @link https://github.com/matjazpotocnik/ProcessFileManager
* @link http://www.gerd-tentler.de/tools/filemanager/
*
* ProcessWire 2.x/3.x, Copyright 2017 by Ryan Cramer
* Licensed under GNU/GPL v2
*
* https://processwire.com
*
*/
class ProcessFileManager extends Process implements Module, ConfigurableModule {
/**
* Module info
*
* @return array
*
*/
public static function getModuleInfo() {
return array(
'title' => 'File Manager',
'summary' => _('File manager'),
'version' => '0.0.5',
'author' => 'Matjaž Potočnik, Gerd Tentler',
'icon' => 'folder-o',
'href' => 'https://github.com/matjazpotocnik/ProcessFileManager/',
'requires' => 'ProcessWire>=2.5.3, PHP>=5.4.20',
'permissions' => array(
'file-manager' => _('File manager')
),
'page' => array(
'name' => 'file-manager',
'parent' => 'setup', //admin
'title' => 'File manager'
),
);
}
/**
* This module config data
* @var array
*/
protected $configData = array();
protected $defaults = array(
'fmView' => 'details',
'explorerWidth' => '25%',
'hideTitleBar' => '0',
'hideTitleBar' => '0',
'language' => 'en',
'dateTimeFormat' => '%Y-%m-%d %H:%M:%S',
'hideFooter' => '0',
//'fmEditor' => 'monaco',
'fmEditor' => 'codemirror',
);
public function init() {
parent::init();
$this->configData = array_merge($this->defaults, $this->wire('modules')->getModuleConfigData($this));
}
/**
* Module entry point
*
* @param array $options
* @return string html markup or download file
*
*/
public function ___execute($options = array()) {
if(!$this->wire('user')->isSuperuser() && !$this->wire('user')->hasPermission('file-manager')) return $this->_('Access denied.');
$input = $this->wire('input');
if($input->get('action') !== null) {
/**
* This code is part of the FileManager software (www.gerd-tentler.de/tools/filemanager), copyright by
* Gerd Tentler. Obtain permission before selling this code or hosting it on a commercial website or
* redistributing it over the Internet or in any other medium. In all cases copyright must remain intact.
*/
$container = $input->get('fmContainer');
if($container != '' && isset($_SESSION[$container])) {
$FileManager = unserialize($_SESSION[$container]);
$fmMode = (string) $input->get('fmMode');
$fmName = (string) $input->get('fmName');
if(!in_array($fmMode, $FileManager->binaryModes)) {
if($FileManager->locale) @setlocale(LC_ALL, $FileManager->locale);
$contentType = in_array($fmMode, $FileManager->htmlModes) ? 'text/html' : 'application/json';
header("Content-Type: $contentType; charset=UTF-8");
header('Cache-Control: private, no-cache, must-revalidate');
header('Expires: 0');
header('X-Robots-Tag: noindex, nofollow');
}
ob_start();
$FileManager->action();
ob_end_flush();
} else {
header('X-Robots-Tag: noindex, nofollow');
$msg = 'Cannot restore FileManager object from PHP session - ';
if($container == '') $msg .= 'fmContainer not set!';
else if(!session_id()) $msg .= 'could not create session!';
else $msg .= "\$_SESSION['$container'] not found!";
FileManager::error($msg);
}
exit(0);
}
$config = $this->wire('config');
$path = $config->urls->siteModules . __CLASS__ . '/filemanager/';
$tmpFilePath = $config->paths->cache . "filemanager";
wireMkdir($tmpFilePath);
$FM = new FileManager($config->paths->root);
$FM->fmView = $this->configData['fmView'];
$FM->explorerWidth = $this->configData['explorerWidth'];
$FM->hideTitleBar = $this->configData['hideTitleBar'];
$FM->language = $this->configData['language'];
if($this->configData['dateTimeFormat'] != '') $FM->dateTimeFormat = $this->configData['dateTimeFormat'];
$FM->tmpFilePath = $tmpFilePath;
$FM->logFilePath = $config->paths->logs;
$adminTheme = $this->wire('user')->admin_theme ? $this->wire('user')->admin_theme : $this->wire('config')->defaultAdminTheme;
$FM->adminTheme = $adminTheme;
$FM->defaultFilePermissions = $config->chmodFile;
$FM->defaultDirPermissions = $config->chmodDir;
//$FM->hideFileCnt = true;
//$FM->logSave = true;
//$FM->publicUrl = ''; //$config->urls->httpRoot;
//$FM->uploadEngine = 'php';
//$FM->forceFlash = false;
//$FM->hideSystemType = true;
$config->styles->add($path . 'css/filemanager.css');
if($this->configData['hideFooter'] == '1') $config->styles->add($config->urls->siteModules . __CLASS__ . '/footer.css');
$config->scripts->add($path . 'js/tools.js');
$config->scripts->add($path . 'js/ajax.js');
$config->scripts->add($path . 'js/filemanager.js');
$config->scripts->add($path . 'js/parser.js');
$config->scripts->add($path . 'ext/uppod/uppod.js');
$codemirror = $config->urls->siteModules . __CLASS__ . "/codemirror/";
$config->scripts->add("{$codemirror}lib/codemirror.js");
$config->scripts->add("{$codemirror}mode/clike/clike.js");
$config->scripts->add("{$codemirror}mode/xml/xml.js");
$config->scripts->add("{$codemirror}mode/javascript/javascript.js");
$config->scripts->add("{$codemirror}mode/css/css.js");
$config->scripts->add("{$codemirror}mode/htmlmixed/htmlmixed.js"); // depends on XML, JavaScript and CSS modes
$config->scripts->add("{$codemirror}mode/php/php.js"); // depends on XML, JavaScript, CSS, HTMLMixed and C-like modes
$config->scripts->add("{$codemirror}mode/sql/sql.js");
$config->scripts->add("{$codemirror}mode/markdown/markdown.js");
$config->scripts->add("{$codemirror}addon/search/search.js"); // https://codemirror.net/demo/search.html
$config->scripts->add("{$codemirror}addon/search/searchcursor.js");
$config->scripts->add("{$codemirror}addon/search/jump-to-line.js");
$config->scripts->add("{$codemirror}addon/dialog/dialog.js");
$config->scripts->add("{$codemirror}addon/selection/active-line.js");
$config->scripts->add("{$codemirror}addon/edit/matchbrackets.js");
$config->scripts->add("{$codemirror}addon/fold/foldcode.js");
$config->scripts->add("{$codemirror}addon/fold/foldgutter.js");
$config->scripts->add("{$codemirror}addon/fold/brace-fold.js");
$config->scripts->add("{$codemirror}addon/fold/xml-fold.js");
$config->scripts->add("{$codemirror}addon/fold/indent-fold.js");
$config->scripts->add("{$codemirror}addon/fold/markdown-fold.js");
$config->scripts->add("{$codemirror}addon/fold/comment-fold.js");
$config->styles->add ("{$codemirror}lib/codemirror.css");
$config->styles->add ("{$codemirror}addon/dialog/dialog.css");
$config->styles->add ("{$codemirror}addon/fold/foldgutter.css");
//if($this->theme != "default") $config->styles->add ("{$codemirror}theme/{$this->theme}.css");
if($this->configData['fmEditor'] == 'monaco') {
$config->scripts->add($config->urls->siteModules . __CLASS__ . '/monaco-editor/min/vs/loader.js');
//$config->scripts->add($config->urls->siteModules . __CLASS__ . '/monaco-editor/min/vs/require.js');
}
$out = "<div id='fmWrapper' style='width:100%; height:100%;'>"; // do not remove this line, leave the styles !!!
$out .= $FM->create();
$out .= "</div>";
return $out;
}
/**
* Module fields
*
* @param array $data config data
* @return InputfieldWrapper
*
*/
public function getModuleConfigInputfields(array $data) {
$fields = new InputfieldWrapper();
$modules = $this->wire('modules');
$defaults = $this->defaults;
$f = $modules->get('InputfieldSelect');
$f->name = 'explorerWidth';
$f->label = $this->_('Show the explorer window?');
$f->columnWidth = 33;
$f->required = true;
$f->addOption('25%', $this->_('Yes'));
$f->addOption('0', $this->_('No'));
$f->value = isset($data[$f->name]) ? $data[$f->name] : $defaults[$f->name];
$fields->add($f);
$f = $modules->get('InputfieldSelect');
$f->name = 'hideTitleBar';
$f->label = $this->_('Show the title bar?');
$f->columnWidth = 33;
$f->required = true;
$f->addOption('0', $this->_('Yes'));
$f->addOption('1', $this->_('No'));
$f->value = isset($data[$f->name]) ? $data[$f->name] : $defaults[$f->name];
$fields->add($f);
$f = $modules->get('InputfieldSelect');
$f->name = 'hideFooter';
$f->label = $this->_('Show admin theme footer?');
$f->columnWidth = 34;
$f->required = true;
$f->addOption('0', $this->_('Yes'));
$f->addOption('1', $this->_('No'));
$f->value = isset($data[$f->name]) ? $data[$f->name] : $defaults[$f->name];
$fields->add($f);
$f = $modules->get('InputfieldSelect');
$f->name = 'fmView';
$f->label = $this->_('Default view:');
$f->columnWidth = 33;
$f->required = true;
$f->addOption('details', $this->_('Details'));
$f->addOption('icons', $this->_('Icons'));
$f->value = isset($data[$f->name]) ? $data[$f->name] : $defaults[$f->name];
$fields->add($f);
$f = $modules->get('InputfieldSelect');
$f->name = 'language';
$f->label = $this->_('Language:');
$f->columnWidth = 33;
$f->required = true;
$f->addOption('en', 'English');
$f->addOption('de', 'Deutch');
$f->addOption('es', 'Español');
$f->addOption('fi', 'Suomi');
$f->addOption('fr', 'Français');
$f->addOption('hu', 'Magyar');
$f->addOption('it', 'Italiano');
$f->addOption('pl', 'Polski');
$f->addOption('pt', 'Português');
$f->addOption('ru', 'Русский');
$f->addOption('tr', 'Türkçe');
$f->value = isset($data[$f->name]) ? $data[$f->name] : $defaults[$f->name];
$fields->add($f);
$f = $modules->get('InputfieldText');
$f->name = 'dateTimeFormat';
$f->label = $this->_('Date/time format:');
$f->columnWidth = 34;
$f->required = true;
$f->value = isset($data[$f->name]) ? $data[$f->name] : $defaults[$f->name];
$fields->add($f);
$f = $modules->get('InputfieldSelect');
$f->name = 'fmEditor';
$f->label = $this->_('Default editor:');
$f->columnWidth = 33;
$f->required = true;
//$f->addOption('monaco', $this->_('Monaco editor'));
$f->addOption('codemirror', $this->_('CodeMirror'));
$f->value = isset($data[$f->name]) ? $data[$f->name] : $defaults[$f->name];
$fields->add($f);
return $fields;
}
/**
* Check for mbstring and iconv support.
*
*/
public function ___install() {
parent::___install();
if(!extension_loaded('mbstring') || !function_exists('iconv')) $this->message("Support for mbstring and iconv is recommended.");
}
}