PluginProbe
WPIDE – File Manager & Code Editor / 3.0
WPIDE – File Manager & Code Editor v3.0
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.0, at App/Services/Storage/LocalFileSystem.php

113 lines 3.3 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 if(!str_contains($root, CONTENT_DIR)) {
30 $root = CONTENT_DIR.$root;
31 }
32
33 return [
34 'root' => $root,
35 'separator' => '/',
36 'excluded_dirs' => !empty($excluded['dirs']) ? $excluded['dirs'] : [],
37 'excluded_files' => !empty($excluded['files']) ? $excluded['files'] : [],
38 'config' => [],
39 'adapter' => function() use($root){
40
41 $permissions = [
42 'file' => [
43 'public' => defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : (fileperms( ABSPATH . 'index.php' ) ? 0644 : 0777),
44 'private' => 0600,
45 ],
46 'dir' => [
47 'public' => defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : (fileperms( ABSPATH ) ? 0755 : 0777),
48 'private' => 0700,
49 ],
50 ];
51
52 $use_wp_filesystem = false;
53 $credentials = null;
54
55 // Try and use WP filesystem
56 if(function_exists('request_filesystem_credentials')) {
57 ob_start();
58 $credentials = request_filesystem_credentials('', '', false, false);
59 ob_end_clean();
60 $use_wp_filesystem = true;
61 }
62
63 if ( $use_wp_filesystem && wp_filesystem( $credentials ) ) {
64 global $wp_filesystem;
65 return new WPFileSystem($root, $wp_filesystem, 1, $permissions );
66 }else{
67 return new Local($root, LOCK_EX, 1, $permissions );
68 }
69
70 }
71 ];
72 }
73
74
75 public static function excludedDirs(): array
76 {
77 $user_excluded_dirs = array_filter(AppConfig::get('file.filter_entries', []), function($entry) {
78
79 return substr($entry , -1) === '/';
80 });
81
82 return array_merge(
83 [
84 DIR,
85 UPLOADS_DIR,
86 ABSPATH . 'wp-admin/',
87 ABSPATH . 'wp-includes/'
88 ],
89 $user_excluded_dirs
90 );
91 }
92
93 public static function excludedFiles(): array
94 {
95
96 $user_excluded_files = array_filter(AppConfig::get('file.filter_entries', []), function($entry) {
97
98 return substr($entry , -1) !== '/';
99 });
100
101 return array_merge(
102 [
103 ABSPATH . '!wp-config.php',
104 ABSPATH . 'wp-*.php',
105 ABSPATH . 'index.php',
106 ABSPATH . 'xmlrpc.php',
107 CONTENT_DIR.'/fatal-error-handler.php',
108 ],
109 $user_excluded_files
110 );
111 }
112
113 }