list( $img_src, $width, $height ) = image_downsize($id, $size);
$hwstring = image_hwstring($width, $height);
- $class = 'align'.attribute_escape($align).' size-'.attribute_escape($size).' wp-image-'.$id;
+ $class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;
$class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
- $html = '<img src="'.attribute_escape($img_src).'" alt="'.attribute_escape($alt).'" title="'.attribute_escape($title).'" '.$hwstring.'class="'.$class.'" />';
+ $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title).'" '.$hwstring.'class="'.$class.'" />';
$html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
$width_ratio = $height_ratio = 1.0;
- if ( $max_width > 0 && $current_width > $max_width )
+ if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width )
$width_ratio = $max_width / $current_width;
- if ( $max_height > 0 && $current_height > $max_height )
+ if ( $max_height > 0 && $current_height > 0 && $current_height > $max_height )
$height_ratio = $max_height / $current_height;
// the smaller ratio is the one we need to fit it to the constraining box
else {
// all other formats are converted to jpg
$destfilename = "{$dir}/{$name}-{$suffix}.jpg";
- if (!imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality ) ) )
+ if (!imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
}
if ( $image = image_downsize($attachment_id, $size) )
return $image;
+ $src = false;
+
if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );
$src_file = $icon_dir . '/' . basename($src);
}
/**
- * Retrieve img HTML content for an image to represent an attachment.
+ * Get an HTML img element representing an image attachment
*
- * @see wp_get_attachment_image_src() Returns img HTML element based on array.
+ * @uses apply_filters() Calls 'wp_get_attachment_image_attributes' hook on attributes array
+ * @uses wp_get_attachment_image_src() Gets attachment file URL and dimensions
* @since 2.5.0
*
* @param int $attachment_id Image attachment ID.
$hwstring = image_hwstring($width, $height);
if ( is_array($size) )
$size = join('x', $size);
- $html = '<img src="'.attribute_escape($src).'" '.$hwstring.'class="attachment-'.attribute_escape($size).'" alt="" />';
+ $attachment =& get_post($attachment_id);
+ $attr = array(
+ 'src' => $src,
+ 'class' => "attachment-$size",
+ 'alt' => trim(strip_tags( $attachment->post_excerpt )),
+ 'title' => trim(strip_tags( $attachment->post_title )),
+ );
+ $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment );
+ $attr = array_map( 'esc_attr', $attr );
+ $html = rtrim("<img $hwstring");
+ foreach ( $attr as $name => $value ) {
+ $html .= " $name=" . '"' . $value . '"';
+ }
+ $html .= ' />';
}
return $html;
if ( 1 > (int) $width || empty($caption) )
return $content;
- if ( $id ) $id = 'id="' . $id . '" ';
+ if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
- return '<div ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . (10 + (int) $width) . 'px">'
- . $content . '<p class="wp-caption-text">' . $caption . '</p></div>';
+ return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
+ . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
}
add_shortcode('gallery', 'gallery_shortcode');
function gallery_shortcode($attr) {
global $post;
+ static $instance = 0;
+ $instance++;
+
// Allow plugins/themes to override the default gallery template.
$output = apply_filters('post_gallery', '', $attr);
if ( $output != '' )
if ( is_feed() ) {
$output = "\n";
- foreach ( $attachments as $id => $attachment )
- $output .= wp_get_attachment_link($id, $size, true) . "\n";
+ foreach ( $attachments as $att_id => $attachment )
+ $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
return $output;
}
$columns = intval($columns);
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
+ $selector = "gallery-{$instance}";
+
$output = apply_filters('gallery_style', "
<style type='text/css'>
- .gallery {
+ #{$selector} {
margin: auto;
}
- .gallery-item {
+ #{$selector} .gallery-item {
float: left;
margin-top: 10px;
text-align: center;
width: {$itemwidth}%; }
- .gallery img {
+ #{$selector} img {
border: 2px solid #cfcfcf;
}
- .gallery-caption {
+ #{$selector} .gallery-caption {
margin-left: 0;
}
</style>
<!-- see gallery_shortcode() in wp-includes/media.php -->
- <div class='gallery'>");
+ <div id='$selector' class='gallery galleryid-{$id}'>");
$i = 0;
foreach ( $attachments as $id => $attachment ) {
if ( $captiontag && trim($attachment->post_excerpt) ) {
$output .= "
<{$captiontag} class='gallery-caption'>
- {$attachment->post_excerpt}
+ " . wptexturize($attachment->post_excerpt) . "
</{$captiontag}>";
}
$output .= "</{$itemtag}>";
* Display previous image link that has the same post parent.
*
* @since 2.5.0
+ * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 0 or 'none' will default to post_title or $text;
+ * @param string $text Optional, default is false. If included, link will reflect $text variable.
+ * @return string HTML content.
*/
-function previous_image_link() {
- adjacent_image_link(true);
+function previous_image_link($size = 'thumbnail', $text = false) {
+ adjacent_image_link(true, $size, $text);
}
/**
* Display next image link that has the same post parent.
*
* @since 2.5.0
+ * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 0 or 'none' will default to post_title or $text;
+ * @param string $text Optional, default is false. If included, link will reflect $text variable.
+ * @return string HTML content.
*/
-function next_image_link() {
- adjacent_image_link(false);
+function next_image_link($size = 'thumbnail', $text = false) {
+ adjacent_image_link(false, $size, $text);
}
/**
*
* @param bool $prev Optional. Default is true to display previous link, true for next.
*/
-function adjacent_image_link($prev = true) {
+function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) {
global $post;
$post = get_post($post);
$attachments = array_values(get_children( array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') ));
$k = $prev ? $k - 1 : $k + 1;
if ( isset($attachments[$k]) )
- echo wp_get_attachment_link($attachments[$k]->ID, 'thumbnail', true);
+ echo wp_get_attachment_link($attachments[$k]->ID, $size, true, false, $text);
}
/**