diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index 91df571a8..3aa22f911 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -60,9 +60,19 @@ function write_post() { $post_ID = wp_insert_post($_POST); add_meta($post_ID); + // Reunite any orphaned subposts with their parent + if ( $_POST['temp_ID'] ) + relocate_children($_POST['temp_ID'], $post_ID); + return $post_ID; } +// Move child posts to a new parent +function relocate_children($old_ID, $new_ID) { + global $wpdb; + $wpdb->query("UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID"); +} + // Update an existing post with values provided in $_POST. function edit_post() { global $user_ID; @@ -1739,4 +1749,46 @@ function current_theme_info() { $ct->author = $themes[$current_theme]['Author']; return $ct; } -?> \ No newline at end of file + +// Returns an array containing the current upload directory's path and url, or an error message. +function wp_upload_dir() { + if ( defined('UPLOADS') ) + $dir = UPLOADS; + else + $dir = 'wp-content/uploads'; + + $path = ABSPATH . $dir; + + // Make sure we have an uploads dir + if ( ! file_exists( $path ) ) { + if ( ! mkdir( $path ) ) + return array('error' => "Unable to create directory $path. Is its parent directory writable by the server?"); + @ chmod( ABSPATH . $path, 0774 ); + } + + // Generate the yearly and monthly dirs + $time = current_time( 'mysql' ); + $y = substr( $time, 0, 4 ); + $m = substr( $time, 5, 2 ); + $pathy = "$path/$y"; + $pathym = "$path/$y/$m"; + + // Make sure we have a yearly dir + if ( ! file_exists( $pathy ) ) { + if ( ! mkdir( $pathy ) ) + return array('error' => "Unable to create directory $pathy. Is $path writable?"); + @ chmod( $pathy, 0774 ); + } + + // Make sure we have a monthly dir + if ( ! file_exists( $pathym ) ) { + if ( ! mkdir( $pathym ) ) + return array('error' => "Unable to create directory $pathym. Is $pathy writable?"); + @ chmod( $pathym, 0774 ); + } + + $uploads = array('path' => $pathym, 'url' => get_bloginfo('home') . "/$dir/$y/$m", 'error' => false); + return apply_filters('upload_dir', $uploads); +} + +?> diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index c78057180..545b35055 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -17,6 +17,8 @@ $messages[3] = __('Custom field deleted.'); if (0 == $post_ID) { $form_action = 'post'; + $temp_ID = -1 * time(); + $form_extra = ""; } else { $form_action = 'editpost'; $form_extra = ""; @@ -172,6 +174,11 @@ if ('publish' != $post_status || 0 == $post_ID) {
upload_max_filesize
directive in php.ini
.",
+ "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.",
+ "The uploaded file was only partially uploaded.",
+ "No file was uploaded.",
+ "Missing a temporary folder.",
+ "Failed to write file to disk.");
+
+$iuerror = false;
+
+// Failing any single one of the following tests is fatal.
+
+// A correct form post will pass this test.
+if ( !isset($_POST['action']) || $_POST['action'] != 'save' || count($_FILES) != 1 || ! isset($_FILES['image']) || is_array($_FILES['image']['name']) )
+ $error = 'Invalid form submission. Only submit approved forms.';
+
+// A successful upload will pass this test.
+elseif ( $_FILES['image']['error'] > 0 )
+ $error = $upload_err[$_FILES['image']['error']];
+
+// A non-empty file will pass this test.
+elseif ( 0 == $_FILES['image']['size'] )
+ $error = 'File is empty. Please upload something more substantial.';
+
+// A correct MIME category will pass this test. Full types are not consistent across browsers.
+elseif ( ! 'image/' == substr($_FILES['image']['type'], 0, 6) )
+ $error = 'Bad MIME type submitted by your browser.';
+
+// An acceptable file extension will pass this test.
+elseif ( ! ( ( 0 !== preg_match('#\.?([^\.]*)$#', $_FILES['image']['name'], $matches) ) && ( $ext = strtolower($matches[1]) ) && array_key_exists($ext, $exts) ) )
+ $error = 'Bad file extension.';
+
+// A valid uploaded file will pass this test.
+elseif ( ! is_uploaded_file($_FILES['image']['tmp_name']) )
+ $error = 'Bad temp file. Try renaming the file and uploading again.';
+
+// A valid image file will pass this test.
+elseif ( function_exists('exif_imagetype') && $exts[$ext] != $imagetype = exif_imagetype($_FILES['image']['tmp_name']) )
+ $error = 'Bad image file. Try again, or try recreating it.';
+
+// An image with at least one pixel will pass this test.
+elseif ( ! ( ( $imagesize = getimagesize($_FILES['image']['tmp_name']) ) && $imagesize[0] > 1 && $imagesize[1] > 1 ) )
+ $error = 'The image has no pixels. Isn\'t that odd?';
+
+// A writable uploads dir will pass this test.
+elseif ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
+ $error = $uploads['error'];
+
+if ( $error )
+ // Something wasn't right. Abort and never touch the temp file again.
+ die("$error Back to Image Uploading");
+
+// Increment the file number until we have a unique file to save in $dir
+$number = '';
+$filename = $_FILES['image']['name'];
+while ( file_exists($uploads['path'] . "/$filename") )
+ $filename = str_replace("$number.$ext", ++$number . ".$ext", $filename);
+
+// Move the file to the uploads dir
+$file = $uploads['path'] . "/$filename";
+move_uploaded_file($_FILES['image']['tmp_name'], $file);
+chmod($file, 0775);
+
+// Compute the URL
+$url = $uploads['url'] . "/$filename";
+
+// Construct the object array
+$object = array(
+ 'post_title' => $imgtitle ? $imgtitle : $filename,
+ 'post_content' => $descr,
+ 'post_status' => 'object',
+ 'post_parent' => $post,
+ 'post_type' => $_FILES['image']['type'],
+ 'guid' => $url
+ );
+
+// Save the data
+$id = wp_attach_object($object, $post);
+
+// Generate the object's postmeta.
+$imagesize = getimagesize($file);
+$imagedata['width'] = $imagesize['0'];
+$imagedata['height'] = $imagesize['1'];
+if ( $imagedata['height'] < 96 && $imagedata['width'] < 128 ) {
+ $uheight = $imagedata['height'];
+ $uwidth = $imagedata['width'];
+} elseif ( $imagedata['width'] / $imagedata['height'] > 4 / 3 ) {
+ $uwidth = 128;
+ $uheight = $imagedata['height'] / $imagedata['width'] * $uwidth;
+} else {
+ $uheight = 96;
+ $uwidth = $imagedata['width'] / $imagedata['height'] * $uheight;
+}
+$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
+$imagedata['file'] = $file;
+
+if ( false == add_post_meta($id, 'imagedata', $imagedata) )
+ die("failed to add_post_meta");
+
+header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&last=true");
+die;
+
+case 'upload':
+?>
+
+
+
+
+
+
+
+
+
+
+get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post") - 5;
+else
+ $start = (int) $start;
+
+if ( $start < 0 )
+ $start = 0;
+
+if ( '' == $sort )
+ $sort = "ID";
+
+$images = $wpdb->get_results("SELECT ID, post_date, post_title, guid FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post ORDER BY $sort LIMIT $start, 10", ARRAY_A);
+
+//if ( count($images) == 0 )
+// header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=upload");
+
+if ( count($images) > 5 ) {
+ $next = $start + count($images) - 5;
+} else {
+ $next = false;
+}
+
+if ( $start > 0 ) {
+ $back = $start - 5;
+ if ( $back < 1 )
+ $back = '0';
+} else {
+ $back = false;
+}
+
+?>
+
+
+
+
+
+
+