Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r18193 r17200  
    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 */
     165function 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/**
    156192 * Returns a filename of a Temporary unique file.
    157193 * Please note that the calling function must unlink() this itself.
     
    253289    // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
    254290    $upload_error_strings = array( false,
    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." ),
     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." ),
    257293        __( "The uploaded file was only partially uploaded." ),
    258294        __( "No file was uploaded." ),
     
    484520        return new WP_Error('http_no_file', __('Could not create Temporary file.'));
    485521
    486     $response = wp_remote_get( $url, array( 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname ) );
    487 
    488     if ( is_wp_error( $response ) ) {
    489         unlink( $tmpfname );
     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);
    490531        return $response;
    491532    }
    492533
    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     }
     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);
    497542
    498543    return $tmpfname;
     
    519564
    520565    // Unzip can use a lot of memory, but not this much hopefully
    521     @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
     566    @ini_set('memory_limit', '256M');
    522567
    523568    $needed_dirs = array();
     
    653698    global $wp_filesystem;
    654699
    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 
    661700    require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
    662701
    663702    $archive = new PclZip($file);
    664703
    665     $archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
    666 
    667     if ( isset($previous_encoding) )
    668         mb_internal_encoding($previous_encoding);
    669 
    670704    // Is the archive valid?
    671     if ( !is_array($archive_files) )
     705    if ( false == ($archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING)) )
    672706        return new WP_Error('incompatible_archive', __('Incompatible Archive.'), $archive->errorInfo(true));
    673707
     
    728762 * @param string $from source directory
    729763 * @param string $to destination directory
    730  * @param array $skip_list a list of files/folders to skip copying
    731764 * @return mixed WP_Error on failure, True on success.
    732765 */
    733 function copy_dir($from, $to, $skip_list = array() ) {
     766function copy_dir($from, $to) {
    734767    global $wp_filesystem;
    735768
     
    739772    $to = trailingslashit($to);
    740773
    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 
    748774    foreach ( (array) $dirlist as $filename => $fileinfo ) {
    749         if ( !empty($skip_regex) )
    750             if ( preg_match($skip_regex, $from . $filename) )
    751                 continue;
    752 
    753775        if ( 'f' == $fileinfo['type'] ) {
    754             if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
     776            if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) ) {
    755777                // If copy failed, chmod file to 0644 and try again.
    756778                $wp_filesystem->chmod($to . $filename, 0644);
    757                 if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
     779                if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) )
    758780                    return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
    759781            }
     782            $wp_filesystem->chmod($to . $filename, FS_CHMOD_FILE);
    760783        } elseif ( 'd' == $fileinfo['type'] ) {
    761784            if ( !$wp_filesystem->is_dir($to . $filename) ) {
     
    763786                    return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
    764787            }
    765             $result = copy_dir($from . $filename, $to . $filename, $skip_list);
     788            $result = copy_dir($from . $filename, $to . $filename);
    766789            if ( is_wp_error($result) )
    767790                return $result;
Note: See TracChangeset for help on using the changeset viewer.