Plugin Directory

Changeset 203588


Ignore:
Timestamp:
02/09/2010 10:08:59 PM (16 years ago)
Author:
achmafooma
Message:

Re-sync with WP 2.9 code for GSSTH 1.3

Location:
gallery-shortcode-style-to-head/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gallery-shortcode-style-to-head/trunk/gallery-shortcode-style-to-head.php

    r156582 r203588  
    66Author: Scott Bradford
    77Author URI: http://www.scottbradford.us/
    8 Version: 1.2
     8Version: 1.3
    99
    1010        Copyright (c) 2008 Matt Martz (http://sivel.net) (original author)
    11         Copyright (c) 2009 Scott Bradford (http://www.scottbradford.us) (current maintainer)
     11        Copyright (c) 2009-2010 Scott Bradford (http://www.scottbradford.us) (current maintainer)
    1212       
    1313    Gallery Shortcode Style to Head is released under the GNU General Public License (GPL)
     
    1818// http://trac.wordpress.org/attachment/ticket/6380/6380-style.diff
    1919function gallery_shortcode_style_out ( $attr ) {
    20     global $post;
     20    global $post, $wp_locale;
     21
     22    static $instance = 0;
     23    $instance++;
    2124
    2225    // Allow plugins/themes to override the default gallery template.
    23     $output = apply_filters ( 'post_gallery' , '' , $attr );
     26    $output = apply_filters('post_gallery', '', $attr);
    2427    if ( $output != '' )
    2528        return $output;
     
    3235    }
    3336
    34     extract ( shortcode_atts ( apply_filters ( 'gallery_defaults' , array(
     37    extract(shortcode_atts(array(
    3538        'order'      => 'ASC',
    3639        'orderby'    => 'menu_order ID',
     
    4144        'columns'    => 3,
    4245        'size'       => 'thumbnail',
    43     ) ) , $attr ) );
     46        'include'    => '',
     47        'exclude'    => ''
     48    ), $attr));
    4449
    45     $id = intval ( $id );
    46     $attachments = get_children ( array ( 'post_parent' => $id , 'post_status' => 'inherit' , 'post_type' => 'attachment' , 'post_mime_type' => 'image' , 'order' => $order , 'orderby' => $orderby ) );
     50    $id = intval($id);
     51    if ( 'RAND' == $order )
     52        $orderby = 'none';
    4753
    48     if ( empty( $attachments ) )
     54    if ( !empty($include) ) {
     55        $include = preg_replace( '/[^0-9,]+/', '', $include );
     56        $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
     57
     58        $attachments = array();
     59        foreach ( $_attachments as $key => $val ) {
     60            $attachments[$val->ID] = $_attachments[$key];
     61        }
     62    } elseif ( !empty($exclude) ) {
     63        $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
     64        $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
     65    } else {
     66        $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
     67    }
     68
     69    if ( empty($attachments) )
    4970        return '';
    5071
    5172    if ( is_feed() ) {
    5273        $output = "\n";
    53         foreach ( $attachments as $id => $attachment )
    54             $output .= wp_get_attachment_link( $id, $size, false ) . "\n";
     74        foreach ( $attachments as $att_id => $attachment )
     75            $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
    5576        return $output;
    5677    }
    5778
    58     $listtag = tag_escape ( $listtag );
    59     $itemtag = tag_escape ( $itemtag );
    60     $captiontag = tag_escape ( $captiontag );
    61     $columns = intval ( $columns );
    62     $itemwidth = $columns > 0 ? floor ( 100/$columns ) : 100;
     79    $itemtag = tag_escape($itemtag);
     80    $captiontag = tag_escape($captiontag);
     81    $columns = intval($columns);
     82    $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
    6383   
    64     $output = "
    65         <!-- see gallery_shortcode() in wp-includes/media.php -->
    66         <div class='gallery'>";
     84    $selector = "gallery-{$instance}";
    6785
     86    $output = "<!-- see gallery_shortcode() in wp-includes/media.php -->
     87        <div id='$selector' class='gallery galleryid-{$id}'>";
     88
     89    $i = 0;
    6890    foreach ( $attachments as $id => $attachment ) {
    6991        $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
     92
    7093        $output .= "<{$itemtag} class='gallery-item' style='width:{$itemwidth}%'>";
    7194        $output .= "
     
    7396                $link
    7497            </{$icontag}>";
    75         if ( $captiontag && trim ( $attachment->post_excerpt ) ) {
     98        if ( $captiontag && trim($attachment->post_excerpt) ) {
    7699            $output .= "
    77100                <{$captiontag} class='gallery-caption'>
     
    95118function gallery_style () {
    96119
    97 $output = apply_filters('gallery_style', "
    98 <!-- [gallery] shortcode style -->
     120$float = $wp_locale->text_direction == 'rtl' ? 'right' : 'left';
     121$output = apply_filters('gallery_style', "<!-- [gallery] shortcode style -->
    99122<style type='text/css'>
    100        .gallery {
    101                 margin: auto;
    102         }
    103         .gallery-item {
    104                 float: left;
    105                 margin-top: 10px;
    106                 text-align: center;
     123    .gallery {
     124        margin: auto;
    107125    }
    108         .gallery img {
    109                 border: 2px solid #cfcfcf;
    110         }
    111         .gallery-caption {
    112                 margin-left: 0;
    113         }
    114 </style>
    115 ");
     126    .gallery .gallery-item {
     127        float: {$float};
     128        margin-top: 10px;
     129        text-align: center;
     130    }
     131    .gallery img {
     132        border: 2px solid #cfcfcf;
     133    }
     134    .gallery-caption {
     135        margin-left: 0;
     136    }
     137</style>");
    116138 
    117139echo $output;
     
    136158// Tell WordPress what to do
    137159remove_shortcode ( 'gallery_shortcode' );           // Remove included WordPress [gallery] shortcode function
    138 add_shortcode ( 'gallery' , 'gallery_shortcode_style_out' );    // Add not [gallery] shortcode function
     160add_shortcode ( 'gallery' , 'gallery_shortcode_style_out' );    // Add new [gallery] shortcode function
    139161add_action ( 'template_redirect' , 'gallery_scan' );        // Add look ahead for [gallery] shortcode
    140162?>
  • gallery-shortcode-style-to-head/trunk/readme.txt

    r183655 r203588  
    44Requires at least: 2.6
    55Tested up to: 2.9
    6 Stable tag: 1.2
     6Stable tag: 1.3
    77
    88Moves the gallery shortcode styles to the head so it doesn't break XHTML
     
    4949== Changelog ==
    5050
    51 = 1.2.1 (2009-12-16): =
    52 * Iterated the supported WordPress version to 2.9.
     51= 1.3 (2010-02-09): =
     52* Re-Sync with WordPress 2.9 gallery code for support of the new 'include' and 'exclude' options.
    5353
    5454= 1.2 (2009-09-20): =
Note: See TracChangeset for help on using the changeset viewer.