~canonical-sysadmins/wordpress/4.2.4

« back to all changes in this revision

Viewing changes to wp-admin/includes/class-wp-filesystem-direct.php

  • Committer: Nick Moffitt
  • Date: 2015-01-15 11:05:37 UTC
  • mfrom: (1.1.1 wp4-upstream)
  • Revision ID: nick.moffitt@canonical.com-20150115110537-8bp1y42eyg0jsa7c
Tags: 4.1
MergeĀ upstreamĀ versionĀ 4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
        /**
50
50
         * Write a string to a file
51
51
         *
52
 
         * @param string $file Remote path to the file where to write the data.
 
52
         * @param string $file     Remote path to the file where to write the data.
53
53
         * @param string $contents The data to write.
54
 
         * @param int $mode (optional) The file permissions as octal number, usually 0644.
55
 
         * @return bool False upon failure.
 
54
         * @param int    $mode     Optional. The file permissions as octal number, usually 0644.
 
55
         *                         Default false.
 
56
         * @return bool False upon failure, true otherwise.
56
57
         */
57
58
        public function put_contents( $file, $contents, $mode = false ) {
58
59
                $fp = @fopen( $file, 'wb' );
99
100
        /**
100
101
         * Changes file group
101
102
         *
102
 
         * @param string $file Path to the file.
103
 
         * @param mixed $group A group name or number.
104
 
         * @param bool $recursive (optional) If set True changes file group recursively. Defaults to False.
 
103
         * @param string $file      Path to the file.
 
104
         * @param mixed  $group     A group name or number.
 
105
         * @param bool   $recursive Optional. If set True changes file group recursively. Default false.
105
106
         * @return bool Returns true on success or false on failure.
106
107
         */
107
108
        public function chgrp($file, $group, $recursive = false) {
123
124
        /**
124
125
         * Changes filesystem permissions
125
126
         *
126
 
         * @param string $file Path to the file.
127
 
         * @param int $mode (optional) The permissions as octal number, usually 0644 for files, 0755 for dirs.
128
 
         * @param bool $recursive (optional) If set True changes file group recursively. Defaults to False.
 
127
         * @param string $file      Path to the file.
 
128
         * @param int    $mode      Optional. The permissions as octal number, usually 0644 for files,
 
129
         *                          0755 for dirs. Default false.
 
130
         * @param bool   $recursive Optional. If set True changes file group recursively. Default false.
129
131
         * @return bool Returns true on success or false on failure.
130
132
         */
131
133
        public function chmod($file, $mode = false, $recursive = false) {
152
154
        /**
153
155
         * Changes file owner
154
156
         *
155
 
         * @param string $file Path to the file.
156
 
         * @param mixed $owner A user name or number.
157
 
         * @param bool $recursive (optional) If set True changes file owner recursively. Defaults to False.
 
157
         * @param string $file      Path to the file.
 
158
         * @param mixed  $owner     A user name or number.
 
159
         * @param bool   $recursive Optional. If set True changes file owner recursively.
 
160
         *                          Default false.
158
161
         * @return bool Returns true on success or false on failure.
159
162
         */
160
163
        public function chown($file, $owner, $recursive = false) {
200
203
                return substr( decoct( @fileperms( $file ) ), -3 );
201
204
        }
202
205
 
 
206
        /**
 
207
         * @param string $file
 
208
         * @return string|false
 
209
         */
203
210
        public function group($file) {
204
211
                $gid = @filegroup($file);
205
212
                if ( ! $gid )
210
217
                return $grouparray['name'];
211
218
        }
212
219
 
 
220
        /**
 
221
         * @param string $source
 
222
         * @param string $destination
 
223
         * @param bool   $overwrite
 
224
         * @param int    $mode
 
225
         * @return bool
 
226
         */
213
227
        public function copy($source, $destination, $overwrite = false, $mode = false) {
214
228
                if ( ! $overwrite && $this->exists($destination) )
215
229
                        return false;
220
234
                return $rtval;
221
235
        }
222
236
 
 
237
        /**
 
238
         * @param string $source
 
239
         * @param string $destination
 
240
         * @param bool $overwrite
 
241
         * @return bool
 
242
         */
223
243
        public function move($source, $destination, $overwrite = false) {
224
244
                if ( ! $overwrite && $this->exists($destination) )
225
245
                        return false;
236
256
                }
237
257
        }
238
258
 
 
259
        /**
 
260
         * @param string $file
 
261
         * @param bool $recursive
 
262
         * @param string $type
 
263
         * @return bool
 
264
         */
239
265
        public function delete($file, $recursive = false, $type = false) {
240
266
                if ( empty( $file ) ) // Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem.
241
267
                        return false;
263
289
 
264
290
                return $retval;
265
291
        }
266
 
 
 
292
        /**
 
293
         * @param string $file
 
294
         * @return bool
 
295
         */
267
296
        public function exists($file) {
268
297
                return @file_exists($file);
269
298
        }
270
 
 
 
299
        /**
 
300
         * @param string $file
 
301
         * @return bool
 
302
         */
271
303
        public function is_file($file) {
272
304
                return @is_file($file);
273
305
        }
274
 
 
 
306
        /**
 
307
         * @param string $path
 
308
         * @return bool
 
309
         */
275
310
        public function is_dir($path) {
276
311
                return @is_dir($path);
277
312
        }
278
313
 
 
314
        /**
 
315
         * @param string $file
 
316
         * @return bool
 
317
         */
279
318
        public function is_readable($file) {
280
319
                return @is_readable($file);
281
320
        }
282
321
 
 
322
        /**
 
323
         * @param string $file
 
324
         * @return bool
 
325
         */
283
326
        public function is_writable($file) {
284
327
                return @is_writable($file);
285
328
        }
286
329
 
 
330
        /**
 
331
         * @param string $file
 
332
         * @return int
 
333
         */
287
334
        public function atime($file) {
288
335
                return @fileatime($file);
289
336
        }
290
337
 
 
338
        /**
 
339
         * @param string $file
 
340
         * @return int
 
341
         */
291
342
        public function mtime($file) {
292
343
                return @filemtime($file);
293
344
        }
294
345
 
 
346
        /**
 
347
         * @param string $file
 
348
         * @return int
 
349
         */
295
350
        public function size($file) {
296
351
                return @filesize($file);
297
352
        }
298
353
 
 
354
        /**
 
355
         * @param string $file
 
356
         * @param int $time
 
357
         * @param int $atime
 
358
         * @return bool
 
359
         */
299
360
        public function touch($file, $time = 0, $atime = 0) {
300
361
                if ($time == 0)
301
362
                        $time = time();
304
365
                return @touch($file, $time, $atime);
305
366
        }
306
367
 
 
368
        /**
 
369
         * @param string $path
 
370
         * @param mixed  $chmod
 
371
         * @param mixed  $chown
 
372
         * @param mixed  $chgrp
 
373
         * @return bool
 
374
         */
307
375
        public function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
308
376
                // Safe mode fails with a trailing slash under certain PHP versions.
309
377
                $path = untrailingslashit($path);
323
391
                return true;
324
392
        }
325
393
 
 
394
        /**
 
395
         * @param string $path
 
396
         * @param bool $recursive
 
397
         * @return type
 
398
         */
326
399
        public function rmdir($path, $recursive = false) {
327
400
                return $this->delete($path, $recursive);
328
401
        }
329
402
 
 
403
        /**
 
404
         * @param string $path
 
405
         * @param bool $include_hidden
 
406
         * @param bool $recursive
 
407
         * @return bool|array
 
408
         */
330
409
        public function dirlist($path, $include_hidden = true, $recursive = false) {
331
410
                if ( $this->is_file($path) ) {
332
411
                        $limit_file = basename($path);