S3fsCssOptimizer.php in S3 File System 8.3
File
src/Asset/S3fsCssOptimizer.php
View source
<?php
namespace Drupal\s3fs\Asset;
use Drupal\Core\Asset\CssOptimizer;
use Drupal\Core\Config\ConfigFactoryInterface;
class S3fsCssOptimizer extends CssOptimizer {
protected $configFactory;
public function __construct(ConfigFactoryInterface $configFactory) {
$this->configFactory = $configFactory;
}
public function rewriteFileURI($matches) {
$alwaysSecure = !empty($this->configFactory
->get('s3fs.settings')
->get('use_https'));
$useCssjsHost = !empty($this->configFactory
->get('s3fs.settings')
->get('use_cssjs_host'));
$cssjsHost = $this->configFactory
->get('s3fs.settings')
->get('cssjs_host');
$path = $this->rewriteFileURIBasePath . $matches[1];
$last = '';
while ($path != $last) {
$last = $path;
$path = preg_replace('`(^|/)(?!\\.\\./)([^/]+)/\\.\\./`', '$1', $path);
}
$url = file_create_url($path);
if ($useCssjsHost && !empty($cssjsHost)) {
global $base_url;
$pattern = '#' . $base_url . '#';
$url = preg_replace($pattern, $cssjsHost, $url);
}
if ($alwaysSecure) {
$url = preg_replace('#^http?:#', 'https:', $url);
}
else {
$url = preg_replace('#^http?:#', '', $url);
}
return 'url(' . $url . ')';
}
}