Plugin Directory

Changeset 403201


Ignore:
Timestamp:
07/01/2011 10:10:20 AM (15 years ago)
Author:
imthiaz
Message:

Work in progress

File:
1 edited

Legend:

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

    r403109 r403201  
    9393        'deactivatePlugin'));
    9494    add_action('admin_menu', array(&$this, 's3AdminMenu'));
    95     add_filter('script_loader_src', array(&$this, 'script_loader_src'));
     95    add_filter('script_loader_src', array(&$this, 'script_loader_src'), 99);
     96    add_filter('style_loader_src', array(&$this, 'style_loader_src'), 99);
     97
    9698
    9799    if (isset($_GET ['page']) && $_GET ['page'] == 's3plugin-options') {
     
    117119    private function __clone() {
    118120   
    119     }
    120 
    121     function script_loader_src($scriptURL) {
    122     if (!is_admin()) {
    123         $urlParts = parse_url($scriptURL);
    124         $justURL = $urlParts['scheme'] . '://' . $urlParts['host'] . $urlParts['path'];
    125         $fileCDNURL = self::getCDNURL($justURL);
    126         if ($fileCDNURL !== FALSE) {
    127         if (isset($urlParts['query']) && !empty($urlParts['query'])) {
    128             return $fileCDNURL . '?' . $urlParts['query'];
    129         }
    130         return $fileCDNURL;
    131         }
    132     }
    133     return $scriptURL;
    134121    }
    135122
     
    253240    }
    254241
     242    function script_loader_src($scriptURL) {
     243    if (!is_admin()) {
     244        $urlParts = parse_url($scriptURL);
     245        $justURL = $urlParts['scheme'] . '://' . $urlParts['host'] . $urlParts['path'];
     246        $fileCDNURL = self::getCDNURL($justURL);
     247        if ($fileCDNURL !== FALSE) {
     248        if (isset($urlParts['query']) && !empty($urlParts['query'])) {
     249            return $fileCDNURL . '?' . $urlParts['query'];
     250        }
     251        return $fileCDNURL;
     252        }
     253    }
     254    return $scriptURL;
     255    }
     256
     257    function style_loader_src($cssURL) {
     258    if (!is_admin()) {
     259        $urlParts = parse_url($cssURL);
     260        $justURL = $urlParts['scheme'] . '://' . $urlParts['host'] . $urlParts['path'];
     261        $fileCDNURL = self::getCDNURL($justURL);
     262        if ($fileCDNURL !== FALSE) {
     263        if (isset($urlParts['query']) && !empty($urlParts['query'])) {
     264            return $fileCDNURL . '?' . $urlParts['query'];
     265        }
     266        return $fileCDNURL;
     267        }else{
     268        $realPath = $this->getRealPath($justURL);
     269        if (file_exists($realPath)) {
     270            $cssFolder = dirname($realPath);
     271            $cssRelatedFiles = $this->scanDirectoryRecursively($cssFolder);
     272            if(!empty ($cssRelatedFiles)){
     273            foreach ($cssRelatedFiles as $relatedFile){
     274                $queueFiles = self::getCDNURL($this->siteURL.'/'.$relatedFile);
     275            }
     276            }
     277        }
     278        }
     279    }
     280    return $cssURL;
     281    }
     282
     283    function scanDirectoryRecursively($directory, $filter=FALSE, $directoryFiles = array()) {
     284
     285    if (substr($directory, -1) == DIRECTORY_SEPARATOR) {
     286        $directory = substr($directory, 0, -1);
     287    }
     288   
     289    $extensionToInclude = array('css','png','gif','jpg','jpeg');
     290   
     291    if (!file_exists($directory) || !is_dir($directory)) {
     292        return FALSE;
     293    } elseif (is_readable($directory)) {
     294        $directory_list = opendir($directory);
     295        while ($file = readdir($directory_list)) {
     296        if ($file != '.' && $file != '..') {
     297            $path = $directory . DIRECTORY_SEPARATOR . $file;
     298            if (is_readable($path)) {
     299            if (is_dir($path)) {
     300                $directoryFiles = $this->scanDirectoryRecursively($path, $filter, $directoryFiles);
     301            } elseif (is_file($path)) {
     302                $extension = strtolower(end(explode('.',$path)));
     303                if(in_array($extension, $extensionToInclude)){
     304                $directoryFiles[] = str_replace(ABSPATH, '', $path) ;
     305                }
     306            }
     307            }
     308        }
     309        }
     310        closedir($directory_list);
     311        return $directoryFiles;
     312    } else {
     313        return FALSE;
     314    }
     315    }
     316
     317    function getRealPath($fileURL) {
     318    $relativePath = ltrim(str_replace($this->siteURL, '', $fileURL), '/');
     319    return ABSPATH . $relativePath;
     320    }
     321
    255322    public static function getCDNURL($fileURL) {
    256323    $instance = self::getInstance();
    257324    $relativePath = ltrim(str_replace($instance->siteURL, '', $fileURL), '/');
    258 
    259     $realPath = ABSPATH . $relativePath;
     325    $realPath = $instance->getRealPath($fileURL);
    260326    if (file_exists($realPath)) {
    261327        foreach ($instance->blockDirectory as $blokedDirectory) {
     
    271337        }
    272338        }
    273 
    274339        $cacheFilePath = $instance->getFilePath($relativePath);
    275340        if (file_exists($cacheFilePath) === TRUE) {
Note: See TracChangeset for help on using the changeset viewer.