Fix insert, gallery, sizing, type queries, errors, thumbs, type fallback. Props andy. see #5911

git-svn-id: http://svn.automattic.com/wordpress/trunk@7172 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-03-06 19:48:54 +00:00
parent 12a0f3a403
commit c506a8173c
9 changed files with 66 additions and 69 deletions

View File

@ -159,6 +159,9 @@ function wp_handle_upload( &$file, $overrides = false ) {
if ( !$ext )
$ext = ltrim(strrchr($file['name'], '.'), '.');
if ( !$type )
$type = $file['type'];
}
// A writable uploads dir will pass this test. Again, there's no point overriding this one.

View File

@ -53,10 +53,9 @@ function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = fal
$html = get_image_tag($id, $alt, $title, $align, $rel, $size);
$rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
if ( $url )
$html = "<a href='".attribute_escape($url)."'$rel>$html</a>";
elseif ( $size == 'thumbnail' || $size == 'medium' )
$html = '<a href="'.get_attachment_link($id).'"'.$rel.'>'.$html.'</a>';
$html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url );
@ -238,14 +237,17 @@ function media_upload_form_handler() {
wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
}
if ( isset($_POST['insert-media']) )
if ( isset($_POST['insert-gallery']) )
return media_send_to_editor('[gallery]');
if ( isset($_POST['send']) ) {
$keys = array_keys($_POST['send']);
$send_id = (int) array_shift($keys);
$attachment = $_POST['attachments'][$send_id];
$html = apply_filters('media_send_to_editor', get_the_attachment_link($send_id, 0, array(125,125), !empty($attachment['post_content'])), $send_id, $attachment);
$html = $attachment['post_title'];
if ( !empty($attachment['url']) )
$html = "<a href='{$attachment['url']}'>$html</a>";
$html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
return media_send_to_editor($html);
}
@ -881,7 +883,7 @@ jQuery(function($){
<?php echo get_media_items($post_id, $errors); ?>
</div>
<p class="submit">
<input type="submit" class="submit insert-gallery" name="insert-media" value="<?php _e('Insert gallery into post'); ?>" />
<input type="submit" class="submit insert-gallery" name="insert-gallery" value="<?php _e('Insert gallery into post'); ?>" />
</p>
<input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
</form>

View File

@ -4,7 +4,7 @@ function send_to_editor(h) {
if ( !win )
win = top;
tinyMCE = win.tinyMCE;
if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') ) {
if ( typeof tinyMCE != 'undefined' && ( ed = tinyMCE.getInstanceById('content') ) && !ed.isHidden() ) {
tinyMCE.selectedInstance.getWin().focus();
tinyMCE.execCommand('mceInsertContent', false, h);
} else

View File

@ -20,7 +20,7 @@ function fileQueued(fileObj) {
jQuery('#media-items').append('<div id="media-item-' + fileObj.id + '" class="media-item child-of-' + post_id + '"><div class="filename original">' + fileObj.name + '</div><div class="progress"><div class="bar"></div></div></div>');
// Disable the submit button
jQuery('#insert-media').attr('disabled', 'disabled');
jQuery('#insert-gallery').attr('disabled', 'disabled');
}
function uploadStart(fileObj) { return true; }
@ -107,7 +107,7 @@ function uploadSuccess(fileObj, serverData) {
function uploadComplete(fileObj) {
// If no more uploads queued, enable the submit button
if ( swfu.getStats().files_queued == 0 )
jQuery('#insert-media').attr('disabled', '');
jQuery('#insert-gallery').attr('disabled', '');
}

View File

@ -290,4 +290,53 @@ function wp_get_attachment_image($attachment_id, $size='thumbnail') {
return $html;
}
add_shortcode('gallery', 'gallery_shortcode');
function gallery_shortcode($attr) {
global $post;
// Allow plugins/themes to override the default gallery template.
$output = apply_filters('post_gallery', '', $attr);
if ( $output != '' )
return $output;
$attachments = get_children("post_parent=$post->ID&post_type=attachment&post_mime_type=image&orderby=\"menu_order ASC, ID ASC\"");
if ( empty($attachments) )
return '';
$output = apply_filters('gallery_style', "
<style type='text/css'>
.gallery {
margin: auto;
}
.gallery div {
float: left;
margin-top: 10px;
text-align: center;
width: 33%; }
.gallery img {
border: 2px solid #cfcfcf;
}
</style>
<div class='gallery'>");
foreach ( $attachments as $id => $attachment ) {
$link = get_the_attachment_link($id, false, array(128, 96), true);
$output .= "
<div>
$link
</div>";
if ( ++$i % 3 == 0 )
$output .= '<br style="clear: both" />';
}
$output .= "
<br style='clear: both;' >
</div>\n";
return $output;
}
?>

View File

@ -381,7 +381,7 @@ function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false
$post_title = attribute_escape($_post->post_title);
$link_text = wp_get_attachment_image($attachment_id, $size);
$link_text = wp_get_attachment_image($id, $size);
if ( !$link_text )
$link_text = $_post->post_title;

View File

@ -471,6 +471,7 @@ function get_posts($args) {
$query .= empty( $post_parent ) ? '' : $wpdb->prepare("AND $wpdb->posts.post_parent = %d ", $post_parent);
// expected_slashed ($meta_key, $meta_value) -- Also, this looks really funky, doesn't seem like it works
$query .= empty( $meta_key ) | empty($meta_value) ? '' : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )";
$query .= empty( $post_mime_type ) ? '' : wp_post_mime_type_where($post_mime_type);
$query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . ' ' . $order;
if ( 0 < $numberposts )
$query .= $wpdb->prepare(" LIMIT %d,%d", $offset, $numberposts);

View File

@ -89,8 +89,8 @@ class WP_Scripts {
$this->localize( 'swfupload-handlers', 'swfuploadL10n', array(
'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
'file_exceeds_size_limit' => sprintf(__('This file is too big. Your php.ini upload_max_filesize is %s.'), ini_get('upload_max_filesize')),
'zero_byte_file' => __('The file you selected is empty. Please select another file.'),
'invalid_filetype' => __('The file you choose is not an allowed file type.'),
'zero_byte_file' => __('This file is empty. Please try another.'),
'invalid_filetype' => __('This file type is not allowed. Please try another.'),
'default_error' => __('An error occurred in the upload. Please try again later.'),
'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'),
'upload_limit_exceeded' => __('You may only upload 1 file.'),

View File

@ -128,64 +128,6 @@ function shortcode_atts($pairs, $atts) {
return $out;
}
add_shortcode('gallery', 'gallery_shortcode');
function gallery_shortcode($attr) {
global $post;
// Allow plugins/themes to override the default gallery template.
$output = apply_filters('post_gallery', '', $attr);
if ( $output != '' )
return $output;
$attachments = get_children("post_parent=$post->ID&post_type=attachment&orderby=\"menu_order ASC, ID ASC\"");
/*
foreach ( $attachments as $id => $attachment ) {
$meta = get_post_custom($id);
if ( $meta ) foreach ( $meta as $k => $v )
$attachments[$id]->$k = $v;
if ( isset($attachments[$id]->_wp_attachment_metadata[0]) )
$attachments[$id]->meta = unserialize($attachments[$id]->_wp_attachment_metadata[0]);
}
*/
$output = "
<style type='text/css'>
.gallery {
margin: auto;
}
.gallery div {
float: left;
margin-top: 10px;
text-align: center;
width: 33%; }
.gallery img {
border: 2px solid #cfcfcf;
}
</style>
<div class='gallery'>
";
if ( !empty($attachments) ) foreach ( $attachments as $id => $attachment ) {
$src = wp_get_attachment_thumb_url($id);
$href = get_attachment_link($id);
$output .= "
<div>
<a href='$href'><img src='$src' alt='$attachment->post_title' /></a>
</div>
";
if ( ++$i % 3 == 0 )
$output .= '<br style="clear: both" />';
}
$output .= "
<br style='clear: both;' >
</div>
";
return $output;
}
add_filter('the_content', 'do_shortcode');
?>