[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> class-wp-filesystem-ssh2.php (source)

   1  <?php
   2  /**
   3   * WordPress Filesystem Class for implementing SSH2
   4   *
   5   * To use this class you must follow these steps for PHP 5.2.6+
   6   *
   7   * @contrib http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ - Installation Notes
   8   *
   9   * Compile libssh2 (Note: Only 0.14 is officaly working with PHP 5.2.6+ right now, But many users have found the latest versions work)
  10   *
  11   * cd /usr/src
  12   * wget https://www.libssh2.org/download/libssh2-0.14.tar.gz
  13   * tar -zxvf libssh2-0.14.tar.gz
  14   * cd libssh2-0.14/
  15   * ./configure
  16   * make all install
  17   *
  18   * Note: Do not leave the directory yet!
  19   *
  20   * Enter: pecl install -f ssh2
  21   *
  22   * Copy the ssh.so file it creates to your PHP Module Directory.
  23   * Open up your PHP.INI file and look for where extensions are placed.
  24   * Add in your PHP.ini file: extension=ssh2.so
  25   *
  26   * Restart Apache!
  27   * Check phpinfo() streams to confirm that: ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp  exist.
  28   *
  29   * Note: As of WordPress 2.8, this utilises the PHP5+ function `stream_get_contents()`.
  30   *
  31   * @since 2.7.0
  32   *
  33   * @package WordPress
  34   * @subpackage Filesystem
  35   */
  36  class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
  37  
  38      /**
  39       * @since 2.7.0
  40       * @var resource
  41       */
  42      public $link = false;
  43  
  44      /**
  45       * @since 2.7.0
  46       * @var resource
  47       */
  48      public $sftp_link;
  49  
  50      /**
  51       * @since 2.7.0
  52       * @var bool
  53       */
  54      public $keys = false;
  55  
  56      /**
  57       * Constructor.
  58       *
  59       * @since 2.7.0
  60       *
  61       * @param array $opt
  62       */
  63  	public function __construct( $opt = '' ) {
  64          $this->method = 'ssh2';
  65          $this->errors = new WP_Error();
  66  
  67          // Check if possible to use ssh2 functions.
  68          if ( ! extension_loaded( 'ssh2' ) ) {
  69              $this->errors->add( 'no_ssh2_ext', __( 'The ssh2 PHP extension is not available' ) );
  70              return;
  71          }
  72  
  73          // Set defaults:
  74          if ( empty( $opt['port'] ) ) {
  75              $this->options['port'] = 22;
  76          } else {
  77              $this->options['port'] = $opt['port'];
  78          }
  79  
  80          if ( empty( $opt['hostname'] ) ) {
  81              $this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) );
  82          } else {
  83              $this->options['hostname'] = $opt['hostname'];
  84          }
  85  
  86          // Check if the options provided are OK.
  87          if ( ! empty( $opt['public_key'] ) && ! empty( $opt['private_key'] ) ) {
  88              $this->options['public_key']  = $opt['public_key'];
  89              $this->options['private_key'] = $opt['private_key'];
  90  
  91              $this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa' );
  92  
  93              $this->keys = true;
  94          } elseif ( empty( $opt['username'] ) ) {
  95              $this->errors->add( 'empty_username', __( 'SSH2 username is required' ) );
  96          }
  97  
  98          if ( ! empty( $opt['username'] ) ) {
  99              $this->options['username'] = $opt['username'];
 100          }
 101  
 102          if ( empty( $opt['password'] ) ) {
 103              // Password can be blank if we are using keys.
 104              if ( ! $this->keys ) {
 105                  $this->errors->add( 'empty_password', __( 'SSH2 password is required' ) );
 106              }
 107          } else {
 108              $this->options['password'] = $opt['password'];
 109          }
 110      }
 111  
 112      /**
 113       * Connects filesystem.
 114       *
 115       * @since 2.7.0
 116       *
 117       * @return bool True on success, false on failure.
 118       */
 119  	public function connect() {
 120          if ( ! $this->keys ) {
 121              $this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'] );
 122          } else {
 123              $this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'], $this->options['hostkey'] );
 124          }
 125  
 126          if ( ! $this->link ) {
 127              $this->errors->add(
 128                  'connect',
 129                  sprintf(
 130                      /* translators: %s: hostname:port */
 131                      __( 'Failed to connect to SSH2 Server %s' ),
 132                      $this->options['hostname'] . ':' . $this->options['port']
 133                  )
 134              );
 135              return false;
 136          }
 137  
 138          if ( ! $this->keys ) {
 139              if ( ! @ssh2_auth_password( $this->link, $this->options['username'], $this->options['password'] ) ) {
 140                  $this->errors->add(
 141                      'auth',
 142                      sprintf(
 143                          /* translators: %s: Username. */
 144                          __( 'Username/Password incorrect for %s' ),
 145                          $this->options['username']
 146                      )
 147                  );
 148                  return false;
 149              }
 150          } else {
 151              if ( ! @ssh2_auth_pubkey_file( $this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) {
 152                  $this->errors->add(
 153                      'auth',
 154                      sprintf(
 155                          /* translators: %s: Username. */
 156                          __( 'Public and Private keys incorrect for %s' ),
 157                          $this->options['username']
 158                      )
 159                  );
 160                  return false;
 161              }
 162          }
 163  
 164          $this->sftp_link = ssh2_sftp( $this->link );
 165          if ( ! $this->sftp_link ) {
 166              $this->errors->add(
 167                  'connect',
 168                  sprintf(
 169                      /* translators: %s: hostname:port */
 170                      __( 'Failed to initialize a SFTP subsystem session with the SSH2 Server %s' ),
 171                      $this->options['hostname'] . ':' . $this->options['port']
 172                  )
 173              );
 174              return false;
 175          }
 176  
 177          return true;
 178      }
 179  
 180      /**
 181       * Gets the ssh2.sftp PHP stream wrapper path to open for the given file.
 182       *
 183       * This method also works around a PHP bug where the root directory (/) cannot
 184       * be opened by PHP functions, causing a false failure. In order to work around
 185       * this, the path is converted to /./ which is semantically the same as /
 186       * See https://bugs.php.net/bug.php?id=64169 for more details.
 187       *
 188       * @since 4.4.0
 189       *
 190       * @param string $path The File/Directory path on the remote server to return
 191       * @return string The ssh2.sftp:// wrapped path to use.
 192       */
 193  	public function sftp_path( $path ) {
 194          if ( '/' === $path ) {
 195              $path = '/./';
 196          }
 197          return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' );
 198      }
 199  
 200      /**
 201       * @since 2.7.0
 202       *
 203       * @param string $command
 204       * @param bool $returnbool
 205       * @return bool|string True on success, false on failure. String if the command was executed, `$returnbool`
 206       *                     is false (default), and data from the resulting stream was retrieved.
 207       */
 208  	public function run_command( $command, $returnbool = false ) {
 209          if ( ! $this->link ) {
 210              return false;
 211          }
 212  
 213          $stream = ssh2_exec( $this->link, $command );
 214          if ( ! $stream ) {
 215              $this->errors->add(
 216                  'command',
 217                  sprintf(
 218                      /* translators: %s: Command. */
 219                      __( 'Unable to perform command: %s' ),
 220                      $command
 221                  )
 222              );
 223          } else {
 224              stream_set_blocking( $stream, true );
 225              stream_set_timeout( $stream, FS_TIMEOUT );
 226              $data = stream_get_contents( $stream );
 227              fclose( $stream );
 228  
 229              if ( $returnbool ) {
 230                  return ( false === $data ) ? false : '' !== trim( $data );
 231              } else {
 232                  return $data;
 233              }
 234          }
 235          return false;
 236      }
 237  
 238      /**
 239       * Reads entire file into a string.
 240       *
 241       * @since 2.7.0
 242       *
 243       * @param string $file Name of the file to read.
 244       * @return string|false Read data on success, false if no temporary file could be opened,
 245       *                      or if the file couldn't be retrieved.
 246       */
 247  	public function get_contents( $file ) {
 248          return file_get_contents( $this->sftp_path( $file ) );
 249      }
 250  
 251      /**
 252       * Reads entire file into an array.
 253       *
 254       * @since 2.7.0
 255       *
 256       * @param string $file Path to the file.
 257       * @return array|false File contents in an array on success, false on failure.
 258       */
 259  	public function get_contents_array( $file ) {
 260          return file( $this->sftp_path( $file ) );
 261      }
 262  
 263      /**
 264       * Writes a string to a file.
 265       *
 266       * @since 2.7.0
 267       *
 268       * @param string    $file     Remote path to the file where to write the data.
 269       * @param string    $contents The data to write.
 270       * @param int|false $mode     Optional. The file permissions as octal number, usually 0644.
 271       *                            Default false.
 272       * @return bool True on success, false on failure.
 273       */
 274  	public function put_contents( $file, $contents, $mode = false ) {
 275          $ret = file_put_contents( $this->sftp_path( $file ), $contents );
 276  
 277          if ( strlen( $contents ) !== $ret ) {
 278              return false;
 279          }
 280  
 281          $this->chmod( $file, $mode );
 282  
 283          return true;
 284      }
 285  
 286      /**
 287       * Gets the current working directory.
 288       *
 289       * @since 2.7.0
 290       *
 291       * @return string|false The current working directory on success, false on failure.
 292       */
 293  	public function cwd() {
 294          $cwd = ssh2_sftp_realpath( $this->sftp_link, '.' );
 295          if ( $cwd ) {
 296              $cwd = trailingslashit( trim( $cwd ) );
 297          }
 298          return $cwd;
 299      }
 300  
 301      /**
 302       * Changes current directory.
 303       *
 304       * @since 2.7.0
 305       *
 306       * @param string $dir The new current directory.
 307       * @return bool True on success, false on failure.
 308       */
 309  	public function chdir( $dir ) {
 310          return $this->run_command( 'cd ' . $dir, true );
 311      }
 312  
 313      /**
 314       * Changes the file group.
 315       *
 316       * @since 2.7.0
 317       *
 318       * @param string     $file      Path to the file.
 319       * @param string|int $group     A group name or number.
 320       * @param bool       $recursive Optional. If set to true, changes file group recursively.
 321       *                              Default false.
 322       * @return bool True on success, false on failure.
 323       */
 324  	public function chgrp( $file, $group, $recursive = false ) {
 325          if ( ! $this->exists( $file ) ) {
 326              return false;
 327          }
 328          if ( ! $recursive || ! $this->is_dir( $file ) ) {
 329              return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
 330          }
 331          return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
 332      }
 333  
 334      /**
 335       * Changes filesystem permissions.
 336       *
 337       * @since 2.7.0
 338       *
 339       * @param string    $file      Path to the file.
 340       * @param int|false $mode      Optional. The permissions as octal number, usually 0644 for files,
 341       *                             0755 for directories. Default false.
 342       * @param bool      $recursive Optional. If set to true, changes file permissions recursively.
 343       *                             Default false.
 344       * @return bool True on success, false on failure.
 345       */
 346  	public function chmod( $file, $mode = false, $recursive = false ) {
 347          if ( ! $this->exists( $file ) ) {
 348              return false;
 349          }
 350  
 351          if ( ! $mode ) {
 352              if ( $this->is_file( $file ) ) {
 353                  $mode = FS_CHMOD_FILE;
 354              } elseif ( $this->is_dir( $file ) ) {
 355                  $mode = FS_CHMOD_DIR;
 356              } else {
 357                  return false;
 358              }
 359          }
 360  
 361          if ( ! $recursive || ! $this->is_dir( $file ) ) {
 362              return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true );
 363          }
 364          return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true );
 365      }
 366  
 367      /**
 368       * Changes the owner of a file or directory.
 369       *
 370       * @since 2.7.0
 371       *
 372       * @param string     $file      Path to the file or directory.
 373       * @param string|int $owner     A user name or number.
 374       * @param bool       $recursive Optional. If set to true, changes file owner recursively.
 375       *                              Default false.
 376       * @return bool True on success, false on failure.
 377       */
 378  	public function chown( $file, $owner, $recursive = false ) {
 379          if ( ! $this->exists( $file ) ) {
 380              return false;
 381          }
 382          if ( ! $recursive || ! $this->is_dir( $file ) ) {
 383              return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
 384          }
 385          return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
 386      }
 387  
 388      /**
 389       * Gets the file owner.
 390       *
 391       * @since 2.7.0
 392       *
 393       * @param string $file Path to the file.
 394       * @return string|false Username of the owner on success, false on failure.
 395       */
 396  	public function owner( $file ) {
 397          $owneruid = @fileowner( $this->sftp_path( $file ) );
 398          if ( ! $owneruid ) {
 399              return false;
 400          }
 401          if ( ! function_exists( 'posix_getpwuid' ) ) {
 402              return $owneruid;
 403          }
 404          $ownerarray = posix_getpwuid( $owneruid );
 405          return $ownerarray['name'];
 406      }
 407  
 408      /**
 409       * Gets the permissions of the specified file or filepath in their octal format.
 410       *
 411       * @since 2.7.0
 412       *
 413       * @param string $file Path to the file.
 414       * @return string Mode of the file (the last 3 digits).
 415       */
 416  	public function getchmod( $file ) {
 417          return substr( decoct( @fileperms( $this->sftp_path( $file ) ) ), -3 );
 418      }
 419  
 420      /**
 421       * Gets the file's group.
 422       *
 423       * @since 2.7.0
 424       *
 425       * @param string $file Path to the file.
 426       * @return string|false The group on success, false on failure.
 427       */
 428  	public function group( $file ) {
 429          $gid = @filegroup( $this->sftp_path( $file ) );
 430          if ( ! $gid ) {
 431              return false;
 432          }
 433          if ( ! function_exists( 'posix_getgrgid' ) ) {
 434              return $gid;
 435          }
 436          $grouparray = posix_getgrgid( $gid );
 437          return $grouparray['name'];
 438      }
 439  
 440      /**
 441       * Copies a file.
 442       *
 443       * @since 2.7.0
 444       *
 445       * @param string    $source      Path to the source file.
 446       * @param string    $destination Path to the destination file.
 447       * @param bool      $overwrite   Optional. Whether to overwrite the destination file if it exists.
 448       *                               Default false.
 449       * @param int|false $mode        Optional. The permissions as octal number, usually 0644 for files,
 450       *                               0755 for dirs. Default false.
 451       * @return bool True on success, false on failure.
 452       */
 453  	public function copy( $source, $destination, $overwrite = false, $mode = false ) {
 454          if ( ! $overwrite && $this->exists( $destination ) ) {
 455              return false;
 456          }
 457          $content = $this->get_contents( $source );
 458          if ( false === $content ) {
 459              return false;
 460          }
 461          return $this->put_contents( $destination, $content, $mode );
 462      }
 463  
 464      /**
 465       * Moves a file.
 466       *
 467       * @since 2.7.0
 468       *
 469       * @param string $source      Path to the source file.
 470       * @param string $destination Path to the destination file.
 471       * @param bool   $overwrite   Optional. Whether to overwrite the destination file if it exists.
 472       *                            Default false.
 473       * @return bool True on success, false on failure.
 474       */
 475  	public function move( $source, $destination, $overwrite = false ) {
 476          if ( $this->exists( $destination ) ) {
 477              if ( $overwrite ) {
 478                  // We need to remove the destination file before we can rename the source.
 479                  $this->delete( $destination, false, 'f' );
 480              } else {
 481                  // If we're not overwriting, the rename will fail, so return early.
 482                  return false;
 483              }
 484          }
 485  
 486          return ssh2_sftp_rename( $this->sftp_link, $source, $destination );
 487      }
 488  
 489      /**
 490       * Deletes a file or directory.
 491       *
 492       * @since 2.7.0
 493       *
 494       * @param string       $file      Path to the file or directory.
 495       * @param bool         $recursive Optional. If set to true, deletes files and folders recursively.
 496       *                                Default false.
 497       * @param string|false $type      Type of resource. 'f' for file, 'd' for directory.
 498       *                                Default false.
 499       * @return bool True on success, false on failure.
 500       */
 501  	public function delete( $file, $recursive = false, $type = false ) {
 502          if ( 'f' === $type || $this->is_file( $file ) ) {
 503              return ssh2_sftp_unlink( $this->sftp_link, $file );
 504          }
 505          if ( ! $recursive ) {
 506              return ssh2_sftp_rmdir( $this->sftp_link, $file );
 507          }
 508          $filelist = $this->dirlist( $file );
 509          if ( is_array( $filelist ) ) {
 510              foreach ( $filelist as $filename => $fileinfo ) {
 511                  $this->delete( $file . '/' . $filename, $recursive, $fileinfo['type'] );
 512              }
 513          }
 514          return ssh2_sftp_rmdir( $this->sftp_link, $file );
 515      }
 516  
 517      /**
 518       * Checks if a file or directory exists.
 519       *
 520       * @since 2.7.0
 521       *
 522       * @param string $file Path to file or directory.
 523       * @return bool Whether $file exists or not.
 524       */
 525  	public function exists( $file ) {
 526          return file_exists( $this->sftp_path( $file ) );
 527      }
 528  
 529      /**
 530       * Checks if resource is a file.
 531       *
 532       * @since 2.7.0
 533       *
 534       * @param string $file File path.
 535       * @return bool Whether $file is a file.
 536       */
 537  	public function is_file( $file ) {
 538          return is_file( $this->sftp_path( $file ) );
 539      }
 540  
 541      /**
 542       * Checks if resource is a directory.
 543       *
 544       * @since 2.7.0
 545       *
 546       * @param string $path Directory path.
 547       * @return bool Whether $path is a directory.
 548       */
 549  	public function is_dir( $path ) {
 550          return is_dir( $this->sftp_path( $path ) );
 551      }
 552  
 553      /**
 554       * Checks if a file is readable.
 555       *
 556       * @since 2.7.0
 557       *
 558       * @param string $file Path to file.
 559       * @return bool Whether $file is readable.
 560       */
 561  	public function is_readable( $file ) {
 562          return is_readable( $this->sftp_path( $file ) );
 563      }
 564  
 565      /**
 566       * Checks if a file or directory is writable.
 567       *
 568       * @since 2.7.0
 569       *
 570       * @param string $file Path to file or directory.
 571       * @return bool Whether $file is writable.
 572       */
 573  	public function is_writable( $file ) {
 574          // PHP will base its writable checks on system_user === file_owner, not ssh_user === file_owner.
 575          return true;
 576      }
 577  
 578      /**
 579       * Gets the file's last access time.
 580       *
 581       * @since 2.7.0
 582       *
 583       * @param string $file Path to file.
 584       * @return int|false Unix timestamp representing last access time, false on failure.
 585       */
 586  	public function atime( $file ) {
 587          return fileatime( $this->sftp_path( $file ) );
 588      }
 589  
 590      /**
 591       * Gets the file modification time.
 592       *
 593       * @since 2.7.0
 594       *
 595       * @param string $file Path to file.
 596       * @return int|false Unix timestamp representing modification time, false on failure.
 597       */
 598  	public function mtime( $file ) {
 599          return filemtime( $this->sftp_path( $file ) );
 600      }
 601  
 602      /**
 603       * Gets the file size (in bytes).
 604       *
 605       * @since 2.7.0
 606       *
 607       * @param string $file Path to file.
 608       * @return int|false Size of the file in bytes on success, false on failure.
 609       */
 610  	public function size( $file ) {
 611          return filesize( $this->sftp_path( $file ) );
 612      }
 613  
 614      /**
 615       * Sets the access and modification times of a file.
 616       *
 617       * Note: Not implemented.
 618       *
 619       * @since 2.7.0
 620       *
 621       * @param string $file  Path to file.
 622       * @param int    $time  Optional. Modified time to set for file.
 623       *                      Default 0.
 624       * @param int    $atime Optional. Access time to set for file.
 625       *                      Default 0.
 626       */
 627  	public function touch( $file, $time = 0, $atime = 0 ) {
 628          // Not implemented.
 629      }
 630  
 631      /**
 632       * Creates a directory.
 633       *
 634       * @since 2.7.0
 635       *
 636       * @param string     $path  Path for new directory.
 637       * @param int|false  $chmod Optional. The permissions as octal number (or false to skip chmod).
 638       *                          Default false.
 639       * @param string|int $chown Optional. A user name or number (or false to skip chown).
 640       *                          Default false.
 641       * @param string|int $chgrp Optional. A group name or number (or false to skip chgrp).
 642       *                          Default false.
 643       * @return bool True on success, false on failure.
 644       */
 645  	public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
 646          $path = untrailingslashit( $path );
 647          if ( empty( $path ) ) {
 648              return false;
 649          }
 650  
 651          if ( ! $chmod ) {
 652              $chmod = FS_CHMOD_DIR;
 653          }
 654          if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) {
 655              return false;
 656          }
 657          if ( $chown ) {
 658              $this->chown( $path, $chown );
 659          }
 660          if ( $chgrp ) {
 661              $this->chgrp( $path, $chgrp );
 662          }
 663          return true;
 664      }
 665  
 666      /**
 667       * Deletes a directory.
 668       *
 669       * @since 2.7.0
 670       *
 671       * @param string $path      Path to directory.
 672       * @param bool   $recursive Optional. Whether to recursively remove files/directories.
 673       *                          Default false.
 674       * @return bool True on success, false on failure.
 675       */
 676  	public function rmdir( $path, $recursive = false ) {
 677          return $this->delete( $path, $recursive );
 678      }
 679  
 680      /**
 681       * Gets details for files in a directory or a specific file.
 682       *
 683       * @since 2.7.0
 684       *
 685       * @param string $path           Path to directory or file.
 686       * @param bool   $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
 687       *                               Default true.
 688       * @param bool   $recursive      Optional. Whether to recursively include file details in nested directories.
 689       *                               Default false.
 690       * @return array|false {
 691       *     Array of files. False if unable to list directory contents.
 692       *
 693       *     @type string $name        Name of the file or directory.
 694       *     @type string $perms       *nix representation of permissions.
 695       *     @type int    $permsn      Octal representation of permissions.
 696       *     @type string $owner       Owner name or ID.
 697       *     @type int    $size        Size of file in bytes.
 698       *     @type int    $lastmodunix Last modified unix timestamp.
 699       *     @type mixed  $lastmod     Last modified month (3 letter) and day (without leading 0).
 700       *     @type int    $time        Last modified time.
 701       *     @type string $type        Type of resource. 'f' for file, 'd' for directory.
 702       *     @type mixed  $files       If a directory and $recursive is true, contains another array of files.
 703       * }
 704       */
 705  	public function dirlist( $path, $include_hidden = true, $recursive = false ) {
 706          if ( $this->is_file( $path ) ) {
 707              $limit_file = basename( $path );
 708              $path       = dirname( $path );
 709          } else {
 710              $limit_file = false;
 711          }
 712  
 713          if ( ! $this->is_dir( $path ) || ! $this->is_readable( $path ) ) {
 714              return false;
 715          }
 716  
 717          $ret = array();
 718          $dir = dir( $this->sftp_path( $path ) );
 719  
 720          if ( ! $dir ) {
 721              return false;
 722          }
 723  
 724          while ( false !== ( $entry = $dir->read() ) ) {
 725              $struc         = array();
 726              $struc['name'] = $entry;
 727  
 728              if ( '.' === $struc['name'] || '..' === $struc['name'] ) {
 729                  continue; // Do not care about these folders.
 730              }
 731  
 732              if ( ! $include_hidden && '.' === $struc['name'][0] ) {
 733                  continue;
 734              }
 735  
 736              if ( $limit_file && $struc['name'] != $limit_file ) {
 737                  continue;
 738              }
 739  
 740              $struc['perms']       = $this->gethchmod( $path . '/' . $entry );
 741              $struc['permsn']      = $this->getnumchmodfromh( $struc['perms'] );
 742              $struc['number']      = false;
 743              $struc['owner']       = $this->owner( $path . '/' . $entry );
 744              $struc['group']       = $this->group( $path . '/' . $entry );
 745              $struc['size']        = $this->size( $path . '/' . $entry );
 746              $struc['lastmodunix'] = $this->mtime( $path . '/' . $entry );
 747              $struc['lastmod']     = gmdate( 'M j', $struc['lastmodunix'] );
 748              $struc['time']        = gmdate( 'h:i:s', $struc['lastmodunix'] );
 749              $struc['type']        = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f';
 750  
 751              if ( 'd' === $struc['type'] ) {
 752                  if ( $recursive ) {
 753                      $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
 754                  } else {
 755                      $struc['files'] = array();
 756                  }
 757              }
 758  
 759              $ret[ $struc['name'] ] = $struc;
 760          }
 761          $dir->close();
 762          unset( $dir );
 763          return $ret;
 764      }
 765  }


Generated: Fri May 29 01:00:08 2020 Cross-referenced by PHPXref 0.7.1