Plugin Directory

Changeset 1481443


Ignore:
Timestamp:
08/23/2016 10:18:22 AM (10 years ago)
Author:
albinvlc
Message:

version 1.5 + filename sanitization

Location:
imagecare/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • imagecare/trunk/inc-func-cleanregen.php

    r1448419 r1481443  
    99    $pid   = !empty($_POST['id'])    ? (int) $_REQUEST['id'] : 0;
    1010
    11     $info = get_post_meta($pid, '_wp_attachment_metadata', true);
     11    $org = $info = get_post_meta($pid, '_wp_attachment_metadata', true);
    1212    if($info) {
    1313        $path  = $this->path.dirname($info['file']).'/';
     
    1515        $fname = basename($file);
    1616        $finfo = pathinfo($file);
    17         $files = glob($path.$finfo['filename'].'-*.'.$finfo['extension']); // TODO add a safe filter
     17        $files = glob($path.$finfo['filename'].'-*.'.$finfo['extension']); // TODO add a safer filter
    1818        $ok    = true;
    1919        $amt1  = count($files);
     
    3030                $error = sprintf( __('Unable to regenerate metadata (ID %1$s «Unknown reason»)', 'imagecare'), $pid);
    3131            } else {
    32                 if(wp_update_attachment_metadata( $pid, $metadata )) {
     32                if($org===$metadata) {
     33                    $success = sprintf( __( '"%1$s" (ID %2$s) already had the right size.', 'imagecare' ), $fname, $pid );
     34                } elseif(wp_update_attachment_metadata( $pid, $metadata )) {
    3335                    $files = glob($path.$finfo['filename'].'-*.'.$finfo['extension']);
    3436                    $amt2  = count($files);
     
    3941                    $success .= sprintf( __( '"%1$s" (ID %2$s) was successfully regenerated from %3$s files (%4$s Kb) to %5$s files (%6$s Kb) saving %7$s Kb.', 'imagecare' ), $fname, $pid, $amt1, intval($size1/1024), $amt2, intval($size2/1024), $saved );
    4042                } else {
    41                     $error = sprintf( __('File "%1$s" (ID %2$s) failed when updating the database', 'imagecare'), $img, $pid);
     43                    $error = sprintf( __('File "%1$s" (ID %2$s) failed when updating the database', 'imagecare'), $fname, $pid);
    4244                }
    4345            }
  • imagecare/trunk/inc-func-maxres.php

    r1448419 r1481443  
    1616    if($info) {
    1717        $file  = $this->path.$info['file'];
     18        $fname = basename($file);
     19        $finfo = pathinfo($file);
    1820        $img_o = imagecreatefromjpeg($file);
    1921        $img_w = imagesx($img_o);
     
    4749                    $saved = intval(($img_s-$new_s)/1024);
    4850                    if(update_post_meta($pid, '_wp_attachment_metadata', $info)) {
    49                         $success = sprintf( __( '"%1$s" (ID %2$s) was successfully from %3$s to %4$s saving %5$s.', 'imagecare' ), $file, $pid, $res1, $res2, $saved );
     51                        $success = sprintf( __( '"%1$s" (ID %2$s) was successfully from %3$s to %4$s saving %5$s.', 'imagecare' ), $fname, $pid, $res1, $res2, $saved );
    5052                    } else {
    51                         $error = sprintf( __('File "%1$s" (ID %2$s) failed when updating the database', 'imagecare'), $file, $pid);
     53                        $error = sprintf( __('File "%1$s" (ID %2$s) failed when updating the database', 'imagecare'), $fname, $pid);
    5254                    }
    5355                } else {
    54                     $error = sprintf( __('File "%1$s" (ID %2$s) failed when saving the file', 'imagecare'), $file, $pid);
     56                    $error = sprintf( __('File "%1$s" (ID %2$s) failed when saving the file', 'imagecare'), $fname, $pid);
    5557                }
    5658            } else {
    57                 $error = sprintf( __('File "%1$s" (ID %2$s) failed to resample', 'imagecare'), $file, $pid);
     59                $error = sprintf( __('File "%1$s" (ID %2$s) failed to resample', 'imagecare'), $fname, $pid);
    5860            }
    5961        } else {
    60             $success = sprintf( __( '"%1$s" (ID %2$s) already had the right size.', 'imagecare' ), $file, $pid );
     62            $success = sprintf( __( '"%1$s" (ID %2$s) already had the right size.', 'imagecare' ), $fname, $pid );
    6163        }
    6264    } else {
  • imagecare/trunk/inc-func-regensizes.php

    r1448419 r1481443  
    1010    $sizes = !empty($_POST['sizes']) ? explode(chr(44), $_REQUEST['sizes']) : 'x';
    1111
    12     $info = get_post_meta($pid, '_wp_attachment_metadata', true);
     12    $org = $info = get_post_meta($pid, '_wp_attachment_metadata', true);
    1313    if($info) {
    1414        $file  = $this->path.$info['file'];
     15        $fname = basename($file);
     16        $finfo = pathinfo($file);
    1517        $zizes = $this->get_image_sizes();
    1618        if($sizes=='x') {
     
    2325        }
    2426        if(!empty($arr)) {
     27            foreach($arr as $name=>$values) {
     28                $size1 += filesize($finfo['dirname'].'/'.$info['sizes'][$name]['file']);
     29            }
     30            $amt = count($arr);
    2531            $editor = wp_get_image_editor($file);
    2632            if(!is_wp_error($editor)) {
    27                 $info['sizes'] = $editor->multi_resize($arr);
    28                 if(wp_update_attachment_metadata( $pid, $info )) {
    29                     $success .= sprintf( __( '"%1$s" (ID %2$s) was successfully regenerated from %3$s files (%4$s Kb) to %5$s files (%6$s Kb) saving %7$s Kb.', 'imagecare' ), $fname, $pid, $amt1, intval($size1/1024), $amt2, intval($size2/1024), $saved );
     33                $temp = $editor->multi_resize($arr);
     34                foreach($arr as $name=>$values) {
     35                    $info['sizes'][$name] = $temp[$name];
     36                    $size2 += filesize($finfo['dirname'].'/'.$info['sizes'][$name]['file']);
     37                }
     38                $saved = intval(($size1-$size2)/1024);
     39                if($org===$info) {
     40                    $success = sprintf( __( '"%1$s" (ID %2$s) already had the right size.', 'imagecare' ), $fname, $pid );
     41                } elseif(wp_update_attachment_metadata( $pid, $info )) {
     42                    $success .= sprintf( __( '"%1$s" (ID %2$s) was successfully regenerated %3$s files from %4$s Kb to %5$s Kb saving %6$s Kb.', 'imagecare' ), $fname, $pid, $amt, intval($size1/1024), intval($size2/1024), $saved );
    3043                } else {
    31                     $error = sprintf( __('File "%1$s" (ID %2$s) failed when updating the database', 'imagecare'), $img, $pid);
     44                    $error = sprintf( __('File "%1$s" (ID %2$s) failed when updating the database', 'imagecare'), $fname, $pid);
    3245                }
    3346            } else {
    34                 $error = sprintf( __('File "%1$s" (ID %2$s) failed when initializing the editor', 'imagecare'), $img, $pid);
     47                $error = sprintf( __('File "%1$s" (ID %2$s) failed when initializing the editor', 'imagecare'), $fname, $pid);
    3548            }
    3649        } else {
     
    4154    }
    4255
    43 // sleep(10);
     56// sleep(5);
    4457
    4558    die(json_encode(array(
  • imagecare/trunk/inc-iface-regensizes.php

    r1448419 r1481443  
    1919            <td>
    2020                <input type="checkbox" name="dtop" value="x" checked /> All <br/>
    21                 <div style="column-count: 4"><?php foreach($sizes as $name=>$size) { ?>
    22                 <input type="checkbox" name="dtop[]" value="<?php echo $name ?>" /> <?php echo $name ?><br/>
     21                <div style="column-count: 3"><?php foreach($sizes as $name=>$size) { ?>
     22                <input type="checkbox" name="dtop[]" value="<?php echo $name ?>" /> <?php echo $name.' ('.$size['width'].'x'.$size['height'].')' ?><br/>
    2323                <?php } ?></div>
    2424            </td>
     
    141141                        }
    142142                        if(rt_images.length && rt_alive) {
    143                             // do_it(rt_images.shift());
     143                            do_it(rt_images.shift());
    144144                        } else {
    145145                            imagecareFinishUp();
     
    149149                        imagecareUpdateStatus(id, false, response);
    150150                        if(rt_images.length && rt_alive) {
    151                             // do_it(rt_images.shift());
     151                            do_it(rt_images.shift());
    152152                        } else {
    153153                            imagecareFinishUp();
  • imagecare/trunk/readme.txt

    r1448473 r1481443  
    1616
    1717This plugin let the user to scale all the original images because most user upload images from their cameras with a pointless resolution like 4096x3072 that weight 5Mb and the theme doesn´t use more than -let´s say- 1024px that could weigth 100 Kb in the worst case.
     18
     19This plugin let the user to sanitize the filenames removing non-ASCII characters.
    1820
    1921This plugin also let the user backup images based on year-month.
     
    4749* First usable version
    4850
     51= 1.5 =
     52* Added the filename sanitization.
     53
    4954== Upgrade Notice ==
    5055
    51 No previouse versions.
     56Added the filename sanitization.
Note: See TracChangeset for help on using the changeset viewer.