-
+ 8166333E0573868651A1E9DA3A9163177173F0A1115BDDD25FD004AC88D856075B3573B9B8945661BE9066014D4337BE1B95416EE0662FE85C7A2B64A7FD4F5D
mp-wp/wp-admin/includes/class-wp-filesystem-direct.php
(0 . 0)(1 . 274)
30488 <?php
30489 /**
30490 * WordPress Direct Filesystem.
30491 *
30492 * @package WordPress
30493 * @subpackage Filesystem
30494 */
30495
30496 /**
30497 * WordPress Filesystem Class for direct PHP file and folder manipulation.
30498 *
30499 * @since 2.5
30500 * @package WordPress
30501 * @subpackage Filesystem
30502 * @uses WP_Filesystem_Base Extends class
30503 */
30504 class WP_Filesystem_Direct extends WP_Filesystem_Base {
30505 var $permission = null;
30506 var $errors = array();
30507 function WP_Filesystem_Direct($arg) {
30508 $this->method = 'direct';
30509 $this->errors = new WP_Error();
30510 $this->permission = umask();
30511 }
30512 function connect() {
30513 return true;
30514 }
30515 function setDefaultPermissions($perm) {
30516 $this->permission = $perm;
30517 }
30518 function get_contents($file) {
30519 return @file_get_contents($file);
30520 }
30521 function get_contents_array($file) {
30522 return @file($file);
30523 }
30524 function put_contents($file, $contents, $mode = false, $type = '') {
30525 if ( ! ($fp = @fopen($file, 'w' . $type)) )
30526 return false;
30527 @fwrite($fp, $contents);
30528 @fclose($fp);
30529 $this->chmod($file,$mode);
30530 return true;
30531 }
30532 function cwd() {
30533 return @getcwd();
30534 }
30535 function chdir($dir) {
30536 return @chdir($dir);
30537 }
30538 function chgrp($file, $group, $recursive = false) {
30539 if( ! $this->exists($file) )
30540 return false;
30541 if( ! $recursive )
30542 return @chgrp($file, $group);
30543 if( ! $this->is_dir($file) )
30544 return @chgrp($file, $group);
30545 //Is a directory, and we want recursive
30546 $file = trailingslashit($file);
30547 $filelist = $this->dirlist($file);
30548 foreach($filelist as $filename)
30549 $this->chgrp($file . $filename, $group, $recursive);
30550
30551 return true;
30552 }
30553 function chmod($file, $mode = false, $recursive = false) {
30554 if( ! $mode )
30555 $mode = $this->permission;
30556 if( ! $this->exists($file) )
30557 return false;
30558 if( ! $recursive )
30559 return @chmod($file,$mode);
30560 if( ! $this->is_dir($file) )
30561 return @chmod($file, $mode);
30562 //Is a directory, and we want recursive
30563 $file = trailingslashit($file);
30564 $filelist = $this->dirlist($file);
30565 foreach($filelist as $filename)
30566 $this->chmod($file . $filename, $mode, $recursive);
30567
30568 return true;
30569 }
30570 function chown($file, $owner, $recursive = false) {
30571 if( ! $this->exists($file) )
30572 return false;
30573 if( ! $recursive )
30574 return @chown($file, $owner);
30575 if( ! $this->is_dir($file) )
30576 return @chown($file, $owner);
30577 //Is a directory, and we want recursive
30578 $filelist = $this->dirlist($file);
30579 foreach($filelist as $filename){
30580 $this->chown($file . '/' . $filename, $owner, $recursive);
30581 }
30582 return true;
30583 }
30584 function owner($file) {
30585 $owneruid = @fileowner($file);
30586 if( ! $owneruid )
30587 return false;
30588 if( ! function_exists('posix_getpwuid') )
30589 return $owneruid;
30590 $ownerarray = posix_getpwuid($owneruid);
30591 return $ownerarray['name'];
30592 }
30593 function getchmod($file) {
30594 return @fileperms($file);
30595 }
30596 function group($file) {
30597 $gid = @filegroup($file);
30598 if( ! $gid )
30599 return false;
30600 if( ! function_exists('posix_getgrgid') )
30601 return $gid;
30602 $grouparray = posix_getgrgid($gid);
30603 return $grouparray['name'];
30604 }
30605
30606 function copy($source, $destination, $overwrite = false) {
30607 if( ! $overwrite && $this->exists($destination) )
30608 return false;
30609 return copy($source, $destination);
30610 }
30611
30612 function move($source, $destination, $overwrite = false) {
30613 //Possible to use rename()?
30614 if( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){
30615 $this->delete($source);
30616 return true;
30617 } else {
30618 return false;
30619 }
30620 }
30621
30622 function delete($file, $recursive = false) {
30623 $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise
30624
30625 if( $this->is_file($file) )
30626 return @unlink($file);
30627 if( ! $recursive && $this->is_dir($file) )
30628 return @rmdir($file);
30629
30630 //At this point its a folder, and we're in recursive mode
30631 $file = trailingslashit($file);
30632 $filelist = $this->dirlist($file, true);
30633
30634 $retval = true;
30635 if( is_array($filelist) ) //false if no files, So check first.
30636 foreach($filelist as $filename => $fileinfo)
30637 if( ! $this->delete($file . $filename, $recursive) )
30638 $retval = false;
30639
30640 if( ! @rmdir($file) )
30641 return false;
30642 return $retval;
30643 }
30644
30645 function exists($file) {
30646 return @file_exists($file);
30647 }
30648
30649 function is_file($file) {
30650 return @is_file($file);
30651 }
30652
30653 function is_dir($path) {
30654 return @is_dir($path);
30655 }
30656
30657 function is_readable($file) {
30658 return @is_readable($file);
30659 }
30660
30661 function is_writable($file) {
30662 return @is_writable($file);
30663 }
30664
30665 function atime($file) {
30666 return @fileatime($file);
30667 }
30668
30669 function mtime($file) {
30670 return @filemtime($file);
30671 }
30672 function size($file) {
30673 return @filesize($file);
30674 }
30675
30676 function touch($file, $time = 0, $atime = 0){
30677 if($time == 0)
30678 $time = time();
30679 if($atime == 0)
30680 $atime = time();
30681 return @touch($file, $time, $atime);
30682 }
30683
30684 function mkdir($path, $chmod = false, $chown = false, $chgrp = false){
30685 if( ! $chmod)
30686 $chmod = $this->permission;
30687
30688 if( ! @mkdir($path, $chmod) )
30689 return false;
30690 if( $chown )
30691 $this->chown($path, $chown);
30692 if( $chgrp )
30693 $this->chgrp($path, $chgrp);
30694 return true;
30695 }
30696
30697 function rmdir($path, $recursive = false) {
30698 //Currently unused and untested, Use delete() instead.
30699 if( ! $recursive )
30700 return @rmdir($path);
30701 //recursive:
30702 $filelist = $this->dirlist($path);
30703 foreach($filelist as $filename => $det) {
30704 if ( '/' == substr($filename, -1, 1) )
30705 $this->rmdir($path . '/' . $filename, $recursive);
30706 @rmdir($filename);
30707 }
30708 return @rmdir($path);
30709 }
30710
30711 function dirlist($path, $incdot = false, $recursive = false) {
30712 if( $this->is_file($path) ) {
30713 $limitFile = basename($path);
30714 $path = dirname($path);
30715 } else {
30716 $limitFile = false;
30717 }
30718 if( ! $this->is_dir($path) )
30719 return false;
30720
30721 $ret = array();
30722 $dir = @dir($path);
30723 if ( ! $dir )
30724 return false;
30725 while (false !== ($entry = $dir->read()) ) {
30726 $struc = array();
30727 $struc['name'] = $entry;
30728
30729 if( '.' == $struc['name'] || '..' == $struc['name'] )
30730 continue; //Do not care about these folders.
30731 if( '.' == $struc['name'][0] && !$incdot)
30732 continue;
30733 if( $limitFile && $struc['name'] != $limitFile)
30734 continue;
30735
30736 $struc['perms'] = $this->gethchmod($path.'/'.$entry);
30737 $struc['permsn'] = $this->getnumchmodfromh($struc['perms']);
30738 $struc['number'] = false;
30739 $struc['owner'] = $this->owner($path.'/'.$entry);
30740 $struc['group'] = $this->group($path.'/'.$entry);
30741 $struc['size'] = $this->size($path.'/'.$entry);
30742 $struc['lastmodunix']= $this->mtime($path.'/'.$entry);
30743 $struc['lastmod'] = date('M j',$struc['lastmodunix']);
30744 $struc['time'] = date('h:i:s',$struc['lastmodunix']);
30745 $struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f';
30746
30747 if ( 'd' == $struc['type'] ) {
30748 if( $recursive )
30749 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
30750 else
30751 $struc['files'] = array();
30752 }
30753
30754 $ret[ $struc['name'] ] = $struc;
30755 }
30756 $dir->close();
30757 unset($dir);
30758 return $ret;
30759 }
30760 }
30761 ?>