PluginProbe ʕ •ᴥ•ʔ
File Manager Pro – Filester / 1.8.2
File Manager Pro – Filester v1.8.2
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 1 year ago FileManager.php 1 year ago FileManagerHelper.php 1 year ago index.php 1 year ago
FileManager.php
593 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)) {
139 if (is_multisite() && $this->userRole == 'administrator') {
140 $this->fmCapability = 'activate_plugins';
141 }
142 $this->fmCapability = $this->userRole;
143 return true;
144 }
145 }
146 if (is_multisite() && is_super_admin()) {
147 $this->fmCapability = 'create_sites';
148 return true;
149 }
150
151 if (!is_multisite() && is_super_admin()) {
152 $this->fmCapability = 'administrator';
153 return true;
154 }
155 $this->fmCapability = 'read';
156 return false;
157 }
158
159 public function FileManager()
160 {
161 if( class_exists( 'NestedPages' ) ) {
162 $this->fmCapability = 'read';
163 }
164 $icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTEwLDRINEMyLjg5LDQgMiw0Ljg5IDIsNlYxOEEyLDIgMCAwLDAgNCwyMEgyMEEyLDIgMCAwLDAgMjIsMThWOEMyMiw2Ljg5IDIxLjEsNiAyMCw2SDEyTDEwLDRaIiBmaWxsPSIjYTdhYWFkIi8+PC9zdmc+';
165 $display_suffix = add_menu_page(
166 __('Filester', 'textdomain'),
167 'File Manager',
168 $this->fmCapability,
169 'njt-fs-filemanager',
170 array($this, 'fsViewFileCallback'),
171 $icon,
172 9
173 );
174 if (is_multisite()) {
175 $settings_suffix = add_submenu_page (
176 'njt-fs-filemanager',
177 'Settings',
178 'Settings',
179 'create_sites',
180 'filester-settings',
181 array($this, 'fsSettingsPage') );
182 }
183
184 if (!is_multisite()) {
185 $settings_suffix = add_submenu_page (
186 'njt-fs-filemanager',
187 'Settings',
188 'Settings',
189 'manage_options',
190 'filester-settings',
191 array($this, 'fsSettingsPage') );
192 }
193
194 $this->hook_suffix = array($display_suffix, $settings_suffix);
195 }
196
197 public function fsViewFileCallback()
198 {
199 $viewPath = NJT_FS_BN_PLUGIN_PATH . 'views/pages/html-filemanager.php';
200 include_once $viewPath;
201 }
202
203 public function fsSettingsPage()
204 {
205 $viewPath = NJT_FS_BN_PLUGIN_PATH . 'views/pages/html-filemanager-settings.php';
206 include_once $viewPath;
207 }
208
209 public function enqueueAdminScripts($suffix)
210 {
211 if (in_array($suffix, $this->hook_suffix)) {
212 $selectorThemes = get_option('njt_fs_selector_themes');
213 if (empty($selectorThemes[$this->userRole])) {
214 $selectorThemes[$this->userRole]['themesValue'] = 'Default';
215 update_option('njt_fs_selector_themes', $selectorThemes);
216 }
217
218 $selectedTheme = $selectorThemes[$this->userRole]['themesValue'];
219
220 //elfinder css
221 wp_enqueue_style('elfinder.jq.css', plugins_url('/lib/jquery/jquery-ui.min.css', __FILE__));
222 wp_enqueue_style('elfinder.full.css', plugins_url('/lib/css/elfinder.min.css', __FILE__));
223 wp_enqueue_style('themes', plugins_url('/lib/css/theme.css', __FILE__));
224 wp_enqueue_style('themes-selector', plugins_url('/lib/themes/' . $selectedTheme . '/css/theme.css', __FILE__));
225
226 //elfinder core
227 if(version_compare(get_bloginfo('version'),'5.6', '>=') ){
228 wp_enqueue_script('jquery_min', plugins_url('/lib/jquery/jquery-ui.min.js', __FILE__));
229 } else {
230 wp_enqueue_script('jquery_min', plugins_url('/lib/jquery/jquery-ui-old.min.js', __FILE__));
231 }
232
233 //elfinder js, toastr JS, css custom
234 wp_register_style('njt_fs_toastr_css',NJT_FS_BN_PLUGIN_URL . 'assets/js/toastr/toastr.min.css');
235 wp_enqueue_style('njt_fs_toastr_css');
236 wp_enqueue_script('njt_fs_toastr_js', NJT_FS_BN_PLUGIN_URL . 'assets/js/toastr/toastr.min.js', array('jquery'), NJT_FS_BN_VERSION);
237
238 wp_register_style('file_manager_admin_css',NJT_FS_BN_PLUGIN_URL . 'assets/css/file_manager_admin.css');
239 wp_enqueue_style('file_manager_admin_css');
240 wp_enqueue_script('file_manager_admin', NJT_FS_BN_PLUGIN_URL . 'assets/js/file_manager_admin.js', array('jquery'), NJT_FS_BN_VERSION, true);
241
242 //js load elFinder
243 wp_enqueue_script('njt_fs_elFinder', plugins_url('/lib/js/elfinder.min.js', __FILE__));
244
245 wp_enqueue_script('njt_fs_elfinder_editor', plugins_url('/lib/js/extras/editors.default.js', __FILE__));
246 //js load fm_locale
247 if(isset($this->options['njt_fs_file_manager_settings']['fm_locale'])) {
248 $locale = $this->options['njt_fs_file_manager_settings']['fm_locale'];
249 if($locale != 'en') {
250 wp_enqueue_script( 'njt_fs_fma_lang', plugins_url('lib/js/i18n/elfinder.'.$locale.'.js', __FILE__));
251 }
252 }
253
254 wp_localize_script('njt_fs_elFinder', 'wpData', array(
255 'admin_ajax' => admin_url('admin-ajax.php'),
256 'nonce' => wp_create_nonce("njt-fs-file-manager-admin"),
257 'PLUGIN_URL' => NJT_FS_BN_PLUGIN_URL .'includes/File_manager/lib/',
258 'PLUGIN_PATH' => NJT_FS_BN_PLUGIN_PATH.'includes/File_manager/lib/',
259 'PLUGIN_DIR'=> NJT_FS_BN_PLUGIN_DIR,
260 'ABSPATH'=> str_replace("\\", "/", ABSPATH),
261 'is_multisite' => is_multisite()
262
263 ));
264 }
265 }
266
267 //File manager connector function
268
269 public function fsConnector()
270 {
271 check_ajax_referer( 'file-manager-security-token', 'nonce' );
272 $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;
273
274 $opts = array(
275 'bind' => array(
276 'put.pre' => array(new \FileManagerHelper, 'madeStripcslashesFile'), // Check endcode when save file.
277 ),
278 'debug' => false,
279 'roots' => array(
280 array(
281 'driver' => 'LocalFileSystem',
282 '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,
283 '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(),
284 'trashHash' => '', // default is empty, when not enable trash
285 'uploadMaxSize' => $uploadMaxSize .'M',
286 'winHashFix' => DIRECTORY_SEPARATOR !== '/',
287 'uploadDeny' => array(),
288 'uploadAllow' => array('all'),
289 'uploadOrder' => array('deny', 'allow'),
290 'disabled' => array(''),
291 'acceptedName' => 'validName',
292 'attributes' => array() // default is empty
293 ),
294 ),
295 );
296 // .htaccess
297 if(isset($this->options['njt_fs_file_manager_settings']['enable_htaccess']) && ($this->options['njt_fs_file_manager_settings']['enable_htaccess'] == '1')) {
298 $attributes = array(
299 'pattern' => '/.htaccess/',
300 'read' => false,
301 'write' => false,
302 'hidden' => true,
303 'locked' => false
304 );
305 array_push($opts['roots'][0]['attributes'], $attributes);
306 }
307
308 //Enable Trash
309 if(isset($this->options['njt_fs_file_manager_settings']['enable_trash']) && ($this->options['njt_fs_file_manager_settings']['enable_trash'] == '1')) {
310 $trash = array(
311 'id' => '1',
312 'driver' => 'Trash',
313 'path' => NJT_FS_BN_PLUGIN_PATH.'includes/File_manager/lib/files/.trash/',
314 'tmbURL' => site_url() . '/includes/File_manager/lib/files/.trash/.tmb',
315 'winHashFix' => DIRECTORY_SEPARATOR !== '/',
316 'uploadDeny' => array(),
317 'uploadAllow' => array('all'),
318 'uploadOrder' => array('deny', 'allow'),
319 'acceptedName' => 'validName',
320 'attributes' => array(
321 array(
322 'pattern' => '/.tmb/',
323 'read' => false,
324 'write' => false,
325 'hidden' => true,
326 'locked' => false
327 ),
328 array(
329 'pattern' => '/.gitkeep/',
330 'read' => false,
331 'write' => false,
332 'hidden' => true,
333 'locked' => false
334 )
335 )
336 );
337 $opts['roots'][0]['trashHash'] = 't1_Lw';
338 $opts['roots'][1] = $trash;
339 }
340
341 //Start --setting User Role Restrictions
342 $user = wp_get_current_user();
343 $userRoles = $user && $user->roles && $user->roles[0] ? $user->roles[0] : '';
344
345 //Disable Operations
346 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['list_user_restrictions_alow_access'])){
347 $opts['roots'][0]['disabled'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['list_user_restrictions_alow_access'];
348 }
349 //Creat root path for user
350 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'])){
351 $opts['roots'][0]['path'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'] .'/';
352 }
353
354 //Creat url root path for user
355 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'])){
356 $opts['roots'][0]['URL'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'] .'/';
357 }
358
359 //Folder or File Paths That You want to Hide
360 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['hide_paths'])){
361 foreach ($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['hide_paths'] as $key => $value){
362 $arrItemHidePath = array(
363 'pattern' => '~/'.$value.'~',
364 'read' => false,
365 'write' => false,
366 'hidden' => true,
367 'locked' => false
368 );
369 array_push($opts['roots'][0]['attributes'], $arrItemHidePath);
370 };
371 }
372
373 //File extensions which you want to Lock
374 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['lock_files'])){
375 foreach ($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['lock_files'] as $key => $value){
376 $arrItemLockFile = array(
377 'pattern' => '/'.$value.'/',
378 'read' => false,
379 'write' => false,
380 'hidden' => false,
381 'locked' => true
382 );
383 array_push($opts['roots'][0]['attributes'], $arrItemLockFile);
384 };
385 }
386
387 //Enter file extensions which can be uploaded
388 $flag = false;
389
390
391 if (is_multisite()) {
392 if( !current_user_can('create_sites') && empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
393 $opts['roots'][0]['uploadDeny'] = array('all');
394 $opts['roots'][0]['uploadAllow'] = array('');
395 } else if ( !current_user_can('create_sites') && !empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
396 $opts['roots'][0]['uploadDeny'] = array('all');
397 $opts['roots'][0]['uploadAllow'] = array();
398 $arrCanUploadMime = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'];
399 $mimeTypes = new \FileManagerHelper();
400 $arrMimeTypes = $mimeTypes->getArrMimeTypes();
401 foreach ($arrMimeTypes as $key => $value){
402 if(in_array($key,$arrCanUploadMime)) {
403 $explodeValue = explode(',',$value);
404 foreach($explodeValue as $item) {
405 array_push($opts['roots'][0]['uploadAllow'], $item );
406 }
407 }
408
409 };
410 foreach ($arrCanUploadMime as $value){
411 if(strpos($value,"x-conference") !== false
412 || strpos($value,"video") !== false
413 || strpos($value,"text") !== false
414 || strpos($value,"model") !== false
415 || strpos($value,"message") !== false
416 || strpos($value,"image") !== false
417 || strpos($value,"font") !== false
418 || strpos($value,"chemical") !== false
419 || strpos($value,"audio") !== false
420 || strpos($value,"application") !== false
421 ) {
422 array_push($opts['roots'][0]['uploadAllow'], $value );
423 }
424 }
425
426 } else {
427 $opts['roots'][0]['uploadDeny'] = array();
428 $opts['roots'][0]['uploadAllow'] = array('all');
429 }
430 }
431
432 if (!is_multisite()) {
433 if($this->userRole !== 'administrator' && empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
434 $opts['roots'][0]['uploadDeny'] = array('all');
435 $opts['roots'][0]['uploadAllow'] = array('');
436 } else if ( $this->userRole !== 'administrator' && !empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
437 $opts['roots'][0]['uploadDeny'] = array('all');
438 $opts['roots'][0]['uploadAllow'] = array();
439 $arrCanUploadMime = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'];
440 $mimeTypes = new \FileManagerHelper();
441 $arrMimeTypes = $mimeTypes->getArrMimeTypes();
442 foreach ($arrMimeTypes as $key => $value){
443 if(in_array($key,$arrCanUploadMime)) {
444 $explodeValue = explode(',',$value);
445 foreach($explodeValue as $item) {
446 array_push($opts['roots'][0]['uploadAllow'], $item );
447 }
448 }
449
450 };
451 foreach ($arrCanUploadMime as $value){
452 if(strpos($value,"x-conference") !== false
453 || strpos($value,"video") !== false
454 || strpos($value,"text") !== false
455 || strpos($value,"model") !== false
456 || strpos($value,"message") !== false
457 || strpos($value,"image") !== false
458 || strpos($value,"font") !== false
459 || strpos($value,"chemical") !== false
460 || strpos($value,"audio") !== false
461 || strpos($value,"application") !== false
462 ) {
463 array_push($opts['roots'][0]['uploadAllow'], $value );
464 }
465 }
466
467 } else {
468 $opts['roots'][0]['uploadDeny'] = array();
469 $opts['roots'][0]['uploadAllow'] = array('all');
470 }
471 }
472
473
474
475 //End --setting User Role Restrictions
476
477 $connector = new \elFinderConnector(new \elFinder($opts));
478 $connector->run();
479 wp_die();
480 }
481
482 public function selectorThemes()
483 {
484 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
485 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
486
487 $themesValue = sanitize_text_field ($_POST['themesValue']);
488 $selectorThemes = get_option('njt_fs_selector_themes');
489 if (empty($selectorThemes[$this->userRole])) {
490 $selectorThemes[$this->userRole]['themesValue'] = 'Default';
491 update_option('njt_fs_selector_themes', $selectorThemes);
492 }
493
494 if ($selectorThemes[$this->userRole]['themesValue'] != $themesValue) {
495 $selectorThemes[$this->userRole]['themesValue'] = $themesValue;
496 update_option('njt_fs_selector_themes', $selectorThemes);
497 }
498 $selected_themes = get_option('njt_fs_selector_themes');
499 $linkThemes = plugins_url('/lib/themes/' . $selected_themes[$this->userRole]['themesValue'] . '/css/theme.css', __FILE__);
500 wp_send_json_success($linkThemes);
501 wp_die();
502 }
503
504 public function saveOptions()
505 {
506 //if(isset($_POST['njt-settings-form-submit'])) {
507 update_option('njt_fs_settings', $this->options);
508 // if($u) {
509 // $this->f('?page=njt-fs-filemanager-settings&status=1');
510 // } else {
511 // $this->f('?page=njt-fs-filemanager-settings&status=2');
512 // }
513 // }
514 }
515
516 public function f($u) {
517 echo '<script>';
518 echo 'window.location.href="'.$u.'"';
519 echo '</script>';
520 }
521
522 public function getArrRoleRestrictions()
523 {
524 if(!wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
525 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
526 $valueUserRole = filter_var($_POST['valueUserRole']) ? sanitize_text_field ($_POST['valueUserRole']) : '';
527 $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();
528 $dataArrRoleRestrictions = array (
529 'disable_operations' => implode(",", !empty($arrRestrictions[$valueUserRole]['list_user_restrictions_alow_access']) ? $arrRestrictions[$valueUserRole]['list_user_restrictions_alow_access'] : array()),
530 'private_folder_access' => !empty($arrRestrictions[$valueUserRole]['private_folder_access']) ? str_replace("\\\\", "/", trim($arrRestrictions[$valueUserRole]['private_folder_access'])) : '',
531 'private_url_folder_access' => !empty($arrRestrictions[$valueUserRole]['private_url_folder_access']) ? str_replace("\\\\", "/", trim($arrRestrictions[$valueUserRole]['private_url_folder_access'])) : '',
532 'hide_paths' => implode(',', !empty($arrRestrictions[$valueUserRole]['hide_paths']) ? $arrRestrictions[$valueUserRole]['hide_paths'] : array()),
533 'lock_files' => implode(',', !empty($arrRestrictions[$valueUserRole]['lock_files']) ? $arrRestrictions[$valueUserRole]['lock_files'] : array()),
534 'can_upload_mime' => implode(',', !empty($arrRestrictions[$valueUserRole]['can_upload_mime']) ? $arrRestrictions[$valueUserRole]['can_upload_mime'] : array())
535 );
536 wp_send_json_success($dataArrRoleRestrictions);
537 wp_die();
538 }
539
540 public function njt_fs_saveSetting()
541 {
542 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
543 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
544
545 $root_folder_path = filter_var($_POST['root_folder_path'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['root_folder_path'])) : '';
546 $root_folder_url = filter_var($_POST['root_folder_url'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['root_folder_url'])) : site_url();
547 $list_user_alow_access = filter_var($_POST['list_user_alow_access'], FILTER_SANITIZE_STRING) ? explode(',',$_POST['list_user_alow_access']) : array();
548 $upload_max_size = filter_var($_POST['upload_max_size'], FILTER_SANITIZE_STRING) ? sanitize_text_field(trim($_POST['upload_max_size'])) : 0;
549 $fm_locale = filter_var($_POST['fm_locale'], FILTER_SANITIZE_STRING) ? sanitize_text_field($_POST['fm_locale']) : 'en';
550 $enable_htaccess = isset($_POST['enable_htaccess']) && $_POST['enable_htaccess'] == 'true' ? 1 : 0;
551 $enable_trash = isset($_POST['enable_trash']) && $_POST['enable_trash'] == 'true' ? 1 : 0;
552 //save options
553 $this->options['njt_fs_file_manager_settings']['root_folder_path'] = $root_folder_path;
554 $this->options['njt_fs_file_manager_settings']['root_folder_url'] = $root_folder_url;
555 $this->options['njt_fs_file_manager_settings']['list_user_alow_access'] = $list_user_alow_access;
556 $this->options['njt_fs_file_manager_settings']['upload_max_size'] = $upload_max_size;
557 $this->options['njt_fs_file_manager_settings']['fm_locale'] = $fm_locale;
558 $this->options['njt_fs_file_manager_settings']['enable_htaccess'] = $enable_htaccess;
559 $this->options['njt_fs_file_manager_settings']['enable_trash'] = $enable_trash;
560 //update options
561 update_option('njt_fs_settings', $this->options);
562 wp_send_json_success(get_option('njt_fs_settings'));
563 wp_die();
564 }
565
566 public function njt_fs_saveSettingRestrictions() {
567 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
568 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
569
570 if(! $_POST['njt_fs_list_user_restrictions']) wp_die();
571
572 $njt_fs_list_user_restrictions = $_POST['njt_fs_list_user_restrictions'];
573 $list_user_restrictions_alow_access = filter_var($_POST['list_user_restrictions_alow_access'], FILTER_SANITIZE_STRING) ? explode(',', $_POST['list_user_restrictions_alow_access']) : array();
574 $private_folder_access = filter_var($_POST['private_folder_access'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['private_folder_access'])) : '';
575 $private_url_folder_access = filter_var($_POST['private_url_folder_access'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['private_url_folder_access'])) : '';
576 $hide_paths = filter_var($_POST['hide_paths'], FILTER_SANITIZE_STRING) ? explode('|', preg_replace('/\s+/', '', $_POST['hide_paths'])) : array();
577 $lock_files = filter_var($_POST['lock_files'], FILTER_SANITIZE_STRING) ? explode('|', preg_replace('/\s+/', '', $_POST['lock_files'])) : array();
578 $can_upload_mime = filter_var($_POST['can_upload_mime'], FILTER_SANITIZE_STRING) ? explode(',', preg_replace('/\s+/', '', $_POST['can_upload_mime'])) : array();
579
580 //save options
581 $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;
582 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['private_folder_access'] = $private_folder_access;
583 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['private_url_folder_access'] = $private_url_folder_access;
584 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['hide_paths'] = $hide_paths;
585 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['lock_files'] = $lock_files;
586 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['can_upload_mime'] = $can_upload_mime;
587 //update options
588 update_option('njt_fs_settings', $this->options);
589 wp_send_json_success(get_option('njt_fs_settings'));
590 wp_die();
591 }
592
593 }