]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/media.php
Wizard 2.8.2-scripts
[autoinstalls/wordpress.git] / wp-includes / media.php
index 58feaf3ab1ef2868f9f88e91a13a6d4410edb52e..7f34963842d7d62b93ba7de00bcf74945ac28188 100644 (file)
@@ -200,10 +200,10 @@ function get_image_tag($id, $alt, $title, $align, $size='medium') {
        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 );
 
@@ -231,10 +231,10 @@ function wp_constrain_dimensions( $current_width, $current_height, $max_width=0,
 
        $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
@@ -378,7 +378,7 @@ function image_resize( $file, $max_w, $max_h, $crop=false, $suffix=null, $dest_p
        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' ));
        }
 
@@ -503,6 +503,8 @@ function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon =
        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);
@@ -514,9 +516,10 @@ function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon =
 }
 
 /**
- * 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.
@@ -533,7 +536,20 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa
                $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;
@@ -578,7 +594,7 @@ function img_caption_shortcode($attr, $content = null) {
        if ( $id ) $id = 'id="' . $id . '" ';
 
        return '<div ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . (10 + (int) $width) . 'px">'
-       . $content . '<p class="wp-caption-text">' . $caption . '</p></div>';
+       . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
 }
 
 add_shortcode('gallery', 'gallery_shortcode');
@@ -597,6 +613,9 @@ 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 != '' )
@@ -628,8 +647,8 @@ function gallery_shortcode($attr) {
 
        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;
        }
 
@@ -638,25 +657,27 @@ function gallery_shortcode($attr) {
        $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 ) {
@@ -670,7 +691,7 @@ function gallery_shortcode($attr) {
                if ( $captiontag && trim($attachment->post_excerpt) ) {
                        $output .= "
                                <{$captiontag} class='gallery-caption'>
-                               {$attachment->post_excerpt}
+                               " . wptexturize($attachment->post_excerpt) . "
                                </{$captiontag}>";
                }
                $output .= "</{$itemtag}>";
@@ -689,18 +710,24 @@ function gallery_shortcode($attr) {
  * 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);
 }
 
 /**
@@ -712,7 +739,7 @@ function next_image_link() {
  *
  * @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') ));
@@ -724,7 +751,7 @@ function adjacent_image_link($prev = true) {
        $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);
 }
 
 /**