PluginProbe
WPIDE – File Manager & Code Editor / 3.4.2
WPIDE – File Manager & Code Editor v3.4.2
3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 3.4 All 54 releases
wpide / App / Services / Storage / LocalFileSystem.php

LocalFileSystem.php in WPIDE – File Manager & Code Editor 3.4.2, at App/Services/Storage/LocalFileSystem.php

116 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPIDE\App\Services\Storage;
3
4 use const WPIDE\Constants\CONTENT_DIR;
5 use const WPIDE\Constants\DIR;
6 use const WPIDE\Constants\UPLOADS_DIR;
7
8 use WPIDE\App\AppConfig;
9 use WPIDE\App\Services\Storage\Adapters\WPFileSystem;
10 use League\Flysystem\Adapter\Local;
11
12 class LocalFileSystem {
13
14 public static function load($root = null): Filesystem
15 {
16
17 $fs = new Filesystem();
18 $fs->init(self::getConfig($root));
19
20 return $fs;
21 }
22
23 public static function getConfig($root = null, $excluded = []): array
24 {
25 if(empty($root)) {
26 $root = apply_filters('wpide_filesystem_root', AppConfig::get('file.root'));
27 }
28
29 $root = wp_normalize_path($root);
30
31 if(!str_contains($root, CONTENT_DIR)) {
32 $root = CONTENT_DIR.$root;
33 }
34
35 return [
36 'root' => $root,
37 'separator' => '/',
38 'excluded_dirs' => !empty($excluded['dirs']) ? $excluded['dirs'] : [],
39 'excluded_files' => !empty($excluded['files']) ? $excluded['files'] : [],
40 'config' => [],
41 'adapter' => function() use($root){
42
43 $permissions = [
44 'file' => [
45 'public' => defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : (fileperms( ABSPATH . 'index.php' ) ? 0644 : 0777),
46 'private' => 0600,
47 ],
48 'dir' => [
49 'public' => defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : (fileperms( ABSPATH ) ? 0755 : 0777),
50 'private' => 0700,
51 ],
52 ];
53
54 $use_wp_filesystem = false;
55 $credentials = null;
56
57 // Try and use WP filesystem
58 if(function_exists('request_filesystem_credentials')) {
59 ob_start();
60 $credentials = request_filesystem_credentials('', '', false, false);
61 ob_end_clean();
62 $use_wp_filesystem = true;
63 }
64
65 if ( $use_wp_filesystem && wp_filesystem( $credentials ) ) {
66 global $wp_filesystem;
67 return new WPFileSystem($root, $wp_filesystem, 1, $permissions );
68 }else{
69 return new Local($root, LOCK_EX, 1, $permissions );
70 }
71
72 }
73 ];
74 }
75
76
77 public static function excludedDirs(): array
78 {
79 $user_excluded_dirs = array_filter(AppConfig::get('file.filter_entries', []), function($entry) {
80
81 return substr($entry , -1) === '/';
82 });
83
84 return array_merge(
85 [
86 DIR,
87 rtrim(DIR, '/').'-pro/',
88 UPLOADS_DIR,
89 wp_normalize_path(ABSPATH . 'wp-admin/'),
90 wp_normalize_path(ABSPATH . 'wp-includes/')
91 ],
92 $user_excluded_dirs
93 );
94 }
95
96 public static function excludedFiles(): array
97 {
98
99 $user_excluded_files = array_filter(AppConfig::get('file.filter_entries', []), function($entry) {
100
101 return substr($entry , -1) !== '/';
102 });
103
104 return array_merge(
105 [
106 wp_normalize_path(ABSPATH . '!wp-config.php'),
107 wp_normalize_path(ABSPATH . 'wp-*.php'),
108 wp_normalize_path(ABSPATH . 'index.php'),
109 wp_normalize_path(ABSPATH . 'xmlrpc.php'),
110 CONTENT_DIR.'/fatal-error-handler.php',
111 ],
112 $user_excluded_files
113 );
114 }
115
116 }