Plugin Directory

Changeset 3129664

Timestamp:
08/01/2024 06:23:05 PM (7 weeks ago)
Author:
nosilver4u
Message:

tagging and releasing 2.6.0

Location:
s3-image-optimizer
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • s3-image-optimizer/tags/2.6.0/changelog.txt

    r2969432 r3129664  
     1
     2
     3
     4
     5
     6
     7
    18= 2.5.1 =
    29* changed: use updated WP coding standards
  • s3-image-optimizer/tags/2.6.0/phpcs.ruleset.xml

    r2969430 r3129664  
    2121    <rule ref="WordPress.PHP.NoSilencedErrors">
    2222        <properties>
    23             <property name="custom_whitelist" type="array" value="ini_get,exif_read_data,ob_end_flush"/>
     23            <property name="customist" type="array" value="ini_get,exif_read_data,ob_end_flush"/>
    2424        </properties>
    2525    </rule>
    2626    <rule ref="WordPress.NamingConventions.ValidVariableName">
    2727        <properties>
    28             <property name="customPropertiesWhitelist" type="array" value="formatOutput,imgQuality,parentNode,nextSibling,documentElement,imagePath,webimagePath,thumbPath,fileName,Version,Name" />
    29         </properties>
    30         <properties>
    31             <property name="customVariablesWhitelist" type="array" value="formatOutput,parentNode,nextSibling,documentElement" />
     28            <property name="allowed_custom_properties" type="array" value="formatOutput,imgQuality,parentNode,nextSibling,documentElement,imagePath,webimagePath,thumbPath,fileName,Version,Name" />
    3229        </properties>
    3330    </rule>
    3431
    35     <config name="testVersion">7.3-</config>
     32    <config name="testVersion">-</config>
    3633    <rule ref="PHPCompatibilityWP">
    3734        <severity>10</severity>
  • s3-image-optimizer/tags/2.6.0/readme.txt

    r2969432 r3129664  
    11=== S3 Image Optimizer ===
    22Contributors: nosilver4u
    3 Tags: amazon, s3, image, optimize, optimization, photo, picture, seo, compression, wp-cli
    4 Requires at least: 6.1
    5 Tested up to: 6.3
    6 Requires PHP: 7.3
    7 Stable tag: 2.5.1
     3Tags: , compression, wp-cli
     4Requires at least: 6.
     5Tested up to: 6.
     6Requires PHP:
     7Stable tag: 2.
    88License: GPLv3
    99
     
    4040`
    4141
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
    4253[View the full list of region names.](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints)
    4354
     
    6273
    6374== Changelog ==
     75
     76
     77
     78
     79
     80
     81
    6482
    6583= 2.5.1 =
  • s3-image-optimizer/tags/2.6.0/s3-image-optimizer.php

    r2969432 r3129664  
    1212Description: Reduce file sizes for images in S3 buckets using lossless and lossy optimization methods via the EWWW Image Optimizer.
    1313Author: Exactly WWW
    14 Version: 2.5.1
    15 Requires at least: 6.1
    16 Requires PHP: 7.3
     14Version: 2.6.0
     15Requires at least: 6.3
     16Requires PHP: 8.1
     17Requires Plugins: ewww-image-optimizer
    1718Author URI: https://ewww.io/
    1819License: GPLv3
     
    2223 * Constants
    2324 */
    24 define( 'S3IO_VERSION', 251 );
     25define( 'S3IO_VERSION', 2 );
    2526// This is the full path of the plugin file itself.
    2627define( 'S3IO_PLUGIN_FILE', __FILE__ );
     
    7576        add_action( 'admin_notices', 's3io_missing_ewww_plugin' );
    7677    }
    77     if ( ! function_exists( 'ewwwio' ) || ! function_exists( 'ewww_image_optimizer_filesize' ) ) {
     78    if ( ) ) {
    7879        add_action( 'network_admin_notices', 's3io_ewww_plugin_outdated' );
    7980        add_action( 'admin_notices', 's3io_ewww_plugin_outdated' );
     
    194195    if ( defined( 'S3_IMAGE_OPTIMIZER_ENDPOINT' ) && S3_IMAGE_OPTIMIZER_ENDPOINT ) {
    195196        $args['endpoint'] = S3_IMAGE_OPTIMIZER_ENDPOINT;
     197
     198
     199
    196200    }
    197201    return $args;
     
    636640    if ( empty( $bucket_list ) ) {
    637641        global $s3io_amazon_web_services;
     642
    638643        try {
    639644            $client = $s3io_amazon_web_services->get_client();
    640645        } catch ( Exception $e ) {
    641646            $s3io_errors[] = $e->getMessage();
    642         }
    643         $bucket_list = array();
     647       
     648       
    644649        try {
    645650            $buckets = $client->listBuckets();
     
    699704    $bucket_list = s3io_get_selected_buckets();
    700705    if ( ! empty( $s3io_errors ) ) {
    701         /* translators: %s: AWS error message */
    702706        if ( $wpcli ) {
    703707            return 0;
     
    721725        }
    722726        try {
    723             $location = $client->getBucketLocation(
    724                 array(
    725                     'Bucket' => $bucket,
    726                 )
    727             );
     727            $location = $client->getBucketLocation( array( 'Bucket' => $bucket ) );
    728728        } catch ( Exception $e ) {
    729729            $location = new WP_Error( 'exception', $e->getMessage() );
     
    11341134    $alternate = true;
    11351135    foreach ( $already_optimized as $optimized_image ) {
    1136         $file_size = size_format( $optimized_image['image_size'], 2 );
     1136        $file_size = size_format( $optimized_image['image_size'], );
    11371137        $file_size = str_replace( '.00 B ', ' B', $file_size );
    11381138        ?>
     
    11431143                <?php
    11441144                /* translators: %s: size of image, in bytes */
    1145                 echo esc_html( $optimized_image['results'] ) . ' <br>' . sprintf( esc_html__( 'Image Size: %s', 's3-image-optimizer' ), (int) $file_size );
     1145                echo esc_html( $optimized_image['results'] ) . ' <br>' . sprintf( esc_html__( 'Image Size: %s', 's3-image-optimizer' ), );
    11461146                ?>
    11471147                <br><a class="removeimage" onclick="s3ioRemoveImage( <?php echo (int) $optimized_image['id']; ?> )"><?php esc_html_e( 'Remove from table', 's3-image-optimizer' ); ?></a>
     
    14721472        die();
    14731473    }
     1474
     1475
     1476
    14741477    $new_size = ewww_image_optimizer_filesize( $filename );
    14751478    if ( $new_size < $fetch_result['ContentLength'] ) {
     
    14851488                    'Key'          => $image_record['path'],
    14861489                    'SourceFile'   => $filename,
    1487                     'ACL'          => 'public-read',
    14881490                    'ContentType'  => $fetch_result['ContentType'],
    14891491                    'CacheControl' => 'max-age=31536000',
     
    14911493                )
    14921494            );
     1495
     1496
     1497
     1498
     1499
     1500
     1501
     1502
     1503
    14931504        } catch ( Exception $e ) {
    14941505            if ( defined( 'WP_CLI' ) && WP_CLI ) {
     
    15191530                    'Key'          => $image_record['path'] . '.webp',
    15201531                    'SourceFile'   => $filename . '.webp',
    1521                     'ACL'          => 'public-read',
    15221532                    'ContentType'  => 'image/webp',
    15231533                    'CacheControl' => 'max-age=31536000',
     
    15251535                )
    15261536            );
     1537
     1538
     1539
     1540
     1541
     1542
     1543
     1544
     1545
    15271546        } catch ( Exception $e ) {
    15281547            if ( defined( 'WP_CLI' ) && WP_CLI ) {
     
    16051624function s3io_url_loop() {
    16061625    s3io_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
    1607     $output = array();
    16081626    // Verify that an authorized user has started the optimizer.
    16091627    $permissions = apply_filters( 'ewww_image_optimizer_bulk_permissions', '' );
     
    16111629        die( wp_json_encode( array( 'error' => esc_html__( 'Access token has expired, please reload the page.', 's3-image-optimizer' ) ) ) );
    16121630    }
    1613     $started = microtime( true );
     1631    global $s3io_errors;
     1632    $s3io_errors = array();
     1633    $output      = array();
     1634    $started     = microtime( true );
    16141635    if (
    16151636        function_exists( 'ewww_image_optimizer_stl_check' ) &&
     
    16221643    if ( empty( $_REQUEST['s3io_url'] ) ) {
    16231644        $output['error'] = esc_html__( 'No URL supplied', 's3-image-optimizer' );
    1624         echo wp_json_encode( $output );
    1625         die();
     1645        wp_die( wp_json_encode( $output ) );
    16261646    }
    16271647    $url = esc_url_raw( wp_unslash( $_REQUEST['s3io_url'] ) );
     
    16291649        $url_args = s3io_get_args_from_url( $url );
    16301650    }
     1651
     1652
     1653
     1654
     1655
     1656
     1657
     1658
     1659
     1660
     1661
     1662
     1663
    16311664    if ( empty( $url ) || empty( $url_args ) ) {
    16321665        $output['error'] = esc_html__( 'Invalid URL supplied', 's3-image-optimizer' );
    1633         echo wp_json_encode( $output );
    1634         die();
     1666        wp_die( wp_json_encode( $output ) );
    16351667    }
    16361668    $url_args['path'] = ltrim( $url_args['path'], '/' );
     
    16381670    $upload_dir = s3io_make_upload_dir();
    16391671    if ( ! $upload_dir ) {
    1640         die(
     1672        die(
    16411673            wp_json_encode(
    16421674                array(
     
    16491681    s3io_debug_message( "stashing files in $upload_dir" );
    16501682    if ( false !== strpos( $upload_dir, 's3://' ) ) {
    1651         /* translators: %s: path to uploads directory */
    1652         die( wp_json_encode( array( 'error' => sprintf( esc_html__( 'Received an unusable working directory: %s', 's3-image-optimizer' ), $upload_dir ) ) ) );
     1683        wp_die(
     1684            wp_json_encode(
     1685                array(
     1686                    /* translators: %s: path to uploads directory */
     1687                    'error' => sprintf( esc_html__( 'Received an unusable working directory: %s', 's3-image-optimizer' ), $upload_dir ),
     1688                )
     1689            )
     1690        );
    16531691    }
    16541692    global $s3io_amazon_web_services;
     
    16561694        $client = $s3io_amazon_web_services->get_client();
    16571695    } catch ( Exception $e ) {
    1658         die( wp_json_encode( array( 'error' => wp_kses_post( $e->getMessage() ) ) ) );
    1659     }
    1660     try {
    1661         $location = $client->getBucketLocation(
    1662             array(
    1663                 'Bucket' => $url_args['bucket'],
     1696        wp_die(
     1697            wp_json_encode(
     1698                array(
     1699                    'error' => sprintf(
     1700                        /* translators: %s: AWS/S3 error message */
     1701                        esc_html__( 'Error connecting to S3: %s', 's3-image-optimizer' ),
     1702                        wp_kses_post( $e->getMessage() )
     1703                    ),
     1704                )
    16641705            )
    16651706        );
    1666     } catch ( Exception $e ) {
    1667         $location = new WP_Error( 'exception', $e->getMessage() );
    16681707    }
    16691708    $filename = $upload_dir . $url_args['path'];
     
    16911730        die( wp_json_encode( $output ) );
    16921731    }
     1732
     1733
     1734
    16931735    $new_size = filesize( $filename );
    16941736    if ( $new_size < $fetch_result['ContentLength'] ) {
    16951737        // Re-upload to S3.
    1696         $client->putObject(
    1697             array(
    1698                 'Bucket'       => $url_args['bucket'],
    1699                 'Key'          => $url_args['path'],
    1700                 'SourceFile'   => $filename,
    1701                 'ACL'          => 'public-read',
    1702                 'ContentType'  => $fetch_result['ContentType'],
    1703                 'CacheControl' => 'max-age=31536000',
    1704                 'Expires'      => gmdate( 'D, d M Y H:i:s O', time() + 31536000 ),
    1705             )
    1706         );
     1738        try {
     1739            $client->putObject(
     1740                array(
     1741                    'Bucket'       => $url_args['bucket'],
     1742                    'Key'          => $url_args['path'],
     1743                    'SourceFile'   => $filename,
     1744                    'ContentType'  => $fetch_result['ContentType'],
     1745                    'CacheControl' => 'max-age=31536000',
     1746                    'Expires'      => gmdate( 'D, d M Y H:i:s O', time() + 31536000 ),
     1747                )
     1748            );
     1749            if ( ! $ownership_control_enforced ) {
     1750                $client->putObjectAcl(
     1751                    array(
     1752                        'Bucket' => $url_args['bucket'],
     1753                        'Key'    => $url_args['path'],
     1754                        'ACL'    => 'public-read',
     1755                    )
     1756                );
     1757            }
     1758        } catch ( Exception $e ) {
     1759            $output['error'] = wp_kses_post( "Put failed for bucket: {$url_args['bucket']}, path: {$url_args['path']}, message:" . $e->getMessage() );
     1760            wp_die( wp_json_encode( $output ) );
     1761        }
    17071762    }
    17081763    unlink( $filename );
    17091764    $webp_size = ewww_image_optimizer_filesize( $filename . '.webp' );
    17101765    if ( $webp_size ) {
    1711         if ( $verbose && defined( 'WP_CLI' ) && WP_CLI ) {
    1712             WP_CLI::line( "About to upload $filename.webp" );
    1713         }
    17141766        // Upload to S3.
    17151767        try {
     
    17191771                    'Key'          => $url_args['path'] . '.webp',
    17201772                    'SourceFile'   => $filename . '.webp',
    1721                     'ACL'          => 'public-read',
    17221773                    'ContentType'  => 'image/webp',
    17231774                    'CacheControl' => 'max-age=31536000',
     
    17251776                )
    17261777            );
     1778
     1779
     1780
     1781
     1782
     1783
     1784
     1785
     1786
    17271787        } catch ( Exception $e ) {
    1728             if ( defined( 'WP_CLI' ) && WP_CLI ) {
    1729                 WP_CLI::error( "Put failed for bucket: {$image_record['bucket']}, path: {$image_record['path']}.webp, message:" . $e->getMessage() );
    1730             } else {
    1731                 $output['error'] = wp_kses_post( "Put failed for bucket: {$image_record['bucket']}, path: {$image_record['path']}.webp, message:" . $e->getMessage() );
    1732                 echo wp_json_encode( $output );
    1733             }
    1734             die();
    1735         }
    1736         if ( $verbose && defined( 'WP_CLI' ) && WP_CLI ) {
    1737             WP_CLI::line( "Finished upload of $filename.webp" );
     1788            $output['error'] = wp_kses_post( "Put failed for bucket: {$url_args['bucket']}, path: {$url_args['path']}.webp, message:" . $e->getMessage() );
     1789            wp_die( wp_json_encode( $output ) );
    17381790        }
    17391791        unlink( $filename . '.webp' );
     
    17531805
    17541806    die( wp_json_encode( $output ) );
     1807
     1808
     1809
     1810
     1811
     1812
     1813
     1814
     1815
     1816
     1817
     1818
     1819
     1820
     1821
     1822
     1823
     1824
     1825
     1826
     1827
     1828
     1829
     1830
     1831
     1832
     1833
    17551834}
    17561835
     
    17861865        }
    17871866    }
    1788     global $s3io_amazon_web_services;
    1789     try {
    1790         $client = $s3io_amazon_web_services->get_client();
    1791     } catch ( Exception $e ) {
    1792         s3io_debug_message( 'unable to initialize AWS client lib' );
    1793         return false;
    1794     }
    1795     try {
    1796         $buckets = $client->listBuckets();
    1797     } catch ( Exception $e ) {
    1798         $buckets = new WP_Error( 'exception', $e->getMessage() );
    1799     }
    1800 
    1801     // If retrieving buckets from AWS failed, then we use the bucketlist option.
    1802     if ( is_wp_error( $buckets ) ) {
    1803         $bucket_list = get_option( 's3io_bucketlist' );
    1804     } else {
    1805         $bucket_list = array();
    1806         foreach ( $buckets['Buckets'] as $aws_bucket ) {
    1807             $bucket_list[] = $aws_bucket['Name'];
    1808         }
    1809     }
     1867
     1868    $bucket_list = s3io_get_selected_buckets();
    18101869
    18111870    // If we don't have a list of buckets, we can't do much more here.
     
    18351894    // Otherwise, we must have a custom domain, so lets do a quick search for the attachment in all buckets.
    18361895    // Doing it in a separate foreach, in case there are performance implications of switching the region in accounts with lots of buckets.
     1896
     1897
     1898
     1899
     1900
     1901
     1902
    18371903    $key = ltrim( $urlinfo['path'], '/' );
    18381904    foreach ( $bucket_list as $aws_bucket ) {
    1839         try {
    1840             $location = $client->getBucketLocation(
    1841                 array(
    1842                     'Bucket' => $aws_bucket,
    1843                 )
    1844             );
    1845         } catch ( Exception $e ) {
    1846             $location = new WP_Error( 'exception', $e->getMessage() );
    1847         }
    18481905        try {
    18491906            $exists = $client->headObject(
  • s3-image-optimizer/trunk/changelog.txt

    r2969432 r3129664  
     1
     2
     3
     4
     5
     6
     7
    18= 2.5.1 =
    29* changed: use updated WP coding standards
  • s3-image-optimizer/trunk/phpcs.ruleset.xml

    r2969430 r3129664  
    2121    <rule ref="WordPress.PHP.NoSilencedErrors">
    2222        <properties>
    23             <property name="custom_whitelist" type="array" value="ini_get,exif_read_data,ob_end_flush"/>
     23            <property name="customist" type="array" value="ini_get,exif_read_data,ob_end_flush"/>
    2424        </properties>
    2525    </rule>
    2626    <rule ref="WordPress.NamingConventions.ValidVariableName">
    2727        <properties>
    28             <property name="customPropertiesWhitelist" type="array" value="formatOutput,imgQuality,parentNode,nextSibling,documentElement,imagePath,webimagePath,thumbPath,fileName,Version,Name" />
    29         </properties>
    30         <properties>
    31             <property name="customVariablesWhitelist" type="array" value="formatOutput,parentNode,nextSibling,documentElement" />
     28            <property name="allowed_custom_properties" type="array" value="formatOutput,imgQuality,parentNode,nextSibling,documentElement,imagePath,webimagePath,thumbPath,fileName,Version,Name" />
    3229        </properties>
    3330    </rule>
    3431
    35     <config name="testVersion">7.3-</config>
     32    <config name="testVersion">-</config>
    3633    <rule ref="PHPCompatibilityWP">
    3734        <severity>10</severity>
  • s3-image-optimizer/trunk/readme.txt

    r2969432 r3129664  
    11=== S3 Image Optimizer ===
    22Contributors: nosilver4u
    3 Tags: amazon, s3, image, optimize, optimization, photo, picture, seo, compression, wp-cli
    4 Requires at least: 6.1
    5 Tested up to: 6.3
    6 Requires PHP: 7.3
    7 Stable tag: 2.5.1
     3Tags: , compression, wp-cli
     4Requires at least: 6.
     5Tested up to: 6.
     6Requires PHP:
     7Stable tag: 2.
    88License: GPLv3
    99
     
    4040`
    4141
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
    4253[View the full list of region names.](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints)
    4354
     
    6273
    6374== Changelog ==
     75
     76
     77
     78
     79
     80
     81
    6482
    6583= 2.5.1 =
  • s3-image-optimizer/trunk/s3-image-optimizer.php

    r2969432 r3129664  
    1212Description: Reduce file sizes for images in S3 buckets using lossless and lossy optimization methods via the EWWW Image Optimizer.
    1313Author: Exactly WWW
    14 Version: 2.5.1
    15 Requires at least: 6.1
    16 Requires PHP: 7.3
     14Version: 2.6.0
     15Requires at least: 6.3
     16Requires PHP: 8.1
     17Requires Plugins: ewww-image-optimizer
    1718Author URI: https://ewww.io/
    1819License: GPLv3
     
    2223 * Constants
    2324 */
    24 define( 'S3IO_VERSION', 251 );
     25define( 'S3IO_VERSION', 2 );
    2526// This is the full path of the plugin file itself.
    2627define( 'S3IO_PLUGIN_FILE', __FILE__ );
     
    7576        add_action( 'admin_notices', 's3io_missing_ewww_plugin' );
    7677    }
    77     if ( ! function_exists( 'ewwwio' ) || ! function_exists( 'ewww_image_optimizer_filesize' ) ) {
     78    if ( ) ) {
    7879        add_action( 'network_admin_notices', 's3io_ewww_plugin_outdated' );
    7980        add_action( 'admin_notices', 's3io_ewww_plugin_outdated' );
     
    194195    if ( defined( 'S3_IMAGE_OPTIMIZER_ENDPOINT' ) && S3_IMAGE_OPTIMIZER_ENDPOINT ) {
    195196        $args['endpoint'] = S3_IMAGE_OPTIMIZER_ENDPOINT;
     197
     198
     199
    196200    }
    197201    return $args;
     
    636640    if ( empty( $bucket_list ) ) {
    637641        global $s3io_amazon_web_services;
     642
    638643        try {
    639644            $client = $s3io_amazon_web_services->get_client();
    640645        } catch ( Exception $e ) {
    641646            $s3io_errors[] = $e->getMessage();
    642         }
    643         $bucket_list = array();
     647       
     648       
    644649        try {
    645650            $buckets = $client->listBuckets();
     
    699704    $bucket_list = s3io_get_selected_buckets();
    700705    if ( ! empty( $s3io_errors ) ) {
    701         /* translators: %s: AWS error message */
    702706        if ( $wpcli ) {
    703707            return 0;
     
    721725        }
    722726        try {
    723             $location = $client->getBucketLocation(
    724                 array(
    725                     'Bucket' => $bucket,
    726                 )
    727             );
     727            $location = $client->getBucketLocation( array( 'Bucket' => $bucket ) );
    728728        } catch ( Exception $e ) {
    729729            $location = new WP_Error( 'exception', $e->getMessage() );
     
    11341134    $alternate = true;
    11351135    foreach ( $already_optimized as $optimized_image ) {
    1136         $file_size = size_format( $optimized_image['image_size'], 2 );
     1136        $file_size = size_format( $optimized_image['image_size'], );
    11371137        $file_size = str_replace( '.00 B ', ' B', $file_size );
    11381138        ?>
     
    11431143                <?php
    11441144                /* translators: %s: size of image, in bytes */
    1145                 echo esc_html( $optimized_image['results'] ) . ' <br>' . sprintf( esc_html__( 'Image Size: %s', 's3-image-optimizer' ), (int) $file_size );
     1145                echo esc_html( $optimized_image['results'] ) . ' <br>' . sprintf( esc_html__( 'Image Size: %s', 's3-image-optimizer' ), );
    11461146                ?>
    11471147                <br><a class="removeimage" onclick="s3ioRemoveImage( <?php echo (int) $optimized_image['id']; ?> )"><?php esc_html_e( 'Remove from table', 's3-image-optimizer' ); ?></a>
     
    14721472        die();
    14731473    }
     1474
     1475
     1476
    14741477    $new_size = ewww_image_optimizer_filesize( $filename );
    14751478    if ( $new_size < $fetch_result['ContentLength'] ) {
     
    14851488                    'Key'          => $image_record['path'],
    14861489                    'SourceFile'   => $filename,
    1487                     'ACL'          => 'public-read',
    14881490                    'ContentType'  => $fetch_result['ContentType'],
    14891491                    'CacheControl' => 'max-age=31536000',
     
    14911493                )
    14921494            );
     1495
     1496
     1497
     1498
     1499
     1500
     1501
     1502
     1503
    14931504        } catch ( Exception $e ) {
    14941505            if ( defined( 'WP_CLI' ) && WP_CLI ) {
     
    15191530                    'Key'          => $image_record['path'] . '.webp',
    15201531                    'SourceFile'   => $filename . '.webp',
    1521                     'ACL'          => 'public-read',
    15221532                    'ContentType'  => 'image/webp',
    15231533                    'CacheControl' => 'max-age=31536000',
     
    15251535                )
    15261536            );
     1537
     1538
     1539
     1540
     1541
     1542
     1543
     1544
     1545
    15271546        } catch ( Exception $e ) {
    15281547            if ( defined( 'WP_CLI' ) && WP_CLI ) {
     
    16051624function s3io_url_loop() {
    16061625    s3io_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
    1607     $output = array();
    16081626    // Verify that an authorized user has started the optimizer.
    16091627    $permissions = apply_filters( 'ewww_image_optimizer_bulk_permissions', '' );
     
    16111629        die( wp_json_encode( array( 'error' => esc_html__( 'Access token has expired, please reload the page.', 's3-image-optimizer' ) ) ) );
    16121630    }
    1613     $started = microtime( true );
     1631    global $s3io_errors;
     1632    $s3io_errors = array();
     1633    $output      = array();
     1634    $started     = microtime( true );
    16141635    if (
    16151636        function_exists( 'ewww_image_optimizer_stl_check' ) &&
     
    16221643    if ( empty( $_REQUEST['s3io_url'] ) ) {
    16231644        $output['error'] = esc_html__( 'No URL supplied', 's3-image-optimizer' );
    1624         echo wp_json_encode( $output );
    1625         die();
     1645        wp_die( wp_json_encode( $output ) );
    16261646    }
    16271647    $url = esc_url_raw( wp_unslash( $_REQUEST['s3io_url'] ) );
     
    16291649        $url_args = s3io_get_args_from_url( $url );
    16301650    }
     1651
     1652
     1653
     1654
     1655
     1656
     1657
     1658
     1659
     1660
     1661
     1662
     1663
    16311664    if ( empty( $url ) || empty( $url_args ) ) {
    16321665        $output['error'] = esc_html__( 'Invalid URL supplied', 's3-image-optimizer' );
    1633         echo wp_json_encode( $output );
    1634         die();
     1666        wp_die( wp_json_encode( $output ) );
    16351667    }
    16361668    $url_args['path'] = ltrim( $url_args['path'], '/' );
     
    16381670    $upload_dir = s3io_make_upload_dir();
    16391671    if ( ! $upload_dir ) {
    1640         die(
     1672        die(
    16411673            wp_json_encode(
    16421674                array(
     
    16491681    s3io_debug_message( "stashing files in $upload_dir" );
    16501682    if ( false !== strpos( $upload_dir, 's3://' ) ) {
    1651         /* translators: %s: path to uploads directory */
    1652         die( wp_json_encode( array( 'error' => sprintf( esc_html__( 'Received an unusable working directory: %s', 's3-image-optimizer' ), $upload_dir ) ) ) );
     1683        wp_die(
     1684            wp_json_encode(
     1685                array(
     1686                    /* translators: %s: path to uploads directory */
     1687                    'error' => sprintf( esc_html__( 'Received an unusable working directory: %s', 's3-image-optimizer' ), $upload_dir ),
     1688                )
     1689            )
     1690        );
    16531691    }
    16541692    global $s3io_amazon_web_services;
     
    16561694        $client = $s3io_amazon_web_services->get_client();
    16571695    } catch ( Exception $e ) {
    1658         die( wp_json_encode( array( 'error' => wp_kses_post( $e->getMessage() ) ) ) );
    1659     }
    1660     try {
    1661         $location = $client->getBucketLocation(
    1662             array(
    1663                 'Bucket' => $url_args['bucket'],
     1696        wp_die(
     1697            wp_json_encode(
     1698                array(
     1699                    'error' => sprintf(
     1700                        /* translators: %s: AWS/S3 error message */
     1701                        esc_html__( 'Error connecting to S3: %s', 's3-image-optimizer' ),
     1702                        wp_kses_post( $e->getMessage() )
     1703                    ),
     1704                )
    16641705            )
    16651706        );
    1666     } catch ( Exception $e ) {
    1667         $location = new WP_Error( 'exception', $e->getMessage() );
    16681707    }
    16691708    $filename = $upload_dir . $url_args['path'];
     
    16911730        die( wp_json_encode( $output ) );
    16921731    }
     1732
     1733
     1734
    16931735    $new_size = filesize( $filename );
    16941736    if ( $new_size < $fetch_result['ContentLength'] ) {
    16951737        // Re-upload to S3.
    1696         $client->putObject(
    1697             array(
    1698                 'Bucket'       => $url_args['bucket'],
    1699                 'Key'          => $url_args['path'],
    1700                 'SourceFile'   => $filename,
    1701                 'ACL'          => 'public-read',
    1702                 'ContentType'  => $fetch_result['ContentType'],
    1703                 'CacheControl' => 'max-age=31536000',
    1704                 'Expires'      => gmdate( 'D, d M Y H:i:s O', time() + 31536000 ),
    1705             )
    1706         );
     1738        try {
     1739            $client->putObject(
     1740                array(
     1741                    'Bucket'       => $url_args['bucket'],
     1742                    'Key'          => $url_args['path'],
     1743                    'SourceFile'   => $filename,
     1744                    'ContentType'  => $fetch_result['ContentType'],
     1745                    'CacheControl' => 'max-age=31536000',
     1746                    'Expires'      => gmdate( 'D, d M Y H:i:s O', time() + 31536000 ),
     1747                )
     1748            );
     1749            if ( ! $ownership_control_enforced ) {
     1750                $client->putObjectAcl(
     1751                    array(
     1752                        'Bucket' => $url_args['bucket'],
     1753                        'Key'    => $url_args['path'],
     1754                        'ACL'    => 'public-read',
     1755                    )
     1756                );
     1757            }
     1758        } catch ( Exception $e ) {
     1759            $output['error'] = wp_kses_post( "Put failed for bucket: {$url_args['bucket']}, path: {$url_args['path']}, message:" . $e->getMessage() );
     1760            wp_die( wp_json_encode( $output ) );
     1761        }
    17071762    }
    17081763    unlink( $filename );
    17091764    $webp_size = ewww_image_optimizer_filesize( $filename . '.webp' );
    17101765    if ( $webp_size ) {
    1711         if ( $verbose && defined( 'WP_CLI' ) && WP_CLI ) {
    1712             WP_CLI::line( "About to upload $filename.webp" );
    1713         }
    17141766        // Upload to S3.
    17151767        try {
     
    17191771                    'Key'          => $url_args['path'] . '.webp',
    17201772                    'SourceFile'   => $filename . '.webp',
    1721                     'ACL'          => 'public-read',
    17221773                    'ContentType'  => 'image/webp',
    17231774                    'CacheControl' => 'max-age=31536000',
     
    17251776                )
    17261777            );
     1778
     1779
     1780
     1781
     1782
     1783
     1784
     1785
     1786
    17271787        } catch ( Exception $e ) {
    1728             if ( defined( 'WP_CLI' ) && WP_CLI ) {
    1729                 WP_CLI::error( "Put failed for bucket: {$image_record['bucket']}, path: {$image_record['path']}.webp, message:" . $e->getMessage() );
    1730             } else {
    1731                 $output['error'] = wp_kses_post( "Put failed for bucket: {$image_record['bucket']}, path: {$image_record['path']}.webp, message:" . $e->getMessage() );
    1732                 echo wp_json_encode( $output );
    1733             }
    1734             die();
    1735         }
    1736         if ( $verbose && defined( 'WP_CLI' ) && WP_CLI ) {
    1737             WP_CLI::line( "Finished upload of $filename.webp" );
     1788            $output['error'] = wp_kses_post( "Put failed for bucket: {$url_args['bucket']}, path: {$url_args['path']}.webp, message:" . $e->getMessage() );
     1789            wp_die( wp_json_encode( $output ) );
    17381790        }
    17391791        unlink( $filename . '.webp' );
     
    17531805
    17541806    die( wp_json_encode( $output ) );
     1807
     1808
     1809
     1810
     1811
     1812
     1813
     1814
     1815
     1816
     1817
     1818
     1819
     1820
     1821
     1822
     1823
     1824
     1825
     1826
     1827
     1828
     1829
     1830
     1831
     1832
     1833
    17551834}
    17561835
     
    17861865        }
    17871866    }
    1788     global $s3io_amazon_web_services;
    1789     try {
    1790         $client = $s3io_amazon_web_services->get_client();
    1791     } catch ( Exception $e ) {
    1792         s3io_debug_message( 'unable to initialize AWS client lib' );
    1793         return false;
    1794     }
    1795     try {
    1796         $buckets = $client->listBuckets();
    1797     } catch ( Exception $e ) {
    1798         $buckets = new WP_Error( 'exception', $e->getMessage() );
    1799     }
    1800 
    1801     // If retrieving buckets from AWS failed, then we use the bucketlist option.
    1802     if ( is_wp_error( $buckets ) ) {
    1803         $bucket_list = get_option( 's3io_bucketlist' );
    1804     } else {
    1805         $bucket_list = array();
    1806         foreach ( $buckets['Buckets'] as $aws_bucket ) {
    1807             $bucket_list[] = $aws_bucket['Name'];
    1808         }
    1809     }
     1867
     1868    $bucket_list = s3io_get_selected_buckets();
    18101869
    18111870    // If we don't have a list of buckets, we can't do much more here.
     
    18351894    // Otherwise, we must have a custom domain, so lets do a quick search for the attachment in all buckets.
    18361895    // Doing it in a separate foreach, in case there are performance implications of switching the region in accounts with lots of buckets.
     1896
     1897
     1898
     1899
     1900
     1901
     1902
    18371903    $key = ltrim( $urlinfo['path'], '/' );
    18381904    foreach ( $bucket_list as $aws_bucket ) {
    1839         try {
    1840             $location = $client->getBucketLocation(
    1841                 array(
    1842                     'Bucket' => $aws_bucket,
    1843                 )
    1844             );
    1845         } catch ( Exception $e ) {
    1846             $location = new WP_Error( 'exception', $e->getMessage() );
    1847         }
    18481905        try {
    18491906            $exists = $client->headObject(
Note: See TracChangeset for help on using the changeset viewer.