~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-includes/media.php

  • Committer: Andrew Glen-Young
  • Date: 2011-03-08 14:47:51 UTC
  • Revision ID: andrew.glen-young@canonical.com-20110308144751-1n6spqgayztf9h77
[AGY] import 3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
        $meta = wp_get_attachment_metadata($id);
138
138
        $width = $height = 0;
139
139
        $is_intermediate = false;
 
140
        $img_url_basename = wp_basename($img_url);
140
141
 
141
142
        // plugins can use this to provide resize services
142
143
        if ( $out = apply_filters('image_downsize', false, $id, $size) )
144
145
 
145
146
        // try for a new style intermediate size
146
147
        if ( $intermediate = image_get_intermediate_size($id, $size) ) {
147
 
                $img_url = str_replace(basename($img_url), $intermediate['file'], $img_url);
 
148
                $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
148
149
                $width = $intermediate['width'];
149
150
                $height = $intermediate['height'];
150
151
                $is_intermediate = true;
152
153
        elseif ( $size == 'thumbnail' ) {
153
154
                // fall back to the old thumbnail
154
155
                if ( ($thumb_file = wp_get_attachment_thumb_file($id)) && $info = getimagesize($thumb_file) ) {
155
 
                        $img_url = str_replace(basename($img_url), basename($thumb_file), $img_url);
 
156
                        $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
156
157
                        $width = $info[0];
157
158
                        $height = $info[1];
158
159
                        $is_intermediate = true;
177
178
/**
178
179
 * Registers a new image size
179
180
 */
180
 
function add_image_size( $name, $width = 0, $height = 0, $crop = FALSE ) {
 
181
function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
181
182
        global $_wp_additional_image_sizes;
182
 
        $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => !!$crop );
 
183
        $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool) $crop );
183
184
}
184
185
 
185
186
/**
186
187
 * Registers an image size for the post thumbnail
187
188
 */
188
 
function set_post_thumbnail_size( $width = 0, $height = 0, $crop = FALSE ) {
 
189
function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
189
190
        add_image_size( 'post-thumbnail', $width, $height, $crop );
190
191
}
191
192
 
436
437
        $info = pathinfo($file);
437
438
        $dir = $info['dirname'];
438
439
        $ext = $info['extension'];
439
 
        $name = basename($file, ".{$ext}");
 
440
        $name = wp_basename($file, ".$ext");
 
441
 
440
442
        if ( !is_null($dest_path) and $_dest_path = realpath($dest_path) )
441
443
                $dir = $_dest_path;
442
444
        $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
485
487
                if ( !is_wp_error($resized_file) && $resized_file && $info = getimagesize($resized_file) ) {
486
488
                        $resized_file = apply_filters('image_make_intermediate_size', $resized_file);
487
489
                        return array(
488
 
                                'file' => basename( $resized_file ),
 
490
                                'file' => wp_basename( $resized_file ),
489
491
                                'width' => $info[0],
490
492
                                'height' => $info[1],
491
493
                        );
606
608
 
607
609
        if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
608
610
                $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );
609
 
                $src_file = $icon_dir . '/' . basename($src);
 
611
                $src_file = $icon_dir . '/' . wp_basename($src);
610
612
                @list($width, $height) = getimagesize($src_file);
611
613
        }
612
614
        if ( $src && $width && $height )
821
823
 
822
824
        $selector = "gallery-{$instance}";
823
825
 
824
 
        $output = apply_filters('gallery_style', "
 
826
        $gallery_style = $gallery_div = '';
 
827
        if ( apply_filters( 'use_default_gallery_style', true ) )
 
828
                $gallery_style = "
825
829
                <style type='text/css'>
826
830
                        #{$selector} {
827
831
                                margin: auto;
830
834
                                float: {$float};
831
835
                                margin-top: 10px;
832
836
                                text-align: center;
833
 
                                width: {$itemwidth}%;                   }
 
837
                                width: {$itemwidth}%;
 
838
                        }
834
839
                        #{$selector} img {
835
840
                                border: 2px solid #cfcfcf;
836
841
                        }
838
843
                                margin-left: 0;
839
844
                        }
840
845
                </style>
841
 
                <!-- see gallery_shortcode() in wp-includes/media.php -->
842
 
                <div id='$selector' class='gallery galleryid-{$id}'>");
 
846
                <!-- see gallery_shortcode() in wp-includes/media.php -->";
 
847
        $size_class = sanitize_html_class( $size );
 
848
        $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
 
849
        $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
843
850
 
844
851
        $i = 0;
845
852
        foreach ( $attachments as $id => $attachment ) {
852
859
                        </{$icontag}>";
853
860
                if ( $captiontag && trim($attachment->post_excerpt) ) {
854
861
                        $output .= "
855
 
                                <{$captiontag} class='gallery-caption'>
 
862
                                <{$captiontag} class='wp-caption-text gallery-caption'>
856
863
                                " . wptexturize($attachment->post_excerpt) . "
857
864
                                </{$captiontag}>";
858
865
                }
960
967
 *
961
968
 * @since 2.9.0
962
969
 *
963
 
 * @param $mime_type string
 
970
 * @param string $mime_type
964
971
 * @return bool
965
972
 */
966
973
function gd_edit_image_support($mime_type) {
991
998
 *
992
999
 * @since 2.9.0
993
1000
 *
994
 
 * @param $width
995
 
 * @param $height
 
1001
 * @param int $width Image width
 
1002
 * @param int $height Image height
996
1003
 * @return image resource
997
1004
 */
998
1005
function wp_imagecreatetruecolor($width, $height) {
1063
1070
        function run_shortcode( $content ) {
1064
1071
                global $shortcode_tags;
1065
1072
 
1066
 
                // Backup current registered shortcodes and clear them all out
 
1073
                // Back up current registered shortcodes and clear them all out
1067
1074
                $orig_shortcode_tags = $shortcode_tags;
1068
1075
                remove_all_shortcodes();
1069
1076
 
1156
1163
                $rawattr = $attr;
1157
1164
                $attr = wp_parse_args( $attr, wp_embed_defaults() );
1158
1165
 
 
1166
                // kses converts & into &amp; and we need to undo this
 
1167
                // See http://core.trac.wordpress.org/ticket/11311
 
1168
                $url = str_replace( '&amp;', '&', $url );
 
1169
 
1159
1170
                // Look for known internal handlers
1160
1171
                ksort( $this->handlers );
1161
1172
                foreach ( $this->handlers as $priority => $handlers ) {
1184
1195
                                        return $this->maybe_make_link( $url );
1185
1196
 
1186
1197
                                if ( !empty($cache) )
1187
 
                                        return apply_filters( 'embed_oembed_html', $cache, $url, $attr );
 
1198
                                        return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID );
1188
1199
                        }
1189
1200
 
1190
1201
                        // Use oEmbed to get the HTML
1197
1208
 
1198
1209
                        // If there was a result, return it
1199
1210
                        if ( $html )
1200
 
                                return apply_filters( 'embed_oembed_html', $html, $url, $attr );
 
1211
                                return apply_filters( 'embed_oembed_html', $html, $url, $attr, $post_ID );
1201
1212
                }
1202
1213
 
1203
1214
                // Still unknown
1394
1405
        require_once( ABSPATH . WPINC . '/class-oembed.php' );
1395
1406
        $oembed = _wp_oembed_get_object();
1396
1407
        $oembed->providers[$format] = array( $provider, $regex );
1397
 
}
 
1408
}
 
 
b'\\ No newline at end of file'