PluginProbe
Depicter — Popup & Slider Builder / 1.6.2
Depicter — Popup & Slider Builder v1.6.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / averta / wordpress / src / File / FileSystem.php

FileSystem.php in Depicter — Popup & Slider Builder 1.6.2, at vendor/averta/wordpress/src/File/FileSystem.php

217 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Averta\WordPress\File;
4
5
6 class FileSystem
7 {
8
9 protected $wpFilesystem;
10
11
12 public function __construct()
13 {
14 global $wp_filesystem;
15
16 if ( ! function_exists( 'get_filesystem_method' ) || empty( $wp_filesystem ) ) {
17 require_once ( ABSPATH.'/wp-admin/includes/file.php' );
18 WP_Filesystem();
19 }
20
21 $this->wpFilesystem = $wp_filesystem;
22 }
23
24 /**
25 * Validates filesystem credentials.
26 */
27 public function validate( $url = null )
28 {
29 if ( get_filesystem_method() === 'direct' ) {}
30 return true;
31 }
32
33 /**
34 * Reads a file if exists.
35 *
36 * @param string $filename File name.
37 *
38 * @return string
39 */
40 public function read( $filename )
41 {
42 if ( ! $this->validate() ){
43 return false;
44 }
45 return $this->wpFilesystem->get_contents( $filename );
46 }
47
48
49 /**
50 * Creates and stores content in a file
51 *
52 * @param string $file_location The address that we plan to create the file in.
53 * @param string $content The content for writing in the file
54 * @param int $chmod
55 *
56 * @return boolean Returns true if the file is created and updated successfully, false on failure
57 */
58 public function write( $file_location = '', $content = '', $chmod = 0644 )
59 {
60 if ( ! $this->validate() ){
61 return false;
62 }
63
64 $_chmod = defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : $chmod;
65 // Write the content, if possible
66 if ( wp_mkdir_p( dirname( $file_location ) ) && ! $this->wpFilesystem->put_contents( $file_location, $content, $_chmod ) ) {
67 // If writing the content in the file was not successful
68 return false;
69 } else {
70 return true;
71 }
72 }
73
74 /**
75 * Whether the file/path exists or not.
76 *
77 * @param string $file File name or file path.
78 *
79 * @return bool
80 */
81 public function exists( $file )
82 {
83 if ( ! $this->validate() ){
84 return false;
85 }
86
87 return $this->wpFilesystem->exists( $file );
88 }
89
90 /**
91 * Whether the path is a file or not.
92 *
93 * @return bool
94 */
95 public function isFile( $file )
96 {
97 if ( ! $this->validate() ){
98 return false;
99 }
100 return $this->wpFilesystem->is_file( $file );
101 }
102
103 /**
104 * Whether the path is a directory or not.
105 *
106 * @return bool
107 */
108 public function isDir( $path )
109 {
110 if ( ! $this->validate() ){
111 return false;
112 }
113
114 return $this->wpFilesystem->is_dir( $path );
115 }
116
117 /**
118 * Creates a folder path recursively.
119 *
120 * @param string $path Path
121 *
122 * @return bool
123 */
124 public function mkdir( $path )
125 {
126 if ( ! $this->validate() ){
127 return false;
128 }
129
130 return $this->wpFilesystem->mkdir( $path );
131 }
132
133 /**
134 * Removes folder path and contents.
135 *
136 * @return bool
137 * @global $wp_filesytem
138 * @since 0.9.0
139 *
140 */
141 public function rmdir( $path, $recursive = false )
142 {
143 if ( ! $this->validate() ){
144 return false;
145 }
146
147 return $this->wpFilesystem->rmdir( $path, $recursive );
148 }
149
150 /**
151 * Gets details for files in a directory or a specific file.
152 *
153 *
154 * @param string $path Path to directory or file.
155 * @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
156 * Default true.
157 * @param bool $recursive Optional. Whether to recursively include file details in nested directories.
158 * Default false.
159 * @return array|false {
160 * Array of files. False if unable to list directory contents.
161 *
162 * @type string $name Name of the file or directory.
163 * @type string $perms *nix representation of permissions.
164 * @type string $permsn Octal representation of permissions.
165 * @type string $owner Owner name or ID.
166 * @type int $size Size of file in bytes.
167 * @type int $lastmodunix Last modified unix timestamp.
168 * @type mixed $lastmod Last modified month (3 letter) and day (without leading 0).
169 * @type int $time Last modified time.
170 * @type string $type Type of resource. 'f' for file, 'd' for directory.
171 * @type mixed $files If a directory and `$recursive` is true, contains another array of files.
172 * }
173 */
174 public function scan( $path, $include_hidden = true, $recursive = false ) {
175 if ( ! $this->validate() ){
176 return false;
177 }
178
179 return $this->wpFilesystem->dirlist( $path, $include_hidden, $recursive );
180 }
181
182 /**
183 * Copy files from source to destination
184 *
185 * @param string $source
186 * @param string $destination
187 * @param false $overwrite
188 * @param false $mode
189 *
190 * @return bool True on success, false on failure.
191 */
192 public function copy( $source, $destination, $overwrite = false, $mode = false ) {
193 if ( ! $this->validate() ){
194 return false;
195 }
196
197 return $this->wpFilesystem->copy( $source, $destination, $overwrite, $mode );
198 }
199
200 /**
201 * Move files from source to destination
202 *
203 * @param string $source
204 * @param string $destination
205 * @param false $overwrite
206 *
207 * @return bool True on success, false on failure.
208 */
209 public function move( $source, $destination, $overwrite = false ) {
210 if ( ! $this->validate() ){
211 return false;
212 }
213
214 return $this->wpFilesystem->move( $source, $destination, $overwrite );
215 }
216 }
217