Plugin Directory

Changeset 694297


Ignore:
Timestamp:
04/09/2013 06:00:44 AM (13 years ago)
Author:
huntermaster
Message:

allow attached image sizes to be used as thumbnails

Location:
image-formatr/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • image-formatr/trunk/class.admin.php

    r687268 r694297  
    1818                'force'     => "",
    1919                'stdthumb'  => "on",
     20                'attthumb'  => "fullsize",
    2021                'killanc'   => "on",
    2122                'inspect'   => "",
     
    9192                                     'NOTE: may cause pages with lots of images to load slowly.'),
    9293                               ),
     94                'imgdefs'   => array(
     95                    'name'  => 'imglong, imgshort',
     96                    'title' => 'Default dimensions',
     97                    'desc'  => 'These values will be used as the width & height.',
     98                    'html'  => array('These values will be used as the width &amp; height in pixels by the <em>Auto determine orientation</em> setting which, if disabled will default to the <code>width</code> in the first box and the <code>height</code> in second box.',
     99                                     'NOTE: leave one of the boxes blank (or zero) and it will be calculated using the aspect ratio to the other box.'),
     100                               ),
     101                'imgaddl'   => array(
     102                    'name'  => 'img2long, img2short, img2page',
     103                    'title' => 'Additional dimensions',
     104                    'desc'  => 'These values will be used as the width & height.',
     105                    'html'  => array('These dimensions are used if you want to specify different settings for the front page or the single display page or everything else.',
     106                                     'These values will be used as the width &amp; height in pixels by the <em>Auto determine orientation</em> setting which, if disabled will default to the <code>width</code> in the first box and the <code>height</code> in second box.',
     107                                     'NOTE: leave one of the boxes blank (or zero) and it will be calculated using the aspect ratio to the other box.'),
     108                               ),
     109                'attthumb'   => array(
     110                    'title' => 'Use attached image as thumbnail',
     111                    'desc'  => 'Select the size to use for the thumbnail with Wordpress attachment images, if available.',
     112                    'html'  => array('If you attached an image to a post/page using the Wordpress <em>Add Media</em> button or through the <em>Media Library</em>, then you can use one of the auto-generated smaller sizes as the thumbnail.',
     113                                     'Non-attached images will just use the full-size image as the thumbnail and if the attached image size you specify is not available, the full-size image will also be used.'),
     114                               ),
    93115                'addclass'  => array(
    94116                    'title' => 'Additional classes',
     
    160182                                     '<em>Remember: the database is cleaned up when you "Deactivate"</em>.'),
    161183                               ),
    162 
    163                 'imgdefs'   => array(
    164                     'name'  => 'imglong, imgshort',
    165                     'title' => 'Default dimensions',
    166                     'desc'  => 'These values will be used as the width & height.',
    167                     'html'  => array('These values will be used as the width &amp; height in pixels by the <em>Auto determine orientation</em> setting which, if disabled will default to the <code>width</code> in the first box and the <code>height</code> in second box.',
    168                                      'NOTE: leave one of the boxes blank (or zero) and it will be calculated using the aspect ratio to the other box.'),
    169                                ),
    170                 'imgaddl'   => array(
    171                     'name'  => 'img2long, img2short, img2page',
    172                     'title' => 'Additional dimensions',
    173                     'desc'  => 'These values will be used as the width & height.',
    174                     'html'  => array('These dimenstions are used if you want to specify different settings for the front page or the single display page or everything else.',
    175                                      'These values will be used as the width &amp; height in pixels by the <em>Auto determine orientation</em> setting which, if disabled will default to the <code>width</code> in the first box and the <code>height</code> in second box.',
    176                                      'NOTE: leave one of the boxes blank (or zero) and it will be calculated using the aspect ratio to the other box.'),
    177                                ),
    178184            );
    179185
     
    184190
    185191            add_settings_section('main_section', 'Main settings', array($this, 'admin_overview'), __FILE__);
    186             $this-> add_settings(array('capatt'  ), 'print_dropdown', 'main_section');
    187             $this-> add_settings(array('newtitle'), 'print_textbox' , 'main_section');
    188             $this-> add_settings(array('group'   ), 'print_textbox' , 'main_section');
     192            $this-> add_settings(array('capatt'  ), 'print_caption_dd', 'main_section');
     193            $this-> add_settings(array('newtitle'), 'print_textbox'   , 'main_section');
     194            $this-> add_settings(array('group'   ), 'print_textbox'   , 'main_section');
    189195            $this-> add_settings(array('yankit', 'killanc', 'dofx', 'force'), 'print_checkbox', 'main_section');
    190196
    191197            add_settings_section('thumb_section', 'Thumbnail settings', array($this, 'admin_overview'), __FILE__);
    192             $this-> add_settings(array('stdthumb'), 'print_checkbox', 'thumb_section');
    193             $this-> add_settings(array('inspect' ), 'print_checkbox', 'thumb_section');
    194             $this-> add_settings(array('imgdefs' ), 'print_img_defs', 'thumb_section');
    195             $this-> add_settings(array('imgaddl' ), 'print_img_addl', 'thumb_section');
     198            $this-> add_settings(array('stdthumb'), 'print_checkbox'  , 'thumb_section');
     199            $this-> add_settings(array('inspect' ), 'print_checkbox'  , 'thumb_section');
     200            $this-> add_settings(array('imgdefs' ), 'print_img_defs'  , 'thumb_section');
     201            $this-> add_settings(array('imgaddl' ), 'print_img_addl'  , 'thumb_section');
     202            $this-> add_settings(array('attthumb' ), 'print_attach_dd', 'thumb_section');
    196203
    197204            add_settings_section('style_section', 'Styling settings', array($this, 'admin_overview'), __FILE__);
     
    212219        }
    213220
    214         function print_dropdown ( $f )
     221        function print_caption_dd ( $f )
    215222        {
    216223            $sel_tit = ($this->get_option($f) == 'title') ? 'selected="selected"' : '';
     
    224231                   <option value="alt"   $sel_alt>alt</option>
    225232                   <option value="x"     $sel_non>(x) no caption</option>
     233                </select>
     234ELEMENT;
     235            $this-> print_element($e, $f);
     236        }
     237
     238        function print_attach_dd ( $f )
     239        {
     240            $sel_thu = ($this->get_option($f) == 'thumbnail') ? 'selected="selected"' : '';
     241            $sel_med = ($this->get_option($f) == 'medium'   ) ? 'selected="selected"' : '';
     242            $sel_lrg = ($this->get_option($f) == 'large'    ) ? 'selected="selected"' : '';
     243            $sel_ful = ($this->get_option($f) == 'fullsize' ) ? 'selected="selected"' : '';
     244            $e = <<< ELEMENT
     245                <select
     246                    id="$f"
     247                    name="$this->settings_name[$f]"
     248                  ><option value="fullsize"  $sel_ful>full-size</option>
     249                   <option value="large"     $sel_lrg>large</option>
     250                   <option value="medium"    $sel_med>medium</option>
     251                   <option value="thumbnail" $sel_thu>thumbnail</option>
    226252                </select>
    227253ELEMENT;
  • image-formatr/trunk/class.formatr.php

    r687268 r694297  
    4141            $this->cap_class       =            $this->get_option('capclass' ); // list of css classes to add to the caption div
    4242            $this->def_group       =            $this->get_option('group'    ); // the default PrettyPhoto grouping designator
     43            $this->attach_thumb    =            $this->get_option('attthumb' ); // the size of the attachment image to use as the thumbnail
    4344            $this->new_title       =         __($this->get_option('newtitle' )); // the new title replacement
    4445            $this->def_img_width   = abs(intval($this->get_option('imglong'  )));
     
    400401            $img_style  = "style=\"$width $height\"";
    401402
    402             // setup print source and id print variables ///////////////
    403             $src = $param['thumb'] ? $param['thumb'] : $param['src'];
     403            // setup source & id print variables ///////////////////////
     404            $thumb = $param['thumb'] ? $param['thumb'] : $this-> get_attachment_url($param);
     405            $src = $thumb ? $thumb : $param['src'];
    404406            $id  = $param['id'] ? "id=\"{$param['id']}\""  : "";
    405407
     
    459461        }
    460462
     463        /**
     464         * Get the attached image url in the specified size
     465         *
     466         * First we look in the class parameter of the image for the attachment
     467         * id and failing this we look in the database. Then we use this id to
     468         * try and grab the attached image of that size.
     469         */
     470        function get_attachment_url( $param )
     471        {
     472            # first check if the attachment id is available in the image class
     473            preg_match('/wp-image-(\d+)/', $param['class'], $matches); // alignnone size-full wp-image-3338
     474            if (false and count($matches) > 1){
     475                $attachment_id = $matches[1];
     476            }
     477            # otherwise we need to go to the database to find the id
     478            else {
     479                global $wpdb;
     480                $psrc = $param['src'];
     481                $query = "SELECT ID FROM $wpdb->posts WHERE guid='{$param['src']}'";
     482                // $debug_sma_eval ='$psrc';$debug_sma_title=__METHOD__.':'.__LINE__;include('debug_output_sma.php'); #SMA
     483                // $debug_sma_eval ='$query';$debug_sma_title=__METHOD__.':'.__LINE__;include('debug_output_sma.php'); #SMA
     484                $attachment_id = $wpdb->get_var($query);
     485            }
     486            # if the image has been attached, we should have the id now
     487            if ($attachment_id) {
     488                $attachment_img_src = wp_get_attachment_image_src($attachment_id, $this-> attach_thumb);
     489                // $debug_sma_eval ='$attachment_img_src';$debug_sma_title=__METHOD__.':'.__LINE__;include('debug_output_sma.php'); #SMA
     490
     491                if ($attachment_img_src and isset($attachment_img_src[0]))
     492                    return $attachment_img_src[0];
     493            }
     494        }
     495
    461496    } //End Class ImageFormatr
    462497
  • image-formatr/trunk/image-formatr.php

    r687268 r694297  
    44  * Plugin URI: http://warriorself.com/blog/about/image-formatr/
    55  * Description: Formats all content images on a page / post giving them borders and captions.
    6   * Version: 1.0.1
     6  * Version: 1.1
    77  * Author: Steven Almeroth
    88  * Author URI: http://warriorship.org/sma/
     
    2727  */
    2828define ('IMAGEFORMATR_TEXTDOMAIN', 'image-formatr');
    29 define( 'IMAGEFORMATR_VERSION'   , '1.0.1');
    3029
    3130include_once(dirname(__FILE__) . '/class.formatr.php');
  • image-formatr/trunk/readme.txt

    r687272 r694297  
    165165
    166166* add screenshot of output image with caption
     167* admin options name should be unique (accross all plugins)
    167168
    168169== Current Wishlist ==
Note: See TracChangeset for help on using the changeset viewer.