Plugin Directory

Changeset 538292


Ignore:
Timestamp:
04/30/2012 07:11:23 PM (14 years ago)
Author:
eddiemoya
Message:

version 1.2, adding category support to gallery shortcode, cat search is now case insensitive, fixed styling on plupload modals

Location:
media-categories-2
Files:
1 deleted
3 edited
4 copied

Legend:

Unmodified
Added
Removed
  • media-categories-2/tags/1.2/media-categories-script.js

    r495667 r538292  
     1
     2
     3
    14jQuery(document).ready(function($){
    25   
     
    1619        });
    1720       
    18 
    1921        form_fields.find("tr.category > td.field > input.text").val(slug_list);
    2022    })
    2123   
    22    
    23      
     24    $.extend($.expr[":"], {
     25        "icontains": function(elem, i, match, array) {
     26            return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
     27        }
     28    });
    2429    /**
    2530     * The following javascript is borrowed from Jason Corradino's 'Searchable Categories' plugin.
     
    3035     */
    3136   
    32     jQuery('#catsearch').keyup(function() {
    33         var val = jQuery('#catsearch').val(), lis = jQuery("#categorychecklist li");
     37    $('#catsearch').keyup(function() {
     38        var val = $('#catsearch').val(), lis = $("#categorychecklist li");
    3439
    3540        lis.hide();
    36                            // find li labels's containing term, then back to parent li
    37         var containingLabels = jQuery("#categorychecklist label:contains('" + val + "')");
     41       
     42        // find li labels's containing term, then back to parent li
     43        var containingLabels = $("#categorychecklist label:icontains('" + val + "')");
    3844        containingLabels.closest('li').find('li').andSelf().show();
    3945        containingLabels.parents('#categorychecklist li').show();
  • media-categories-2/tags/1.2/media-categories.php

    r519154 r538292  
    33  Plugin Name: Media Categories
    44  Plugin URI: http://wordpress.org/extend/plugins/media-categories-2
    5   Description:  Allows users to assign categories to items in their Media Library with a clean and simplified, filterable version of the standard category metabox
    6   Version: 1.1
     5  Description:  Allows users to assign categories to media with a clean and simplified, filterable category meta box and use shortcodes to display category galleries
     6  Version: 1.2
    77  Author: Eddie Moya
    88  Author URL: http://eddiemoya.com
     
    1212
    1313    /**
     14     * Start your engines.
     15     *
    1416     * @author Eddie Moya
    15      *
    16      * Start your engines.
    1717     */
    1818    function init() {
    19         add_action('admin_init', array(__CLASS__, 'register_media_categories'));
     19        add_action('init', array(__CLASS__, 'register_media_categories'));
     20        add_action('init', array(__CLASS__, 'custom_gallery_shortcode'));
    2021        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_scripts'));
    21         add_action('admin_print_styles-media.php', array(__CLASS__, 'enqueue_media_categories_styles') );
     22        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_styles') );
    2223        add_filter('attachment_fields_to_edit', array(__CLASS__, 'add_media_categories_metabox'), null, 2);
    23     }
     24       
     25    }
     26
    2427
    2528    function enqueue_media_categories_scripts() {
     
    2831            wp_register_script('media_categories_metabox_script', WP_PLUGIN_URL . '/media-categories-2/media-categories-script.js');
    2932            wp_enqueue_script('media_categories_metabox_script');
    30 
    3133        }
    3234    }
     
    3840            wp_enqueue_style( 'media_categories_metabox_style');
    3941        }
    40    
    4142    }
    4243
     
    8485    function media_categories_meta_box($post, $box) {
    8586       
    86         require_once(WP_PLUGIN_DIR . '/media-categories-2/attachment-walker-category-checklist-class.php');
     87        require_once(plugin_dir_path(__FILE__) . 'attachment-walker-category-checklist-class.php');
    8788         
    8889        $defaults = array('taxonomy' => 'category');
     
    9596        ?>
    9697        <div>
    97             <label class='category-filter' for="category-filter">Filter Categories:</label>
     98            <label class='category-filter' for="category-filter">Search Categories:</label>
    9899            <input id='catsearch' name="category-filter" type='text' /></div>
    99100        <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
     
    149150    }
    150151
     152    function custom_gallery_shortcode(){
     153        remove_shortcode('gallery');
     154        add_shortcode('gallery', array(__CLASS__,'gallery_shortcode'));
     155    }
     156   
     157    /**
     158     * The Gallery shortcode with category parameter.
     159     *
     160     * This implements the functionality of the Gallery Shortcode for displaying
     161     * WordPress images on a post.
     162     *
     163     * Almost Identical to the gallery_shortcode() function in /wp-includes/media.php
     164     * but adds a category parameter to the shortcode.
     165     *
     166     * @since 1.2
     167     * @since WordPress 2.6.0
     168     *
     169     * @param array $attr Attributes of the shortcode.
     170     * @return string HTML content to display gallery.
     171     */
     172    function gallery_shortcode($attr) {
     173        global $post;
     174
     175        static $instance = 0;
     176        $instance++;
     177
     178        // Allow plugins/themes to override the default gallery template.
     179        $output = apply_filters('post_gallery', '', $attr);
     180        if ( $output != '' )
     181            return $output;
     182
     183        // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
     184        if ( isset( $attr['orderby'] ) ) {
     185            $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
     186            if ( !$attr['orderby'] )
     187                unset( $attr['orderby'] );
     188        }
     189
     190        extract(shortcode_atts(array(
     191            'order'      => 'ASC',
     192            'orderby'    => 'menu_order ID',
     193            'id'         => $post->ID,
     194            'itemtag'    => 'dl',
     195            'icontag'    => 'dt',
     196            'captiontag' => 'dd',
     197            'columns'    => 3,
     198            'size'       => 'thumbnail',
     199            'include'    => '',
     200            'exclude'    => '',
     201            'category'   => ''
     202        ), $attr));
     203       
     204        $id = intval($id);
     205        if ( 'RAND' == $order )
     206            $orderby = 'none';
     207
     208        if( !empty($category) ){
     209            if(!is_numeric($category))
     210                $category = get_category_by_slug($category)->term_id;
     211
     212            if(!isset($attr['id']))
     213                $id = '';
     214        }
     215       
     216        if ( !empty($include) ) {
     217            $include = preg_replace( '/[^0-9,]+/', '', $include );
     218            $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) );
     219
     220            $attachments = array();
     221            foreach ( $_attachments as $key => $val ) {
     222                $attachments[$val->ID] = $_attachments[$key];
     223            }
     224        } elseif ( !empty($exclude) ) {
     225            $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
     226            $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) );
     227        } else {
     228            $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) );
     229        }
     230
     231        if ( empty($attachments) )
     232            return '';
     233
     234        if ( is_feed() ) {
     235            $output = "\n";
     236            foreach ( $attachments as $att_id => $attachment )
     237                $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
     238            return $output;
     239        }
     240
     241        $itemtag = tag_escape($itemtag);
     242        $captiontag = tag_escape($captiontag);
     243        $columns = intval($columns);
     244        $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
     245        $float = is_rtl() ? 'right' : 'left';
     246
     247        $selector = "gallery-{$instance}";
     248
     249        $gallery_style = $gallery_div = '';
     250        if ( apply_filters( 'use_default_gallery_style', true ) )
     251            $gallery_style = "
     252            <style type='text/css'>
     253                #{$selector} {
     254                    margin: auto;
     255                }
     256                #{$selector} .gallery-item {
     257                    float: {$float};
     258                    margin-top: 10px;
     259                    text-align: center;
     260                    width: {$itemwidth}%;
     261                }
     262                #{$selector} img {
     263                    border: 2px solid #cfcfcf;
     264                }
     265                #{$selector} .gallery-caption {
     266                    margin-left: 0;
     267                }
     268            </style>
     269            <!-- see gallery_shortcode() in wp-includes/media.php -->";
     270        $size_class = sanitize_html_class( $size );
     271        $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
     272        $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
     273
     274        $i = 0;
     275        foreach ( $attachments as $id => $attachment ) {
     276            $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
     277
     278            $output .= "<{$itemtag} class='gallery-item'>";
     279            $output .= "
     280                <{$icontag} class='gallery-icon'>
     281                    $link
     282                </{$icontag}>";
     283            if ( $captiontag && trim($attachment->post_excerpt) ) {
     284                $output .= "
     285                    <{$captiontag} class='wp-caption-text gallery-caption'>
     286                    " . wptexturize($attachment->post_excerpt) . "
     287                    </{$captiontag}>";
     288            }
     289            $output .= "</{$itemtag}>";
     290            if ( $columns > 0 && ++$i % $columns == 0 )
     291                $output .= '<br style="clear: both" />';
     292        }
     293
     294        $output .= "
     295                <br style='clear: both;' />
     296            </div>\n";
     297
     298        return $output;
     299    }
    151300}
    152301
  • media-categories-2/tags/1.2/readme.txt

    r495667 r538292  
    22Contributors: eddiemoya
    33Donate link: http://eddiemoya.com
    4 Tags: media categories, media, category, categories, attachment categories, taxonomy, category metabox, metabox, admin, media library, media editor, attachment editor, attachment
     4Tags: media categories, media, category, categories, attachment categories, taxonomy, category metabox, metabox, admin, media library, media editor, attachment editor, attachment, images, gallery shortcode, gallery, shortcode, gallery category
    55Requires at least: 3.0
    66Tested up to: 3.3.1
    7 Stable tag: trunk
     7Stable tag: 1.2
    88
    9 Allows users to assign categories to items in their Media Library with a clean and simplified, filterable version of the standard category meta box
     9Easily assign categories to media with a clean, simple, and searchable category meta box. Then use the gallery shortcode to display category galleries
    1010
    1111== Description ==
    1212
    13 Allows users to assign categories to items in their Media Library with a clean and simplified, filterable version of the standard category meta box.
    14 The filter allows you to narrow your search for category as you type - this filter is not native to WordPress but is instead borrowed from Jason Corradino's
    15 [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. If you would like to enable this feature for your posts and pages
     13Allows users to assign categories to items in their Media Library with a clean and simplified, searchable version of the standard category meta box.
     14The "Search Categories" field allows you to narrow your search for a category as you type - this functionality is not native to WordPress but is instead borrowed from Jason Corradino's
     15[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. If you would like to enable this feature for your posts
    1616[download his plugin here](http://wordpress.org/extend/plugins/searchable-categories/)
     17
     18NEW! Since version 1.2 this plugin extends the native [gallery] shortcode of WordPress so that it has a 'category' parameter. See the "Shortcode Usage" under "Other Notes" for more details.
     19
     20
     21== Shortcode Usage ==
     22
     23This plugin takes advantage of the existing `[gallery]` shortcode for showing images by adding the `'category'` parameter.
     24The value passed to the `'category'` parameter can be either the `category` `slug`, or the `term_id`.
     25
     26`[gallery category="my-category-slug"]
     27OR
     28[gallery category="12"]`
     29
     30Its important to note that when passing the `'category'` parameter, the `[gallery]` shortcode will by default **ignore the current post
     31and simply try to include all images from the category**. The syntax above will retrieve any images that are assigned
     32to `'my-category-slug'` a.k.a term id `#12`, regardless of whether or not those images are attached to the current post.
     33
     34To query within a post (even the current post), you'll need to explicitly add the post id as such...
     35
     36`[gallery category="my-category-slug" id="43"]`
     37
     38This shortcode will retreive any images attached to post `#43` that are categorized as `'my-slug-category'`.
     39
     40Aside from this behavior, the [gallery] shortcode should behave exactly as it does by default with the built-in shortcode.
     41The `id` parameter will behave as normal when the `category` parameter is not invoked.
     42For more information on using the built-in [gallery shortcode checkout the codex page](http://codex.wordpress.org/Gallery_Shortcode).
    1743
    1844== Related Plugins ==
    1945
    20 As stated in the description, the filtering ability in this plugin is taken from Jason Corradino's
     46As stated in the description, the search functionality in this plugin is taken from Jason Corradino's
    2147[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. While I do
    22 not employ the plugin directory, the javascript used for filtering is in fact derived with consent from
     48not employ the plugin directly, the javascript used for filtering is in fact derived with consent from
    2349that plugin. To enable this feature on all you category metabox, the
    2450[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin
    2551
    26 I'd like to point out that I drew some inspiration from the ['WOS Media Categories'](http://suburbia.org.uk/page/projects.html#wos_media_categories) plugin which
    27 is not generally easy to find since its not in the plugin directory. However [WOS Media Categories](http://suburbia.org.uk/page/projects.html#wos_media_categories)
    28 was missing the clean simple to use hierarchical category interface that we are used to in
    29 WordPress. A couple of my projects were dependant that plugin, but as the scale of the project
    30 increased and the number of categories grew exponentially, the disorganized grid of checkboxes
    31 were no longer a viable option.
    32 
    3352= TL;DR =
    34 Checkout these related plugins from which I borrowed code and drew inspiration.
     53Checkout this great plugin for Searchable Categories by Jason Corradino, whose javascript I use in this plugin.
     54I believe this very simple functionality should be a part of the standard categories metabox in core.
    3555
    3656* [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) by Jason Corradino
    37 * [WOS Media Categories](http://suburbia.org.uk/page/projects.html#wos_media_categories) by Rick Curran
    38 
    39 WOS is not as relevant since this plugin supplants that one, but the Searchable Categories plugin is a
    40 great simple plugin which adds very useful functionality that I think should be included in WordPress Core.
    4157
    4258== Screenshots ==
    4359
    44 1. This plugin will include clean, simple to use, filterable categories to your Media Editor page.
     601. This plugin will include clean, simple to use, searchable categories to your Media Editor page.
    45612. Use categories in much the same way you use them on your posts and pages.
    46623. Filter categories as you type, very useful if you have a lot of categories to look through (thanks to Jason Corradino's "Searchable Categories" plugin)
     
    5470== Changelog ==
    5571
     72= 1.2 =
     73* Added 'category' parameter to [gallery] shortcode.
     74* Modified the Searchable Categories script to make the search field case insensitive.
     75* Fixed styling problem on Media Library modal windows - the filter and styling were not working.
     76
     77= 1.1 =
     78* Changed jQuery to use .live() rather than .on() for compatability with WordPress earlier than 3.3 - jQuery 1.7 was only added in v3.3
     79* Removed superfluous file which was accidentally included from a different plugin of mine. Would cause fatal errors if both plugins were turned on at the same time.
     80
    5681= 1.0 =
    5782* Initial commit.
    5883
    59 = 1.1 =
    60 * Changed jQuery to use .live() rather than .on() for compatability with WordPress which only added jQuery 1.7 in v3.3
    61 * Removed superfilous file which was accidentally included from a different plugin of mine. Would fatal errors if both plugins were turned on at the same time.
    62 
    6384== Upgrade Notice ==
    64 * For compatibility with WordPress versions earlier than 3.3, upgrade to version 1.1 of this plugin.
     85* For compatibility with WordPress versions earlier than 3.3, upgrade to version 1.1 of this plugin or later.
  • media-categories-2/trunk/media-categories-script.js

    r495667 r538292  
     1
     2
     3
    14jQuery(document).ready(function($){
    25   
     
    1619        });
    1720       
    18 
    1921        form_fields.find("tr.category > td.field > input.text").val(slug_list);
    2022    })
    2123   
    22    
    23      
     24    $.extend($.expr[":"], {
     25        "icontains": function(elem, i, match, array) {
     26            return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
     27        }
     28    });
    2429    /**
    2530     * The following javascript is borrowed from Jason Corradino's 'Searchable Categories' plugin.
     
    3035     */
    3136   
    32     jQuery('#catsearch').keyup(function() {
    33         var val = jQuery('#catsearch').val(), lis = jQuery("#categorychecklist li");
     37    $('#catsearch').keyup(function() {
     38        var val = $('#catsearch').val(), lis = $("#categorychecklist li");
    3439
    3540        lis.hide();
    36                            // find li labels's containing term, then back to parent li
    37         var containingLabels = jQuery("#categorychecklist label:contains('" + val + "')");
     41       
     42        // find li labels's containing term, then back to parent li
     43        var containingLabels = $("#categorychecklist label:icontains('" + val + "')");
    3844        containingLabels.closest('li').find('li').andSelf().show();
    3945        containingLabels.parents('#categorychecklist li').show();
  • media-categories-2/trunk/media-categories.php

    r519154 r538292  
    33  Plugin Name: Media Categories
    44  Plugin URI: http://wordpress.org/extend/plugins/media-categories-2
    5   Description:  Allows users to assign categories to items in their Media Library with a clean and simplified, filterable version of the standard category metabox
    6   Version: 1.1
     5  Description:  Allows users to assign categories to media with a clean and simplified, filterable category meta box and use shortcodes to display category galleries
     6  Version: 1.2
    77  Author: Eddie Moya
    88  Author URL: http://eddiemoya.com
     
    1212
    1313    /**
     14     * Start your engines.
     15     *
    1416     * @author Eddie Moya
    15      *
    16      * Start your engines.
    1717     */
    1818    function init() {
    19         add_action('admin_init', array(__CLASS__, 'register_media_categories'));
     19        add_action('init', array(__CLASS__, 'register_media_categories'));
     20        add_action('init', array(__CLASS__, 'custom_gallery_shortcode'));
    2021        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_scripts'));
    21         add_action('admin_print_styles-media.php', array(__CLASS__, 'enqueue_media_categories_styles') );
     22        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_styles') );
    2223        add_filter('attachment_fields_to_edit', array(__CLASS__, 'add_media_categories_metabox'), null, 2);
    23     }
     24       
     25    }
     26
    2427
    2528    function enqueue_media_categories_scripts() {
     
    2831            wp_register_script('media_categories_metabox_script', WP_PLUGIN_URL . '/media-categories-2/media-categories-script.js');
    2932            wp_enqueue_script('media_categories_metabox_script');
    30 
    3133        }
    3234    }
     
    3840            wp_enqueue_style( 'media_categories_metabox_style');
    3941        }
    40    
    4142    }
    4243
     
    8485    function media_categories_meta_box($post, $box) {
    8586       
    86         require_once(WP_PLUGIN_DIR . '/media-categories-2/attachment-walker-category-checklist-class.php');
     87        require_once(plugin_dir_path(__FILE__) . 'attachment-walker-category-checklist-class.php');
    8788         
    8889        $defaults = array('taxonomy' => 'category');
     
    9596        ?>
    9697        <div>
    97             <label class='category-filter' for="category-filter">Filter Categories:</label>
     98            <label class='category-filter' for="category-filter">Search Categories:</label>
    9899            <input id='catsearch' name="category-filter" type='text' /></div>
    99100        <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
     
    149150    }
    150151
     152    function custom_gallery_shortcode(){
     153        remove_shortcode('gallery');
     154        add_shortcode('gallery', array(__CLASS__,'gallery_shortcode'));
     155    }
     156   
     157    /**
     158     * The Gallery shortcode with category parameter.
     159     *
     160     * This implements the functionality of the Gallery Shortcode for displaying
     161     * WordPress images on a post.
     162     *
     163     * Almost Identical to the gallery_shortcode() function in /wp-includes/media.php
     164     * but adds a category parameter to the shortcode.
     165     *
     166     * @since 1.2
     167     * @since WordPress 2.6.0
     168     *
     169     * @param array $attr Attributes of the shortcode.
     170     * @return string HTML content to display gallery.
     171     */
     172    function gallery_shortcode($attr) {
     173        global $post;
     174
     175        static $instance = 0;
     176        $instance++;
     177
     178        // Allow plugins/themes to override the default gallery template.
     179        $output = apply_filters('post_gallery', '', $attr);
     180        if ( $output != '' )
     181            return $output;
     182
     183        // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
     184        if ( isset( $attr['orderby'] ) ) {
     185            $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
     186            if ( !$attr['orderby'] )
     187                unset( $attr['orderby'] );
     188        }
     189
     190        extract(shortcode_atts(array(
     191            'order'      => 'ASC',
     192            'orderby'    => 'menu_order ID',
     193            'id'         => $post->ID,
     194            'itemtag'    => 'dl',
     195            'icontag'    => 'dt',
     196            'captiontag' => 'dd',
     197            'columns'    => 3,
     198            'size'       => 'thumbnail',
     199            'include'    => '',
     200            'exclude'    => '',
     201            'category'   => ''
     202        ), $attr));
     203       
     204        $id = intval($id);
     205        if ( 'RAND' == $order )
     206            $orderby = 'none';
     207
     208        if( !empty($category) ){
     209            if(!is_numeric($category))
     210                $category = get_category_by_slug($category)->term_id;
     211
     212            if(!isset($attr['id']))
     213                $id = '';
     214        }
     215       
     216        if ( !empty($include) ) {
     217            $include = preg_replace( '/[^0-9,]+/', '', $include );
     218            $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) );
     219
     220            $attachments = array();
     221            foreach ( $_attachments as $key => $val ) {
     222                $attachments[$val->ID] = $_attachments[$key];
     223            }
     224        } elseif ( !empty($exclude) ) {
     225            $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
     226            $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) );
     227        } else {
     228            $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) );
     229        }
     230
     231        if ( empty($attachments) )
     232            return '';
     233
     234        if ( is_feed() ) {
     235            $output = "\n";
     236            foreach ( $attachments as $att_id => $attachment )
     237                $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
     238            return $output;
     239        }
     240
     241        $itemtag = tag_escape($itemtag);
     242        $captiontag = tag_escape($captiontag);
     243        $columns = intval($columns);
     244        $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
     245        $float = is_rtl() ? 'right' : 'left';
     246
     247        $selector = "gallery-{$instance}";
     248
     249        $gallery_style = $gallery_div = '';
     250        if ( apply_filters( 'use_default_gallery_style', true ) )
     251            $gallery_style = "
     252            <style type='text/css'>
     253                #{$selector} {
     254                    margin: auto;
     255                }
     256                #{$selector} .gallery-item {
     257                    float: {$float};
     258                    margin-top: 10px;
     259                    text-align: center;
     260                    width: {$itemwidth}%;
     261                }
     262                #{$selector} img {
     263                    border: 2px solid #cfcfcf;
     264                }
     265                #{$selector} .gallery-caption {
     266                    margin-left: 0;
     267                }
     268            </style>
     269            <!-- see gallery_shortcode() in wp-includes/media.php -->";
     270        $size_class = sanitize_html_class( $size );
     271        $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
     272        $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
     273
     274        $i = 0;
     275        foreach ( $attachments as $id => $attachment ) {
     276            $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
     277
     278            $output .= "<{$itemtag} class='gallery-item'>";
     279            $output .= "
     280                <{$icontag} class='gallery-icon'>
     281                    $link
     282                </{$icontag}>";
     283            if ( $captiontag && trim($attachment->post_excerpt) ) {
     284                $output .= "
     285                    <{$captiontag} class='wp-caption-text gallery-caption'>
     286                    " . wptexturize($attachment->post_excerpt) . "
     287                    </{$captiontag}>";
     288            }
     289            $output .= "</{$itemtag}>";
     290            if ( $columns > 0 && ++$i % $columns == 0 )
     291                $output .= '<br style="clear: both" />';
     292        }
     293
     294        $output .= "
     295                <br style='clear: both;' />
     296            </div>\n";
     297
     298        return $output;
     299    }
    151300}
    152301
  • media-categories-2/trunk/readme.txt

    r495667 r538292  
    22Contributors: eddiemoya
    33Donate link: http://eddiemoya.com
    4 Tags: media categories, media, category, categories, attachment categories, taxonomy, category metabox, metabox, admin, media library, media editor, attachment editor, attachment
     4Tags: media categories, media, category, categories, attachment categories, taxonomy, category metabox, metabox, admin, media library, media editor, attachment editor, attachment, images, gallery shortcode, gallery, shortcode, gallery category
    55Requires at least: 3.0
    66Tested up to: 3.3.1
    7 Stable tag: trunk
     7Stable tag: 1.2
    88
    9 Allows users to assign categories to items in their Media Library with a clean and simplified, filterable version of the standard category meta box
     9Easily assign categories to media with a clean, simple, and searchable category meta box. Then use the gallery shortcode to display category galleries
    1010
    1111== Description ==
    1212
    13 Allows users to assign categories to items in their Media Library with a clean and simplified, filterable version of the standard category meta box.
    14 The filter allows you to narrow your search for category as you type - this filter is not native to WordPress but is instead borrowed from Jason Corradino's
    15 [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. If you would like to enable this feature for your posts and pages
     13Allows users to assign categories to items in their Media Library with a clean and simplified, searchable version of the standard category meta box.
     14The "Search Categories" field allows you to narrow your search for a category as you type - this functionality is not native to WordPress but is instead borrowed from Jason Corradino's
     15[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. If you would like to enable this feature for your posts
    1616[download his plugin here](http://wordpress.org/extend/plugins/searchable-categories/)
     17
     18NEW! Since version 1.2 this plugin extends the native [gallery] shortcode of WordPress so that it has a 'category' parameter. See the "Shortcode Usage" under "Other Notes" for more details.
     19
     20
     21== Shortcode Usage ==
     22
     23This plugin takes advantage of the existing `[gallery]` shortcode for showing images by adding the `'category'` parameter.
     24The value passed to the `'category'` parameter can be either the `category` `slug`, or the `term_id`.
     25
     26`[gallery category="my-category-slug"]
     27OR
     28[gallery category="12"]`
     29
     30Its important to note that when passing the `'category'` parameter, the `[gallery]` shortcode will by default **ignore the current post
     31and simply try to include all images from the category**. The syntax above will retrieve any images that are assigned
     32to `'my-category-slug'` a.k.a term id `#12`, regardless of whether or not those images are attached to the current post.
     33
     34To query within a post (even the current post), you'll need to explicitly add the post id as such...
     35
     36`[gallery category="my-category-slug" id="43"]`
     37
     38This shortcode will retrieve any images attached to post `#43` that are categorized as `'my-slug-category'`.
     39
     40Aside from this behavior, the [gallery] shortcode should behave exactly as it does by default with the built-in shortcode.
     41The `id` parameter will behave as normal when the `category` parameter is not invoked.
     42For more information on using the built-in [gallery shortcode checkout the codex page](http://codex.wordpress.org/Gallery_Shortcode).
    1743
    1844== Related Plugins ==
    1945
    20 As stated in the description, the filtering ability in this plugin is taken from Jason Corradino's
     46As stated in the description, the search functionality in this plugin is taken from Jason Corradino's
    2147[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. While I do
    22 not employ the plugin directory, the javascript used for filtering is in fact derived with consent from
     48not employ the plugin directly, the javascript used for filtering is in fact derived with consent from
    2349that plugin. To enable this feature on all you category metabox, the
    2450[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin
    2551
    26 I'd like to point out that I drew some inspiration from the ['WOS Media Categories'](http://suburbia.org.uk/page/projects.html#wos_media_categories) plugin which
    27 is not generally easy to find since its not in the plugin directory. However [WOS Media Categories](http://suburbia.org.uk/page/projects.html#wos_media_categories)
    28 was missing the clean simple to use hierarchical category interface that we are used to in
    29 WordPress. A couple of my projects were dependant that plugin, but as the scale of the project
    30 increased and the number of categories grew exponentially, the disorganized grid of checkboxes
    31 were no longer a viable option.
    32 
    3352= TL;DR =
    34 Checkout these related plugins from which I borrowed code and drew inspiration.
     53Checkout this great plugin for Searchable Categories by Jason Corradino, whose javascript I use in this plugin.
     54I believe this very simple functionality should be a part of the standard categories metabox in core.
    3555
    3656* [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) by Jason Corradino
    37 * [WOS Media Categories](http://suburbia.org.uk/page/projects.html#wos_media_categories) by Rick Curran
    38 
    39 WOS is not as relevant since this plugin supplants that one, but the Searchable Categories plugin is a
    40 great simple plugin which adds very useful functionality that I think should be included in WordPress Core.
    4157
    4258== Screenshots ==
    4359
    44 1. This plugin will include clean, simple to use, filterable categories to your Media Editor page.
     601. This plugin will include clean, simple to use, searchable categories to your Media Editor page.
    45612. Use categories in much the same way you use them on your posts and pages.
    46623. Filter categories as you type, very useful if you have a lot of categories to look through (thanks to Jason Corradino's "Searchable Categories" plugin)
     
    5470== Changelog ==
    5571
     72= 1.2 =
     73* Added 'category' parameter to [gallery] shortcode.
     74* Modified the Searchable Categories script to make the search field case insensitive.
     75* Fixed styling problem on Media Library modal windows - the filter and styling were not working.
     76
     77= 1.1 =
     78* Changed jQuery to use .live() rather than .on() for compatability with WordPress earlier than 3.3 - jQuery 1.7 was only added in v3.3
     79* Removed superfluous file which was accidentally included from a different plugin of mine. Would cause fatal errors if both plugins were turned on at the same time.
     80
    5681= 1.0 =
    5782* Initial commit.
    5883
    59 = 1.1 =
    60 * Changed jQuery to use .live() rather than .on() for compatability with WordPress which only added jQuery 1.7 in v3.3
    61 * Removed superfilous file which was accidentally included from a different plugin of mine. Would fatal errors if both plugins were turned on at the same time.
    62 
    6384== Upgrade Notice ==
    64 * For compatibility with WordPress versions earlier than 3.3, upgrade to version 1.1 of this plugin.
     85* For compatibility with WordPress versions earlier than 3.3, upgrade to version 1.1 of this plugin or later.
Note: See TracChangeset for help on using the changeset viewer.