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