PluginProbe ʕ •ᴥ•ʔ
File Manager Pro – Filester / 2.0.1
File Manager Pro – Filester v2.0.1
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 8 months ago FileManager.php 8 months ago FileManagerHelper.php 8 months ago index.php 8 months ago
FileManager.php
658 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 'tmpPath' => NJT_FS_BN_PLUGIN_PATH . 'includes/File_manager/lib/files/.tmp/',
288 'trashHash' => '', // default is empty, when not enable trash
289 'uploadMaxSize' => $uploadMaxSize .'M',
290 'winHashFix' => DIRECTORY_SEPARATOR !== '/',
291 'uploadOrder' => array('deny', 'allow'),
292 'uploadDeny' => array('htaccess'),
293 //'acceptedName' => 'validName',
294 'attributes' => array() // default is empty
295 ),
296 ),
297 );
298
299
300
301 //Enable Trash
302 if(isset($this->options['njt_fs_file_manager_settings']['enable_trash']) && ($this->options['njt_fs_file_manager_settings']['enable_trash'] == '1')) {
303 $trash = array(
304 'id' => '1',
305 'driver' => 'Trash',
306 'path' => NJT_FS_BN_PLUGIN_PATH.'includes/File_manager/lib/files/.trash/',
307 'tmbURL' => site_url() . '/includes/File_manager/lib/files/.trash/.tmb',
308 'winHashFix' => DIRECTORY_SEPARATOR !== '/',
309 'uploadDeny' => array('htaccess'),
310 'uploadAllow' => array('all'),
311 'uploadOrder' => array('deny', 'allow'),
312 // 'acceptedName' => 'validName',
313 'attributes' => array(
314 array(
315 'pattern' => '/.tmb/',
316 'read' => false,
317 'write' => false,
318 'hidden' => true,
319 'locked' => false
320 ),
321 array(
322 'pattern' => '/.gitkeep/',
323 'read' => false,
324 'write' => false,
325 'hidden' => true,
326 'locked' => false
327 )
328 )
329 );
330 $opts['roots'][0]['trashHash'] = 't1_Lw';
331 $opts['roots'][1] = $trash;
332 }
333
334 //Start --setting User Role Restrictions
335 $user = wp_get_current_user();
336 $userRoles = $user && $user->roles && $user->roles[0] ? $user->roles[0] : '';
337
338 //Disable Operations
339 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['list_user_restrictions_alow_access'])){
340 $opts['roots'][0]['disabled'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['list_user_restrictions_alow_access'];
341 }
342 //Creat root path for user
343 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'])){
344 $opts['roots'][0]['path'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'] .'/';
345 }
346
347 //Creat url root path for user
348 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'])){
349 $opts['roots'][0]['URL'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'] .'/';
350 }
351
352 //Folder or File Paths That You want to Hide
353 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['hide_paths'])){
354 foreach ($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['hide_paths'] as $key => $value){
355 $arrItemHidePath = array(
356 'pattern' => '~/'.$value.'~',
357 'read' => false,
358 'write' => false,
359 'hidden' => true,
360 'locked' => false
361 );
362 array_push($opts['roots'][0]['attributes'], $arrItemHidePath);
363 };
364 }
365
366 //File extensions which you want to Lock
367 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['lock_files'])){
368 foreach ($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['lock_files'] as $key => $value){
369 $arrItemLockFile = array(
370 'pattern' => '/'.$value.'/',
371 'read' => false,
372 'write' => false,
373 'hidden' => false,
374 'locked' => true
375 );
376 array_push($opts['roots'][0]['attributes'], $arrItemLockFile);
377 };
378 }
379
380 //Enter file extensions which can be uploaded
381 $flag = false;
382
383
384 if (is_multisite()) {
385 if( !current_user_can('create_sites') && empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
386 $opts['roots'][0]['uploadDeny'] = array('all');
387 $opts['roots'][0]['uploadAllow'] = array('');
388 } else if ( !current_user_can('create_sites') && !empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
389 $opts['roots'][0]['uploadDeny'] = array('all');
390 $opts['roots'][0]['uploadAllow'] = array();
391 $arrCanUploadMime = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'];
392 $mimeTypes = new \FileManagerHelper();
393 $arrMimeTypes = $mimeTypes->getArrMimeTypes();
394 foreach ($arrMimeTypes as $key => $value){
395 if(in_array($key,$arrCanUploadMime)) {
396 $explodeValue = explode(',',$value);
397 foreach($explodeValue as $item) {
398 array_push($opts['roots'][0]['uploadAllow'], $item );
399 }
400 }
401
402 };
403 foreach ($arrCanUploadMime as $value){
404 if(strpos($value,"x-conference") !== false
405 || strpos($value,"video") !== false
406 || strpos($value,"text") !== false
407 || strpos($value,"model") !== false
408 || strpos($value,"message") !== false
409 || strpos($value,"image") !== false
410 || strpos($value,"font") !== false
411 || strpos($value,"chemical") !== false
412 || strpos($value,"audio") !== false
413 || strpos($value,"application") !== false
414 ) {
415 array_push($opts['roots'][0]['uploadAllow'], $value );
416 }
417 }
418
419 } else {
420 $opts['roots'][0]['uploadDeny'] = array();
421 $opts['roots'][0]['uploadAllow'] = array('all');
422 }
423 }
424
425 if (!is_multisite()) {
426 if($this->userRole !== 'administrator' && empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
427 $opts['roots'][0]['uploadDeny'] = array('all');
428 $opts['roots'][0]['uploadAllow'] = array('');
429 } else if ( $this->userRole !== 'administrator' && !empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
430 $opts['roots'][0]['uploadDeny'] = array('all');
431 $opts['roots'][0]['uploadAllow'] = array();
432 $arrCanUploadMime = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'];
433 $mimeTypes = new \FileManagerHelper();
434 $arrMimeTypes = $mimeTypes->getArrMimeTypes();
435 foreach ($arrMimeTypes as $key => $value){
436 if(in_array($key,$arrCanUploadMime)) {
437 $explodeValue = explode(',',$value);
438 foreach($explodeValue as $item) {
439 $listFileCanNotUpload = $mimeTypes->listFileCanNotUpload();
440 if(!in_array($item, $listFileCanNotUpload)) {
441 array_push($opts['roots'][0]['uploadAllow'], $item );
442 }
443 }
444 }
445
446 };
447 foreach ($arrCanUploadMime as $value){
448 if(strpos($value,"x-conference") !== false
449 || strpos($value,"video") !== false
450 || strpos($value,"text") !== false
451 || strpos($value,"model") !== false
452 || strpos($value,"message") !== false
453 || strpos($value,"image") !== false
454 || strpos($value,"font") !== false
455 || strpos($value,"chemical") !== false
456 || strpos($value,"audio") !== false
457 || strpos($value,"application") !== false
458 ) {
459 array_push($opts['roots'][0]['uploadAllow'], $value );
460 }
461 }
462
463 } else {
464 $opts['roots'][0]['uploadDeny'] = array();
465 $opts['roots'][0]['uploadAllow'] = array('all');
466 }
467 }
468
469 // Sensitive files protection
470 if(isset($this->options['njt_fs_file_manager_settings']['enable_sensitive_protection']) && ($this->options['njt_fs_file_manager_settings']['enable_sensitive_protection'] == '1')) {
471 $sensitive_files = apply_filters('njt_fs_sensitive_files', array(
472 '.htaccess',
473 'wp-config.php',
474 '.env',
475 'wp-config-sample.php',
476 'readme.html',
477 'license.txt',
478 'xmlrpc.php'
479 ));
480
481 foreach ($sensitive_files as $file) {
482 $attributes = array(
483 'pattern' => '/' . preg_quote($file, '/') . '/',
484 'read' => $this->canAccessSensitiveFiles(),
485 'write' => $this->canEditSensitiveFiles(),
486 'hidden' => !$this->canAccessSensitiveFiles(),
487 'locked' => !$this->canEditSensitiveFiles()
488 );
489 array_push($opts['roots'][0]['attributes'], $attributes);
490 }
491 }
492
493 // .htaccess
494 if(isset($this->options['njt_fs_file_manager_settings']['enable_htaccess']) && ($this->options['njt_fs_file_manager_settings']['enable_htaccess'] == '1')) {
495 $attributes = array(
496 'pattern' => '/.htaccess/',
497 'read' => true,
498 'write' => false,
499 'hidden' => true,
500 'locked' => true
501 );
502 array_push($opts['roots'][0]['attributes'], $attributes);
503 }
504
505 //End --setting User Role Restrictions
506
507 $connector = new \elFinderConnector(new \elFinder($opts));
508 $connector->run();
509 wp_die();
510 }
511
512 public function selectorThemes()
513 {
514 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
515 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
516
517 $themesValue = sanitize_text_field ($_POST['themesValue']);
518 $selectorThemes = get_option('njt_fs_selector_themes');
519 if (empty($selectorThemes[$this->userRole])) {
520 $selectorThemes[$this->userRole]['themesValue'] = 'Default';
521 update_option('njt_fs_selector_themes', $selectorThemes);
522 }
523
524 if ($selectorThemes[$this->userRole]['themesValue'] != $themesValue) {
525 $selectorThemes[$this->userRole]['themesValue'] = $themesValue;
526 update_option('njt_fs_selector_themes', $selectorThemes);
527 }
528 $selected_themes = get_option('njt_fs_selector_themes');
529 $linkThemes = plugins_url('/lib/themes/' . $selected_themes[$this->userRole]['themesValue'] . '/css/theme.css', __FILE__);
530 wp_send_json_success($linkThemes);
531 wp_die();
532 }
533
534 public function saveOptions()
535 {
536 //if(isset($_POST['njt-settings-form-submit'])) {
537 update_option('njt_fs_settings', $this->options);
538 // if($u) {
539 // $this->f('?page=njt-fs-filemanager-settings&status=1');
540 // } else {
541 // $this->f('?page=njt-fs-filemanager-settings&status=2');
542 // }
543 // }
544 }
545
546 public function f($u) {
547 echo '<script>';
548 echo 'window.location.href="'.$u.'"';
549 echo '</script>';
550 }
551
552 public function getArrRoleRestrictions()
553 {
554 if(!wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
555 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
556 $valueUserRole = filter_var($_POST['valueUserRole']) ? sanitize_text_field ($_POST['valueUserRole']) : '';
557 $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();
558 $dataArrRoleRestrictions = array (
559 'disable_operations' => implode(",", !empty($arrRestrictions[$valueUserRole]['list_user_restrictions_alow_access']) ? $arrRestrictions[$valueUserRole]['list_user_restrictions_alow_access'] : array()),
560 'private_folder_access' => !empty($arrRestrictions[$valueUserRole]['private_folder_access']) ? str_replace("\\\\", "/", trim($arrRestrictions[$valueUserRole]['private_folder_access'])) : '',
561 'private_url_folder_access' => !empty($arrRestrictions[$valueUserRole]['private_url_folder_access']) ? str_replace("\\\\", "/", trim($arrRestrictions[$valueUserRole]['private_url_folder_access'])) : '',
562 'hide_paths' => implode(',', !empty($arrRestrictions[$valueUserRole]['hide_paths']) ? $arrRestrictions[$valueUserRole]['hide_paths'] : array()),
563 'lock_files' => implode(',', !empty($arrRestrictions[$valueUserRole]['lock_files']) ? $arrRestrictions[$valueUserRole]['lock_files'] : array()),
564 'can_upload_mime' => implode(',', !empty($arrRestrictions[$valueUserRole]['can_upload_mime']) ? $arrRestrictions[$valueUserRole]['can_upload_mime'] : array())
565 );
566 wp_send_json_success($dataArrRoleRestrictions);
567 wp_die();
568 }
569
570 public function njt_fs_saveSetting()
571 {
572 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
573 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
574
575 if (!current_user_can('manage_options')) {
576 wp_die();
577 }
578
579 $root_folder_path = !empty($_POST['root_folder_path']) ? str_replace("\\\\", "/", trim(sanitize_text_field($_POST['root_folder_path']))) : '';
580 $root_folder_url = !empty($_POST['root_folder_url']) ? str_replace("\\\\", "/", trim(sanitize_url($_POST['root_folder_url']))) : site_url();
581 $list_user_alow_access = !empty($_POST['list_user_alow_access']) ? explode(',', sanitize_text_field($_POST['list_user_alow_access'])) : array();
582 $upload_max_size = !empty($_POST['upload_max_size']) ? sanitize_text_field(trim($_POST['upload_max_size'])) : 0;
583 $fm_locale = !empty($_POST['fm_locale']) ? sanitize_text_field($_POST['fm_locale']) : 'en';
584 $enable_htaccess = isset($_POST['enable_htaccess']) && $_POST['enable_htaccess'] == 'true' ? 1 : 0;
585 $enable_trash = isset($_POST['enable_trash']) && $_POST['enable_trash'] == 'true' ? 1 : 0;
586 $enable_sensitive_protection = isset($_POST['enable_sensitive_protection']) && $_POST['enable_sensitive_protection'] == 'true' ? 1 : 0;
587 //save options
588 $this->options['njt_fs_file_manager_settings']['root_folder_path'] = $root_folder_path;
589 $this->options['njt_fs_file_manager_settings']['root_folder_url'] = $root_folder_url;
590 $this->options['njt_fs_file_manager_settings']['list_user_alow_access'] = $list_user_alow_access;
591 $this->options['njt_fs_file_manager_settings']['upload_max_size'] = $upload_max_size;
592 $this->options['njt_fs_file_manager_settings']['fm_locale'] = $fm_locale;
593 $this->options['njt_fs_file_manager_settings']['enable_htaccess'] = $enable_htaccess;
594 $this->options['njt_fs_file_manager_settings']['enable_trash'] = $enable_trash;
595 $this->options['njt_fs_file_manager_settings']['enable_sensitive_protection'] = $enable_sensitive_protection;
596 //update options
597 update_option('njt_fs_settings', $this->options);
598 wp_send_json_success(get_option('njt_fs_settings'));
599 wp_die();
600 }
601
602 public function njt_fs_saveSettingRestrictions() {
603 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
604 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
605
606 if (!current_user_can('manage_options')) {
607 wp_die();
608 }
609
610 if(! $_POST['njt_fs_list_user_restrictions']) wp_die();
611
612 $njt_fs_list_user_restrictions = sanitize_text_field($_POST['njt_fs_list_user_restrictions']);
613 $list_user_restrictions_alow_access = !empty($_POST['list_user_restrictions_alow_access']) ? explode(',', sanitize_text_field($_POST['list_user_restrictions_alow_access'])) : array();
614 $private_folder_access = !empty($_POST['private_folder_access']) ? str_replace("\\\\", "/", trim(sanitize_text_field($_POST['private_folder_access']))) : '';
615 $private_url_folder_access = !empty($_POST['private_url_folder_access']) ? str_replace("\\\\", "/", trim(sanitize_text_field($_POST['private_url_folder_access']))) : '';
616 $hide_paths = !empty($_POST['hide_paths']) ? explode('|', preg_replace('/\s+/', '', sanitize_text_field($_POST['hide_paths']))) : array();
617 $lock_files = !empty($_POST['lock_files']) ? explode('|', preg_replace('/\s+/', '', sanitize_text_field($_POST['lock_files']))) : array();
618
619 $can_upload_mime = !empty($_POST['can_upload_mime']) ? explode(',', preg_replace('/\s+/', '', sanitize_text_field($_POST['can_upload_mime']))) : array();
620
621 $can_upload_mime = array_filter($can_upload_mime, function($item) {
622 $helper = new \FileManagerHelper();
623 $listFileCanNotUpload = $helper->listFileCanNotUpload();
624 return !in_array($item, $listFileCanNotUpload);
625 });
626
627 //save options
628 $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;
629 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['private_folder_access'] = $private_folder_access;
630 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['private_url_folder_access'] = $private_url_folder_access;
631 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['hide_paths'] = $hide_paths;
632 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['lock_files'] = $lock_files;
633 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['can_upload_mime'] = $can_upload_mime;
634 //update options
635 update_option('njt_fs_settings', $this->options);
636 wp_send_json_success(get_option('njt_fs_settings'));
637 wp_die();
638 }
639
640 public function canAccessSensitiveFiles() {
641 // Filter hook for developers
642 if (apply_filters('njt_fs_allow_sensitive_access', false)) {
643 return true;
644 }
645
646 return false;
647 }
648
649 public function canEditSensitiveFiles() {
650 // Filter hook for developers
651 if (apply_filters('njt_fs_allow_sensitive_edit', false)) {
652 return true;
653 }
654
655 return false;
656 }
657
658 }