Plugin Directory

Changeset 403637


Ignore:
Timestamp:
07/02/2011 07:13:14 AM (15 years ago)
Author:
imthiaz
Message:

Added gzip compress option for js and css files

Location:
wp-s3/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-s3/trunk/s3-options.php

    r403515 r403637  
    107107        </tr>
    108108        <tr valign="top">
     109        <th scope="row"><?php _e('Compress JS & CSS') ?></th>
     110        <td>
     111            <fieldset>
     112            <legend class="screen-reader-text"><span><?php _e('Use SSL') ?></span></legend>
     113            <label for="s3plugin_compress_files">
     114                <input name="s3plugin_compress_files" type="checkbox" id="s3plugin_compress_files" value="1" <?php checked('1', get_option('s3plugin_compress_files')); ?> />
     115                <?php _e('Enable this to compress and push js and css files to s3') ?>
     116            </label>
     117            </fieldset>
     118        </td>
     119        </tr>       
     120        <tr valign="top">
    109121        <th scope="row"><label for="s3plugin_cloudfrontURL"><?php _e('Path prefix') ?></label></th>
    110122        <td>
  • wp-s3/trunk/s3.php

    r403515 r403637  
    2424    var $s3UseCloudFrontURL;
    2525    var $s3CloudFrontURL;
     26    var $s3CompressFiles;
    2627    var $s3DirPrefix;
    2728    var $cronScheduleTime;
     
    7273    $this->s3BucketName = get_option('s3plugin_amazon_bucket_name');
    7374    $this->s3UseSSL = (bool) get_option('s3plugin_use_ssl', 0);
     75    $this->s3CompressFiles = (bool) get_option('s3plugin_compress_files', 0);
    7476    $this->s3DirPrefix = get_option('s3plugin_dir_prefix');
    7577
     
    8284        $this->isCloudFrontURLEnabled = FALSE;
    8385    }
    84 
    8586
    8687    $this->cronScheduleTime = get_option('s3plugin_cron_interval', 300);
     
    9798        'deactivatePlugin'));
    9899    add_action('admin_menu', array(&$this, 's3AdminMenu'));
     100
    99101    add_filter('script_loader_src', array(&$this, 'script_loader_src'), 99);
    100102    add_filter('style_loader_src', array(&$this, 'style_loader_src'), 99);
     
    140142        update_option('s3plugin_amazon_secret_key', $_POST ['s3plugin_amazon_secret_key']);
    141143        update_option('s3plugin_amazon_bucket_name', $_POST ['s3plugin_amazon_bucket_name']);
     144
    142145        if (isset($_POST ['s3plugin_use_ssl'])) {
    143146        update_option('s3plugin_use_ssl', $_POST ['s3plugin_use_ssl']);
     
    145148        delete_option('s3plugin_use_ssl');
    146149        }
     150
     151        if (isset($_POST ['s3plugin_compress_files'])) {
     152        update_option('s3plugin_compress_files', $_POST ['s3plugin_compress_files']);
     153        } else {
     154        delete_option('s3plugin_compress_files');
     155        }
     156
    147157        if (isset($_POST ['s3plugin_use_cloudfrontURL'])) {
    148158        update_option('s3plugin_use_cloudfrontURL', $_POST ['s3plugin_use_cloudfrontURL']);
     
    150160        delete_option('s3plugin_use_cloudfrontURL');
    151161        }
     162
    152163        if (isset($_POST ['s3plugin_clear_cache'])) {
    153164        $this->recursive_remove_directory($this->s3CacheFolder, FALSE);
     
    210221    ignore_user_abort(true);
    211222    set_time_limit(0);
    212    
     223
     224    ini_set('display_errors', 1);
     225    ini_set('log_errors', 1);
     226    ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
     227    error_reporting(E_ALL);
     228
    213229    print "Hello";
    214230
     
    218234    $availableBuckets = @$s3Adapter->listBuckets();
    219235    cmVarDebug($availableBuckets);
    220    
     236
    221237    if (!empty($availableBuckets) && in_array($this->s3BucketName, $availableBuckets) == TRUE) {
    222238        $query = "SELECT * FROM {$this->tabeImageQueue} WHERE status='queue' ORDER BY added LIMIT {$this->cronUploadLimit};";
     
    224240        if (!empty($filesToUpload)) {
    225241        foreach ($filesToUpload as $fileInfo) {
     242            cmVarDebug($fileInfo);
    226243            $shouldUpload = TRUE;
    227244            $fileStatus = 'error';
     
    239256            }
    240257            if ($shouldUpload) {
    241             $fileMimeType = $this->getFileType($filePath);
    242             if ($s3Adapter->putObjectFile($filePath, $this->s3BucketName, $this->s3DirPrefix . $fileInfo ['path'], S3::ACL_PUBLIC_READ, array(), $fileMimeType) === TRUE) {
     258            $fileContentType = $this->getFileType($filePath);
     259            $fileRequestHeaders = array(
     260                'Content-Type' => $fileContentType
     261            );
     262            $tempFile = '';
     263            if ($this->s3CompressFiles && ( $fileContentType == 'text/css' || $fileContentType == 'text/javascript')) {
     264                $fileRequestHeaders['Content-Encoding'] = 'gzip';
     265                $tempFile = tempnam($this->s3CacheFolder, 'tmp_gzip');
     266                $gzipFilePointer = fopen($tempFile, "wb+");
     267                fwrite($gzipFilePointer, gzencode(file_get_contents($filePath), 9));
     268                fclose($gzipFilePointer);
     269                $fileResource = $s3Adapter->inputResource(fopen($tempFile, 'rb'), filesize($tempFile));
     270            } else {
     271                $fileResource = $s3Adapter->inputResource(fopen($filePath, 'rb'), filesize($filePath));
     272            }
     273            if ($s3Adapter->putObject($fileResource, $this->s3BucketName, $this->s3DirPrefix . $fileInfo ['path'], S3::ACL_PUBLIC_READ, array(), $fileRequestHeaders) === TRUE) {
    243274                $fileStatus = 'done';
     275            }
     276            if (!empty($tempFile)) {
     277                @unlink($tempFile);
    244278            }
    245279            }
     
    374408    $instance = self::getInstance();
    375409    $relativePath = ltrim(str_replace($instance->siteURL, '', $fileURL), '/');
    376     $realPath = $instance->getRealPath($fileURL);
     410    $realPath = trim($instance->getRealPath($fileURL));
     411    if (empty($realPath)) {
     412        return FALSE;
     413    }
    377414    if (file_exists($realPath)) {
    378415        foreach ($instance->blockDirectory as $blokedDirectory) {
Note: See TracChangeset for help on using the changeset viewer.