Changeset 6984 for trunk/wp-includes/functions.php
- Timestamp:
- 02/22/2008 05:46:03 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r6983 r6984 1023 1023 } 1024 1024 1025 // Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows') 1026 function path_is_absolute( $path ) { 1027 // this is definitive if true but fails if $path does not exist or contains a symbolic link 1028 if ( realpath($path) == $path ) 1029 return true; 1030 1031 if ( strlen($path) == 0 || $path{0} == '.' ) 1032 return false; 1033 1034 // windows allows absolute paths like this 1035 if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) 1036 return true; 1037 1038 // a path starting with / or \ is absolute; anything else is relative 1039 return (bool) preg_match('#^[/\\\\]#', $path); 1040 } 1041 1042 // Join two filesystem paths together (e.g. 'give me $path relative to $base') 1043 function path_join( $base, $path ) { 1044 if ( path_is_absolute($path) ) 1045 return $path; 1046 1047 return rtrim($base, '/') . '/' . ltrim($path, '/'); 1048 } 1025 1049 1026 1050 // Returns an array containing the current upload directory's path and url, or an error message. … … 1029 1053 $upload_path = $dir = get_option( 'upload_path' ); 1030 1054 1031 if ( $upload_path != realpath( $upload_path ) ) { // not an absolute path 1032 //prepend ABSPATH to $dir and $siteurl to $url if they're not already there 1033 $path = str_replace( ABSPATH, '', trim( $upload_path ) ); 1034 $dir = ABSPATH . $path; 1035 } 1055 // $dir is absolute, $path is (maybe) relative to ABSPATH 1056 $dir = path_join( ABSPATH, $upload_path ); 1057 $path = str_replace( ABSPATH, '', trim( $upload_path ) ); 1036 1058 1037 1059 if ( !$url = get_option( 'upload_url_path' ) ) … … 1046 1068 } 1047 1069 1070 $subdir = ''; 1048 1071 if ( get_option( 'uploads_use_yearmonth_folders' ) ) { 1049 1072 // Generate the yearly and monthly dirs … … 1052 1075 $y = substr( $time, 0, 4 ); 1053 1076 $m = substr( $time, 5, 2 ); 1054 $dir = $dir . "/$y/$m"; 1055 $url = $url . "/$y/$m"; 1056 } 1077 $subdir = "/$y/$m"; 1078 } 1079 1080 $dir .= $subdir; 1081 $url .= $subdir; 1057 1082 1058 1083 // Make sure we have an uploads dir … … 1062 1087 } 1063 1088 1064 $uploads = array( 'path' => $dir, 'url' => $url, 'error' => false );1089 $uploads = array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'error' => false ); 1065 1090 return apply_filters( 'upload_dir', $uploads ); 1066 1091 }
Note: See TracChangeset
for help on using the changeset viewer.