PluginProbe ʕ •ᴥ•ʔ
File Manager Pro – Filester / 1.8.7
File Manager Pro – Filester v1.8.7
2.1.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
602 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( !empty($locale) && $locale != 'en' && in_array($locale, njt_fs_locales(), true)) {
250 $locale = sanitize_file_name($locale);
251 wp_enqueue_script( 'njt_fs_fma_lang', plugins_url('lib/js/i18n/elfinder.'.$locale.'.js', __FILE__));
252 }
253 }
254
255 wp_localize_script('njt_fs_elFinder', 'wpData', array(
256 'admin_ajax' => admin_url('admin-ajax.php'),
257 'nonce' => wp_create_nonce("njt-fs-file-manager-admin"),
258 'PLUGIN_URL' => NJT_FS_BN_PLUGIN_URL .'includes/File_manager/lib/',
259 'PLUGIN_PATH' => NJT_FS_BN_PLUGIN_PATH.'includes/File_manager/lib/',
260 'PLUGIN_DIR'=> NJT_FS_BN_PLUGIN_DIR,
261 'ABSPATH'=> str_replace("\\", "/", ABSPATH),
262 'is_multisite' => is_multisite(),
263 'lang' => !empty( $this->options['njt_fs_file_manager_settings']['fm_locale']) ? sanitize_file_name($this->options['njt_fs_file_manager_settings']['fm_locale']) : '',
264 'nonce_connector' => wp_create_nonce('file-manager-security-token'),
265 ));
266 }
267 }
268
269 //File manager connector function
270
271 public function fsConnector()
272 {
273 check_ajax_referer( 'file-manager-security-token', 'nonce' );
274 $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;
275
276 $opts = array(
277 'bind' => array(
278 'put.pre' => array(new \FileManagerHelper, 'madeStripcslashesFile'), // Check endcode when save file.
279 ),
280 'debug' => false,
281 'roots' => array(
282 array(
283 'driver' => 'LocalFileSystem',
284 '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,
285 '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(),
286 'trashHash' => '', // default is empty, when not enable trash
287 'uploadMaxSize' => $uploadMaxSize .'M',
288 'winHashFix' => DIRECTORY_SEPARATOR !== '/',
289 'uploadOrder' => array('deny', 'allow'),
290 'disabled' => array(''),
291 //'acceptedName' => 'validName',
292 'attributes' => array() // default is empty
293 ),
294 ),
295 );
296
297 // .htaccess
298 if(isset($this->options['njt_fs_file_manager_settings']['enable_htaccess']) && ($this->options['njt_fs_file_manager_settings']['enable_htaccess'] == '1')) {
299 $attributes = array(
300 'pattern' => '/.htaccess/',
301 'read' => false,
302 'write' => false,
303 'hidden' => true,
304 'locked' => false
305 );
306 array_push($opts['roots'][0]['attributes'], $attributes);
307 }
308
309 //Enable Trash
310 if(isset($this->options['njt_fs_file_manager_settings']['enable_trash']) && ($this->options['njt_fs_file_manager_settings']['enable_trash'] == '1')) {
311 $trash = array(
312 'id' => '1',
313 'driver' => 'Trash',
314 'path' => NJT_FS_BN_PLUGIN_PATH.'includes/File_manager/lib/files/.trash/',
315 'tmbURL' => site_url() . '/includes/File_manager/lib/files/.trash/.tmb',
316 'winHashFix' => DIRECTORY_SEPARATOR !== '/',
317 'uploadDeny' => array('htaccess'),
318 'uploadAllow' => array('all'),
319 'uploadOrder' => array('deny', 'allow'),
320 'acceptedName' => 'validName',
321 'attributes' => array(
322 array(
323 'pattern' => '/.tmb/',
324 'read' => false,
325 'write' => false,
326 'hidden' => true,
327 'locked' => false
328 ),
329 array(
330 'pattern' => '/.gitkeep/',
331 'read' => false,
332 'write' => false,
333 'hidden' => true,
334 'locked' => false
335 )
336 )
337 );
338 $opts['roots'][0]['trashHash'] = 't1_Lw';
339 $opts['roots'][1] = $trash;
340 }
341
342 //Start --setting User Role Restrictions
343 $user = wp_get_current_user();
344 $userRoles = $user && $user->roles && $user->roles[0] ? $user->roles[0] : '';
345
346 //Disable Operations
347 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['list_user_restrictions_alow_access'])){
348 $opts['roots'][0]['disabled'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['list_user_restrictions_alow_access'];
349 }
350 //Creat root path for user
351 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'])){
352 $opts['roots'][0]['path'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_folder_access'] .'/';
353 }
354
355 //Creat url root path for user
356 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'])){
357 $opts['roots'][0]['URL'] = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['private_url_folder_access'] .'/';
358 }
359
360 //Folder or File Paths That You want to Hide
361 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['hide_paths'])){
362 foreach ($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['hide_paths'] as $key => $value){
363 $arrItemHidePath = array(
364 'pattern' => '~/'.$value.'~',
365 'read' => false,
366 'write' => false,
367 'hidden' => true,
368 'locked' => false
369 );
370 array_push($opts['roots'][0]['attributes'], $arrItemHidePath);
371 };
372 }
373
374 //File extensions which you want to Lock
375 if(!empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['lock_files'])){
376 foreach ($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['lock_files'] as $key => $value){
377 $arrItemLockFile = array(
378 'pattern' => '/'.$value.'/',
379 'read' => false,
380 'write' => false,
381 'hidden' => false,
382 'locked' => true
383 );
384 array_push($opts['roots'][0]['attributes'], $arrItemLockFile);
385 };
386 }
387
388 //Enter file extensions which can be uploaded
389 $flag = false;
390
391
392 if (is_multisite()) {
393 if( !current_user_can('create_sites') && empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
394 $opts['roots'][0]['uploadDeny'] = array('all');
395 $opts['roots'][0]['uploadAllow'] = array('');
396 } else if ( !current_user_can('create_sites') && !empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
397 $opts['roots'][0]['uploadDeny'] = array('all');
398 $opts['roots'][0]['uploadAllow'] = array();
399 $arrCanUploadMime = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'];
400 $mimeTypes = new \FileManagerHelper();
401 $arrMimeTypes = $mimeTypes->getArrMimeTypes();
402 foreach ($arrMimeTypes as $key => $value){
403 if(in_array($key,$arrCanUploadMime)) {
404 $explodeValue = explode(',',$value);
405 foreach($explodeValue as $item) {
406 array_push($opts['roots'][0]['uploadAllow'], $item );
407 }
408 }
409
410 };
411 foreach ($arrCanUploadMime as $value){
412 if(strpos($value,"x-conference") !== false
413 || strpos($value,"video") !== false
414 || strpos($value,"text") !== false
415 || strpos($value,"model") !== false
416 || strpos($value,"message") !== false
417 || strpos($value,"image") !== false
418 || strpos($value,"font") !== false
419 || strpos($value,"chemical") !== false
420 || strpos($value,"audio") !== false
421 || strpos($value,"application") !== false
422 ) {
423 array_push($opts['roots'][0]['uploadAllow'], $value );
424 }
425 }
426
427 } else {
428 $opts['roots'][0]['uploadDeny'] = array();
429 $opts['roots'][0]['uploadAllow'] = array('all');
430 }
431 }
432
433 if (!is_multisite()) {
434 if($this->userRole !== 'administrator' && empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
435 $opts['roots'][0]['uploadDeny'] = array('all');
436 $opts['roots'][0]['uploadAllow'] = array('');
437 } else if ( $this->userRole !== 'administrator' && !empty($this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'])) {
438 $opts['roots'][0]['uploadDeny'] = array('all');
439 $opts['roots'][0]['uploadAllow'] = array();
440 $arrCanUploadMime = $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$this->userRole]['can_upload_mime'];
441 $mimeTypes = new \FileManagerHelper();
442 $arrMimeTypes = $mimeTypes->getArrMimeTypes();
443 foreach ($arrMimeTypes as $key => $value){
444 if(in_array($key,$arrCanUploadMime)) {
445 $explodeValue = explode(',',$value);
446 foreach($explodeValue as $item) {
447 array_push($opts['roots'][0]['uploadAllow'], $item );
448 }
449 }
450
451 };
452 foreach ($arrCanUploadMime as $value){
453 if(strpos($value,"x-conference") !== false
454 || strpos($value,"video") !== false
455 || strpos($value,"text") !== false
456 || strpos($value,"model") !== false
457 || strpos($value,"message") !== false
458 || strpos($value,"image") !== false
459 || strpos($value,"font") !== false
460 || strpos($value,"chemical") !== false
461 || strpos($value,"audio") !== false
462 || strpos($value,"application") !== false
463 ) {
464 array_push($opts['roots'][0]['uploadAllow'], $value );
465 }
466 }
467
468 } else {
469 $opts['roots'][0]['uploadDeny'] = array();
470 $opts['roots'][0]['uploadAllow'] = array('all');
471 }
472 }
473
474
475
476 //End --setting User Role Restrictions
477
478 $connector = new \elFinderConnector(new \elFinder($opts));
479 $connector->run();
480 wp_die();
481 }
482
483 public function selectorThemes()
484 {
485 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
486 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
487
488 $themesValue = sanitize_text_field ($_POST['themesValue']);
489 $selectorThemes = get_option('njt_fs_selector_themes');
490 if (empty($selectorThemes[$this->userRole])) {
491 $selectorThemes[$this->userRole]['themesValue'] = 'Default';
492 update_option('njt_fs_selector_themes', $selectorThemes);
493 }
494
495 if ($selectorThemes[$this->userRole]['themesValue'] != $themesValue) {
496 $selectorThemes[$this->userRole]['themesValue'] = $themesValue;
497 update_option('njt_fs_selector_themes', $selectorThemes);
498 }
499 $selected_themes = get_option('njt_fs_selector_themes');
500 $linkThemes = plugins_url('/lib/themes/' . $selected_themes[$this->userRole]['themesValue'] . '/css/theme.css', __FILE__);
501 wp_send_json_success($linkThemes);
502 wp_die();
503 }
504
505 public function saveOptions()
506 {
507 //if(isset($_POST['njt-settings-form-submit'])) {
508 update_option('njt_fs_settings', $this->options);
509 // if($u) {
510 // $this->f('?page=njt-fs-filemanager-settings&status=1');
511 // } else {
512 // $this->f('?page=njt-fs-filemanager-settings&status=2');
513 // }
514 // }
515 }
516
517 public function f($u) {
518 echo '<script>';
519 echo 'window.location.href="'.$u.'"';
520 echo '</script>';
521 }
522
523 public function getArrRoleRestrictions()
524 {
525 if(!wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
526 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
527 $valueUserRole = filter_var($_POST['valueUserRole']) ? sanitize_text_field ($_POST['valueUserRole']) : '';
528 $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();
529 $dataArrRoleRestrictions = array (
530 'disable_operations' => implode(",", !empty($arrRestrictions[$valueUserRole]['list_user_restrictions_alow_access']) ? $arrRestrictions[$valueUserRole]['list_user_restrictions_alow_access'] : array()),
531 'private_folder_access' => !empty($arrRestrictions[$valueUserRole]['private_folder_access']) ? str_replace("\\\\", "/", trim($arrRestrictions[$valueUserRole]['private_folder_access'])) : '',
532 'private_url_folder_access' => !empty($arrRestrictions[$valueUserRole]['private_url_folder_access']) ? str_replace("\\\\", "/", trim($arrRestrictions[$valueUserRole]['private_url_folder_access'])) : '',
533 'hide_paths' => implode(',', !empty($arrRestrictions[$valueUserRole]['hide_paths']) ? $arrRestrictions[$valueUserRole]['hide_paths'] : array()),
534 'lock_files' => implode(',', !empty($arrRestrictions[$valueUserRole]['lock_files']) ? $arrRestrictions[$valueUserRole]['lock_files'] : array()),
535 'can_upload_mime' => implode(',', !empty($arrRestrictions[$valueUserRole]['can_upload_mime']) ? $arrRestrictions[$valueUserRole]['can_upload_mime'] : array())
536 );
537 wp_send_json_success($dataArrRoleRestrictions);
538 wp_die();
539 }
540
541 public function njt_fs_saveSetting()
542 {
543 if( ! wp_verify_nonce( $_POST['nonce'] ,'njt-fs-file-manager-admin')) wp_die();
544 check_ajax_referer('njt-fs-file-manager-admin', 'nonce', true);
545
546 if (!current_user_can('manage_options')) {
547 wp_die();
548 }
549
550 $root_folder_path = filter_var($_POST['root_folder_path'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['root_folder_path'])) : '';
551 $root_folder_url = filter_var($_POST['root_folder_url'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['root_folder_url'])) : site_url();
552 $list_user_alow_access = filter_var($_POST['list_user_alow_access'], FILTER_SANITIZE_STRING) ? explode(',',$_POST['list_user_alow_access']) : array();
553 $upload_max_size = filter_var($_POST['upload_max_size'], FILTER_SANITIZE_STRING) ? sanitize_text_field(trim($_POST['upload_max_size'])) : 0;
554 $fm_locale = filter_var($_POST['fm_locale'], FILTER_SANITIZE_STRING) ? sanitize_text_field($_POST['fm_locale']) : 'en';
555 $enable_htaccess = isset($_POST['enable_htaccess']) && $_POST['enable_htaccess'] == 'true' ? 1 : 0;
556 $enable_trash = isset($_POST['enable_trash']) && $_POST['enable_trash'] == 'true' ? 1 : 0;
557 //save options
558 $this->options['njt_fs_file_manager_settings']['root_folder_path'] = $root_folder_path;
559 $this->options['njt_fs_file_manager_settings']['root_folder_url'] = $root_folder_url;
560 $this->options['njt_fs_file_manager_settings']['list_user_alow_access'] = $list_user_alow_access;
561 $this->options['njt_fs_file_manager_settings']['upload_max_size'] = $upload_max_size;
562 $this->options['njt_fs_file_manager_settings']['fm_locale'] = $fm_locale;
563 $this->options['njt_fs_file_manager_settings']['enable_htaccess'] = $enable_htaccess;
564 $this->options['njt_fs_file_manager_settings']['enable_trash'] = $enable_trash;
565 //update options
566 update_option('njt_fs_settings', $this->options);
567 wp_send_json_success(get_option('njt_fs_settings'));
568 wp_die();
569 }
570
571 public function njt_fs_saveSettingRestrictions() {
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 if(! $_POST['njt_fs_list_user_restrictions']) wp_die();
580
581 $njt_fs_list_user_restrictions = sanitize_text_field($_POST['njt_fs_list_user_restrictions']);
582 $list_user_restrictions_alow_access = filter_var($_POST['list_user_restrictions_alow_access'], FILTER_SANITIZE_STRING) ? explode(',', $_POST['list_user_restrictions_alow_access']) : array();
583 $private_folder_access = filter_var($_POST['private_folder_access'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['private_folder_access'])) : '';
584 $private_url_folder_access = filter_var($_POST['private_url_folder_access'], FILTER_SANITIZE_STRING) ? str_replace("\\\\", "/", trim($_POST['private_url_folder_access'])) : '';
585 $hide_paths = filter_var($_POST['hide_paths'], FILTER_SANITIZE_STRING) ? explode('|', preg_replace('/\s+/', '', $_POST['hide_paths'])) : array();
586 $lock_files = filter_var($_POST['lock_files'], FILTER_SANITIZE_STRING) ? explode('|', preg_replace('/\s+/', '', $_POST['lock_files'])) : array();
587 $can_upload_mime = filter_var($_POST['can_upload_mime'], FILTER_SANITIZE_STRING) ? explode(',', preg_replace('/\s+/', '', $_POST['can_upload_mime'])) : array();
588
589 //save options
590 $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;
591 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['private_folder_access'] = $private_folder_access;
592 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['private_url_folder_access'] = $private_url_folder_access;
593 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['hide_paths'] = $hide_paths;
594 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['lock_files'] = $lock_files;
595 $this->options['njt_fs_file_manager_settings']['list_user_role_restrictions'][$njt_fs_list_user_restrictions]['can_upload_mime'] = $can_upload_mime;
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 }