From 45435f003eb5a6ebad1cf155a7df8112387faf6d Mon Sep 17 00:00:00 2001
From: ryan 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."));
+
+ // Accepted MIME types are set here as PCRE. Override with $override['mimes'].
+ $mimes = apply_filters('upload_mimes', array(
+ 'image/jpeg' => 'jpg|jpeg|jpe',
+ 'image/gif' => 'gif',
+ 'image/(png|x-png)' => 'png',
+ 'image/(bmp|x-bmp|x-ms-bmp)' => 'bmp',
+ 'image/(tiff|x-tiff)' => 'tif|tiff',
+ 'image/(ico|x-ico)' => 'ico',
+ 'video/(asf|x-asf|x-ms-asf)' => 'asf|asx|wma|wax|wmv|wmx',
+ 'video/(wmv|x-wmv|x-ms-wmv)' => 'wmv',
+ 'video/(msvideo|x-msvideo)' => 'avi',
+ 'video/(quicktime|x-quicktime)' => 'mov|qt',
+ 'video/(mpeg|x-mpeg)' => 'mpeg|mpg|mpe',
+ 'text/plain' => 'txt|c|cc|h|php',
+ 'text/richtext' => 'rtx',
+ 'text/css' => 'css',
+ 'text/html' => 'htm|html',
+ 'text/javascript' => 'js',
+ 'audio/(mpeg|x-mpeg|mpeg3|x-mpeg3)' => 'mp3',
+ 'audio/x-realaudio' => 'ra|ram',
+ 'audio/(wav|x-wav)' => 'wav',
+ 'audio/(ogg|x-ogg)' => 'ogg',
+ 'audio/(midi|x-midi)' => 'mid|midi',
+ 'application/pdf' => 'pdf',
+ 'application/msword' => 'doc',
+ 'application/mspowerpoint' => 'pot|pps|ppt',
+ 'application/mswrite' => 'wri',
+ 'application/(msexcel|vnd.ms-excel)' => 'xla|xls|xlt|xlw',
+ 'application/msaccess' => 'mdb',
+ 'application/msproject' => 'mpp',
+ 'application/x-shockwave-flash' => 'swf',
+ 'application/java' => 'class',
+ 'application/x-tar' => 'tar',
+ 'application/(zip|x-zip-compressed)' => 'zip',
+ 'application/(x-gzip|x-gzip-compressed)' => 'gz|gzip'));
+
+ // For security, we never trust HTTP Content-Type headers unless the user overrides this.
+ $trust_content_type = false;
+
+ // All tests are on by default. Most can be turned off by $override[{test_name}] = false;
+ $test_form = true;
+ $test_size = true;
+ $test_type = true;
+
+ // Install user overrides. Did we mention that this voids your warranty?
+ if ( is_array($overrides) )
+ extract($overrides, EXTR_OVERWRITE);
+
+ // A correct form post will pass this test.
+ if ( $test_form && (!isset($_POST['action']) || ($_POST['action'] != $action)) )
+ return $upload_error_handler($file, __('Invalid form submission.'));
+
+ // A successful upload will pass this test. It makes no sense to override this one.
+ if ( $file['error'] > 0 )
+ return $upload_error_handler($file, $upload_error_strings[$file['error']]);
+
+ // A non-empty file will pass this test.
+ if ( $test_size && !($file['size'] > 0) )
+ return $upload_error_handler($file, __('File is empty. Please upload something more substantial.'));
+
+ // A properly uploaded file will pass this test. There should be no reason to override this one.
+ if (! is_uploaded_file($file['tmp_name']) )
+ return $upload_error_handler($file, __('Specified file failed upload test.'));
+
+ // A correct MIME type will pass this test. We can't always determine it programatically, so we'll trust the HTTP headers.
+ if ( $test_type ) {
+ $type = false;
+ $ext = false;
+ foreach ($mimes as $mime_preg => $ext_preg) {
+ $mime_preg = '!^' . $mime_preg . '$!i';
+ $ext_preg = '![^.]\.(' . $ext_preg . ')$!i';
+ if ( preg_match($mime_preg, $file['type'], $type) ) {
+ if ( preg_match($ext_preg, $file['name'], $ext) ) {
+ break;
+ } else {
+ return $upload_error_handler($file, __('File extension does not match file type. Try another.'));
+ }
+ }
+ }
+ if (! $type && $ext )
+ return $upload_error_handler($file, __('File type does not meet security guidelines. Try another.'));
+ $type = $type[0];
+ $ext = $ext[1];
+ }
+
+ // A writable uploads dir will pass this test. Again, there's no point overriding this one.
+ if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
+ return $upload_error_handler($file, $uploads['error']);
+
+ // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
+ if ( isset($unique_filename_callback) && function_exists($unique_filename_callback) ) {
+ $filename = $unique_filename_callback($uploads['path'], $file['name']);
+ } else {
+ $number = '';
+ $filename = $file['name'];
+ while ( file_exists($uploads['path'] . "/$filename") )
+ $filename = str_replace("$number.$ext", ++$number . ".$ext", $filename);
+ }
+
+ // Move the file to the uploads dir
+ $new_file = $uploads['path'] . "/$filename";
+ if ( false === move_uploaded_file($file['tmp_name'], $new_file) )
+ die('The uploaded file could not be moved to $file.');
+
+ // Set correct file permissions
+ $stat = stat(dirname($new_file));
+ $perms = $stat['mode'] & 0000777;
+ @ chmod($new_file, $perms);
+
+ // Compute the URL
+ $url = $uploads['url'] . "/$filename";
+
+ return array('file' => $new_file, 'url' => $url);
+}
+
?>
diff --git a/wp-admin/image-uploading.php b/wp-admin/image-uploading.php
index 873be76c4a..817e1ea2f0 100644
--- a/wp-admin/image-uploading.php
+++ b/wp-admin/image-uploading.php
@@ -1,505 +1,624 @@
- 4 / 3 )
- return array(128, (int) ($height / $width * 128));
- else
- return array((int) ($width / $height * 96), 96);
-}
-
-switch($action) {
-case 'delete':
-
-wp_delete_object($object);
-
-header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&start=$start");
-die;
-
-case 'save':
-
-// Define acceptable image extentions/types here. Tests will apply strtolower().
-$exts = array('gif' => IMAGETYPE_GIF, 'jpg' => IMAGETYPE_JPEG, 'png' => IMAGETYPE_PNG);
-
-// Define the error messages for bad uploads.
-$upload_err = array(false,
- __("The uploaded file exceeds the 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";
-if ( false === move_uploaded_file($_FILES['image']['tmp_name'], $file) )
- die('The uploaded file could not be moved to $file.');
-chmod($file, 0666); // FIXME: Need to set this according to rw bits on parent dir.
-
-// 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'];
-list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
-$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
-$imagedata['file'] = $file;
-$imagedata['thumb'] = "thumb-$filename";
-
-add_post_meta($id, 'imagedata', $imagedata);
-
-if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
- if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
- $error = wp_create_thumbnail($file, 128);
- elseif ( $imagedata['height'] > 96 )
- $error = wp_create_thumbnail($file, 96);
-}
-
-header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&last=true");
-die;
-
-case 'upload':
-
-$current_1 = ' class="current"';
-$back = $next = false;
-break;
-
-case 'view':
-
-// How many images do we show? How many do we query?
-$num = 5;
-$double = $num * 2;
-
-if ( $post && empty($all) ) {
- $and_post = "AND post_parent = '$post'";
- $current_2 = ' class="current"';
-} else {
- $current_3 = ' class="current"';
-}
-
-if ( $last )
- $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post") - $num;
-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, $double", ARRAY_A);
-
-if ( count($images) > $num ) {
- $next = $start + count($images) - $num;
-} else {
- $next = false;
-}
-
-if ( $start > 0 ) {
- $back = $start - $num;
- if ( $back < 1 )
- $back = '0';
-} else {
- $back = false;
-}
-
-$i = 0;
-$uwidth_sum = 0;
-$images_html = '';
-$images_style = '';
-$images_script = '';
-if ( count($images) > 0 ) {
- $images = array_slice( $images, 0, $num );
- $__delete = __('DELETE');
- $__subpost_on = __('SUBPOST ON');
- $__subpost_off = __('SUBPOST OFF');
- $__thumbnail_on = __('THUMBNAIL ON');
- $__thumbnail_off = __('THUMBNAIL OFF');
- $__no_thumbnail = __('THUMBNAIL');
- $__close = __('CLOSE');
- $__confirmdelete = __('Delete this photo from the server?');
- $__nothumb = __('There is no thumbnail associated with this photo.');
- $images_script .= "subposton = '$__subpost_on';\nsubpostoff = '$__subpost_off';\n";
- $images_script .= "thumbnailon = '$__thumbnail_on';\nthumbnailoff = '$__thumbnail_off';\n";
- foreach ( $images as $key => $image ) {
- $meta = get_post_meta($image['ID'], 'imagedata', true);
- if (!is_array($meta)) {
- wp_delete_object($image['ID']);
- continue;
- }
- $image = array_merge($image, $meta);
- if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) {
- $src = str_replace(basename($image['guid']), '', $image['guid']) . $image['thumb'];
- $images_script .= "src".$i."a = '$src';\nsrc".$i."b = '".$image['guid']."';\n";
- $thumb = 'true';
- $thumbtext = $__thumbnail_on;
- } else {
- $src = $image['guid'];
- $thumb = 'false';
- $thumbtext = $__no_thumbnail;
- }
- list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);
- $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"';
- $uwidth_sum += 128;
- $xpadding = (128 - $image['uwidth']) / 2;
- $ypadding = (96 - $image['uheight']) / 2;
- $object = $image['ID'];
- $images_style .= "#target$i img { padding: {$ypadding}px {$xpadding}px; }\n";
- $href = get_subpost_link($object);
- $images_script .= "href".$i."a = '$href';\nhref".$i."b = '{$image['guid']}';\n";
- $images_html .= <<
-
-
-HERE;
- $i++;
- }
-}
-
-$images_width = $uwidth_sum + ( count($images) * 5 ) + 30;
-
-break;
-
-default:
-die('This script was not meant to be called directly.');
-}
-
-?>
-
-
-
-
-
-
-
-
-
-
-Drag and drop photos to post
-Click photos for more options
-
THUMBNAIL');
+ $__close = __('CLOSE');
+ $__confirmdelete = __('Delete this photo from the server?');
+ $__nothumb = __('There is no thumbnail associated with this photo.');
+ $images_script .= "subposton = '$__subpost_on';\nsubpostoff = '$__subpost_off';\n";
+ $images_script .= "thumbnailon = '$__thumbnail_on';\nthumbnailoff = '$__thumbnail_off';\n";
+ foreach ( $images as $key => $image ) {
+ $meta = get_post_meta($image['ID'], 'imagedata', true);
+ if (!is_array($meta)) {
+ wp_delete_object($image['ID']);
+ continue;
+ }
+ $image = array_merge($image, $meta);
+ if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) {
+ $src = str_replace(basename($image['guid']), '', $image['guid']) . $image['thumb'];
+ $images_script .= "src".$i."a = '$src';\nsrc".$i."b = '".$image['guid']."';\n";
+ $thumb = 'true';
+ $thumbtext = $__thumbnail_on;
+ } else {
+ $src = $image['guid'];
+ $thumb = 'false';
+ $thumbtext = $__no_thumbnail;
+ }
+ list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);
+ $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"';
+ $uwidth_sum += 128;
+ $xpadding = (128 - $image['uwidth']) / 2;
+ $ypadding = (96 - $image['uheight']) / 2;
+ $object = $image['ID'];
+ $images_style .= "#target$i img { padding: {$ypadding}px {$xpadding}px; }\n";
+ $href = get_subpost_link($object);
+ $images_script .= "href".$i."a = '$href';\nhref".$i."b = '{$image['guid']}';\n";
+ $images_html .= <<
+
+
+HERE;
+ $i++;
+ }
+}
+
+$images_width = $uwidth_sum + ( count($images) * 5 ) + 30;
+
+break;
+
+case 'flickr':
+
+require_once ABSPATH . WPINC . '/class-snoopy.php';
+
+function flickr_api_call($method, $params = '') {
+ $api_key = '7cd7b7dea9c9d3069caf99d12471008e'; // An API key reserved for WordPress
+ $searchurl = 'http://www.flickr.com/services/rest/?method=' . $method . '&api_key=' . $api_key . '&' . $params;
+ $client = new Snoopy();
+ $client->agent = 'WordPress/Flickr Browser';
+ $client->read_timeout = 2;
+ $client->use_gzip = true;
+ @$client->fetch($searchurl);
+ return $client->results;
+}
+
+// How many images do we show? How many do we query?
+$num = 5;
+$double = $num * 2;
+
+$flickr_user_id = get_user_option('flickr_userid');
+if($flickr_user_id == '') {
+ $flickr_username = get_user_option('flickr_username');
+ $user_xml = flickr_api_call('flickr.people.findByUsername', "username={$flickr_username}");
+ if(preg_match('/nsid="(.*?)">/', $user_xml, $matches)) {
+ $flickr_user_id = $matches[1];
+ }
+ else die("Failed to find Flickr ID for '$flickr_username'"); // Oh, dear - no Flickr user_id!
+
+ // Store the found Flickr user_id in usermeta...
+ // Don't forget on the options page to update the user_id along with the username!
+ update_user_option($current_user->id, 'flickr_userid', $flickr_user_id, true);
+}
+
+// Fetch photo list from Flickr
+$ustart = $start + 1;
+//$photos_xml = flickr_api_call('flickr.photos.search', array('per_page' => $num, 'user_id' => $flickr_user_id));
+if($flickrtag == '') {
+ $all = '0';
+ $photos_xml = flickr_api_call('flickr.people.getPublicPhotos', "per_page={$num}&user_id={$flickr_user_id}&page={$ustart}");
+}
+else {
+ $photos_xml = flickr_api_call('flickr.photos.search', "per_page={$num}&user_id={$flickr_user_id}&page={$ustart}&tags={$flickrtag}");
+ $all = '0&flickrtag=' . $flickrtag;
+}
+//echo "
" . htmlentities($photos_xml) . "
"; // Displays the XML returned by Flickr for the photo list
+
+//Get Page Count
+preg_match('/
+
+