Plugin Directory

Changeset 801594


Ignore:
Timestamp:
11/09/2013 02:51:09 PM (12 years ago)
Author:
Shellbot
Message:

Added option to include/exclude images based on ID. Fixed issue with widget form not expanding correctly

Location:
easy-image-display/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • easy-image-display/trunk/readme.txt

    r791858 r801594  
    33Tags: image, gallery, latest image, random image
    44Requires at least: 3.5
    5 Tested up to: 3.6.1
     5Tested up to: 3.7.1
    66Stable tag: trunk
    77License: GPLv2 or later
     
    1919Current features include:
    2020
     21* Include/exclude images based on ID
    2122* Widget, shortcode and template tag for maximum flexibility
    2223* Display images at various sizes
     
    2728Features soon to be added:
    2829
    29 * Include/exclude images based on ID
    30 * Include/exclude only images associated with content, or only used as feature images
     30* Filter images by attachment status
    3131* Slideshow layout
    3232* Custom image sizes
     
    8080== Installation ==
    8181
    82 1. Upload the 'sb-easy-image-display' folder to the '/wp-content/plugins/' directory
     821. Upload the 'easy-image-display' folder to the '/wp-content/plugins/' directory
    83832. Activate the plugin through the 'Plugins' menu in WordPress
    84843. Add images using the widget, shortcode or template tag
     
    9898== Changelog ==
    9999
    100 = 1.01 =
     100= 1.0.2 =
     101* Added option to include/exclude images based on ID
     102* Fixed issue with widget form not expanding correctly
     103
     104= 1.0.1 =
    101105* Fixed an incompatibility with other lightbox plugins
    102106
     
    106110== Upgrade Notice ==
    107111
    108 = 1.01 =
     112= 1.0.2 =
     113* New feature! Include/exclude images based on ID.
     114
     115= 1.0.1 =
    109116Fixes an incompatibility with other lightbox plugins.
  • easy-image-display/trunk/sb-easy-image-display.php

    r791878 r801594  
    44Plugin URI: http://shellbotics.com/wordpress-plugins/easy-image-display/
    55Description: An easy way to display random or latest images on your site.
    6 Version: 1.01
     6Version: 1.0.2
    77Author: Shellbot
    88Author URI: http://shellbotics.com
     
    8383            'link' => 'file',
    8484            'columns' => '3',
     85            'filter' => 'only',
    8586        ), $args ) );
    8687
     
    9293            'link' => $link, 
    9394            'columns' => $columns,
     95            'filter' => $filter,
     96            'ids' => $args['ids'],
    9497        );
    9598
     
    108111            'link' => 'file',
    109112            'columns' => '3',
     113            'filter' => 'only',
    110114        ), $args ) );
    111115
     
    117121            'link' => $link, 
    118122            'columns' => $columns,
     123            'filter' => $filter,
     124            'ids' => $args['ids'],
    119125        );
    120126
     
    133139            'link' => 'file',
    134140            'columns' => '5',
     141            'filter' => 'only',
    135142        ), $args ) );
    136143
     
    142149            'link' => $link, 
    143150            'columns' => $columns,
     151            'filter' => $filter,
     152            'ids' => $args['ids'],
    144153        );
    145154
     
    150159    /* Construct query and return array of images ------------------------------- */
    151160
    152     function sb_get_easy_image( $args, $src = '' ) {     
     161    function sb_get_easy_image( $args, $src = '' ) { 
    153162
    154163        $query = array (
     
    158167
    159168        if( $args['num'] ) {
    160             $query['numberposts'] = $args['num']; 
     169            $query['posts_per_page'] = $args['num']; 
    161170        }
    162171
     
    170179            break;
    171180        };
    172 
    173         $attachments = get_posts( $query  );
     181       
     182        if( $args['ids'] && strtolower( $args['filter'] ) == 'include' ) {
     183            $attachments = $this->include_action( $args, $query );
     184        } elseif( $args['ids'] ) {
     185            $ids = split( ',', $args['ids'] );
     186           
     187            if( strtolower( $args['filter'] ) == 'exclude' ) {
     188                $query['post__not_in'] = $ids;
     189            } else {
     190                //Default "only"
     191                $query['post__in'] = $ids;
     192            }
     193           
     194            $attachments = get_posts( $query );
     195        } else {
     196            $attachments = get_posts( $query );
     197        }
    174198
    175199        if ( $attachments ) {
     
    177201            $ids = '';
    178202            foreach ( $attachments as $attachment ) {
    179                 $ids .= $attachment->ID.', ';
     203                $ids .= $attachment->ID . ', ';
    180204            }
    181205            return do_shortcode( '[gallery columns="' . $args['columns'] . '" ids="' . $ids . '" size="' . strtolower( $args['size'] ) . '" link="' . strtolower( $args['link'] ) . '"]' );
     
    185209        }
    186210   
     211    }
     212   
     213   
     214    /* Rejig query based on action parameter -------------------------------- */
     215    function include_action( $args, $query ) {
     216       
     217        $ids = split( ',', $args['ids'] );
     218       
     219        if( count( $ids ) >= $args['num'] ) {
     220            //Equal or more IDs than total images.
     221            $query['post__in'] = $ids;
     222           
     223            $attachments = get_posts( $query );
     224        } else {
     225            //Less IDs than total images.   
     226            $diff = $args['num'] - count( $ids );
     227
     228            //Original query continues, but number changed to difference
     229            //Excludes specified IDs
     230            $query['posts_per_page'] = $diff;
     231            $query['post__not_in'] = $ids;
     232           
     233            $attachments = get_posts( $query );
     234            wp_reset_postdata();
     235           
     236            //new query retrieves specified IDs
     237            $include = array(
     238                'post_type' => 'attachment',
     239                'post_mime_type' => 'image',
     240                'posts_per_page' => count( $ids ),
     241                'post__in' => $ids,
     242            );
     243            $included = get_posts( $include );
     244
     245            //smoosh all posts together
     246            $all = array_merge( $attachments, $included );
     247
     248            //order by whatever they were supposed to be ordered by
     249            switch( strtolower( $args['order'] ) ) {
     250                case 'newest':
     251                    $sort = SORT_DESC;
     252                break;
     253                   
     254                case 'oldest':
     255                    $sort = SORT_ASC;
     256                break;
     257                       
     258                default:
     259                    $sort = 'random';
     260                break;
     261            }
     262           
     263            if( $sort == 'random' ) {
     264                shuffle( $all );
     265            } else {
     266               
     267                $date = array();
     268
     269                foreach( $all as $key => $row ) {
     270                    $date[$key] = $row->post_date;
     271                }
     272                array_multisort( $date, $sort, $all );   
     273               
     274            }
     275           
     276            //return
     277            return $all;
     278           
     279        }
     280
     281        return $attachments;
    187282    }
    188283
     
    225320    function sb_easy_image_widget_js() {
    226321        echo "<script type='text/javascript'>
    227                 window.onload = init;
    228 
    229                 function init(){
    230                     jQuery('.widget-inside').on( 'click', '#sb-easy-image-advanced-toggle', function () {
    231                         jQuery(this).siblings('#sb-easy-image-advanced').toggle();
    232                     });
     322                function sb_advanced_toggle(el){   
     323                    jQuery(el).siblings('#sb-easy-image-advanced').toggle();
    233324                }
    234 
    235325            </script>";
    236326    }
  • easy-image-display/trunk/sb-easy-image-widget.php

    r791878 r801594  
    22/**
    33 * Widget Name: Easy Image Display
    4  * Version: 1.01
     4 * Version: 1.0.2
    55 */
    66
     
    4545        $instance['columns'] = $new_instance['columns'];
    4646        $instance['link']    = $new_instance['link'];
     47        $instance['filter']    = $new_instance['filter'];
     48        $instance['ids']    = $new_instance['ids'];
    4749
    4850        return $instance;
     
    5456
    5557        $params = array(
    56             'include' => array (
     58            'include' => array(
    5759                'Show all',
    5860                'Include only',
    5961                'Exclude', 
    6062            ),
    61             'yesno' => array (
     63            'yesno' => array(
    6264                'Yes',
    6365                'No', 
    6466            ),
    65             'order' => array (
     67            'order' => array(
    6668                'Newest',
    6769                'Oldest',
    6870                'Random',
    6971            ),
    70             'sizes' => array (
     72            'sizes' => array(
    7173                'Thumbnail',
    7274                'Medium',
     
    7476                'Full',
    7577            ),
    76             'link' => array (
     78            'link' => array(
    7779                'None',
    7880                'Lightbox',
    7981                'Attachment',
    8082                'File',
    81             )
     83            ),
     84            'filter' => array(
     85                'Only',
     86                'Include',
     87                'Exclude',
     88            ),
    8289        );
    8390
     
    98105                'link' => 'File',
    99106                'columns' => 1,
     107                'filter' => 'Only',
    100108            );
    101109
     
    132140            </p>
    133141
    134             <a id="sb-easy-image-advanced-toggle" href="#">Advanced settings</a>
     142            <a id="sb-easy-image-advanced-toggle" href="#" onclick="javascript:sb_advanced_toggle( jQuery(this) ); return false;">Advanced settings</a>
    135143
    136144            <div id="sb-easy-image-advanced" style="display:none;">
     
    172180                <label for="<?php echo $this->get_field_id( 'columns' ); ?>"><?php esc_html_e( 'Number of columns to display', 'shellbotics' ); ?></label>
    173181                <input id="<?php echo $this->get_field_id( 'columns' ); ?>" type="text" name="<?php echo $this->get_field_name( 'columns' ); ?>" value="<?php echo $instance['columns']; ?>" class="widefat" />
     182            </p> 
     183           
     184            <!-- Filter -->
     185            <p>
     186                <label for="<?php echo $this->get_field_id( 'filter' ); ?>"><?php esc_html_e('Filter:', 'shellbotics'); ?></label>
     187                <select id="<?php echo $this->get_field_id( 'filter' ); ?>" name="<?php echo $this->get_field_name( 'filter' ); ?>" >
     188                    <?php
     189                    foreach ( $params['filter'] as $filter ) {
     190                    ?>
     191                        <option value="<?php echo $filter; ?>" <?php if ( $filter == $instance['filter'] ) { echo 'selected="selected"'; } ?>>
     192                            <?php echo $filter; ?>
     193                        </option>
     194                    <?php
     195                    }
     196                    ?>
     197                </select>
     198            </p>
     199               
     200            <!-- Image IDs -->
     201            <p>
     202                <label for="<?php echo $this->get_field_id( 'ids' ); ?>"><?php esc_html_e( 'Image IDs (separate with comma)', 'shellbotics' ); ?></label>
     203                <input id="<?php echo $this->get_field_id( 'ids' ); ?>" type="text" name="<?php echo $this->get_field_name( 'ids' ); ?>" value="<?php echo $instance['ids']; ?>" class="widefat" />
    174204            </p> 
    175205
     
    194224            'link'    => $instance['link'], 
    195225            'columns' => $instance['columns'],
     226            'filter'  => $instance['filter'],
     227            'ids'     => $instance['ids'],
    196228        );
    197229
Note: See TracChangeset for help on using the changeset viewer.