Changeset 4961
- Timestamp:
- 03/03/2007 04:56:46 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r4951 r4961 1116 1116 else 1117 1117 $ext = ".$ext"; 1118 while ( file_exists($upload['path'] . "/$filename") && !$overwrite) {1118 while ( file_exists($upload['path'] . "/$filename") ) { 1119 1119 if ( '' == "$number$ext" ) 1120 1120 $filename = $filename . ++$number . $ext; … … 1123 1123 } 1124 1124 1125 $new_file = $upload['path'] . "/$filename"; 1126 if ( ! wp_mkdir_p( dirname($new_file) ) ) { 1127 $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file)); 1128 return array('error' => $message); 1125 // If we are asked to over write the file then make sure 1126 // the $name has the complete path and is writable. 1127 if($overwrite) { 1128 if(!is_writable($name)) { 1129 return(array("error" => __("Can not over write file."))); 1130 } 1131 $new_file = $name; 1132 $filename = basename($name); 1133 } 1134 else { 1135 $new_file = $upload['path'] . "/$filename"; 1136 if ( ! wp_mkdir_p( dirname($new_file) ) ) { 1137 $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file)); 1138 return array('error' => $message); 1139 } 1129 1140 } 1130 1141 … … 1141 1152 @ chmod($new_file, $perms); 1142 1153 1143 // Compute the URL 1154 // Compute the URL if this is a new file. 1144 1155 $url = $upload['url'] . "/$filename"; 1156 if($overwrite) { 1157 $url = $name; 1158 } 1145 1159 1146 1160 return array('file' => $new_file, 'url' => $url, 'error' => false); -
trunk/xmlrpc.php
r4953 r4961 150 150 global $wpdb; 151 151 152 if( is_string($array)) {152 if(!is_array($array)) { 153 153 return($wpdb->escape($array)); 154 154 } … … 1101 1101 1102 1102 // Only set a post parent if one was given. 1103 if( !empty($content_struct["wp_page_parent_id"])) {1103 if(isset($content_struct["wp_page_parent_id"])) { 1104 1104 $post_parent = $content_struct["wp_page_parent_id"]; 1105 1105 } … … 1167 1167 if ( is_array($to_ping) ) 1168 1168 $to_ping = implode(' ', $to_ping); 1169 1170 if(isset($content_struct["mt_allow_comments"])) { 1171 $comment_status = $content_struct["mt_allow_comments"]; 1172 } 1169 1173 1170 $comment_status = (!isset($content_struct['mt_allow_comments'])) ?1171 get_option('default_comment_status')1172 : $content_struct['mt_allow_comments'];1173 1174 1174 // Do some timestamp voodoo 1175 1175 $dateCreatedd = $content_struct['dateCreated']; … … 1388 1388 if(!empty($data["overwrite"]) && ($data["overwrite"] == true)) { 1389 1389 $overwrite = true; 1390 1391 // If the file isn't writable then error out now. 1392 if(!is_writable($data["name"])) { 1393 return(new IXR_Error(500, "File is not writable, over write failed.")); 1394 } 1395 1396 // We now know the file is good so don't use the sanitized name. 1397 $name = $data["name"]; 1398 1399 // Get postmeta info on the object. 1400 $old_meta = $wpdb->get_row(" 1401 SELECT * 1402 FROM {$wpdb->postmeta} 1403 WHERE meta_key = '_wp_attached_file' 1404 AND meta_value = '{$name}' 1405 "); 1406 1407 // Get post info on the object. 1408 $old_post = get_post($old_meta->post_id); 1390 1409 } 1391 1410 … … 1422 1441 ); 1423 1442 1424 // Only make a database entry if this is a new file. 1425 if(!$overwrite) { 1426 // Save the data 1427 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id ); 1428 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 1429 } 1443 // If we are over writing then set the correct post_id and URL 1444 // instead of getting new ones. 1445 if($overwrite) { 1446 $post_id = $old_meta->post_id; 1447 $attachment["post_parent"] = $old_meta->post_id; 1448 $attachment["ID"] = $old_meta->post_id; 1449 1450 $upload["url"] = $old_post->guid; 1451 $attachment["guid"] = $old_post->guid; 1452 } 1453 1454 // Save the data 1455 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id ); 1456 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 1430 1457 1431 1458 return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) );
Note: See TracChangeset
for help on using the changeset viewer.