Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17200 r18193  
    8181    $siteurl = get_option( 'siteurl' );
    8282    if ( $home != '' && $home != $siteurl ) {
    83             $wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */
    84             $pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home);
    85             $home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos);
     83        $wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */
     84        $pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home);
     85        $home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos);
    8686        $home_path = trailingslashit( $home_path );
    8787    } else {
     
    154154
    155155/**
    156  * Determines a writable directory for temporary files.
    157  * 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/
    158  *
    159  * 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.
    160  *
    161  * @since 2.5.0
    162  *
    163  * @return string Writable temporary directory
    164  */
    165 function get_temp_dir() {
    166     static $temp;
    167     if ( defined('WP_TEMP_DIR') )
    168         return trailingslashit(WP_TEMP_DIR);
    169 
    170     if ( $temp )
    171         return trailingslashit($temp);
    172 
    173     $temp = WP_CONTENT_DIR . '/';
    174     if ( is_dir($temp) && @is_writable($temp) )
    175         return $temp;
    176 
    177     if  ( function_exists('sys_get_temp_dir') ) {
    178         $temp = sys_get_temp_dir();
    179         if ( @is_writable($temp) )
    180             return trailingslashit($temp);
    181     }
    182 
    183     $temp = ini_get('upload_tmp_dir');
    184     if ( is_dir($temp) && @is_writable($temp) )
    185         return trailingslashit($temp);
    186 
    187     $temp = '/tmp/';
    188     return $temp;
    189 }
    190 
    191 /**
    192156 * Returns a filename of a Temporary unique file.
    193157 * Please note that the calling function must unlink() this itself.
     
    289253    // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
    290254    $upload_error_strings = array( false,
    291         __( "The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>." ),
    292         __( "The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form." ),
     255        __( "The uploaded file exceeds the upload_max_filesize directive in php.ini." ),
     256        __( "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form." ),
    293257        __( "The uploaded file was only partially uploaded." ),
    294258        __( "No file was uploaded." ),
     
    520484        return new WP_Error('http_no_file', __('Could not create Temporary file.'));
    521485
    522     $handle = @fopen($tmpfname, 'wb');
    523     if ( ! $handle )
    524         return new WP_Error('http_no_file', __('Could not create Temporary file.'));
    525 
    526     $response = wp_remote_get($url, array('timeout' => $timeout));
    527 
    528     if ( is_wp_error($response) ) {
    529         fclose($handle);
    530         unlink($tmpfname);
     486    $response = wp_remote_get( $url, array( 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname ) );
     487
     488    if ( is_wp_error( $response ) ) {
     489        unlink( $tmpfname );
    531490        return $response;
    532491    }
    533492
    534     if ( $response['response']['code'] != '200' ){
    535         fclose($handle);
    536         unlink($tmpfname);
    537         return new WP_Error('http_404', trim($response['response']['message']));
    538     }
    539 
    540     fwrite($handle, $response['body']);
    541     fclose($handle);
     493    if ( 200 != wp_remote_retrieve_response_code( $response ) ){
     494        unlink( $tmpfname );
     495        return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
     496    }
    542497
    543498    return $tmpfname;
     
    564519
    565520    // Unzip can use a lot of memory, but not this much hopefully
    566     @ini_set('memory_limit', '256M');
     521    @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
    567522
    568523    $needed_dirs = array();
     
    698653    global $wp_filesystem;
    699654
     655    // See #15789 - PclZip uses string functions on binary data, If it's overloaded with Multibyte safe functions the results are incorrect.
     656    if ( ini_get('mbstring.func_overload') && function_exists('mb_internal_encoding') ) {
     657        $previous_encoding = mb_internal_encoding();
     658        mb_internal_encoding('ISO-8859-1');
     659    }
     660
    700661    require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
    701662
    702663    $archive = new PclZip($file);
    703664
     665    $archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
     666
     667    if ( isset($previous_encoding) )
     668        mb_internal_encoding($previous_encoding);
     669
    704670    // Is the archive valid?
    705     if ( false == ($archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING)) )
     671    if ( !is_array($archive_files) )
    706672        return new WP_Error('incompatible_archive', __('Incompatible Archive.'), $archive->errorInfo(true));
    707673
     
    762728 * @param string $from source directory
    763729 * @param string $to destination directory
     730 * @param array $skip_list a list of files/folders to skip copying
    764731 * @return mixed WP_Error on failure, True on success.
    765732 */
    766 function copy_dir($from, $to) {
     733function copy_dir($from, $to, $skip_list = array() ) {
    767734    global $wp_filesystem;
    768735
     
    772739    $to = trailingslashit($to);
    773740
     741    $skip_regex = '';
     742    foreach ( (array)$skip_list as $key => $skip_file )
     743        $skip_regex .= preg_quote($skip_file, '!') . '|';
     744
     745    if ( !empty($skip_regex) )
     746        $skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i';
     747
    774748    foreach ( (array) $dirlist as $filename => $fileinfo ) {
     749        if ( !empty($skip_regex) )
     750            if ( preg_match($skip_regex, $from . $filename) )
     751                continue;
     752
    775753        if ( 'f' == $fileinfo['type'] ) {
    776             if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) ) {
     754            if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
    777755                // If copy failed, chmod file to 0644 and try again.
    778756                $wp_filesystem->chmod($to . $filename, 0644);
    779                 if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) )
     757                if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
    780758                    return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
    781759            }
    782             $wp_filesystem->chmod($to . $filename, FS_CHMOD_FILE);
    783760        } elseif ( 'd' == $fileinfo['type'] ) {
    784761            if ( !$wp_filesystem->is_dir($to . $filename) ) {
     
    786763                    return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
    787764            }
    788             $result = copy_dir($from . $filename, $to . $filename);
     765            $result = copy_dir($from . $filename, $to . $filename, $skip_list);
    789766            if ( is_wp_error($result) )
    790767                return $result;
Note: See TracChangeset for help on using the changeset viewer.