Permalink
Browse files

media-categories 1.2

  • Loading branch information...
eddiemoya committed Apr 28, 2012
1 parent 817e1c4 commit 826edc92b430a72d29b5be6c0a5a14c2c30a64ca
@@ -1,6 +1,9 @@
+
+
+
jQuery(document).ready(function($){
- $('tr.category_metabox input').on('click', function(){
+ $('tr.category_metabox input').live('click', function(){
var form_fields = $(this).closest("tbody");
@@ -15,12 +18,14 @@ jQuery(document).ready(function($){
slug_list += $(this).val();
});
-
form_fields.find("tr.category > td.field > input.text").val(slug_list);
})
-
-
+ $.extend($.expr[":"], {
+ "icontains": function(elem, i, match, array) {
+ return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
+ }
+ });
/**
* The following javascript is borrowed from Jason Corradino's 'Searchable Categories' plugin.
* It allows the category metabox to be filtered as the user types. To do this with your
@@ -29,12 +34,13 @@ jQuery(document).ready(function($){
* http://wordpress.org/extend/plugins/searchable-categories/
*/
- jQuery('#catsearch').keyup(function() {
- var val = jQuery('#catsearch').val(), lis = jQuery("#categorychecklist li");
+ $('#catsearch').keyup(function() {
+ var val = $('#catsearch').val(), lis = $("#categorychecklist li");
lis.hide();
-                    // find li labels's containing term, then back to parent li
- var containingLabels = jQuery("#categorychecklist label:contains('" + val + "')");
+
+ // find li labels's containing term, then back to parent li
+ var containingLabels = $("#categorychecklist label:icontains('" + val + "')");
containingLabels.closest('li').find('li').andSelf().show();
containingLabels.parents('#categorychecklist li').show();
});
@@ -1,42 +1,44 @@
<?php
/*
Plugin Name: Media Categories
- Plugin URI: http://eddiemoya.com/
- Description: Allows users to assign categories to items in their Media Library with a clean and simplified, filterable version of the standard category metabox
+ Plugin URI: http://wordpress.org/extend/plugins/media-categories-2
+ Description: Allows users to assign categories to media with a clean and simplified, filterable category meta box and use shortcodes to display category galleries
+ Version: 1.2
Author: Eddie Moya
- Version: 0.5
+ Author URL: http://eddiemoya.com
*/
class Media_Categories {
/**
- * @author Eddie Moya
- *
* Start your engines.
+ *
+ * @author Eddie Moya
*/
function init() {
- add_action('admin_init', array(__CLASS__, 'register_media_categories'));
+ add_action('init', array(__CLASS__, 'register_media_categories'));
+ add_action('init', array(__CLASS__, 'custom_gallery_shortcode'));
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_scripts'));
- add_action('admin_print_styles-media.php', array(__CLASS__, 'enqueue_media_categories_styles') );
+ add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_styles') );
add_filter('attachment_fields_to_edit', array(__CLASS__, 'add_media_categories_metabox'), null, 2);
+
}
+
function enqueue_media_categories_scripts() {
if (is_admin()) {
- wp_register_script('media_categories_metabox_script', WP_PLUGIN_URL . '/media-categories/media-categories-script.js');
+ wp_register_script('media_categories_metabox_script', WP_PLUGIN_URL . '/media-categories-2/media-categories-script.js');
wp_enqueue_script('media_categories_metabox_script');
-
}
}
function enqueue_media_categories_styles() {
if (is_admin()) {
- wp_register_style('media_categories_metabox_style', WP_PLUGIN_URL . '/media-categories/media-categories-style.css');
+ wp_register_style('media_categories_metabox_style', WP_PLUGIN_URL . '/media-categories-2/media-categories-style.css');
wp_enqueue_style( 'media_categories_metabox_style');
}
-
}
/**
@@ -82,7 +84,7 @@ function add_media_categories_metabox($form_fields, $post) {
*/
function media_categories_meta_box($post, $box) {
- require_once(WP_PLUGIN_DIR . '/media-categories/attachment-walker-category-checklist-class.php');
+ require_once(plugin_dir_path(__FILE__) . 'attachment-walker-category-checklist-class.php');
$defaults = array('taxonomy' => 'category');
if (!isset($box['args']) || !is_array($box['args']))
@@ -93,7 +95,7 @@ function media_categories_meta_box($post, $box) {
$tax = get_taxonomy($taxonomy);
?>
<div>
- <label class='category-filter' for="category-filter">Filter Categories:</label>
+ <label class='category-filter' for="category-filter">Search Categories:</label>
<input id='catsearch' name="category-filter" type='text' /></div>
<div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
<ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">
@@ -147,6 +149,154 @@ function media_categories_meta_box($post, $box) {
<?php
}
+ function custom_gallery_shortcode(){
+ remove_shortcode('gallery');
+ add_shortcode('gallery', array(__CLASS__,'gallery_shortcode'));
+ }
+
+ /**
+ * The Gallery shortcode with category parameter.
+ *
+ * This implements the functionality of the Gallery Shortcode for displaying
+ * WordPress images on a post.
+ *
+ * Almost Identical to the gallery_shortcode() function in /wp-includes/media.php
+ * but adds a category parameter to the shortcode.
+ *
+ * @since 1.2
+ * @since WordPress 2.6.0
+ *
+ * @param array $attr Attributes of the shortcode.
+ * @return string HTML content to display gallery.
+ */
+ 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 != '' )
+ return $output;
+
+ // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
+ if ( isset( $attr['orderby'] ) ) {
+ $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
+ if ( !$attr['orderby'] )
+ unset( $attr['orderby'] );
+ }
+
+ extract(shortcode_atts(array(
+ 'order' => 'ASC',
+ 'orderby' => 'menu_order ID',
+ 'id' => $post->ID,
+ 'itemtag' => 'dl',
+ 'icontag' => 'dt',
+ 'captiontag' => 'dd',
+ 'columns' => 3,
+ 'size' => 'thumbnail',
+ 'include' => '',
+ 'exclude' => '',
+ 'category' => ''
+ ), $attr));
+
+ $id = intval($id);
+ if ( 'RAND' == $order )
+ $orderby = 'none';
+
+ if( !empty($category) ){
+ if(!is_numeric($category))
+ $category = get_category_by_slug($category)->term_id;
+
+ if(!isset($attr['id']))
+ $id = '';
+ }
+
+ if ( !empty($include) ) {
+ $include = preg_replace( '/[^0-9,]+/', '', $include );
+ $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) );
+
+ $attachments = array();
+ foreach ( $_attachments as $key => $val ) {
+ $attachments[$val->ID] = $_attachments[$key];
+ }
+ } elseif ( !empty($exclude) ) {
+ $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
+ $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) );
+ } else {
+ $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) );
+ }
+
+ if ( empty($attachments) )
+ return '';
+
+ if ( is_feed() ) {
+ $output = "\n";
+ foreach ( $attachments as $att_id => $attachment )
+ $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
+ return $output;
+ }
+
+ $itemtag = tag_escape($itemtag);
+ $captiontag = tag_escape($captiontag);
+ $columns = intval($columns);
+ $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
+ $float = is_rtl() ? 'right' : 'left';
+
+ $selector = "gallery-{$instance}";
+
+ $gallery_style = $gallery_div = '';
+ if ( apply_filters( 'use_default_gallery_style', true ) )
+ $gallery_style = "
+ <style type='text/css'>
+ #{$selector} {
+ margin: auto;
+ }
+ #{$selector} .gallery-item {
+ float: {$float};
+ margin-top: 10px;
+ text-align: center;
+ width: {$itemwidth}%;
+ }
+ #{$selector} img {
+ border: 2px solid #cfcfcf;
+ }
+ #{$selector} .gallery-caption {
+ margin-left: 0;
+ }
+ </style>
+ <!-- see gallery_shortcode() in wp-includes/media.php -->";
+ $size_class = sanitize_html_class( $size );
+ $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
+ $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
+
+ $i = 0;
+ foreach ( $attachments as $id => $attachment ) {
+ $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
+
+ $output .= "<{$itemtag} class='gallery-item'>";
+ $output .= "
+ <{$icontag} class='gallery-icon'>
+ $link
+ </{$icontag}>";
+ if ( $captiontag && trim($attachment->post_excerpt) ) {
+ $output .= "
+ <{$captiontag} class='wp-caption-text gallery-caption'>
+ " . wptexturize($attachment->post_excerpt) . "
+ </{$captiontag}>";
+ }
+ $output .= "</{$itemtag}>";
+ if ( $columns > 0 && ++$i % $columns == 0 )
+ $output .= '<br style="clear: both" />';
+ }
+
+ $output .= "
+ <br style='clear: both;' />
+ </div>\n";
+
+ return $output;
+ }
}
Media_Categories::init();
@@ -1,51 +0,0 @@
-=== Media Categories ===
-Contributors: eddiemoya
-Donate link: http://eddiemoya.com
-Tags: media categories, media, category, categories, attachment categories, taxonomy, category metabox, metabox, admin, media library, media editor, attachment editor
-Requires at least: 3.0
-Tested up to: 3.3.1
-Stable tag: trunk
-
-Allows users to assign categories to items in their Media Library with a clean and simplified, filterable version of the standard category meta box
-
-== Description ==
-
-Allows users to assign categories to items in their Media Library with a clean and simplified, filterable version of the standard category meta box.
-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
-[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. If you would like to enable this feature for your posts and pages
-[download his plugin here](http://wordpress.org/extend/plugins/searchable-categories/)
-
-== Related Plugins ==
-
-As stated in the description, the filtering ability in this plugin is taken from Jason Corradino's
-[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. While I do
-not employ the plugin directory, the javascript used for filtering is in fact derived with consent from
-that plugin. To enable this feature on all you category metabox, the
-[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin
-
-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
-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)
-was missing the clean simple to use hierarchical category interface that we are used to in
-WordPress. A couple of my projects were dependant that plugin, but as the scale of the project
-increased and the number of categories grew exponentially, the disorganized grid of checkboxes
-were no longer a viable option.
-
-= TL;DR =
-Checkout these related plugins from which I borrowed code and drew inspiration.
-
-* [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) by Jason Corradino
-* [WOS Media Categories](http://suburbia.org.uk/page/projects.html#wos_media_categories) by Rick Curran
-
-WOS is not as relevant since this plugin supplants that one, but the Searchable Categories plugin is a
-great simple plugin which adds very useful functionality that I think should be included in WordPress Core.
-
-== Installation ==
-
-1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
-1. Activate the plugin through the 'Plugins' menu in WordPress
-
-
-== Changelog ==
-
-= 1.0 =
-* Initial commit.
Oops, something went wrong.

0 comments on commit 826edc9

Please sign in to comment.