PluginProbe ʕ •ᴥ•ʔ
File Manager Pro – Filester / 1.9
File Manager Pro – Filester v1.9
2.1.1 trunk 1.6.1 1.7.6 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 2.0 2.0.1 2.0.2 2.1.0
filester / includes / File_manager / FileManager.php
filester / includes / File_manager Last commit date
lib 9 months ago FileManager.php 9 months ago FileManagerHelper.php 9 months ago index.php 9 months ago
FileManager.php
657 lines
1 <?php
2 namespace NinjaFileManager\File_manager;
3
4 defined('ABSPATH') || exit;
5
6 /**
7 * Settings Page
8 */
9
10 class FileManager
11 {
12 protected static $instance = null;
13
14 /**
15 *
16 * @var object $options The object of the options class
17 *
18 * */
19 public $options;
20 public $fmCapability = '';
21 public $userRole = '';
22 private $hook_suffix = array();
23
24 public static function getInstance()
25 {
26 if (null == self::$instance) {
27 self::$instance = new self;
28 }
29
30 return self::$instance;
31 }
32
33 private function __construct()
34 {
35 //get user role
36 $user = wp_get_current_user();
37 $this->userRole = $user && $user->roles && isset($user->roles[0]) ? $user->roles[0] : '';
38
39 if ( empty($this->userRole) && isset($user->roles)) {
40 $role = '';
41 foreach( $user->roles as $key => $value) {
42 $role = $value;
43 }
44
45 $this->userRole = $role;
46 }
47
48 // Loading Options
49 // Options
50 $this->options = get_option('njt_fs_settings');
51 if(empty($this->options)) {
52 $this->options = array( // Setting up default values
53 'njt_fs_file_manager_settings' => array(
54 'root_folder_path' => ABSPATH,
55 'root_folder_url' => site_url(),
56 'enable_sensitive_protection' => '1'
57 ),
58 );
59 }
60 register_shutdown_function(array($this, 'saveOptions'));
61
62 add_action('init', array($this, 'isAlowUserAccess'));
63 if ($this->isAlowUserAccess()) {
64 add_action('admin_enqueue_scripts', array($this, 'enqueueAdminScripts'));
65 add_action('admin_menu', array($this, 'FileManager'));
66 add_action('wp_ajax_fs_connector', array($this, 'fsConnector'));
67 add_action('wp_ajax_selector_themes', array($this, 'selectorThemes'));
68 add_action('wp_ajax_get_role_restrictions', array($this, 'getArrRoleRestrictions'));
69 add_action('wp_ajax_njt_fs_save_setting', array($this, 'njt_fs_saveSetting'));
70 add_action('wp_ajax_njt_fs_save_setting_restrictions', array($this, 'njt_fs_saveSettingRestrictions'));
71
72 $optionReview = get_option('njt_fs_review');
73 if (time() >= (int)$optionReview && $optionReview !== '0'){
74 add_action('admin_notices', array($this, 'njt_fs_give_review'));
75 }
76
77 add_action('wp_ajax_njt_fs_save_review', array($this, 'njt_fs_save_review'));
78 }
79 }
80
81 public function njt_fs_give_review()
82 {
83 if (function_exists('get_current_screen')) {
84 if (get_current_screen()->id == 'file-manager_page_filester-settings' || get_current_screen()->id == 'toplevel_page_njt-fs-filemanager' || get_current_screen()->id == 'plugins') {
85 $this->enqueue_scripts();
86 ?>
87 <div class="notice notice-success is-dismissible" id="njt-fs-review">
88 <h3><?php _e('Give Filester a review', 'filester')?></h3>
89 <p>
90 <?php _e('Thank you for choosing Filester. We hope you love it. Could you take a couple of seconds posting a nice review to share your happy experience?', 'filester')?>
91 </p>
92 <p>
93 <?php _e('We will be forever grateful. Thank you in advance ;)', 'filester')?>
94 </p>
95 <p>
96 <a href="javascript:;" data="rateNow" class="button button-primary" style="margin-right: 5px"><?php _e('Rate now', 'filester')?></a>
97 <a href="javascript:;" data="later" class="button" style="margin-right: 5px"><?php _e('Later', 'filester')?></a>
98 <a href="javascript:;" data="alreadyDid" class="button"><?php _e('Already did', 'filester')?></a>
99 </p>
100 </div>
101 <?php
102 }
103 }
104 }
105
106 public function njt_fs_save_review()
107 {
108 if ( isset( $_POST ) ) {
109 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : null;
110 $field = isset( $_POST['field'] ) ? sanitize_text_field( $_POST['field'] ) : null;
111
112 if ( ! wp_verify_nonce( $nonce, 'njt-fs-review' ) ) {
113 wp_send_json_error( array( 'status' => 'Wrong nonce validate!' ) );
114 exit();
115 }
116
117 if ($field == 'later'){
118 update_option('njt_fs_review', time() + 3*60*60*24); //After 3 days show
119 } else if ($field == 'alreadyDid'){
120 update_option('njt_fs_review', 0);
121 }
122 wp_send_json_success();
123 }
124 wp_send_json_error( array( 'message' => 'Update fail!' ) );
125 }
126
127 public function enqueue_scripts(){
128 wp_enqueue_script('njt-fs-review', NJT_FS_BN_PLUGIN_URL . 'assets/js/review.js', array('jquery'), NJT_FS_BN_VERSION, false);
129 wp_localize_script('njt-fs-review', 'wpDataFs', array(
130 'admin_ajax' => admin_url('admin-ajax.php'),
131 'nonce' => wp_create_nonce("njt-fs-review"),
132 ));
133 }
134
135 public function isAlowUserAccess()
136 {
137 if($this->userRole) {
138 $allowed_roles = !empty($this->options['njt_fs_file_manager_settings']['list_user_alow_access']) ? $this->options['njt_fs_file_manager_settings']['list_user_alow_access'] : array();
139 if( in_array($this->userRole,$allowed_roles)) {
140 if (is_multisite() && $this->userRole == 'administrator') {
141 $this->fmCapability = 'activate_plugins';
142 }
143 $this->fmCapability = $this->userRole;
144 return true;
145 }
146 }
147 if (is_multisite() && is_super_admin()) {
148 $this->fmCapability = 'create_sites';
149 return true;
150 }
151
152 if (!is_multisite() && is_super_admin()) {
153 $this->fmCapability = 'administrator';
154 return true;
155 }
156 $this->fmCapability = 'read';
157 return false;
158 }
159
160 public function FileManager()
161 {
162 if( class_exists( 'NestedPages' ) ) {
163 $this->fmCapability = 'read';
164 }
165 $icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTEwLDRINEMyLjg5LDQgMiw0Ljg5IDIsNlYxOEEyLDIgMCAwLDAgNCwyMEgyMEEyLDIgMCAwLDAgMjIsMThWOEMyMiw2Ljg5IDIxLjEsNiAyMCw2SDEyTDEwLDRaIiBmaWxsPSIjYTdhYWFkIi8+PC9zdmc+';
166 $display_suffix = add_menu_page(
167 __('Filester', 'textdomain'),
168 'File Manager',
169 $this->fmCapability,
170 'njt-fs-filemanager',
171 array($this, 'fsViewFileCallback'),
172 $icon,
173 9
174 );
175 if (is_multisite()) {
176 $settings_suffix = add_submenu_page (
177 'njt-fs-filemanager',
178 'Settings',
179 'Settings',
180 'create_sites',
181 'filester-settings',
182 array($this, 'fsSettingsPage') );
183 }
184
185 if (!is_multisite()) {
186 $settings_suffix = add_submenu_page (
187 'njt-fs-filemanager',
188 'Settings',
189 'Settings',
190 'manage_options',
191 'filester-settings',
192 array($this, 'fsSettingsPage') );
193 }
194
195 $this->hook_suffix = array($display_suffix, $settings_suffix);
196 }
197
198 public function fsViewFileCallback()
199 {
200 $viewPath = NJT_FS_BN_PLUGIN_PATH . 'views/pages/html-filemanager.php';
201 include_once $viewPath;
202 }
203
204 public function fsSettingsPage()
205 {
206 $viewPath = NJT_FS_BN_PLUGIN_PATH . 'views/pages/html-filemanager-settings.php';
207 include_once $viewPath;
208 }
209
210 public function enqueueAdminScripts($suffix)
211 {
212 if (in_array($suffix, $this->hook_suffix)) {
213 $selectorThemes = get_option('njt_fs_selector_themes');
214 if (empty($selectorThemes[$this->userRole])) {
215 $selectorThemes[$this->userRole]['themesValue'] = 'Default';
216 update_option('njt_fs_selector_themes', $selectorThemes);
217 }
218
219 $selectedTheme = $selectorThemes[$this->userRole]['themesValue'];
220
221 //elfinder css
222 wp_enqueue_style('elfinder.jq.css', plugins_url('/lib/jquery/jquery-ui.min.css', __FILE__));
223 wp_enqueue_style('elfinder.full.css', plugins_url('/lib/css/elfinder.min.css', __FILE__));
224 wp_enqueue_style('themes', plugins_url('/lib/css/theme.css', __FILE__));
225 wp_enqueue_style('themes-selector', plugins_url('/lib/themes/' . $selectedTheme . '/css/theme.css', __FILE__));
226
227 //elfinder core
228 if(version_compare(get_bloginfo('version'),'5.6', '>=') ){
229 wp_enqueue_script('jquery_min', plugins_url('/lib/jquery/jquery-ui.min.js', __FILE__));
230 } else {
231 wp_enqueue_script('jquery_min', plugins_url('/lib/jquery/jquery-ui-old.min.js', __FILE__));
232 }
233
234 //elfinder js, toastr JS, css custom
235 wp_register_style('njt_fs_toastr_css',NJT_FS_BN_PLUGIN_URL . 'assets/js/toastr/toastr.min.css');
236 wp_enqueue_style('njt_fs_toastr_css');
237 wp_enqueue_script('njt_fs_toastr_js', NJT_FS_BN_PLUGIN_URL . 'assets/js/toastr/toastr.min.js', array('jquery'), NJT_FS_BN_VERSION);
238
239 wp_register_style('file_manager_admin_css',NJT_FS_BN_PLUGIN_URL . 'assets/css/file_manager_admin.css');
240 wp_enqueue_style('file_manager_admin_css');
241 wp_enqueue_script('file_manager_admin', NJT_FS_BN_PLUGIN_URL . 'assets/js/file_manager_admin.js', array('jquery'), NJT_FS_BN_VERSION, true);
242
243 //js load elFinder
244 wp_enqueue_script('njt_fs_elFinder', plugins_url('/lib/js/elfinder.min.js', __FILE__));
245
246 wp_enqueue_script('njt_fs_elfinder_editor', plugins_url('/lib/js/extras/editors.default.js', __FILE__));
247 //js load fm_locale
248 if(isset($this->options['njt_fs_file_manager_settings']['fm_locale'])) {
249 $locale = $this->options['njt_fs_file_manager_settings']['fm_locale'];
250 if( !empty($locale) && $locale != 'en' && in_array($locale, njt_fs_locales(), true)) {
251 $locale = sanitize_file_name($locale);
252 wp_enqueue_script( 'njt_fs_fma_lang', plugins_url('lib/js/i18n/elfinder.'.$locale.'.js', __FILE__));
253 }
254 }
255
256 wp_localize_script('njt_fs_elFinder', 'wpData', array(
257 'admin_ajax' => admin_url('admin-ajax.php'),
258 'nonce' => wp_create_nonce("njt-fs-file-manager-admin"),
259 'PLUGIN_URL' => NJT_FS_BN_PLUGIN_URL .'includes/File_manager/lib/',
260 'PLUGIN_PATH' => NJT_FS_BN_PLUGIN_PATH.'includes/File_manager/lib/',
261 'PLUGIN_DIR'=> NJT_FS_BN_PLUGIN_DIR,
262 'ABSPATH'=> str_replace("\\", "/", ABSPATH),
263 'is_multisite' => is_multisite(),
264 'lang' => !empty( $this->options['njt_fs_file_manager_settings']['fm_locale']) ? sanitize_file_name($this->options['njt_fs_file_manager_settings']['fm_locale']) : '',
265 'nonce_connector' => wp_create_nonce('file-manager-security-token'),
266 ));
267 }
268 }
269
270 //File manager connector function
271
272 public function fsConnector()
273 {
274 check_ajax_referer( 'file-manager-security-token', 'nonce' );
275 $uploadMaxSize = isset($this->options['njt_fs_file_manager_settings']['upload_max_size']) && !empty($this->options['njt_fs_file_manager_settings']['upload_max_size']) ? $this->options['njt_fs_file_manager_settings']['upload_max_size'] : 0;
276
277 $opts = array(
278 'bind' => array(
279 'put.pre' => array(new \FileManagerHelper, 'madeStripcslashesFile'), // Check endcode when save file.
280 ),
281 'debug' => false,
282 'roots' => array(
283 array(
284 'driver' => 'LocalFileSystem',
285 'path' => isset($this->options['njt_fs_file_manager_settings']['root_folder_path']) && !empty($this->options['njt_fs_file_manager_settings']['root_folder_path']) ? $this->options['njt_fs_file_manager_settings']['root_folder_path'] : ABSPATH,
286 'URL' => isset($this->options['njt_fs_file_manager_settings']['root_folder_url']) && !empty($this->options['njt_fs_file_manager_settings']['root_folder_url']) ? $this->options['njt_fs_file_manager_settings']['root_folder_url'] : site_url(),
287 'trashHash' => '', // default is empty, when not enable trash
288 'uploadMaxSize' => $uploadMaxSize .'M',
289 'winHashFix' => DIRECTORY_SEPARATOR !== '/',
290 'uploadOrder' => array('deny', 'allow'),
291 'uploadDeny' => array('htaccess'),
292 //'acceptedName' => 'validName',
293 'attributes' => array() // default is empty
294 ),
295 ),
296 );
297
298
299
300 //Enable Trash
301 if(isset($this->options['njt_fs_file_manager_settings']['enable_trash']) && ($this->options['njt_fs_file_manager_settings']['enable_trash'] == '1')) {
302 $trash = array(
303 'id' => '1',
304 'driver' => 'Trash',
305 'path' => NJT_FS_BN_PLUGIN_PATH.'includes/File_manager/lib/files/.trash/',
306 'tmbURL' => site_url() . '/includes/File_manager/lib/files/.trash/.tmb',
307 'winHashFix' => DIRECTORY_SEPARATOR !== '/',
308 'uploadDeny' => array('htaccess'),
309 'uploadAllow' => array('all'),
310 'uploadOrder' => array('deny', 'allow'),
311 // 'acceptedName' => 'validName',
312 'attributes' => array(
313 array(
314 'pattern' => '/.tmb/',
315 'read' => false,
316 'write' => false,
317 'hidden' => true,
318 'locked' => false
319 ),
320 array(
321 'pattern' => '/.gitkeep/',
322 'read' => false,
323 'write' => false,
324 'hidden' => true,
325 'locked' => false
326 )
327 )
328 );
329 $opts['roots'][0]['trashHash'] = 't1_Lw';
330 $opts['roots'][1] = $trash;
331 }
332
333 //Start --setting User Role Restrictions
334 $user = wp_get_current_user();
335 $userRoles = $user && $user->roles && $user->roles[0] ? $user->roles[0] : '';
336
337 //Disable Operations
338 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['list_user_restrictions_alow_access'])){
339 $opts['roots'][0]['disabled'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['list_user_restrictions_alow_access'];
340 }
341 //Creat root path for user
342 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'])){
343 $opts['roots'][0]['path'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'] .'/';
344 }
345
346 //Creat url root path for user
347 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'])){
348 $opts['roots'][0]['URL'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'] .'/';
349 }
350
351 //Folder or File Paths That You want to Hide
352 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['hide_paths'])){
353 foreach ($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['hide_paths'] as $key => $value){
354 $arrItemHidePath = array(
355 'pattern' => '~/'.$value.'~',
356 'read' => false,
357 'write' => false,
358 'hidden' => true,
359 'locked' => false
360 );
361 array_push($opts['roots'][0]['attributes'], $arrItemHidePath);
362 };
363 }
364
365 //File extensions which you want to Lock
366 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['lock_files'])){
367 foreach ($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['lock_files'] as $key => $value){
368 $arrItemLockFile = array(
369 'pattern' => '/'.$value.'/',
370 'read' => false,
371 'write' => false,
372 'hidden' => false,
373 'locked' => true
374 );
375 array_push($opts['roots'][0]['attributes'], $arrItemLockFile);
376 };
377 }
378
379 //Enter file extensions which can be uploaded
380 $flag = false;
381
382
383 if (is_multisite()) {
384 if( !current_user_can('create_sites') && empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
385 $opts['roots'][0]['uploadDeny'] = array('all');
386 $opts['roots'][0]['uploadAllow'] = array('');
387 } else if ( !current_user_can('create_sites') && !empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
388 $opts['roots'][0]['uploadDeny'] = array('all');
389 $opts['roots'][0]['uploadAllow'] = array();
390 $arrCanUploadMime = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'];
391 $mimeTypes = new \FileManagerHelper();
392 $arrMimeTypes = $mimeTypes->getArrMimeTypes();
393 foreach ($arrMimeTypes as $key => $value){
394 if(in_array($key,$arrCanUploadMime)) {
395 $explodeValue = explode(',',$value);
396 foreach($explodeValue as $item) {
397 array_push($opts['roots'][0]['uploadAllow'], $item );
398 }
399 }
400
401 };
402 foreach ($arrCanUploadMime as $value){
403 if(strpos($value,"x-conference") !== false
404 || strpos($value,"video") !== false
405 || strpos($value,"text") !== false
406 || strpos($value,"model") !== false
407 || strpos($value,"message") !== false
408 || strpos($value,"image") !== false
409 || strpos($value,"font") !== false
410 || strpos($value,"chemical") !== false
411 || strpos($value,"audio") !== false
412 || strpos($value,"application") !== false
413 ) {
414 array_push($opts['roots'][0]['uploadAllow'], $value );
415 }
416 }
417
418 } else {
419 $opts['roots'][0]['uploadDeny'] = array();
420 $opts['roots'][0]['uploadAllow'] = array('all');
421 }
422 }
423
424 if (!is_multisite()) {
425 if($this->userRole !== 'administrator' && empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
426 $opts['roots'][0]['uploadDeny'] = array('all');
427 $opts['roots'][0]['uploadAllow'] = array('');
428 } else if ( $this->userRole !== 'administrator' && !empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
429 $opts['roots'][0]['uploadDeny'] = array('all');
430 $opts['roots'][0]['uploadAllow'] = array();
431 $arrCanUploadMime = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'];
432 $mimeTypes = new \FileManagerHelper();
433 $arrMimeTypes = $mimeTypes->getArrMimeTypes();
434 foreach ($arrMimeTypes as $key => $value){
435 if(in_array($key,$arrCanUploadMime)) {
436 $explodeValue = explode(',',$value);
437 foreach($explodeValue as $item) {
438 $listFileCanNotUpload = $mimeTypes->listFileCanNotUpload();
439 if(!in_array($item, $listFileCanNotUpload)) {
440 array_push($opts['roots'][0]['uploadAllow'], $item );
441 }
442 }
443 }
444
445 };
446 foreach ($arrCanUploadMime as $value){
447 if(strpos($value,"x-conference") !== false
448 || strpos($value,"video") !== false
449 || strpos($value,"text") !== false
450 || strpos($value,"model") !== false
451 || strpos($value,"message") !== false
452 || strpos($value,"image") !== false
453 || strpos($value,"font") !== false
454 || strpos($value,"chemical") !== false
455 || strpos($value,"audio") !== false
456 || strpos($value,"application") !== false
457 ) {
458 array_push($opts['roots'][0]['uploadAllow'], $value );
459 }
460 }
461
462 } else {
463 $opts['roots'][0]['uploadDeny'] = array();
464 $opts['roots'][0]['uploadAllow'] = array('all');
465 }
466 }
467
468 // Sensitive files protection
469 if(isset($this->options['njt_fs_file_manager_settings']['enable_sensitive_protection']) && ($this->options['njt_fs_file_manager_settings']['enable_sensitive_protection'] == '1')) {
470 $sensitive_files = apply_filters('njt_fs_sensitive_files', array(
471 '.htaccess',
472 'wp-config.php',
473 '.env',
474 'wp-config-sample.php',
475 'readme.html',
476 'license.txt',
477 'xmlrpc.php'
478 ));
479
480 foreach ($sensitive_files as $file) {
481 $attributes = array(
482 'pattern' => '/' . preg_quote($file, '/') . '/',
483 'read' => $this->canAccessSensitiveFiles(),
484 'write' => $this->canEditSensitiveFiles(),
485 'hidden' => !$this->canAccessSensitiveFiles(),
486 'locked' => !$this->canEditSensitiveFiles()
487 );
488 array_push($opts['roots'][0]['attributes'], $attributes);
489 }
490 }
491
492 // .htaccess
493 if(isset($this->options['njt_fs_file_manager_settings']['enable_htaccess']) && ($this->options['njt_fs_file_manager_settings']['enable_htaccess'] == '1')) {
494 $attributes = array(
495 'pattern' => '/.htaccess/',
496 'read' => true,
497 'write' => false,
498 'hidden' => true,
499 'locked' => true
500 );
501 array_push($opts['roots'][0]['attributes'], $attributes);
502 }
503
504 //End --setting User Role Restrictions
505
506 $connector = new \elFinderConnector(new \elFinder($opts));
507 $connector->run();
508 wp_die();
509 }
510
511 public function selectorThemes()
512 {
513 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
514 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
515
516 $themesValue = sanitize_text_field ($_POST['themesValue']);
517 $selectorThemes = get_option('njt_fs_selector_themes');
518 if (empty($selectorThemes[$this->userRole])) {
519 $selectorThemes[$this->userRole]['themesValue'] = 'Default';
520 update_option('njt_fs_selector_themes', $selectorThemes);
521 }
522
523 if ($selectorThemes[$this->userRole]['themesValue'] != $themesValue) {
524 $selectorThemes[$this->userRole]['themesValue'] = $themesValue;
525 update_option('njt_fs_selector_themes', $selectorThemes);
526 }
527 $selected_themes = get_option('njt_fs_selector_themes');
528 $linkThemes = plugins_url('/lib/themes/' . $selected_themes[$this->userRole]['themesValue'] . '/css/theme.css', __FILE__);
529 wp_send_json_success($linkThemes);
530 wp_die();
531 }
532
533 public function saveOptions()
534 {
535 //if(isset($_POST['njt-settings-form-submit'])) {
536 update_option('njt_fs_settings', $this->options);
537 // if($u) {
538 // $this->f('?page=njt-fs-filemanager-settings&status=1');
539 // } else {
540 // $this->f('?page=njt-fs-filemanager-settings&status=2');
541 // }
542 // }
543 }
544
545 public function f($u) {
546 echo '<script>';
547 echo 'window.location.href="'.$u.'"';
548 echo '</script>';
549 }
550
551 public function getArrRoleRestrictions()
552 {
553 if(!wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
554 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
555 $valueUserRole = filter_var($_POST['valueUserRole']) ? sanitize_text_field ($_POST['valueUserRole']) : '';
556 $arrRestrictions = !empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions']) ? $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'] : array();
557 $dataArrRoleRestrictions = array (
558 'disable_operations' => implode(",", !empty($arrRestrictions[$valueUserRole]['list_user_restrictions_alow_access']) ? $arrRestrictions[$valueUserRole]['list_user_restrictions_alow_access'] : array()),
559 'private_folder_access' => !empty($arrRestrictions[$valueUserRole]['private_folder_access']) ? str_replace("\\\\", "/", trim($arrRestrictions[$valueUserRole]['private_folder_access'])) : '',
560 'private_url_folder_access' => !empty($arrRestrictions[$valueUserRole]['private_url_folder_access']) ? str_replace("\\\\", "/", trim($arrRestrictions[$valueUserRole]['private_url_folder_access'])) : '',
561 'hide_paths' => implode(',', !empty($arrRestrictions[$valueUserRole]['hide_paths']) ? $arrRestrictions[$valueUserRole]['hide_paths'] : array()),
562 'lock_files' => implode(',', !empty($arrRestrictions[$valueUserRole]['lock_files']) ? $arrRestrictions[$valueUserRole]['lock_files'] : array()),
563 'can_upload_mime' => implode(',', !empty($arrRestrictions[$valueUserRole]['can_upload_mime']) ? $arrRestrictions[$valueUserRole]['can_upload_mime'] : array())
564 );
565 wp_send_json_success($dataArrRoleRestrictions);
566 wp_die();
567 }
568
569 public function njt_fs_saveSetting()
570 {
571 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
572 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
573
574 if (!current_user_can('manage_options')) {
575 wp_die();
576 }
577
578 $root_folder_path = !empty($_POST['root_folder_path']) ? str_replace("\\\\", "/", trim(sanitize_text_field($_POST['root_folder_path']))) : '';
579 $root_folder_url = !empty($_POST['root_folder_url']) ? str_replace("\\\\", "/", trim(sanitize_url($_POST['root_folder_url']))) : site_url();
580 $list_user_alow_access = !empty($_POST['list_user_alow_access']) ? explode(',', sanitize_text_field($_POST['list_user_alow_access'])) : array();
581 $upload_max_size = !empty($_POST['upload_max_size']) ? sanitize_text_field(trim($_POST['upload_max_size'])) : 0;
582 $fm_locale = !empty($_POST['fm_locale']) ? sanitize_text_field($_POST['fm_locale']) : 'en';
583 $enable_htaccess = isset($_POST['enable_htaccess']) && $_POST['enable_htaccess'] == 'true' ? 1 : 0;
584 $enable_trash = isset($_POST['enable_trash']) && $_POST['enable_trash'] == 'true' ? 1 : 0;
585 $enable_sensitive_protection = isset($_POST['enable_sensitive_protection']) && $_POST['enable_sensitive_protection'] == 'true' ? 1 : 0;
586 //save options
587 $this->options['njt_fs_file_manager_settings']['root_folder_path'] = $root_folder_path;
588 $this->options['njt_fs_file_manager_settings']['root_folder_url'] = $root_folder_url;
589 $this->options['njt_fs_file_manager_settings']['list_user_alow_access'] = $list_user_alow_access;
590 $this->options['njt_fs_file_manager_settings']['upload_max_size'] = $upload_max_size;
591 $this->options['njt_fs_file_manager_settings']['fm_locale'] = $fm_locale;
592 $this->options['njt_fs_file_manager_settings']['enable_htaccess'] = $enable_htaccess;
593 $this->options['njt_fs_file_manager_settings']['enable_trash'] = $enable_trash;
594 $this->options['njt_fs_file_manager_settings']['enable_sensitive_protection'] = $enable_sensitive_protection;
595 //update options
596 update_option('njt_fs_settings', $this->options);
597 wp_send_json_success(get_option('njt_fs_settings'));
598 wp_die();
599 }
600
601 public function njt_fs_saveSettingRestrictions() {
602 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
603 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
604
605 if (!current_user_can('manage_options')) {
606 wp_die();
607 }
608
609 if(! $_POST['njt_fs_list_user_restrictions']) wp_die();
610
611 $njt_fs_list_user_restrictions = sanitize_text_field($_POST['njt_fs_list_user_restrictions']);
612 $list_user_restrictions_alow_access = !empty($_POST['list_user_restrictions_alow_access']) ? explode(',', sanitize_text_field($_POST['list_user_restrictions_alow_access'])) : array();
613 $private_folder_access = !empty($_POST['private_folder_access']) ? str_replace("\\\\", "/", trim(sanitize_text_field($_POST['private_folder_access']))) : '';
614 $private_url_folder_access = !empty($_POST['private_url_folder_access']) ? str_replace("\\\\", "/", trim(sanitize_text_field($_POST['private_url_folder_access']))) : '';
615 $hide_paths = !empty($_POST['hide_paths']) ? explode('|', preg_replace('/\s+/', '', sanitize_text_field($_POST['hide_paths']))) : array();
616 $lock_files = !empty($_POST['lock_files']) ? explode('|', preg_replace('/\s+/', '', sanitize_text_field($_POST['lock_files']))) : array();
617
618 $can_upload_mime = !empty($_POST['can_upload_mime']) ? explode(',', preg_replace('/\s+/', '', sanitize_text_field($_POST['can_upload_mime']))) : array();
619
620 $can_upload_mime = array_filter($can_upload_mime, function($item) {
621 $helper = new \FileManagerHelper();
622 $listFileCanNotUpload = $helper->listFileCanNotUpload();
623 return !in_array($item, $listFileCanNotUpload);
624 });
625
626 //save options
627 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['list_user_restrictions_alow_access'] = $list_user_restrictions_alow_access;
628 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['private_folder_access'] = $private_folder_access;
629 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['private_url_folder_access'] = $private_url_folder_access;
630 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['hide_paths'] = $hide_paths;
631 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['lock_files'] = $lock_files;
632 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['can_upload_mime'] = $can_upload_mime;
633 //update options
634 update_option('njt_fs_settings', $this->options);
635 wp_send_json_success(get_option('njt_fs_settings'));
636 wp_die();
637 }
638
639 public function canAccessSensitiveFiles() {
640 // Filter hook for developers
641 if (apply_filters('njt_fs_allow_sensitive_access', false)) {
642 return true;
643 }
644
645 return false;
646 }
647
648 public function canEditSensitiveFiles() {
649 // Filter hook for developers
650 if (apply_filters('njt_fs_allow_sensitive_edit', false)) {
651 return true;
652 }
653
654 return false;
655 }
656
657 }