PluginProbe ʕ •ᴥ•ʔ
File Manager Pro – Filester / 1.8
File Manager Pro – Filester v1.8
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 2 years ago FileManager.php 2 years ago FileManagerHelper.php 2 years ago index.php 2 years ago
FileManager.php
524 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 ),
57 );
58 }
59 register_shutdown_function(array($this, 'saveOptions'));
60
61 add_action('init', array($this, 'isAlowUserAccess'));
62 if ($this->isAlowUserAccess()) {
63 add_action('admin_enqueue_scripts', array($this, 'enqueueAdminScripts'));
64 add_action('admin_menu', array($this, 'FileManager'));
65 add_action('wp_ajax_fs_connector', array($this, 'fsConnector'));
66 add_action('wp_ajax_selector_themes', array($this, 'selectorThemes'));
67 add_action('wp_ajax_get_role_restrictions', array($this, 'getArrRoleRestrictions'));
68 add_action('wp_ajax_njt_fs_save_setting', array($this, 'njt_fs_saveSetting'));
69 add_action('wp_ajax_njt_fs_save_setting_restrictions', array($this, 'njt_fs_saveSettingRestrictions'));
70
71 $optionReview = get_option('njt_fs_review');
72 if (time() >= (int)$optionReview && $optionReview !== '0'){
73 add_action('admin_notices', array($this, 'njt_fs_give_review'));
74 }
75
76 add_action('wp_ajax_njt_fs_save_review', array($this, 'njt_fs_save_review'));
77 }
78 }
79
80 public function njt_fs_give_review()
81 {
82 if (function_exists('get_current_screen')) {
83 if (get_current_screen()->id == 'file-manager_page_filester-settings' || get_current_screen()->id == 'toplevel_page_njt-fs-filemanager' || get_current_screen()->id == 'plugins') {
84 $this->enqueue_scripts();
85 ?>
86 <div class="notice notice-success is-dismissible" id="njt-fs-review">
87 <h3><?php _e('Give Filester a review', 'filester')?></h3>
88 <p>
89 <?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')?>
90 </p>
91 <p>
92 <?php _e('We will be forever grateful. Thank you in advance ;)', 'filester')?>
93 </p>
94 <p>
95 <a href="javascript:;" data="rateNow" class="button button-primary" style="margin-right: 5px"><?php _e('Rate now', 'filester')?></a>
96 <a href="javascript:;" data="later" class="button" style="margin-right: 5px"><?php _e('Later', 'filester')?></a>
97 <a href="javascript:;" data="alreadyDid" class="button"><?php _e('Already did', 'filester')?></a>
98 </p>
99 </div>
100 <?php
101 }
102 }
103 }
104
105 public function njt_fs_save_review()
106 {
107 if ( isset( $_POST ) ) {
108 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : null;
109 $field = isset( $_POST['field'] ) ? sanitize_text_field( $_POST['field'] ) : null;
110
111 if ( ! wp_verify_nonce( $nonce, 'njt-fs-review' ) ) {
112 wp_send_json_error( array( 'status' => 'Wrong nonce validate!' ) );
113 exit();
114 }
115
116 if ($field == 'later'){
117 update_option('njt_fs_review', time() + 3*60*60*24); //After 3 days show
118 } else if ($field == 'alreadyDid'){
119 update_option('njt_fs_review', 0);
120 }
121 wp_send_json_success();
122 }
123 wp_send_json_error( array( 'message' => 'Update fail!' ) );
124 }
125
126 public function enqueue_scripts(){
127 wp_enqueue_script('njt-fs-review', NJT_FS_BN_PLUGIN_URL . 'assets/js/review.js', array('jquery'), NJT_FS_BN_VERSION, false);
128 wp_localize_script('njt-fs-review', 'wpDataFs', array(
129 'admin_ajax' => admin_url('admin-ajax.php'),
130 'nonce' => wp_create_nonce("njt-fs-review"),
131 ));
132 }
133
134 public function isAlowUserAccess()
135 {
136 if($this->userRole) {
137 $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();
138 if( in_array($this->userRole,$allowed_roles) || $this->userRole == 'administrator') {
139 $this->fmCapability = $this->userRole;
140 return true;
141 }
142 }
143 if (is_super_admin()) {
144 $this->fmCapability = 'administrator';
145 return true;
146 }
147 $this->fmCapability = 'read';
148 return false;
149 }
150
151 public function FileManager()
152 {
153 if( class_exists( 'NestedPages' ) ) {
154 $this->fmCapability = 'read';
155 }
156 $icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTEwLDRINEMyLjg5LDQgMiw0Ljg5IDIsNlYxOEEyLDIgMCAwLDAgNCwyMEgyMEEyLDIgMCAwLDAgMjIsMThWOEMyMiw2Ljg5IDIxLjEsNiAyMCw2SDEyTDEwLDRaIiBmaWxsPSIjYTdhYWFkIi8+PC9zdmc+';
157 $display_suffix = add_menu_page(
158 __('Filester', 'textdomain'),
159 'File Manager',
160 $this->fmCapability,
161 'njt-fs-filemanager',
162 array($this, 'fsViewFileCallback'),
163 $icon,
164 9
165 );
166
167 $settings_suffix = add_submenu_page (
168 'njt-fs-filemanager',
169 'Settings',
170 'Settings',
171 'manage_options',
172 'filester-settings',
173 array($this, 'fsSettingsPage') );
174
175 $this->hook_suffix = array($display_suffix, $settings_suffix);
176 }
177
178 public function fsViewFileCallback()
179 {
180 $viewPath = NJT_FS_BN_PLUGIN_PATH . 'views/pages/html-filemanager.php';
181 include_once $viewPath;
182 }
183
184 public function fsSettingsPage()
185 {
186 $viewPath = NJT_FS_BN_PLUGIN_PATH . 'views/pages/html-filemanager-settings.php';
187 include_once $viewPath;
188 }
189
190 public function enqueueAdminScripts($suffix)
191 {
192 if (in_array($suffix, $this->hook_suffix)) {
193 $selectorThemes = get_option('njt_fs_selector_themes');
194 if (empty($selectorThemes[$this->userRole])) {
195 $selectorThemes[$this->userRole]['themesValue'] = 'Default';
196 update_option('njt_fs_selector_themes', $selectorThemes);
197 }
198
199 $selectedTheme = $selectorThemes[$this->userRole]['themesValue'];
200
201 //elfinder css
202 wp_enqueue_style('elfinder.jq.css', plugins_url('/lib/jquery/jquery-ui.min.css', __FILE__));
203 wp_enqueue_style('elfinder.full.css', plugins_url('/lib/css/elfinder.min.css', __FILE__));
204 wp_enqueue_style('themes', plugins_url('/lib/css/theme.css', __FILE__));
205 wp_enqueue_style('themes-selector', plugins_url('/lib/themes/' . $selectedTheme . '/css/theme.css', __FILE__));
206
207 //elfinder core
208 if(version_compare(get_bloginfo('version'),'5.6', '>=') ){
209 wp_enqueue_script('jquery_min', plugins_url('/lib/jquery/jquery-ui.min.js', __FILE__));
210 } else {
211 wp_enqueue_script('jquery_min', plugins_url('/lib/jquery/jquery-ui-old.min.js', __FILE__));
212 }
213
214 //elfinder js, toastr JS, css custom
215 wp_register_style('njt_fs_toastr_css',NJT_FS_BN_PLUGIN_URL . 'assets/js/toastr/toastr.min.css');
216 wp_enqueue_style('njt_fs_toastr_css');
217 wp_enqueue_script('njt_fs_toastr_js', NJT_FS_BN_PLUGIN_URL . 'assets/js/toastr/toastr.min.js', array('jquery'), NJT_FS_BN_VERSION);
218
219 wp_register_style('file_manager_admin_css',NJT_FS_BN_PLUGIN_URL . 'assets/css/file_manager_admin.css');
220 wp_enqueue_style('file_manager_admin_css');
221 wp_enqueue_script('file_manager_admin', NJT_FS_BN_PLUGIN_URL . 'assets/js/file_manager_admin.js', array('jquery'), NJT_FS_BN_VERSION, true);
222
223 //js load elFinder
224 wp_enqueue_script('njt_fs_elFinder', plugins_url('/lib/js/elfinder.min.js', __FILE__));
225
226 wp_enqueue_script('njt_fs_elfinder_editor', plugins_url('/lib/js/extras/editors.default.js', __FILE__));
227 //js load fm_locale
228 if(isset($this->options['njt_fs_file_manager_settings']['fm_locale'])) {
229 $locale = $this->options['njt_fs_file_manager_settings']['fm_locale'];
230 if($locale != 'en') {
231 wp_enqueue_script( 'njt_fs_fma_lang', plugins_url('lib/js/i18n/elfinder.'.$locale.'.js', __FILE__));
232 }
233 }
234
235 wp_localize_script('njt_fs_elFinder', 'wpData', array(
236 'admin_ajax' => admin_url('admin-ajax.php'),
237 'nonce' => wp_create_nonce("njt-fs-file-manager-admin"),
238 'PLUGIN_URL' => NJT_FS_BN_PLUGIN_URL .'includes/File_manager/lib/',
239 'PLUGIN_PATH' => NJT_FS_BN_PLUGIN_PATH.'includes/File_manager/lib/',
240 'PLUGIN_DIR'=> NJT_FS_BN_PLUGIN_DIR,
241 'ABSPATH'=> str_replace("\\", "/", ABSPATH)
242
243 ));
244 }
245 }
246
247 //File manager connector function
248
249 public function fsConnector()
250 {
251 check_ajax_referer( 'file-manager-security-token', 'nonce' );
252 $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;
253
254 $opts = array(
255 'bind' => array(
256 'put.pre' => array(new \FileManagerHelper, 'madeStripcslashesFile'), // Check endcode when save file.
257 ),
258 'debug' => false,
259 'roots' => array(
260 array(
261 'driver' => 'LocalFileSystem',
262 '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,
263 '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(),
264 'trashHash' => '', // default is empty, when not enable trash
265 'uploadMaxSize' => $uploadMaxSize .'M',
266 'winHashFix' => DIRECTORY_SEPARATOR !== '/',
267 'uploadDeny' => array(),
268 'uploadAllow' => array('all'),
269 'uploadOrder' => array('deny', 'allow'),
270 'disabled' => array(''),
271 'acceptedName' => 'validName',
272 'attributes' => array() // default is empty
273 ),
274 ),
275 );
276 // .htaccess
277 if(isset($this->options['njt_fs_file_manager_settings']['enable_htaccess']) && ($this->options['njt_fs_file_manager_settings']['enable_htaccess'] == '1')) {
278 $attributes = array(
279 'pattern' => '/.htaccess/',
280 'read' => false,
281 'write' => false,
282 'hidden' => true,
283 'locked' => false
284 );
285 array_push($opts['roots'][0]['attributes'], $attributes);
286 }
287
288 //Enable Trash
289 if(isset($this->options['njt_fs_file_manager_settings']['enable_trash']) && ($this->options['njt_fs_file_manager_settings']['enable_trash'] == '1')) {
290 $trash = array(
291 'id' => '1',
292 'driver' => 'Trash',
293 'path' => NJT_FS_BN_PLUGIN_PATH.'includes/File_manager/lib/files/.trash/',
294 'tmbURL' => site_url() . '/includes/File_manager/lib/files/.trash/.tmb',
295 'winHashFix' => DIRECTORY_SEPARATOR !== '/',
296 'uploadDeny' => array(),
297 'uploadAllow' => array('all'),
298 'uploadOrder' => array('deny', 'allow'),
299 'acceptedName' => 'validName',
300 'attributes' => array(
301 array(
302 'pattern' => '/.tmb/',
303 'read' => false,
304 'write' => false,
305 'hidden' => true,
306 'locked' => false
307 ),
308 array(
309 'pattern' => '/.gitkeep/',
310 'read' => false,
311 'write' => false,
312 'hidden' => true,
313 'locked' => false
314 )
315 )
316 );
317 $opts['roots'][0]['trashHash'] = 't1_Lw';
318 $opts['roots'][1] = $trash;
319 }
320
321 //Start --setting User Role Restrictions
322 $user = wp_get_current_user();
323 $userRoles = $user && $user->roles && $user->roles[0] ? $user->roles[0] : '';
324
325 //Disable Operations
326 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['list_user_restrictions_alow_access'])){
327 $opts['roots'][0]['disabled'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['list_user_restrictions_alow_access'];
328 }
329 //Creat root path for user
330 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'])){
331 $opts['roots'][0]['path'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'] .'/';
332 }
333
334 //Creat url root path for user
335 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'])){
336 $opts['roots'][0]['URL'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'] .'/';
337 }
338
339 //Folder or File Paths That You want to Hide
340 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['hide_paths'])){
341 foreach ($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['hide_paths'] as $key => $value){
342 $arrItemHidePath = array(
343 'pattern' => '~/'.$value.'~',
344 'read' => false,
345 'write' => false,
346 'hidden' => true,
347 'locked' => false
348 );
349 array_push($opts['roots'][0]['attributes'], $arrItemHidePath);
350 };
351 }
352
353 //File extensions which you want to Lock
354 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['lock_files'])){
355 foreach ($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['lock_files'] as $key => $value){
356 $arrItemLockFile = array(
357 'pattern' => '/'.$value.'/',
358 'read' => false,
359 'write' => false,
360 'hidden' => false,
361 'locked' => true
362 );
363 array_push($opts['roots'][0]['attributes'], $arrItemLockFile);
364 };
365 }
366
367 //Enter file extensions which can be uploaded
368 if($this->userRole !== 'administrator' && empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
369 $opts['roots'][0]['uploadDeny'] = array('all');
370 $opts['roots'][0]['uploadAllow'] = array('');
371 } else if ( $this->userRole !== 'administrator' && !empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
372 $opts['roots'][0]['uploadDeny'] = array('all');
373 $opts['roots'][0]['uploadAllow'] = array();
374 $arrCanUploadMime = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'];
375 $mimeTypes = new \FileManagerHelper();
376 $arrMimeTypes = $mimeTypes->getArrMimeTypes();
377 foreach ($arrMimeTypes as $key => $value){
378 if(in_array($key,$arrCanUploadMime)) {
379 $explodeValue = explode(',',$value);
380 foreach($explodeValue as $item) {
381 array_push($opts['roots'][0]['uploadAllow'], $item );
382 }
383 }
384
385 };
386 foreach ($arrCanUploadMime as $value){
387 if(strpos($value,"x-conference") !== false
388 || strpos($value,"video") !== false
389 || strpos($value,"text") !== false
390 || strpos($value,"model") !== false
391 || strpos($value,"message") !== false
392 || strpos($value,"image") !== false
393 || strpos($value,"font") !== false
394 || strpos($value,"chemical") !== false
395 || strpos($value,"audio") !== false
396 || strpos($value,"application") !== false
397 ) {
398 array_push($opts['roots'][0]['uploadAllow'], $value );
399 }
400 }
401
402 } else {
403 $opts['roots'][0]['uploadDeny'] = array();
404 $opts['roots'][0]['uploadAllow'] = array('all');
405 }
406 //End --setting User Role Restrictions
407
408 $connector = new \elFinderConnector(new \elFinder($opts));
409 $connector->run();
410 wp_die();
411 }
412
413 public function selectorThemes()
414 {
415 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
416 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
417
418 $themesValue = sanitize_text_field ($_POST['themesValue']);
419 $selectorThemes = get_option('njt_fs_selector_themes');
420 if (empty($selectorThemes[$this->userRole])) {
421 $selectorThemes[$this->userRole]['themesValue'] = 'Default';
422 update_option('njt_fs_selector_themes', $selectorThemes);
423 }
424
425 if ($selectorThemes[$this->userRole]['themesValue'] != $themesValue) {
426 $selectorThemes[$this->userRole]['themesValue'] = $themesValue;
427 update_option('njt_fs_selector_themes', $selectorThemes);
428 }
429 $selected_themes = get_option('njt_fs_selector_themes');
430 $linkThemes = plugins_url('/lib/themes/' . $selected_themes[$this->userRole]['themesValue'] . '/css/theme.css', __FILE__);
431 wp_send_json_success($linkThemes);
432 wp_die();
433 }
434
435 public function saveOptions()
436 {
437 //if(isset($_POST['njt-settings-form-submit'])) {
438 update_option('njt_fs_settings', $this->options);
439 // if($u) {
440 // $this->f('?page=njt-fs-filemanager-settings&status=1');
441 // } else {
442 // $this->f('?page=njt-fs-filemanager-settings&status=2');
443 // }
444 // }
445 }
446
447 public function f($u) {
448 echo '<script>';
449 echo 'window.location.href="'.$u.'"';
450 echo '</script>';
451 }
452
453 public function getArrRoleRestrictions()
454 {
455 if(!wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
456 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
457 $valueUserRole = filter_var($_POST['valueUserRole']) ? sanitize_text_field ($_POST['valueUserRole']) : '';
458 $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();
459 $dataArrRoleRestrictions = array (
460 'disable_operations' => implode(",", !empty($arrRestrictions[$valueUserRole]['list_user_restrictions_alow_access']) ? $arrRestrictions[$valueUserRole]['list_user_restrictions_alow_access'] : array()),
461 'private_folder_access' => !empty($arrRestrictions[$valueUserRole]['private_folder_access']) ? str_replace("\\\\", "/", trim($arrRestrictions[$valueUserRole]['private_folder_access'])) : '',
462 'private_url_folder_access' => !empty($arrRestrictions[$valueUserRole]['private_url_folder_access']) ? str_replace("\\\\", "/", trim($arrRestrictions[$valueUserRole]['private_url_folder_access'])) : '',
463 'hide_paths' => implode(',', !empty($arrRestrictions[$valueUserRole]['hide_paths']) ? $arrRestrictions[$valueUserRole]['hide_paths'] : array()),
464 'lock_files' => implode(',', !empty($arrRestrictions[$valueUserRole]['lock_files']) ? $arrRestrictions[$valueUserRole]['lock_files'] : array()),
465 'can_upload_mime' => implode(',', !empty($arrRestrictions[$valueUserRole]['can_upload_mime']) ? $arrRestrictions[$valueUserRole]['can_upload_mime'] : array())
466 );
467 wp_send_json_success($dataArrRoleRestrictions);
468 wp_die();
469 }
470
471 public function njt_fs_saveSetting()
472 {
473 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
474 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
475
476 $root_folder_path = filter_var($_POST['root_folder_path'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['root_folder_path'])) : '';
477 $root_folder_url = filter_var($_POST['root_folder_url'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['root_folder_url'])) : site_url();
478 $list_user_alow_access = filter_var($_POST['list_user_alow_access'], FILTER_SANITIZE_STRING) ? explode(',',$_POST['list_user_alow_access']) : array();
479 $upload_max_size = filter_var($_POST['upload_max_size'], FILTER_SANITIZE_STRING) ? sanitize_text_field(trim($_POST['upload_max_size'])) : 0;
480 $fm_locale = filter_var($_POST['fm_locale'], FILTER_SANITIZE_STRING) ? sanitize_text_field($_POST['fm_locale']) : 'en';
481 $enable_htaccess = isset($_POST['enable_htaccess']) && $_POST['enable_htaccess'] == 'true' ? 1 : 0;
482 $enable_trash = isset($_POST['enable_trash']) && $_POST['enable_trash'] == 'true' ? 1 : 0;
483 //save options
484 $this->options['njt_fs_file_manager_settings']['root_folder_path'] = $root_folder_path;
485 $this->options['njt_fs_file_manager_settings']['root_folder_url'] = $root_folder_url;
486 $this->options['njt_fs_file_manager_settings']['list_user_alow_access'] = $list_user_alow_access;
487 $this->options['njt_fs_file_manager_settings']['upload_max_size'] = $upload_max_size;
488 $this->options['njt_fs_file_manager_settings']['fm_locale'] = $fm_locale;
489 $this->options['njt_fs_file_manager_settings']['enable_htaccess'] = $enable_htaccess;
490 $this->options['njt_fs_file_manager_settings']['enable_trash'] = $enable_trash;
491 //update options
492 update_option('njt_fs_settings', $this->options);
493 wp_send_json_success(get_option('njt_fs_settings'));
494 wp_die();
495 }
496
497 public function njt_fs_saveSettingRestrictions() {
498 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
499 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
500
501 if(! $_POST['njt_fs_list_user_restrictions']) wp_die();
502
503 $njt_fs_list_user_restrictions = $_POST['njt_fs_list_user_restrictions'];
504 $list_user_restrictions_alow_access = filter_var($_POST['list_user_restrictions_alow_access'], FILTER_SANITIZE_STRING) ? explode(',', $_POST['list_user_restrictions_alow_access']) : array();
505 $private_folder_access = filter_var($_POST['private_folder_access'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['private_folder_access'])) : '';
506 $private_url_folder_access = filter_var($_POST['private_url_folder_access'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['private_url_folder_access'])) : '';
507 $hide_paths = filter_var($_POST['hide_paths'], FILTER_SANITIZE_STRING) ? explode('|', preg_replace('/\s+/', '', $_POST['hide_paths'])) : array();
508 $lock_files = filter_var($_POST['lock_files'], FILTER_SANITIZE_STRING) ? explode('|', preg_replace('/\s+/', '', $_POST['lock_files'])) : array();
509 $can_upload_mime = filter_var($_POST['can_upload_mime'], FILTER_SANITIZE_STRING) ? explode(',', preg_replace('/\s+/', '', $_POST['can_upload_mime'])) : array();
510
511 //save options
512 $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;
513 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['private_folder_access'] = $private_folder_access;
514 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['private_url_folder_access'] = $private_url_folder_access;
515 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['hide_paths'] = $hide_paths;
516 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['lock_files'] = $lock_files;
517 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['can_upload_mime'] = $can_upload_mime;
518 //update options
519 update_option('njt_fs_settings', $this->options);
520 wp_send_json_success(get_option('njt_fs_settings'));
521 wp_die();
522 }
523
524 }