Plugin Directory

Changeset 403224


Ignore:
Timestamp:
07/01/2011 12:07:24 PM (15 years ago)
Author:
imthiaz
Message:

Work in progress
Files Mime type fix as for some server it is not detecting the proper type for css and js files

File:
1 edited

Legend:

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

    r403201 r403224  
    6060
    6161    $this->blockDirectory = array('wpcf7_captcha');
    62     $this->blockExtension = array('php');
     62    $this->blockExtension = array('php', 'htm', 'html');
    6363
    6464    $this->s3CacheFolder = ABSPATH . 'wp-content' . DIRECTORY_SEPARATOR . 's3temp' . DIRECTORY_SEPARATOR;
     
    226226            }
    227227            if ($shouldUpload) {
    228             if ($s3Adapter->putObjectFile($filePath, $this->s3BucketName, $fileInfo ['path'], S3::ACL_PUBLIC_READ) === TRUE) {
     228            $fileMimeType = $this->getFileType($filePath);
     229            if ($s3Adapter->putObjectFile($filePath, $this->s3BucketName, $fileInfo ['path'], S3::ACL_PUBLIC_READ, array(), $fileMimeType) === TRUE) {
    229230                $fileStatus = 'done';
    230231            }
     
    240241    }
    241242
     243    function getFileType($file) {
     244    $ext = strtolower(pathInfo($file, PATHINFO_EXTENSION));
     245    static $exts = array(
     246    'jpg' => 'image/jpeg',
     247    'gif' => 'image/gif',
     248    'png' => 'image/png',
     249    'tif' => 'image/tiff',
     250    'tiff' => 'image/tiff',
     251    'ico' => 'image/x-icon',
     252    'swf' => 'application/x-shockwave-flash',
     253    'pdf' => 'application/pdf',
     254    'zip' => 'application/zip',
     255    'gz' => 'application/x-gzip',
     256    'tar' => 'application/x-tar',
     257    'bz' => 'application/x-bzip',
     258    'bz2' => 'application/x-bzip2',
     259    'txt' => 'text/plain',
     260    'asc' => 'text/plain',
     261    'htm' => 'text/html',
     262    'html' => 'text/html',
     263    'css' => 'text/css',
     264    'js' => 'text/javascript',
     265    'xml' => 'text/xml',
     266    'xsl' => 'application/xsl+xml',
     267    'ogg' => 'application/ogg',
     268    'mp3' => 'audio/mpeg',
     269    'wav' => 'audio/x-wav',
     270    'avi' => 'video/x-msvideo',
     271    'mpg' => 'video/mpeg',
     272    'mpeg' => 'video/mpeg',
     273    'mov' => 'video/quicktime',
     274    'flv' => 'video/x-flv',
     275    'php' => 'text/x-php'
     276    );
     277    return isset($exts[$ext]) ? $exts[$ext] : 'application/octet-stream';
     278    }
     279
    242280    function script_loader_src($scriptURL) {
    243281    if (!is_admin()) {
     
    265303        }
    266304        return $fileCDNURL;
    267         }else{
     305        } else {
    268306        $realPath = $this->getRealPath($justURL);
    269307        if (file_exists($realPath)) {
    270308            $cssFolder = dirname($realPath);
    271309            $cssRelatedFiles = $this->scanDirectoryRecursively($cssFolder);
    272             if(!empty ($cssRelatedFiles)){
    273             foreach ($cssRelatedFiles as $relatedFile){
    274                 $queueFiles = self::getCDNURL($this->siteURL.'/'.$relatedFile);
     310            if (!empty($cssRelatedFiles)) {
     311            foreach ($cssRelatedFiles as $relatedFile) {
     312                $queueFiles = self::getCDNURL($this->siteURL . '/' . $relatedFile);
    275313            }
    276314            }
     
    286324        $directory = substr($directory, 0, -1);
    287325    }
    288    
    289     $extensionToInclude = array('css','png','gif','jpg','jpeg');
    290    
     326
     327    $extensionToInclude = array('css', 'png', 'gif', 'jpg', 'jpeg');
     328
    291329    if (!file_exists($directory) || !is_dir($directory)) {
    292330        return FALSE;
     
    300338                $directoryFiles = $this->scanDirectoryRecursively($path, $filter, $directoryFiles);
    301339            } elseif (is_file($path)) {
    302                 $extension = strtolower(end(explode('.',$path)));
    303                 if(in_array($extension, $extensionToInclude)){
    304                 $directoryFiles[] = str_replace(ABSPATH, '', $path) ;
     340                $extension = strtolower(end(explode('.', $path)));
     341                if (in_array($extension, $extensionToInclude)) {
     342                $directoryFiles[] = str_replace(ABSPATH, '', $path);
    305343                }
    306344            }
Note: See TracChangeset for help on using the changeset viewer.