Make WordPress Core

Changeset 12151


Ignore:
Timestamp:
11/05/2009 11:03:48 PM (15 years ago)
Author:
azaozz
Message:

Add phpdoc and extra filter to file.php, props dd32, fixes #11002

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/file.php

    r12142 r12151  
    100100
    101101/**
    102  * {@internal Missing Short Description}}
    103  *
    104  * @since unknown
    105  *
    106  * @param string $folder Optional. Full path to folder
    107  * @param int $levels Optional. Levels of folders to follow, Default: 100 (PHP Loop limit).
    108  * @return bool|array
     102 * Returns a listing of all files in the specified folder and all subdirectories up to 100 levels deep.
     103 * The depth of the recursiveness can be controlled by the $levels param.
     104 *
     105 * @since 2.6.0
     106 *
     107 * @param string $folder Full path to folder
     108 * @param int $levels (optional) Levels of folders to follow, Default: 100 (PHP Loop limit).
     109 * @return bool|array False on failure, Else array of files
    109110 */
    110111function list_files( $folder = '', $levels = 100 ) {
     
    136137
    137138/**
    138  * {@internal Missing Short Description}}
    139  *
    140  * @since unknown
    141  *
    142  * @return unknown
     139 * Determines a writable directory for temporary files.
     140 * Function's preference is to WP_CONTENT_DIR followed by the return value of <code>sys_get_temp_dir()</code>, before finally defaulting to /tmp/
     141 *
     142 * In the event that this function does not find a writable location, It may be overridden by the <code>WP_TEMP_DIR</code> constant in your <code>wp-config.php</code> file.
     143 *
     144 * @since 2.5.0
     145 *
     146 * @return string Writable temporary directory
    143147 */
    144148function get_temp_dir() {
     
    157161
    158162/**
    159  * {@internal Missing Short Description}}
    160  *
    161  * @since unknown
    162  *
    163  * @param unknown_type $filename
    164  * @param unknown_type $dir
    165  * @return unknown
     163 * Returns a filename of a Temporary unique file.
     164 * Please note that the calling function must unlink() this itself.
     165 *
     166 * The filename is based off the passed parameter or defaults to the current unix timestamp,
     167 * while the directory can either be passed as well, or by leaving  it blank, default to a writable temporary directory.
     168 *
     169 * @since 2.6.0
     170 *
     171 * @param string $filename (optional) Filename to base the Unique file off
     172 * @param string $dir (optional) Directory to store the file in
     173 * @return string a writable filename
    166174 */
    167175function wp_tempnam($filename = '', $dir = ''){
     
    432440
    433441/**
    434  * Downloads a url to a local file using the Snoopy HTTP Class.
    435  *
    436  * @since unknown
    437  * @todo Transition over to using the new HTTP Request API (jacob).
     442 * Downloads a url to a local temporary file using the WordPress HTTP Class.
     443 * Please note, That the calling function must unlink() the  file.
     444 *
     445 * @since 2.5.0
    438446 *
    439447 * @param string $url the URL of the file to download
     
    474482
    475483/**
    476  * {@internal Missing Short Description}}
    477  *
    478  * @since unknown
    479  *
    480  * @param unknown_type $file
    481  * @param unknown_type $to
    482  * @return unknown
     484 * Unzip's a specified ZIP file to a location on the Filesystem via the WordPress Filesystem Abstraction.
     485 * Assumes that WP_Filesystem() has already been called and set up.
     486 *
     487 * Attempts to increase the PHP Memory limit to 256M before uncompressing,
     488 * However, The most memory required shouldn't be much larger than the Archive itself.
     489 *
     490 * @since 2.5.0
     491 *
     492 * @param string $file Full path and filename of zip archive
     493 * @param string $to Full path on the filesystem to extract archive to
     494 * @return mixed WP_Error on failure, True on success
    483495 */
    484496function unzip_file($file, $to) {
     
    488500        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    489501
    490     // Unzip uses a lot of memory
     502    // Unzip uses a lot of memory, but not this much hopefully
    491503    @ini_set('memory_limit', '256M');
    492504
     
    546558
    547559/**
    548  * {@internal Missing Short Description}}
    549  *
    550  * @since unknown
    551  *
    552  * @param unknown_type $from
    553  * @param unknown_type $to
    554  * @return unknown
     560 * Copies a directory from one location to another via the WordPress Filesystem Abstraction.
     561 * Assumes that WP_Filesystem() has already been called and setup.
     562 *
     563 * @since 2.5.0
     564 *
     565 * @param string $from source directory
     566 * @param string $to destination directory
     567 * @return mixed WP_Error on failure, True on success.
    555568 */
    556569function copy_dir($from, $to) {
     
    581594        }
    582595    }
    583 }
    584 
    585 /**
    586  * {@internal Missing Short Description}}
    587  *
    588  * @since unknown
    589  *
    590  * @param unknown_type $args
    591  * @return unknown
     596    return true;
     597}
     598
     599/**
     600 * Initialises and connects the WordPress Filesystem Abstraction classes.
     601 * This function will include the chosen transport and attempt connecting.
     602 *
     603 * Plugins may add extra transports, And force WordPress to use them by returning the filename via the 'filesystem_method_file' filter.
     604 *
     605 * @since 2.5.0
     606 *
     607 * @param array $args (optional) Connection args, These are passed directly to the WP_Filesystem_*() classes.
     608 * @param string $context (optional) Context for get_filesystem_method(), See function declaration for more information.
     609 * @return boolean false on failure, true on success
    592610 */
    593611function WP_Filesystem( $args = false, $context = false ) {
     
    634652
    635653/**
    636  * {@internal Missing Short Description}}
    637  *
    638  * @since unknown
    639  *
    640  * @param unknown_type $args
     654 * Determines which Filesystem Method to use.
     655 * The priority of the Transports are: Direct, SSH2, FTP PHP Extension, FTP Sockets (Via Sockets class, or fsoxkopen())
     656 *
     657 * Note that the return value of this function can be overridden in 2 ways
     658 *  - By defining FS_METHOD in your <code>wp-config.php</code> file
     659 *  - By using the filesystem_method filter
     660 * Valid values for these are: 'direct', 'ssh', 'ftpext' or 'ftpsockets'
     661 * Plugins may also define a custom transport handler, See the WP_Filesystem function for more information.
     662 *
     663 * @since 2.5.0
     664 *
     665 * @param array $args Connection details.
    641666 * @param string $context Full path to the directory that is tested for being writable.
    642  * @return unknown
     667 * @return string The transport to use, see description for valid return values.
    643668 */
    644669function get_filesystem_method($args = array(), $context = false) {
     
    666691
    667692/**
    668  * {@internal Missing Short Description}}
    669  *
    670  * @since unknown
    671  *
    672  * @param unknown_type $form_post
    673  * @param unknown_type $type
    674  * @param unknown_type $error
    675  * @return unknown
     693 * Displays a form to the user to request for their FTP/SSH details in order to  connect to the filesystem.
     694 * All chosen/entered details are saved, Excluding the Password.
     695 *
     696 * Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467) to specify an alternate FTP/SSH port.
     697 *
     698 * Plugins may override this form by returning true|false via the <code>request_filesystem_credentials</code> filter.
     699 *
     700 * @since 2.5.0
     701 *
     702 * @param string $form_post the URL to post the form to
     703 * @param string $type the chosen Filesystem method in use
     704 * @param boolean $error if the current request has failed to connect
     705 * @param string $context The directory which is needed access to, The write-test will be performed on  this directory by get_filesystem_method()
     706 * @return boolean False on failure. True on success.
    676707 */
    677708function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false) {
     
    700731    $credentials['hostname'] = preg_replace('|\w+://|', '', $credentials['hostname']); //Strip any schemes off
    701732
    702     if ( strpos($credentials['hostname'], ':') )
     733    if ( strpos($credentials['hostname'], ':') ) {
    703734        list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2);
    704     else
     735        if ( ! is_numeric($credentials['port']) )
     736            unset($credentials['port']);
     737    } else {
    705738        unset($credentials['port']);
     739    }
    706740
    707741    if ( defined('FTP_SSH') || (defined('FS_METHOD') && 'ssh' == FS_METHOD) )
     
    739773        echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
    740774    }
     775
     776    $types = array();
     777    if ( extension_loaded('ftp') || extension_loaded('sockets') || function_exists('fsockopen') )
     778        $types[ 'ftp' ] = __('FTP');
     779    if ( extension_loaded('ftp') ) //Only this supports FTPS
     780        $types[ 'ftps' ] = __('FTPS (SSL)');
     781    if ( extension_loaded('ssh2') && function_exists('stream_get_contents') )
     782        $types[ 'ssh' ] = __('SSH2');
     783
     784    $types = apply_filters('fs_ftp_connection_types', $types, $credentials, $type, $error, $context);
     785
    741786?>
    742787<script type="text/javascript">
     
    775820</tr>
    776821
    777 <?php if ( extension_loaded('ssh2') && function_exists('stream_get_contents') ) : ?>
     822<?php if ( isset($types['ssh']) ) : ?>
    778823<tr id="ssh_keys" valign="top" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>">
    779824<th scope="row"><?php _e('Authentication Keys') ?>
     
    791836<td>
    792837<fieldset><legend class="screen-reader-text"><span><?php _e('Connection Type') ?></span></legend>
    793 <label><input id="ftp" name="connection_type"  type="radio" value="ftp" <?php checked('ftp', $connection_type); if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"'; ?>/> <?php _e('FTP') ?></label>
    794 <?php if ( 'ftpext' == $type ) : ?>
    795 <br /><label><input id="ftps" name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"';  ?>/> <?php _e('FTPS (SSL)') ?></label>
    796 <?php endif; ?>
    797 <?php if ( extension_loaded('ssh2') && function_exists('stream_get_contents') ) : ?>
    798 <br /><label><input id="ssh" name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type);  if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"'; ?>/> <?php _e('SSH') ?></label>
    799 <?php endif; ?>
     838<?php
     839
     840    $disabled = defined('FTP_SSL') || defined('FTP_SSH') ? '' : ' disabled="disabled"';
     841
     842    foreach ( $types as $name => $text ) : ?>
     843    <label for="<?php echo esc_atr($name) ?>">
     844        <input type="radio" name="connection_type" id="<?php echo esc_atr($name) ?>" value="<?php echo esc_atr($name) ?>" <?php checked($name, $connection_type); echo $disabled; ?>/>
     845        <?php echo $text ?>
     846    </label>
     847    <?php endforeach; ?>
    800848</fieldset>
    801849</td>
Note: See TracChangeset for help on using the changeset viewer.