Plugin Directory

Changeset 568393


Ignore:
Timestamp:
07/06/2012 06:06:34 PM (14 years ago)
Author:
sbutze
Message:

fixed file size calculation issues

Location:
wp-image-size-limit
Files:
4 edited
3 copied

Legend:

Unmodified
Added
Removed
  • wp-image-size-limit/tags/1.0.2/readme.txt

    r568379 r568393  
    55Requires at least: 3.3.2
    66Tested up to: 3.4.1
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • wp-image-size-limit/tags/1.0.2/wp-image-size-limit.php

    r568379 r568393  
    66Author: Sean Butze
    77Author URI: http://www.seanbutze.com
    8 Version: 1.0.1
     8Version: 1.0.2
    99*/
    1010
     
    1616            add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array($this, 'add_plugin_links') );
    1717            add_filter('wp_handle_upload_prefilter', array($this, 'error_message'));
    18             add_action('admin_head', array($this, 'load_styles'));
    1918    } 
    2019
     
    3029    public function get_limit() {
    3130        $option = get_option('wpisl_options');
    32         $limit = $option['img_upload_limit'];
     31
     32        if ( isset($option['img_upload_limit']) ){
     33            $limit = $option['img_upload_limit'];
     34        } else {
     35            $limit = $this->wp_limit();
     36        }
    3337
    3438        return $limit;
     
    4852    }
    4953
    50     public function increase_unit($input) {
    51         $output = $input / 1000;
    52         return $output;
    53     }
    54 
    5554    public function wp_limit() {
    5655        $output = wp_max_upload_size();
    5756        $output = round($output);
    58         $output = $output / 1000000;
     57        $output = $output / 1000000; //convert to megabytes
    5958        $output = round($output);
    60         $output = $output * 1000;
     59        $output = $output * 1000; // convert to kilobytes
    6160
    6261        return $output;
     
    7877    public function error_message($file) {
    7978        $size = $file['size'];
    80         $size = $size / 1000;
     79        $size = $size / 1024;
    8180        $type = $file['type'];
    8281        $is_image = strpos($type, 'image');
     
    8685
    8786      if ( ( $size > $limit ) && ($is_image !== false) ) {
    88          $file['error'] = 'Image files must be smaller than '.$limit_output.$unit;
     87         //$file['error'] = 'Image files must be smaller than '.$limit_output.$unit;
     88         $file['error'] = 'filesize = '.$size.', limit ='.$limit;
    8989      }
    9090      return $file;
     
    100100
    101101        ?>
    102         <!-- Custom Max Upload Size -->
     102        <!-- .Custom Max Upload Size -->
    103103        <style type="text/css">
    104104        .after-file-upload {
     
    107107        <?php if ( $limit < $wplimit ) : ?>
    108108        .upload-flash-bypass:after {
    109             content: ' Maximum image size: <?php echo $limit_output . $unit; ?>.';
     109            content: 'Maximum image size: <?php echo $limit_output . $unit; ?>.';
    110110            display: block;
    111111            margin: 15px 0;
     
    121121}
    122122$WP_Image_Size_Limit = new WP_Image_Size_Limit;
     123add_action('admin_head', array($WP_Image_Size_Limit, 'load_styles'));
    123124
    124125
  • wp-image-size-limit/tags/1.0.2/wpisl-options.php

    r568368 r568393  
    4343 */
    4444function wpisl_get_default_options() {
     45    $wpisl = new WP_Image_Size_Limit;
     46    $limit = $wpisl->wp_limit();
    4547    $default_options = array(
    46         'img_upload_limit' => 1000,
     48        'img_upload_limit' => $limit,
    4749    );
    4850
     
    7880            $value = $options[$id];
    7981        }
    80         elseif  ( empty($options[$id])  )  {
     82        /*elseif  ( empty($options[$id])  )  {
    8183            $value = '1000';
    82         }
     84        } */
    8385        else {
    8486            $value = $limit;
     
    103105function wpisl_options_validate( $input ) {
    104106    $output = $defaults = wpisl_get_default_options();
     107    $wpisl = new WP_Image_Size_Limit;
     108    $limit = $wpisl->wp_limit();
    105109
    106110    $output['img_upload_limit'] = str_replace(',','', $input['img_upload_limit']);
     
    108112    $output['img_upload_limit'] = absint( intval( $output['img_upload_limit'] ) );
    109113
    110     $message = 'Image size limit must be smaller than global upload limt.';
    111     add_settings_error('wpisl_options', 'img-size-too-large', $message);
     114    if ( $output['img_upload_limit'] > $limit ) {
     115        $output['img_upload_limit'] = $limit;
     116    }
    112117
    113118    return apply_filters( 'wpisl_options_validate', $output, $input, $defaults );
  • wp-image-size-limit/trunk/readme.txt

    r568379 r568393  
    55Requires at least: 3.3.2
    66Tested up to: 3.4.1
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • wp-image-size-limit/trunk/wp-image-size-limit.php

    r568379 r568393  
    66Author: Sean Butze
    77Author URI: http://www.seanbutze.com
    8 Version: 1.0.1
     8Version: 1.0.2
    99*/
    1010
     
    1616            add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array($this, 'add_plugin_links') );
    1717            add_filter('wp_handle_upload_prefilter', array($this, 'error_message'));
    18             add_action('admin_head', array($this, 'load_styles'));
    1918    } 
    2019
     
    3029    public function get_limit() {
    3130        $option = get_option('wpisl_options');
    32         $limit = $option['img_upload_limit'];
     31
     32        if ( isset($option['img_upload_limit']) ){
     33            $limit = $option['img_upload_limit'];
     34        } else {
     35            $limit = $this->wp_limit();
     36        }
    3337
    3438        return $limit;
     
    4852    }
    4953
    50     public function increase_unit($input) {
    51         $output = $input / 1000;
    52         return $output;
    53     }
    54 
    5554    public function wp_limit() {
    5655        $output = wp_max_upload_size();
    5756        $output = round($output);
    58         $output = $output / 1000000;
     57        $output = $output / 1000000; //convert to megabytes
    5958        $output = round($output);
    60         $output = $output * 1000;
     59        $output = $output * 1000; // convert to kilobytes
    6160
    6261        return $output;
     
    7877    public function error_message($file) {
    7978        $size = $file['size'];
    80         $size = $size / 1000;
     79        $size = $size / 1024;
    8180        $type = $file['type'];
    8281        $is_image = strpos($type, 'image');
     
    8685
    8786      if ( ( $size > $limit ) && ($is_image !== false) ) {
    88          $file['error'] = 'Image files must be smaller than '.$limit_output.$unit;
     87         //$file['error'] = 'Image files must be smaller than '.$limit_output.$unit;
     88         $file['error'] = 'filesize = '.$size.', limit ='.$limit;
    8989      }
    9090      return $file;
     
    100100
    101101        ?>
    102         <!-- Custom Max Upload Size -->
     102        <!-- .Custom Max Upload Size -->
    103103        <style type="text/css">
    104104        .after-file-upload {
     
    107107        <?php if ( $limit < $wplimit ) : ?>
    108108        .upload-flash-bypass:after {
    109             content: ' Maximum image size: <?php echo $limit_output . $unit; ?>.';
     109            content: 'Maximum image size: <?php echo $limit_output . $unit; ?>.';
    110110            display: block;
    111111            margin: 15px 0;
     
    121121}
    122122$WP_Image_Size_Limit = new WP_Image_Size_Limit;
     123add_action('admin_head', array($WP_Image_Size_Limit, 'load_styles'));
    123124
    124125
  • wp-image-size-limit/trunk/wpisl-options.php

    r568368 r568393  
    4343 */
    4444function wpisl_get_default_options() {
     45    $wpisl = new WP_Image_Size_Limit;
     46    $limit = $wpisl->wp_limit();
    4547    $default_options = array(
    46         'img_upload_limit' => 1000,
     48        'img_upload_limit' => $limit,
    4749    );
    4850
     
    7880            $value = $options[$id];
    7981        }
    80         elseif  ( empty($options[$id])  )  {
     82        /*elseif  ( empty($options[$id])  )  {
    8183            $value = '1000';
    82         }
     84        } */
    8385        else {
    8486            $value = $limit;
     
    103105function wpisl_options_validate( $input ) {
    104106    $output = $defaults = wpisl_get_default_options();
     107    $wpisl = new WP_Image_Size_Limit;
     108    $limit = $wpisl->wp_limit();
    105109
    106110    $output['img_upload_limit'] = str_replace(',','', $input['img_upload_limit']);
     
    108112    $output['img_upload_limit'] = absint( intval( $output['img_upload_limit'] ) );
    109113
    110     $message = 'Image size limit must be smaller than global upload limt.';
    111     add_settings_error('wpisl_options', 'img-size-too-large', $message);
     114    if ( $output['img_upload_limit'] > $limit ) {
     115        $output['img_upload_limit'] = $limit;
     116    }
    112117
    113118    return apply_filters( 'wpisl_options_validate', $output, $input, $defaults );
Note: See TracChangeset for help on using the changeset viewer.