Make WordPress Core


Ignore:
Timestamp:
05/15/2014 03:40:46 AM (12 years ago)
Author:
wonderboymusic
Message:

Eliminate use of extract() in gallery_shortcode().

See #22400.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r28377 r28414  
    912912        if ( ! empty( $attr['ids'] ) ) {
    913913                // 'ids' is explicitly ordered, unless you specify otherwise.
    914                 if ( empty( $attr['orderby'] ) )
     914                if ( empty( $attr['orderby'] ) ) {
    915915                        $attr['orderby'] = 'post__in';
     916                }
    916917                $attr['include'] = $attr['ids'];
    917918        }
     
    931932         */
    932933        $output = apply_filters( 'post_gallery', '', $attr );
    933         if ( $output != '' )
     934        if ( $output != '' ) {
    934935                return $output;
     936        }
    935937
    936938        // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
    937939        if ( isset( $attr['orderby'] ) ) {
    938940                $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
    939                 if ( !$attr['orderby'] )
     941                if ( ! $attr['orderby'] ) {
    940942                        unset( $attr['orderby'] );
     943                }
    941944        }
    942945
    943946        $html5 = current_theme_supports( 'html5', 'gallery' );
    944         extract(shortcode_atts(array(
     947        $atts = shortcode_atts( array(
    945948                'order'      => 'ASC',
    946949                'orderby'    => 'menu_order ID',
     
    954957                'exclude'    => '',
    955958                'link'       => ''
    956         ), $attr, 'gallery'));
    957 
    958         $id = intval($id);
    959         if ( 'RAND' == $order )
    960                 $orderby = 'none';
    961 
    962         if ( !empty($include) ) {
    963                 $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
     959        ), $attr, 'gallery' );
     960
     961        $id = intval( $atts['id'] );
     962        if ( 'RAND' == $atts['order'] ) {
     963                $atts['orderby'] = 'none';
     964        }
     965
     966        if ( ! empty( $atts['include'] ) ) {
     967                $_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
    964968
    965969                $attachments = array();
     
    967971                        $attachments[$val->ID] = $_attachments[$key];
    968972                }
    969         } elseif ( !empty($exclude) ) {
    970                 $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
     973        } elseif ( ! empty( $atts['exclude'] ) ) {
     974                $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
    971975        } else {
    972                 $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
    973         }
    974 
    975         if ( empty($attachments) )
     976                $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
     977        }
     978
     979        if ( empty( $attachments ) ) {
    976980                return '';
     981        }
    977982
    978983        if ( is_feed() ) {
    979984                $output = "\n";
    980                 foreach ( $attachments as $att_id => $attachment )
    981                         $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
     985                foreach ( $attachments as $att_id => $attachment ) {
     986                        $output .= wp_get_attachment_link( $att_id, $atts['size'], true ) . "\n";
     987                }
    982988                return $output;
    983989        }
    984990
    985         $itemtag = tag_escape($itemtag);
    986         $captiontag = tag_escape($captiontag);
    987         $icontag = tag_escape($icontag);
     991        $itemtag = tag_escape( $atts['itemtag'] );
     992        $captiontag = tag_escape( $atts['captiontag'] );
     993        $icontag = tag_escape( $atts['icontag'] );
    988994        $valid_tags = wp_kses_allowed_html( 'post' );
    989         if ( ! isset( $valid_tags[ $itemtag ] ) )
     995        if ( ! isset( $valid_tags[ $itemtag ] ) ) {
    990996                $itemtag = 'dl';
    991         if ( ! isset( $valid_tags[ $captiontag ] ) )
     997        }
     998        if ( ! isset( $valid_tags[ $captiontag ] ) ) {
    992999                $captiontag = 'dd';
    993         if ( ! isset( $valid_tags[ $icontag ] ) )
     1000        }
     1001        if ( ! isset( $valid_tags[ $icontag ] ) ) {
    9941002                $icontag = 'dt';
    995 
    996         $columns = intval($columns);
     1003        }
     1004
     1005        $columns = intval( $atts['columns'] );
    9971006        $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
    9981007        $float = is_rtl() ? 'right' : 'left';
     
    10331042        }
    10341043
    1035         $size_class = sanitize_html_class( $size );
     1044        $size_class = sanitize_html_class( $atts['size'] );
    10361045        $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
    10371046
     
    10481057        $i = 0;
    10491058        foreach ( $attachments as $id => $attachment ) {
    1050                 if ( ! empty( $link ) && 'file' === $link )
    1051                         $image_output = wp_get_attachment_link( $id, $size, false, false );
    1052                 elseif ( ! empty( $link ) && 'none' === $link )
    1053                         $image_output = wp_get_attachment_image( $id, $size, false );
    1054                 else
    1055                         $image_output = wp_get_attachment_link( $id, $size, true, false );
    1056 
     1059                if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) {
     1060                        $image_output = wp_get_attachment_link( $id, $atts['size'], false, false );
     1061                } elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) {
     1062                        $image_output = wp_get_attachment_image( $id, $atts['size'], false );
     1063                } else {
     1064                        $image_output = wp_get_attachment_link( $id, $atts['size'], true, false );
     1065                }
    10571066                $image_meta  = wp_get_attachment_metadata( $id );
    10581067
    10591068                $orientation = '';
    1060                 if ( isset( $image_meta['height'], $image_meta['width'] ) )
     1069                if ( isset( $image_meta['height'], $image_meta['width'] ) ) {
    10611070                        $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
    1062 
     1071                }
    10631072                $output .= "<{$itemtag} class='gallery-item'>";
    10641073                $output .= "
Note: See TracChangeset for help on using the changeset viewer.