~ubuntu-branches/debian/jessie/wordpress/jessie

« back to all changes in this revision

Viewing changes to wp-admin/includes/file.php

  • Committer: Package Import Robot
  • Author(s): Craig Small
  • Date: 2014-04-17 20:56:19 UTC
  • mfrom: (1.2.35)
  • Revision ID: package-import@ubuntu.com-20140417205619-nurbet6eho4yvwfv
Tags: 3.9+dfsg-1
* New upstream release
* 3.9 seems to handle different locations for plugins so the
  plugin directory handling patches have been cut back.

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
 
178
178
        switch ( $code ) {
179
179
                case 1 :
180
 
                        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.' ));
 
180
                        wp_die( __( 'Sorry, that file cannot be edited.' ) );
181
181
 
182
182
                //case 2 :
183
183
                //      wp_die( __('Sorry, can’t call files with their real path.' ));
184
184
 
185
185
                case 3 :
186
 
                        wp_die( __('Sorry, that file cannot be edited.' ));
 
186
                        wp_die( __( 'Sorry, that file cannot be edited.' ) );
187
187
        }
188
188
}
189
189
 
191
191
 * Handle PHP uploads in WordPress, sanitizing file names, checking extensions for mime type,
192
192
 * and moving the file to the appropriate directory within the uploads directory.
193
193
 *
194
 
 * @since 2.0
 
194
 * @since 2.0.0
195
195
 *
196
196
 * @uses wp_handle_upload_error
197
 
 * @uses apply_filters
198
197
 * @uses is_multisite
199
198
 * @uses wp_check_filetype_and_ext
200
199
 * @uses current_user_can
214
213
                }
215
214
        }
216
215
 
 
216
        /**
 
217
         * Filter data for the current file to upload.
 
218
         *
 
219
         * @since 2.9.0
 
220
         *
 
221
         * @param array $file An array of data for a single file.
 
222
         */
217
223
        $file = apply_filters( 'wp_handle_upload_prefilter', $file );
218
224
 
219
225
        // You may define your own function and pass the name in $overrides['upload_error_handler']
258
264
                return call_user_func($upload_error_handler, $file, __( 'Invalid form submission.' ));
259
265
 
260
266
        // A successful upload will pass this test. It makes no sense to override this one.
261
 
        if ( $file['error'] > 0 )
262
 
                return call_user_func($upload_error_handler, $file, $upload_error_strings[$file['error']] );
 
267
        if ( isset( $file['error'] ) && $file['error'] > 0 ) {
 
268
                return call_user_func( $upload_error_handler, $file, $upload_error_strings[ $file['error'] ] );
 
269
        }
263
270
 
264
271
        // A non-empty file will pass this test.
265
272
        if ( $test_size && !($file['size'] > 0 ) ) {
324
331
        if ( is_multisite() )
325
332
                delete_transient( 'dirsize_cache' );
326
333
 
 
334
        /**
 
335
         * Filter the data array for the uploaded file.
 
336
         *
 
337
         * @since 2.1.0
 
338
         *
 
339
         * @param array  $upload {
 
340
         *     Array of upload data.
 
341
         *
 
342
         *     @type string $file Filename of the newly-uploaded file.
 
343
         *     @type string $url  URL of the uploaded file.
 
344
         *     @type string $type File type.
 
345
         * }
 
346
         * @param string $context The type of upload action. Accepts 'upload' or 'sideload'.
 
347
         */
327
348
        return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload' );
328
349
}
329
350
 
335
356
 * @since 2.6.0
336
357
 *
337
358
 * @uses wp_handle_upload_error
338
 
 * @uses apply_filters
339
359
 * @uses wp_check_filetype_and_ext
340
360
 * @uses current_user_can
341
361
 * @uses wp_upload_dir
449
469
        // Compute the URL
450
470
        $url = $uploads['url'] . "/$filename";
451
471
 
 
472
        /** This filter is documented in wp-admin/includes/file.php */
452
473
        $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'sideload' );
453
474
 
454
475
        return $return;
498
519
}
499
520
 
500
521
/**
501
 
 * Calculates and compares the MD5 of a file to it's expected value.
 
522
 * Calculates and compares the MD5 of a file to its expected value.
502
523
 *
503
524
 * @since 3.7.0
504
525
 *
542
563
                return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
543
564
 
544
565
        // Unzip can use a lot of memory, but not this much hopefully
 
566
        /** This filter is documented in wp-admin/admin.php */
545
567
        @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
546
568
 
547
569
        $needed_dirs = array();
565
587
                }
566
588
        }
567
589
 
568
 
        if ( class_exists('ZipArchive') && apply_filters('unzip_file_use_ziparchive', true ) ) {
 
590
        /**
 
591
         * Filter whether to use ZipArchive to unzip archives.
 
592
         *
 
593
         * @since 3.0.0
 
594
         *
 
595
         * @param bool $ziparchive Whether to use ZipArchive. Default true.
 
596
         */
 
597
        if ( class_exists( 'ZipArchive' ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
569
598
                $result = _unzip_file_ziparchive($file, $to, $needed_dirs);
570
599
                if ( true === $result ) {
571
600
                        return $result;
842
871
                return false;
843
872
 
844
873
        if ( ! class_exists("WP_Filesystem_$method") ) {
845
 
                $abstraction_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
 
874
 
 
875
                /**
 
876
                 * Filter the path for a specific filesystem method class file.
 
877
                 *
 
878
                 * @since 2.6.0
 
879
                 *
 
880
                 * @see get_filesystem_method()
 
881
                 *
 
882
                 * @param string $path   Path to the specific filesystem method class file.
 
883
                 * @param string $method The filesystem method to use.
 
884
                 */
 
885
                $abstraction_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
 
886
 
846
887
                if ( ! file_exists($abstraction_file) )
847
888
                        return;
848
889
 
880
921
 * Note that the return value of this function can be overridden in 2 ways
881
922
 *  - By defining FS_METHOD in your <code>wp-config.php</code> file
882
923
 *  - By using the filesystem_method filter
883
 
 * Valid values for these are: 'direct', 'ssh', 'ftpext' or 'ftpsockets'
 
924
 * Valid values for these are: 'direct', 'ssh2', 'ftpext' or 'ftpsockets'
884
925
 * Plugins may also define a custom transport handler, See the WP_Filesystem function for more information.
885
926
 *
886
927
 * @since 2.5.0
890
931
 * @return string The transport to use, see description for valid return values.
891
932
 */
892
933
function get_filesystem_method($args = array(), $context = false) {
893
 
        $method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
 
934
        $method = defined('FS_METHOD') ? FS_METHOD : false; // Please ensure that this is either 'direct', 'ssh2', 'ftpext' or 'ftpsockets'
894
935
 
895
936
        if ( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
896
937
                if ( !$context )
914
955
        if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && function_exists('stream_get_contents') ) $method = 'ssh2';
915
956
        if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext';
916
957
        if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
917
 
        return apply_filters('filesystem_method', $method, $args);
 
958
 
 
959
        /**
 
960
         * Filter the filesystem method to use.
 
961
         *
 
962
         * @since 2.6.0
 
963
         *
 
964
         * @param string $method Filesystem method to return.
 
965
         * @param array  $args   An array of connection details for the method.
 
966
         */
 
967
        return apply_filters( 'filesystem_method', $method, $args );
918
968
}
919
969
 
920
970
/**
935
985
 * @return boolean False on failure. True on success.
936
986
 */
937
987
function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false, $extra_fields = null) {
 
988
 
 
989
        /**
 
990
         * Filter the filesystem credentials form output.
 
991
         *
 
992
         * Returning anything other than an empty string will effectively short-circuit
 
993
         * output of the filesystem credentials form, returning that value instead.
 
994
         *
 
995
         * @since 2.5.0
 
996
         *
 
997
         * @param mixed  $output       Form output to return instead. Default empty.
 
998
         * @param string $form_post    URL to POST the form to.
 
999
         * @param string $type         Chosen type of filesystem.
 
1000
         * @param bool   $error        Whether the current request has failed to connect.
 
1001
         *                             Default false.
 
1002
         * @param string $context      Full path to the directory that is tested for
 
1003
         *                             being writable.
 
1004
         * @param array  $extra_fields Extra POST fields.
 
1005
         */
938
1006
        $req_cred = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields );
939
1007
        if ( '' !== $req_cred )
940
1008
                return $req_cred;
970
1038
                unset($credentials['port']);
971
1039
        }
972
1040
 
973
 
        if ( (defined('FTP_SSH') && FTP_SSH) || (defined('FS_METHOD') && 'ssh' == FS_METHOD) )
 
1041
        if ( ( defined('FTP_SSH') && FTP_SSH ) || ( defined('FS_METHOD') && 'ssh2' == FS_METHOD ) )
974
1042
                $credentials['connection_type'] = 'ssh';
975
1043
        else if ( (defined('FTP_SSL') && FTP_SSL) && 'ftpext' == $type ) //Only the FTP Extension understands SSL
976
1044
                $credentials['connection_type'] = 'ftps';
1013
1081
        if ( extension_loaded('ssh2') && function_exists('stream_get_contents') )
1014
1082
                $types[ 'ssh' ] = __('SSH2');
1015
1083
 
1016
 
        $types = apply_filters('fs_ftp_connection_types', $types, $credentials, $type, $error, $context);
 
1084
        /**
 
1085
         * Filter the connection types to output to the filesystem credentials form.
 
1086
         *
 
1087
         * @since 2.9.0
 
1088
         *
 
1089
         * @param array  $types       Types of connections.
 
1090
         * @param array  $credentials Credentials to connect with.
 
1091
         * @param string $type        Chosen filesystem method.
 
1092
         * @param object $error       Error object.
 
1093
         * @param string $context     Full path to the directory that is tested
 
1094
         *                            for being writable.
 
1095
         */
 
1096
        $types = apply_filters( 'fs_ftp_connection_types', $types, $credentials, $type, $error, $context );
1017
1097
 
1018
1098
?>
1019
1099
<script type="text/javascript">
1052
1132
        _e('If you do not remember your credentials, you should contact your web host.');
1053
1133
?></p>
1054
1134
<table class="form-table">
1055
 
<tr valign="top">
 
1135
<tr>
1056
1136
<th scope="row"><label for="hostname"><?php _e('Hostname') ?></label></th>
1057
1137
<td><input name="hostname" type="text" id="hostname" value="<?php echo esc_attr($hostname); if ( !empty($port) ) echo ":$port"; ?>"<?php disabled( defined('FTP_HOST') ); ?> size="40" /></td>
1058
1138
</tr>
1059
1139
 
1060
 
<tr valign="top">
 
1140
<tr>
1061
1141
<th scope="row"><label for="username"><?php echo $label_user; ?></label></th>
1062
1142
<td><input name="username" type="text" id="username" value="<?php echo esc_attr($username) ?>"<?php disabled( defined('FTP_USER') ); ?> size="40" /></td>
1063
1143
</tr>
1064
1144
 
1065
 
<tr valign="top">
 
1145
<tr>
1066
1146
<th scope="row"><label for="password"><?php echo $label_pass; ?></label></th>
1067
1147
<td><div><input name="password" type="password" id="password" value="<?php if ( defined('FTP_PASS') ) echo '*****'; ?>"<?php disabled( defined('FTP_PASS') ); ?> size="40" /></div>
1068
1148
<div><em><?php if ( ! defined('FTP_PASS') ) _e( 'This password will not be stored on the server.' ); ?></em></div></td>
1069
1149
</tr>
1070
1150
 
1071
1151
<?php if ( isset($types['ssh']) ) : ?>
1072
 
<tr id="ssh_keys" valign="top" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>">
 
1152
<tr id="ssh_keys" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>">
1073
1153
<th scope="row"><?php _e('Authentication Keys') ?>
1074
1154
<div class="key-labels textright">
1075
1155
<label for="public_key"><?php _e('Public Key:') ?></label ><br />
1080
1160
</tr>
1081
1161
<?php endif; ?>
1082
1162
 
1083
 
<tr valign="top">
 
1163
<tr>
1084
1164
<th scope="row"><?php _e('Connection Type') ?></th>
1085
1165
<td>
1086
1166
<fieldset><legend class="screen-reader-text"><span><?php _e('Connection Type') ?></span></legend>