102
* {@internal Missing Short Description}}
106
* @param string $folder Optional. Full path to folder
107
* @param int $levels Optional. Levels of folders to follow, Default: 100 (PHP Loop limit).
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.
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
110
111
function list_files( $folder = '', $levels = 100 ) {
111
112
if( empty($folder) )
138
* {@internal Missing Short Description}}
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/
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.
146
* @return string Writable temporary directory
144
148
function get_temp_dir() {
145
149
if ( defined('WP_TEMP_DIR') )
159
* {@internal Missing Short Description}}
163
* @param unknown_type $filename
164
* @param unknown_type $dir
163
* Returns a filename of a Temporary unique file.
164
* Please note that the calling function must unlink() this itself.
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.
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
167
175
function wp_tempnam($filename = '', $dir = ''){
168
176
if ( empty($dir) )
198
205
wp_die( __('Sorry, can’t edit files with “..” in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.' ));
201
wp_die( __('Sorry, can’t call files with their real path.' ));
208
// wp_die( __('Sorry, can’t call files with their real path.' ));
204
211
wp_die( __('Sorry, that file cannot be edited.' ));
232
$file = apply_filters( 'wp_handle_upload_prefilter', $file );
225
234
// You may define your own function and pass the name in $overrides['upload_error_handler']
226
235
$upload_error_handler = 'wp_handle_upload_error';
237
// You may have had one or more 'wp_handle_upload_prefilter' functions error out the file. Handle that gracefully.
238
if ( isset( $file['error'] ) && !is_numeric( $file['error'] ) && $file['error'] )
239
return $upload_error_handler( $file, $file['error'] );
228
241
// You may define your own function and pass the name in $overrides['unique_filename_callback']
229
242
$unique_filename_callback = null;
265
278
// A non-empty file will pass this test.
266
279
if ( $test_size && !($file['size'] > 0 ) )
267
return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini.' ));
280
return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' ));
269
282
// A properly uploaded file will pass this test. There should be no reason to override this one.
270
283
if (! @ is_uploaded_file( $file['tmp_name'] ) )
427
* Downloads a url to a local file using the Snoopy HTTP Class.
440
* Downloads a url to a local temporary file using the WordPress HTTP Class.
441
* Please note, That the calling function must unlink() the file.
430
* @todo Transition over to using the new HTTP Request API (jacob).
432
445
* @param string $url the URL of the file to download
433
446
* @return mixed WP_Error on failure, string Filename on success.
469
* {@internal Missing Short Description}}
473
* @param unknown_type $file
474
* @param unknown_type $to
482
* Unzip's a specified ZIP file to a location on the Filesystem via the WordPress Filesystem Abstraction.
483
* Assumes that WP_Filesystem() has already been called and set up.
485
* Attempts to increase the PHP Memory limit to 256M before uncompressing,
486
* However, The most memory required shouldn't be much larger than the Archive itself.
490
* @param string $file Full path and filename of zip archive
491
* @param string $to Full path on the filesystem to extract archive to
492
* @return mixed WP_Error on failure, True on success
477
494
function unzip_file($file, $to) {
478
495
global $wp_filesystem;
480
497
if ( ! $wp_filesystem || !is_object($wp_filesystem) )
481
498
return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
483
// Unzip uses a lot of memory
500
// Unzip uses a lot of memory, but not this much hopefully
484
501
@ini_set('memory_limit', '256M');
486
503
$fs =& $wp_filesystem;
541
* {@internal Missing Short Description}}
545
* @param unknown_type $from
546
* @param unknown_type $to
558
* Copies a directory from one location to another via the WordPress Filesystem Abstraction.
559
* Assumes that WP_Filesystem() has already been called and setup.
563
* @param string $from source directory
564
* @param string $to destination directory
565
* @return mixed WP_Error on failure, True on success.
549
567
function copy_dir($from, $to) {
550
568
global $wp_filesystem;
579
* {@internal Missing Short Description}}
583
* @param unknown_type $args
598
* Initialises and connects the WordPress Filesystem Abstraction classes.
599
* This function will include the chosen transport and attempt connecting.
601
* Plugins may add extra transports, And force WordPress to use them by returning the filename via the 'filesystem_method_file' filter.
605
* @param array $args (optional) Connection args, These are passed directly to the WP_Filesystem_*() classes.
606
* @param string $context (optional) Context for get_filesystem_method(), See function declaration for more information.
607
* @return boolean false on failure, true on success
586
609
function WP_Filesystem( $args = false, $context = false ) {
587
610
global $wp_filesystem;
597
620
$abstraction_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
598
621
if( ! file_exists($abstraction_file) )
601
624
require_once($abstraction_file);
603
626
$method = "WP_Filesystem_$method";
605
628
$wp_filesystem = new $method($args);
630
//Define the timeouts for the connections. Only available after the construct is called to allow for per-transport overriding of the default.
631
if ( ! defined('FS_CONNECT_TIMEOUT') )
632
define('FS_CONNECT_TIMEOUT', 30);
633
if ( ! defined('FS_TIMEOUT') )
634
define('FS_TIMEOUT', 30);
607
636
if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
623
* {@internal Missing Short Description}}
627
* @param unknown_type $args
652
* Determines which Filesystem Method to use.
653
* The priority of the Transports are: Direct, SSH2, FTP PHP Extension, FTP Sockets (Via Sockets class, or fsoxkopen())
655
* Note that the return value of this function can be overridden in 2 ways
656
* - By defining FS_METHOD in your <code>wp-config.php</code> file
657
* - By using the filesystem_method filter
658
* Valid values for these are: 'direct', 'ssh', 'ftpext' or 'ftpsockets'
659
* Plugins may also define a custom transport handler, See the WP_Filesystem function for more information.
663
* @param array $args Connection details.
628
664
* @param string $context Full path to the directory that is tested for being writable.
665
* @return string The transport to use, see description for valid return values.
631
667
function get_filesystem_method($args = array(), $context = false) {
632
668
$method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
636
672
$context = WP_CONTENT_DIR;
637
673
$context = trailingslashit($context);
638
$temp_file_name = $context . '.write-test-' . time();
674
$temp_file_name = $context . 'temp-write-test-' . time();
639
675
$temp_handle = @fopen($temp_file_name, 'w');
640
676
if ( $temp_handle ) {
641
if ( getmyuid() == fileowner($temp_file_name) )
677
if ( getmyuid() == @fileowner($temp_file_name) )
642
678
$method = 'direct';
643
679
@fclose($temp_handle);
644
unlink($temp_file_name);
680
@unlink($temp_file_name);
655
* {@internal Missing Short Description}}
659
* @param unknown_type $form_post
660
* @param unknown_type $type
661
* @param unknown_type $error
691
* Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.
692
* All chosen/entered details are saved, Excluding the Password.
694
* Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467) to specify an alternate FTP/SSH port.
696
* Plugins may override this form by returning true|false via the <code>request_filesystem_credentials</code> filter.
700
* @param string $form_post the URL to post the form to
701
* @param string $type the chosen Filesystem method in use
702
* @param boolean $error if the current request has failed to connect
703
* @param string $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method()
704
* @return boolean False on failure. True on success.
664
706
function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false) {
665
707
$req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error, $context);
675
717
$credentials = get_option('ftp_credentials', array( 'hostname' => '', 'username' => ''));
677
719
// If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
678
$credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? $_POST['hostname'] : $credentials['hostname']);
679
$credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? $_POST['username'] : $credentials['username']);
680
$credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? $_POST['password'] : '');
720
$credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? stripslashes($_POST['hostname']) : $credentials['hostname']);
721
$credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? stripslashes($_POST['username']) : $credentials['username']);
722
$credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? stripslashes($_POST['password']) : '');
682
724
// Check to see if we are setting the public/private keys for ssh
683
$credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? $_POST['public_key'] : '');
684
$credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? $_POST['private_key'] : '');
725
$credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? stripslashes($_POST['public_key']) : '');
726
$credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? stripslashes($_POST['private_key']) : '');
686
728
//sanitize the hostname, Some people might pass in odd-data:
687
729
$credentials['hostname'] = preg_replace('|\w+://|', '', $credentials['hostname']); //Strip any schemes off
689
if ( strpos($credentials['hostname'], ':') )
731
if ( strpos($credentials['hostname'], ':') ) {
690
732
list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2);
733
if ( ! is_numeric($credentials['port']) )
734
unset($credentials['port']);
692
736
unset($credentials['port']);
694
if ( defined('FTP_SSH') || (defined('FS_METHOD') && 'ssh' == FS_METHOD) )
739
if ( (defined('FTP_SSH') && FTP_SSH) || (defined('FS_METHOD') && 'ssh' == FS_METHOD) )
695
740
$credentials['connection_type'] = 'ssh';
696
else if ( defined('FTP_SSL') && 'ftpext' == $type ) //Only the FTP Extension understands SSL
741
else if ( (defined('FTP_SSL') && FTP_SSL) && 'ftpext' == $type ) //Only the FTP Extension understands SSL
697
742
$credentials['connection_type'] = 'ftps';
698
743
else if ( !empty($_POST['connection_type']) )
699
$credentials['connection_type'] = $_POST['connection_type'];
744
$credentials['connection_type'] = stripslashes($_POST['connection_type']);
700
745
else if ( !isset($credentials['connection_type']) ) //All else fails (And its not defaulted to something else saved), Default to FTP
701
746
$credentials['connection_type'] = 'ftp';
725
770
$error_string = $error->get_error_message();
726
771
echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
775
if ( extension_loaded('ftp') || extension_loaded('sockets') || function_exists('fsockopen') )
776
$types[ 'ftp' ] = __('FTP');
777
if ( extension_loaded('ftp') ) //Only this supports FTPS
778
$types[ 'ftps' ] = __('FTPS (SSL)');
779
if ( extension_loaded('ssh2') && function_exists('stream_get_contents') )
780
$types[ 'ssh' ] = __('SSH2');
782
$types = apply_filters('fs_ftp_connection_types', $types, $credentials, $type, $error, $context);
729
785
<script type="text/javascript">
761
817
<td><input name="password" type="password" id="password" value="<?php if ( defined('FTP_PASS') ) echo '*****'; ?>"<?php if ( defined('FTP_PASS') ) echo ' disabled="disabled"' ?> size="40" /></td>
764
<?php if ( extension_loaded('ssh2') && function_exists('stream_get_contents') ) : ?>
820
<?php if ( isset($types['ssh']) ) : ?>
765
821
<tr id="ssh_keys" valign="top" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>">
766
822
<th scope="row"><?php _e('Authentication Keys') ?>
767
823
<div class="key-labels textright">
777
833
<th scope="row"><?php _e('Connection Type') ?></th>
779
835
<fieldset><legend class="screen-reader-text"><span><?php _e('Connection Type') ?></span></legend>
780
<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>
781
<?php if ( 'ftpext' == $type ) : ?>
782
<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>
784
<?php if ( extension_loaded('ssh2') && function_exists('stream_get_contents') ) : ?>
785
<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>
838
$disabled = (defined('FTP_SSL') && FTP_SSL) || (defined('FTP_SSH') && FTP_SSH) ? ' disabled="disabled"' : '';
840
foreach ( $types as $name => $text ) : ?>
841
<label for="<?php echo esc_attr($name) ?>">
842
<input type="radio" name="connection_type" id="<?php echo esc_attr($name) ?>" value="<?php echo esc_attr($name) ?>" <?php checked($name, $connection_type); echo $disabled; ?>/>
792
851
<?php if ( isset( $_POST['version'] ) ) : ?>
793
<input type="hidden" name="version" value="<?php echo esc_attr($_POST['version']) ?>" />
852
<input type="hidden" name="version" value="<?php echo esc_attr(stripslashes($_POST['version'])) ?>" />
795
854
<?php if ( isset( $_POST['locale'] ) ) : ?>
796
<input type="hidden" name="locale" value="<?php echo esc_attr($_POST['locale']) ?>" />
855
<input type="hidden" name="locale" value="<?php echo esc_attr(stripslashes($_POST['locale'])) ?>" />
798
857
<p class="submit">
799
858
<input id="upgrade" name="upgrade" type="submit" class="button" value="<?php esc_attr_e('Proceed'); ?>" />