Changes in trunk/wp-admin/includes/file.php [17200:18193]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/file.php
r17200 r18193 81 81 $siteurl = get_option( 'siteurl' ); 82 82 if ( $home != '' && $home != $siteurl ) { 83 84 85 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); 86 86 $home_path = trailingslashit( $home_path ); 87 87 } else { … … 154 154 155 155 /** 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.0162 *163 * @return string Writable temporary directory164 */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 /**192 156 * Returns a filename of a Temporary unique file. 193 157 * Please note that the calling function must unlink() this itself. … … 289 253 // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error']. 290 254 $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." ), 293 257 __( "The uploaded file was only partially uploaded." ), 294 258 __( "No file was uploaded." ), … … 520 484 return new WP_Error('http_no_file', __('Could not create Temporary file.')); 521 485 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 ); 531 490 return $response; 532 491 } 533 492 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 } 542 497 543 498 return $tmpfname; … … 564 519 565 520 // 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 ) ); 567 522 568 523 $needed_dirs = array(); … … 698 653 global $wp_filesystem; 699 654 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 700 661 require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php'); 701 662 702 663 $archive = new PclZip($file); 703 664 665 $archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING); 666 667 if ( isset($previous_encoding) ) 668 mb_internal_encoding($previous_encoding); 669 704 670 // Is the archive valid? 705 if ( false == ($archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING)) )671 if ( !is_array($archive_files) ) 706 672 return new WP_Error('incompatible_archive', __('Incompatible Archive.'), $archive->errorInfo(true)); 707 673 … … 762 728 * @param string $from source directory 763 729 * @param string $to destination directory 730 * @param array $skip_list a list of files/folders to skip copying 764 731 * @return mixed WP_Error on failure, True on success. 765 732 */ 766 function copy_dir($from, $to ) {733 function copy_dir($from, $to, $skip_list = array() ) { 767 734 global $wp_filesystem; 768 735 … … 772 739 $to = trailingslashit($to); 773 740 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 774 748 foreach ( (array) $dirlist as $filename => $fileinfo ) { 749 if ( !empty($skip_regex) ) 750 if ( preg_match($skip_regex, $from . $filename) ) 751 continue; 752 775 753 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) ) { 777 755 // If copy failed, chmod file to 0644 and try again. 778 756 $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) ) 780 758 return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename); 781 759 } 782 $wp_filesystem->chmod($to . $filename, FS_CHMOD_FILE);783 760 } elseif ( 'd' == $fileinfo['type'] ) { 784 761 if ( !$wp_filesystem->is_dir($to . $filename) ) { … … 786 763 return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename); 787 764 } 788 $result = copy_dir($from . $filename, $to . $filename );765 $result = copy_dir($from . $filename, $to . $filename, $skip_list); 789 766 if ( is_wp_error($result) ) 790 767 return $result;
Note: See TracChangeset
for help on using the changeset viewer.